Skip to content

Commit 77b8444

Browse files
zertoshDaniel15
authored andcommitted
Fix: Correctly load v8-compile-cache (#6261)
`v8-compile-cache` is not loading because `fs.existsSync` is checking for a file that doesn't exist. `fs.existsSync` resolves relative to the cwd, not the current module (like `require`), and `v8CompileCachePath`'s filename is missing `.js`. Instead of checking for the existence of `v8-compile-cache.js`, just try to `require` it in a `try`/`catch`, using a full path. Also switched the `require` of `cli.js` to use the same pattern for consistency (plus it's a module resolution micro-optimization). ``` # before $ time ./dist/bin/yarn -v 1.10.0-0 ./dist/bin/yarn -v 0.28s user 0.06s system 98% cpu 0.344 total # after $ time ./dist/bin/yarn -v 1.10.0-0 ./dist/bin/yarn -v 0.16s user 0.05s system 97% cpu 0.213 total ```
1 parent 36f0bf6 commit 77b8444

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

bin/yarn.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@ if (majorVer < 4) {
1111
console.error('Node version ' + ver + ' is not supported, please use Node.js 4.0 or higher.');
1212
process.exit(1); // eslint-disable-line no-process-exit
1313
} else {
14-
var dirPath = '../lib/';
15-
var v8CompileCachePath = dirPath + 'v8-compile-cache';
16-
var fs = require('fs');
17-
// We don't have/need this on legacy builds and dev builds
18-
if (fs.existsSync(v8CompileCachePath)) {
19-
require(v8CompileCachePath);
14+
try {
15+
require(__dirname + '/../lib/v8-compile-cache.js');
16+
} catch (err) {
17+
// We don't have/need this on legacy builds and dev builds
2018
}
2119

2220
// Just requiring this package will trigger a yarn run since the
2321
// `require.main === module` check inside `cli/index.js` will always
2422
// be truthy when built with webpack :(
25-
var cli = require(dirPath + 'cli');
23+
// `lib/cli` may be `lib/cli/index.js` or `lib/cli.js` depending on the build.
24+
var cli = require(__dirname + '/../lib/cli');
2625
if (!cli.autoRun) {
2726
cli.default().catch(function(error) {
2827
console.error(error.stack || error.message || error);

0 commit comments

Comments
 (0)