Skip to content

Commit

Permalink
chore: Ensure to install all nested packages on npm install
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jul 1, 2020
1 parent c014003 commit 6879eec
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"license": "Apache",
"scripts": {
"lint": "eslint --ignore-path .gitignore .",
"postinstall": "./scripts/install-nested-packages.js",
"prettier-check": "prettier -c --ignore-path .gitignore \"**/*.{css,html,js,json,yaml,yml}\"",
"prettify": "prettier --write --ignore-path .gitignore \"**/*.{css,html,js,json,yaml,yml}\"",
"test": "jest --bail 1 --testEnvironment node ./test/integration.test.js"
Expand Down
39 changes: 39 additions & 0 deletions scripts/install-nested-packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env node

'use strict';

process.on('unhandledRejection', (reason) => {
throw reason;
});

const path = require('path');
const childProcess = require('child_process');

const platformRoot = path.resolve(__dirname, '..');

const npmInstall = (packagePath) =>
new Promise((resolve, reject) => {
console.log('---------------------------------------');
console.log(`Install \x1b[33m${packagePath}\x1b[39m ...\n`);
const child = childProcess.spawn('npm', ['install'], {
cwd: path.resolve(platformRoot, packagePath),
stdio: 'inherit',
});
child.on('error', reject);
child.on('close', (code) => {
if (code) {
reject(new Error(`npm install failed at ${packagePath}`));
} else {
resolve();
}
});
});

const packagesPaths = ['src', 'src/_express', 'src/_src', 'test/src'];

(async () => {
// Running multiple "npm install" prcesses in parallel is not confirmed to be safe.
for (const packagePath of packagesPaths) {
await npmInstall(packagePath);
}
})();

0 comments on commit 6879eec

Please sign in to comment.