Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
fix: execute all the relevant install scripts for top level package
Browse files Browse the repository at this point in the history
The same way that npm does. Closes #12
  • Loading branch information
dominykas committed Jan 29, 2019
1 parent 77c8c4c commit beab25e
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const Path = require('path');
const Topo = require('topo');



const internals = {};


Expand Down Expand Up @@ -47,13 +46,14 @@ internals.queue = (tree) => {
return topo.nodes;
};

internals.runScript = (stage, { childPkg, path, cwd }) => {
internals.runScript = (stage, { pkg, path, cwd, unsafePerm }) => {

console.log();
console.log(`==========> ${stage} ${path}...`);
console.log(`==========> ${stage} ${path || pkg.name}...`);

return Npm.runScript(childPkg, stage, Path.join(cwd, path), {
return Npm.runScript(pkg, stage, Path.join(cwd, path), {
dir: cwd,
unsafePerm, // @todo: find an official way to do this for top level package
log: Object.assign({
pause: () => {},
clearProgress: () => {},
Expand All @@ -70,6 +70,9 @@ exports.run = async (cmd = 'install') => {

const cwd = process.cwd();
const pkg = require(Path.join(cwd, 'package.json'));

pkg._id = `${pkg.name}@${pkg.version}`; // @todo: find an official way to do this for top level package

const shrinkwrap = require(Path.join(cwd, 'npm-shrinkwrap.json'));

const tree = Npm.logicalTree(pkg, shrinkwrap);
Expand All @@ -82,13 +85,13 @@ exports.run = async (cmd = 'install') => {

const childPkg = require(Path.join(cwd, path, 'package.json'));

return [path, childPkg];
return { path, childPkg };
})
.filter(([,childPkg]) => {
.filter(({ childPkg }) => {

return childPkg.scripts && (childPkg.scripts[cmd] || childPkg.scripts[`pre${cmd}`] || childPkg.scripts[`post${childPkg}`]);
})
.filter(([path, childPkg]) => {
.filter(({ path, childPkg }) => {

const name = childPkg.name;

Expand All @@ -103,15 +106,22 @@ exports.run = async (cmd = 'install') => {
return allowScripts[name];
});

for (const [path, childPkg] of allowedScripts) {
await internals.runScript('preinstall', { childPkg, path, cwd });
await internals.runScript('preinstall', { pkg, path: '', cwd, unsafePerm: true });

for (const { path, childPkg } of allowedScripts) {
await internals.runScript('preinstall', { pkg: childPkg, path, cwd });
}

for (const [path, childPkg] of allowedScripts) {
await internals.runScript('install', { childPkg, path, cwd });
for (const { path, childPkg } of allowedScripts) {
await internals.runScript('install', { pkg: childPkg, path, cwd });
}

for (const [path, childPkg] of allowedScripts) {
await internals.runScript('postinstall', { childPkg, path, cwd });
for (const { path, childPkg } of allowedScripts) {
await internals.runScript('postinstall', { pkg: childPkg, path, cwd });
}

await internals.runScript('install', { pkg, path: '', cwd, unsafePerm: true });
await internals.runScript('postinstall', { pkg, path: '', cwd, unsafePerm: true });
await internals.runScript('prepublish', { pkg, path: '', cwd, unsafePerm: true });
await internals.runScript('prepare', { pkg, path: '', cwd, unsafePerm: true });
};

0 comments on commit beab25e

Please sign in to comment.