Skip to content

Commit

Permalink
fix: run prepack lifecycle scripts on git fetcher (#121)
Browse files Browse the repository at this point in the history
When running prepare steps for git dependencies, we should also check
for `prepack` scripts and make sure the prepare steps are run in case
one is found.

Fixes: npm/cli#4391
  • Loading branch information
ruyadorno committed Feb 16, 2022
1 parent 56d0c62 commit 82d8afc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/git.js
Expand Up @@ -159,6 +159,7 @@ class GitFetcher extends Fetcher {
scripts.build ||
scripts.preinstall ||
scripts.install ||
scripts.prepack ||
scripts.prepare))) {
return
}
Expand Down
35 changes: 35 additions & 0 deletions test/git.js
Expand Up @@ -53,6 +53,7 @@ const remote = `git://localhost:${gitPort}/repo`
const remoteHosted = `git://127.0.0.1:${gitPort}/repo`
const submodsRemote = `git://localhost:${gitPort}/submodule-repo`
const workspacesRemote = `git://localhost:${gitPort}/workspaces-repo`
const prepackRemote = `git://localhost:${gitPort}/prepack-repo`

const GitFetcher = require('../lib/git.js')
const t = require('tap')
Expand Down Expand Up @@ -315,6 +316,28 @@ t.test('setup', { bail: true }, t => {
.then(() => git('commit', '-m', 'a/package.json'))
})

t.test('create a repo with only a prepack script', t => {
const repo = resolve(me, 'prepack-repo')
const git = (...cmd) => spawnGit(cmd, { cwd: repo })
const write = (f, c) => fs.writeFileSync(`${repo}/${f}`, c)
mkdirp.sync(repo)
return git('init')
.then(() => git('config', 'user.name', 'pacotedev'))
.then(() => git('config', 'user.email', 'i+pacotedev@github.com'))
.then(() => git('config', 'tag.gpgSign', 'false'))
.then(() => git('config', 'commit.gpgSign', 'false'))
.then(() => git('config', 'tag.forceSignAnnotated', 'false'))
.then(() => write('package.json', JSON.stringify({
name: 'prepack-root',
version: '1.0.0',
scripts: {
prepare: 'touch foo',
},
})))
.then(() => git('add', 'package.json'))
.then(() => git('commit', '-m', 'package.json'))
})

t.test('hosted service', t => {
const s = http.createServer((req, res) => {
res.setHeader('connection', 'close')
Expand Down Expand Up @@ -711,3 +734,15 @@ t.test('simple repo with workspaces', async t => {
'should run prepare phase when finding workspaces'
)
})

t.test('simple repo with only a prepack script', async t => {
const ws = new GitFetcher(prepackRemote, { cache })
const extract = resolve(me, 'extract-prepack')
await ws.extract(extract)
// the file ./foo does not exist in the original repo
// and should have been created when running prepack
t.ok(
fs.statSync(me + '/extract-prepack/foo'),
'should run prepack lifecycle script'
)
})

0 comments on commit 82d8afc

Please sign in to comment.