From 295c5fd57a773d613613dc1539d50361fc3e8b47 Mon Sep 17 00:00:00 2001 From: Danny Gleckler Date: Thu, 4 Aug 2022 16:54:04 -0400 Subject: [PATCH] Add `prefetch` script to install and ci commands --- lib/commands/ci.js | 21 ++++++++++++++++++++- lib/commands/install.js | 17 +++++++++++++++++ test/lib/commands/ci.js | 1 + test/lib/commands/install.js | 1 + 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/commands/ci.js b/lib/commands/ci.js index 0adf203a9856e..8d443ef12fd34 100644 --- a/lib/commands/ci.js +++ b/lib/commands/ci.js @@ -73,9 +73,28 @@ class CI extends ArboristWorkspaceCmd { return Promise.all(entries.map(f => rimraf(`${path}/${f}`, { glob: false }))) }) + const ignoreScripts = this.npm.config.get('ignore-scripts') + // run the same set of scripts that `npm install` runs. + if (!ignoreScripts) { + const scripts = [ + 'prefetch', + ] + const scriptShell = this.npm.config.get('script-shell') || undefined + for (const event of scripts) { + await runScript({ + path: where, + args: [], + scriptShell, + stdio: 'inherit', + stdioString: true, + banner: !this.npm.silent, + event, + }) + } + } + await arb.reify(opts) - const ignoreScripts = this.npm.config.get('ignore-scripts') // run the same set of scripts that `npm install` runs. if (!ignoreScripts) { const scripts = [ diff --git a/lib/commands/install.js b/lib/commands/install.js index ecc0727a2ef7c..69553ae76da37 100644 --- a/lib/commands/install.js +++ b/lib/commands/install.js @@ -134,6 +134,23 @@ class Install extends ArboristWorkspaceCmd { throw this.usageError() } + if (!args.length && !isGlobalInstall && !ignoreScripts) { + const scripts = [ + 'prefetch', + ] + for (const event of scripts) { + await runScript({ + path: where, + args: [], + scriptShell, + stdio: 'inherit', + stdioString: true, + banner: !this.npm.silent, + event, + }) + } + } + const opts = { ...this.npm.flatOptions, auditLevel: null, diff --git a/test/lib/commands/ci.js b/test/lib/commands/ci.js index 179cee6c9b7e7..d2650e4101ee7 100644 --- a/test/lib/commands/ci.js +++ b/test/lib/commands/ci.js @@ -139,6 +139,7 @@ t.test('lifecycle scripts', async t => { registry.nock.post('/-/npm/v1/security/advisories/bulk').reply(200, {}) await npm.exec('ci', []) t.same(scripts, [ + 'prefetch', 'preinstall', 'install', 'postinstall', diff --git a/test/lib/commands/install.js b/test/lib/commands/install.js index 9b2d52f6edd21..474fe8162c5c2 100644 --- a/test/lib/commands/install.js +++ b/test/lib/commands/install.js @@ -81,6 +81,7 @@ t.test('without args', async t => { t.match(ARB_ARGS, { global: false, path: npm.prefix }) t.equal(REIFY_CALLED, true, 'called reify') t.strictSame(SCRIPTS, [ + 'prefetch', 'preinstall', 'install', 'postinstall',