Skip to content

Commit

Permalink
fix(byonm): correct resolution for scoped packages (#21083)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Nov 6, 2023
1 parent 56a4c98 commit 7eb34c7
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 28 deletions.
67 changes: 39 additions & 28 deletions cli/tests/integration/npm_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2227,17 +2227,9 @@ pub fn byonm_cjs_esm_packages() {
.use_temp_cwd()
.build();
let dir = test_context.temp_dir();
let run_npm = |args: &str| {
test_context
.new_command()
.name("npm")
.args(args)
.run()
.skip_output_check();
};

run_npm("init -y");
run_npm("install @denotest/esm-basic @denotest/cjs-default-export @denotest/dual-cjs-esm chalk@4 chai@4.3");
test_context.run_npm("init -y");
test_context.run_npm("install @denotest/esm-basic @denotest/cjs-default-export @denotest/dual-cjs-esm chalk@4 chai@4.3");

dir.write(
"main.ts",
Expand Down Expand Up @@ -2346,12 +2338,7 @@ pub fn byonm_package_specifier_not_installed_and_invalid_subpath() {
"import '@denotest/conditional-exports-strict/test';",
);

test_context
.new_command()
.name("npm")
.args("install")
.run()
.skip_output_check();
test_context.run_npm("install");

let output = test_context.new_command().args("run main.ts").run();
output.assert_matches_text(
Expand Down Expand Up @@ -2395,12 +2382,7 @@ pub fn byonm_package_npm_specifier_not_installed_and_invalid_subpath() {
"import 'npm:@denotest/conditional-exports-strict/test';",
);

test_context
.new_command()
.name("npm")
.args("install")
.run()
.skip_output_check();
test_context.run_npm("install");

let output = test_context.new_command().args("run main.ts").run();
output.assert_matches_text(
Expand Down Expand Up @@ -2487,12 +2469,7 @@ console.log(add(1, 2));
"#,
);

test_context
.new_command()
.name("npm")
.args("install")
.run()
.skip_output_check();
test_context.run_npm("install");

let output = test_context
.new_command()
Expand Down Expand Up @@ -2530,3 +2507,37 @@ itest!(imports_package_json_sub_path_import_not_defined {
exit_code: 1,
http_server: true,
});

itest!(different_nested_dep_node_modules_dir_false {
args: "run --quiet --node-modules-dir=false npm/different_nested_dep/main.js",
output: "npm/different_nested_dep/main.out",
envs: env_vars_for_npm_tests(),
exit_code: 0,
http_server: true,
});

itest!(different_nested_dep_node_modules_dir_true {
args: "run --quiet --node-modules-dir=true main.js",
output: "npm/different_nested_dep/main.out",
copy_temp_dir: Some("npm/different_nested_dep/"),
cwd: Some("npm/different_nested_dep/"),
envs: env_vars_for_npm_tests(),
exit_code: 0,
http_server: true,
});

#[test]
pub fn different_nested_dep_byonm() {
let test_context = TestContextBuilder::for_npm()
.use_copy_temp_dir("npm/different_nested_dep")
.cwd("npm/different_nested_dep/")
.build();

test_context.run_npm("install");

let output = test_context
.new_command()
.args("run --unstable-byonm main.js")
.run();
output.assert_matches_file("npm/different_nested_dep/main.out");
}
5 changes: 5 additions & 0 deletions cli/tests/testdata/npm/different_nested_dep/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import dep from "@denotest/different-nested-dep";
import childDep from "@denotest/different-nested-dep-child";

console.log(dep);
console.log(childDep);
2 changes: 2 additions & 0 deletions cli/tests/testdata/npm/different_nested_dep/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
2
6 changes: 6 additions & 0 deletions cli/tests/testdata/npm/different_nested_dep/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"@denotest/different-nested-dep": "1.0.0",
"@denotest/different-nested-dep-child": "2.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@denotest/different-nested-dep-child",
"type": "module",
"version": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@denotest/different-nested-dep-child",
"type": "module",
"version": "2.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import version from "@denotest/different-nested-dep-child";
export default version;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@denotest/different-nested-dep",
"version": "1.0.0",
"type": "module",
"dependencies": {
"@denotest/different-nested-dep-child": "1.0.0"
}
}
9 changes: 9 additions & 0 deletions test_util/src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ impl TestContext {
builder.deno_exe(&self.deno_exe).set_test_context(self);
builder
}

pub fn run_npm(&self, args: impl AsRef<str>) {
self
.new_command()
.name("npm")
.args(args)
.run()
.skip_output_check();
}
}

pub struct TestCommandBuilder {
Expand Down

0 comments on commit 7eb34c7

Please sign in to comment.