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

Commit beab25e

Browse files
committed
fix: execute all the relevant install scripts for top level package
The same way that npm does. Closes #12
1 parent 77c8c4c commit beab25e

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

lib/index.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const Path = require('path');
55
const Topo = require('topo');
66

77

8-
98
const internals = {};
109

1110

@@ -47,13 +46,14 @@ internals.queue = (tree) => {
4746
return topo.nodes;
4847
};
4948

50-
internals.runScript = (stage, { childPkg, path, cwd }) => {
49+
internals.runScript = (stage, { pkg, path, cwd, unsafePerm }) => {
5150

5251
console.log();
53-
console.log(`==========> ${stage} ${path}...`);
52+
console.log(`==========> ${stage} ${path || pkg.name}...`);
5453

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

7171
const cwd = process.cwd();
7272
const pkg = require(Path.join(cwd, 'package.json'));
73+
74+
pkg._id = `${pkg.name}@${pkg.version}`; // @todo: find an official way to do this for top level package
75+
7376
const shrinkwrap = require(Path.join(cwd, 'npm-shrinkwrap.json'));
7477

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

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

85-
return [path, childPkg];
88+
return { path, childPkg };
8689
})
87-
.filter(([,childPkg]) => {
90+
.filter(({ childPkg }) => {
8891

8992
return childPkg.scripts && (childPkg.scripts[cmd] || childPkg.scripts[`pre${cmd}`] || childPkg.scripts[`post${childPkg}`]);
9093
})
91-
.filter(([path, childPkg]) => {
94+
.filter(({ path, childPkg }) => {
9295

9396
const name = childPkg.name;
9497

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

106-
for (const [path, childPkg] of allowedScripts) {
107-
await internals.runScript('preinstall', { childPkg, path, cwd });
109+
await internals.runScript('preinstall', { pkg, path: '', cwd, unsafePerm: true });
110+
111+
for (const { path, childPkg } of allowedScripts) {
112+
await internals.runScript('preinstall', { pkg: childPkg, path, cwd });
108113
}
109114

110-
for (const [path, childPkg] of allowedScripts) {
111-
await internals.runScript('install', { childPkg, path, cwd });
115+
for (const { path, childPkg } of allowedScripts) {
116+
await internals.runScript('install', { pkg: childPkg, path, cwd });
112117
}
113118

114-
for (const [path, childPkg] of allowedScripts) {
115-
await internals.runScript('postinstall', { childPkg, path, cwd });
119+
for (const { path, childPkg } of allowedScripts) {
120+
await internals.runScript('postinstall', { pkg: childPkg, path, cwd });
116121
}
122+
123+
await internals.runScript('install', { pkg, path: '', cwd, unsafePerm: true });
124+
await internals.runScript('postinstall', { pkg, path: '', cwd, unsafePerm: true });
125+
await internals.runScript('prepublish', { pkg, path: '', cwd, unsafePerm: true });
126+
await internals.runScript('prepare', { pkg, path: '', cwd, unsafePerm: true });
117127
};

0 commit comments

Comments
 (0)