Skip to content

Conversation

@joyeecheung
Copy link
Member

@joyeecheungjoyeecheung commented Dec 21, 2023

This patch adds support for using vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADER as the
importModuleDynamically option in all vm APIs that take this option except vm.SourceTextModule. This allows users to have a shortcut to support dynamic import() in the compiled code without missing the compilation cache if they don't need customization of the loading process. We emit an experimental warning when the import() is actually handled by the default loader through this option instead of requiring --experimental-vm-modules.

const{ Script, constants }=require('node:vm');const{ resolve }=require('node:path');const{ writeFileSync }=require('node:fs');// Write test.js and test.txt to the directory where the current script// being run is located.writeFileSync(resolve(__dirname,'test.mjs'),'export const filename = "./test.json";');writeFileSync(resolve(__dirname,'test.json'),'{"hello": "world"}');// Compile a script that loads test.mjs and then test.json// as if the script is placed in the same directory.constscript=newScript(`(async function(){ const{filename } = await import('./test.mjs'); return import(filename,{with:{type: 'json' } }) })();`,{filename: resolve(__dirname,'test-with-default.js'),importModuleDynamically: constants.USE_MAIN_CONTEXT_DEFAULT_LOADER,});//{default:{hello: 'world' }}script.runInThisContext().then(console.log);

In addition this refactors the documentation for
importModuleDynamically and adds a dedicated section for it with examples.

vm.SourceTextModule is not supported in this patch because it needs additional refactoring to handle initializeImportMeta, which can be done in a follow-up.

Fixes: #51154

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/vm
  • @nodejs/web-infra

@nodejs-github-botnodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Dec 21, 2023
@joyeecheungjoyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 21, 2023
@github-actionsgithub-actionsbot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 21, 2023
@nodejs-github-bot
Copy link
Collaborator

@joyeecheungjoyeecheung added the semver-minor PRs that contain new features and should be released in the next minor version. label Dec 21, 2023
Copy link
Member

@GeoffreyBoothGeoffreyBooth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few small things, but mostly looks great! Thank you for doing this. The last time I tried to use --experimental-vm-modules I was overwhelmed by the amount of boilerplate required; I’m glad to see a lot of that going away.

doc/api/vm.md Outdated
Comment on lines 1656 to 1659
constscript=newScript('import("./foo.json",{with:{type: "json"} })',{
filename:resolve(import.meta.dirname, 'test-with-default.js'),
importModuleDynamically:constants.USE_MAIN_CONTEXT_DEFAULT_LOADER,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it’s a CommonJS script? But it’s a bit of an awkward example since in CommonJS most users would use require to get a JSON file, rather than dynamic import. Maybe change it to a dynamic import of an ES module, with a comment above like // Import ES module into CommonJS code?

I assume we can’t show how this would be used with an ESM script because this doesn’t yet support SourceTextModule?

Copy link
MemberAuthor

@joyeecheungjoyeecheungDec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a CommonJS script, vm.Script is just a script. If you run it in a new context, there is no require() at all (there also isn't going to be process, or URL, or anything not implemented by V8).

doc/api/vm.md Outdated
Comment on lines 1686 to 1687
`filename` that's either an absolute path or a URL string. If `filename` is
a string that's neither an absolute path or a URL string, or if it's
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL string, or URL instance? Generally we don’t allow a path to be either a path string or an URL string, because of ambiguity. #48994

Copy link
MemberAuthor

@joyeecheungjoyeecheungDec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only strings are allowed as resource names, passing URL instances result in an error, this is the compilation API where the name is going to be used for stack traces and must be primitives.

Copy link
MemberAuthor

@joyeecheungjoyeecheungDec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that this is not necessarily a path, it can be a http:// URL. As long as import('file:///path/to/foo') is allowed by the default loader, this is allowed. Whenever that becomes disallowed by the default loader, the default loader can throw, and this documentation can be updated.

}
returnnewURL(referrer).href;

if(StringPrototypeStartsWith(referrerName,'file://')){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can’t do this. I proposed this in #48994 but it was shot down because you can, in fact, have a path that begins with file://; and it’s actually not all that uncommon, when people mirror URLs in a local filesystem. The logic needs to be “if it’s an instance of the URL class, parse as URL; else parse strings as paths.” cc @aduh95

Copy link
MemberAuthor

@joyeecheungjoyeecheungDec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not accept URL in the API, only the strings. This is the current behavior and disallowing file:// paths is semver major (because the filename is part of the stable API).

Also note that only strings or other primitives can end up here after the hands of V8. The default loader can also choose to throw for a file:/// string in the future, and we can update the docs when that happens. For now this is just mimic-ing the existing behavior.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to simply return the string as-is instead of parsing it at all when it looks like a URL. However the default loader treat a module with a file:// URL string name is up to the default loader, we are only passing the name over.

Comment on lines 105 to +112
functionmaybeCacheSourceMap(filename,content,cjsModuleInstance,isGeneratedSource,sourceURL,sourceMapURL){
constsourceMapsEnabled=getSourceMapsEnabled();
if(!(process.env.NODE_V8_COVERAGE||sourceMapsEnabled))return;
try{
const{ normalizeReferrerURL }=require('internal/modules/helpers');
filename=normalizeReferrerURL(filename);
}catch(err){
const{ normalizeReferrerURL }=require('internal/modules/helpers');
filename=normalizeReferrerURL(filename);
if(filename===undefined){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function could really use a JSDoc, if you know what it should be. What is filename? Is it a path string? Because normalizeReferrerURL returns an URL string; shouldn’t it be one or the other?

This feature should support data URLs and --experimental-network-imports, so path strings should probably be normalized to URL strings so that non-file:// URLs work.

Copy link
MemberAuthor

@joyeecheungjoyeecheungDec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function could really use a JSDoc, if you know what it should be.

I don't know fully what this does but filename is supposed to be always a string because it's used as keys to SafeMaps below.

shouldn’t it be one or the other?

The current behavior is that "it doesn't matter as long as this string identifies a module that contains the sourceURL that V8 gives back to us". I think there can be some cache misses caused by this but that's probably out of scope of this PR, because this PR just tries to preserve the existing mapping behavior in normalizeReferrerURL.

This feature should support data URLs and --experimental-network-imports, so path strings should probably be normalized to URL strings so that non-file:// URLs work.

Supporting those for source maps seems to be out of scope for this PR? Again this is just preserving the existing behavior. Whether additional normalization should happen and how that should work with other components should probably be discussed elsewhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filename here can either be an absolute path string (for CJS) or a URL string (for ESM) and is normalized to a URL string by normalizeReferrerURL. I can add JSDoc for source map related functions in a follow-up PR.

@joyeecheungjoyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Dec 21, 2023
@github-actionsgithub-actionsbot removed the request-ci Add this label to start a Jenkins CI on a PR. label Dec 21, 2023
@nodejs-github-bot
Copy link
Collaborator

@joyeecheung
Copy link
MemberAuthor

Ping @GeoffreyBooth did I answer your question about URL strings? The vm APIs only allows strings as identifiers and after the hands of V8 the resource names must be strings. I don't think URL is that big of an issue for this change. Whatever the vm API supports, it will continue to support. Disallowing file:// strings for resource names in vm APIs would be a semver-major that should be discussed elsewhere.

@joyeecheungjoyeecheung added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 10, 2024
@github-actionsgithub-actionsbot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 10, 2024
@nodejs-github-bot

This comment was marked as outdated.

This patch adds support for using `vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADER` as `importModuleDynamically` in all APIs that take the option except `vm.SourceTextModule`. This allows users to have a shortcut to support dynamic import() in the compiled code without missing the compilation cache if they don't need customization of the loading process. We emit an experimental warning when the `import()` is actually handled by the default loader through this option instead of requiring `--experimental-vm-modules`. In addition this refactors the documentation for `importModuleDynamically` and adds a dedicated section for it with examples. `vm.SourceTextModule` is not supported in this patch because it needs additional refactoring to handle `initializeImportMeta`, which can be done in a follow-up.
marco-ippolito pushed a commit to marco-ippolito/node that referenced this pull request Feb 19, 2024
This patch adds support for using `vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADER` as `importModuleDynamically` in all APIs that take the option except `vm.SourceTextModule`. This allows users to have a shortcut to support dynamic import() in the compiled code without missing the compilation cache if they don't need customization of the loading process. We emit an experimental warning when the `import()` is actually handled by the default loader through this option instead of requiring `--experimental-vm-modules`. In addition this refactors the documentation for `importModuleDynamically` and adds a dedicated section for it with examples. `vm.SourceTextModule` is not supported in this patch because it needs additional refactoring to handle `initializeImportMeta`, which can be done in a follow-up. PR-URL: nodejs#51244Fixes: nodejs#51154 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
marco-ippolito added a commit that referenced this pull request Mar 1, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add zcbenz to collaborators (Cheng Zhao) #51812 * add lemire to collaborators (Daniel Lemire) #51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) #51412 * (SEMVER-MINOR) add server handshake utility (snek) #51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) #51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) #51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) #51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) #51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) #50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: TODO
@marco-ippolitomarco-ippolito mentioned this pull request Mar 1, 2024
marco-ippolito added a commit that referenced this pull request Mar 1, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add zcbenz to collaborators (Cheng Zhao) #51812 * add lemire to collaborators (Daniel Lemire) #51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) #51412 * (SEMVER-MINOR) add server handshake utility (snek) #51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) #51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) #51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) #51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) #51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) #50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: #51932
marco-ippolito added a commit that referenced this pull request Mar 1, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add zcbenz to collaborators (Cheng Zhao) #51812 * add lemire to collaborators (Daniel Lemire) #51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) #51412 * (SEMVER-MINOR) add server handshake utility (snek) #51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) #51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) #51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) #51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) #51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) #50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: #51932
marco-ippolito added a commit that referenced this pull request Mar 1, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add zcbenz to collaborators (Cheng Zhao) #51812 * add lemire to collaborators (Daniel Lemire) #51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) #51412 * (SEMVER-MINOR) add server handshake utility (snek) #51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) #51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) #51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) #51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) #51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) #50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: #51932
marco-ippolito added a commit that referenced this pull request Mar 1, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add zcbenz to collaborators (Cheng Zhao) #51812 * add lemire to collaborators (Daniel Lemire) #51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) #51412 * (SEMVER-MINOR) add server handshake utility (snek) #51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) #51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) #51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) #51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) #51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) #50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: #51932
marco-ippolito added a commit that referenced this pull request Mar 1, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add zcbenz to collaborators (Cheng Zhao) #51812 * add lemire to collaborators (Daniel Lemire) #51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) #51412 * (SEMVER-MINOR) add server handshake utility (snek) #51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) #51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) #51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) #51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) #51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) #50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: #51932
marco-ippolito added a commit that referenced this pull request Mar 1, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add zcbenz to collaborators (Cheng Zhao) #51812 * add lemire to collaborators (Daniel Lemire) #51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) #51412 * (SEMVER-MINOR) add server handshake utility (snek) #51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) #51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) #51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) #51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) #51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) #50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: #51932
marco-ippolito added a commit that referenced this pull request Mar 2, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add zcbenz to collaborators (Cheng Zhao) #51812 * add lemire to collaborators (Daniel Lemire) #51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) #51412 * (SEMVER-MINOR) add server handshake utility (snek) #51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) #51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) #51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) #51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) #51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) #50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: #51932
marco-ippolito added a commit that referenced this pull request Mar 5, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add zcbenz to collaborators (Cheng Zhao) #51812 * add lemire to collaborators (Daniel Lemire) #51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) #51412 * (SEMVER-MINOR) add server handshake utility (snek) #51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) #51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) #51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) #51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) #51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) #50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: #51932
marco-ippolito added a commit that referenced this pull request Mar 5, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add zcbenz to collaborators (Cheng Zhao) #51812 * add lemire to collaborators (Daniel Lemire) #51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) #51412 * (SEMVER-MINOR) add server handshake utility (snek) #51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) #51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) #51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) #51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) #51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) #50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: #51932
RafaelGSS pushed a commit that referenced this pull request Mar 6, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add zcbenz to collaborators (Cheng Zhao) #51812 * add lemire to collaborators (Daniel Lemire) #51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) #51412 * (SEMVER-MINOR) add server handshake utility (snek) #51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) #51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) #51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) #51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) #51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) #50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: #51932
richardlau pushed a commit that referenced this pull request Mar 25, 2024
This patch adds support for using `vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADER` as `importModuleDynamically` in all APIs that take the option except `vm.SourceTextModule`. This allows users to have a shortcut to support dynamic import() in the compiled code without missing the compilation cache if they don't need customization of the loading process. We emit an experimental warning when the `import()` is actually handled by the default loader through this option instead of requiring `--experimental-vm-modules`. In addition this refactors the documentation for `importModuleDynamically` and adds a dedicated section for it with examples. `vm.SourceTextModule` is not supported in this patch because it needs additional refactoring to handle `initializeImportMeta`, which can be done in a follow-up. PR-URL: #51244Fixes: #51154 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
richardlau pushed a commit that referenced this pull request Mar 25, 2024
This patch adds support for using `vm.constants.USE_MAIN_CONTEXT_DEFAULT_LOADER` as `importModuleDynamically` in all APIs that take the option except `vm.SourceTextModule`. This allows users to have a shortcut to support dynamic import() in the compiled code without missing the compilation cache if they don't need customization of the loading process. We emit an experimental warning when the `import()` is actually handled by the default loader through this option instead of requiring `--experimental-vm-modules`. In addition this refactors the documentation for `importModuleDynamically` and adds a dedicated section for it with examples. `vm.SourceTextModule` is not supported in this patch because it needs additional refactoring to handle `initializeImportMeta`, which can be done in a follow-up. PR-URL: #51244Fixes: #51154 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
richardlau added a commit that referenced this pull request Mar 25, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add lemire to collaborators (Daniel Lemire) #51572 * add zcbenz to collaborators (Cheng Zhao) #51812 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: #52212
@richardlaurichardlau mentioned this pull request Mar 25, 2024
rdw-msft pushed a commit to rdw-msft/node that referenced this pull request Mar 26, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) nodejs#51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) nodejs#51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) nodejs#51794 doc: * add zcbenz to collaborators (Cheng Zhao) nodejs#51812 * add lemire to collaborators (Daniel Lemire) nodejs#51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) nodejs#51412 * (SEMVER-MINOR) add server handshake utility (snek) nodejs#51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) nodejs#51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) nodejs#51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) nodejs#50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) nodejs#50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) nodejs#50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) nodejs#51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) nodejs#51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) nodejs#51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) nodejs#50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) nodejs#51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) nodejs#51244 PR-URL: nodejs#51932
richardlau added a commit that referenced this pull request Mar 26, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) #51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) #51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) #51794 doc: * add lemire to collaborators (Daniel Lemire) #51572 * add zcbenz to collaborators (Cheng Zhao) #51812 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) #51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) #50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) #50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) #50960 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) #51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) #51244 PR-URL: #52212
jcbhmr pushed a commit to jcbhmr/node that referenced this pull request May 15, 2024
Notable changes: build: * (SEMVER-MINOR) build opt to set local location of headers (Michael Dawson) nodejs#51525 crypto: * (SEMVER-MINOR) implement crypto.hash() (Joyee Cheung) nodejs#51044 * update root certificates to NSS 3.98 (Node.js GitHub Bot) nodejs#51794 doc: * add zcbenz to collaborators (Cheng Zhao) nodejs#51812 * add lemire to collaborators (Daniel Lemire) nodejs#51572 http2: * (SEMVER-MINOR) add h2 compat support for appendHeader (Tim Perry) nodejs#51412 * (SEMVER-MINOR) add server handshake utility (snek) nodejs#51172 * (SEMVER-MINOR) receive customsettings (Marten Richter) nodejs#51323 lib: * (SEMVER-MINOR) move encodingsMap to internal/util (Joyee Cheung) nodejs#51044 sea: * (SEMVER-MINOR) support sea.getRawAsset() (Joyee Cheung) nodejs#50960 * (SEMVER-MINOR) support embedding assets (Joyee Cheung) nodejs#50960 src: * (SEMVER-MINOR) print string content better in BlobDeserializer (Joyee Cheung) nodejs#50960 * (SEMVER-MINOR) support multi-line values for .env file (IlyasShabi) nodejs#51289 * (SEMVER-MINOR) add `process.loadEnvFile` and `util.parseEnv` (Yagiz Nizipli) nodejs#51476 * (SEMVER-MINOR) do not coerce dotenv paths (Tobias Nießen) nodejs#51425 stream: * (SEMVER-MINOR) implement `min` option for `ReadableStreamBYOBReader.read` (Mattias Buelens) nodejs#50888 util: * (SEMVER-MINOR) add styleText API to text formatting (Rafael Gonzaga) nodejs#51850 vm: * (SEMVER-MINOR) support using the default loader to handle dynamic import() (Joyee Cheung) nodejs#51244 PR-URL: nodejs#51932
hkleungai added a commit to hkleungai/node that referenced this pull request May 3, 2025
Current alignment mislead doc reader into thinking `importModuleDynamically` is a separate positional param right next to `options`, which is incorrect and need to be fixed. This misalignment is introduced in a PR merged in Feb 2024. I belive this doc fix applies to node v20 and above. Refs: nodejs#51244
nodejs-github-bot pushed a commit that referenced this pull request May 5, 2025
Current alignment mislead doc reader into thinking `importModuleDynamically` is a separate positional param right next to `options`, which is incorrect and need to be fixed. This misalignment is introduced in a PR merged in Feb 2024. I belive this doc fix applies to node v20 and above. Refs: #51244 PR-URL: #58145 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Daeyeon Jeong <[email protected]>
aduh95 pushed a commit that referenced this pull request May 8, 2025
Current alignment mislead doc reader into thinking `importModuleDynamically` is a separate positional param right next to `options`, which is incorrect and need to be fixed. This misalignment is introduced in a PR merged in Feb 2024. I belive this doc fix applies to node v20 and above. Refs: #51244 PR-URL: #58145 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Daeyeon Jeong <[email protected]>
aduh95 pushed a commit that referenced this pull request May 19, 2025
Current alignment mislead doc reader into thinking `importModuleDynamically` is a separate positional param right next to `options`, which is incorrect and need to be fixed. This misalignment is introduced in a PR merged in Feb 2024. I belive this doc fix applies to node v20 and above. Refs: #51244 PR-URL: #58145 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Daeyeon Jeong <[email protected]>
marco-ippolito pushed a commit that referenced this pull request Jun 5, 2025
Current alignment mislead doc reader into thinking `importModuleDynamically` is a separate positional param right next to `options`, which is incorrect and need to be fixed. This misalignment is introduced in a PR merged in Feb 2024. I belive this doc fix applies to node v20 and above. Refs: #51244 PR-URL: #58145 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Daeyeon Jeong <[email protected]>
marco-ippolito pushed a commit that referenced this pull request Jun 5, 2025
Current alignment mislead doc reader into thinking `importModuleDynamically` is a separate positional param right next to `options`, which is incorrect and need to be fixed. This misalignment is introduced in a PR merged in Feb 2024. I belive this doc fix applies to node v20 and above. Refs: #51244 PR-URL: #58145 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Daeyeon Jeong <[email protected]>
marco-ippolito pushed a commit that referenced this pull request Jun 10, 2025
Current alignment mislead doc reader into thinking `importModuleDynamically` is a separate positional param right next to `options`, which is incorrect and need to be fixed. This misalignment is introduced in a PR merged in Feb 2024. I belive this doc fix applies to node v20 and above. Refs: #51244 PR-URL: #58145 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Daeyeon Jeong <[email protected]>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.lib / srcIssues and PRs related to general changes in the lib or src directory.needs-ciPRs that need a full CI run.semver-minorPRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vm importModuleDynamically option in Node 20.10 requires --experimental-vm-modules flag and 20.9 does not

7 participants

@joyeecheung@nodejs-github-bot@GeoffreyBooth@bmuenzenmeyer@targos@legendecas@aduh95