Skip to content

Commit 6184667

Browse files
committed
perf(bootstrap): swap out npm root call for global-modules dep
no issue - increase startup perf time by not shelling out to npm and instead using 'global-modules' - add extra bootstrap cli debug statement to see startup times more accurately
1 parent 791301a commit 6184667

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

lib/bootstrap.js

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const bootstrap = {
9292
* @param Yargs yargs instance
9393
*/
9494
run: function run(argv, yargs) {
95+
debug('Starting bootstrap process');
9596
// Look for any available extensions, including ones built-in to the CLI itself
9697
const extensions = findExtensions();
9798
debug(`Found ${extensions.length} extensions: ${extensions.map((ext) => ext.pkg.name).join(', ')}`);

lib/utils/find-extensions.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
const path = require('path');
33
const findPlugins = require('find-plugins');
44
const createDebug = require('debug');
5-
const execa = require('execa');
65

76
const debug = createDebug('ghost-cli:find-extensions');
87

@@ -19,8 +18,8 @@ const localExtensions = [
1918
* @return Array array containing the package.json and dir of any found extensions
2019
*/
2120
module.exports = function findExtensions() {
22-
const npmRoot = execa.shellSync('npm root -g').stdout;
23-
debug('searching for extensions');
21+
const npmRoot = require('global-modules');
22+
debug(`searching for extensions in ${npmRoot}`);
2423

2524
return findPlugins({
2625
keyword: 'ghost-cli-extension',

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"fs-extra": "5.0.0",
6060
"generate-password": "1.3.0",
6161
"ghost-ignition": "2.8.18",
62+
"global-modules": "1.0.0",
6263
"got": "8.0.2",
6364
"inquirer": "3.3.0",
6465
"is-running": "2.1.0",

test/unit/utils/find-extensions-spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('Unit: Utils > find-extensions', function () {
3030

3131
findExtensions = proxyquire(modulePath, {
3232
'find-plugins': findStub,
33-
execa: {shellSync: () => ({stdout: '.'})}
33+
'global-modules': '.'
3434
});
3535
});
3636

yarn.lock

+51-6
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,12 @@ expand-range@^1.8.1:
12681268
dependencies:
12691269
fill-range "^2.1.0"
12701270

1271+
expand-tilde@^2.0.0, expand-tilde@^2.0.2:
1272+
version "2.0.2"
1273+
resolved "https://registry.yarnpkg.com/expand-tilde/-/expand-tilde-2.0.2.tgz#97e801aa052df02454de46b02bf621642cdc8502"
1274+
dependencies:
1275+
homedir-polyfill "^1.0.1"
1276+
12711277
ext-list@^2.0.0:
12721278
version "2.2.2"
12731279
resolved "https://registry.yarnpkg.com/ext-list/-/ext-list-2.2.2.tgz#0b98e64ed82f5acf0f2931babf69212ef52ddd37"
@@ -1667,6 +1673,24 @@ global-dirs@^0.1.0:
16671673
dependencies:
16681674
ini "^1.3.4"
16691675

1676+
[email protected], global-modules@^1.0.0:
1677+
version "1.0.0"
1678+
resolved "https://registry.yarnpkg.com/global-modules/-/global-modules-1.0.0.tgz#6d770f0eb523ac78164d72b5e71a8877265cc3ea"
1679+
dependencies:
1680+
global-prefix "^1.0.1"
1681+
is-windows "^1.0.1"
1682+
resolve-dir "^1.0.0"
1683+
1684+
global-prefix@^1.0.1:
1685+
version "1.0.2"
1686+
resolved "https://registry.yarnpkg.com/global-prefix/-/global-prefix-1.0.2.tgz#dbf743c6c14992593c655568cb66ed32c0122ebe"
1687+
dependencies:
1688+
expand-tilde "^2.0.2"
1689+
homedir-polyfill "^1.0.1"
1690+
ini "^1.3.4"
1691+
is-windows "^1.0.1"
1692+
which "^1.2.14"
1693+
16701694
globals@^11.0.1:
16711695
version "11.1.0"
16721696
resolved "https://registry.yarnpkg.com/globals/-/globals-11.1.0.tgz#632644457f5f0e3ae711807183700ebf2e4633e4"
@@ -1832,6 +1856,12 @@ [email protected]:
18321856
version "4.2.0"
18331857
resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.0.tgz#72d9d0754f7fe25ca2d01ad8f8f9a9449a89526d"
18341858

1859+
homedir-polyfill@^1.0.1:
1860+
version "1.0.1"
1861+
resolved "https://registry.yarnpkg.com/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz#4c2bbc8a758998feebf5ed68580f76d46768b4bc"
1862+
dependencies:
1863+
parse-passwd "^1.0.0"
1864+
18351865
hosted-git-info@^2.1.4:
18361866
version "2.4.2"
18371867
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.4.2.tgz#0076b9f46a270506ddbaaea56496897460612a67"
@@ -2115,6 +2145,10 @@ is-utf8@^0.2.0:
21152145
version "0.2.1"
21162146
resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"
21172147

2148+
is-windows@^1.0.1:
2149+
version "1.0.2"
2150+
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d"
2151+
21182152
21192153
version "0.0.1"
21202154
resolved "https://registry.yarnpkg.com/isarray/-/isarray-0.0.1.tgz#8a18acfca9a8f4177e09abfc6038939b05d1eedf"
@@ -2978,6 +3012,10 @@ parse-json@^2.2.0:
29783012
dependencies:
29793013
error-ex "^1.2.0"
29803014

3015+
parse-passwd@^1.0.0:
3016+
version "1.0.0"
3017+
resolved "https://registry.yarnpkg.com/parse-passwd/-/parse-passwd-1.0.0.tgz#6d5b934a456993b23d37f40a382d6f1666a8e5c6"
3018+
29813019
path-exists@^2.0.0:
29823020
version "2.1.0"
29833021
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-2.1.0.tgz#0feb6c64f0fc518d9a754dd5efb62c7022761f4b"
@@ -3314,6 +3352,13 @@ require-uncached@^1.0.3:
33143352
caller-path "^0.1.0"
33153353
resolve-from "^1.0.0"
33163354

3355+
resolve-dir@^1.0.0:
3356+
version "1.0.1"
3357+
resolved "https://registry.yarnpkg.com/resolve-dir/-/resolve-dir-1.0.1.tgz#79a40644c362be82f26effe739c9bb5382046f43"
3358+
dependencies:
3359+
expand-tilde "^2.0.0"
3360+
global-modules "^1.0.0"
3361+
33173362
resolve-from@^1.0.0:
33183363
version "1.0.1"
33193364
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"
@@ -4019,15 +4064,15 @@ which-module@^2.0.0:
40194064
version "2.0.0"
40204065
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"
40214066

4022-
which@^1.2.8, which@^1.2.9:
4023-
version "1.2.14"
4024-
resolved "https://registry.yarnpkg.com/which/-/which-1.2.14.tgz#9a87c4378f03e827cecaf1acdf56c736c01c14e5"
4067+
which@^1.2.14, which@^1.3.0:
4068+
version "1.3.0"
4069+
resolved "https://registry.yarnpkg.com/which/-/which-1.3.0.tgz#ff04bdfc010ee547d780bec38e1ac1c2777d253a"
40254070
dependencies:
40264071
isexe "^2.0.0"
40274072

4028-
which@^1.3.0:
4029-
version "1.3.0"
4030-
resolved "https://registry.yarnpkg.com/which/-/which-1.3.0.tgz#ff04bdfc010ee547d780bec38e1ac1c2777d253a"
4073+
which@^1.2.8, which@^1.2.9:
4074+
version "1.2.14"
4075+
resolved "https://registry.yarnpkg.com/which/-/which-1.2.14.tgz#9a87c4378f03e827cecaf1acdf56c736c01c14e5"
40314076
dependencies:
40324077
isexe "^2.0.0"
40334078

0 commit comments

Comments
 (0)