fix(scripts): run prepublish only on argumentless install

Close #396
This commit is contained in:
zkochan
2016-10-06 22:11:00 +03:00
parent 4a76fa57fd
commit 124d9c7368
2 changed files with 24 additions and 7 deletions

View File

@@ -130,7 +130,14 @@ async function installInContext (installType: string, packagesToInstall: Depende
}
await linkBins(path.join(ctx.root, 'node_modules'))
if (!opts.ignoreScripts && ctx.pkg) {
await mainPostInstall(ctx.pkg && ctx.pkg.scripts || {}, ctx.root, opts.production)
const scripts = ctx.pkg && ctx.pkg.scripts || {}
if (scripts['postinstall']) {
npmRun('postinstall', ctx.root)
}
if (installType === 'general' && scripts['prepublish']) {
npmRun('prepublish', ctx.root)
}
}
}
@@ -186,11 +193,6 @@ function adaptConfig (opts: StrictPnpmOptions) {
}
}
function mainPostInstall (scripts: Object, pkgRoot: string, isProductionInstall: boolean) {
if (scripts['postinstall']) npmRun('postinstall', pkgRoot)
if (!isProductionInstall && scripts['prepublish']) npmRun('prepublish', pkgRoot)
}
function npmRun (scriptName: string, pkgRoot: string) {
const result = runScriptSync('npm', ['run', scriptName], {
cwd: pkgRoot,

View File

@@ -508,7 +508,7 @@ test('postinstall is executed after installation', t => {
t.end()
})
test('prepublish is executed after installation', t => {
test('prepublish is not executed after installation with arguments', t => {
prepare({
scripts: {
prepublish: 'echo "Hello world!"'
@@ -517,6 +517,21 @@ test('prepublish is executed after installation', t => {
const result = spawnSync('ts-node', [pnpmBin, 'install', 'is-negative'])
t.equal(result.status, 0, 'installation was successfull')
t.ok(result.stdout.toString().indexOf('Hello world!') === -1, 'prepublish script was not executed')
t.end()
})
test('prepublish is executed after argumentless installation', t => {
prepare({
scripts: {
prepublish: 'echo "Hello world!"'
}
})
const result = spawnSync('ts-node', [pnpmBin, 'install'])
t.equal(result.status, 0, 'installation was successfull')
t.ok(result.stdout.toString().indexOf('Hello world!') !== -1, 'prepublish script was executed')