summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/01_require.js
diff options
context:
space:
mode:
authorsnek <snek@deno.com>2024-07-31 16:22:34 -0700
committerGitHub <noreply@github.com>2024-07-31 23:22:34 +0000
commitf57745fe2106a4d26dd2209e1b2cacb2d6430245 (patch)
treef3ea0c476940b296ec3cc507adca05088ed947be /ext/node/polyfills/01_require.js
parentfbcd250bc8ffb3b577afca7131d1d37f55eb47a2 (diff)
feat: upgrade V8 to 12.8 (#24693)
- upgrade to v8 12.8 - optimizes DataView bigint methods - fixes global interceptors - includes CPED methods for ALS - fix global resolution - makes global resolution consistent using host_defined_options. originally a separate patch but due to the global interceptor bug it needs to be included in this pr for all tests to pass.
Diffstat (limited to 'ext/node/polyfills/01_require.js')
-rw-r--r--ext/node/polyfills/01_require.js30
1 files changed, 25 insertions, 5 deletions
diff --git a/ext/node/polyfills/01_require.js b/ext/node/polyfills/01_require.js
index 94d6e90e0..f71e009ba 100644
--- a/ext/node/polyfills/01_require.js
+++ b/ext/node/polyfills/01_require.js
@@ -976,9 +976,14 @@ function wrapSafe(
filename,
content,
cjsModuleInstance,
+ format,
) {
const wrapper = Module.wrap(content);
- const [f, err] = core.evalContext(wrapper, `file://${filename}`);
+ const [f, err] = core.evalContext(
+ wrapper,
+ url.pathToFileURL(filename).toString(),
+ [format !== "module"],
+ );
if (err) {
if (process.mainModule === cjsModuleInstance) {
enrichCJSError(err.thrown);
@@ -995,8 +1000,16 @@ function wrapSafe(
return f;
}
-Module.prototype._compile = function (content, filename) {
- const compiledWrapper = wrapSafe(filename, content, this);
+Module.prototype._compile = function (content, filename, format) {
+ const compiledWrapper = wrapSafe(filename, content, this, format);
+
+ if (format === "module") {
+ // TODO(https://github.com/denoland/deno/issues/24822): implement require esm
+ throw createRequireEsmError(
+ filename,
+ moduleParentCache.get(module)?.filename,
+ );
+ }
const dirname = pathDirname(filename);
const require = makeRequireFunction(this);
@@ -1053,17 +1066,24 @@ Module.prototype._compile = function (content, filename) {
Module._extensions[".js"] = function (module, filename) {
const content = op_require_read_file(filename);
+ let format;
if (StringPrototypeEndsWith(filename, ".js")) {
const pkg = op_require_read_closest_package_json(filename);
- if (pkg && pkg.typ === "module") {
+ if (pkg?.typ === "module") {
+ // TODO(https://github.com/denoland/deno/issues/24822): implement require esm
+ format = "module";
throw createRequireEsmError(
filename,
moduleParentCache.get(module)?.filename,
);
+ } else if (pkg?.type === "commonjs") {
+ format = "commonjs";
}
+ } else if (StringPrototypeEndsWith(filename, ".cjs")) {
+ format = "commonjs";
}
- module._compile(content, filename);
+ module._compile(content, filename, format);
};
function createRequireEsmError(filename, parent) {