mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 08:39:09 -05:00
fix(node): regression where ts files were sometimes resolved instead of js (#26971)
This commit is contained in:
parent
75f8164b04
commit
9288081638
12 changed files with 53 additions and 20 deletions
|
@ -1060,22 +1060,39 @@ Module.prototype._compile = function (content, filename, format) {
|
|||
return result;
|
||||
};
|
||||
|
||||
Module._extensions[".js"] =
|
||||
Module._extensions[".ts"] =
|
||||
Module._extensions[".jsx"] =
|
||||
Module._extensions[".tsx"] =
|
||||
function (module, filename) {
|
||||
const content = op_require_read_file(filename);
|
||||
const format = op_require_is_maybe_cjs(filename) ? undefined : "module";
|
||||
module._compile(content, filename, format);
|
||||
};
|
||||
Module._extensions[".js"] = function (module, filename) {
|
||||
// We don't define everything on Module.extensions in
|
||||
// order to prevent probing for these files
|
||||
if (
|
||||
StringPrototypeEndsWith(filename, ".js") ||
|
||||
StringPrototypeEndsWith(filename, ".ts") ||
|
||||
StringPrototypeEndsWith(filename, ".jsx") ||
|
||||
StringPrototypeEndsWith(filename, ".tsx")
|
||||
) {
|
||||
return loadMaybeCjs(module, filename);
|
||||
} else if (StringPrototypeEndsWith(filename, ".mts")) {
|
||||
return loadESMFromCJS(module, filename);
|
||||
} else if (StringPrototypeEndsWith(filename, ".cts")) {
|
||||
return loadCjs(module, filename);
|
||||
} else {
|
||||
return loadMaybeCjs(module, filename);
|
||||
}
|
||||
};
|
||||
|
||||
Module._extensions[".cjs"] =
|
||||
Module._extensions[".cts"] =
|
||||
function (module, filename) {
|
||||
const content = op_require_read_file(filename);
|
||||
module._compile(content, filename, "commonjs");
|
||||
};
|
||||
Module._extensions[".cjs"] = loadCjs;
|
||||
Module._extensions[".mjs"] = loadESMFromCJS;
|
||||
Module._extensions[".wasm"] = loadESMFromCJS;
|
||||
|
||||
function loadMaybeCjs(module, filename) {
|
||||
const content = op_require_read_file(filename);
|
||||
const format = op_require_is_maybe_cjs(filename) ? undefined : "module";
|
||||
module._compile(content, filename, format);
|
||||
}
|
||||
|
||||
function loadCjs(module, filename) {
|
||||
const content = op_require_read_file(filename);
|
||||
module._compile(content, filename, "commonjs");
|
||||
}
|
||||
|
||||
function loadESMFromCJS(module, filename, code) {
|
||||
const namespace = op_import_sync(
|
||||
|
@ -1086,11 +1103,6 @@ function loadESMFromCJS(module, filename, code) {
|
|||
module.exports = namespace;
|
||||
}
|
||||
|
||||
Module._extensions[".mjs"] =
|
||||
Module._extensions[".mts"] =
|
||||
Module._extensions[".wasm"] =
|
||||
loadESMFromCJS;
|
||||
|
||||
function stripBOM(content) {
|
||||
if (StringPrototypeCharCodeAt(content, 0) === 0xfeff) {
|
||||
content = StringPrototypeSlice(content, 1);
|
||||
|
|
4
tests/specs/npm/pkg_index_ts_and_js/__test__.jsonc
Normal file
4
tests/specs/npm/pkg_index_ts_and_js/__test__.jsonc
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"args": "run index.js",
|
||||
"output": "Hi\nWasm\nJSON\n"
|
||||
}
|
1
tests/specs/npm/pkg_index_ts_and_js/index.js
Normal file
1
tests/specs/npm/pkg_index_ts_and_js/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
import "package";
|
3
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/index.js
generated
vendored
Normal file
3
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/index.js
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
require("./subdir");
|
||||
require("./wasm");
|
||||
require("./json");
|
1
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/json/index.js
generated
vendored
Normal file
1
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/json/index.js
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
console.log("JSON");
|
1
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/json/index.json
generated
vendored
Normal file
1
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/json/index.json
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
3
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/package.json
generated
vendored
Normal file
3
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/package.json
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"name": "package"
|
||||
}
|
1
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/subdir/index.js
generated
vendored
Normal file
1
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/subdir/index.js
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
console.log("Hi")
|
1
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/subdir/index.ts
generated
vendored
Normal file
1
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/subdir/index.ts
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
console.log("No");
|
1
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/wasm/index.js
generated
vendored
Normal file
1
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/wasm/index.js
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
console.log("Wasm");
|
BIN
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/wasm/index.wasm
generated
vendored
Normal file
BIN
tests/specs/npm/pkg_index_ts_and_js/node_modules/package/wasm/index.wasm
generated
vendored
Normal file
Binary file not shown.
5
tests/specs/npm/pkg_index_ts_and_js/package.json
Normal file
5
tests/specs/npm/pkg_index_ts_and_js/package.json
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"package": "*"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue