-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f51aa15
feat(vendor): support for npm specifiers
dsherret c8d7d58
Merge branch 'main' into feat_vendor_npm_specifiers
dsherret bd37486
Modify the config file
dsherret 95e5f63
Add tests
dsherret 364c4a6
Merge branch 'main' into feat_vendor_npm_specifiers
dsherret 0219d5f
Update
dsherret a197f8c
Cache the node_modules folder when running `deno vendor` if necessary
dsherret 460dc29
Add test and fix issues with vendoring only npm packages
dsherret 9a8d86b
Update message.
dsherret File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -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() { | ||
|
@@ -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 { | ||
|
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as path } from "node:path"; | ||
export { getValue, setValue } from "npm:@denotest/esm-basic"; |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.