mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -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;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
Module._extensions[".js"] =
|
Module._extensions[".js"] = function (module, filename) {
|
||||||
Module._extensions[".ts"] =
|
// We don't define everything on Module.extensions in
|
||||||
Module._extensions[".jsx"] =
|
// order to prevent probing for these files
|
||||||
Module._extensions[".tsx"] =
|
if (
|
||||||
function (module, filename) {
|
StringPrototypeEndsWith(filename, ".js") ||
|
||||||
const content = op_require_read_file(filename);
|
StringPrototypeEndsWith(filename, ".ts") ||
|
||||||
const format = op_require_is_maybe_cjs(filename) ? undefined : "module";
|
StringPrototypeEndsWith(filename, ".jsx") ||
|
||||||
module._compile(content, filename, format);
|
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[".cjs"] = loadCjs;
|
||||||
Module._extensions[".cts"] =
|
Module._extensions[".mjs"] = loadESMFromCJS;
|
||||||
function (module, filename) {
|
Module._extensions[".wasm"] = loadESMFromCJS;
|
||||||
const content = op_require_read_file(filename);
|
|
||||||
module._compile(content, filename, "commonjs");
|
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) {
|
function loadESMFromCJS(module, filename, code) {
|
||||||
const namespace = op_import_sync(
|
const namespace = op_import_sync(
|
||||||
|
@ -1086,11 +1103,6 @@ function loadESMFromCJS(module, filename, code) {
|
||||||
module.exports = namespace;
|
module.exports = namespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
Module._extensions[".mjs"] =
|
|
||||||
Module._extensions[".mts"] =
|
|
||||||
Module._extensions[".wasm"] =
|
|
||||||
loadESMFromCJS;
|
|
||||||
|
|
||||||
function stripBOM(content) {
|
function stripBOM(content) {
|
||||||
if (StringPrototypeCharCodeAt(content, 0) === 0xfeff) {
|
if (StringPrototypeCharCodeAt(content, 0) === 0xfeff) {
|
||||||
content = StringPrototypeSlice(content, 1);
|
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