Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add preinstallOnly script #6888

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/lib/content/using-npm/scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ situations. These scripts happen in addition to the `pre<event>`, `post<event>`,

* `prepare`, `prepublish`, `prepublishOnly`, `prepack`, `postpack`, `dependencies`

**preinstallOnly**
* Runs BEFORE installation, ONLY on `npm install`.

**prepare** (since `npm@4.0.0`)
* Runs BEFORE the package is packed, i.e. during `npm publish`
and `npm pack`
Expand Down
12 changes: 12 additions & 0 deletions lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ class Install extends ArboristWorkspaceCmd {
throw this.usageError()
}

// Special 'preinstallOnly' script that actually runs before installation
if (!args.length && !isGlobalInstall && !ignoreScripts) {
await runScript({
path: where,
args: [],
scriptShell,
stdio: 'inherit',
banner: !this.npm.silent,
event: 'preinstallOnly',
})
}

const Arborist = require('@npmcli/arborist')
const opts = {
...this.npm.flatOptions,
Expand Down
1 change: 1 addition & 0 deletions test/lib/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ t.test('exec commands', async t => {
t.match(ARB_ARGS, { global: false, path: npm.prefix })
t.equal(REIFY_CALLED, true, 'called reify')
t.strictSame(SCRIPTS, [
'preinstallOnly',
'preinstall',
'install',
'postinstall',
Expand Down