From 115a3066565c96500ad740a8c6a3b4ef99af7fb0 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 26 Nov 2024 14:38:24 -0500 Subject: [PATCH] fix(node): correct resolution of dynamic import of esm from cjs (#27071) Ensures a dynamic import in a CJS file will consider the referrer as an import for node resolution. Also adds fixes (adds) support for `"resolution-mode"` in TypeScript. --- Cargo.lock | 153 +-------- cli/Cargo.toml | 4 +- cli/cache/module_info.rs | 24 +- cli/graph_util.rs | 64 ++-- cli/lsp/analysis.rs | 63 ++-- cli/lsp/completions.rs | 52 ++- cli/lsp/diagnostics.rs | 6 +- cli/lsp/documents.rs | 76 +++-- cli/lsp/language_server.rs | 26 +- cli/lsp/resolver.rs | 64 ++-- cli/lsp/tsc.rs | 30 +- cli/module_loader.rs | 27 +- cli/resolver.rs | 40 +-- cli/standalone/mod.rs | 20 +- cli/tools/doc.rs | 28 +- cli/tools/info.rs | 35 +- cli/tools/lint/rules/no_sloppy_imports.rs | 22 +- cli/tools/registry/diagnostics.rs | 14 +- cli/tools/registry/unfurl.rs | 14 +- cli/tools/repl/session.rs | 16 +- cli/tsc/99_main_compiler.js | 73 +++-- cli/tsc/mod.rs | 63 ++-- cli/worker.rs | 8 +- ext/node/ops/require.rs | 16 +- resolvers/deno/cjs.rs | 92 +++--- resolvers/deno/lib.rs | 42 +-- resolvers/deno/npm/mod.rs | 34 +- resolvers/deno/sloppy_imports.rs | 36 ++- resolvers/node/analyze.rs | 20 +- resolvers/node/errors.rs | 32 +- resolvers/node/lib.rs | 4 +- resolvers/node/resolution.rs | 303 ++++++++++-------- .../__test__.jsonc | 44 +++ .../dynamic_import_and_require_dual/check.out | 5 + .../dynamic_import_and_require_dual/index.cts | 8 + .../dynamic_import_and_require_dual/index.mjs | 11 + .../jsdoc_import_decl.js | 12 + .../jsdoc_import_decl.out | 5 + .../node_modules/package/mod.d.mts | 1 + .../node_modules/package/mod.mjs | 1 + .../node_modules/package/package.json | 11 + .../node_modules/package/require.cjs | 1 + .../node_modules/package/require.d.cts | 1 + .../package.json | 6 + .../resolution_mode_import.mts | 6 + .../resolution_mode_import.out | 5 + .../resolution_mode_require.mts | 6 + .../resolution_mode_require.out | 5 + .../resolution_mode_require_import_type.out | 0 .../resolution_mode_require_import_type.ts | 5 + .../resolution_mode_require_jsdoc.js | 12 + .../resolution_mode_require_jsdoc.out | 5 + .../run_cjs.out | 2 + .../run_mts.out | 3 + .../npm/info_chalk_display/__test__.jsonc | 4 +- .../info_chalk_display/cjs_with_deps/main.out | 33 -- .../cjs_with_deps/main_info_json.out | 148 --------- .../cjs_with_deps/main_node_modules.out | 47 --- .../{cjs_with_deps => }/main.js | 0 .../main_info.out | 2 +- .../__test__.jsonc | 4 +- .../cjs_with_deps/main.out | 33 -- .../cjs_with_deps/main_info.out | 22 -- .../cjs_with_deps/main_info_json.out | 148 --------- .../cjs_with_deps/main_node_modules.out | 47 --- .../{cjs_with_deps => }/main.js | 0 .../main_info.out | 2 +- .../specs/npm/info_chalk_json/__test__.jsonc | 4 +- .../info_chalk_json/cjs_with_deps/main.out | 33 -- .../cjs_with_deps/main_node_modules.out | 47 --- .../{cjs_with_deps => }/main.js | 0 .../{cjs_with_deps => }/main_info_json.out | 0 .../__test__.jsonc | 4 +- .../cjs_with_deps/main.out | 33 -- .../cjs_with_deps/main_info.out | 22 -- .../cjs_with_deps/main_node_modules.out | 47 --- .../{cjs_with_deps => }/main.js | 0 .../{cjs_with_deps => }/main_info_json.out | 0 tests/specs/npm/info_peer_deps/__test__.jsonc | 4 +- .../main.ts | 0 .../main_info.out | 2 +- .../peer_deps_with_copied_folders/main.out | 14 - .../main_info_json.out | 97 ------ .../main_node_modules.out | 9 - .../main_node_modules_reload.out | 19 -- .../npm/info_peer_deps_json/__test__.jsonc | 4 +- .../main.ts | 0 .../main_info_json.out | 0 .../peer_deps_with_copied_folders/main.out | 14 - .../main_info.out | 14 - .../main_node_modules.out | 9 - .../main_node_modules_reload.out | 19 -- 92 files changed, 868 insertions(+), 1673 deletions(-) create mode 100644 tests/specs/node/dynamic_import_and_require_dual/__test__.jsonc create mode 100644 tests/specs/node/dynamic_import_and_require_dual/check.out create mode 100644 tests/specs/node/dynamic_import_and_require_dual/index.cts create mode 100644 tests/specs/node/dynamic_import_and_require_dual/index.mjs create mode 100644 tests/specs/node/dynamic_import_and_require_dual/jsdoc_import_decl.js create mode 100644 tests/specs/node/dynamic_import_and_require_dual/jsdoc_import_decl.out create mode 100644 tests/specs/node/dynamic_import_and_require_dual/node_modules/package/mod.d.mts create mode 100644 tests/specs/node/dynamic_import_and_require_dual/node_modules/package/mod.mjs create mode 100644 tests/specs/node/dynamic_import_and_require_dual/node_modules/package/package.json create mode 100644 tests/specs/node/dynamic_import_and_require_dual/node_modules/package/require.cjs create mode 100644 tests/specs/node/dynamic_import_and_require_dual/node_modules/package/require.d.cts create mode 100644 tests/specs/node/dynamic_import_and_require_dual/package.json create mode 100644 tests/specs/node/dynamic_import_and_require_dual/resolution_mode_import.mts create mode 100644 tests/specs/node/dynamic_import_and_require_dual/resolution_mode_import.out create mode 100644 tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require.mts create mode 100644 tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require.out create mode 100644 tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_import_type.out create mode 100644 tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_import_type.ts create mode 100644 tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_jsdoc.js create mode 100644 tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_jsdoc.out create mode 100644 tests/specs/node/dynamic_import_and_require_dual/run_cjs.out create mode 100644 tests/specs/node/dynamic_import_and_require_dual/run_mts.out delete mode 100644 tests/specs/npm/info_chalk_display/cjs_with_deps/main.out delete mode 100644 tests/specs/npm/info_chalk_display/cjs_with_deps/main_info_json.out delete mode 100644 tests/specs/npm/info_chalk_display/cjs_with_deps/main_node_modules.out rename tests/specs/npm/info_chalk_display/{cjs_with_deps => }/main.js (100%) rename tests/specs/npm/{info_chalk_json/cjs_with_deps => info_chalk_display}/main_info.out (94%) delete mode 100644 tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main.out delete mode 100644 tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_info.out delete mode 100644 tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_info_json.out delete mode 100644 tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_node_modules.out rename tests/specs/npm/info_chalk_display_node_modules_dir/{cjs_with_deps => }/main.js (100%) rename tests/specs/npm/{info_chalk_display/cjs_with_deps => info_chalk_display_node_modules_dir}/main_info.out (94%) delete mode 100644 tests/specs/npm/info_chalk_json/cjs_with_deps/main.out delete mode 100644 tests/specs/npm/info_chalk_json/cjs_with_deps/main_node_modules.out rename tests/specs/npm/info_chalk_json/{cjs_with_deps => }/main.js (100%) rename tests/specs/npm/info_chalk_json/{cjs_with_deps => }/main_info_json.out (100%) delete mode 100644 tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main.out delete mode 100644 tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_info.out delete mode 100644 tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_node_modules.out rename tests/specs/npm/info_chalk_json_node_modules_dir/{cjs_with_deps => }/main.js (100%) rename tests/specs/npm/info_chalk_json_node_modules_dir/{cjs_with_deps => }/main_info_json.out (100%) rename tests/specs/npm/info_peer_deps/{peer_deps_with_copied_folders => }/main.ts (100%) rename tests/specs/npm/info_peer_deps/{peer_deps_with_copied_folders => }/main_info.out (91%) delete mode 100644 tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main.out delete mode 100644 tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_info_json.out delete mode 100644 tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_node_modules.out delete mode 100644 tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_node_modules_reload.out rename tests/specs/npm/info_peer_deps_json/{peer_deps_with_copied_folders => }/main.ts (100%) rename tests/specs/npm/info_peer_deps_json/{peer_deps_with_copied_folders => }/main_info_json.out (100%) delete mode 100644 tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main.out delete mode 100644 tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_info.out delete mode 100644 tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_node_modules.out delete mode 100644 tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_node_modules_reload.out diff --git a/Cargo.lock b/Cargo.lock index 00b4da07cd..5f59c936e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,19 +128,6 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" -[[package]] -name = "ammonia" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ab99eae5ee58501ab236beb6f20f6ca39be615267b014899c89b2f0bc18a459" -dependencies = [ - "html5ever", - "maplit", - "once_cell", - "tendril", - "url", -] - [[package]] name = "android_system_properties" version = "0.1.5" @@ -1557,18 +1544,16 @@ dependencies = [ [[package]] name = "deno_doc" -version = "0.160.0" +version = "0.161.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2baa33e5d1ed235209c2990f5fe9644bac6b9e7bcb789dd92894f907b09ad7" +checksum = "32d994915f85e873865fc341e592080a487b0a987d06177016b2d93fd62162f8" dependencies = [ - "ammonia", "anyhow", "cfg-if", "comrak", "deno_ast", "deno_graph", "deno_path_util", - "futures", "handlebars", "html-escape", "import_map", @@ -1665,9 +1650,9 @@ dependencies = [ [[package]] name = "deno_graph" -version = "0.85.1" +version = "0.86.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c11027d9b4e9ff4f8bcb8316a1a5dd5241dc267380507e177457bc491696189" +checksum = "4c3f4be49dad28e794ff4eeb2daaf7956c97f8557097ef6f9c3ff1292e0a5c28" dependencies = [ "anyhow", "async-trait", @@ -3265,16 +3250,6 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" -[[package]] -name = "futf" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df420e2e84819663797d1ec6544b13c5be84629e7bb00dc960d6917db2987843" -dependencies = [ - "mac", - "new_debug_unreachable", -] - [[package]] name = "futures" version = "0.3.30" @@ -3802,20 +3777,6 @@ dependencies = [ "utf8-width", ] -[[package]] -name = "html5ever" -version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" -dependencies = [ - "log", - "mac", - "markup5ever", - "proc-macro2", - "quote", - "syn 2.0.87", -] - [[package]] name = "http" version = "0.2.12" @@ -4663,12 +4624,6 @@ dependencies = [ "serde_repr", ] -[[package]] -name = "mac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" - [[package]] name = "malloc_buf" version = "0.0.6" @@ -4691,26 +4646,6 @@ dependencies = [ "tiny_pretty", ] -[[package]] -name = "maplit" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" - -[[package]] -name = "markup5ever" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" -dependencies = [ - "log", - "phf", - "phf_codegen", - "string_cache", - "string_cache_codegen", - "tendril", -] - [[package]] name = "markup_fmt" version = "0.16.0" @@ -5468,27 +5403,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ "phf_macros", - "phf_shared 0.11.2", -] - -[[package]] -name = "phf_codegen" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8d39688d359e6b34654d328e262234662d16cc0f60ec8dcbe5e718709342a5a" -dependencies = [ - "phf_generator 0.11.2", - "phf_shared 0.11.2", -] - -[[package]] -name = "phf_generator" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" -dependencies = [ - "phf_shared 0.10.0", - "rand", + "phf_shared", ] [[package]] @@ -5497,7 +5412,7 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48e4cc64c2ad9ebe670cb8fd69dd50ae301650392e81c05f9bfcb2d5bdbc24b0" dependencies = [ - "phf_shared 0.11.2", + "phf_shared", "rand", ] @@ -5507,22 +5422,13 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3444646e286606587e49f3bcf1679b8cef1dc2c5ecc29ddacaffc305180d464b" dependencies = [ - "phf_generator 0.11.2", - "phf_shared 0.11.2", + "phf_generator", + "phf_shared", "proc-macro2", "quote", "syn 2.0.87", ] -[[package]] -name = "phf_shared" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" -dependencies = [ - "siphasher", -] - [[package]] name = "phf_shared" version = "0.11.2" @@ -5645,12 +5551,6 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" -[[package]] -name = "precomputed-hash" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" - [[package]] name = "pretty_assertions" version = "1.4.0" @@ -6985,32 +6885,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "string_cache" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" -dependencies = [ - "new_debug_unreachable", - "once_cell", - "parking_lot", - "phf_shared 0.10.0", - "precomputed-hash", - "serde", -] - -[[package]] -name = "string_cache_codegen" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" -dependencies = [ - "phf_generator 0.10.0", - "phf_shared 0.10.0", - "proc-macro2", - "quote", -] - [[package]] name = "string_enum" version = "0.4.4" @@ -7598,17 +7472,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "tendril" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d24a120c5fc464a3458240ee02c299ebcb9d67b5249c8848b09d639dca8d7bb0" -dependencies = [ - "futf", - "mac", - "utf-8", -] - [[package]] name = "termcolor" version = "1.4.1" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 96bb206d0f..fd28b315d4 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -72,8 +72,8 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposa deno_cache_dir.workspace = true deno_config.workspace = true deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } -deno_doc = { version = "0.160.0", features = ["rust", "comrak"] } -deno_graph = { version = "=0.85.1" } +deno_doc = { version = "=0.161.1", features = ["rust", "comrak"] } +deno_graph = { version = "=0.86.2" } deno_lint = { version = "=0.68.0", features = ["docs"] } deno_lockfile.workspace = true deno_npm.workspace = true diff --git a/cli/cache/module_info.rs b/cli/cache/module_info.rs index 060a6f4f0c..469e2fafac 100644 --- a/cli/cache/module_info.rs +++ b/cli/cache/module_info.rs @@ -284,6 +284,7 @@ fn serialize_media_type(media_type: MediaType) -> i64 { #[cfg(test)] mod test { + use deno_graph::JsDocImportInfo; use deno_graph::PositionRange; use deno_graph::SpecifierWithRange; @@ -308,18 +309,21 @@ mod test { ); let mut module_info = ModuleInfo::default(); - module_info.jsdoc_imports.push(SpecifierWithRange { - range: PositionRange { - start: deno_graph::Position { - line: 0, - character: 3, - }, - end: deno_graph::Position { - line: 1, - character: 2, + module_info.jsdoc_imports.push(JsDocImportInfo { + specifier: SpecifierWithRange { + range: PositionRange { + start: deno_graph::Position { + line: 0, + character: 3, + }, + end: deno_graph::Position { + line: 1, + character: 2, + }, }, + text: "test".to_string(), }, - text: "test".to_string(), + resolution_mode: None, }); cache .set_module_info( diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 6ed0506dd7..360021d22d 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -25,7 +25,7 @@ use deno_config::deno_json::JsxImportSourceConfig; use deno_config::workspace::JsrPackageConfig; use deno_core::anyhow::bail; use deno_graph::source::LoaderChecksum; -use deno_graph::source::ResolutionMode; +use deno_graph::source::ResolutionKind; use deno_graph::FillFromLockfileOptions; use deno_graph::JsrLoadError; use deno_graph::ModuleLoadError; @@ -44,7 +44,7 @@ use deno_graph::ModuleGraphError; use deno_graph::ResolutionError; use deno_graph::SpecifierError; use deno_path_util::url_to_file_path; -use deno_resolver::sloppy_imports::SloppyImportsResolutionMode; +use deno_resolver::sloppy_imports::SloppyImportsResolutionKind; use deno_runtime::deno_fs::FileSystem; use deno_runtime::deno_node; use deno_runtime::deno_permissions::PermissionsContainer; @@ -795,7 +795,7 @@ fn enhanced_sloppy_imports_error_message( ModuleError::LoadingErr(specifier, _, ModuleLoadError::Loader(_)) // ex. "Is a directory" error | ModuleError::Missing(specifier, _) => { let additional_message = CliSloppyImportsResolver::new(SloppyImportsCachedFs::new(fs.clone())) - .resolve(specifier, SloppyImportsResolutionMode::Execution)? + .resolve(specifier, SloppyImportsResolutionKind::Execution)? .as_suggestion_message(); Some(format!( "{} {} or run with --unstable-sloppy-imports", @@ -1100,12 +1100,12 @@ impl<'a> deno_graph::source::FileSystem for DenoGraphFsAdapter<'a> { } } -pub fn format_range_with_colors(range: &deno_graph::Range) -> String { +pub fn format_range_with_colors(referrer: &deno_graph::Range) -> String { format!( "{}:{}:{}", - colors::cyan(range.specifier.as_str()), - colors::yellow(&(range.start.line + 1).to_string()), - colors::yellow(&(range.start.character + 1).to_string()) + colors::cyan(referrer.specifier.as_str()), + colors::yellow(&(referrer.range.start.line + 1).to_string()), + colors::yellow(&(referrer.range.start.character + 1).to_string()) ) } @@ -1195,26 +1195,54 @@ impl<'a> deno_graph::source::Resolver for CliGraphResolver<'a> { &self, raw_specifier: &str, referrer_range: &deno_graph::Range, - mode: ResolutionMode, + resolution_kind: ResolutionKind, ) -> Result { self.resolver.resolve( raw_specifier, - referrer_range, - self - .cjs_tracker - .get_referrer_kind(&referrer_range.specifier), - mode, + &referrer_range.specifier, + referrer_range.range.start, + referrer_range + .resolution_mode + .map(to_node_resolution_mode) + .unwrap_or_else(|| { + self + .cjs_tracker + .get_referrer_kind(&referrer_range.specifier) + }), + to_node_resolution_kind(resolution_kind), ) } } +pub fn to_node_resolution_kind( + kind: ResolutionKind, +) -> node_resolver::NodeResolutionKind { + match kind { + ResolutionKind::Execution => node_resolver::NodeResolutionKind::Execution, + ResolutionKind::Types => node_resolver::NodeResolutionKind::Types, + } +} + +pub fn to_node_resolution_mode( + mode: deno_graph::source::ResolutionMode, +) -> node_resolver::ResolutionMode { + match mode { + deno_graph::source::ResolutionMode::Import => { + node_resolver::ResolutionMode::Import + } + deno_graph::source::ResolutionMode::Require => { + node_resolver::ResolutionMode::Require + } + } +} + #[cfg(test)] mod test { use std::sync::Arc; use deno_ast::ModuleSpecifier; use deno_graph::source::ResolveError; - use deno_graph::Position; + use deno_graph::PositionRange; use deno_graph::Range; use deno_graph::ResolutionError; use deno_graph::SpecifierError; @@ -1235,8 +1263,8 @@ mod test { specifier: input.to_string(), range: Range { specifier, - start: Position::zeroed(), - end: Position::zeroed(), + resolution_mode: None, + range: PositionRange::zeroed(), }, }; assert_eq!(get_resolution_error_bare_node_specifier(&err), output); @@ -1251,8 +1279,8 @@ mod test { let err = ResolutionError::InvalidSpecifier { range: Range { specifier, - start: Position::zeroed(), - end: Position::zeroed(), + resolution_mode: None, + range: PositionRange::zeroed(), }, error: SpecifierError::ImportPrefixMissing { specifier: input.to_string(), diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs index 044b1573b9..eca1f15ed0 100644 --- a/cli/lsp/analysis.rs +++ b/cli/lsp/analysis.rs @@ -15,7 +15,6 @@ use crate::lsp::search::PackageSearchApi; use crate::tools::lint::CliLinter; use crate::util::path::relative_specifier; use deno_config::workspace::MappedResolution; -use deno_graph::source::ResolutionMode; use deno_lint::diagnostic::LintDiagnosticRange; use deno_ast::SourceRange; @@ -39,7 +38,8 @@ use deno_semver::package::PackageReq; use deno_semver::package::PackageReqReference; use deno_semver::Version; use import_map::ImportMap; -use node_resolver::NodeModuleKind; +use node_resolver::NodeResolutionKind; +use node_resolver::ResolutionMode; use once_cell::sync::Lazy; use regex::Regex; use std::borrow::Cow; @@ -467,7 +467,7 @@ impl<'a> TsResponseImportMapper<'a> { &self, specifier: &str, referrer: &ModuleSpecifier, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, ) -> Option { let specifier_stem = specifier.strip_suffix(".js").unwrap_or(specifier); let specifiers = std::iter::once(Cow::Borrowed(specifier)).chain( @@ -481,13 +481,10 @@ impl<'a> TsResponseImportMapper<'a> { .as_cli_resolver(Some(&self.file_referrer)) .resolve( &specifier, - &deno_graph::Range { - specifier: referrer.clone(), - start: deno_graph::Position::zeroed(), - end: deno_graph::Position::zeroed(), - }, - referrer_kind, - ResolutionMode::Types, + referrer, + deno_graph::Position::zeroed(), + resolution_mode, + NodeResolutionKind::Types, ) .ok() .and_then(|s| self.tsc_specifier_map.normalize(s.as_str()).ok()) @@ -509,20 +506,17 @@ impl<'a> TsResponseImportMapper<'a> { &self, specifier_text: &str, referrer: &ModuleSpecifier, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, ) -> bool { self .resolver .as_cli_resolver(Some(&self.file_referrer)) .resolve( specifier_text, - &deno_graph::Range { - specifier: referrer.clone(), - start: deno_graph::Position::zeroed(), - end: deno_graph::Position::zeroed(), - }, - referrer_kind, - deno_graph::source::ResolutionMode::Types, + referrer, + deno_graph::Position::zeroed(), + resolution_mode, + NodeResolutionKind::Types, ) .is_ok() } @@ -590,7 +584,7 @@ fn try_reverse_map_package_json_exports( /// like an import and rewrite the import specifier to include the extension pub fn fix_ts_import_changes( referrer: &ModuleSpecifier, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, changes: &[tsc::FileTextChanges], language_server: &language_server::Inner, ) -> Result, AnyError> { @@ -608,7 +602,7 @@ pub fn fix_ts_import_changes( let specifier = captures.iter().skip(1).find_map(|s| s).unwrap().as_str(); if let Some(new_specifier) = import_mapper - .check_unresolved_specifier(specifier, referrer, referrer_kind) + .check_unresolved_specifier(specifier, referrer, resolution_mode) { line.replace(specifier, &new_specifier) } else { @@ -638,7 +632,7 @@ pub fn fix_ts_import_changes( /// resolution by Deno (includes the extension). fn fix_ts_import_action<'a>( referrer: &ModuleSpecifier, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, action: &'a tsc::CodeFixAction, language_server: &language_server::Inner, ) -> Option> { @@ -657,9 +651,11 @@ fn fix_ts_import_action<'a>( return Some(Cow::Borrowed(action)); }; let import_mapper = language_server.get_ts_response_import_mapper(referrer); - if let Some(new_specifier) = - import_mapper.check_unresolved_specifier(specifier, referrer, referrer_kind) - { + if let Some(new_specifier) = import_mapper.check_unresolved_specifier( + specifier, + referrer, + resolution_mode, + ) { let description = action.description.replace(specifier, &new_specifier); let changes = action .changes @@ -689,7 +685,8 @@ fn fix_ts_import_action<'a>( fix_id: None, fix_all_description: None, })) - } else if !import_mapper.is_valid_import(specifier, referrer, referrer_kind) { + } else if !import_mapper.is_valid_import(specifier, referrer, resolution_mode) + { None } else { Some(Cow::Borrowed(action)) @@ -1023,7 +1020,7 @@ impl CodeActionCollection { pub fn add_ts_fix_action( &mut self, specifier: &ModuleSpecifier, - specifier_kind: NodeModuleKind, + resolution_mode: ResolutionMode, action: &tsc::CodeFixAction, diagnostic: &lsp::Diagnostic, language_server: &language_server::Inner, @@ -1042,7 +1039,7 @@ impl CodeActionCollection { )); } let Some(action) = - fix_ts_import_action(specifier, specifier_kind, action, language_server) + fix_ts_import_action(specifier, resolution_mode, action, language_server) else { return Ok(()); }; @@ -1237,12 +1234,12 @@ impl CodeActionCollection { let text_info = parsed_source.text_info_lazy(); let specifier_range = SourceRange::new( text_info.loc_to_source_pos(LineAndColumnIndex { - line_index: import.specifier_range.start.line, - column_index: import.specifier_range.start.character, + line_index: import.specifier_range.range.start.line, + column_index: import.specifier_range.range.start.character, }), text_info.loc_to_source_pos(LineAndColumnIndex { - line_index: import.specifier_range.end.line, - column_index: import.specifier_range.end.character, + line_index: import.specifier_range.range.end.line, + column_index: import.specifier_range.range.end.character, }), ); @@ -1277,7 +1274,7 @@ impl CodeActionCollection { if json!(i.kind) != json!("es") && json!(i.kind) != json!("tsType") { return None; } - if !i.specifier_range.includes(&position) { + if !i.specifier_range.includes(position) { return None; } @@ -1286,7 +1283,7 @@ impl CodeActionCollection { let referrer = document.specifier(); let referrer_kind = language_server .is_cjs_resolver - .get_doc_module_kind(document); + .get_doc_resolution_mode(document); let file_referrer = document.file_referrer(); let config_data = language_server .config diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs index 3ee8ae93e4..a77f3506fd 100644 --- a/cli/lsp/completions.rs +++ b/cli/lsp/completions.rs @@ -14,11 +14,10 @@ use super::resolver::LspResolver; use super::search::PackageSearchApi; use super::tsc; +use crate::graph_util::to_node_resolution_mode; use crate::jsr::JsrFetchResolver; use crate::util::path::is_importable_ext; use crate::util::path::relative_specifier; -use deno_graph::source::ResolutionMode; -use deno_graph::Range; use deno_runtime::deno_node::SUPPORTED_BUILTIN_NODE_MODULES; use deno_ast::LineAndColumnIndex; @@ -36,7 +35,8 @@ use deno_semver::package::PackageNv; use import_map::ImportMap; use indexmap::IndexSet; use lsp_types::CompletionList; -use node_resolver::NodeModuleKind; +use node_resolver::NodeResolutionKind; +use node_resolver::ResolutionMode; use once_cell::sync::Lazy; use regex::Regex; use tower_lsp::lsp_types as lsp; @@ -113,7 +113,7 @@ async fn check_auto_config_registry( /// which we want to ignore when replacing text. fn to_narrow_lsp_range( text_info: &SourceTextInfo, - range: &deno_graph::Range, + range: deno_graph::PositionRange, ) -> lsp::Range { let end_byte_index = text_info .loc_to_source_pos(LineAndColumnIndex { @@ -166,21 +166,21 @@ pub async fn get_import_completions( maybe_import_map: Option<&ImportMap>, ) -> Option { let document = documents.get(specifier)?; - let specifier_kind = is_cjs_resolver.get_doc_module_kind(&document); let file_referrer = document.file_referrer(); - let (text, _, range) = document.get_maybe_dependency(position)?; - let range = to_narrow_lsp_range(document.text_info(), &range); + let (text, _, graph_range) = document.get_maybe_dependency(position)?; + let resolution_mode = graph_range + .resolution_mode + .map(to_node_resolution_mode) + .unwrap_or_else(|| is_cjs_resolver.get_doc_resolution_mode(&document)); + let range = to_narrow_lsp_range(document.text_info(), graph_range.range); let resolved = resolver .as_cli_resolver(file_referrer) .resolve( &text, - &Range { - specifier: specifier.clone(), - start: deno_graph::Position::zeroed(), - end: deno_graph::Position::zeroed(), - }, - specifier_kind, - ResolutionMode::Execution, + specifier, + deno_graph::Position::zeroed(), + resolution_mode, + NodeResolutionKind::Execution, ) .ok(); if let Some(completion_list) = get_jsr_completions( @@ -206,7 +206,7 @@ pub async fn get_import_completions( // completions for import map specifiers Some(lsp::CompletionResponse::List(completion_list)) } else if let Some(completion_list) = - get_local_completions(specifier, specifier_kind, &text, &range, resolver) + get_local_completions(specifier, resolution_mode, &text, &range, resolver) { // completions for local relative modules Some(lsp::CompletionResponse::List(completion_list)) @@ -361,7 +361,7 @@ fn get_import_map_completions( /// Return local completions that are relative to the base specifier. fn get_local_completions( referrer: &ModuleSpecifier, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, text: &str, range: &lsp::Range, resolver: &LspResolver, @@ -374,13 +374,10 @@ fn get_local_completions( .as_cli_resolver(Some(referrer)) .resolve( parent, - &Range { - specifier: referrer.clone(), - start: deno_graph::Position::zeroed(), - end: deno_graph::Position::zeroed(), - }, - referrer_kind, - ResolutionMode::Execution, + referrer, + deno_graph::Position::zeroed(), + resolution_mode, + NodeResolutionKind::Execution, ) .ok()?; let resolved_parent_path = url_to_file_path(&resolved_parent).ok()?; @@ -831,7 +828,6 @@ mod tests { use crate::lsp::documents::LanguageId; use crate::lsp::search::tests::TestPackageSearchApi; use deno_core::resolve_url; - use deno_graph::Range; use pretty_assertions::assert_eq; use std::collections::HashMap; use test_util::TempDir; @@ -912,7 +908,7 @@ mod tests { ModuleSpecifier::from_file_path(file_c).expect("could not create"); let actual = get_local_completions( &specifier, - NodeModuleKind::Esm, + ResolutionMode::Import, "./", &lsp::Range { start: lsp::Position { @@ -1608,8 +1604,7 @@ mod tests { let text_info = SourceTextInfo::from_string(r#""te""#.to_string()); let range = to_narrow_lsp_range( &text_info, - &Range { - specifier: ModuleSpecifier::parse("https://deno.land").unwrap(), + deno_graph::PositionRange { start: deno_graph::Position { line: 0, character: 0, @@ -1632,8 +1627,7 @@ mod tests { let text_info = SourceTextInfo::from_string(r#""te"#.to_string()); let range = to_narrow_lsp_range( &text_info, - &Range { - specifier: ModuleSpecifier::parse("https://deno.land").unwrap(), + deno_graph::PositionRange { start: deno_graph::Position { line: 0, character: 0, diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs index e4fb82e58d..1967cdd7c9 100644 --- a/cli/lsp/diagnostics.rs +++ b/cli/lsp/diagnostics.rs @@ -45,7 +45,7 @@ use deno_graph::Resolution; use deno_graph::ResolutionError; use deno_graph::SpecifierError; use deno_resolver::sloppy_imports::SloppyImportsResolution; -use deno_resolver::sloppy_imports::SloppyImportsResolutionMode; +use deno_resolver::sloppy_imports::SloppyImportsResolutionKind; use deno_runtime::deno_fs; use deno_runtime::deno_node; use deno_runtime::tokio_util::create_basic_runtime; @@ -1266,7 +1266,7 @@ impl DenoDiagnostic { Self::NoLocal(specifier) => { let maybe_sloppy_resolution = CliSloppyImportsResolver::new( SloppyImportsCachedFs::new(Arc::new(deno_fs::RealFs)) - ).resolve(specifier, SloppyImportsResolutionMode::Execution); + ).resolve(specifier, SloppyImportsResolutionKind::Execution); let data = maybe_sloppy_resolution.as_ref().map(|res| { json!({ "specifier": specifier, @@ -1531,7 +1531,7 @@ fn diagnose_dependency( && !dependency.imports.iter().any(|i| { dependency .maybe_type - .includes(&i.specifier_range.start) + .includes(i.specifier_range.range.start) .is_some() }); diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index cdc25f3ac3..96332b4388 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -27,7 +27,6 @@ use deno_core::futures::future::Shared; use deno_core::futures::FutureExt; use deno_core::parking_lot::Mutex; use deno_core::ModuleSpecifier; -use deno_graph::source::ResolutionMode; use deno_graph::Resolution; use deno_path_util::url_to_file_path; use deno_runtime::deno_node; @@ -36,7 +35,8 @@ use deno_semver::npm::NpmPackageReqReference; use deno_semver::package::PackageReq; use indexmap::IndexMap; use indexmap::IndexSet; -use node_resolver::NodeModuleKind; +use node_resolver::NodeResolutionKind; +use node_resolver::ResolutionMode; use std::borrow::Cow; use std::collections::BTreeMap; use std::collections::HashMap; @@ -442,8 +442,8 @@ impl Document { config_data.and_then(|d| d.maybe_jsx_import_source_config()); let resolver = SingleReferrerGraphResolver { valid_referrer: &self.specifier, - referrer_kind: is_cjs_resolver - .get_lsp_referrer_kind(&self.specifier, self.is_script), + module_resolution_mode: is_cjs_resolver + .get_lsp_resolution_mode(&self.specifier, self.is_script), cli_resolver, jsx_import_source_config: jsx_import_source_config.as_ref(), }; @@ -768,7 +768,7 @@ impl Document { }; self.dependencies().iter().find_map(|(s, dep)| { dep - .includes(&position) + .includes(position) .map(|r| (s.clone(), dep.clone(), r.clone())) }) } @@ -809,15 +809,15 @@ fn resolve_media_type( MediaType::from_specifier(specifier) } -pub fn to_lsp_range(range: &deno_graph::Range) -> lsp::Range { +pub fn to_lsp_range(referrer: &deno_graph::Range) -> lsp::Range { lsp::Range { start: lsp::Position { - line: range.start.line as u32, - character: range.start.character as u32, + line: referrer.range.start.line as u32, + character: referrer.range.start.character as u32, }, end: lsp::Position { - line: range.end.line as u32, - character: range.end.character as u32, + line: referrer.range.end.line as u32, + character: referrer.range.end.character as u32, }, } } @@ -1271,7 +1271,8 @@ impl Documents { /// tsc when type checking. pub fn resolve( &self, - raw_specifiers: &[String], + // (is_cjs: bool, raw_specifier: String) + raw_specifiers: &[(bool, String)], referrer: &ModuleSpecifier, file_referrer: Option<&ModuleSpecifier>, ) -> Vec> { @@ -1281,11 +1282,12 @@ impl Documents { .and_then(|d| d.file_referrer()) .or(file_referrer); let dependencies = referrer_doc.as_ref().map(|d| d.dependencies()); - let referrer_kind = self - .is_cjs_resolver - .get_maybe_doc_module_kind(referrer, referrer_doc.as_deref()); let mut results = Vec::new(); - for raw_specifier in raw_specifiers { + for (is_cjs, raw_specifier) in raw_specifiers { + let resolution_mode = match is_cjs { + true => ResolutionMode::Require, + false => ResolutionMode::Import, + }; if raw_specifier.starts_with("asset:") { if let Ok(specifier) = ModuleSpecifier::parse(raw_specifier) { let media_type = MediaType::from_specifier(&specifier); @@ -1300,14 +1302,14 @@ impl Documents { results.push(self.resolve_dependency( specifier, referrer, - referrer_kind, + resolution_mode, file_referrer, )); } else if let Some(specifier) = dep.maybe_code.maybe_specifier() { results.push(self.resolve_dependency( specifier, referrer, - referrer_kind, + resolution_mode, file_referrer, )); } else { @@ -1316,19 +1318,16 @@ impl Documents { } else if let Ok(specifier) = self.resolver.as_cli_resolver(file_referrer).resolve( raw_specifier, - &deno_graph::Range { - specifier: referrer.clone(), - start: deno_graph::Position::zeroed(), - end: deno_graph::Position::zeroed(), - }, - referrer_kind, - ResolutionMode::Types, + referrer, + deno_graph::Position::zeroed(), + resolution_mode, + NodeResolutionKind::Types, ) { results.push(self.resolve_dependency( &specifier, referrer, - referrer_kind, + resolution_mode, file_referrer, )); } else { @@ -1477,27 +1476,24 @@ impl Documents { let type_specifier = jsx_config.default_types_specifier.as_ref()?; let code_specifier = jsx_config.default_specifier.as_ref()?; let cli_resolver = self.resolver.as_cli_resolver(Some(scope)); - let range = deno_graph::Range { - specifier: jsx_config.base_url.clone(), - start: deno_graph::Position::zeroed(), - end: deno_graph::Position::zeroed(), - }; let type_specifier = cli_resolver .resolve( type_specifier, - &range, + &jsx_config.base_url, + deno_graph::Position::zeroed(), // todo(dsherret): this is wrong because it doesn't consider CJS referrers - deno_package_json::NodeModuleKind::Esm, - ResolutionMode::Types, + ResolutionMode::Import, + NodeResolutionKind::Types, ) .ok()?; let code_specifier = cli_resolver .resolve( code_specifier, - &range, + &jsx_config.base_url, + deno_graph::Position::zeroed(), // todo(dsherret): this is wrong because it doesn't consider CJS referrers - deno_package_json::NodeModuleKind::Esm, - ResolutionMode::Execution, + ResolutionMode::Import, + NodeResolutionKind::Execution, ) .ok()?; dep_info @@ -1542,7 +1538,7 @@ impl Documents { &self, specifier: &ModuleSpecifier, referrer: &ModuleSpecifier, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, file_referrer: Option<&ModuleSpecifier>, ) -> Option<(ModuleSpecifier, MediaType)> { if let Some(module_name) = specifier.as_str().strip_prefix("node:") { @@ -1559,7 +1555,7 @@ impl Documents { let (s, mt) = self.resolver.npm_to_file_url( &npm_ref, referrer, - referrer_kind, + resolution_mode, file_referrer, )?; specifier = s; @@ -1571,7 +1567,7 @@ impl Documents { return Some((specifier, media_type)); }; if let Some(types) = doc.maybe_types_dependency().maybe_specifier() { - let specifier_kind = self.is_cjs_resolver.get_doc_module_kind(&doc); + let specifier_kind = self.is_cjs_resolver.get_doc_resolution_mode(&doc); self.resolve_dependency(types, &specifier, specifier_kind, file_referrer) } else { Some((doc.specifier().clone(), doc.media_type())) @@ -1688,7 +1684,7 @@ fn analyze_module( config_data.and_then(|d| d.maybe_jsx_import_source_config()); let resolver = SingleReferrerGraphResolver { valid_referrer: &valid_referrer, - referrer_kind: is_cjs_resolver.get_lsp_referrer_kind( + module_resolution_mode: is_cjs_resolver.get_lsp_resolution_mode( &specifier, Some(parsed_source.compute_is_script()), ), diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 9a9531eded..8fccfd0411 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -22,7 +22,8 @@ use deno_semver::jsr::JsrPackageReqReference; use indexmap::Equivalent; use indexmap::IndexSet; use log::error; -use node_resolver::NodeModuleKind; +use node_resolver::NodeResolutionKind; +use node_resolver::ResolutionMode; use serde::Deserialize; use serde_json::from_value; use std::collections::BTreeMap; @@ -993,13 +994,10 @@ impl Inner { let resolver = inner.resolver.as_cli_resolver(Some(&referrer)); let Ok(specifier) = resolver.resolve( &specifier, - &deno_graph::Range { - specifier: referrer.clone(), - start: deno_graph::Position::zeroed(), - end: deno_graph::Position::zeroed(), - }, - NodeModuleKind::Esm, - deno_graph::source::ResolutionMode::Types, + &referrer, + deno_graph::Position::zeroed(), + ResolutionMode::Import, + NodeResolutionKind::Types, ) else { return; }; @@ -1640,8 +1638,8 @@ impl Inner { .get_ts_diagnostics(&specifier, asset_or_doc.document_lsp_version()); let specifier_kind = asset_or_doc .document() - .map(|d| self.is_cjs_resolver.get_doc_module_kind(d)) - .unwrap_or(NodeModuleKind::Esm); + .map(|d| self.is_cjs_resolver.get_doc_resolution_mode(d)) + .unwrap_or(ResolutionMode::Import); let mut includes_no_cache = false; for diagnostic in &fixable_diagnostics { match diagnostic.source.as_deref() { @@ -1864,8 +1862,8 @@ impl Inner { maybe_asset_or_doc .as_ref() .and_then(|d| d.document()) - .map(|d| self.is_cjs_resolver.get_doc_module_kind(d)) - .unwrap_or(NodeModuleKind::Esm), + .map(|d| self.is_cjs_resolver.get_doc_resolution_mode(d)) + .unwrap_or(ResolutionMode::Import), &combined_code_actions.changes, self, ) @@ -1921,8 +1919,8 @@ impl Inner { &action_data.specifier, asset_or_doc .document() - .map(|d| self.is_cjs_resolver.get_doc_module_kind(d)) - .unwrap_or(NodeModuleKind::Esm), + .map(|d| self.is_cjs_resolver.get_doc_resolution_mode(d)) + .unwrap_or(ResolutionMode::Import), &refactor_edit_info.edits, self, ) diff --git a/cli/lsp/resolver.rs b/cli/lsp/resolver.rs index 4ede799227..49203c5bfd 100644 --- a/cli/lsp/resolver.rs +++ b/cli/lsp/resolver.rs @@ -9,7 +9,6 @@ use deno_config::workspace::PackageJsonDepResolution; use deno_config::workspace::WorkspaceResolver; use deno_core::parking_lot::Mutex; use deno_core::url::Url; -use deno_graph::source::ResolutionMode; use deno_graph::GraphImport; use deno_graph::ModuleSpecifier; use deno_graph::Range; @@ -30,8 +29,8 @@ use deno_semver::package::PackageReq; use indexmap::IndexMap; use node_resolver::errors::ClosestPkgJsonError; use node_resolver::InNpmPackageChecker; -use node_resolver::NodeModuleKind; -use node_resolver::NodeResolutionMode; +use node_resolver::NodeResolutionKind; +use node_resolver::ResolutionMode; use std::borrow::Cow; use std::collections::BTreeMap; use std::collections::BTreeSet; @@ -48,6 +47,8 @@ use crate::args::CliLockfile; use crate::args::NpmInstallDepsProvider; use crate::cache::DenoCacheEnvFsAdapter; use crate::factory::Deferred; +use crate::graph_util::to_node_resolution_kind; +use crate::graph_util::to_node_resolution_mode; use crate::graph_util::CliJsrUrlProvider; use crate::http_util::HttpClientProvider; use crate::lsp::config::Config; @@ -146,7 +147,7 @@ impl LspScopeResolver { .map(|(referrer, imports)| { let resolver = SingleReferrerGraphResolver { valid_referrer: &referrer, - referrer_kind: NodeModuleKind::Esm, + module_resolution_mode: ResolutionMode::Import, cli_resolver: &cli_resolver, jsx_import_source_config: maybe_jsx_import_source_config .as_ref(), @@ -180,16 +181,16 @@ impl LspScopeResolver { &req_ref, &referrer, // todo(dsherret): this is wrong because it doesn't consider CJS referrers - NodeModuleKind::Esm, - NodeResolutionMode::Types, + ResolutionMode::Import, + NodeResolutionKind::Types, ) .or_else(|_| { npm_pkg_req_resolver.resolve_req_reference( &req_ref, &referrer, // todo(dsherret): this is wrong because it doesn't consider CJS referrers - NodeModuleKind::Esm, - NodeResolutionMode::Execution, + ResolutionMode::Import, + NodeResolutionKind::Execution, ) }) .ok()?, @@ -424,7 +425,7 @@ impl LspResolver { &self, req_ref: &NpmPackageReqReference, referrer: &ModuleSpecifier, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, file_referrer: Option<&ModuleSpecifier>, ) -> Option<(ModuleSpecifier, MediaType)> { let resolver = self.get_scope_resolver(file_referrer); @@ -434,8 +435,8 @@ impl LspResolver { .resolve_req_reference( req_ref, referrer, - referrer_kind, - NodeResolutionMode::Types, + resolution_mode, + NodeResolutionKind::Types, ) .ok()?, ))) @@ -492,7 +493,7 @@ impl LspResolver { &self, specifier_text: &str, referrer: &ModuleSpecifier, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, ) -> bool { let resolver = self.get_scope_resolver(Some(referrer)); let Some(npm_pkg_req_resolver) = resolver.npm_pkg_req_resolver.as_ref() @@ -503,8 +504,8 @@ impl LspResolver { .resolve_if_for_npm_pkg( specifier_text, referrer, - referrer_kind, - NodeResolutionMode::Types, + resolution_mode, + NodeResolutionKind::Types, ) .ok() .flatten() @@ -868,34 +869,23 @@ impl LspIsCjsResolver { } } - pub fn get_maybe_doc_module_kind( - &self, - specifier: &ModuleSpecifier, - maybe_document: Option<&Document>, - ) -> NodeModuleKind { - self.get_lsp_referrer_kind( - specifier, - maybe_document.and_then(|d| d.is_script()), - ) + pub fn get_doc_resolution_mode(&self, document: &Document) -> ResolutionMode { + self.get_lsp_resolution_mode(document.specifier(), document.is_script()) } - pub fn get_doc_module_kind(&self, document: &Document) -> NodeModuleKind { - self.get_lsp_referrer_kind(document.specifier(), document.is_script()) - } - - pub fn get_lsp_referrer_kind( + pub fn get_lsp_resolution_mode( &self, specifier: &ModuleSpecifier, is_script: Option, - ) -> NodeModuleKind { - self.inner.get_lsp_referrer_kind(specifier, is_script) + ) -> ResolutionMode { + self.inner.get_lsp_resolution_mode(specifier, is_script) } } #[derive(Debug)] pub struct SingleReferrerGraphResolver<'a> { pub valid_referrer: &'a ModuleSpecifier, - pub referrer_kind: NodeModuleKind, + pub module_resolution_mode: ResolutionMode, pub cli_resolver: &'a CliResolver, pub jsx_import_source_config: Option<&'a JsxImportSourceConfig>, } @@ -924,16 +914,20 @@ impl<'a> deno_graph::source::Resolver for SingleReferrerGraphResolver<'a> { &self, specifier_text: &str, referrer_range: &Range, - mode: ResolutionMode, + resolution_kind: deno_graph::source::ResolutionKind, ) -> Result { // this resolver assumes it will only be used with a single referrer // with the provided referrer kind debug_assert_eq!(referrer_range.specifier, *self.valid_referrer); self.cli_resolver.resolve( specifier_text, - referrer_range, - self.referrer_kind, - mode, + &referrer_range.specifier, + referrer_range.range.start, + referrer_range + .resolution_mode + .map(to_node_resolution_mode) + .unwrap_or(self.module_resolution_mode), + to_node_resolution_kind(resolution_kind), ) } } diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index ae87a9914f..cf0107acfd 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -70,7 +70,7 @@ use indexmap::IndexMap; use indexmap::IndexSet; use lazy_regex::lazy_regex; use log::error; -use node_resolver::NodeModuleKind; +use node_resolver::ResolutionMode; use once_cell::sync::Lazy; use regex::Captures; use regex::Regex; @@ -4449,9 +4449,14 @@ fn op_load<'s>( version: state.script_version(&specifier), is_cjs: doc .document() - .map(|d| state.state_snapshot.is_cjs_resolver.get_doc_module_kind(d)) - .unwrap_or(NodeModuleKind::Esm) - == NodeModuleKind::Cjs, + .map(|d| { + state + .state_snapshot + .is_cjs_resolver + .get_doc_resolution_mode(d) + }) + .unwrap_or(ResolutionMode::Import) + == ResolutionMode::Require, }) }; let serialized = serde_v8::to_v8(scope, maybe_load_response)?; @@ -4479,17 +4484,9 @@ fn op_release( fn op_resolve( state: &mut OpState, #[string] base: String, - is_base_cjs: bool, - #[serde] specifiers: Vec, + #[serde] specifiers: Vec<(bool, String)>, ) -> Result>, AnyError> { - op_resolve_inner( - state, - ResolveArgs { - base, - is_base_cjs, - specifiers, - }, - ) + op_resolve_inner(state, ResolveArgs { base, specifiers }) } struct TscRequestArray { @@ -4695,7 +4692,7 @@ fn op_script_names(state: &mut OpState) -> ScriptNames { state .state_snapshot .is_cjs_resolver - .get_doc_module_kind(doc), + .get_doc_resolution_mode(doc), doc.file_referrer(), )?; let types_doc = documents.get_or_load(&types, doc.file_referrer())?; @@ -6430,8 +6427,7 @@ mod tests { &mut state, ResolveArgs { base: temp_dir.url().join("a.ts").unwrap().to_string(), - is_base_cjs: false, - specifiers: vec!["./b.ts".to_string()], + specifiers: vec![(false, "./b.ts".to_string())], }, ) .unwrap(); diff --git a/cli/module_loader.rs b/cli/module_loader.rs index 035ae4264b..3d2dfb2a66 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -57,9 +57,7 @@ use deno_core::ModuleSourceCode; use deno_core::ModuleSpecifier; use deno_core::ModuleType; use deno_core::RequestedModuleType; -use deno_core::ResolutionKind; use deno_core::SourceCodeCacheInfo; -use deno_graph::source::ResolutionMode; use deno_graph::GraphKind; use deno_graph::JsModule; use deno_graph::JsonModule; @@ -76,7 +74,8 @@ use deno_runtime::deno_permissions::PermissionsContainer; use deno_semver::npm::NpmPackageReqReference; use node_resolver::errors::ClosestPkgJsonError; use node_resolver::InNpmPackageChecker; -use node_resolver::NodeResolutionMode; +use node_resolver::NodeResolutionKind; +use node_resolver::ResolutionMode; pub struct ModuleLoadPreparer { options: Arc, @@ -498,13 +497,11 @@ impl } Resolution::None => Cow::Owned(self.shared.resolver.resolve( raw_specifier, - &deno_graph::Range { - specifier: referrer.clone(), - start: deno_graph::Position::zeroed(), - end: deno_graph::Position::zeroed(), - }, - self.shared.cjs_tracker.get_referrer_kind(referrer), - ResolutionMode::Execution, + referrer, + deno_graph::Position::zeroed(), + // if we're here, that means it's resolving a dynamic import + ResolutionMode::Import, + NodeResolutionKind::Execution, )?), }; @@ -517,8 +514,8 @@ impl .resolve_req_reference( &reference, referrer, - self.shared.cjs_tracker.get_referrer_kind(referrer), - NodeResolutionMode::Execution, + ResolutionMode::Import, + NodeResolutionKind::Execution, ) .map_err(AnyError::from); } @@ -539,8 +536,8 @@ impl &package_folder, module.nv_reference.sub_path(), Some(referrer), - self.shared.cjs_tracker.get_referrer_kind(referrer), - NodeResolutionMode::Execution, + ResolutionMode::Import, + NodeResolutionKind::Execution, ) .with_context(|| { format!("Could not resolve '{}'.", module.nv_reference) @@ -806,7 +803,7 @@ impl ModuleLoader &self, specifier: &str, referrer: &str, - _kind: ResolutionKind, + _kind: deno_core::ResolutionKind, ) -> Result { fn ensure_not_jsr_non_jsr_remote_import( specifier: &ModuleSpecifier, diff --git a/cli/resolver.rs b/cli/resolver.rs index a2dd47430f..7f6dc0b1ac 100644 --- a/cli/resolver.rs +++ b/cli/resolver.rs @@ -12,7 +12,6 @@ use deno_core::error::AnyError; use deno_core::url::Url; use deno_core::ModuleSourceCode; use deno_core::ModuleSpecifier; -use deno_graph::source::ResolutionMode; use deno_graph::source::ResolveError; use deno_graph::source::UnknownBuiltInNodeModuleError; use deno_graph::NpmLoadError; @@ -25,8 +24,8 @@ use deno_runtime::deno_fs::FileSystem; use deno_runtime::deno_node::is_builtin_node_module; use deno_runtime::deno_node::DenoFsNodeResolverEnv; use deno_semver::package::PackageReq; -use node_resolver::NodeModuleKind; -use node_resolver::NodeResolutionMode; +use node_resolver::NodeResolutionKind; +use node_resolver::ResolutionMode; use std::borrow::Cow; use std::path::Path; use std::path::PathBuf; @@ -247,25 +246,14 @@ impl CliResolver { pub fn resolve( &self, raw_specifier: &str, - referrer_range: &deno_graph::Range, - referrer_kind: NodeModuleKind, - mode: ResolutionMode, + referrer: &ModuleSpecifier, + referrer_range_start: deno_graph::Position, + resolution_mode: ResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { - fn to_node_mode(mode: ResolutionMode) -> NodeResolutionMode { - match mode { - ResolutionMode::Execution => NodeResolutionMode::Execution, - ResolutionMode::Types => NodeResolutionMode::Types, - } - } - let resolution = self .deno_resolver - .resolve( - raw_specifier, - &referrer_range.specifier, - referrer_kind, - to_node_mode(mode), - ) + .resolve(raw_specifier, referrer, resolution_mode, resolution_kind) .map_err(|err| match err.into_kind() { deno_resolver::DenoResolveErrorKind::MappedResolution( mapped_resolution_error, @@ -291,10 +279,11 @@ impl CliResolver { } => { if self.warned_pkgs.insert(reference.req().clone()) { log::warn!( - "{} {}\n at {}", + "{} {}\n at {}:{}", colors::yellow("Warning"), diagnostic, - referrer_range + referrer, + referrer_range_start, ); } } @@ -335,13 +324,10 @@ impl<'a> deno_graph::source::NpmResolver for WorkerCliNpmGraphResolver<'a> { module_name: &str, range: &deno_graph::Range, ) { - let deno_graph::Range { - start, specifier, .. - } = range; - let line = start.line + 1; - let column = start.character + 1; + let start = range.range.start; + let specifier = &range.specifier; if !*DENO_DISABLE_PEDANTIC_NODE_WARNINGS { - log::warn!("{} Resolving \"{module_name}\" as \"node:{module_name}\" at {specifier}:{line}:{column}. If you want to use a built-in Node module, add a \"node:\" prefix.", colors::yellow("Warning")) + log::warn!("{} Resolving \"{module_name}\" as \"node:{module_name}\" at {specifier}:{start}. If you want to use a built-in Node module, add a \"node:\" prefix.", colors::yellow("Warning")) } } diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index 27b03fec63..16aa4cde2b 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -50,8 +50,8 @@ use deno_semver::npm::NpmPackageReqReference; use import_map::parse_from_json; use node_resolver::analyze::NodeCodeTranslator; use node_resolver::errors::ClosestPkgJsonError; -use node_resolver::NodeModuleKind; -use node_resolver::NodeResolutionMode; +use node_resolver::NodeResolutionKind; +use node_resolver::ResolutionMode; use serialization::DenoCompileModuleSource; use std::borrow::Cow; use std::rc::Rc; @@ -193,9 +193,9 @@ impl ModuleLoader for EmbeddedModuleLoader { .cjs_tracker .is_maybe_cjs(&referrer, MediaType::from_specifier(&referrer))? { - NodeModuleKind::Cjs + ResolutionMode::Require } else { - NodeModuleKind::Esm + ResolutionMode::Import }; if self.shared.node_resolver.in_npm_package(&referrer) { @@ -207,7 +207,7 @@ impl ModuleLoader for EmbeddedModuleLoader { raw_specifier, &referrer, referrer_kind, - NodeResolutionMode::Execution, + NodeResolutionKind::Execution, )? .into_url(), ); @@ -235,7 +235,7 @@ impl ModuleLoader for EmbeddedModuleLoader { sub_path.as_deref(), Some(&referrer), referrer_kind, - NodeResolutionMode::Execution, + NodeResolutionKind::Execution, )?, ), Ok(MappedResolution::PackageJson { @@ -252,7 +252,7 @@ impl ModuleLoader for EmbeddedModuleLoader { sub_path.as_deref(), &referrer, referrer_kind, - NodeResolutionMode::Execution, + NodeResolutionKind::Execution, ) .map_err(AnyError::from), PackageJsonDepValue::Workspace(version_req) => { @@ -272,7 +272,7 @@ impl ModuleLoader for EmbeddedModuleLoader { sub_path.as_deref(), Some(&referrer), referrer_kind, - NodeResolutionMode::Execution, + NodeResolutionKind::Execution, )?, ) } @@ -286,7 +286,7 @@ impl ModuleLoader for EmbeddedModuleLoader { &reference, &referrer, referrer_kind, - NodeResolutionMode::Execution, + NodeResolutionKind::Execution, )?); } @@ -313,7 +313,7 @@ impl ModuleLoader for EmbeddedModuleLoader { raw_specifier, &referrer, referrer_kind, - NodeResolutionMode::Execution, + NodeResolutionKind::Execution, )?; if let Some(res) = maybe_res { return Ok(res.into_url()); diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index 4487d70fd7..197596167f 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -427,33 +427,7 @@ fn generate_docs_directory( symbol_redirect_map, default_symbol_map, markdown_renderer: deno_doc::html::comrak::create_renderer( - None, - Some(Box::new(|ammonia| { - ammonia.add_allowed_classes( - "code", - &[ - "language-ts", - "language-tsx", - "language-typescript", - "language-js", - "language-jsx", - "language-javascript", - "language-bash", - "language-shell", - "language-md", - "language-markdown", - "language-rs", - "language-rust", - "language-html", - "language-xml", - "language-css", - "language-json", - "language-regex", - "language-svg", - ], - ); - })), - None, + None, None, None, ), markdown_stripper: Rc::new(deno_doc::html::comrak::strip), head_inject: Some(Rc::new(|root| { diff --git a/cli/tools/info.rs b/cli/tools/info.rs index c3c37f0268..fcc9fdcfa1 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -235,22 +235,31 @@ fn add_npm_packages_to_json( .get_mut("dependencies") .and_then(|d| d.as_array_mut()); if let Some(dependencies) = dependencies { - for dep in dependencies.iter_mut() { - if let serde_json::Value::Object(dep) = dep { - let specifier = dep.get("specifier").and_then(|s| s.as_str()); - if let Some(specifier) = specifier { - if let Ok(npm_ref) = NpmPackageReqReference::from_str(specifier) { - if let Ok(pkg) = - snapshot.resolve_pkg_from_pkg_req(npm_ref.req()) - { - dep.insert( - "npmPackage".to_string(), - pkg.id.as_serialized().into(), - ); - } + for dep in dependencies.iter_mut().flat_map(|d| d.as_object_mut()) { + if let Some(specifier) = dep.get("specifier").and_then(|s| s.as_str()) + { + if let Ok(npm_ref) = NpmPackageReqReference::from_str(specifier) { + if let Ok(pkg) = snapshot.resolve_pkg_from_pkg_req(npm_ref.req()) + { + dep.insert( + "npmPackage".to_string(), + pkg.id.as_serialized().into(), + ); } } } + + // don't show this in the output unless someone needs it + if let Some(code) = + dep.get_mut("code").and_then(|c| c.as_object_mut()) + { + code.remove("resolutionMode"); + } + if let Some(types) = + dep.get_mut("types").and_then(|c| c.as_object_mut()) + { + types.remove("resolutionMode"); + } } } } diff --git a/cli/tools/lint/rules/no_sloppy_imports.rs b/cli/tools/lint/rules/no_sloppy_imports.rs index 94bf9a7c67..1bf7eddf6e 100644 --- a/cli/tools/lint/rules/no_sloppy_imports.rs +++ b/cli/tools/lint/rules/no_sloppy_imports.rs @@ -8,7 +8,7 @@ use std::sync::Arc; use deno_ast::SourceRange; use deno_config::workspace::WorkspaceResolver; use deno_core::anyhow::anyhow; -use deno_graph::source::ResolutionMode; +use deno_graph::source::ResolutionKind; use deno_graph::source::ResolveError; use deno_graph::Range; use deno_lint::diagnostic::LintDiagnosticDetails; @@ -17,7 +17,7 @@ use deno_lint::diagnostic::LintFix; use deno_lint::diagnostic::LintFixChange; use deno_lint::rules::LintRule; use deno_resolver::sloppy_imports::SloppyImportsResolution; -use deno_resolver::sloppy_imports::SloppyImportsResolutionMode; +use deno_resolver::sloppy_imports::SloppyImportsResolutionKind; use text_lines::LineAndColumnIndex; use crate::graph_util::CliJsrUrlProvider; @@ -101,16 +101,16 @@ impl LintRule for NoSloppyImportsRule { maybe_npm_resolver: None, }); - for (range, sloppy_import) in resolver.captures.borrow_mut().drain() { + for (referrer, sloppy_import) in resolver.captures.borrow_mut().drain() { let start_range = context.text_info().loc_to_source_pos(LineAndColumnIndex { - line_index: range.start.line, - column_index: range.start.character, + line_index: referrer.range.start.line, + column_index: referrer.range.start.character, }); let end_range = context.text_info().loc_to_source_pos(LineAndColumnIndex { - line_index: range.end.line, - column_index: range.end.character, + line_index: referrer.range.end.line, + column_index: referrer.range.end.character, }); let source_range = SourceRange::new(start_range, end_range); context.add_diagnostic_details( @@ -183,7 +183,7 @@ impl<'a> deno_graph::source::Resolver for SloppyImportCaptureResolver<'a> { &self, specifier_text: &str, referrer_range: &Range, - mode: ResolutionMode, + resolution_kind: ResolutionKind, ) -> Result { let resolution = self .workspace_resolver @@ -198,9 +198,9 @@ impl<'a> deno_graph::source::Resolver for SloppyImportCaptureResolver<'a> { specifier, .. } => match self.sloppy_imports_resolver.resolve( &specifier, - match mode { - ResolutionMode::Execution => SloppyImportsResolutionMode::Execution, - ResolutionMode::Types => SloppyImportsResolutionMode::Types, + match resolution_kind { + ResolutionKind::Execution => SloppyImportsResolutionKind::Execution, + ResolutionKind::Types => SloppyImportsResolutionKind::Types, }, ) { Some(res) => { diff --git a/cli/tools/registry/diagnostics.rs b/cli/tools/registry/diagnostics.rs index 733a78ddac..f2b630d782 100644 --- a/cli/tools/registry/diagnostics.rs +++ b/cli/tools/registry/diagnostics.rs @@ -234,8 +234,8 @@ impl Diagnostic for PublishDiagnostic { specifier: Cow::Borrowed(&referrer.specifier), text_info: Cow::Borrowed(text_info), source_pos: DiagnosticSourcePos::LineAndCol { - line: referrer.start.line, - column: referrer.start.character, + line: referrer.range.start.line, + column: referrer.range.start.character, }, } } @@ -300,7 +300,7 @@ impl Diagnostic for PublishDiagnostic { text_info: &'a SourceTextInfo, referrer: &'a deno_graph::Range, ) -> Option> { - if referrer.start.line == 0 && referrer.start.character == 0 { + if referrer.range.start.line == 0 && referrer.range.start.character == 0 { return None; // no range, probably a jsxImportSource import } @@ -310,12 +310,12 @@ impl Diagnostic for PublishDiagnostic { style: DiagnosticSnippetHighlightStyle::Error, range: DiagnosticSourceRange { start: DiagnosticSourcePos::LineAndCol { - line: referrer.start.line, - column: referrer.start.character, + line: referrer.range.start.line, + column: referrer.range.start.character, }, end: DiagnosticSourcePos::LineAndCol { - line: referrer.end.line, - column: referrer.end.character, + line: referrer.range.end.line, + column: referrer.range.end.character, }, }, description: Some("the specifier".into()), diff --git a/cli/tools/registry/unfurl.rs b/cli/tools/registry/unfurl.rs index 5ec726a640..90343ac656 100644 --- a/cli/tools/registry/unfurl.rs +++ b/cli/tools/registry/unfurl.rs @@ -12,7 +12,7 @@ use deno_graph::DynamicTemplatePart; use deno_graph::ParserModuleAnalyzer; use deno_graph::TypeScriptReference; use deno_package_json::PackageJsonDepValue; -use deno_resolver::sloppy_imports::SloppyImportsResolutionMode; +use deno_resolver::sloppy_imports::SloppyImportsResolutionKind; use deno_runtime::deno_node::is_builtin_node_module; use crate::resolver::CliSloppyImportsResolver; @@ -180,7 +180,7 @@ impl SpecifierUnfurler { let resolved = if let Some(sloppy_imports_resolver) = &self.sloppy_imports_resolver { sloppy_imports_resolver - .resolve(&resolved, SloppyImportsResolutionMode::Execution) + .resolve(&resolved, SloppyImportsResolutionKind::Execution) .map(|res| res.into_specifier()) .unwrap_or(resolved) } else { @@ -319,8 +319,8 @@ impl SpecifierUnfurler { } for ts_ref in &module_info.ts_references { let specifier_with_range = match ts_ref { - TypeScriptReference::Path(range) => range, - TypeScriptReference::Types(range) => range, + TypeScriptReference::Path(s) => s, + TypeScriptReference::Types { specifier, .. } => specifier, }; analyze_specifier( &specifier_with_range.text, @@ -328,10 +328,10 @@ impl SpecifierUnfurler { &mut text_changes, ); } - for specifier_with_range in &module_info.jsdoc_imports { + for jsdoc in &module_info.jsdoc_imports { analyze_specifier( - &specifier_with_range.text, - &specifier_with_range.range, + &jsdoc.specifier.text, + &jsdoc.specifier.range, &mut text_changes, ); } diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index 8e05c4abbc..26e1eeac2f 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -43,13 +43,13 @@ use deno_core::unsync::spawn; use deno_core::url::Url; use deno_core::LocalInspectorSession; use deno_core::PollEventLoopOptions; -use deno_graph::source::ResolutionMode; use deno_graph::Position; use deno_graph::PositionRange; use deno_graph::SpecifierWithRange; use deno_runtime::worker::MainWorker; use deno_semver::npm::NpmPackageReqReference; -use node_resolver::NodeModuleKind; +use node_resolver::NodeResolutionKind; +use node_resolver::ResolutionMode; use once_cell::sync::Lazy; use regex::Match; use regex::Regex; @@ -701,11 +701,6 @@ impl ReplSession { let mut collector = ImportCollector::new(); program.visit_with(&mut collector); - let referrer_range = deno_graph::Range { - specifier: self.referrer.clone(), - start: deno_graph::Position::zeroed(), - end: deno_graph::Position::zeroed(), - }; let resolved_imports = collector .imports .iter() @@ -714,9 +709,10 @@ impl ReplSession { .resolver .resolve( i, - &referrer_range, - NodeModuleKind::Esm, - ResolutionMode::Execution, + &self.referrer, + deno_graph::Position::zeroed(), + ResolutionMode::Import, + NodeResolutionKind::Execution, ) .ok() .or_else(|| ModuleSpecifier::parse(i).ok()) diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index 93b9e92d89..7e8a407cf9 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -681,14 +681,18 @@ delete Object.prototype.__proto__; getNewLine() { return "\n"; }, - resolveTypeReferenceDirectives( - typeDirectiveNames, + resolveTypeReferenceDirectiveReferences( + typeDirectiveReferences, containingFilePath, redirectedReference, options, - containingFileMode, + containingSourceFile, + _reusedNames, ) { - return typeDirectiveNames.map((arg) => { + const isCjs = + containingSourceFile?.impliedNodeFormat === ts.ModuleKind.CommonJS; + /** @type {Array} */ + const result = typeDirectiveReferences.map((arg) => { /** @type {ts.FileReference} */ const fileReference = typeof arg === "string" ? { @@ -701,16 +705,28 @@ delete Object.prototype.__proto__; /** @type {[string, ts.Extension] | undefined} */ const resolved = ops.op_resolve( containingFilePath, - containingFileMode === ts.ModuleKind.CommonJS, - [fileReference.fileName], + [ + [ + fileReference.resolutionMode == null + ? isCjs + : fileReference.resolutionMode === ts.ModuleKind.CommonJS, + fileReference.fileName, + ], + ], )?.[0]; if (resolved) { return { - primary: true, - resolvedFileName: resolved[0], + resolvedTypeReferenceDirective: { + primary: true, + resolvedFileName: resolved[0], + // todo(dsherret): we should probably be setting this + isExternalLibraryImport: undefined, + }, }; } else { - return undefined; + return { + resolvedTypeReferenceDirective: undefined, + }; } } else { return ts.resolveTypeReferenceDirective( @@ -720,41 +736,56 @@ delete Object.prototype.__proto__; host, redirectedReference, undefined, - containingFileMode ?? fileReference.resolutionMode, - ).resolvedTypeReferenceDirective; + containingSourceFile?.impliedNodeFormat ?? + fileReference.resolutionMode, + ); } }); + return result; }, - resolveModuleNames( - specifiers, + resolveModuleNameLiterals( + moduleLiterals, base, - _reusedNames, _redirectedReference, - _options, + compilerOptions, containingSourceFile, + _reusedNames, ) { + const specifiers = moduleLiterals.map((literal) => [ + ts.getModeForUsageLocation( + containingSourceFile, + literal, + compilerOptions, + ) === ts.ModuleKind.CommonJS, + literal.text, + ]); if (logDebug) { debug(`host.resolveModuleNames()`); debug(` base: ${base}`); - debug(` specifiers: ${specifiers.join(", ")}`); + debug(` specifiers: ${specifiers.map((s) => s[1]).join(", ")}`); } /** @type {Array<[string, ts.Extension] | undefined>} */ const resolved = ops.op_resolve( base, - containingSourceFile?.impliedNodeFormat === ts.ModuleKind.CommonJS, specifiers, ); if (resolved) { + /** @type {Array} */ const result = resolved.map((item) => { if (item) { const [resolvedFileName, extension] = item; return { - resolvedFileName, - extension, - isExternalLibraryImport: false, + resolvedModule: { + resolvedFileName, + extension, + // todo(dsherret): we should probably be setting this + isExternalLibraryImport: false, + }, }; } - return undefined; + return { + resolvedModule: undefined, + }; }); result.length = specifiers.length; return result; diff --git a/cli/tsc/mod.rs b/cli/tsc/mod.rs index 976d407c15..50127b093d 100644 --- a/cli/tsc/mod.rs +++ b/cli/tsc/mod.rs @@ -41,8 +41,8 @@ use deno_semver::npm::NpmPackageReqReference; use node_resolver::errors::NodeJsErrorCode; use node_resolver::errors::NodeJsErrorCoded; use node_resolver::errors::PackageSubpathResolveError; -use node_resolver::NodeModuleKind; -use node_resolver::NodeResolutionMode; +use node_resolver::NodeResolutionKind; +use node_resolver::ResolutionMode; use once_cell::sync::Lazy; use std::borrow::Cow; use std::collections::HashMap; @@ -703,10 +703,9 @@ pub struct ResolveArgs { /// The base specifier that the supplied specifier strings should be resolved /// relative to. pub base: String, - /// If the base is cjs. - pub is_base_cjs: bool, /// A list of specifiers that should be resolved. - pub specifiers: Vec, + /// (is_cjs: bool, raw_specifier: String) + pub specifiers: Vec<(bool, String)>, } #[op2] @@ -714,17 +713,9 @@ pub struct ResolveArgs { fn op_resolve( state: &mut OpState, #[string] base: String, - is_base_cjs: bool, - #[serde] specifiers: Vec, + #[serde] specifiers: Vec<(bool, String)>, ) -> Result, AnyError> { - op_resolve_inner( - state, - ResolveArgs { - base, - is_base_cjs, - specifiers, - }, - ) + op_resolve_inner(state, ResolveArgs { base, specifiers }) } #[inline] @@ -735,11 +726,6 @@ fn op_resolve_inner( let state = state.borrow_mut::(); let mut resolved: Vec<(String, &'static str)> = Vec::with_capacity(args.specifiers.len()); - let referrer_kind = if args.is_base_cjs { - NodeModuleKind::Cjs - } else { - NodeModuleKind::Esm - }; let referrer = if let Some(remapped_specifier) = state.remapped_specifiers.get(&args.base) { @@ -752,7 +738,7 @@ fn op_resolve_inner( )? }; let referrer_module = state.graph.get(&referrer); - for specifier in args.specifiers { + for (is_cjs, specifier) in args.specifiers { if specifier.starts_with("node:") { resolved.push(( MISSING_DEPENDENCY_SPECIFIER.to_string(), @@ -771,13 +757,20 @@ fn op_resolve_inner( .and_then(|m| m.js()) .and_then(|m| m.dependencies_prefer_fast_check().get(&specifier)) .and_then(|d| d.maybe_type.ok().or_else(|| d.maybe_code.ok())); + let resolution_mode = if is_cjs { + ResolutionMode::Require + } else { + ResolutionMode::Import + }; let maybe_result = match resolved_dep { Some(ResolutionResolved { specifier, .. }) => { resolve_graph_specifier_types( specifier, &referrer, - referrer_kind, + // we could get this from the resolved dep, but for now assume + // the value resolved in TypeScript is better + resolution_mode, state, )? } @@ -785,7 +778,7 @@ fn op_resolve_inner( match resolve_non_graph_specifier_types( &specifier, &referrer, - referrer_kind, + resolution_mode, state, ) { Ok(maybe_result) => maybe_result, @@ -852,7 +845,7 @@ fn op_resolve_inner( fn resolve_graph_specifier_types( specifier: &ModuleSpecifier, referrer: &ModuleSpecifier, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, state: &State, ) -> Result, AnyError> { let graph = &state.graph; @@ -908,8 +901,8 @@ fn resolve_graph_specifier_types( &package_folder, module.nv_reference.sub_path(), Some(referrer), - referrer_kind, - NodeResolutionMode::Types, + resolution_mode, + NodeResolutionKind::Types, ); let maybe_url = match res_result { Ok(url) => Some(url), @@ -949,7 +942,7 @@ enum ResolveNonGraphSpecifierTypesError { fn resolve_non_graph_specifier_types( raw_specifier: &str, referrer: &ModuleSpecifier, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, state: &State, ) -> Result< Option<(ModuleSpecifier, MediaType)>, @@ -967,8 +960,8 @@ fn resolve_non_graph_specifier_types( .resolve( raw_specifier, referrer, - referrer_kind, - NodeResolutionMode::Types, + resolution_mode, + NodeResolutionKind::Types, ) .ok() .map(|res| res.into_url()), @@ -976,7 +969,7 @@ fn resolve_non_graph_specifier_types( } else if let Ok(npm_req_ref) = NpmPackageReqReference::from_str(raw_specifier) { - debug_assert_eq!(referrer_kind, NodeModuleKind::Esm); + debug_assert_eq!(resolution_mode, ResolutionMode::Import); // todo(dsherret): add support for injecting this in the graph so // we don't need this special code here. // This could occur when resolving npm:@types/node when it is @@ -988,8 +981,8 @@ fn resolve_non_graph_specifier_types( &package_folder, npm_req_ref.sub_path(), Some(referrer), - referrer_kind, - NodeResolutionMode::Types, + resolution_mode, + NodeResolutionKind::Types, ); let maybe_url = match res_result { Ok(url) => Some(url), @@ -1388,8 +1381,7 @@ mod tests { &mut state, ResolveArgs { base: "https://deno.land/x/a.ts".to_string(), - is_base_cjs: false, - specifiers: vec!["./b.ts".to_string()], + specifiers: vec![(false, "./b.ts".to_string())], }, ) .expect("should have invoked op"); @@ -1408,8 +1400,7 @@ mod tests { &mut state, ResolveArgs { base: "https://deno.land/x/a.ts".to_string(), - is_base_cjs: false, - specifiers: vec!["./bad.ts".to_string()], + specifiers: vec![(false, "./bad.ts".to_string())], }, ) .expect("should have not errored"); diff --git a/cli/worker.rs b/cli/worker.rs index e79ed61422..161d8bcc21 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -44,8 +44,8 @@ use deno_runtime::WorkerLogLevel; use deno_semver::npm::NpmPackageReqReference; use deno_telemetry::OtelConfig; use deno_terminal::colors; -use node_resolver::NodeModuleKind; -use node_resolver::NodeResolutionMode; +use node_resolver::NodeResolutionKind; +use node_resolver::ResolutionMode; use tokio::select; use crate::args::CliLockfile; @@ -698,8 +698,8 @@ impl CliMainWorkerFactory { package_folder, sub_path, /* referrer */ None, - NodeModuleKind::Esm, - NodeResolutionMode::Execution, + ResolutionMode::Import, + NodeResolutionKind::Execution, )?; if specifier .to_file_path() diff --git a/ext/node/ops/require.rs b/ext/node/ops/require.rs index f8de07a3be..64dc4423ae 100644 --- a/ext/node/ops/require.rs +++ b/ext/node/ops/require.rs @@ -8,13 +8,13 @@ use deno_core::v8; use deno_core::JsRuntimeInspector; use deno_core::OpState; use deno_fs::FileSystemRc; -use deno_package_json::NodeModuleKind; use deno_package_json::PackageJsonRc; use deno_path_util::normalize_path; use deno_path_util::url_from_file_path; use deno_path_util::url_to_file_path; use node_resolver::errors::ClosestPkgJsonError; -use node_resolver::NodeResolutionMode; +use node_resolver::NodeResolutionKind; +use node_resolver::ResolutionMode; use node_resolver::REQUIRE_CONDITIONS; use std::borrow::Cow; use std::cell::RefCell; @@ -462,9 +462,9 @@ where &expansion, exports, Some(&referrer), - NodeModuleKind::Cjs, + ResolutionMode::Require, REQUIRE_CONDITIONS, - NodeResolutionMode::Execution, + NodeResolutionKind::Execution, )?; Ok(Some(if r.scheme() == "file" { url_to_file_path_string(&r)? @@ -559,9 +559,9 @@ where &format!(".{expansion}"), exports, referrer.as_ref(), - NodeModuleKind::Cjs, + ResolutionMode::Require, REQUIRE_CONDITIONS, - NodeResolutionMode::Execution, + NodeResolutionKind::Execution, )?; Ok(Some(if r.scheme() == "file" { url_to_file_path_string(&r)? @@ -630,10 +630,10 @@ where let url = node_resolver.package_imports_resolve( &request, Some(&referrer_url), - NodeModuleKind::Cjs, + ResolutionMode::Require, Some(&pkg), REQUIRE_CONDITIONS, - NodeResolutionMode::Execution, + NodeResolutionKind::Execution, )?; Ok(Some(url_to_file_path_string(&url)?)) } else { diff --git a/resolvers/deno/cjs.rs b/resolvers/deno/cjs.rs index dbcbd8b6bf..e322036dfe 100644 --- a/resolvers/deno/cjs.rs +++ b/resolvers/deno/cjs.rs @@ -7,8 +7,8 @@ use deno_media_type::MediaType; use node_resolver::env::NodeResolverEnv; use node_resolver::errors::ClosestPkgJsonError; use node_resolver::InNpmPackageChecker; -use node_resolver::NodeModuleKind; use node_resolver::PackageJsonResolver; +use node_resolver::ResolutionMode; use url::Url; /// Keeps track of what module specifiers were resolved as CJS. @@ -19,7 +19,7 @@ use url::Url; #[derive(Debug)] pub struct CjsTracker { is_cjs_resolver: IsCjsResolver, - known: DashMap, + known: DashMap, } impl CjsTracker { @@ -70,42 +70,42 @@ impl CjsTracker { is_script: Option, ) -> Result { let kind = match self - .get_known_kind_with_is_script(specifier, media_type, is_script) + .get_known_mode_with_is_script(specifier, media_type, is_script) { Some(kind) => kind, None => self.is_cjs_resolver.check_based_on_pkg_json(specifier)?, }; - Ok(kind == NodeModuleKind::Cjs) + Ok(kind == ResolutionMode::Require) } /// Gets the referrer for the specified module specifier. /// /// Generally the referrer should already be tracked by calling /// `is_cjs_with_known_is_script` before calling this method. - pub fn get_referrer_kind(&self, specifier: &Url) -> NodeModuleKind { + pub fn get_referrer_kind(&self, specifier: &Url) -> ResolutionMode { if specifier.scheme() != "file" { - return NodeModuleKind::Esm; + return ResolutionMode::Import; } self - .get_known_kind(specifier, MediaType::from_specifier(specifier)) - .unwrap_or(NodeModuleKind::Esm) + .get_known_mode(specifier, MediaType::from_specifier(specifier)) + .unwrap_or(ResolutionMode::Import) } - fn get_known_kind( + fn get_known_mode( &self, specifier: &Url, media_type: MediaType, - ) -> Option { - self.get_known_kind_with_is_script(specifier, media_type, None) + ) -> Option { + self.get_known_mode_with_is_script(specifier, media_type, None) } - fn get_known_kind_with_is_script( + fn get_known_mode_with_is_script( &self, specifier: &Url, media_type: MediaType, is_script: Option, - ) -> Option { - self.is_cjs_resolver.get_known_kind_with_is_script( + ) -> Option { + self.is_cjs_resolver.get_known_mode_with_is_script( specifier, media_type, is_script, @@ -141,25 +141,25 @@ impl IsCjsResolver { } } - /// Gets the referrer kind for a script in the LSP. - pub fn get_lsp_referrer_kind( + /// Gets the resolution mode for a module in the LSP. + pub fn get_lsp_resolution_mode( &self, specifier: &Url, is_script: Option, - ) -> NodeModuleKind { + ) -> ResolutionMode { if specifier.scheme() != "file" { - return NodeModuleKind::Esm; + return ResolutionMode::Import; } match MediaType::from_specifier(specifier) { - MediaType::Mts | MediaType::Mjs | MediaType::Dmts => NodeModuleKind::Esm, - MediaType::Cjs | MediaType::Cts | MediaType::Dcts => NodeModuleKind::Cjs, + MediaType::Mts | MediaType::Mjs | MediaType::Dmts => ResolutionMode::Import, + MediaType::Cjs | MediaType::Cts | MediaType::Dcts => ResolutionMode::Require, MediaType::Dts => { // dts files are always determined based on the package.json because // they contain imports/exports even when considered CJS - self.check_based_on_pkg_json(specifier).unwrap_or(NodeModuleKind::Esm) + self.check_based_on_pkg_json(specifier).unwrap_or(ResolutionMode::Import) } MediaType::Wasm | - MediaType::Json => NodeModuleKind::Esm, + MediaType::Json => ResolutionMode::Import, MediaType::JavaScript | MediaType::Jsx | MediaType::TypeScript @@ -169,27 +169,27 @@ impl IsCjsResolver { | MediaType::SourceMap | MediaType::Unknown => { match is_script { - Some(true) => self.check_based_on_pkg_json(specifier).unwrap_or(NodeModuleKind::Esm), - Some(false) | None => NodeModuleKind::Esm, + Some(true) => self.check_based_on_pkg_json(specifier).unwrap_or(ResolutionMode::Import), + Some(false) | None => ResolutionMode::Import, } } } } - fn get_known_kind_with_is_script( + fn get_known_mode_with_is_script( &self, specifier: &Url, media_type: MediaType, is_script: Option, - known_cache: &DashMap, - ) -> Option { + known_cache: &DashMap, + ) -> Option { if specifier.scheme() != "file" { - return Some(NodeModuleKind::Esm); + return Some(ResolutionMode::Import); } match media_type { - MediaType::Mts | MediaType::Mjs | MediaType::Dmts => Some(NodeModuleKind::Esm), - MediaType::Cjs | MediaType::Cts | MediaType::Dcts => Some(NodeModuleKind::Cjs), + MediaType::Mts | MediaType::Mjs | MediaType::Dmts => Some(ResolutionMode::Import), + MediaType::Cjs | MediaType::Cts | MediaType::Dcts => Some(ResolutionMode::Require), MediaType::Dts => { // dts files are always determined based on the package.json because // they contain imports/exports even when considered CJS @@ -200,11 +200,11 @@ impl IsCjsResolver { if let Some(value) = value { known_cache.insert(specifier.clone(), value); } - Some(value.unwrap_or(NodeModuleKind::Esm)) + Some(value.unwrap_or(ResolutionMode::Import)) } } MediaType::Wasm | - MediaType::Json => Some(NodeModuleKind::Esm), + MediaType::Json => Some(ResolutionMode::Import), MediaType::JavaScript | MediaType::Jsx | MediaType::TypeScript @@ -214,17 +214,17 @@ impl IsCjsResolver { | MediaType::SourceMap | MediaType::Unknown => { if let Some(value) = known_cache.get(specifier).map(|v| *v) { - if value == NodeModuleKind::Cjs && is_script == Some(false) { + if value == ResolutionMode::Require && is_script == Some(false) { // we now know this is actually esm - known_cache.insert(specifier.clone(), NodeModuleKind::Esm); - Some(NodeModuleKind::Esm) + known_cache.insert(specifier.clone(), ResolutionMode::Import); + Some(ResolutionMode::Import) } else { Some(value) } } else if is_script == Some(false) { // we know this is esm - known_cache.insert(specifier.clone(), NodeModuleKind::Esm); - Some(NodeModuleKind::Esm) + known_cache.insert(specifier.clone(), ResolutionMode::Import); + Some(ResolutionMode::Import) } else { None } @@ -235,19 +235,19 @@ impl IsCjsResolver { fn check_based_on_pkg_json( &self, specifier: &Url, - ) -> Result { + ) -> Result { if self.in_npm_pkg_checker.in_npm_package(specifier) { if let Some(pkg_json) = self.pkg_json_resolver.get_closest_package_json(specifier)? { let is_file_location_cjs = pkg_json.typ != "module"; Ok(if is_file_location_cjs { - NodeModuleKind::Cjs + ResolutionMode::Require } else { - NodeModuleKind::Esm + ResolutionMode::Import }) } else { - Ok(NodeModuleKind::Cjs) + Ok(ResolutionMode::Require) } } else if self.options.detect_cjs || self.options.is_node_main { if let Some(pkg_json) = @@ -256,17 +256,17 @@ impl IsCjsResolver { let is_cjs_type = pkg_json.typ == "commonjs" || self.options.is_node_main && pkg_json.typ == "none"; Ok(if is_cjs_type { - NodeModuleKind::Cjs + ResolutionMode::Require } else { - NodeModuleKind::Esm + ResolutionMode::Import }) } else if self.options.is_node_main { - Ok(NodeModuleKind::Cjs) + Ok(ResolutionMode::Require) } else { - Ok(NodeModuleKind::Esm) + Ok(ResolutionMode::Import) } } else { - Ok(NodeModuleKind::Esm) + Ok(ResolutionMode::Import) } } } diff --git a/resolvers/deno/lib.rs b/resolvers/deno/lib.rs index 303a827102..661caf836d 100644 --- a/resolvers/deno/lib.rs +++ b/resolvers/deno/lib.rs @@ -20,10 +20,10 @@ use node_resolver::env::NodeResolverEnv; use node_resolver::errors::NodeResolveError; use node_resolver::errors::PackageSubpathResolveError; use node_resolver::InNpmPackageChecker; -use node_resolver::NodeModuleKind; use node_resolver::NodeResolution; -use node_resolver::NodeResolutionMode; +use node_resolver::NodeResolutionKind; use node_resolver::NodeResolver; +use node_resolver::ResolutionMode; use npm::MissingPackageNodeModulesFolderError; use npm::NodeModulesOutOfDateError; use npm::NpmReqResolver; @@ -31,7 +31,7 @@ use npm::ResolveIfForNpmPackageErrorKind; use npm::ResolvePkgFolderFromDenoReqError; use npm::ResolveReqWithSubPathErrorKind; use sloppy_imports::SloppyImportResolverFs; -use sloppy_imports::SloppyImportsResolutionMode; +use sloppy_imports::SloppyImportsResolutionKind; use sloppy_imports::SloppyImportsResolver; use thiserror::Error; use url::Url; @@ -145,8 +145,8 @@ impl< &self, raw_specifier: &str, referrer: &Url, - referrer_kind: NodeModuleKind, - mode: NodeResolutionMode, + resolution_mode: ResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { let mut found_package_json_dep = false; let mut maybe_diagnostic = None; @@ -157,7 +157,7 @@ impl< && self.in_npm_pkg_checker.in_npm_package(referrer) { return node_resolver - .resolve(raw_specifier, referrer, referrer_kind, mode) + .resolve(raw_specifier, referrer, resolution_mode, resolution_kind) .map(|res| DenoResolution { url: res.into_url(), found_package_json_dep, @@ -189,12 +189,12 @@ impl< sloppy_imports_resolver .resolve( &specifier, - match mode { - NodeResolutionMode::Execution => { - SloppyImportsResolutionMode::Execution + match resolution_kind { + NodeResolutionKind::Execution => { + SloppyImportsResolutionKind::Execution } - NodeResolutionMode::Types => { - SloppyImportsResolutionMode::Types + NodeResolutionKind::Types => { + SloppyImportsResolutionKind::Types } }, ) @@ -221,8 +221,8 @@ impl< pkg_json.dir_path(), sub_path.as_deref(), Some(referrer), - referrer_kind, - mode, + resolution_mode, + resolution_kind, ) .map_err(|e| e.into()), MappedResolution::PackageJson { @@ -272,8 +272,8 @@ impl< pkg_folder, sub_path.as_deref(), Some(referrer), - referrer_kind, - mode, + resolution_mode, + resolution_kind, ) .map_err(|e| { DenoResolveErrorKind::PackageSubpathResolve(e).into_box() @@ -328,8 +328,8 @@ impl< pkg_folder, npm_req_ref.sub_path(), Some(referrer), - referrer_kind, - mode, + resolution_mode, + resolution_kind, ) .map(|url| DenoResolution { url, @@ -345,8 +345,8 @@ impl< .resolve_req_reference( &npm_req_ref, referrer, - referrer_kind, - mode, + resolution_mode, + resolution_kind, ) .map(|url| DenoResolution { url, @@ -384,8 +384,8 @@ impl< .resolve_if_for_npm_pkg( raw_specifier, referrer, - referrer_kind, - mode, + resolution_mode, + resolution_kind, ) .map_err(|e| match e.into_kind() { ResolveIfForNpmPackageErrorKind::NodeResolve(e) => { diff --git a/resolvers/deno/npm/mod.rs b/resolvers/deno/npm/mod.rs index 09e35b15c3..83db04480a 100644 --- a/resolvers/deno/npm/mod.rs +++ b/resolvers/deno/npm/mod.rs @@ -16,10 +16,10 @@ use node_resolver::errors::PackageNotFoundError; use node_resolver::errors::PackageResolveErrorKind; use node_resolver::errors::PackageSubpathResolveError; use node_resolver::InNpmPackageChecker; -use node_resolver::NodeModuleKind; use node_resolver::NodeResolution; -use node_resolver::NodeResolutionMode; +use node_resolver::NodeResolutionKind; use node_resolver::NodeResolver; +use node_resolver::ResolutionMode; use thiserror::Error; use url::Url; @@ -132,15 +132,15 @@ impl &self, req_ref: &NpmPackageReqReference, referrer: &Url, - referrer_kind: NodeModuleKind, - mode: NodeResolutionMode, + resolution_mode: ResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { self.resolve_req_with_sub_path( req_ref.req(), req_ref.sub_path(), referrer, - referrer_kind, - mode, + resolution_mode, + resolution_kind, ) } @@ -149,8 +149,8 @@ impl req: &PackageReq, sub_path: Option<&str>, referrer: &Url, - referrer_kind: NodeModuleKind, - mode: NodeResolutionMode, + resolution_mode: ResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { let package_folder = self .npm_resolver @@ -160,8 +160,8 @@ impl &package_folder, sub_path, Some(referrer), - referrer_kind, - mode, + resolution_mode, + resolution_kind, ); match resolution_result { Ok(url) => Ok(url), @@ -183,13 +183,15 @@ impl &self, specifier: &str, referrer: &Url, - referrer_kind: NodeModuleKind, - mode: NodeResolutionMode, + resolution_mode: ResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result, ResolveIfForNpmPackageError> { - let resolution_result = - self - .node_resolver - .resolve(specifier, referrer, referrer_kind, mode); + let resolution_result = self.node_resolver.resolve( + specifier, + referrer, + resolution_mode, + resolution_kind, + ); match resolution_result { Ok(res) => Ok(Some(res)), Err(err) => { diff --git a/resolvers/deno/sloppy_imports.rs b/resolvers/deno/sloppy_imports.rs index 7aba5b771a..ccaa547435 100644 --- a/resolvers/deno/sloppy_imports.rs +++ b/resolvers/deno/sloppy_imports.rs @@ -80,16 +80,16 @@ impl SloppyImportsResolution { /// The kind of resolution currently being done. #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum SloppyImportsResolutionMode { +pub enum SloppyImportsResolutionKind { /// Resolving for code that will be executed. Execution, /// Resolving for code that will be used for type information. Types, } -impl SloppyImportsResolutionMode { +impl SloppyImportsResolutionKind { pub fn is_types(&self) -> bool { - *self == SloppyImportsResolutionMode::Types + *self == SloppyImportsResolutionKind::Types } } @@ -114,7 +114,7 @@ impl SloppyImportsResolver { pub fn resolve( &self, specifier: &Url, - mode: SloppyImportsResolutionMode, + resolution_kind: SloppyImportsResolutionKind, ) -> Option { fn path_without_ext( path: &Path, @@ -167,7 +167,7 @@ impl SloppyImportsResolver { let probe_paths: Vec<(PathBuf, SloppyImportsResolutionReason)> = match self.fs.stat_sync(&path) { Some(SloppyImportsFsEntry::File) => { - if mode.is_types() { + if resolution_kind.is_types() { let media_type = MediaType::from_specifier(specifier); // attempt to resolve the .d.ts file before the .js file let probe_media_type_types = match media_type { @@ -197,7 +197,7 @@ impl SloppyImportsResolver { let media_type = MediaType::from_specifier(specifier); let probe_media_type_types = match media_type { MediaType::JavaScript => ( - if mode.is_types() { + if resolution_kind.is_types() { vec![MediaType::TypeScript, MediaType::Tsx, MediaType::Dts] } else { vec![MediaType::TypeScript, MediaType::Tsx] @@ -208,7 +208,7 @@ impl SloppyImportsResolver { (vec![MediaType::Tsx], SloppyImportsResolutionReason::JsToTs) } MediaType::Mjs => ( - if mode.is_types() { + if resolution_kind.is_types() { vec![MediaType::Mts, MediaType::Dmts, MediaType::Dts] } else { vec![MediaType::Mts] @@ -216,7 +216,7 @@ impl SloppyImportsResolver { SloppyImportsResolutionReason::JsToTs, ), MediaType::Cjs => ( - if mode.is_types() { + if resolution_kind.is_types() { vec![MediaType::Cts, MediaType::Dcts, MediaType::Dts] } else { vec![MediaType::Cts] @@ -237,7 +237,7 @@ impl SloppyImportsResolver { return None; } MediaType::Unknown => ( - if mode.is_types() { + if resolution_kind.is_types() { vec![ MediaType::TypeScript, MediaType::Tsx, @@ -274,7 +274,7 @@ impl SloppyImportsResolver { if matches!(entry, Some(SloppyImportsFsEntry::Dir)) { // try to resolve at the index file - if mode.is_types() { + if resolution_kind.is_types() { probe_paths.push(( path.join("index.ts"), SloppyImportsResolutionReason::Directory, @@ -373,16 +373,22 @@ mod test { #[test] fn test_unstable_sloppy_imports() { fn resolve(specifier: &Url) -> Option { - resolve_with_mode(specifier, SloppyImportsResolutionMode::Execution) + resolve_with_resolution_kind( + specifier, + SloppyImportsResolutionKind::Execution, + ) } fn resolve_types(specifier: &Url) -> Option { - resolve_with_mode(specifier, SloppyImportsResolutionMode::Types) + resolve_with_resolution_kind( + specifier, + SloppyImportsResolutionKind::Types, + ) } - fn resolve_with_mode( + fn resolve_with_resolution_kind( specifier: &Url, - mode: SloppyImportsResolutionMode, + resolution_kind: SloppyImportsResolutionKind, ) -> Option { struct RealSloppyImportsResolverFs; impl SloppyImportResolverFs for RealSloppyImportsResolverFs { @@ -400,7 +406,7 @@ mod test { } SloppyImportsResolver::new(RealSloppyImportsResolverFs) - .resolve(specifier, mode) + .resolve(specifier, resolution_kind) } let context = TestContext::default(); diff --git a/resolvers/node/analyze.rs b/resolvers/node/analyze.rs index 9126890805..a444f4d923 100644 --- a/resolvers/node/analyze.rs +++ b/resolvers/node/analyze.rs @@ -21,11 +21,11 @@ use url::Url; use crate::env::NodeResolverEnv; use crate::npm::InNpmPackageCheckerRc; use crate::resolution::NodeResolverRc; -use crate::NodeModuleKind; -use crate::NodeResolutionMode; +use crate::NodeResolutionKind; use crate::NpmPackageFolderResolverRc; use crate::PackageJsonResolverRc; use crate::PathClean; +use crate::ResolutionMode; #[derive(Debug, Clone)] pub enum CjsAnalysis<'a> { @@ -209,7 +209,7 @@ impl // FIXME(bartlomieju): check if these conditions are okay, probably // should be `deno-require`, because `deno` is already used in `esm_resolver.rs` &["deno", "node", "require", "default"], - NodeResolutionMode::Execution, + NodeResolutionKind::Execution, ); let reexport_specifier = match result { Ok(Some(specifier)) => specifier, @@ -303,7 +303,7 @@ impl specifier: &str, referrer: &Url, conditions: &[&str], - mode: NodeResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result, AnyError> { if specifier.starts_with('/') { todo!(); @@ -354,9 +354,9 @@ impl &package_subpath, exports, Some(referrer), - NodeModuleKind::Esm, + ResolutionMode::Import, conditions, - mode, + resolution_kind, ) .map_err(AnyError::from), ) @@ -373,7 +373,9 @@ impl .pkg_json_resolver .load_package_json(&package_json_path)?; if let Some(package_json) = maybe_package_json { - if let Some(main) = package_json.main(NodeModuleKind::Cjs) { + if let Some(main) = + package_json.main(deno_package_json::NodeModuleKind::Cjs) + { return Ok(Some(url_from_file_path(&d.join(main).clean())?)); } } @@ -384,7 +386,9 @@ impl .file_extension_probe(d, &referrer_path) .and_then(|p| url_from_file_path(&p).map_err(AnyError::from)) .map(Some); - } else if let Some(main) = package_json.main(NodeModuleKind::Cjs) { + } else if let Some(main) = + package_json.main(deno_package_json::NodeModuleKind::Cjs) + { return Ok(Some(url_from_file_path(&module_dir.join(main).clean())?)); } else { return Ok(Some(url_from_file_path( diff --git a/resolvers/node/errors.rs b/resolvers/node/errors.rs index 0f332d2c93..600a365a8f 100644 --- a/resolvers/node/errors.rs +++ b/resolvers/node/errors.rs @@ -8,8 +8,8 @@ use boxed_error::Boxed; use thiserror::Error; use url::Url; -use crate::NodeModuleKind; -use crate::NodeResolutionMode; +use crate::NodeResolutionKind; +use crate::ResolutionMode; #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] #[allow(non_camel_case_types)] @@ -203,24 +203,24 @@ pub enum PackageSubpathResolveErrorKind { maybe_referrer.as_ref().map(|r| format!( " from{} referrer {}", - match referrer_kind { - NodeModuleKind::Esm => "", - NodeModuleKind::Cjs => " cjs", + match resolution_mode { + ResolutionMode::Import => "", + ResolutionMode::Require => " cjs", }, r ) ).unwrap_or_default(), - match mode { - NodeResolutionMode::Execution => "", - NodeResolutionMode::Types => " for types", + match resolution_kind { + NodeResolutionKind::Execution => "", + NodeResolutionKind::Types => " for types", } )] pub struct PackageTargetNotFoundError { pub pkg_json_path: PathBuf, pub target: String, pub maybe_referrer: Option, - pub referrer_kind: NodeModuleKind, - pub mode: NodeResolutionMode, + pub resolution_mode: ResolutionMode, + pub resolution_kind: NodeResolutionKind, } impl NodeJsErrorCoded for PackageTargetNotFoundError { @@ -586,7 +586,7 @@ pub struct PackagePathNotExportedError { pub pkg_json_path: PathBuf, pub subpath: String, pub maybe_referrer: Option, - pub mode: NodeResolutionMode, + pub resolution_kind: NodeResolutionKind, } impl NodeJsErrorCoded for PackagePathNotExportedError { @@ -603,9 +603,9 @@ impl std::fmt::Display for PackagePathNotExportedError { f.write_str(self.code().as_str())?; f.write_char(']')?; - let types_msg = match self.mode { - NodeResolutionMode::Execution => String::new(), - NodeResolutionMode::Types => " for types".to_string(), + let types_msg = match self.resolution_kind { + NodeResolutionKind::Execution => String::new(), + NodeResolutionKind::Types => " for types".to_string(), }; if self.subpath == "." { write!( @@ -678,7 +678,7 @@ mod test { pkg_json_path: PathBuf::from("test_path").join("package.json"), subpath: "./jsx-runtime".to_string(), maybe_referrer: None, - mode: NodeResolutionMode::Types + resolution_kind: NodeResolutionKind::Types }.to_string(), format!("[ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './jsx-runtime' is not defined for types by \"exports\" in 'test_path{separator_char}package.json'") ); @@ -687,7 +687,7 @@ mod test { pkg_json_path: PathBuf::from("test_path").join("package.json"), subpath: ".".to_string(), maybe_referrer: None, - mode: NodeResolutionMode::Types + resolution_kind: NodeResolutionKind::Types }.to_string(), format!("[ERR_PACKAGE_PATH_NOT_EXPORTED] No \"exports\" main defined for types in 'test_path{separator_char}package.json'") ); diff --git a/resolvers/node/lib.rs b/resolvers/node/lib.rs index 87bd629946..8da20c421e 100644 --- a/resolvers/node/lib.rs +++ b/resolvers/node/lib.rs @@ -23,9 +23,9 @@ pub use package_json::PackageJsonThreadLocalCache; pub use path::PathClean; pub use resolution::parse_npm_pkg_name; pub use resolution::resolve_specifier_into_node_modules; -pub use resolution::NodeModuleKind; pub use resolution::NodeResolution; -pub use resolution::NodeResolutionMode; +pub use resolution::NodeResolutionKind; pub use resolution::NodeResolver; +pub use resolution::ResolutionMode; pub use resolution::DEFAULT_CONDITIONS; pub use resolution::REQUIRE_CONDITIONS; diff --git a/resolvers/node/resolution.rs b/resolvers/node/resolution.rs index c2ec25aca4..5f87698cd6 100644 --- a/resolvers/node/resolution.rs +++ b/resolvers/node/resolution.rs @@ -50,26 +50,30 @@ pub static DEFAULT_CONDITIONS: &[&str] = &["deno", "node", "import"]; pub static REQUIRE_CONDITIONS: &[&str] = &["require", "node"]; static TYPES_ONLY_CONDITIONS: &[&str] = &["types"]; -fn conditions_from_module_kind( - kind: NodeModuleKind, +fn conditions_from_resolution_mode( + resolution_mode: ResolutionMode, ) -> &'static [&'static str] { - match kind { - NodeModuleKind::Esm => DEFAULT_CONDITIONS, - NodeModuleKind::Cjs => REQUIRE_CONDITIONS, + match resolution_mode { + ResolutionMode::Import => DEFAULT_CONDITIONS, + ResolutionMode::Require => REQUIRE_CONDITIONS, } } -pub type NodeModuleKind = deno_package_json::NodeModuleKind; +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum ResolutionMode { + Import, + Require, +} -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum NodeResolutionMode { +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum NodeResolutionKind { Execution, Types, } -impl NodeResolutionMode { +impl NodeResolutionKind { pub fn is_types(&self) -> bool { - matches!(self, NodeResolutionMode::Types) + matches!(self, NodeResolutionKind::Types) } } @@ -130,8 +134,8 @@ impl NodeResolver { &self, specifier: &str, referrer: &Url, - referrer_kind: NodeModuleKind, - mode: NodeResolutionMode, + resolution_mode: ResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { // Note: if we are here, then the referrer is an esm module // TODO(bartlomieju): skipped "policy" part as we don't plan to support it @@ -174,14 +178,18 @@ impl NodeResolver { let url = self.module_resolve( specifier, referrer, - referrer_kind, - conditions_from_module_kind(referrer_kind), - mode, + resolution_mode, + conditions_from_resolution_mode(resolution_mode), + resolution_kind, )?; - let url = if mode.is_types() { + let url = if resolution_kind.is_types() { let file_path = to_file_path(&url); - self.path_to_declaration_url(&file_path, Some(referrer), referrer_kind)? + self.path_to_declaration_url( + &file_path, + Some(referrer), + resolution_mode, + )? } else { url }; @@ -197,9 +205,9 @@ impl NodeResolver { &self, specifier: &str, referrer: &Url, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, conditions: &[&str], - mode: NodeResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { if should_be_treated_as_relative_or_absolute_path(specifier) { Ok(node_join_url(referrer, specifier).map_err(|err| { @@ -218,10 +226,10 @@ impl NodeResolver { Ok(self.package_imports_resolve( specifier, Some(referrer), - referrer_kind, + resolution_mode, pkg_config.as_deref(), conditions, - mode, + resolution_kind, )?) } else if let Ok(resolved) = Url::parse(specifier) { Ok(resolved) @@ -229,9 +237,9 @@ impl NodeResolver { Ok(self.package_resolve( specifier, referrer, - referrer_kind, + resolution_mode, conditions, - mode, + resolution_kind, )?) } } @@ -307,8 +315,8 @@ impl NodeResolver { package_dir: &Path, package_subpath: Option<&str>, maybe_referrer: Option<&Url>, - referrer_kind: NodeModuleKind, - mode: NodeResolutionMode, + resolution_mode: ResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { let package_subpath = package_subpath .map(|s| format!("./{s}")) @@ -317,9 +325,9 @@ impl NodeResolver { package_dir, &package_subpath, maybe_referrer, - referrer_kind, - conditions_from_module_kind(referrer_kind), - mode, + resolution_mode, + conditions_from_resolution_mode(resolution_mode), + resolution_kind, )?; // TODO(bartlomieju): skipped checking errors for commonJS resolution and // "preserveSymlinksMain"/"preserveSymlinks" options. @@ -385,13 +393,13 @@ impl NodeResolver { &self, path: &Path, maybe_referrer: Option<&Url>, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, ) -> Result { fn probe_extensions( fs: &TEnv, path: &Path, lowercase_path: &str, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, ) -> Option { let mut searched_for_d_mts = false; let mut searched_for_d_cts = false; @@ -414,11 +422,11 @@ impl NodeResolver { return Some(dts_path); } - let specific_dts_path = match referrer_kind { - NodeModuleKind::Cjs if !searched_for_d_cts => { + let specific_dts_path = match resolution_mode { + ResolutionMode::Require if !searched_for_d_cts => { Some(with_known_extension(path, "d.cts")) } - NodeModuleKind::Esm if !searched_for_d_mts => { + ResolutionMode::Import if !searched_for_d_mts => { Some(with_known_extension(path, "d.mts")) } _ => None, // already searched above @@ -439,7 +447,7 @@ impl NodeResolver { return Ok(url_from_file_path(path).unwrap()); } if let Some(path) = - probe_extensions(&self.env, path, &lowercase_path, referrer_kind) + probe_extensions(&self.env, path, &lowercase_path, resolution_mode) { return Ok(url_from_file_path(&path).unwrap()); } @@ -448,9 +456,9 @@ impl NodeResolver { path, /* sub path */ ".", maybe_referrer, - referrer_kind, - conditions_from_module_kind(referrer_kind), - NodeResolutionMode::Types, + resolution_mode, + conditions_from_resolution_mode(resolution_mode), + NodeResolutionKind::Types, ); if let Ok(resolution) = resolution_result { return Ok(resolution); @@ -460,7 +468,7 @@ impl NodeResolver { &self.env, &index_path, &index_path.to_string_lossy().to_lowercase(), - referrer_kind, + resolution_mode, ) { return Ok(url_from_file_path(&path).unwrap()); } @@ -480,10 +488,10 @@ impl NodeResolver { &self, name: &str, maybe_referrer: Option<&Url>, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, referrer_pkg_json: Option<&PackageJson>, conditions: &[&str], - mode: NodeResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { if name == "#" || name.starts_with("#/") || name.ends_with('/') { let reason = "is not a valid internal imports specifier name"; @@ -509,11 +517,11 @@ impl NodeResolver { "", name, maybe_referrer, - referrer_kind, + resolution_mode, false, true, conditions, - mode, + resolution_kind, )?; if let Some(resolved) = maybe_resolved { return Ok(resolved); @@ -549,11 +557,11 @@ impl NodeResolver { best_match_subpath.unwrap(), best_match, maybe_referrer, - referrer_kind, + resolution_mode, true, true, conditions, - mode, + resolution_kind, )?; if let Some(resolved) = maybe_resolved { return Ok(resolved); @@ -581,11 +589,11 @@ impl NodeResolver { match_: &str, package_json_path: &Path, maybe_referrer: Option<&Url>, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, pattern: bool, internal: bool, conditions: &[&str], - mode: NodeResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { if !subpath.is_empty() && !pattern && !target.ends_with('/') { return Err( @@ -626,9 +634,9 @@ impl NodeResolver { let result = match self.package_resolve( &export_target, &package_json_url, - referrer_kind, + resolution_mode, conditions, - mode, + resolution_kind, ) { Ok(url) => Ok(url), Err(err) => match err.code() { @@ -649,8 +657,8 @@ impl NodeResolver { pkg_json_path: package_json_path.to_path_buf(), target: export_target.to_string(), maybe_referrer: maybe_referrer.map(ToOwned::to_owned), - referrer_kind, - mode, + resolution_mode, + resolution_kind, }, ) .into(), @@ -746,11 +754,11 @@ impl NodeResolver { subpath: &str, package_subpath: &str, maybe_referrer: Option<&Url>, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, pattern: bool, internal: bool, conditions: &[&str], - mode: NodeResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result, PackageTargetResolveError> { let result = self.resolve_package_target_inner( package_json_path, @@ -758,16 +766,16 @@ impl NodeResolver { subpath, package_subpath, maybe_referrer, - referrer_kind, + resolution_mode, pattern, internal, conditions, - mode, + resolution_kind, ); match result { Ok(maybe_resolved) => Ok(maybe_resolved), Err(err) => { - if mode.is_types() + if resolution_kind.is_types() && err.code() == NodeJsErrorCode::ERR_TYPES_NOT_FOUND && conditions != TYPES_ONLY_CONDITIONS { @@ -779,11 +787,11 @@ impl NodeResolver { subpath, package_subpath, maybe_referrer, - referrer_kind, + resolution_mode, pattern, internal, TYPES_ONLY_CONDITIONS, - mode, + resolution_kind, ) { return Ok(Some(resolved)); } @@ -802,11 +810,11 @@ impl NodeResolver { subpath: &str, package_subpath: &str, maybe_referrer: Option<&Url>, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, pattern: bool, internal: bool, conditions: &[&str], - mode: NodeResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result, PackageTargetResolveError> { if let Some(target) = target.as_str() { let url = self.resolve_package_target_string( @@ -815,18 +823,18 @@ impl NodeResolver { package_subpath, package_json_path, maybe_referrer, - referrer_kind, + resolution_mode, pattern, internal, conditions, - mode, + resolution_kind, )?; - if mode.is_types() && url.scheme() == "file" { + if resolution_kind.is_types() && url.scheme() == "file" { let path = deno_path_util::url_to_file_path(&url).unwrap(); return Ok(Some(self.path_to_declaration_url( &path, maybe_referrer, - referrer_kind, + resolution_mode, )?)); } else { return Ok(Some(url)); @@ -844,11 +852,11 @@ impl NodeResolver { subpath, package_subpath, maybe_referrer, - referrer_kind, + resolution_mode, pattern, internal, conditions, - mode, + resolution_kind, ); match resolved_result { @@ -882,7 +890,7 @@ impl NodeResolver { if key == "default" || conditions.contains(&key.as_str()) - || mode.is_types() && key.as_str() == "types" + || resolution_kind.is_types() && key.as_str() == "types" { let condition_target = target_obj.get(key).unwrap(); @@ -892,11 +900,11 @@ impl NodeResolver { subpath, package_subpath, maybe_referrer, - referrer_kind, + resolution_mode, pattern, internal, conditions, - mode, + resolution_kind, )?; match resolved { Some(resolved) => return Ok(Some(resolved)), @@ -929,9 +937,9 @@ impl NodeResolver { package_subpath: &str, package_exports: &Map, maybe_referrer: Option<&Url>, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, conditions: &[&str], - mode: NodeResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { if package_exports.contains_key(package_subpath) && package_subpath.find('*').is_none() @@ -944,11 +952,11 @@ impl NodeResolver { "", package_subpath, maybe_referrer, - referrer_kind, + resolution_mode, false, false, conditions, - mode, + resolution_kind, )?; return match resolved { Some(resolved) => Ok(resolved), @@ -957,7 +965,7 @@ impl NodeResolver { pkg_json_path: package_json_path.to_path_buf(), subpath: package_subpath.to_string(), maybe_referrer: maybe_referrer.map(ToOwned::to_owned), - mode, + resolution_kind, } .into(), ), @@ -1006,11 +1014,11 @@ impl NodeResolver { &best_match_subpath.unwrap(), best_match, maybe_referrer, - referrer_kind, + resolution_mode, true, false, conditions, - mode, + resolution_kind, )?; if let Some(resolved) = maybe_resolved { return Ok(resolved); @@ -1020,7 +1028,7 @@ impl NodeResolver { pkg_json_path: package_json_path.to_path_buf(), subpath: package_subpath.to_string(), maybe_referrer: maybe_referrer.map(ToOwned::to_owned), - mode, + resolution_kind, } .into(), ); @@ -1032,7 +1040,7 @@ impl NodeResolver { pkg_json_path: package_json_path.to_path_buf(), subpath: package_subpath.to_string(), maybe_referrer: maybe_referrer.map(ToOwned::to_owned), - mode, + resolution_kind, } .into(), ) @@ -1042,9 +1050,9 @@ impl NodeResolver { &self, specifier: &str, referrer: &Url, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, conditions: &[&str], - mode: NodeResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { let (package_name, package_subpath, _is_scoped) = parse_npm_pkg_name(specifier, referrer)?; @@ -1061,9 +1069,9 @@ impl NodeResolver { &package_subpath, exports, Some(referrer), - referrer_kind, + resolution_mode, conditions, - mode, + resolution_kind, ) .map_err(|err| err.into()); } @@ -1074,9 +1082,9 @@ impl NodeResolver { &package_name, &package_subpath, referrer, - referrer_kind, + resolution_mode, conditions, - mode, + resolution_kind, ) } @@ -1086,28 +1094,28 @@ impl NodeResolver { package_name: &str, package_subpath: &str, referrer: &Url, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, conditions: &[&str], - mode: NodeResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { let result = self.resolve_package_subpath_for_package_inner( package_name, package_subpath, referrer, - referrer_kind, + resolution_mode, conditions, - mode, + resolution_kind, ); - if mode.is_types() && !matches!(result, Ok(Url { .. })) { + if resolution_kind.is_types() && !matches!(result, Ok(Url { .. })) { // try to resolve with the @types package let package_name = types_package_name(package_name); if let Ok(result) = self.resolve_package_subpath_for_package_inner( &package_name, package_subpath, referrer, - referrer_kind, + resolution_mode, conditions, - mode, + resolution_kind, ) { return Ok(result); } @@ -1121,9 +1129,9 @@ impl NodeResolver { package_name: &str, package_subpath: &str, referrer: &Url, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, conditions: &[&str], - mode: NodeResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { let package_dir_path = self .npm_pkg_folder_resolver @@ -1148,9 +1156,9 @@ impl NodeResolver { &package_dir_path, package_subpath, Some(referrer), - referrer_kind, + resolution_mode, conditions, - mode, + resolution_kind, ) .map_err(|err| err.into()) } @@ -1161,9 +1169,9 @@ impl NodeResolver { package_dir_path: &Path, package_subpath: &str, maybe_referrer: Option<&Url>, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, conditions: &[&str], - mode: NodeResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { let package_json_path = package_dir_path.join("package.json"); match self @@ -1174,17 +1182,17 @@ impl NodeResolver { &pkg_json, package_subpath, maybe_referrer, - referrer_kind, + resolution_mode, conditions, - mode, + resolution_kind, ), None => self .resolve_package_subpath_no_pkg_json( package_dir_path, package_subpath, maybe_referrer, - referrer_kind, - mode, + resolution_mode, + resolution_kind, ) .map_err(|err| { PackageSubpathResolveErrorKind::LegacyResolve(err).into() @@ -1198,9 +1206,9 @@ impl NodeResolver { package_json: &PackageJson, package_subpath: &str, referrer: Option<&Url>, - referrer_kind: NodeModuleKind, + resolution_mode: ResolutionMode, conditions: &[&str], - mode: NodeResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { if let Some(exports) = &package_json.exports { let result = self.package_exports_resolve( @@ -1208,16 +1216,21 @@ impl NodeResolver { package_subpath, exports, referrer, - referrer_kind, + resolution_mode, conditions, - mode, + resolution_kind, ); match result { Ok(found) => return Ok(found), Err(exports_err) => { - if mode.is_types() && package_subpath == "." { + if resolution_kind.is_types() && package_subpath == "." { return self - .legacy_main_resolve(package_json, referrer, referrer_kind, mode) + .legacy_main_resolve( + package_json, + referrer, + resolution_mode, + resolution_kind, + ) .map_err(|err| { PackageSubpathResolveErrorKind::LegacyResolve(err).into() }); @@ -1231,7 +1244,12 @@ impl NodeResolver { if package_subpath == "." { return self - .legacy_main_resolve(package_json, referrer, referrer_kind, mode) + .legacy_main_resolve( + package_json, + referrer, + resolution_mode, + resolution_kind, + ) .map_err(|err| { PackageSubpathResolveErrorKind::LegacyResolve(err).into() }); @@ -1242,8 +1260,8 @@ impl NodeResolver { package_json.path.parent().unwrap(), package_subpath, referrer, - referrer_kind, - mode, + resolution_mode, + resolution_kind, ) .map_err(|err| { PackageSubpathResolveErrorKind::LegacyResolve(err.into()).into() @@ -1255,13 +1273,13 @@ impl NodeResolver { directory: &Path, package_subpath: &str, referrer: Option<&Url>, - referrer_kind: NodeModuleKind, - mode: NodeResolutionMode, + resolution_mode: ResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { assert_ne!(package_subpath, "."); let file_path = directory.join(package_subpath); - if mode.is_types() { - Ok(self.path_to_declaration_url(&file_path, referrer, referrer_kind)?) + if resolution_kind.is_types() { + Ok(self.path_to_declaration_url(&file_path, referrer, resolution_mode)?) } else { Ok(url_from_file_path(&file_path).unwrap()) } @@ -1272,19 +1290,24 @@ impl NodeResolver { directory: &Path, package_subpath: &str, maybe_referrer: Option<&Url>, - referrer_kind: NodeModuleKind, - mode: NodeResolutionMode, + resolution_mode: ResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { if package_subpath == "." { - self.legacy_index_resolve(directory, maybe_referrer, referrer_kind, mode) + self.legacy_index_resolve( + directory, + maybe_referrer, + resolution_mode, + resolution_kind, + ) } else { self .resolve_subpath_exact( directory, package_subpath, maybe_referrer, - referrer_kind, - mode, + resolution_mode, + resolution_kind, ) .map_err(|err| err.into()) } @@ -1294,21 +1317,25 @@ impl NodeResolver { &self, package_json: &PackageJson, maybe_referrer: Option<&Url>, - referrer_kind: NodeModuleKind, - mode: NodeResolutionMode, + resolution_mode: ResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { - let maybe_main = if mode.is_types() { + let pkg_json_kind = match resolution_mode { + ResolutionMode::Require => deno_package_json::NodeModuleKind::Cjs, + ResolutionMode::Import => deno_package_json::NodeModuleKind::Esm, + }; + let maybe_main = if resolution_kind.is_types() { match package_json.types.as_ref() { Some(types) => Some(types.as_str()), None => { // fallback to checking the main entrypoint for // a corresponding declaration file - if let Some(main) = package_json.main(referrer_kind) { + if let Some(main) = package_json.main(pkg_json_kind) { let main = package_json.path.parent().unwrap().join(main).clean(); let decl_url_result = self.path_to_declaration_url( &main, maybe_referrer, - referrer_kind, + resolution_mode, ); // don't surface errors, fallback to checking the index now if let Ok(url) = decl_url_result { @@ -1319,7 +1346,7 @@ impl NodeResolver { } } } else { - package_json.main(referrer_kind) + package_json.main(pkg_json_kind) }; if let Some(main) = maybe_main { @@ -1329,12 +1356,12 @@ impl NodeResolver { } // todo(dsherret): investigate exactly how node and typescript handles this - let endings = if mode.is_types() { - match referrer_kind { - NodeModuleKind::Cjs => { + let endings = if resolution_kind.is_types() { + match resolution_mode { + ResolutionMode::Require => { vec![".d.ts", ".d.cts", "/index.d.ts", "/index.d.cts"] } - NodeModuleKind::Esm => vec![ + ResolutionMode::Import => vec![ ".d.ts", ".d.mts", "/index.d.ts", @@ -1363,8 +1390,8 @@ impl NodeResolver { self.legacy_index_resolve( package_json.path.parent().unwrap(), maybe_referrer, - referrer_kind, - mode, + resolution_mode, + resolution_kind, ) } @@ -1372,14 +1399,16 @@ impl NodeResolver { &self, directory: &Path, maybe_referrer: Option<&Url>, - referrer_kind: NodeModuleKind, - mode: NodeResolutionMode, + resolution_mode: ResolutionMode, + resolution_kind: NodeResolutionKind, ) -> Result { - let index_file_names = if mode.is_types() { + let index_file_names = if resolution_kind.is_types() { // todo(dsherret): investigate exactly how typescript does this - match referrer_kind { - NodeModuleKind::Cjs => vec!["index.d.ts", "index.d.cts"], - NodeModuleKind::Esm => vec!["index.d.ts", "index.d.mts", "index.d.cts"], + match resolution_mode { + ResolutionMode::Require => vec!["index.d.ts", "index.d.cts"], + ResolutionMode::Import => { + vec!["index.d.ts", "index.d.mts", "index.d.cts"] + } } } else { vec!["index.js"] @@ -1392,7 +1421,7 @@ impl NodeResolver { } } - if mode.is_types() { + if resolution_kind.is_types() { Err( TypesNotFoundError(Box::new(TypesNotFoundErrorData { code_specifier: url_from_file_path(&directory.join("index.js")) diff --git a/tests/specs/node/dynamic_import_and_require_dual/__test__.jsonc b/tests/specs/node/dynamic_import_and_require_dual/__test__.jsonc new file mode 100644 index 0000000000..8e03984f0b --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/__test__.jsonc @@ -0,0 +1,44 @@ +{ + "tests": { + "cjs_check": { + "args": "check index.cts", + "output": "check.out", + "exitCode": 1 + }, + "cjs_run": { + "args": "run index.cts", + "output": "run_cjs.out" + }, + "mjs_run": { + "args": "run index.mjs", + "output": "run_mts.out" + }, + "jsdoc_import_decl": { + "args": "check jsdoc_import_decl.js", + "output": "jsdoc_import_decl.out", + "exitCode": 1 + }, + "resolution_mode_import": { + "args": "check resolution_mode_import.mts", + "output": "resolution_mode_import.out", + "exitCode": 1 + }, + "resolution_mode_require": { + "args": "check resolution_mode_require.mts", + "output": "resolution_mode_require.out", + "exitCode": 1 + }, + "resolution_mode_require_jsdoc": { + "args": "check resolution_mode_require_jsdoc.js", + "output": "resolution_mode_require_jsdoc.out", + "exitCode": 1 + }, + "resolution_mode_require_import_type": { + // waiting on https://github.com/swc-project/swc/issues/9377 + "ignore": true, + "args": "check resolution_mode_require_import_type.ts", + "output": "resolution_mode_require_import_type.out", + "exitCode": 1 + } + } +} diff --git a/tests/specs/node/dynamic_import_and_require_dual/check.out b/tests/specs/node/dynamic_import_and_require_dual/check.out new file mode 100644 index 0000000000..bbea340cce --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/check.out @@ -0,0 +1,5 @@ +Check file:///[WILDLINE]/index.cts +error: TS2322 [ERROR]: Type '"mjs"' is not assignable to type '"value"'. + const value: "value" = mod.kind; + ~~~~~ + at file:///[WILDLINE]/index.cts:3:9 diff --git a/tests/specs/node/dynamic_import_and_require_dual/index.cts b/tests/specs/node/dynamic_import_and_require_dual/index.cts new file mode 100644 index 0000000000..d3bc653c65 --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/index.cts @@ -0,0 +1,8 @@ +async function main() { + const mod = await import("package"); + const value: "value" = mod.kind; + console.log(value); + console.log(mod); +} + +main(); diff --git a/tests/specs/node/dynamic_import_and_require_dual/index.mjs b/tests/specs/node/dynamic_import_and_require_dual/index.mjs new file mode 100644 index 0000000000..76f21fec90 --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/index.mjs @@ -0,0 +1,11 @@ +import { createRequire } from "node:module"; +{ + const mod = await import("package"); + console.log(mod.kind); + console.log(mod); +} +{ + const require = createRequire(import.meta.url); + const mod = require("package"); + console.log(mod); +} diff --git a/tests/specs/node/dynamic_import_and_require_dual/jsdoc_import_decl.js b/tests/specs/node/dynamic_import_and_require_dual/jsdoc_import_decl.js new file mode 100644 index 0000000000..153b9fe3a6 --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/jsdoc_import_decl.js @@ -0,0 +1,12 @@ +// @ts-check + +/** @import { kind } from "package" */ + +/** + * @param {typeof kind} myValue + */ +export function log(myValue) { + console.log(myValue); +} + +log("value"); diff --git a/tests/specs/node/dynamic_import_and_require_dual/jsdoc_import_decl.out b/tests/specs/node/dynamic_import_and_require_dual/jsdoc_import_decl.out new file mode 100644 index 0000000000..655d47117f --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/jsdoc_import_decl.out @@ -0,0 +1,5 @@ +Check file:///[WILDLINE]/jsdoc_import_decl.js +error: TS2345 [ERROR]: Argument of type '"value"' is not assignable to parameter of type '"mjs"'. +log("value"); + ~~~~~~~ + at file:///[WILDLINE]/jsdoc_import_decl.js:12:5 diff --git a/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/mod.d.mts b/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/mod.d.mts new file mode 100644 index 0000000000..bd4baa5919 --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/mod.d.mts @@ -0,0 +1 @@ +export const kind: "mjs"; diff --git a/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/mod.mjs b/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/mod.mjs new file mode 100644 index 0000000000..cd2f5f05cb --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/mod.mjs @@ -0,0 +1 @@ +export const kind = "esm"; diff --git a/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/package.json b/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/package.json new file mode 100644 index 0000000000..f4adc7925e --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/package.json @@ -0,0 +1,11 @@ +{ + "name": "package", + "version": "1.0.0", + "type": "module", + "exports": { + ".": { + "import": "./mod.mjs", + "require": "./require.cjs" + } + } +} \ No newline at end of file diff --git a/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/require.cjs b/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/require.cjs new file mode 100644 index 0000000000..2b7ebd9693 --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/require.cjs @@ -0,0 +1 @@ +module.exports.kind = "cjs"; diff --git a/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/require.d.cts b/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/require.d.cts new file mode 100644 index 0000000000..604f6136b4 --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/node_modules/package/require.d.cts @@ -0,0 +1 @@ +export const kind: "cjs"; diff --git a/tests/specs/node/dynamic_import_and_require_dual/package.json b/tests/specs/node/dynamic_import_and_require_dual/package.json new file mode 100644 index 0000000000..ab1ab85da2 --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/package.json @@ -0,0 +1,6 @@ +{ + "type": "commonjs", + "dependencies": { + "package": "*" + } +} diff --git a/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_import.mts b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_import.mts new file mode 100644 index 0000000000..86b06fb832 --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_import.mts @@ -0,0 +1,6 @@ +import type { kind } from "package" with { + "resolution-mode": "import", +}; + +const test: typeof kind = "other"; +console.log(test); diff --git a/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_import.out b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_import.out new file mode 100644 index 0000000000..735cfe53ac --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_import.out @@ -0,0 +1,5 @@ +Check file:///[WILDLINE]/resolution_mode_import.mts +error: TS2322 [ERROR]: Type '"other"' is not assignable to type '"mjs"'. +const test: typeof kind = "other"; + ~~~~ + at file:///[WILDLINE]/resolution_mode_import.mts:5:7 diff --git a/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require.mts b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require.mts new file mode 100644 index 0000000000..1695f29ade --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require.mts @@ -0,0 +1,6 @@ +import type { kind } from "package" with { + "resolution-mode": "require", +}; + +const test: typeof kind = "other"; +console.log(test); diff --git a/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require.out b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require.out new file mode 100644 index 0000000000..32cdd86f0d --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require.out @@ -0,0 +1,5 @@ +Check file:///[WILDLINE]/resolution_mode_require.mts +error: TS2322 [ERROR]: Type '"other"' is not assignable to type '"cjs"'. +const test: typeof kind = "other"; + ~~~~ + at file:///[WILDLINE]/resolution_mode_require.mts:5:7 diff --git a/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_import_type.out b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_import_type.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_import_type.ts b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_import_type.ts new file mode 100644 index 0000000000..295bab0e9c --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_import_type.ts @@ -0,0 +1,5 @@ +// deno-fmt-ignore-file +type Value = typeof import("package", { with: { 'resolution-mode': 'require' } }).kind; + +const value: Value = "value"; +console.log(value); \ No newline at end of file diff --git a/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_jsdoc.js b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_jsdoc.js new file mode 100644 index 0000000000..0d0040513f --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_jsdoc.js @@ -0,0 +1,12 @@ +// @ts-check + +/** @import { kind } from "package" with { 'resolution-mode': 'require' } */ + +/** + * @param {typeof kind} myValue + */ +export function log(myValue) { + console.log(myValue); +} + +log("value"); diff --git a/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_jsdoc.out b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_jsdoc.out new file mode 100644 index 0000000000..924681fe80 --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/resolution_mode_require_jsdoc.out @@ -0,0 +1,5 @@ +Check file:///[WILDLINE]/resolution_mode_require_jsdoc.js +error: TS2345 [ERROR]: Argument of type '"value"' is not assignable to parameter of type '"cjs"'. +log("value"); + ~~~~~~~ + at file:///[WILDLINE]/resolution_mode_require_jsdoc.js:12:5 diff --git a/tests/specs/node/dynamic_import_and_require_dual/run_cjs.out b/tests/specs/node/dynamic_import_and_require_dual/run_cjs.out new file mode 100644 index 0000000000..d64c24da5d --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/run_cjs.out @@ -0,0 +1,2 @@ +esm +[Module: null prototype] { kind: "esm" } diff --git a/tests/specs/node/dynamic_import_and_require_dual/run_mts.out b/tests/specs/node/dynamic_import_and_require_dual/run_mts.out new file mode 100644 index 0000000000..afd3f2e277 --- /dev/null +++ b/tests/specs/node/dynamic_import_and_require_dual/run_mts.out @@ -0,0 +1,3 @@ +esm +[Module: null prototype] { kind: "esm" } +{ kind: "cjs" } diff --git a/tests/specs/npm/info_chalk_display/__test__.jsonc b/tests/specs/npm/info_chalk_display/__test__.jsonc index 54b5b74396..717f1f9a15 100644 --- a/tests/specs/npm/info_chalk_display/__test__.jsonc +++ b/tests/specs/npm/info_chalk_display/__test__.jsonc @@ -1,5 +1,5 @@ { - "args": "info --quiet cjs_with_deps/main.js", - "output": "cjs_with_deps/main_info.out", + "args": "info --quiet main.js", + "output": "main_info.out", "exitCode": 0 } diff --git a/tests/specs/npm/info_chalk_display/cjs_with_deps/main.out b/tests/specs/npm/info_chalk_display/cjs_with_deps/main.out deleted file mode 100644 index 7051c23953..0000000000 --- a/tests/specs/npm/info_chalk_display/cjs_with_deps/main.out +++ /dev/null @@ -1,33 +0,0 @@ -[UNORDERED_START] -Download http://localhost:4260/chalk -Download http://localhost:4260/chai -Download http://localhost:4260/ansi-styles -Download http://localhost:4260/supports-color -Download http://localhost:4260/assertion-error -Download http://localhost:4260/check-error -Download http://localhost:4260/deep-eql -Download http://localhost:4260/get-func-name -Download http://localhost:4260/loupe -Download http://localhost:4260/pathval -Download http://localhost:4260/type-detect -Download http://localhost:4260/color-convert -Download http://localhost:4260/has-flag -Download http://localhost:4260/color-name -[UNORDERED_END] -[UNORDERED_START] -Download http://localhost:4260/ansi-styles/ansi-styles-4.3.0.tgz -Download http://localhost:4260/assertion-error/assertion-error-1.1.0.tgz -Download http://localhost:4260/chai/chai-4.3.6.tgz -Download http://localhost:4260/chalk/chalk-4.1.2.tgz -Download http://localhost:4260/check-error/check-error-1.0.2.tgz -Download http://localhost:4260/color-convert/color-convert-2.0.1.tgz -Download http://localhost:4260/color-name/color-name-1.1.4.tgz -Download http://localhost:4260/deep-eql/deep-eql-3.0.1.tgz -Download http://localhost:4260/get-func-name/get-func-name-2.0.0.tgz -Download http://localhost:4260/has-flag/has-flag-4.0.0.tgz -Download http://localhost:4260/loupe/loupe-2.3.4.tgz -Download http://localhost:4260/pathval/pathval-1.1.1.tgz -Download http://localhost:4260/supports-color/supports-color-7.2.0.tgz -Download http://localhost:4260/type-detect/type-detect-4.0.8.tgz -[UNORDERED_END] -chalk cjs loads diff --git a/tests/specs/npm/info_chalk_display/cjs_with_deps/main_info_json.out b/tests/specs/npm/info_chalk_display/cjs_with_deps/main_info_json.out deleted file mode 100644 index 137b9f8ce5..0000000000 --- a/tests/specs/npm/info_chalk_display/cjs_with_deps/main_info_json.out +++ /dev/null @@ -1,148 +0,0 @@ -{ - "version": 1, - "roots": [ - "file://[WILDCARD]/main.js" - ], - "modules": [ - { - "kind": "esm", - "dependencies": [ - { - "specifier": "npm:chalk@4", - "code": { - "specifier": "npm:chalk@4", - "span": { - "start": { - "line": 0, - "character": 18 - }, - "end": { - "line": 0, - "character": 31 - } - } - }, - "npmPackage": "chalk@4.1.2" - }, - { - "specifier": "npm:chai@4.3", - "code": { - "specifier": "npm:chai@4.3", - "span": { - "start": { - "line": 1, - "character": 23 - }, - "end": { - "line": 1, - "character": 37 - } - } - }, - "npmPackage": "chai@4.3.6" - } - ], - "local": "[WILDCARD]main.js", - "size": 325, - "mediaType": "JavaScript", - "specifier": "[WILDCARD]/main.js" - } - ], - "redirects": { - "npm:chai@4.3": "npm:/chai@4.3.6", - "npm:chalk@4": "npm:/chalk@4.1.2" - }, - "npmPackages": { - "ansi-styles@4.3.0": { - "name": "ansi-styles", - "version": "4.3.0", - "dependencies": [ - "color-convert@2.0.1" - ] - }, - "assertion-error@1.1.0": { - "name": "assertion-error", - "version": "1.1.0", - "dependencies": [] - }, - "chai@4.3.6": { - "name": "chai", - "version": "4.3.6", - "dependencies": [ - "assertion-error@1.1.0", - "check-error@1.0.2", - "deep-eql@3.0.1", - "get-func-name@2.0.0", - "loupe@2.3.4", - "pathval@1.1.1", - "type-detect@4.0.8" - ] - }, - "chalk@4.1.2": { - "name": "chalk", - "version": "4.1.2", - "dependencies": [ - "ansi-styles@4.3.0", - "supports-color@7.2.0" - ] - }, - "check-error@1.0.2": { - "name": "check-error", - "version": "1.0.2", - "dependencies": [] - }, - "color-convert@2.0.1": { - "name": "color-convert", - "version": "2.0.1", - "dependencies": [ - "color-name@1.1.4" - ] - }, - "color-name@1.1.4": { - "name": "color-name", - "version": "1.1.4", - "dependencies": [] - }, - "deep-eql@3.0.1": { - "name": "deep-eql", - "version": "3.0.1", - "dependencies": [ - "type-detect@4.0.8" - ] - }, - "get-func-name@2.0.0": { - "name": "get-func-name", - "version": "2.0.0", - "dependencies": [] - }, - "has-flag@4.0.0": { - "name": "has-flag", - "version": "4.0.0", - "dependencies": [] - }, - "loupe@2.3.4": { - "name": "loupe", - "version": "2.3.4", - "dependencies": [ - "get-func-name@2.0.0" - ] - }, - "pathval@1.1.1": { - "name": "pathval", - "version": "1.1.1", - "dependencies": [] - }, - "supports-color@7.2.0": { - "name": "supports-color", - "version": "7.2.0", - "dependencies": [ - "has-flag@4.0.0" - ] - }, - "type-detect@4.0.8": { - "name": "type-detect", - "version": "4.0.8", - "dependencies": [] - } - } -} diff --git a/tests/specs/npm/info_chalk_display/cjs_with_deps/main_node_modules.out b/tests/specs/npm/info_chalk_display/cjs_with_deps/main_node_modules.out deleted file mode 100644 index 1ab3679521..0000000000 --- a/tests/specs/npm/info_chalk_display/cjs_with_deps/main_node_modules.out +++ /dev/null @@ -1,47 +0,0 @@ -[UNORDERED_START] -Download http://localhost:4260/chalk -Download http://localhost:4260/chai -Download http://localhost:4260/ansi-styles -Download http://localhost:4260/supports-color -Download http://localhost:4260/assertion-error -Download http://localhost:4260/check-error -Download http://localhost:4260/deep-eql -Download http://localhost:4260/get-func-name -Download http://localhost:4260/loupe -Download http://localhost:4260/pathval -Download http://localhost:4260/type-detect -Download http://localhost:4260/color-convert -Download http://localhost:4260/has-flag -Download http://localhost:4260/color-name -[UNORDERED_END] -[UNORDERED_START] -Download http://localhost:4260/ansi-styles/ansi-styles-4.3.0.tgz -Initialize ansi-styles@4.3.0 -Download http://localhost:4260/assertion-error/assertion-error-1.1.0.tgz -Initialize assertion-error@1.1.0 -Download http://localhost:4260/chai/chai-4.3.6.tgz -Initialize chai@4.3.6 -Download http://localhost:4260/chalk/chalk-4.1.2.tgz -Initialize chalk@4.1.2 -Download http://localhost:4260/check-error/check-error-1.0.2.tgz -Initialize check-error@1.0.2 -Download http://localhost:4260/color-convert/color-convert-2.0.1.tgz -Initialize color-convert@2.0.1 -Download http://localhost:4260/color-name/color-name-1.1.4.tgz -Initialize color-name@1.1.4 -Download http://localhost:4260/deep-eql/deep-eql-3.0.1.tgz -Initialize deep-eql@3.0.1 -Download http://localhost:4260/get-func-name/get-func-name-2.0.0.tgz -Initialize get-func-name@2.0.0 -Download http://localhost:4260/has-flag/has-flag-4.0.0.tgz -Initialize has-flag@4.0.0 -Download http://localhost:4260/loupe/loupe-2.3.4.tgz -Initialize loupe@2.3.4 -Download http://localhost:4260/pathval/pathval-1.1.1.tgz -Initialize pathval@1.1.1 -Download http://localhost:4260/supports-color/supports-color-7.2.0.tgz -Initialize supports-color@7.2.0 -Download http://localhost:4260/type-detect/type-detect-4.0.8.tgz -Initialize type-detect@4.0.8 -[UNORDERED_END] -chalk cjs loads diff --git a/tests/specs/npm/info_chalk_display/cjs_with_deps/main.js b/tests/specs/npm/info_chalk_display/main.js similarity index 100% rename from tests/specs/npm/info_chalk_display/cjs_with_deps/main.js rename to tests/specs/npm/info_chalk_display/main.js diff --git a/tests/specs/npm/info_chalk_json/cjs_with_deps/main_info.out b/tests/specs/npm/info_chalk_display/main_info.out similarity index 94% rename from tests/specs/npm/info_chalk_json/cjs_with_deps/main_info.out rename to tests/specs/npm/info_chalk_display/main_info.out index 8e37c88eb0..f1271ec1f1 100644 --- a/tests/specs/npm/info_chalk_json/cjs_with_deps/main_info.out +++ b/tests/specs/npm/info_chalk_display/main_info.out @@ -3,7 +3,7 @@ type: JavaScript dependencies: 14 unique size: [WILDCARD] -file:///[WILDCARD]/cjs_with_deps/main.js ([WILDCARD]) +file:///[WILDCARD]/main.js ([WILDCARD]) ├─┬ npm:/chalk@4.1.2 ([WILDCARD]) │ ├─┬ npm:/ansi-styles@4.3.0 ([WILDCARD]) │ │ └─┬ npm:/color-convert@2.0.1 ([WILDCARD]) diff --git a/tests/specs/npm/info_chalk_display_node_modules_dir/__test__.jsonc b/tests/specs/npm/info_chalk_display_node_modules_dir/__test__.jsonc index 4358f64883..b5c36dc6c1 100644 --- a/tests/specs/npm/info_chalk_display_node_modules_dir/__test__.jsonc +++ b/tests/specs/npm/info_chalk_display_node_modules_dir/__test__.jsonc @@ -1,6 +1,6 @@ { "tempDir": true, - "args": "info --quiet --node-modules-dir cjs_with_deps/main.js", - "output": "cjs_with_deps/main_info.out", + "args": "info --quiet --node-modules-dir main.js", + "output": "main_info.out", "exitCode": 0 } diff --git a/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main.out b/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main.out deleted file mode 100644 index 7051c23953..0000000000 --- a/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main.out +++ /dev/null @@ -1,33 +0,0 @@ -[UNORDERED_START] -Download http://localhost:4260/chalk -Download http://localhost:4260/chai -Download http://localhost:4260/ansi-styles -Download http://localhost:4260/supports-color -Download http://localhost:4260/assertion-error -Download http://localhost:4260/check-error -Download http://localhost:4260/deep-eql -Download http://localhost:4260/get-func-name -Download http://localhost:4260/loupe -Download http://localhost:4260/pathval -Download http://localhost:4260/type-detect -Download http://localhost:4260/color-convert -Download http://localhost:4260/has-flag -Download http://localhost:4260/color-name -[UNORDERED_END] -[UNORDERED_START] -Download http://localhost:4260/ansi-styles/ansi-styles-4.3.0.tgz -Download http://localhost:4260/assertion-error/assertion-error-1.1.0.tgz -Download http://localhost:4260/chai/chai-4.3.6.tgz -Download http://localhost:4260/chalk/chalk-4.1.2.tgz -Download http://localhost:4260/check-error/check-error-1.0.2.tgz -Download http://localhost:4260/color-convert/color-convert-2.0.1.tgz -Download http://localhost:4260/color-name/color-name-1.1.4.tgz -Download http://localhost:4260/deep-eql/deep-eql-3.0.1.tgz -Download http://localhost:4260/get-func-name/get-func-name-2.0.0.tgz -Download http://localhost:4260/has-flag/has-flag-4.0.0.tgz -Download http://localhost:4260/loupe/loupe-2.3.4.tgz -Download http://localhost:4260/pathval/pathval-1.1.1.tgz -Download http://localhost:4260/supports-color/supports-color-7.2.0.tgz -Download http://localhost:4260/type-detect/type-detect-4.0.8.tgz -[UNORDERED_END] -chalk cjs loads diff --git a/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_info.out b/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_info.out deleted file mode 100644 index 8e37c88eb0..0000000000 --- a/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_info.out +++ /dev/null @@ -1,22 +0,0 @@ -local: [WILDCARD]main.js -type: JavaScript -dependencies: 14 unique -size: [WILDCARD] - -file:///[WILDCARD]/cjs_with_deps/main.js ([WILDCARD]) -├─┬ npm:/chalk@4.1.2 ([WILDCARD]) -│ ├─┬ npm:/ansi-styles@4.3.0 ([WILDCARD]) -│ │ └─┬ npm:/color-convert@2.0.1 ([WILDCARD]) -│ │ └── npm:/color-name@1.1.4 ([WILDCARD]) -│ └─┬ npm:/supports-color@7.2.0 ([WILDCARD]) -│ └── npm:/has-flag@4.0.0 ([WILDCARD]) -└─┬ npm:/chai@4.3.6 ([WILDCARD]) - ├── npm:/assertion-error@1.1.0 ([WILDCARD]) - ├── npm:/check-error@1.0.2 ([WILDCARD]) - ├─┬ npm:/deep-eql@3.0.1 ([WILDCARD]) - │ └── npm:/type-detect@4.0.8 ([WILDCARD]) - ├── npm:/get-func-name@2.0.0 ([WILDCARD]) - ├─┬ npm:/loupe@2.3.4 ([WILDCARD]) - │ └── npm:/get-func-name@2.0.0 ([WILDCARD]) - ├── npm:/pathval@1.1.1 ([WILDCARD]) - └── npm:/type-detect@4.0.8 ([WILDCARD]) diff --git a/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_info_json.out b/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_info_json.out deleted file mode 100644 index 137b9f8ce5..0000000000 --- a/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_info_json.out +++ /dev/null @@ -1,148 +0,0 @@ -{ - "version": 1, - "roots": [ - "file://[WILDCARD]/main.js" - ], - "modules": [ - { - "kind": "esm", - "dependencies": [ - { - "specifier": "npm:chalk@4", - "code": { - "specifier": "npm:chalk@4", - "span": { - "start": { - "line": 0, - "character": 18 - }, - "end": { - "line": 0, - "character": 31 - } - } - }, - "npmPackage": "chalk@4.1.2" - }, - { - "specifier": "npm:chai@4.3", - "code": { - "specifier": "npm:chai@4.3", - "span": { - "start": { - "line": 1, - "character": 23 - }, - "end": { - "line": 1, - "character": 37 - } - } - }, - "npmPackage": "chai@4.3.6" - } - ], - "local": "[WILDCARD]main.js", - "size": 325, - "mediaType": "JavaScript", - "specifier": "[WILDCARD]/main.js" - } - ], - "redirects": { - "npm:chai@4.3": "npm:/chai@4.3.6", - "npm:chalk@4": "npm:/chalk@4.1.2" - }, - "npmPackages": { - "ansi-styles@4.3.0": { - "name": "ansi-styles", - "version": "4.3.0", - "dependencies": [ - "color-convert@2.0.1" - ] - }, - "assertion-error@1.1.0": { - "name": "assertion-error", - "version": "1.1.0", - "dependencies": [] - }, - "chai@4.3.6": { - "name": "chai", - "version": "4.3.6", - "dependencies": [ - "assertion-error@1.1.0", - "check-error@1.0.2", - "deep-eql@3.0.1", - "get-func-name@2.0.0", - "loupe@2.3.4", - "pathval@1.1.1", - "type-detect@4.0.8" - ] - }, - "chalk@4.1.2": { - "name": "chalk", - "version": "4.1.2", - "dependencies": [ - "ansi-styles@4.3.0", - "supports-color@7.2.0" - ] - }, - "check-error@1.0.2": { - "name": "check-error", - "version": "1.0.2", - "dependencies": [] - }, - "color-convert@2.0.1": { - "name": "color-convert", - "version": "2.0.1", - "dependencies": [ - "color-name@1.1.4" - ] - }, - "color-name@1.1.4": { - "name": "color-name", - "version": "1.1.4", - "dependencies": [] - }, - "deep-eql@3.0.1": { - "name": "deep-eql", - "version": "3.0.1", - "dependencies": [ - "type-detect@4.0.8" - ] - }, - "get-func-name@2.0.0": { - "name": "get-func-name", - "version": "2.0.0", - "dependencies": [] - }, - "has-flag@4.0.0": { - "name": "has-flag", - "version": "4.0.0", - "dependencies": [] - }, - "loupe@2.3.4": { - "name": "loupe", - "version": "2.3.4", - "dependencies": [ - "get-func-name@2.0.0" - ] - }, - "pathval@1.1.1": { - "name": "pathval", - "version": "1.1.1", - "dependencies": [] - }, - "supports-color@7.2.0": { - "name": "supports-color", - "version": "7.2.0", - "dependencies": [ - "has-flag@4.0.0" - ] - }, - "type-detect@4.0.8": { - "name": "type-detect", - "version": "4.0.8", - "dependencies": [] - } - } -} diff --git a/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_node_modules.out b/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_node_modules.out deleted file mode 100644 index 1ab3679521..0000000000 --- a/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main_node_modules.out +++ /dev/null @@ -1,47 +0,0 @@ -[UNORDERED_START] -Download http://localhost:4260/chalk -Download http://localhost:4260/chai -Download http://localhost:4260/ansi-styles -Download http://localhost:4260/supports-color -Download http://localhost:4260/assertion-error -Download http://localhost:4260/check-error -Download http://localhost:4260/deep-eql -Download http://localhost:4260/get-func-name -Download http://localhost:4260/loupe -Download http://localhost:4260/pathval -Download http://localhost:4260/type-detect -Download http://localhost:4260/color-convert -Download http://localhost:4260/has-flag -Download http://localhost:4260/color-name -[UNORDERED_END] -[UNORDERED_START] -Download http://localhost:4260/ansi-styles/ansi-styles-4.3.0.tgz -Initialize ansi-styles@4.3.0 -Download http://localhost:4260/assertion-error/assertion-error-1.1.0.tgz -Initialize assertion-error@1.1.0 -Download http://localhost:4260/chai/chai-4.3.6.tgz -Initialize chai@4.3.6 -Download http://localhost:4260/chalk/chalk-4.1.2.tgz -Initialize chalk@4.1.2 -Download http://localhost:4260/check-error/check-error-1.0.2.tgz -Initialize check-error@1.0.2 -Download http://localhost:4260/color-convert/color-convert-2.0.1.tgz -Initialize color-convert@2.0.1 -Download http://localhost:4260/color-name/color-name-1.1.4.tgz -Initialize color-name@1.1.4 -Download http://localhost:4260/deep-eql/deep-eql-3.0.1.tgz -Initialize deep-eql@3.0.1 -Download http://localhost:4260/get-func-name/get-func-name-2.0.0.tgz -Initialize get-func-name@2.0.0 -Download http://localhost:4260/has-flag/has-flag-4.0.0.tgz -Initialize has-flag@4.0.0 -Download http://localhost:4260/loupe/loupe-2.3.4.tgz -Initialize loupe@2.3.4 -Download http://localhost:4260/pathval/pathval-1.1.1.tgz -Initialize pathval@1.1.1 -Download http://localhost:4260/supports-color/supports-color-7.2.0.tgz -Initialize supports-color@7.2.0 -Download http://localhost:4260/type-detect/type-detect-4.0.8.tgz -Initialize type-detect@4.0.8 -[UNORDERED_END] -chalk cjs loads diff --git a/tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main.js b/tests/specs/npm/info_chalk_display_node_modules_dir/main.js similarity index 100% rename from tests/specs/npm/info_chalk_display_node_modules_dir/cjs_with_deps/main.js rename to tests/specs/npm/info_chalk_display_node_modules_dir/main.js diff --git a/tests/specs/npm/info_chalk_display/cjs_with_deps/main_info.out b/tests/specs/npm/info_chalk_display_node_modules_dir/main_info.out similarity index 94% rename from tests/specs/npm/info_chalk_display/cjs_with_deps/main_info.out rename to tests/specs/npm/info_chalk_display_node_modules_dir/main_info.out index 8e37c88eb0..f1271ec1f1 100644 --- a/tests/specs/npm/info_chalk_display/cjs_with_deps/main_info.out +++ b/tests/specs/npm/info_chalk_display_node_modules_dir/main_info.out @@ -3,7 +3,7 @@ type: JavaScript dependencies: 14 unique size: [WILDCARD] -file:///[WILDCARD]/cjs_with_deps/main.js ([WILDCARD]) +file:///[WILDCARD]/main.js ([WILDCARD]) ├─┬ npm:/chalk@4.1.2 ([WILDCARD]) │ ├─┬ npm:/ansi-styles@4.3.0 ([WILDCARD]) │ │ └─┬ npm:/color-convert@2.0.1 ([WILDCARD]) diff --git a/tests/specs/npm/info_chalk_json/__test__.jsonc b/tests/specs/npm/info_chalk_json/__test__.jsonc index c6e65db94b..c5a4a95bf7 100644 --- a/tests/specs/npm/info_chalk_json/__test__.jsonc +++ b/tests/specs/npm/info_chalk_json/__test__.jsonc @@ -1,5 +1,5 @@ { - "args": "info --quiet --json cjs_with_deps/main.js", - "output": "cjs_with_deps/main_info_json.out", + "args": "info --quiet --json main.js", + "output": "main_info_json.out", "exitCode": 0 } diff --git a/tests/specs/npm/info_chalk_json/cjs_with_deps/main.out b/tests/specs/npm/info_chalk_json/cjs_with_deps/main.out deleted file mode 100644 index 7051c23953..0000000000 --- a/tests/specs/npm/info_chalk_json/cjs_with_deps/main.out +++ /dev/null @@ -1,33 +0,0 @@ -[UNORDERED_START] -Download http://localhost:4260/chalk -Download http://localhost:4260/chai -Download http://localhost:4260/ansi-styles -Download http://localhost:4260/supports-color -Download http://localhost:4260/assertion-error -Download http://localhost:4260/check-error -Download http://localhost:4260/deep-eql -Download http://localhost:4260/get-func-name -Download http://localhost:4260/loupe -Download http://localhost:4260/pathval -Download http://localhost:4260/type-detect -Download http://localhost:4260/color-convert -Download http://localhost:4260/has-flag -Download http://localhost:4260/color-name -[UNORDERED_END] -[UNORDERED_START] -Download http://localhost:4260/ansi-styles/ansi-styles-4.3.0.tgz -Download http://localhost:4260/assertion-error/assertion-error-1.1.0.tgz -Download http://localhost:4260/chai/chai-4.3.6.tgz -Download http://localhost:4260/chalk/chalk-4.1.2.tgz -Download http://localhost:4260/check-error/check-error-1.0.2.tgz -Download http://localhost:4260/color-convert/color-convert-2.0.1.tgz -Download http://localhost:4260/color-name/color-name-1.1.4.tgz -Download http://localhost:4260/deep-eql/deep-eql-3.0.1.tgz -Download http://localhost:4260/get-func-name/get-func-name-2.0.0.tgz -Download http://localhost:4260/has-flag/has-flag-4.0.0.tgz -Download http://localhost:4260/loupe/loupe-2.3.4.tgz -Download http://localhost:4260/pathval/pathval-1.1.1.tgz -Download http://localhost:4260/supports-color/supports-color-7.2.0.tgz -Download http://localhost:4260/type-detect/type-detect-4.0.8.tgz -[UNORDERED_END] -chalk cjs loads diff --git a/tests/specs/npm/info_chalk_json/cjs_with_deps/main_node_modules.out b/tests/specs/npm/info_chalk_json/cjs_with_deps/main_node_modules.out deleted file mode 100644 index 1ab3679521..0000000000 --- a/tests/specs/npm/info_chalk_json/cjs_with_deps/main_node_modules.out +++ /dev/null @@ -1,47 +0,0 @@ -[UNORDERED_START] -Download http://localhost:4260/chalk -Download http://localhost:4260/chai -Download http://localhost:4260/ansi-styles -Download http://localhost:4260/supports-color -Download http://localhost:4260/assertion-error -Download http://localhost:4260/check-error -Download http://localhost:4260/deep-eql -Download http://localhost:4260/get-func-name -Download http://localhost:4260/loupe -Download http://localhost:4260/pathval -Download http://localhost:4260/type-detect -Download http://localhost:4260/color-convert -Download http://localhost:4260/has-flag -Download http://localhost:4260/color-name -[UNORDERED_END] -[UNORDERED_START] -Download http://localhost:4260/ansi-styles/ansi-styles-4.3.0.tgz -Initialize ansi-styles@4.3.0 -Download http://localhost:4260/assertion-error/assertion-error-1.1.0.tgz -Initialize assertion-error@1.1.0 -Download http://localhost:4260/chai/chai-4.3.6.tgz -Initialize chai@4.3.6 -Download http://localhost:4260/chalk/chalk-4.1.2.tgz -Initialize chalk@4.1.2 -Download http://localhost:4260/check-error/check-error-1.0.2.tgz -Initialize check-error@1.0.2 -Download http://localhost:4260/color-convert/color-convert-2.0.1.tgz -Initialize color-convert@2.0.1 -Download http://localhost:4260/color-name/color-name-1.1.4.tgz -Initialize color-name@1.1.4 -Download http://localhost:4260/deep-eql/deep-eql-3.0.1.tgz -Initialize deep-eql@3.0.1 -Download http://localhost:4260/get-func-name/get-func-name-2.0.0.tgz -Initialize get-func-name@2.0.0 -Download http://localhost:4260/has-flag/has-flag-4.0.0.tgz -Initialize has-flag@4.0.0 -Download http://localhost:4260/loupe/loupe-2.3.4.tgz -Initialize loupe@2.3.4 -Download http://localhost:4260/pathval/pathval-1.1.1.tgz -Initialize pathval@1.1.1 -Download http://localhost:4260/supports-color/supports-color-7.2.0.tgz -Initialize supports-color@7.2.0 -Download http://localhost:4260/type-detect/type-detect-4.0.8.tgz -Initialize type-detect@4.0.8 -[UNORDERED_END] -chalk cjs loads diff --git a/tests/specs/npm/info_chalk_json/cjs_with_deps/main.js b/tests/specs/npm/info_chalk_json/main.js similarity index 100% rename from tests/specs/npm/info_chalk_json/cjs_with_deps/main.js rename to tests/specs/npm/info_chalk_json/main.js diff --git a/tests/specs/npm/info_chalk_json/cjs_with_deps/main_info_json.out b/tests/specs/npm/info_chalk_json/main_info_json.out similarity index 100% rename from tests/specs/npm/info_chalk_json/cjs_with_deps/main_info_json.out rename to tests/specs/npm/info_chalk_json/main_info_json.out diff --git a/tests/specs/npm/info_chalk_json_node_modules_dir/__test__.jsonc b/tests/specs/npm/info_chalk_json_node_modules_dir/__test__.jsonc index 29c5e8bdff..ed9a96606e 100644 --- a/tests/specs/npm/info_chalk_json_node_modules_dir/__test__.jsonc +++ b/tests/specs/npm/info_chalk_json_node_modules_dir/__test__.jsonc @@ -1,6 +1,6 @@ { "tempDir": true, - "args": "info --quiet --node-modules-dir --json cjs_with_deps/main.js", - "output": "cjs_with_deps/main_info_json.out", + "args": "info --quiet --node-modules-dir --json main.js", + "output": "main_info_json.out", "exitCode": 0 } diff --git a/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main.out b/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main.out deleted file mode 100644 index 7051c23953..0000000000 --- a/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main.out +++ /dev/null @@ -1,33 +0,0 @@ -[UNORDERED_START] -Download http://localhost:4260/chalk -Download http://localhost:4260/chai -Download http://localhost:4260/ansi-styles -Download http://localhost:4260/supports-color -Download http://localhost:4260/assertion-error -Download http://localhost:4260/check-error -Download http://localhost:4260/deep-eql -Download http://localhost:4260/get-func-name -Download http://localhost:4260/loupe -Download http://localhost:4260/pathval -Download http://localhost:4260/type-detect -Download http://localhost:4260/color-convert -Download http://localhost:4260/has-flag -Download http://localhost:4260/color-name -[UNORDERED_END] -[UNORDERED_START] -Download http://localhost:4260/ansi-styles/ansi-styles-4.3.0.tgz -Download http://localhost:4260/assertion-error/assertion-error-1.1.0.tgz -Download http://localhost:4260/chai/chai-4.3.6.tgz -Download http://localhost:4260/chalk/chalk-4.1.2.tgz -Download http://localhost:4260/check-error/check-error-1.0.2.tgz -Download http://localhost:4260/color-convert/color-convert-2.0.1.tgz -Download http://localhost:4260/color-name/color-name-1.1.4.tgz -Download http://localhost:4260/deep-eql/deep-eql-3.0.1.tgz -Download http://localhost:4260/get-func-name/get-func-name-2.0.0.tgz -Download http://localhost:4260/has-flag/has-flag-4.0.0.tgz -Download http://localhost:4260/loupe/loupe-2.3.4.tgz -Download http://localhost:4260/pathval/pathval-1.1.1.tgz -Download http://localhost:4260/supports-color/supports-color-7.2.0.tgz -Download http://localhost:4260/type-detect/type-detect-4.0.8.tgz -[UNORDERED_END] -chalk cjs loads diff --git a/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_info.out b/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_info.out deleted file mode 100644 index 8e37c88eb0..0000000000 --- a/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_info.out +++ /dev/null @@ -1,22 +0,0 @@ -local: [WILDCARD]main.js -type: JavaScript -dependencies: 14 unique -size: [WILDCARD] - -file:///[WILDCARD]/cjs_with_deps/main.js ([WILDCARD]) -├─┬ npm:/chalk@4.1.2 ([WILDCARD]) -│ ├─┬ npm:/ansi-styles@4.3.0 ([WILDCARD]) -│ │ └─┬ npm:/color-convert@2.0.1 ([WILDCARD]) -│ │ └── npm:/color-name@1.1.4 ([WILDCARD]) -│ └─┬ npm:/supports-color@7.2.0 ([WILDCARD]) -│ └── npm:/has-flag@4.0.0 ([WILDCARD]) -└─┬ npm:/chai@4.3.6 ([WILDCARD]) - ├── npm:/assertion-error@1.1.0 ([WILDCARD]) - ├── npm:/check-error@1.0.2 ([WILDCARD]) - ├─┬ npm:/deep-eql@3.0.1 ([WILDCARD]) - │ └── npm:/type-detect@4.0.8 ([WILDCARD]) - ├── npm:/get-func-name@2.0.0 ([WILDCARD]) - ├─┬ npm:/loupe@2.3.4 ([WILDCARD]) - │ └── npm:/get-func-name@2.0.0 ([WILDCARD]) - ├── npm:/pathval@1.1.1 ([WILDCARD]) - └── npm:/type-detect@4.0.8 ([WILDCARD]) diff --git a/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_node_modules.out b/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_node_modules.out deleted file mode 100644 index 1ab3679521..0000000000 --- a/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_node_modules.out +++ /dev/null @@ -1,47 +0,0 @@ -[UNORDERED_START] -Download http://localhost:4260/chalk -Download http://localhost:4260/chai -Download http://localhost:4260/ansi-styles -Download http://localhost:4260/supports-color -Download http://localhost:4260/assertion-error -Download http://localhost:4260/check-error -Download http://localhost:4260/deep-eql -Download http://localhost:4260/get-func-name -Download http://localhost:4260/loupe -Download http://localhost:4260/pathval -Download http://localhost:4260/type-detect -Download http://localhost:4260/color-convert -Download http://localhost:4260/has-flag -Download http://localhost:4260/color-name -[UNORDERED_END] -[UNORDERED_START] -Download http://localhost:4260/ansi-styles/ansi-styles-4.3.0.tgz -Initialize ansi-styles@4.3.0 -Download http://localhost:4260/assertion-error/assertion-error-1.1.0.tgz -Initialize assertion-error@1.1.0 -Download http://localhost:4260/chai/chai-4.3.6.tgz -Initialize chai@4.3.6 -Download http://localhost:4260/chalk/chalk-4.1.2.tgz -Initialize chalk@4.1.2 -Download http://localhost:4260/check-error/check-error-1.0.2.tgz -Initialize check-error@1.0.2 -Download http://localhost:4260/color-convert/color-convert-2.0.1.tgz -Initialize color-convert@2.0.1 -Download http://localhost:4260/color-name/color-name-1.1.4.tgz -Initialize color-name@1.1.4 -Download http://localhost:4260/deep-eql/deep-eql-3.0.1.tgz -Initialize deep-eql@3.0.1 -Download http://localhost:4260/get-func-name/get-func-name-2.0.0.tgz -Initialize get-func-name@2.0.0 -Download http://localhost:4260/has-flag/has-flag-4.0.0.tgz -Initialize has-flag@4.0.0 -Download http://localhost:4260/loupe/loupe-2.3.4.tgz -Initialize loupe@2.3.4 -Download http://localhost:4260/pathval/pathval-1.1.1.tgz -Initialize pathval@1.1.1 -Download http://localhost:4260/supports-color/supports-color-7.2.0.tgz -Initialize supports-color@7.2.0 -Download http://localhost:4260/type-detect/type-detect-4.0.8.tgz -Initialize type-detect@4.0.8 -[UNORDERED_END] -chalk cjs loads diff --git a/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main.js b/tests/specs/npm/info_chalk_json_node_modules_dir/main.js similarity index 100% rename from tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main.js rename to tests/specs/npm/info_chalk_json_node_modules_dir/main.js diff --git a/tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_info_json.out b/tests/specs/npm/info_chalk_json_node_modules_dir/main_info_json.out similarity index 100% rename from tests/specs/npm/info_chalk_json_node_modules_dir/cjs_with_deps/main_info_json.out rename to tests/specs/npm/info_chalk_json_node_modules_dir/main_info_json.out diff --git a/tests/specs/npm/info_peer_deps/__test__.jsonc b/tests/specs/npm/info_peer_deps/__test__.jsonc index 00dfbc98b7..b726c50db1 100644 --- a/tests/specs/npm/info_peer_deps/__test__.jsonc +++ b/tests/specs/npm/info_peer_deps/__test__.jsonc @@ -1,5 +1,5 @@ { - "args": "info --quiet peer_deps_with_copied_folders/main.ts", - "output": "peer_deps_with_copied_folders/main_info.out", + "args": "info --quiet main.ts", + "output": "main_info.out", "exitCode": 0 } diff --git a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main.ts b/tests/specs/npm/info_peer_deps/main.ts similarity index 100% rename from tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main.ts rename to tests/specs/npm/info_peer_deps/main.ts diff --git a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_info.out b/tests/specs/npm/info_peer_deps/main_info.out similarity index 91% rename from tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_info.out rename to tests/specs/npm/info_peer_deps/main_info.out index e8b92399df..1269b1c1db 100644 --- a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_info.out +++ b/tests/specs/npm/info_peer_deps/main_info.out @@ -3,7 +3,7 @@ type: TypeScript dependencies: 6 unique size: [WILDCARD] -file:///[WILDCARD]/peer_deps_with_copied_folders/main.ts (171B) +file:///[WILDCARD]/main.ts (171B) ├─┬ npm:/@denotest/peer-dep-test-child@1.0.0 ([WILDCARD]) │ ├─┬ npm:/@denotest/peer-dep-test-grandchild@1.0.0_@denotest+peer-dep-test-peer@1.0.0 ([WILDCARD]) │ │ └── npm:/@denotest/peer-dep-test-peer@1.0.0 ([WILDCARD]) diff --git a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main.out b/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main.out deleted file mode 100644 index b7a5835577..0000000000 --- a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main.out +++ /dev/null @@ -1,14 +0,0 @@ -[UNORDERED_START] -Download http://localhost:4260/@denotest%2fpeer-dep-test-child -Download http://localhost:4260/@denotest%2fpeer-dep-test-grandchild -Download http://localhost:4260/@denotest%2fpeer-dep-test-peer -[UNORDERED_END] -[UNORDERED_START] -Download http://localhost:4260/@denotest/peer-dep-test-child/1.0.0.tgz -Download http://localhost:4260/@denotest/peer-dep-test-child/2.0.0.tgz -Download http://localhost:4260/@denotest/peer-dep-test-grandchild/1.0.0.tgz -Download http://localhost:4260/@denotest/peer-dep-test-peer/1.0.0.tgz -Download http://localhost:4260/@denotest/peer-dep-test-peer/2.0.0.tgz -[UNORDERED_END] -1 -2 diff --git a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_info_json.out b/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_info_json.out deleted file mode 100644 index 46cc35c650..0000000000 --- a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_info_json.out +++ /dev/null @@ -1,97 +0,0 @@ -{ - "version": 1, - "roots": [ - "[WILDCARD]/peer_deps_with_copied_folders/main.ts" - ], - "modules": [ - { - "kind": "esm", - "dependencies": [ - { - "specifier": "npm:@denotest/peer-dep-test-child@1", - "code": { - "specifier": "npm:@denotest/peer-dep-test-child@1", - "span": { - "start": { - "line": 0, - "character": 21 - }, - "end": { - "line": 0, - "character": 58 - } - } - }, - "npmPackage": "@denotest/peer-dep-test-child@1.0.0_@denotest+peer-dep-test-peer@1.0.0" - }, - { - "specifier": "npm:@denotest/peer-dep-test-child@2", - "code": { - "specifier": "npm:@denotest/peer-dep-test-child@2", - "span": { - "start": { - "line": 1, - "character": 21 - }, - "end": { - "line": 1, - "character": 58 - } - } - }, - "npmPackage": "@denotest/peer-dep-test-child@2.0.0_@denotest+peer-dep-test-peer@2.0.0" - } - ], - "local": "[WILDCARD]main.ts", - "size": 171, - "mediaType": "TypeScript", - "specifier": "file://[WILDCARD]/main.ts" - } - ], - "redirects": { - "npm:@denotest/peer-dep-test-child@1": "npm:/@denotest/peer-dep-test-child@1.0.0", - "npm:@denotest/peer-dep-test-child@2": "npm:/@denotest/peer-dep-test-child@2.0.0" - }, - "npmPackages": { - "@denotest/peer-dep-test-child@1.0.0_@denotest+peer-dep-test-peer@1.0.0": { - "name": "@denotest/peer-dep-test-child", - "version": "1.0.0", - "dependencies": [ - "@denotest/peer-dep-test-grandchild@1.0.0_@denotest+peer-dep-test-peer@1.0.0", - "@denotest/peer-dep-test-peer@1.0.0" - ] - }, - "@denotest/peer-dep-test-child@2.0.0_@denotest+peer-dep-test-peer@2.0.0": { - "name": "@denotest/peer-dep-test-child", - "version": "2.0.0", - "dependencies": [ - "@denotest/peer-dep-test-grandchild@1.0.0_@denotest+peer-dep-test-peer@2.0.0", - "@denotest/peer-dep-test-peer@2.0.0" - ] - }, - "@denotest/peer-dep-test-grandchild@1.0.0_@denotest+peer-dep-test-peer@1.0.0": { - "name": "@denotest/peer-dep-test-grandchild", - "version": "1.0.0", - "dependencies": [ - "@denotest/peer-dep-test-peer@1.0.0" - ] - }, - "@denotest/peer-dep-test-grandchild@1.0.0_@denotest+peer-dep-test-peer@2.0.0": { - "name": "@denotest/peer-dep-test-grandchild", - "version": "1.0.0", - "dependencies": [ - "@denotest/peer-dep-test-peer@2.0.0" - ] - }, - "@denotest/peer-dep-test-peer@1.0.0": { - "name": "@denotest/peer-dep-test-peer", - "version": "1.0.0", - "dependencies": [] - }, - "@denotest/peer-dep-test-peer@2.0.0": { - "name": "@denotest/peer-dep-test-peer", - "version": "2.0.0", - "dependencies": [] - } - } -} diff --git a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_node_modules.out b/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_node_modules.out deleted file mode 100644 index 02b5cbafd6..0000000000 --- a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_node_modules.out +++ /dev/null @@ -1,9 +0,0 @@ -[UNORDERED_START] -Initialize @denotest/peer-dep-test-child@1.0.0 -Initialize @denotest/peer-dep-test-child@2.0.0 -Initialize @denotest/peer-dep-test-grandchild@1.0.0 -Initialize @denotest/peer-dep-test-peer@1.0.0 -Initialize @denotest/peer-dep-test-peer@2.0.0 -[UNORDERED_END] -1 -2 diff --git a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_node_modules_reload.out b/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_node_modules_reload.out deleted file mode 100644 index 18d7f7865b..0000000000 --- a/tests/specs/npm/info_peer_deps/peer_deps_with_copied_folders/main_node_modules_reload.out +++ /dev/null @@ -1,19 +0,0 @@ -[UNORDERED_START] -Download http://localhost:4260/@denotest%2fpeer-dep-test-child -Download http://localhost:4260/@denotest%2fpeer-dep-test-grandchild -Download http://localhost:4260/@denotest%2fpeer-dep-test-peer -[UNORDERED_END] -[UNORDERED_START] -Download http://localhost:4260/@denotest/peer-dep-test-child/1.0.0.tgz -Initialize @denotest/peer-dep-test-child@1.0.0 -Download http://localhost:4260/@denotest/peer-dep-test-child/2.0.0.tgz -Initialize @denotest/peer-dep-test-child@2.0.0 -Download http://localhost:4260/@denotest/peer-dep-test-grandchild/1.0.0.tgz -Initialize @denotest/peer-dep-test-grandchild@1.0.0 -Download http://localhost:4260/@denotest/peer-dep-test-peer/1.0.0.tgz -Initialize @denotest/peer-dep-test-peer@1.0.0 -Download http://localhost:4260/@denotest/peer-dep-test-peer/2.0.0.tgz -Initialize @denotest/peer-dep-test-peer@2.0.0 -[UNORDERED_END] -1 -2 diff --git a/tests/specs/npm/info_peer_deps_json/__test__.jsonc b/tests/specs/npm/info_peer_deps_json/__test__.jsonc index 5dd08c325f..6950448398 100644 --- a/tests/specs/npm/info_peer_deps_json/__test__.jsonc +++ b/tests/specs/npm/info_peer_deps_json/__test__.jsonc @@ -1,5 +1,5 @@ { - "args": "info --quiet --json peer_deps_with_copied_folders/main.ts", - "output": "peer_deps_with_copied_folders/main_info_json.out", + "args": "info --quiet --json main.ts", + "output": "main_info_json.out", "exitCode": 0 } diff --git a/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main.ts b/tests/specs/npm/info_peer_deps_json/main.ts similarity index 100% rename from tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main.ts rename to tests/specs/npm/info_peer_deps_json/main.ts diff --git a/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_info_json.out b/tests/specs/npm/info_peer_deps_json/main_info_json.out similarity index 100% rename from tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_info_json.out rename to tests/specs/npm/info_peer_deps_json/main_info_json.out diff --git a/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main.out b/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main.out deleted file mode 100644 index b7a5835577..0000000000 --- a/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main.out +++ /dev/null @@ -1,14 +0,0 @@ -[UNORDERED_START] -Download http://localhost:4260/@denotest%2fpeer-dep-test-child -Download http://localhost:4260/@denotest%2fpeer-dep-test-grandchild -Download http://localhost:4260/@denotest%2fpeer-dep-test-peer -[UNORDERED_END] -[UNORDERED_START] -Download http://localhost:4260/@denotest/peer-dep-test-child/1.0.0.tgz -Download http://localhost:4260/@denotest/peer-dep-test-child/2.0.0.tgz -Download http://localhost:4260/@denotest/peer-dep-test-grandchild/1.0.0.tgz -Download http://localhost:4260/@denotest/peer-dep-test-peer/1.0.0.tgz -Download http://localhost:4260/@denotest/peer-dep-test-peer/2.0.0.tgz -[UNORDERED_END] -1 -2 diff --git a/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_info.out b/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_info.out deleted file mode 100644 index e8b92399df..0000000000 --- a/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_info.out +++ /dev/null @@ -1,14 +0,0 @@ -local: [WILDCARD]main.ts -type: TypeScript -dependencies: 6 unique -size: [WILDCARD] - -file:///[WILDCARD]/peer_deps_with_copied_folders/main.ts (171B) -├─┬ npm:/@denotest/peer-dep-test-child@1.0.0 ([WILDCARD]) -│ ├─┬ npm:/@denotest/peer-dep-test-grandchild@1.0.0_@denotest+peer-dep-test-peer@1.0.0 ([WILDCARD]) -│ │ └── npm:/@denotest/peer-dep-test-peer@1.0.0 ([WILDCARD]) -│ └── npm:/@denotest/peer-dep-test-peer@1.0.0 ([WILDCARD]) -└─┬ npm:/@denotest/peer-dep-test-child@2.0.0 ([WILDCARD]) - ├─┬ npm:/@denotest/peer-dep-test-grandchild@1.0.0_@denotest+peer-dep-test-peer@2.0.0 ([WILDCARD]) - │ └── npm:/@denotest/peer-dep-test-peer@2.0.0 ([WILDCARD]) - └── npm:/@denotest/peer-dep-test-peer@2.0.0 ([WILDCARD]) diff --git a/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_node_modules.out b/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_node_modules.out deleted file mode 100644 index 02b5cbafd6..0000000000 --- a/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_node_modules.out +++ /dev/null @@ -1,9 +0,0 @@ -[UNORDERED_START] -Initialize @denotest/peer-dep-test-child@1.0.0 -Initialize @denotest/peer-dep-test-child@2.0.0 -Initialize @denotest/peer-dep-test-grandchild@1.0.0 -Initialize @denotest/peer-dep-test-peer@1.0.0 -Initialize @denotest/peer-dep-test-peer@2.0.0 -[UNORDERED_END] -1 -2 diff --git a/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_node_modules_reload.out b/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_node_modules_reload.out deleted file mode 100644 index 18d7f7865b..0000000000 --- a/tests/specs/npm/info_peer_deps_json/peer_deps_with_copied_folders/main_node_modules_reload.out +++ /dev/null @@ -1,19 +0,0 @@ -[UNORDERED_START] -Download http://localhost:4260/@denotest%2fpeer-dep-test-child -Download http://localhost:4260/@denotest%2fpeer-dep-test-grandchild -Download http://localhost:4260/@denotest%2fpeer-dep-test-peer -[UNORDERED_END] -[UNORDERED_START] -Download http://localhost:4260/@denotest/peer-dep-test-child/1.0.0.tgz -Initialize @denotest/peer-dep-test-child@1.0.0 -Download http://localhost:4260/@denotest/peer-dep-test-child/2.0.0.tgz -Initialize @denotest/peer-dep-test-child@2.0.0 -Download http://localhost:4260/@denotest/peer-dep-test-grandchild/1.0.0.tgz -Initialize @denotest/peer-dep-test-grandchild@1.0.0 -Download http://localhost:4260/@denotest/peer-dep-test-peer/1.0.0.tgz -Initialize @denotest/peer-dep-test-peer@1.0.0 -Download http://localhost:4260/@denotest/peer-dep-test-peer/2.0.0.tgz -Initialize @denotest/peer-dep-test-peer@2.0.0 -[UNORDERED_END] -1 -2