From df62f1d6edcc26ff5e17ba9ad4455b500364716e 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 --- 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 125fa11ebd4d26..93ad447b626903 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, @@ -149,9 +150,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; @@ -271,7 +269,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); @@ -473,7 +470,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) { @@ -638,7 +634,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',