GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib: load fewer builtins when bootstrapping without a snapshot · nodejs/node@e8e2abc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • fs.js
    • internal
      • bootstrap/switches
        • is_main_thread.js
      • dns
        • utils.js
      • modules
        • cjs
          • loader.js
        • esm
          • load.js
          • translators.js
      • process
        • execution.js
        • pre_execution.js
      • url.js
      • worker.js
    • worker_threads.js
  • test/parallel
    • test-bootstrap-modules.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/fs.js‎

Copy file name to clipboardExpand all lines: lib/fs.js
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ const { isArrayBufferView } = require('internal/util/types');
6464

6565
const binding = internalBinding('fs');
6666

67-
const { createBlobFromFilePath } = require('internal/blob');
68-
6967
const { Buffer } = require('buffer');
7068
const { isBuffer: BufferIsBuffer } = Buffer;
7169
const BufferToString = uncurryThis(Buffer.prototype.toString);
@@ -784,6 +782,7 @@ function openAsBlob(path, options = kEmptyObject) {
784782
// To give ourselves flexibility to maybe return the Blob asynchronously,
785783
// this API returns a Promise.
786784
path = getValidatedPath(path);
785+
const { createBlobFromFilePath } = require('internal/blob');
787786
return PromiseResolve(createBlobFromFilePath(path, { type }));
788787
}
789788

Collapse file

‎lib/internal/bootstrap/switches/is_main_thread.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/switches/is_main_thread.js
+18-5Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,27 @@ rawMethods.resetStdioForTesting = function() {
292292

293293
// Needed by the module loader and generally needed everywhere.
294294
require('fs');
295-
require('util');
296-
require('url'); // eslint-disable-line no-restricted-modules
297295
internalBinding('module_wrap');
298296
require('internal/modules/cjs/loader');
299-
require('internal/modules/esm/loader');
300297
require('internal/modules/esm/utils');
298+
if (isBuildingSnapshot()) {
299+
// Preloaded so that they are part of the snapshot, where they cost nothing
300+
// at startup. When bootstrapping WITHOUT a snapshot (worker threads,
301+
// embedders that create their own isolate, --no-node-snapshot) they are
302+
// loaded on first use instead: the ESM loader (with its translators,
303+
// resolver and their dependencies) by run_main/import(), the public util
304+
// and url modules by whoever requires them, data: URL and TypeScript
305+
// support by the module loaders, internal/blob by fs.openAsBlob(), and the
306+
// DNS helpers by node:dns or an explicit --dns-result-order (see
307+
// pre_execution).
308+
require('util');
309+
require('url'); // eslint-disable-line no-restricted-modules
310+
require('internal/modules/esm/loader');
311+
require('internal/data_url');
312+
require('internal/modules/typescript');
313+
require('internal/blob');
314+
require('internal/dns/utils');
315+
}
301316

302317
// Needed to refresh the time origin.
303318
require('internal/perf/utils');
@@ -311,8 +326,6 @@ internalBinding('wasm_web_api');
311326
internalBinding('worker');
312327
// Needed by most execution modes.
313328
require('internal/modules/run_main');
314-
// Needed to refresh DNS configurations.
315-
require('internal/dns/utils');
316329
// Needed by almost all execution modes. It's fine to
317330
// load them into the snapshot as long as we don't run
318331
// any of the initialization.
Collapse file

‎lib/internal/dns/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/dns/utils.js
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,15 @@ class ResolverBase {
214214
}
215215

216216
let defaultResolver;
217-
let dnsOrder;
217+
// May already hold a value chosen by the snapshotted application; a
218+
// --dns-result-order flag given at runtime overrides it in initializeDns().
219+
let dnsOrder = 'verbatim';
218220
const validDnsOrders = ['verbatim', 'ipv4first', 'ipv6first'];
219221
const validFamilies = [0, 4, 6];
220222

221223
function initializeDns() {
222224
const orderFromCLI = getOptionValue('--dns-result-order');
223-
if (!orderFromCLI) {
224-
dnsOrder ??= 'verbatim';
225-
} else {
225+
if (orderFromCLI) {
226226
// Allow the deserialized application to override order from CLI.
227227
validateOneOf(orderFromCLI, '--dns-result-order', validDnsOrders);
228228
dnsOrder = orderFromCLI;
Collapse file

‎lib/internal/modules/cjs/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ const {
180180
resolveWithHooks,
181181
validateLoadStrict,
182182
} = require('internal/modules/customization_hooks');
183-
const { stripTypeScriptModuleTypes } = require('internal/modules/typescript');
183+
const lazyTypeScript = getLazy(() => require('internal/modules/typescript'));
184184
const packageJsonReader = require('internal/modules/package_json_reader');
185185
const { getOptionValue, getEmbedderOptions } = require('internal/options');
186186
const shouldReportRequiredModules = getLazy(() => process.env.WATCH_REPORT_DEPENDENCIES);
@@ -1885,7 +1885,7 @@ function wrapSafe(filename, content, cjsModuleInstance, format) {
18851885
Module.prototype._compile = function(content, filename, format) {
18861886
if (format === 'commonjs-typescript' || format === 'module-typescript' || format === 'typescript') {
18871887
this[kURL] ??= convertCJSFilenameToURL(filename);
1888-
content = stripTypeScriptModuleTypes(content, filename, this[kURL]);
1888+
content = lazyTypeScript().stripTypeScriptModuleTypes(content, filename, this[kURL]);
18891889
switch (format) {
18901890
case 'commonjs-typescript': {
18911891
format = 'commonjs';
Collapse file

‎lib/internal/modules/esm/load.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/load.js
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ const {
2020
ERR_UNSUPPORTED_ESM_URL_SCHEME,
2121
} = require('internal/errors').codes;
2222

23-
const {
24-
dataURLProcessor,
25-
} = require('internal/data_url');
2623

2724
/**
2825
* @param {URL} url URL to the module
@@ -40,6 +37,7 @@ function getSourceSync(url, context) {
4037
// Prefer module.registerHooks() or other more formal fs hooks released in the future.
4138
source = fs.readFileSync(url);
4239
} else if (protocol === 'data:') {
40+
const { dataURLProcessor } = require('internal/data_url'); // Only for data: URLs.
4341
const result = dataURLProcessor(url);
4442
if (result === 'failure') {
4543
throw new ERR_INVALID_URL(responseURL);
Collapse file

‎lib/internal/modules/esm/translators.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/translators.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ const {
3030
stripBOM,
3131
urlToFilename,
3232
} = require('internal/modules/helpers');
33-
const { stripTypeScriptModuleTypes } = require('internal/modules/typescript');
33+
function stripTypeScriptModuleTypes(source, url) {
34+
// Only needed for TypeScript sources; keep it out of the loader's startup path.
35+
return require('internal/modules/typescript').stripTypeScriptModuleTypes(source, url);
36+
}
3437
const {
3538
kIsCachedByESMLoader,
3639
Module: CJSModule,
Collapse file

‎lib/internal/process/execution.js‎

Copy file name to clipboardExpand all lines: lib/internal/process/execution.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ const {
2525
kSourcePhase,
2626
kEvaluationPhase,
2727
} = internalBinding('module_wrap');
28-
const { stripTypeScriptModuleTypes } = require('internal/modules/typescript');
28+
function stripTypeScriptModuleTypes(source, filename) {
29+
return require('internal/modules/typescript').stripTypeScriptModuleTypes(source, filename);
30+
}
2931

3032
const {
3133
executionAsyncId,
Collapse file

‎lib/internal/process/pre_execution.js‎

Copy file name to clipboardExpand all lines: lib/internal/process/pre_execution.js
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ function prepareExecution(options) {
137137

138138
initializeConfigFileSupport();
139139

140-
require('internal/dns/utils').initializeDns();
140+
// internal/dns/utils (and internal/net behind it) is only needed up front
141+
// to validate an explicit --dns-result-order or to register the resolver's
142+
// snapshot serialization; otherwise it is loaded with node:dns.
143+
if (getOptionValue('--dns-result-order') || isBuildingSnapshot()) {
144+
require('internal/dns/utils').initializeDns();
145+
}
141146

142147
if (isMainThread) {
143148
assert(internalBinding('worker').isMainThread);
Collapse file

‎lib/internal/url.js‎

Copy file name to clipboardExpand all lines: lib/internal/url.js
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ const {
9393
kValidateObjectAllowObjects,
9494
} = require('internal/validators');
9595

96-
const { percentDecode } = require('internal/data_url');
96+
let percentDecode;
97+
function lazyPercentDecode(input) {
98+
percentDecode ??= require('internal/data_url').percentDecode;
99+
return percentDecode(input);
100+
}
97101

98102
const querystring = require('querystring');
99103

@@ -1560,7 +1564,7 @@ function getPathBufferFromURLWin32(url) {
15601564
// percent encoded characters and we take the string as is. Any invalid
15611565
// percent encodings, e.g. `%ZZ` are ignored and are passed through
15621566
// literally.
1563-
const decodedu8 = percentDecode(Buffer.from(pathname, 'utf8'));
1567+
const decodedu8 = lazyPercentDecode(Buffer.from(pathname, 'utf8'));
15641568
const decodedPathname = Buffer.from(TypedArrayPrototypeGetBuffer(decodedu8),
15651569
TypedArrayPrototypeGetByteOffset(decodedu8),
15661570
TypedArrayPrototypeGetByteLength(decodedu8));
@@ -1635,7 +1639,7 @@ function getPathBufferFromURLPosix(url) {
16351639
// won't scan for the slashes at all, and instead will decode the bytes
16361640
// literally into the returned Buffer. We're going to do the best we can and
16371641
// just interpret the input url as a sequence of bytes.
1638-
const u8 = percentDecode(Buffer.from(pathname, 'utf8'));
1642+
const u8 = lazyPercentDecode(Buffer.from(pathname, 'utf8'));
16391643
return Buffer.from(TypedArrayPrototypeGetBuffer(u8),
16401644
TypedArrayPrototypeGetByteOffset(u8),
16411645
TypedArrayPrototypeGetByteLength(u8));
Collapse file

‎lib/internal/worker.js‎

Copy file name to clipboardExpand all lines: lib/internal/worker.js
+2-5Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ const {
3030
const EventEmitter = require('events');
3131
const assert = require('internal/assert');
3232
const path = require('path');
33-
const {
34-
internalEventLoopUtilization,
35-
} = require('internal/perf/event_loop_utilization');
36-
3733
const errorCodes = require('internal/errors').codes;
3834
const {
3935
ERR_WORKER_NOT_RUNNING,
@@ -60,7 +56,6 @@ const {
6056
WritableWorkerStdio,
6157
} = workerIo;
6258
const { createMainThreadPort, destroyMainThreadPort } = require('internal/worker/messaging');
63-
const { deserializeError } = require('internal/error_serdes');
6459
const { fileURLToPath, isURL, pathToFileURL } = require('internal/url');
6560
const {
6661
constructSharedArrayBuffer,
@@ -415,6 +410,7 @@ class Worker extends EventEmitter {
415410

416411
[kOnErrorMessage](serialized) {
417412
// This is what is called for uncaught exceptions.
413+
const { deserializeError } = require('internal/error_serdes');
418414
const error = deserializeError(serialized);
419415
this.emit('error', error);
420416
}
@@ -697,6 +693,7 @@ function makeResourceLimits(float64arr) {
697693
}
698694

699695
function eventLoopUtilization(util1, util2) {
696+
const { internalEventLoopUtilization } = require('internal/perf/event_loop_utilization');
700697
// TODO(trevnorris): Works to solve the thread-safe read/write issue of
701698
// loopTime, but has the drawback that it can't be set until the event loop
702699
// has had a chance to turn. So it will be impossible to read the ELU of

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.