Skip to content

Commit

Permalink
perf(core): skip unnecessary exists checks (#3963)
Browse files Browse the repository at this point in the history
  • Loading branch information
merceyz authored Jan 11, 2022
1 parent d38d995 commit 8c23ead
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
33 changes: 33 additions & 0 deletions .yarn/versions/c608964d.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/core": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
10 changes: 7 additions & 3 deletions packages/yarnpkg-core/sources/Manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ export class Manifest {
static async tryFind(path: PortablePath, {baseFs = new NodeFS()}: {baseFs?: FakeFS<PortablePath>} = {}) {
const manifestPath = ppath.join(path, `package.json` as Filename);

if (!await baseFs.existsPromise(manifestPath))
return null;
try {
return await Manifest.fromFile(manifestPath, {baseFs});
} catch (err) {
if (err.code === `ENOENT`)
return null;

return await Manifest.fromFile(manifestPath, {baseFs});
throw err;
}
}

static async find(path: PortablePath, {baseFs}: {baseFs?: FakeFS<PortablePath>} = {}) {
Expand Down
4 changes: 1 addition & 3 deletions packages/yarnpkg-core/sources/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ export class Workspace {

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

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

0 comments on commit 8c23ead

Please sign in to comment.