| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1007,7 +1007,9 @@ added: | |||
| 1007 | 1007 | ||
| 1008 | 1008 | > Stability: 1 - Experimental | |
| 1009 | 1009 | ||
| 1010 | - Preload the specified module at startup. | ||
| 1010 | + Preload the specified module at startup. If the flag is provided several times, | ||
| 1011 | + each module will be executed sequentially in the order they appear, starting | ||
| 1012 | + with the ones provided in [`NODE_OPTIONS`][]. | ||
| 1011 | 1013 | ||
| 1012 | 1014 | Follows [ECMAScript module][] resolution rules. | |
| 1013 | 1015 | Use [`--require`][] to load a [CommonJS module][]. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,9 +1,5 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - const { | ||
| 4 | - SafePromiseAllReturnVoid, | ||
| 5 | - } = primordials; | ||
| 6 | - | ||
| 7 | 3 | const { createModuleLoader } = require('internal/modules/esm/loader'); | |
| 8 | 4 | const { getOptionValue } = require('internal/options'); | |
| 9 | 5 | const { | |
@@ -23,11 +19,9 @@ module.exports = { | |||
| 23 | 19 | const userImports = getOptionValue('--import'); | |
| 24 | 20 | if (userImports.length > 0) { | |
| 25 | 21 | const parentURL = getCWDURL().href; | |
| 26 | - await SafePromiseAllReturnVoid(userImports, (specifier) => esmLoader.import( | ||
| 27 | - specifier, | ||
| 28 | - parentURL, | ||
| 29 | - kEmptyObject, | ||
| 30 | - )); | ||
| 22 | + for (let i = 0; i < userImports.length; i++) { | ||
| 23 | + await esmLoader.import(userImports[i], parentURL, kEmptyObject); | ||
| 24 | + } | ||
| 31 | 25 | } else { | |
| 32 | 26 | esmLoader.forceLoadHooks(); | |
| 33 | 27 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -182,4 +182,37 @@ describe('import modules using --import', { concurrency: true }, () => { | |||
| 182 | 182 | assert.strictEqual(code, 0); | |
| 183 | 183 | assert.strictEqual(signal, null); | |
| 184 | 184 | }); | |
| 185 | + | ||
| 186 | + it('should import files sequentially', async () => { | ||
| 187 | + const { code, signal, stderr, stdout } = await spawnPromisified( | ||
| 188 | + execPath, | ||
| 189 | + [ | ||
| 190 | + '--import', fixtures.fileURL('es-modules', 'esm-top-level-await.mjs'), | ||
| 191 | + '--import', fixtures.fileURL('es-modules', 'print-3.mjs'), | ||
| 192 | + fixtures.path('empty.js'), | ||
| 193 | + ] | ||
| 194 | + ); | ||
| 195 | + | ||
| 196 | + assert.strictEqual(stderr, ''); | ||
| 197 | + assert.match(stdout, /^1\r?\n2\r?\n3\r?\n$/); | ||
| 198 | + assert.strictEqual(code, 0); | ||
| 199 | + assert.strictEqual(signal, null); | ||
| 200 | + }); | ||
| 201 | + | ||
| 202 | + it('should import files from the env before ones from the CLI', async () => { | ||
| 203 | + const { code, signal, stderr, stdout } = await spawnPromisified( | ||
| 204 | + execPath, | ||
| 205 | + [ | ||
| 206 | + '--import', fixtures.fileURL('es-modules', 'print-3.mjs'), | ||
| 207 | + fixtures.path('empty.js'), | ||
| 208 | + ], | ||
| 209 | + { env: { ...process.env, NODE_OPTIONS: `--import ${JSON.stringify(fixtures.fileURL('es-modules', 'esm-top-level-await.mjs'))}` } } | ||
| 210 | + ); | ||
| 211 | + | ||
| 212 | + assert.strictEqual(stderr, ''); | ||
| 213 | + assert.match(stdout, /^1\r?\n2\r?\n3\r?\n$/); | ||
| 214 | + assert.strictEqual(code, 0); | ||
| 215 | + assert.strictEqual(signal, null); | ||
| 216 | + | ||
| 217 | + }); | ||
| 185 | 218 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,7 @@ | |||
| 1 | - import { setImmediate } from 'node:timers/promises'; | ||
| 1 | + import { setTimeout } from 'node:timers/promises'; | ||
| 2 | 2 | ||
| 3 | - await setImmediate(); | ||
| 3 | + // Waiting some arbitrary amount of time to make sure other tasks won't start | ||
| 4 | + // executing in the mean time. | ||
| 5 | + await setTimeout(9); | ||
| 4 | 6 | console.log(1); | |
| 5 | 7 | console.log(2); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments