Skip to content

Commit

Permalink
fix: show every runscript log before run it (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored and dead-horse committed Dec 28, 2018
1 parent 052b3c2 commit 0975790
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 19 deletions.
8 changes: 4 additions & 4 deletions lib/local_install.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ function* runPostInstallTasks(options) {
const postinstallScript = pkg.scripts.postinstall;
try {
if (installScript) {
options.console.info(
options.console.warn(
'%s %s run %j, root: %j',
chalk.yellow(`[${count}/${total}] scripts.install`),
chalk.gray(displayName),
Expand All @@ -375,15 +375,15 @@ function* runPostInstallTasks(options) {
chalk.red(displayName), installScript, err);
throw err;
}
options.console.info(
options.console.warn(
'%s %s finished in %s',
chalk.yellow(`[${count}/${total}] scripts.install`),
chalk.gray(displayName),
ms(Date.now() - start)
);
}
if (postinstallScript) {
options.console.info(
options.console.warn(
'%s %s run %j, root: %j',
chalk.yellow(`[${count}/${total}] scripts.postinstall`),
chalk.gray(displayName),
Expand All @@ -398,7 +398,7 @@ function* runPostInstallTasks(options) {
chalk.red(displayName), postinstallScript, err);
throw err;
}
options.console.info(
options.console.warn(
'%s %s finished in %s',
chalk.yellow(`[${count}/${total}] scripts.postinstall`),
chalk.gray(displayName),
Expand Down
15 changes: 11 additions & 4 deletions lib/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ function* postinstall(pkg, root, optional, displayName, options) {
// If there is a binding.gyp file in the root of your package,
// npm will default the install command to compile using node-gyp.
if (!scripts.install && (yield fs.exists(path.join(root, 'binding.gyp')))) {
options.console.info(
'%s found binding.gyp file, auto run "node-gyp rebuild"',
chalk.gray(displayName)
options.console.warn(
'[npminstall:runscript] %s found binding.gyp file, auto run "node-gyp rebuild", root: %j',
chalk.gray(displayName), root
);
yield utils.runScript(root, 'node-gyp rebuild', options);
const cmd = 'node-gyp rebuild';
try {
yield utils.runScript(root, cmd, options);
} catch (err) {
options.console.warn('[npminstall:runscript:error] %s has binding.gyp file, run %j error: %s',
chalk.red(displayName), cmd, err);
throw err;
}
}

if (scripts.install || scripts.postinstall) {
Expand Down
4 changes: 2 additions & 2 deletions lib/postuninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module.exports = postuninstall;
function* postuninstall(pkg, root, options) {
const scripts = pkg.scripts || {};
if (scripts.postuninstall) {
options.console.warn(chalk.yellow('[%s@%s]%s scripts.postuninstall: %j'),
pkg.name, pkg.version, options.ignoreScripts ? ' ignore' : '', scripts.postuninstall);
options.console.warn(chalk.yellow('[npminstall:runscript] [%s@%s]%s scripts.postuninstall: %j, root: %j'),
pkg.name, pkg.version, options.ignoreScripts ? ' ignore' : '', scripts.postuninstall, options.root);
if (!options.ignoreScripts) {
// root is removed
yield runScript(options.root, scripts.postuninstall, options);
Expand Down
7 changes: 4 additions & 3 deletions lib/preinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ module.exports = preinstall;
function* preinstall(pkg, root, displayName, options) {
const scripts = pkg.scripts || {};
if (scripts.preinstall) {
options.console.log(
'%s %s %s %j',
options.console.warn(
'[npminstall:runscript] %s %s %s %j, root: %j',
chalk.yellow('scripts.preinstall'),
chalk.gray(displayName),
chalk.yellow(options.ignoreScripts ? ' ignore' : ''),
scripts.preinstall
scripts.preinstall,
root
);
if (!options.ignoreScripts) {
yield runScript(root, scripts.preinstall, options);
Expand Down
7 changes: 4 additions & 3 deletions lib/prepublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ module.exports = prepublish;
function* prepublish(pkg, root, options) {
const scripts = pkg.scripts || {};
if (scripts.prepublish) {
options.console.log(
'%s %s %j',
options.console.warn(
'[npminstall:runscript] %s %s %j, root: %j',
chalk.yellow('scripts.prepublish'),
chalk.gray(`${pkg.name}@${pkg.version}`),
scripts.prepublish
scripts.prepublish,
root
);
yield runScript(root, scripts.prepublish, options);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/preuninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ module.exports = preuninstall;
function* preuninstall(pkg, root, options) {
const scripts = pkg.scripts || {};
if (scripts.preuninstall) {
options.console.warn(chalk.yellow('[%s@%s]%s scripts.preuninstall: %j'),
options.console.warn(chalk.yellow('[npminstall:runscript] [%s@%s]%s scripts.preuninstall: %j'),
pkg.name, pkg.version, options.ignoreScripts ? ' ignore' : '', scripts.preuninstall);
if (!options.ignoreScripts) {
yield runScript(root, scripts.preuninstall, options);
}
}
if (scripts.uninstall) {
options.console.warn(chalk.yellow('[%s@%s]%s scripts.uninstall: %j'),
options.console.warn(chalk.yellow('[npminstall:runscript] [%s@%s]%s scripts.uninstall: %j'),
pkg.name, pkg.version, options.ignoreScripts ? ' ignore' : '', scripts.uninstall);
if (!options.ignoreScripts) {
yield runScript(root, scripts.uninstall, options);
Expand Down
2 changes: 1 addition & 1 deletion test/postInstallError.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('test/postInstallError.test.js', () => {
.debug()
.expect('code', 0)
.expect('stderr', /httpsync@\* optional error: Error: Run ".*?build\.sh" error/)
.expect('stdout', /scripts.install httpsync@\* run "sh build.sh"/)
.expect('stderr', /scripts.install httpsync@\* run "sh build.sh"/)
.expect('stdout', /All packages installed/)
.end();
});
Expand Down

0 comments on commit 0975790

Please sign in to comment.