1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

fix(npm): translate CJS to ESM with name clashes for files and dirs (#15697)

This commit is contained in:
Bartek Iwańczuk 2022-08-31 00:31:59 +02:00 committed by GitHub
parent 79fe8ffff8
commit adec4f575e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 32 additions and 9 deletions

View file

@ -738,7 +738,6 @@ pub fn translate_cjs_to_esm(
// if there are reexports, handle them first
for (idx, reexport) in analysis.reexports.iter().enumerate() {
// Firstly, resolve relate reexport specifier
// todo(dsherret): call module_resolve instead?
let resolved_reexport = resolve(
reexport,
specifier,
@ -1039,19 +1038,29 @@ fn is_relative_specifier(specifier: &str) -> bool {
}
fn file_extension_probe(
mut p: PathBuf,
p: PathBuf,
referrer: &Path,
) -> Result<PathBuf, AnyError> {
if p.exists() && !p.is_dir() {
Ok(p.clean())
let p = p.clean();
if p.exists() {
let mut p_js = p.clone();
p_js.set_extension("js");
if p_js.exists() && p_js.is_file() {
return Ok(p_js);
} else if p.is_dir() {
return Ok(p.join("index.js"));
} else {
p.set_extension("js");
if p.exists() && !p.is_dir() {
Ok(p)
return Ok(p);
}
} else {
Err(not_found(&p.clean().to_string_lossy(), referrer))
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 {

View file

@ -61,6 +61,13 @@ itest!(cjs_reexport_collision {
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 {
args: "run --allow-read --unstable npm/compare_globals/main.js",
output: "npm/compare_globals/main.out",

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

View file

@ -0,0 +1,2 @@
import fsx from "npm:fs-extra@10.1.0";
console.log(fsx.access);

View file

@ -0,0 +1 @@
[Function: access]