Skip to content

feat(vendor): support for npm specifiers #19186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions cli/tests/integration/vendor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use test_util as util;
use test_util::TempDir;
use util::http_server;
use util::new_deno_dir;
use util::TestContextBuilder;

#[test]
fn output_dir_exists() {
Expand Down Expand Up @@ -537,6 +538,51 @@ fn update_existing_config_test() {
assert!(output.status.success());
}

#[test]
fn vendor_npm_node_specifiers() {
let context = TestContextBuilder::for_npm().use_temp_cwd().build();
let temp_dir = context.temp_dir();
temp_dir.write(
"my_app.ts",
concat!(
"import { path, getValue, setValue } from 'http://localhost:4545/vendor/npm_and_node_specifier.ts';\n",
"setValue(5);\n",
"console.log(path.isAbsolute(Deno.cwd()), getValue());",
),
);
temp_dir.write("deno.json", "{}");

let output = context.new_command().args("vendor my_app.ts").run();
output.assert_matches_text(
format!(
concat!(
"Download http://localhost:4545/vendor/npm_and_node_specifier.ts\n",
"Download http://localhost:4545/npm/registry/@denotest/esm-basic\n",
"Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz\n",
"{}\n",
),
success_text_updated_deno_json("1 module", "vendor/")
)
);
let output = context.new_command().args("run -A my_app.ts").run();
output.assert_matches_text("Initialize @denotest/[email protected]\ntrue 5\n");
assert!(temp_dir.path().join("node_modules").exists());
assert!(temp_dir.path().join("deno.lock").exists());

// now try re-vendoring with a lockfile
let output = context.new_command().args("vendor --force my_app.ts").run();
output.assert_matches_text(format!(
concat!(
"Ignoring import map. Specifying an import map file ({}) in the deno ",
"vendor output directory is not supported. If you wish to use an ",
"import map while vendoring, please specify one located outside this ",
"directory.\n{}\n",
),
PathBuf::from("vendor").join("import_map.json").display(),
success_text_updated_deno_json("1 module", "vendor/"),
));
}

fn success_text(module_count: &str, dir: &str, has_import_map: bool) -> String {
let mut text = format!("Vendored {module_count} into {dir} directory.");
if has_import_map {
Expand Down
2 changes: 2 additions & 0 deletions cli/tests/testdata/vendor/npm_and_node_specifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as path } from "node:path";
export { getValue, setValue } from "npm:@denotest/esm-basic";
2 changes: 1 addition & 1 deletion cli/tools/vendor/import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ fn handle_dep_specifier(
referrer,
mappings,
)
} else {
} else if specifier.scheme() == "file" {
handle_local_dep_specifier(
text,
unresolved_specifier,
Expand Down
Loading