Skip to content

Commit 0139d8b

Browse files
authored
perf(core): skip unnecessary exists checks (#3963)
1 parent 2887003 commit 0139d8b

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

Diff for: .yarn/versions/c608964d.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/core": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-exec"
11+
- "@yarnpkg/plugin-file"
12+
- "@yarnpkg/plugin-git"
13+
- "@yarnpkg/plugin-github"
14+
- "@yarnpkg/plugin-http"
15+
- "@yarnpkg/plugin-init"
16+
- "@yarnpkg/plugin-interactive-tools"
17+
- "@yarnpkg/plugin-link"
18+
- "@yarnpkg/plugin-nm"
19+
- "@yarnpkg/plugin-npm"
20+
- "@yarnpkg/plugin-npm-cli"
21+
- "@yarnpkg/plugin-pack"
22+
- "@yarnpkg/plugin-patch"
23+
- "@yarnpkg/plugin-pnp"
24+
- "@yarnpkg/plugin-pnpm"
25+
- "@yarnpkg/plugin-stage"
26+
- "@yarnpkg/plugin-typescript"
27+
- "@yarnpkg/plugin-version"
28+
- "@yarnpkg/plugin-workspace-tools"
29+
- "@yarnpkg/builder"
30+
- "@yarnpkg/doctor"
31+
- "@yarnpkg/nm"
32+
- "@yarnpkg/pnpify"
33+
- "@yarnpkg/sdks"

Diff for: packages/yarnpkg-core/sources/Manifest.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,14 @@ export class Manifest {
9696
static async tryFind(path: PortablePath, {baseFs = new NodeFS()}: {baseFs?: FakeFS<PortablePath>} = {}) {
9797
const manifestPath = ppath.join(path, `package.json` as Filename);
9898

99-
if (!await baseFs.existsPromise(manifestPath))
100-
return null;
99+
try {
100+
return await Manifest.fromFile(manifestPath, {baseFs});
101+
} catch (err) {
102+
if (err.code === `ENOENT`)
103+
return null;
101104

102-
return await Manifest.fromFile(manifestPath, {baseFs});
105+
throw err;
106+
}
103107
}
104108

105109
static async find(path: PortablePath, {baseFs}: {baseFs?: FakeFS<PortablePath>} = {}) {

Diff for: packages/yarnpkg-core/sources/Workspace.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ export class Workspace {
4141

4242
async setup() {
4343
// @ts-expect-error: It's ok to initialize it now
44-
this.manifest = xfs.existsSync(ppath.join(this.cwd, Manifest.fileName))
45-
? await Manifest.find(this.cwd)
46-
: new Manifest();
44+
this.manifest = await Manifest.tryFind(this.cwd) ?? new Manifest();
4745

4846
// We use ppath.relative to guarantee that the default hash will be consistent even if the project is installed on different OS / path
4947
// @ts-expect-error: It's ok to initialize it now, even if it's readonly (setup is called right after construction)

0 commit comments

Comments
 (0)