mirror of
https://github.com/denoland/deno.git
synced 2025-01-08 15:19:40 -05:00
fix(npm): translate CJS to ESM with name clashes for files and dirs (#15697)
This commit is contained in:
parent
79fe8ffff8
commit
adec4f575e
12 changed files with 32 additions and 9 deletions
|
@ -738,7 +738,6 @@ pub fn translate_cjs_to_esm(
|
||||||
// if there are reexports, handle them first
|
// if there are reexports, handle them first
|
||||||
for (idx, reexport) in analysis.reexports.iter().enumerate() {
|
for (idx, reexport) in analysis.reexports.iter().enumerate() {
|
||||||
// Firstly, resolve relate reexport specifier
|
// Firstly, resolve relate reexport specifier
|
||||||
// todo(dsherret): call module_resolve instead?
|
|
||||||
let resolved_reexport = resolve(
|
let resolved_reexport = resolve(
|
||||||
reexport,
|
reexport,
|
||||||
specifier,
|
specifier,
|
||||||
|
@ -1039,19 +1038,29 @@ fn is_relative_specifier(specifier: &str) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn file_extension_probe(
|
fn file_extension_probe(
|
||||||
mut p: PathBuf,
|
p: PathBuf,
|
||||||
referrer: &Path,
|
referrer: &Path,
|
||||||
) -> Result<PathBuf, AnyError> {
|
) -> Result<PathBuf, AnyError> {
|
||||||
if p.exists() && !p.is_dir() {
|
let p = p.clean();
|
||||||
Ok(p.clean())
|
if p.exists() {
|
||||||
} else {
|
let mut p_js = p.clone();
|
||||||
p.set_extension("js");
|
p_js.set_extension("js");
|
||||||
if p.exists() && !p.is_dir() {
|
if p_js.exists() && p_js.is_file() {
|
||||||
Ok(p)
|
return Ok(p_js);
|
||||||
|
} else if p.is_dir() {
|
||||||
|
return Ok(p.join("index.js"));
|
||||||
} else {
|
} else {
|
||||||
Err(not_found(&p.clean().to_string_lossy(), referrer))
|
return Ok(p);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let mut p_js = p.clone();
|
||||||
|
p_js.set_extension("js");
|
||||||
|
if p_js.exists() && p_js.is_file() {
|
||||||
|
return Ok(p_js);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Err(not_found(&p.to_string_lossy(), referrer))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn not_found(path: &str, referrer: &Path) -> AnyError {
|
fn not_found(path: &str, referrer: &Path) -> AnyError {
|
||||||
|
|
|
@ -61,6 +61,13 @@ itest!(cjs_reexport_collision {
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(translate_cjs_to_esm {
|
||||||
|
args: "run --unstable -A --quiet npm/translate_cjs_to_esm/main.js",
|
||||||
|
output: "npm/translate_cjs_to_esm/main.out",
|
||||||
|
envs: env_vars(),
|
||||||
|
http_server: true,
|
||||||
|
});
|
||||||
|
|
||||||
itest!(compare_globals {
|
itest!(compare_globals {
|
||||||
args: "run --allow-read --unstable npm/compare_globals/main.js",
|
args: "run --allow-read --unstable npm/compare_globals/main.js",
|
||||||
output: "npm/compare_globals/main.out",
|
output: "npm/compare_globals/main.out",
|
||||||
|
|
BIN
cli/tests/testdata/npm/registry/fs-extra/fs-extra-10.1.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/fs-extra/fs-extra-10.1.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/fs-extra/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/fs-extra/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/graceful-fs/graceful-fs-4.2.10.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/graceful-fs/graceful-fs-4.2.10.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/graceful-fs/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/graceful-fs/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/jsonfile/jsonfile-6.1.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/jsonfile/jsonfile-6.1.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/jsonfile/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/jsonfile/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
1
cli/tests/testdata/npm/registry/universalify/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/universalify/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/universalify/universalify-2.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/universalify/universalify-2.0.0.tgz
vendored
Normal file
Binary file not shown.
2
cli/tests/testdata/npm/translate_cjs_to_esm/main.js
vendored
Normal file
2
cli/tests/testdata/npm/translate_cjs_to_esm/main.js
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
import fsx from "npm:fs-extra@10.1.0";
|
||||||
|
console.log(fsx.access);
|
1
cli/tests/testdata/npm/translate_cjs_to_esm/main.out
vendored
Normal file
1
cli/tests/testdata/npm/translate_cjs_to_esm/main.out
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
[Function: access]
|
Loading…
Reference in a new issue