-
Notifications
You must be signed in to change notification settings - Fork 5.6k
feat(compat): Node CJS and ESM resolvers #12424
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 16 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
29883b3
temp
bartlomieju 9200bb2
parse_package_name
bartlomieju becf749
module_resolve
bartlomieju 96a84d3
package_exports_resolve
bartlomieju 371ffcc
resolve_package_target_string
bartlomieju 0f62c43
Merge branch 'main' into compat_node_resolver
bartlomieju dfd1190
node_resolve
bartlomieju 6954cf6
chalk example working
bartlomieju a0b1ba6
legacy_main_resolve
bartlomieju 5d41393
pass conditions
bartlomieju 03ef6f7
rename, remove debug prints
bartlomieju ccf73ec
clippy
bartlomieju 34bb541
add tests
ry bea885a
add deep test
ry bba059a
fmt
ry 89e11b3
remove import map
bartlomieju 349804c
port errors
bartlomieju be08d09
lint
bartlomieju fe5460f
revert pub modifiers, rename module
bartlomieju ef6f6d3
fix tests
bartlomieju 28efb3e
add helpers
bartlomieju 13079df
finish resolve_package_target_string
bartlomieju 57f3323
err_package_not_exported
bartlomieju 8e0a80b
add missing methods
bartlomieju efdfd6a
add error code
bartlomieju 3696f95
reset CI
bartlomieju a12f3e9
add CJS resolver
bartlomieju adb3fc4
reorganize code
bartlomieju f2104fa
add deno condition
bartlomieju c1c49d0
use raw.githubusercontent.com
bartlomieju 6d9b808
Merge branch 'main' into compat_node_resolver
bartlomieju 4c855f2
don't require --allow-net permission for compat mode
bartlomieju 43984e4
add test for conditional exports
bartlomieju cfb47bd
update reference to deno_std
bartlomieju b583bd7
Merge branch 'main' into compat_node_resolver
ry 62dd1c6
small clean ups
ry b32b4cd
add test_is_relative_specifier
ry 09e9dae
review comments
bartlomieju 8c39946
fix test
bartlomieju a3f6a61
Merge branch 'main' into compat_node_resolver
bartlomieju f357f98
fix test
bartlomieju fa59547
Escape injected string.
dsherret cb1652c
Escape other injected single quote string too.
dsherret f6686da
Remove accidental println
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 |
---|---|---|
@@ -1,16 +1,19 @@ | ||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. | ||
|
||
mod node_module_loader; | ||
|
||
use deno_core::url::Url; | ||
use std::collections::HashMap; | ||
|
||
pub use node_module_loader::NodeEsmResolver; | ||
|
||
// TODO(bartlomieju): this needs to be bumped manually for | ||
// each release, a better mechanism is preferable, but it's a quick and dirty | ||
// solution to avoid printing `X-Deno-Warning` headers when the compat layer is | ||
// downloaded | ||
static STD_URL: &str = "https://deno.land/[email protected]/"; | ||
pub(crate) static STD_URL: &str = "https://deno.land/[email protected]/"; | ||
static GLOBAL_MODULE: &str = "global.ts"; | ||
|
||
static SUPPORTED_MODULES: &[&str] = &[ | ||
pub(crate) static SUPPORTED_MODULES: &[&str] = &[ | ||
"assert", | ||
"assert/strict", | ||
"async_hooks", | ||
|
@@ -66,23 +69,11 @@ pub(crate) fn get_node_imports() -> Vec<(Url, Vec<String>)> { | |
vec![(COMPAT_IMPORT_URL.clone(), vec![GLOBAL_URL_STR.clone()])] | ||
} | ||
|
||
/// Create a map that can be used to update import map. | ||
/// | ||
/// Keys are built-in Node modules (and built-ins prefixed with "node:"), while | ||
/// values are URLs pointing to relevant files in deno.land/std/node/ directory. | ||
pub fn get_mapped_node_builtins() -> HashMap<String, String> { | ||
let mut mappings = HashMap::new(); | ||
|
||
for module in SUPPORTED_MODULES { | ||
// TODO(bartlomieju): this is unversioned, and should be fixed to use latest stable? | ||
let module_url = format!("{}node/{}.ts", STD_URL, module); | ||
mappings.insert(module.to_string(), module_url.clone()); | ||
|
||
// Support for `node:<module_name>` | ||
// https://nodejs.org/api/esm.html#esm_node_imports | ||
let node_prefixed = format!("node:{}", module); | ||
mappings.insert(node_prefixed, module_url); | ||
pub(crate) fn try_resolve_builtin_module(specifier: &str) -> Option<Url> { | ||
if SUPPORTED_MODULES.contains(&specifier) { | ||
let module_url = format!("{}node/{}.ts", crate::compat::STD_URL, specifier); | ||
Some(Url::parse(&module_url).unwrap()) | ||
} else { | ||
None | ||
} | ||
|
||
mappings | ||
} |
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.