1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix(node): regression where ts files were sometimes resolved instead of js (#26971)

This commit is contained in:
David Sherret 2024-11-21 11:37:10 -05:00 committed by GitHub
parent 75f8164b04
commit 9288081638
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 53 additions and 20 deletions

View file

@ -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) {
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"] = 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);
};
}
Module._extensions[".cjs"] =
Module._extensions[".cts"] =
function (module, filename) {
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);

View file

@ -0,0 +1,4 @@
{
"args": "run index.js",
"output": "Hi\nWasm\nJSON\n"
}

View file

@ -0,0 +1 @@
import "package";

View file

@ -0,0 +1,3 @@
require("./subdir");
require("./wasm");
require("./json");

View file

@ -0,0 +1 @@
console.log("JSON");

View file

@ -0,0 +1 @@
{}

View file

@ -0,0 +1,3 @@
{
"name": "package"
}

View file

@ -0,0 +1 @@
console.log("Hi")

View file

@ -0,0 +1 @@
console.log("No");

View file

@ -0,0 +1 @@
console.log("Wasm");

Binary file not shown.

View file

@ -0,0 +1,5 @@
{
"dependencies": {
"package": "*"
}
}