Skip to content

Commit ff6db30

Browse files
Improve the postinstall hook (#3933)
1 parent d4b7ef4 commit ff6db30

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# In the script, we use syntax that this version of ESLint can't parse
2+
postinstall.js

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"test:runner": "mocha tests/testrunner-tests.js",
2727
"test": "npm-run-all test:*",
2828
"release": "release-it",
29-
"postinstall": "npm run build"
29+
"postinstall": "node postinstall.js"
3030
},
3131
"repository": {
3232
"type": "git",

postinstall.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// The script is compatible with Node.js 10+
2+
3+
const { execSync } = require('child_process');
4+
const { resolve } = require('path');
5+
6+
function gulpInstalled () {
7+
try {
8+
require.resolve('gulp');
9+
return true;
10+
}
11+
catch {
12+
return false;
13+
}
14+
}
15+
16+
const root = resolve(__dirname, '.');
17+
18+
if (!gulpInstalled()) {
19+
console.log('[postinstall] Dependencies missing — installing...');
20+
execSync('npm install', { cwd: root, stdio: 'inherit' });
21+
}
22+
else {
23+
console.log('[postinstall] Dependencies already installed.');
24+
}
25+
26+
console.log('[postinstall] Running build...');
27+
execSync('npm run build', { cwd: root, stdio: 'inherit' });

0 commit comments

Comments
 (0)