From 4884991a129758a6ddd515855961b05db23d8e86 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 20 May 2021 02:50:13 +0800 Subject: [PATCH] lib: include url in bootstrap snapshot and remove unnecessary lazy-loads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/38826 Refs: https://github.com/nodejs/node/issues/35711 Reviewed-By: James M Snell Reviewed-By: Michaƫl Zasso Reviewed-By: Khaidi Chu --- lib/internal/bootstrap/node.js | 1 + lib/internal/url.js | 4 +--- lib/url.js | 7 +------ test/parallel/test-bootstrap-modules.js | 1 + 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index de5acbef5b580a..863d4ef5608bce 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -362,6 +362,7 @@ process.emitWarning = emitWarning; require('fs'); require('v8'); require('vm'); +require('url'); function setupPrepareStackTrace() { const { diff --git a/lib/internal/url.js b/lib/internal/url.js index 16a453c7845a30..7d2bed80028d30 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -70,8 +70,7 @@ const { validateObject, } = require('internal/validators'); -// Lazy loaded for startup performance. -let querystring; +const querystring = require('querystring'); const { platform } = process; const isWindows = platform === 'win32'; @@ -1046,7 +1045,6 @@ function parseParams(qs) { } else if (encodeCheck > 0) { if (isHexTable[code] === 1) { if (++encodeCheck === 3) { - querystring = require('querystring'); encoded = true; } } else { diff --git a/lib/url.js b/lib/url.js index 177bd9eb59ca44..e3071a3a56fd59 100644 --- a/lib/url.js +++ b/lib/url.js @@ -32,6 +32,7 @@ const { const { toASCII } = require('internal/idna'); const { encodeStr, hexTable } = require('internal/querystring'); +const querystring = require('querystring'); const { ERR_INVALID_ARG_TYPE @@ -148,9 +149,6 @@ const { CHAR_AT, } = require('internal/constants'); -// Lazy loaded for startup performance. -let querystring; - function urlParse(url, parseQueryString, slashesDenoteHost) { if (url instanceof Url) return url; @@ -256,7 +254,6 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { if (simplePath[2]) { this.search = simplePath[2]; if (parseQueryString) { - if (querystring === undefined) querystring = require('querystring'); this.query = querystring.parse(this.search.slice(1)); } else { this.query = this.search.slice(1); @@ -445,7 +442,6 @@ Url.prototype.parse = function parse(url, parseQueryString, slashesDenoteHost) { this.query = rest.slice(questionIdx + 1, hashIdx); } if (parseQueryString) { - if (querystring === undefined) querystring = require('querystring'); this.query = querystring.parse(this.query); } } else if (parseQueryString) { @@ -610,7 +606,6 @@ Url.prototype.format = function format() { } if (this.query !== null && typeof this.query === 'object') { - if (querystring === undefined) querystring = require('querystring'); query = querystring.stringify(this.query); } diff --git a/test/parallel/test-bootstrap-modules.js b/test/parallel/test-bootstrap-modules.js index 28feaff6f3310a..f18f85728d36e3 100644 --- a/test/parallel/test-bootstrap-modules.js +++ b/test/parallel/test-bootstrap-modules.js @@ -116,6 +116,7 @@ const expectedModules = new Set([ 'NativeModule internal/blob', 'NativeModule async_hooks', 'NativeModule path', + 'NativeModule querystring', 'NativeModule stream', 'NativeModule stream/promises', 'NativeModule string_decoder',