Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdbc1b16

Browse files
committed
lib: improve esm resolve performance
PR-URL:nodejs/node#46652Refs:nodejs/performance#39Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>Reviewed-By: Michaël Zasso <targos@protonmail.com>Reviewed-By: Matteo Collina <matteo.collina@gmail.com>Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>Reviewed-By: James M Snell <jasnell@gmail.com>Reviewed-By: Erick Wendel <erick.workspace@gmail.com>Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent1988563 commitdbc1b16

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

‎graal-nodejs/lib/internal/modules/esm/resolve.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,20 @@ const {
2525
}=primordials;
2626
constinternalFS=require('internal/fs/utils');
2727
const{ BuiltinModule}=require('internal/bootstrap/realm');
28-
const{
29-
realpathSync,
30-
statSync,
31-
Stats,
32-
}=require('fs');
28+
const{ realpathSync}=require('fs');
3329
const{ getOptionValue}=require('internal/options');
3430
constpendingDeprecation=getOptionValue('--pending-deprecation');
3531
// Do not eagerly grab .manifest, it may be in TDZ
3632
constpolicy=getOptionValue('--experimental-policy') ?
3733
require('internal/process/policy') :
3834
null;
39-
const{ sep, relative, resolve}=require('path');
35+
const{ sep, relative, resolve, toNamespacedPath}=require('path');
4036
constpreserveSymlinks=getOptionValue('--preserve-symlinks');
4137
constpreserveSymlinksMain=getOptionValue('--preserve-symlinks-main');
4238
constexperimentalNetworkImports=
4339
getOptionValue('--experimental-network-imports');
4440
consttypeFlag=getOptionValue('--input-type');
45-
const{URL, pathToFileURL, fileURLToPath}=require('internal/url');
41+
const{URL, pathToFileURL, fileURLToPath, toPathIfFileURL}=require('internal/url');
4642
const{
4743
ERR_INPUT_TYPE_NOT_ALLOWED,
4844
ERR_INVALID_MODULE_SPECIFIER,
@@ -60,6 +56,7 @@ const { Module: CJSModule } = require('internal/modules/cjs/loader');
6056
constpackageJsonReader=require('internal/modules/package_json_reader');
6157
const{ getPackageConfig, getPackageScopeConfig}=require('internal/modules/esm/package_config');
6258
const{ getConditionsSet}=require('internal/modules/esm/utils');
59+
const{ internalModuleStat}=internalBinding('fs');
6360

6461
/**
6562
*@typedef {import('internal/modules/esm/package_config.js').PackageConfig} PackageConfig
@@ -138,19 +135,12 @@ function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) {
138135

139136
constrealpathCache=newSafeMap();
140137

141-
/**
142-
*@param {string | URL} path
143-
*@returns {import('fs').Stats}
144-
*/
145-
consttryStatSync=
146-
(path)=>statSync(path,{throwIfNoEntry:false})??newStats();
147-
148138
/**
149139
*@param {string | URL} url
150140
*@returns {boolean}
151141
*/
152142
functionfileExists(url){
153-
returnstatSync(url,{throwIfNoEntry:false})?.isFile()??false;
143+
returninternalModuleStat(toNamespacedPath(toPathIfFileURL(url)))===0;
154144
}
155145

156146
/**
@@ -285,13 +275,16 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
285275
path=fileURLToPath(resolved);
286276
}
287277

288-
conststats=tryStatSync(StringPrototypeEndsWith(path,'/') ?
289-
StringPrototypeSlice(path,-1) :path);
290-
if(stats.isDirectory()){
278+
conststats=internalModuleStat(toNamespacedPath(StringPrototypeEndsWith(path,'/') ?
279+
StringPrototypeSlice(path,-1) :path));
280+
281+
// Check for stats.isDirectory()
282+
if(stats===1){
291283
consterr=newERR_UNSUPPORTED_DIR_IMPORT(path,fileURLToPath(base));
292284
err.url=String(resolved);
293285
throwerr;
294-
}elseif(!stats.isFile()){
286+
}elseif(stats!==0){
287+
// Check for !stats.isFile()
295288
if(process.env.WATCH_REPORT_DEPENDENCIES&&process.send){
296289
process.send({'watch:require':[path||resolved.pathname]});
297290
}
@@ -826,9 +819,10 @@ function packageResolve(specifier, base, conditions) {
826819
letpackageJSONPath=fileURLToPath(packageJSONUrl);
827820
letlastPath;
828821
do{
829-
conststat=tryStatSync(StringPrototypeSlice(packageJSONPath,0,
830-
packageJSONPath.length-13));
831-
if(!stat.isDirectory()){
822+
conststat=internalModuleStat(toNamespacedPath(StringPrototypeSlice(packageJSONPath,0,
823+
packageJSONPath.length-13)));
824+
// Check for !stat.isDirectory()
825+
if(stat!==1){
832826
lastPath=packageJSONPath;
833827
packageJSONUrl=newURL((isScoped ?
834828
'../../../../node_modules/' :'../../../node_modules/')+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp