diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2021-10-28 10:11:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-28 10:11:38 +0200 |
commit | f77c5701f774b5f0ba548fb1e0eb53dfd304f440 (patch) | |
tree | eb243ccce5516a8e2ed90484b94cb81b0f67ad1a /cli/tests | |
parent | a065604155991dbf4417b606d4562d275cd8955f (diff) |
feat(compat): integrate import map and classic resolutions in ESM resolution (#12549)
This commit integrates import map and "classic" resolutions in
the "--compat" mode when using ES modules; in effect
"http:", "https:" and "blob:" imports now work in compat mode.
The algorithm works as follows:
1. If there's an import map, try to resolve using it and if succeeded
return the specifier
2. Try to resolve using "Node ESM resolution", and if succeeded return
the specifier
3. Fall back to regular ESM resolution
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/integration/compat_tests.rs | 5 | ||||
-rw-r--r-- | cli/tests/testdata/compat/import_map.json | 5 | ||||
-rw-r--r-- | cli/tests/testdata/compat/import_map_https_imports.mjs | 7 | ||||
-rw-r--r-- | cli/tests/testdata/compat/import_map_https_imports.out | 3 |
4 files changed, 20 insertions, 0 deletions
diff --git a/cli/tests/integration/compat_tests.rs b/cli/tests/integration/compat_tests.rs index 2886056ec..81d2985b3 100644 --- a/cli/tests/integration/compat_tests.rs +++ b/cli/tests/integration/compat_tests.rs @@ -18,6 +18,11 @@ itest!(node_prefix_fs_promises { output: "compat/fs_promises.out", }); +itest!(compat_with_import_map_and_https_imports { + args: "run --quiet --compat --unstable -A --import-map=compat/import_map.json compat/import_map_https_imports.mjs", + output: "compat/import_map_https_imports.out", +}); + #[test] fn globals_in_repl() { let (out, _err) = util::run_and_collect_output_with_args( diff --git a/cli/tests/testdata/compat/import_map.json b/cli/tests/testdata/compat/import_map.json new file mode 100644 index 000000000..2c7b8a6d0 --- /dev/null +++ b/cli/tests/testdata/compat/import_map.json @@ -0,0 +1,5 @@ +{ + "imports": { + "std/": "https://deno.land/std@0.113.0/" + } +} diff --git a/cli/tests/testdata/compat/import_map_https_imports.mjs b/cli/tests/testdata/compat/import_map_https_imports.mjs new file mode 100644 index 000000000..f4f27fdb9 --- /dev/null +++ b/cli/tests/testdata/compat/import_map_https_imports.mjs @@ -0,0 +1,7 @@ +import { sortBy } from "std/collections/sort_by.ts"; +import { findSingle } from "https://deno.land/std@0.113.0/collections/find_single.ts"; +import os from "node:os"; + +console.log(sortBy([2, 3, 1], (it) => it)); +console.log(findSingle([2, 3, 1], (it) => it == 2)); +console.log("arch", os.arch()); diff --git a/cli/tests/testdata/compat/import_map_https_imports.out b/cli/tests/testdata/compat/import_map_https_imports.out new file mode 100644 index 000000000..7ee30676e --- /dev/null +++ b/cli/tests/testdata/compat/import_map_https_imports.out @@ -0,0 +1,3 @@ +[ 1, 2, 3 ] +2 +arch [WILDCARD] |