diff --git a/resolvers/node/analyze.rs b/resolvers/node/analyze.rs index f80a15816fdc6f..79d442ffd26fe9 100644 --- a/resolvers/node/analyze.rs +++ b/resolvers/node/analyze.rs @@ -210,7 +210,7 @@ impl< )); for export in &all_exports { - if export.as_str() != "default" { + if !matches!(export.as_str(), "default" | "module.exports") { add_export( &mut source, export, @@ -221,6 +221,7 @@ impl< } source.push("export default mod;".to_string()); + add_export(&mut source, "module.exports", "mod", &mut temp_var_count); let translated_source = source.join("\n"); Ok(Cow::Owned(translated_source)) diff --git a/tests/specs/install/alias_pkg_json_and_deno_json_npm_pkg/verify.out b/tests/specs/install/alias_pkg_json_and_deno_json_npm_pkg/verify.out index 8c989abd4a607b..b61b22ef43b42d 100644 --- a/tests/specs/install/alias_pkg_json_and_deno_json_npm_pkg/verify.out +++ b/tests/specs/install/alias_pkg_json_and_deno_json_npm_pkg/verify.out @@ -1,5 +1,6 @@ @denotest/esm-basic [Module: null prototype] { add: [Function (anonymous)], - default: { add: [Function (anonymous)] } + default: { add: [Function (anonymous)] }, + "module.exports": { add: [Function (anonymous)] } } diff --git a/tests/specs/node/cjs_key_escaped_whitespace/output.out b/tests/specs/node/cjs_key_escaped_whitespace/output.out index 49e92abdec5879..605f57e260e5e4 100644 --- a/tests/specs/node/cjs_key_escaped_whitespace/output.out +++ b/tests/specs/node/cjs_key_escaped_whitespace/output.out @@ -3,5 +3,6 @@ imported: [Module: null prototype] { "\nx": "test", "\rz": "test", '"a': "test", - default: { "\nx": "test", "\ty": "test", "\rz": "test", '"a': "test" } + default: { "\nx": "test", "\ty": "test", "\rz": "test", '"a': "test" }, + "module.exports": { "\nx": "test", "\ty": "test", "\rz": "test", '"a': "test" } } diff --git a/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.out b/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.out index c50f064d7f6d33..2a2c2f6cecd945 100644 --- a/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.out +++ b/tests/specs/node/cjs_reexport_same_specifier_in_sub_folder/main.out @@ -3,5 +3,6 @@ Download http://localhost:4260/@denotest/cjs-reexport-same-specifier-in-sub-fold [Module: null prototype] { default: { main: [Getter], sub: [Getter] }, main: 1, + "module.exports": { main: [Getter], sub: [Getter] }, sub: 2 } diff --git a/tests/specs/npm/cjs_invalid_name_exports/__test__.jsonc b/tests/specs/npm/cjs_invalid_name_exports/__test__.jsonc index 1d66adbd2349a3..a71173ce37b911 100644 --- a/tests/specs/npm/cjs_invalid_name_exports/__test__.jsonc +++ b/tests/specs/npm/cjs_invalid_name_exports/__test__.jsonc @@ -1,4 +1,4 @@ { - "args": "run --allow-read --quiet cjs-invalid-name-exports/main.ts", - "output": "cjs-invalid-name-exports/main.out" + "args": "run --allow-read --quiet main.ts", + "output": "main.out" } diff --git a/tests/specs/npm/cjs_invalid_name_exports/cjs-invalid-name-exports/main.out b/tests/specs/npm/cjs_invalid_name_exports/main.out similarity index 63% rename from tests/specs/npm/cjs_invalid_name_exports/cjs-invalid-name-exports/main.out rename to tests/specs/npm/cjs_invalid_name_exports/main.out index 45ec15d0e29f1f..b7125ada8f146d 100644 --- a/tests/specs/npm/cjs_invalid_name_exports/cjs-invalid-name-exports/main.out +++ b/tests/specs/npm/cjs_invalid_name_exports/main.out @@ -9,5 +9,12 @@ "foo - bar": "foo - bar" }, "foo - bar": "foo - bar", + "module.exports": { + 'wow "double quotes"': "double quotes", + "another 'case'": "example", + "a \\ b": "a \\ b", + "name variable": "a", + "foo - bar": "foo - bar" + }, 'wow "double quotes"': "double quotes" } diff --git a/tests/specs/npm/cjs_invalid_name_exports/cjs-invalid-name-exports/main.ts b/tests/specs/npm/cjs_invalid_name_exports/main.ts similarity index 100% rename from tests/specs/npm/cjs_invalid_name_exports/cjs-invalid-name-exports/main.ts rename to tests/specs/npm/cjs_invalid_name_exports/main.ts diff --git a/tests/specs/npm/cjs_local_global_decls/__test__.jsonc b/tests/specs/npm/cjs_local_global_decls/__test__.jsonc index 6a42f26e6d54b6..70840dee2b585a 100644 --- a/tests/specs/npm/cjs_local_global_decls/__test__.jsonc +++ b/tests/specs/npm/cjs_local_global_decls/__test__.jsonc @@ -1,4 +1,4 @@ { - "args": "run --allow-read cjs_local_global_decls/main.ts", - "output": "cjs_local_global_decls/main.out" + "args": "run --allow-read main.ts", + "output": "main.out" } diff --git a/tests/specs/npm/cjs_local_global_decls/cjs_local_global_decls/main.out b/tests/specs/npm/cjs_local_global_decls/main.out similarity index 100% rename from tests/specs/npm/cjs_local_global_decls/cjs_local_global_decls/main.out rename to tests/specs/npm/cjs_local_global_decls/main.out diff --git a/tests/specs/npm/cjs_local_global_decls/cjs_local_global_decls/main.ts b/tests/specs/npm/cjs_local_global_decls/main.ts similarity index 100% rename from tests/specs/npm/cjs_local_global_decls/cjs_local_global_decls/main.ts rename to tests/specs/npm/cjs_local_global_decls/main.ts diff --git a/tests/specs/npm/cjs_module_export_assignment/__test__.jsonc b/tests/specs/npm/cjs_module_export_assignment/__test__.jsonc index 3a8c104aba9e44..ec213f308ccbbc 100644 --- a/tests/specs/npm/cjs_module_export_assignment/__test__.jsonc +++ b/tests/specs/npm/cjs_module_export_assignment/__test__.jsonc @@ -1,4 +1,4 @@ { - "args": "run -A --quiet --check=all cjs_module_export_assignment/main.ts", - "output": "cjs_module_export_assignment/main.out" + "args": "run -A --quiet --check=all main.ts", + "output": "main.out" } diff --git a/tests/specs/npm/cjs_module_export_assignment/cjs_module_export_assignment/main.out b/tests/specs/npm/cjs_module_export_assignment/main.out similarity index 57% rename from tests/specs/npm/cjs_module_export_assignment/cjs_module_export_assignment/main.out rename to tests/specs/npm/cjs_module_export_assignment/main.out index dea185e38f5fa5..b4d7dee0a4fe23 100644 --- a/tests/specs/npm/cjs_module_export_assignment/cjs_module_export_assignment/main.out +++ b/tests/specs/npm/cjs_module_export_assignment/main.out @@ -1,6 +1,7 @@ { func: [Function: func] } [Module: null prototype] { default: { func: [Function: func] }, - func: [Function: func] + func: [Function: func], + "module.exports": { func: [Function: func] } } 5 diff --git a/tests/specs/npm/cjs_module_export_assignment/cjs_module_export_assignment/main.ts b/tests/specs/npm/cjs_module_export_assignment/main.ts similarity index 100% rename from tests/specs/npm/cjs_module_export_assignment/cjs_module_export_assignment/main.ts rename to tests/specs/npm/cjs_module_export_assignment/main.ts diff --git a/tests/specs/npm/cjs_module_export_assignment_number/__test__.jsonc b/tests/specs/npm/cjs_module_export_assignment_number/__test__.jsonc index 1b44f98c377631..ec213f308ccbbc 100644 --- a/tests/specs/npm/cjs_module_export_assignment_number/__test__.jsonc +++ b/tests/specs/npm/cjs_module_export_assignment_number/__test__.jsonc @@ -1,4 +1,4 @@ { - "args": "run -A --quiet --check=all cjs_module_export_assignment_number/main.ts", - "output": "cjs_module_export_assignment_number/main.out" + "args": "run -A --quiet --check=all main.ts", + "output": "main.out" } diff --git a/tests/specs/npm/cjs_module_export_assignment_number/cjs_module_export_assignment_number/main.out b/tests/specs/npm/cjs_module_export_assignment_number/cjs_module_export_assignment_number/main.out deleted file mode 100644 index e559775cf9940d..00000000000000 --- a/tests/specs/npm/cjs_module_export_assignment_number/cjs_module_export_assignment_number/main.out +++ /dev/null @@ -1,3 +0,0 @@ -5 -5 -[Module: null prototype] { default: 5 } diff --git a/tests/specs/npm/cjs_module_export_assignment_number/main.out b/tests/specs/npm/cjs_module_export_assignment_number/main.out new file mode 100644 index 00000000000000..61a66742fb6437 --- /dev/null +++ b/tests/specs/npm/cjs_module_export_assignment_number/main.out @@ -0,0 +1,3 @@ +5 +5 +[Module: null prototype] { default: 5, "module.exports": 5 } diff --git a/tests/specs/npm/cjs_module_export_assignment_number/cjs_module_export_assignment_number/main.ts b/tests/specs/npm/cjs_module_export_assignment_number/main.ts similarity index 100% rename from tests/specs/npm/cjs_module_export_assignment_number/cjs_module_export_assignment_number/main.ts rename to tests/specs/npm/cjs_module_export_assignment_number/main.ts diff --git a/tests/specs/npm/cjs_require_esm/__test__.jsonc b/tests/specs/npm/cjs_require_esm/__test__.jsonc index b4e03afa3b7f71..a71173ce37b911 100644 --- a/tests/specs/npm/cjs_require_esm/__test__.jsonc +++ b/tests/specs/npm/cjs_require_esm/__test__.jsonc @@ -1,4 +1,4 @@ { - "args": "run --allow-read --quiet cjs_require_esm/main.ts", - "output": "cjs_require_esm/main.out" + "args": "run --allow-read --quiet main.ts", + "output": "main.out" } diff --git a/tests/specs/npm/cjs_require_esm_mjs/cjs_require_esm_mjs/main.out b/tests/specs/npm/cjs_require_esm/main.out similarity index 64% rename from tests/specs/npm/cjs_require_esm_mjs/cjs_require_esm_mjs/main.out rename to tests/specs/npm/cjs_require_esm/main.out index 4afceccc951504..842700f7982ad1 100644 --- a/tests/specs/npm/cjs_require_esm_mjs/cjs_require_esm_mjs/main.out +++ b/tests/specs/npm/cjs_require_esm/main.out @@ -1,4 +1,5 @@ [Module: null prototype] { Test: [Module: null prototype] { Test: [class Test] }, - default: { Test: [Module: null prototype] { Test: [class Test] } } + default: { Test: [Module: null prototype] { Test: [class Test] } }, + "module.exports": { Test: [Module: null prototype] { Test: [class Test] } } } diff --git a/tests/specs/npm/cjs_require_esm/cjs_require_esm/main.ts b/tests/specs/npm/cjs_require_esm/main.ts similarity index 100% rename from tests/specs/npm/cjs_require_esm/cjs_require_esm/main.ts rename to tests/specs/npm/cjs_require_esm/main.ts diff --git a/tests/specs/npm/cjs_require_esm_mjs/__test__.jsonc b/tests/specs/npm/cjs_require_esm_mjs/__test__.jsonc index 6bcb382e8da57b..a71173ce37b911 100644 --- a/tests/specs/npm/cjs_require_esm_mjs/__test__.jsonc +++ b/tests/specs/npm/cjs_require_esm_mjs/__test__.jsonc @@ -1,4 +1,4 @@ { - "args": "run --allow-read --quiet cjs_require_esm_mjs/main.ts", - "output": "cjs_require_esm_mjs/main.out" + "args": "run --allow-read --quiet main.ts", + "output": "main.out" } diff --git a/tests/specs/npm/cjs_require_esm/cjs_require_esm/main.out b/tests/specs/npm/cjs_require_esm_mjs/main.out similarity index 64% rename from tests/specs/npm/cjs_require_esm/cjs_require_esm/main.out rename to tests/specs/npm/cjs_require_esm_mjs/main.out index 4afceccc951504..842700f7982ad1 100644 --- a/tests/specs/npm/cjs_require_esm/cjs_require_esm/main.out +++ b/tests/specs/npm/cjs_require_esm_mjs/main.out @@ -1,4 +1,5 @@ [Module: null prototype] { Test: [Module: null prototype] { Test: [class Test] }, - default: { Test: [Module: null prototype] { Test: [class Test] } } + default: { Test: [Module: null prototype] { Test: [class Test] } }, + "module.exports": { Test: [Module: null prototype] { Test: [class Test] } } } diff --git a/tests/specs/npm/cjs_require_esm_mjs/cjs_require_esm_mjs/main.ts b/tests/specs/npm/cjs_require_esm_mjs/main.ts similarity index 100% rename from tests/specs/npm/cjs_require_esm_mjs/cjs_require_esm_mjs/main.ts rename to tests/specs/npm/cjs_require_esm_mjs/main.ts diff --git a/tests/specs/npm/esm_import_cjs_default/main.out b/tests/specs/npm/esm_import_cjs_default/main.out index 6528a68d7c2c0e..d6f1e65227c74e 100644 --- a/tests/specs/npm/esm_import_cjs_default/main.out +++ b/tests/specs/npm/esm_import_cjs_default/main.out @@ -21,11 +21,17 @@ Node esm importing node cjs named: [Function (anonymous)], MyClass: [class MyClass] }, + "module.exports": { + default: [Function (anonymous)], + named: [Function (anonymous)], + MyClass: [class MyClass] + }, named: [Function (anonymous)] } [Module: null prototype] { __esModule: true, default: { default: [Function (anonymous)], named: [Function (anonymous)] }, + "module.exports": { default: [Function (anonymous)], named: [Function (anonymous)] }, named: [Function (anonymous)] } =========================== @@ -45,6 +51,11 @@ Deno esm importing node cjs named: [Function (anonymous)], MyClass: [class MyClass] }, + "module.exports": { + default: [Function (anonymous)], + named: [Function (anonymous)], + MyClass: [class MyClass] + }, named: [Function (anonymous)] } =========================== diff --git a/tests/specs/npm/reserved_word_exports/__test__.jsonc b/tests/specs/npm/reserved_word_exports/__test__.jsonc index 01d5974c38077c..5517e693d6ed29 100644 --- a/tests/specs/npm/reserved_word_exports/__test__.jsonc +++ b/tests/specs/npm/reserved_word_exports/__test__.jsonc @@ -1,4 +1,4 @@ { - "args": "run reserved_word_exports/main.ts", - "output": "reserved_word_exports/main.out" + "args": "run main.ts", + "output": "main.out" } diff --git a/tests/specs/npm/reserved_word_exports/reserved_word_exports/main.out b/tests/specs/npm/reserved_word_exports/main.out similarity index 64% rename from tests/specs/npm/reserved_word_exports/reserved_word_exports/main.out rename to tests/specs/npm/reserved_word_exports/main.out index 2a82194e37578d..b203c268e917e9 100644 --- a/tests/specs/npm/reserved_word_exports/reserved_word_exports/main.out +++ b/tests/specs/npm/reserved_word_exports/main.out @@ -111,6 +111,76 @@ Download http://localhost:4260/@denotest/reserved-word-exports/1.0.0.tgz let: "let", long: "long", mod: "mod", + "module.exports": { + abstract: "abstract", + arguments: "arguments", + async: "async", + await: "await", + boolean: "boolean", + break: "break", + byte: "byte", + case: "case", + catch: "catch", + char: "char", + class: "class", + const: "const", + continue: "continue", + debugger: "debugger", + default: "default", + delete: "delete", + do: "do", + double: "double", + else: "else", + enum: "enum", + eval: "eval", + export: "export", + extends: "extends", + false: "false", + final: "final", + finally: "finally", + float: "float", + for: "for", + function: "function", + get: "get", + goto: "goto", + if: "if", + implements: "implements", + import: "import", + in: "in", + instanceof: "instanceof", + int: "int", + interface: "interface", + let: "let", + long: "long", + mod: "mod", + native: "native", + new: "new", + null: "null", + package: "package", + private: "private", + protected: "protected", + public: "public", + return: "return", + set: "set", + short: "short", + static: "static", + super: "super", + switch: "switch", + synchronized: "synchronized", + this: "this", + throw: "throw", + throws: "throws", + transient: "transient", + true: "true", + try: "try", + typeof: "typeof", + var: "var", + void: "void", + volatile: "volatile", + while: "while", + with: "with", + yield: "yield" + }, native: "native", new: "new", null: "null", @@ -139,3 +209,7 @@ Download http://localhost:4260/@denotest/reserved-word-exports/1.0.0.tgz with: "with", yield: "yield" } +[Module: null prototype] { + default: { "module.exports": 6 }, + "module.exports": { "module.exports": 6 } +} diff --git a/tests/specs/npm/reserved_word_exports/reserved_word_exports/main.ts b/tests/specs/npm/reserved_word_exports/main.ts similarity index 51% rename from tests/specs/npm/reserved_word_exports/reserved_word_exports/main.ts rename to tests/specs/npm/reserved_word_exports/main.ts index 33cf183d366fed..2f3f2ffdb4c941 100644 --- a/tests/specs/npm/reserved_word_exports/reserved_word_exports/main.ts +++ b/tests/specs/npm/reserved_word_exports/main.ts @@ -1,3 +1,5 @@ import * as exports from "npm:@denotest/reserved-word-exports"; +import * as moduleExports from "./module_exports.cjs"; console.log(exports); +console.log(moduleExports); diff --git a/tests/specs/npm/reserved_word_exports/module_exports.cjs b/tests/specs/npm/reserved_word_exports/module_exports.cjs new file mode 100644 index 00000000000000..fafb645f116abf --- /dev/null +++ b/tests/specs/npm/reserved_word_exports/module_exports.cjs @@ -0,0 +1 @@ +module.exports["module.exports"] = 6;