Skip to content

Commit

Permalink
Update: handle entries specified with source in a specific case for perf
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyaigeek committed Mar 23, 2022
1 parent 6d0ccf2 commit 7c9d5a8
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions packages/core/core/src/resolveOptions.js
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7c9d5a8

Please sign in to comment.