From 7c9d5a856d7f1a58db35dd51e20e0311e1f72109 Mon Sep 17 00:00:00 2001 From: Shinyaigeek Date: Thu, 24 Mar 2022 01:06:37 +0900 Subject: [PATCH] Update: handle entries specified with source in a specific case for perf --- packages/core/core/src/resolveOptions.js | 26 ++++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/core/core/src/resolveOptions.js b/packages/core/core/src/resolveOptions.js index 2fd201844b3..153e6421e50 100644 --- a/packages/core/core/src/resolveOptions.js +++ b/packages/core/core/src/resolveOptions.js @@ -14,7 +14,7 @@ import {hashString} from '@parcel/hash'; import {NodeFS} from '@parcel/fs'; import {LMDBCache, FSCache} from '@parcel/cache'; import {NodePackageManager} from '@parcel/package-manager'; -import {getRootDir, relativePath, resolveConfig} from '@parcel/utils'; +import {getRootDir, relativePath, resolveConfig, isGlob} from '@parcel/utils'; import loadDotEnv from './loadDotEnv'; import {toProjectPath} from './projectPath'; import {getResolveFrom} from './requests/ParcelConfigRequest'; @@ -50,18 +50,22 @@ export default async function resolveOptions( entries = [path.resolve(inputCwd, initialOptions.entries)]; } + let shouldMakeEntryReferFolder = false; + // if entries have the only one entry and the one is not glob and refers to directory, we need to make the entry refer to some file. + if (entries.length === 1 && !isGlob(entries[0])) { + let [entry] = entries; + try { + shouldMakeEntryReferFolder = (await inputFS.stat(entry)).isDirectory(); + } catch { + // ignore failing stat call + } + } + + // getRootDir treats the input as files, so getRootDir(["/home/user/myproject"]) returns "/home/user". + // Instead we need to make the the entry refer to some file inside the specified folders if entries refers to the directory. let entryRoot = getRootDir( - await Promise.all( - entries.map(async entry => - // getRootDir treats the input as files, so getRootDir(["/home/user/myproject"]) returns "/home/user". - // Instead we need to make the entries refer to some file inside the specified folders. - (await inputFS.stat(entry)).isFile() - ? entry - : path.join(entry, 'index'), - ), - ), + shouldMakeEntryReferFolder ? [path.join(entries[0], 'index')] : entries, ); - let projectRootFile = (await resolveConfig( inputFS,