Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V20.5.0 proposal #48761

Merged
merged 55 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
df363d0
src: deduplicate X509 getter implementations
tniessen Jul 3, 2023
25c5a0a
meta: bump github/codeql-action from 2.3.6 to 2.20.1
dependabot[bot] Jul 3, 2023
332e480
meta: bump ossf/scorecard-action from 2.1.3 to 2.2.0
dependabot[bot] Jul 3, 2023
9cf2e1f
src,lib: reducing C++ calls of esm legacy main resolve
H4ad Jul 3, 2023
b5cb69c
meta: bump step-security/harden-runner from 2.4.0 to 2.4.1
dependabot[bot] Jul 3, 2023
42dc6eb
tools: update lint-md-dependencies to rollup@3.26.0
nodejs-github-bot Jul 4, 2023
a1f4ff7
tools: update eslint to 8.44.0
nodejs-github-bot Jul 4, 2023
f4333b1
permission: v8.writeHeapSnapshot and process.report
RafaelGSS Jul 4, 2023
dff6c25
meta: bump actions/checkout from 3.5.2 to 3.5.3
dependabot[bot] Jul 5, 2023
e2d0195
bootstrap: hide experimental web globals with flag kNoBrowserGlobals
legendecas Jul 5, 2023
4e08160
child_process: support `Symbol.dispose`
MoLow Jul 5, 2023
e2442bb
timers: support Symbol.dispose
MoLow Jul 5, 2023
dfa0aee
Revert "test: remove test-crypto-keygen flaky designation"
lpinca Jul 5, 2023
a316808
events: allow safely adding listener to abortSignal
atlowChemi Jul 5, 2023
4a0b66e
http2: send RST code 8 on AbortController signal
devm33 Jul 6, 2023
dd7ea3e
doc: mention git node release prepare
RafaelGSS Jul 6, 2023
7daefae
doc: drop <b> of v20 changelog
RafaelGSS Jul 6, 2023
999ae0c
doc: fix copy node executable in Windows
yoavain Jul 6, 2023
150e155
deps: upgrade npm to 9.8.0
npm-cli-bot Jul 8, 2023
caccb05
doc: clarify transform._transform() callback argument logic
rafasofizada Jul 8, 2023
67b13d1
events: fix bug listenerCount don't compare wrapped listener
yuzheng14 Jul 10, 2023
d99ea48
src: remove kEagerCompile for CompileFunction
kvakil Jul 6, 2023
b7a076a
deps: V8: cherry-pick cb00db4dba6c
kvakil Jul 6, 2023
b25e78a
tools: update lint-md-dependencies to rollup@3.26.2
nodejs-github-bot Jul 11, 2023
38ce95d
tools: update doc to unist-util-select@5.0.0 unist-util-visit@5.0.0
nodejs-github-bot Jul 11, 2023
cc7809d
esm: fix emit deprecation on legacy main resolve
aduh95 Jul 11, 2023
e4333ac
http2: use addAbortListener
atlowChemi Jul 5, 2023
f691dca
readline: use addAbortListener
atlowChemi Jul 5, 2023
5a382d0
stream: use addAbortListener
atlowChemi Jul 5, 2023
002ce31
dgram: use addAbortListener
atlowChemi Jul 5, 2023
ac11264
net: use addAbortListener
atlowChemi Jul 5, 2023
7d843bb
child_process: use addAbortListener
atlowChemi Jul 5, 2023
1295c76
lib: use addAbortListener
atlowChemi Jul 5, 2023
c47b2cb
dgram: socket add `asyncDispose`
atlowChemi Jul 9, 2023
cfa69bd
net: server add `asyncDispose`
atlowChemi Jul 9, 2023
eb0aba5
bootstrap: use correct descriptor for Symbol.{dispose,asyncDispose}
ljharb Jul 12, 2023
d378b2c
test: move test-net-throttle to parallel
lpinca Jun 29, 2023
6e82077
test: deflake test-net-throttle
lpinca Jun 29, 2023
c73cfcc
deps: update acorn to 8.10.0
nodejs-github-bot Jul 12, 2023
69b55d2
doc: fix ambiguity in http.md and https.md
an5er Jul 8, 2023
daeb21d
stream: fix deadlock when pipeing to full sink
ronag Jul 12, 2023
4398ade
tools: run fetch_deps.py with Python 3
richardlau Jul 12, 2023
67a1018
build: do not pass target toolchain flags to host toolchain
tie Jul 12, 2023
a9a4b73
src: make BaseObject iteration order deterministic
joyeecheung Jul 12, 2023
fa94deb
deps: update minimatch to 9.0.3
nodejs-github-bot Jul 12, 2023
6406f50
module: add SourceMap.lineLengths
isaacs Jul 12, 2023
986b46a
fs: add a fast-path for readFileSync utf-8
anonrig Jul 12, 2023
45be29d
doc: add atlowChemi to collaborators
atlowChemi Jul 13, 2023
82d6b13
permission: add debug log when inserting fs nodes
RafaelGSS Jul 13, 2023
1454f02
deps: update nghttp2 to 1.55.0
nodejs-github-bot Jul 14, 2023
ef7728b
deps: update nghttp2 to 1.55.1
nodejs-github-bot Jul 17, 2023
227e6bd
src: pass syscall on `fs.readFileSync` fail operation
anonrig Jul 17, 2023
07bfcc4
url: fix `canParse` false value when v8 optimizes
anonrig Jul 17, 2023
0ef73ff
test_runner: add shards support
rluvaton Jul 5, 2023
f13c7f5
2023-07-18, Version 20.5.0 (Current)
juanarbol Jul 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
src,lib: reducing C++ calls of esm legacy main resolve
Instead of many C++ calls, now we make only one C++ call
to return a enum number that represents the selected state.

PR-URL: #48325
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
  • Loading branch information
H4ad authored and juanarbol committed Jul 13, 2023
commit 9cf2e1f55b8446a7cde23699d00a3be73aa0c8f1
53 changes: 53 additions & 0 deletions benchmark/esm/esm-legacyMainResolve.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Tests the impact on eager operations required for policies affecting
// general startup, does not test lazy operations
'use strict';
const fs = require('node:fs');
const path = require('node:path');
const common = require('../common.js');

const tmpdir = require('../../test/common/tmpdir.js');
const { pathToFileURL } = require('node:url');

const benchmarkDirectory =
path.resolve(tmpdir.path, 'benchmark-import-meta-resolve');

const configs = {
n: [1e4],
packageJsonUrl: [
'node_modules/test/package.json',
],
packageConfigMain: ['', './index.js'],
resolvedFile: [
'node_modules/test/index.js',
'node_modules/test/index.json',
'node_modules/test/index.node',
'node_modules/non-exist',
],
};

const options = {
flags: ['--expose-internals'],
};

const bench = common.createBenchmark(main, configs, options);

function main(conf) {
const { legacyMainResolve } = require('internal/modules/esm/resolve');
tmpdir.refresh();

fs.mkdirSync(path.join(benchmarkDirectory, 'node_modules', 'test'), { recursive: true });
fs.writeFileSync(path.join(benchmarkDirectory, conf.resolvedFile), '\n');

const packageJsonUrl = pathToFileURL(conf.packageJsonUrl);
const packageConfigMain = { main: conf.packageConfigMain };

bench.start();

for (let i = 0; i < conf.n; i++) {
try {
legacyMainResolve(packageJsonUrl, packageConfigMain, undefined);
} catch { /* empty */ }
}

bench.end(conf.n);
}
91 changes: 46 additions & 45 deletions lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ const preserveSymlinksMain = getOptionValue('--preserve-symlinks-main');
const experimentalNetworkImports =
getOptionValue('--experimental-network-imports');
const typeFlag = getOptionValue('--input-type');
const { URL, pathToFileURL, fileURLToPath, isURL, toPathIfFileURL } = require('internal/url');
const { URL, pathToFileURL, fileURLToPath, isURL } = require('internal/url');
const { canParse: URLCanParse } = internalBinding('url');
const { legacyMainResolve: FSLegacyMainResolve } = internalBinding('fs');
const {
ERR_INPUT_TYPE_NOT_ALLOWED,
ERR_INVALID_ARG_TYPE,
Expand Down Expand Up @@ -133,13 +134,34 @@ function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) {

const realpathCache = new SafeMap();

/**
* @param {string | URL} url
* @returns {boolean}
*/
function fileExists(url) {
return internalModuleStat(toNamespacedPath(toPathIfFileURL(url))) === 0;
}
const legacyMainResolveExtensions = [
'',
'.js',
'.json',
'.node',
'/index.js',
'/index.json',
'/index.node',
'./index.js',
'./index.json',
'./index.node',
];

const legacyMainResolveExtensionsIndexes = {
// 0-6: when packageConfig.main is defined
kResolvedByMain: 0,
kResolvedByMainJs: 1,
kResolvedByMainJson: 2,
kResolvedByMainNode: 3,
kResolvedByMainIndexJs: 4,
kResolvedByMainIndexJson: 5,
kResolvedByMainIndexNode: 6,
// 7-9: when packageConfig.main is NOT defined,
// or when the previous case didn't found the file
kResolvedByPackageAndJs: 7,
kResolvedByPackageAndJson: 8,
kResolvedByPackageAndNode: 9,
};

/**
* Legacy CommonJS main resolution:
Expand All @@ -154,44 +176,22 @@ function fileExists(url) {
* @returns {URL}
*/
function legacyMainResolve(packageJSONUrl, packageConfig, base) {
let guess;
if (packageConfig.main !== undefined) {
// Note: fs check redundances will be handled by Descriptor cache here.
if (fileExists(guess = new URL(`./${packageConfig.main}`,
packageJSONUrl))) {
return guess;
} else if (fileExists(guess = new URL(`./${packageConfig.main}.js`,
packageJSONUrl)));
else if (fileExists(guess = new URL(`./${packageConfig.main}.json`,
packageJSONUrl)));
else if (fileExists(guess = new URL(`./${packageConfig.main}.node`,
packageJSONUrl)));
else if (fileExists(guess = new URL(`./${packageConfig.main}/index.js`,
packageJSONUrl)));
else if (fileExists(guess = new URL(`./${packageConfig.main}/index.json`,
packageJSONUrl)));
else if (fileExists(guess = new URL(`./${packageConfig.main}/index.node`,
packageJSONUrl)));
else guess = undefined;
if (guess) {
emitLegacyIndexDeprecation(guess, packageJSONUrl, base,
packageConfig.main);
return guess;
}
// Fallthrough.
}
if (fileExists(guess = new URL('./index.js', packageJSONUrl)));
// So fs.
else if (fileExists(guess = new URL('./index.json', packageJSONUrl)));
else if (fileExists(guess = new URL('./index.node', packageJSONUrl)));
else guess = undefined;
if (guess) {
emitLegacyIndexDeprecation(guess, packageJSONUrl, base, packageConfig.main);
return guess;
const packageJsonUrlString = packageJSONUrl.href;

if (typeof packageJsonUrlString !== 'string') {
throw new ERR_INVALID_ARG_TYPE('packageJSONUrl', ['URL'], packageJSONUrl);
}
// Not found.
throw new ERR_MODULE_NOT_FOUND(
fileURLToPath(new URL('.', packageJSONUrl)), fileURLToPath(base));

const baseStringified = isURL(base) ? base.href : base;

const resolvedOption = FSLegacyMainResolve(packageJsonUrlString, packageConfig.main, baseStringified);

const baseUrl = resolvedOption <= legacyMainResolveExtensionsIndexes.kResolvedByMainIndexNode ? `./${packageConfig.main}` : '';
const resolvedUrl = new URL(baseUrl + legacyMainResolveExtensions[resolvedOption], packageJSONUrl);

emitLegacyIndexDeprecation(resolvedUrl, packageJSONUrl, base, packageConfig.main);

return resolvedUrl;
}

const encodedSepRegEx = /%2F|%5C/i;
Expand Down Expand Up @@ -1078,6 +1078,7 @@ module.exports = {
packageExportsResolve,
packageImportsResolve,
throwIfInvalidParentURL,
legacyMainResolve,
};

// cycle
Expand Down
5 changes: 5 additions & 0 deletions src/node_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,22 @@ void AppendExceptionLine(Environment* env,
V(ERR_INVALID_ARG_VALUE, TypeError) \
V(ERR_OSSL_EVP_INVALID_DIGEST, Error) \
V(ERR_INVALID_ARG_TYPE, TypeError) \
V(ERR_INVALID_FILE_URL_HOST, TypeError) \
V(ERR_INVALID_FILE_URL_PATH, TypeError) \
V(ERR_INVALID_OBJECT_DEFINE_PROPERTY, TypeError) \
V(ERR_INVALID_MODULE, Error) \
V(ERR_INVALID_STATE, Error) \
V(ERR_INVALID_THIS, TypeError) \
V(ERR_INVALID_TRANSFER_OBJECT, TypeError) \
V(ERR_INVALID_URL, TypeError) \
V(ERR_INVALID_URL_SCHEME, TypeError) \
V(ERR_MEMORY_ALLOCATION_FAILED, Error) \
V(ERR_MESSAGE_TARGET_CONTEXT_UNAVAILABLE, Error) \
V(ERR_MISSING_ARGS, TypeError) \
V(ERR_MISSING_TRANSFERABLE_IN_TRANSFER_LIST, TypeError) \
V(ERR_MISSING_PASSPHRASE, TypeError) \
V(ERR_MISSING_PLATFORM_FOR_WORKER, Error) \
V(ERR_MODULE_NOT_FOUND, Error) \
V(ERR_NON_CONTEXT_AWARE_DISABLED, Error) \
V(ERR_OUT_OF_RANGE, RangeError) \
V(ERR_SCRIPT_EXECUTION_INTERRUPTED, Error) \
Expand Down Expand Up @@ -165,6 +169,7 @@ ERRORS_WITH_CODE(V)
V(ERR_INVALID_STATE, "Invalid state") \
V(ERR_INVALID_THIS, "Value of \"this\" is the wrong type") \
V(ERR_INVALID_TRANSFER_OBJECT, "Found invalid object in transferList") \
V(ERR_INVALID_URL_SCHEME, "The URL must be of scheme file:") \
V(ERR_MEMORY_ALLOCATION_FAILED, "Failed to allocate memory") \
V(ERR_OSSL_EVP_INVALID_DIGEST, "Invalid digest used") \
V(ERR_MESSAGE_TARGET_CONTEXT_UNAVAILABLE, \
Expand Down
Loading