Skip to content

Commit 30c6a20

Browse files
authored
build: fix husky autoinstall #3433
Problem: husky doesn't autoinstall since c7637c2 Solution: auto install husky only if not running in CI.
1 parent ad31eb8 commit 30c6a20

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,6 +3431,7 @@
34313431
}
34323432
},
34333433
"scripts": {
3434+
"prepare": "ts-node ./scripts/build/prepare.ts",
34343435
"vscode:prepublish": "npm run clean && npm run buildScripts && webpack --mode production && npm run copyFiles -- --webpacked",
34353436
"clean": "ts-node ./scripts/clean.ts dist",
34363437
"reset": "npm run clean -- node_modules && npm install",

scripts/build/prepare.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*!
2+
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
//
7+
// Performs NPM "prepare" step, except when running in CI.
8+
//
9+
// prepare: https://docs.npmjs.com/cli/v9/using-npm/scripts#prepare-and-prepublish:
10+
// - Runs BEFORE the package is packed, i.e. during "npm publish" AND "npm pack".
11+
// - Runs on local "npm install".
12+
// - Runs AFTER `prepublish`, but BEFORE `prepublishOnly`.
13+
// - Runs in the background. To see the output, run with "--foreground-scripts".
14+
//
15+
16+
import * as child_process from 'child_process'
17+
18+
/**
19+
* Returns true if the current build is running on CI (build server).
20+
*/
21+
export function isCI(): boolean {
22+
return undefined !== process.env['GITHUB_ACTION'] || undefined !== process.env['CODEBUILD_BUILD_ID']
23+
}
24+
25+
function main() {
26+
if (isCI()) {
27+
console.log('prepare: skipped (running in CI)')
28+
return
29+
}
30+
child_process.execSync('husky install', { stdio: 'inherit' })
31+
}
32+
33+
main()

src/shared/systemUtilities.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,4 @@ export class SystemUtilities {
332332
getLogger().warn('findBashPath: failed: %s', proc)
333333
}
334334
}
335-
336-
/**
337-
* Returns true if the current build is running on CI (build server).
338-
*/
339-
public static isCI(): boolean {
340-
return undefined !== process.env['CODEBUILD_BUILD_ID']
341-
}
342335
}

src/shared/vscode/env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DefaultEnv implements Env {
3737
* Returns true if the current build is running on CI (build server).
3838
*/
3939
export function isCI(): boolean {
40-
return undefined !== process.env['CODEBUILD_BUILD_ID']
40+
return undefined !== process.env['GITHUB_ACTION'] || undefined !== process.env['CODEBUILD_BUILD_ID']
4141
}
4242

4343
/** Variable added via webpack */

0 commit comments

Comments
 (0)