Skip to content

ci: run install scripts for root project #2316

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

Merged
merged 1 commit into from
Dec 11, 2020
Merged
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
23 changes: 23 additions & 0 deletions lib/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const util = require('util')
const Arborist = require('@npmcli/arborist')
const rimraf = util.promisify(require('rimraf'))
const reifyFinish = require('./utils/reify-finish.js')
const runScript = require('@npmcli/run-script')

const log = require('npmlog')
const npm = require('./npm.js')
Expand All @@ -20,6 +21,7 @@ const ci = async () => {
}

const where = npm.prefix
const { scriptShell } = npm.flatOptions
const arb = new Arborist({ ...npm.flatOptions, path: where })

await Promise.all([
Expand All @@ -35,6 +37,27 @@ const ci = async () => {
])
// npm ci should never modify the lockfile or package.json
await arb.reify({ ...npm.flatOptions, save: false })

// run the same set of scripts that `npm install` runs.
const scripts = [
'preinstall',
'install',
'postinstall',
'prepublish', // XXX should we remove this finally??
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering, I thought prepublish was deprecated?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't remove it yet :-) imo the churn isn't worth it. it'd be better to remove prepublishOnly and make prepublish, only running on prepublish, the actual behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since we already shipped v7, we have this on the agenda for npm v8. It's a breaking change if we remove it, and at least an annoying change (if not actually breaking) if we deprecate it with a warning.

  • remove (or deprecate with a warning) prepublish on install/ci
  • remove (or deprecate with a warning) prepublishOnly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that’s the plan, I’d prefer the former :-D (which, iirc, was the original planned end state)

'preprepare',
'prepare',
'postprepare',
]
for (const event of scripts) {
await runScript({
path: where,
args: [],
scriptShell,
stdio: 'inherit',
stdioString: true,
event,
})
}
await reifyFinish(arb)
}

Expand Down
19 changes: 18 additions & 1 deletion test/lib/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ const { test } = require('tap')

const requireInject = require('require-inject')

test('should use Arborist', (t) => {
test('should use Arborist and run-script', (t) => {
const scripts = [
'preinstall',
'install',
'postinstall',
'prepublish', // XXX should we remove this finally??
'preprepare',
'prepare',
'postprepare',
]
const ci = requireInject('../../lib/ci.js', {
'../../lib/npm.js': {
prefix: 'foo',
Expand All @@ -15,6 +24,9 @@ test('should use Arborist', (t) => {
},
},
'../../lib/utils/reify-finish.js': async () => {},
'@npmcli/run-script': opts => {
t.match(opts, { event: scripts.shift() })
},
'@npmcli/arborist': function (args) {
t.ok(args, 'gets options object')
this.loadVirtual = () => {
Expand All @@ -40,6 +52,7 @@ test('should use Arborist', (t) => {
ci(null, er => {
if (er)
throw er
t.strictSame(scripts, [], 'called all scripts')
t.end()
})
})
Expand All @@ -53,6 +66,7 @@ test('should pass flatOptions to Arborist.reify', (t) => {
},
},
'../../lib/utils/reify-finish.js': async () => {},
'@npmcli/run-script': opts => {},
'@npmcli/arborist': function () {
this.loadVirtual = () => Promise.resolve(true)
this.reify = async (options) => {
Expand Down Expand Up @@ -80,6 +94,7 @@ test('should throw if package-lock.json or npm-shrinkwrap missing', (t) => {
global: false,
},
},
'@npmcli/run-script': opts => {},
'../../lib/utils/reify-finish.js': async () => {},
npmlog: {
verbose: () => {
Expand All @@ -102,6 +117,7 @@ test('should throw ECIGLOBAL', (t) => {
global: true,
},
},
'@npmcli/run-script': opts => {},
'../../lib/utils/reify-finish.js': async () => {},
})
ci(null, (err, res) => {
Expand All @@ -125,6 +141,7 @@ test('should remove existing node_modules before installing', (t) => {
global: false,
},
},
'@npmcli/run-script': opts => {},
'../../lib/utils/reify-finish.js': async () => {},
'@npmcli/arborist': function () {
this.loadVirtual = () => Promise.resolve(true)
Expand Down