forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
javascript: fix running scripts with yarn (pantsbuild#20543)
Fixes pantsbuild#20542
- Loading branch information
Kevin Oliveira
authored
Feb 14, 2024
1 parent
b39e2c4
commit a7f86a0
Showing
2 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ def rule_runner() -> RuleRunner: | |
return rule_runner | ||
|
||
|
||
def test_creates_run_requests_package_json_scripts(rule_runner: RuleRunner) -> None: | ||
def test_creates_npm_run_requests_package_json_scripts(rule_runner: RuleRunner) -> None: | ||
rule_runner.write_files( | ||
{ | ||
"src/js/BUILD": dedent( | ||
|
@@ -77,6 +77,49 @@ def test_creates_run_requests_package_json_scripts(rule_runner: RuleRunner) -> N | |
assert result.args == ("npm", "--prefix", "{chroot}", "run", script) | ||
|
||
|
||
def test_creates_yarn_run_requests_package_json_scripts(rule_runner: RuleRunner) -> None: | ||
rule_runner.write_files( | ||
{ | ||
"src/js/BUILD": dedent( | ||
"""\ | ||
package_json( | ||
scripts=[ | ||
node_build_script(entry_point="build", output_directories=["dist"]), | ||
node_build_script(entry_point="compile", output_directories=["dist"]), | ||
node_build_script(entry_point="transpile", output_directories=["dist"]), | ||
] | ||
) | ||
""" | ||
), | ||
"src/js/package.json": json.dumps( | ||
{ | ||
"name": "ham", | ||
"version": "0.0.1", | ||
"browser": "lib/index.mjs", | ||
"scripts": { | ||
"build": "swc ./lib -d dist", | ||
"transpile": "babel ./lib -d dist", | ||
"compile": "tsc ./lib --emit -d bin", | ||
}, | ||
"packageManager": "[email protected]", | ||
} | ||
), | ||
"src/js/yarn.lock": "", | ||
"src/js/lib/BUILD": dedent( | ||
"""\ | ||
javascript_sources() | ||
""" | ||
), | ||
"src/js/lib/index.mjs": "", | ||
} | ||
) | ||
for script in ("build", "compile", "transpile"): | ||
tgt = rule_runner.get_target(Address("src/js", generated_name=script)) | ||
result = rule_runner.request(RunRequest, [RunNodeBuildScriptFieldSet.create(tgt)]) | ||
|
||
assert result.args == ("yarn", "--cwd", "{chroot}", "run", script) | ||
|
||
|
||
def test_extra_envs(rule_runner: RuleRunner) -> None: | ||
rule_runner.write_files( | ||
{ | ||
|