Skip to content

Commit 37c411f

Browse files
authored
Infra/pre push and yarn constraints (#3854)
* prepush and yarn constraints (initial commit) * yarn constraints - avoid unwanted dependencies
1 parent ef88a73 commit 37c411f

File tree

7 files changed

+205
-5
lines changed

7 files changed

+205
-5
lines changed

.githooks/pre-push

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
COMMAND="yarn prepush"
4+
5+
$COMMAND
6+
RESULT=$?
7+
if [ $RESULT -ne 0 ]; then
8+
echo "pre-push hook failed $COMMAND"
9+
exit 1
10+
fi
7.13 KB
Binary file not shown.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
"build": "node scripts/build/build.js",
3131
"build:local": "./scripts/build/createLocalPackage.sh",
3232
"pre-push": "npm run build:dev && npm run test",
33+
"prepush": "node ./scripts/prepush.js",
34+
"yarnConstraints": "yarn constraints",
35+
"yarnConstraintsFix": "yarn constraints --fix",
3336
"docs:deploy": "./scripts/docs/deployDocs.sh",
3437
"docs:build": "node scripts/docs/buildDocs.js",
3538
"docs:start": "(cd docuilib && yarn start)",
@@ -84,6 +87,7 @@
8487
"@shopify/flash-list": "1.7.6",
8588
"@testing-library/react-hooks": "^8.0.1",
8689
"@testing-library/react-native": "^11.5.1",
90+
"@topcli/spinner": "patch:@topcli/spinner@npm%3A2.1.2#./.yarn/patches/@topcli-spinner-npm-2.1.2-262b584167.patch",
8791
"@types/hoist-non-react-statics": "^3.3.1",
8892
"@types/jest": "^29.5.13",
8993
"@types/lodash": "^4.0.0",
@@ -95,8 +99,10 @@
9599
"@typescript-eslint/eslint-plugin": "^5.3.1",
96100
"@typescript-eslint/parser": "^5.3.1",
97101
"@welldone-software/why-did-you-render": "^3.2.1",
102+
"@yarnpkg/types": "^4.0.1",
98103
"babel-plugin-lodash": "^3.3.4",
99104
"babel-plugin-module-resolver": "^5.0.0",
105+
"chalk": "^4.1.2",
100106
"eslint": "8.19.0",
101107
"eslint-config-wix": "2.0.0",
102108
"eslint-plugin-react": "^7.24.0",

scripts/prepush.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env node
2+
3+
const semver = require('semver');
4+
const fs = require('fs');
5+
const path = require('path');
6+
7+
const nodeVersion = fs.readFileSync(path.resolve(process.cwd(), '.nvmrc'), 'utf-8').trim();
8+
if (!semver.gte(process.version.substring(1), nodeVersion)) {
9+
throw new Error(`Node version must be at least ${nodeVersion}`);
10+
}
11+
12+
const cp = require('child_process');
13+
const {logGreen, logError} = require('./utils');
14+
const {Spinner} = require('@topcli/spinner');
15+
16+
const ARGS = process.argv.slice(2);
17+
const TEST_ARG = 'test';
18+
const TEST_COMMAND = 'yarn test';
19+
20+
const PRE_PUSH_COMMANDS = [
21+
'yarn yarnConstraints',
22+
'yarn dedupe --check',
23+
'yarn lint --quiet',
24+
'yarn build:dev >/dev/null'
25+
];
26+
27+
async function run() {
28+
logGreen('Running pre-push checks...');
29+
const commands = [...PRE_PUSH_COMMANDS];
30+
if (ARGS.includes(TEST_ARG)) {
31+
commands.push(TEST_COMMAND);
32+
}
33+
const promises = commands.map(execute);
34+
const results = await Promise.allSettled(promises);
35+
const failed = results.filter(result => result.status === 'rejected');
36+
if (failed.length > 0) {
37+
logError('Pre-push checks failed!');
38+
failed.forEach(result => logFailedCommand(result.reason));
39+
process.exit(1);
40+
}
41+
process.exit(0);
42+
}
43+
44+
function logFailedCommand({command, stdout, stderr}) {
45+
logError(`${command}:`);
46+
if (stdout) {
47+
logError('STDOUT:');
48+
logError(stdout);
49+
}
50+
if (stderr) {
51+
logError('STDERR:');
52+
logError(stderr);
53+
}
54+
}
55+
56+
async function execute(command) {
57+
const spinner = new Spinner();
58+
return new Promise((resolve, reject) => {
59+
spinner.start(command);
60+
cp.exec(command, {encoding: 'utf-8'}, (error, stdout, stderr) => {
61+
if (error) {
62+
spinner.failed();
63+
reject({command, error, stdout, stderr});
64+
}
65+
spinner.succeed();
66+
resolve();
67+
});
68+
});
69+
}
70+
71+
run();

scripts/utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const chalk = require('chalk');
2+
3+
function logDebug() {
4+
console.log(chalk.gray(...arguments));
5+
}
6+
7+
function logGreen() {
8+
console.log(chalk.green(...arguments));
9+
}
10+
11+
function logError() {
12+
// eslint-disable-next-line no-restricted-syntax
13+
console.error(chalk.red(...arguments));
14+
}
15+
16+
17+
module.exports = {
18+
logDebug,
19+
logGreen,
20+
logError
21+
};

yarn.config.cjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const fs = require('fs');
2+
const {defineConfig} = require(`@yarnpkg/types`);
3+
const {logError} = require('./scripts/utils');
4+
5+
function checkYarnLock() {
6+
const yarnLock = fs.readFileSync('./yarn.lock', 'utf8');
7+
const matches = yarnLock.match(/npm.dev/);
8+
9+
if (matches !== null) {
10+
logError('Yarn lock contains unwanted dependencies');
11+
process.exit(1);
12+
}
13+
}
14+
15+
module.exports = defineConfig({
16+
constraints: async () => {
17+
checkYarnLock();
18+
}
19+
});

yarn.lock

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,6 +2929,41 @@ __metadata:
29292929
languageName: node
29302930
linkType: hard
29312931

2932+
"@topcli/spinner@npm:2.1.2":
2933+
version: 2.1.2
2934+
resolution: "@topcli/spinner@npm:2.1.2"
2935+
dependencies:
2936+
"@topcli/wcwidth": "npm:^1.0.1"
2937+
ansi-regex: "npm:^6.0.1"
2938+
cli-cursor: "npm:^4.0.0"
2939+
cli-spinners: "npm:^2.9.0"
2940+
kleur: "npm:^4.1.5"
2941+
strip-ansi: "npm:^7.1.0"
2942+
checksum: 10c0/6ccdba1d642c736473b942f05ddf967bc6fd7d23a608bcfa9ddd9c13810545d12b29c27f7a0c2f7723e6ebc27f016ef224217ef04307285d6da0b2031281b806
2943+
languageName: node
2944+
linkType: hard
2945+
2946+
"@topcli/spinner@patch:@topcli/spinner@npm%3A2.1.2#./.yarn/patches/@topcli-spinner-npm-2.1.2-262b584167.patch::locator=react-native-ui-lib%40workspace%3A.":
2947+
version: 2.1.2
2948+
resolution: "@topcli/spinner@patch:@topcli/spinner@npm%3A2.1.2#./.yarn/patches/@topcli-spinner-npm-2.1.2-262b584167.patch::version=2.1.2&hash=a05f52&locator=react-native-ui-lib%40workspace%3A."
2949+
dependencies:
2950+
"@topcli/wcwidth": "npm:^1.0.1"
2951+
ansi-regex: "npm:^6.0.1"
2952+
cli-cursor: "npm:^4.0.0"
2953+
cli-spinners: "npm:^2.9.0"
2954+
kleur: "npm:^4.1.5"
2955+
strip-ansi: "npm:^7.1.0"
2956+
checksum: 10c0/5f600f7989942b05fbe7e93e0db4ec8c7f22d8ac8a509e7f51fdd60c0584ecaea66c0a23a5225f4d04150b8914386ddb386dd3642769a7e3be5c11d244352bd0
2957+
languageName: node
2958+
linkType: hard
2959+
2960+
"@topcli/wcwidth@npm:^1.0.1":
2961+
version: 1.0.1
2962+
resolution: "@topcli/wcwidth@npm:1.0.1"
2963+
checksum: 10c0/b7ef1f226811853f38dc97063a5b09150e6e4b1c77b608acdb9befdcc81db2a3d636be68395dfe9c4150bef5628d3ca468f735efc6d17fe672e349fa6c82f4b4
2964+
languageName: node
2965+
linkType: hard
2966+
29322967
"@trysound/sax@npm:0.2.0":
29332968
version: 0.2.0
29342969
resolution: "@trysound/sax@npm:0.2.0"
@@ -3470,6 +3505,15 @@ __metadata:
34703505
languageName: node
34713506
linkType: hard
34723507

3508+
"@yarnpkg/types@npm:^4.0.1":
3509+
version: 4.0.1
3510+
resolution: "@yarnpkg/types@npm:4.0.1"
3511+
dependencies:
3512+
tslib: "npm:^2.4.0"
3513+
checksum: 10c0/90226789475680ba599833571dd76c0718dd5b4c5022481263ef309d6a628f6246671cd6ca86e49c966ddefa7aca6ccef82240dc1476d2cea702ea5bee2a6b72
3514+
languageName: node
3515+
linkType: hard
3516+
34733517
"abbrev@npm:^2.0.0":
34743518
version: 2.0.0
34753519
resolution: "abbrev@npm:2.0.0"
@@ -4367,7 +4411,16 @@ __metadata:
43674411
languageName: node
43684412
linkType: hard
43694413

4370-
"cli-spinners@npm:^2.5.0":
4414+
"cli-cursor@npm:^4.0.0":
4415+
version: 4.0.0
4416+
resolution: "cli-cursor@npm:4.0.0"
4417+
dependencies:
4418+
restore-cursor: "npm:^4.0.0"
4419+
checksum: 10c0/e776e8c3c6727300d0539b0d25160b2bb56aed1a63942753ba1826b012f337a6f4b7ace3548402e4f2f13b5e16bfd751be672c44b203205e7eca8be94afec42c
4420+
languageName: node
4421+
linkType: hard
4422+
4423+
"cli-spinners@npm:^2.5.0, cli-spinners@npm:^2.9.0":
43714424
version: 2.9.2
43724425
resolution: "cli-spinners@npm:2.9.2"
43734426
checksum: 10c0/907a1c227ddf0d7a101e7ab8b300affc742ead4b4ebe920a5bf1bc6d45dce2958fcd195eb28fa25275062fe6fa9b109b93b63bc8033396ed3bcb50297008b3a3
@@ -7820,6 +7873,13 @@ __metadata:
78207873
languageName: node
78217874
linkType: hard
78227875

7876+
"kleur@npm:^4.1.5":
7877+
version: 4.1.5
7878+
resolution: "kleur@npm:4.1.5"
7879+
checksum: 10c0/e9de6cb49657b6fa70ba2d1448fd3d691a5c4370d8f7bbf1c2f64c24d461270f2117e1b0afe8cb3114f13bbd8e51de158c2a224953960331904e636a5e4c0f2a
7880+
languageName: node
7881+
linkType: hard
7882+
78237883
"leven@npm:^3.1.0":
78247884
version: 3.1.0
78257885
resolution: "leven@npm:3.1.0"
@@ -9719,6 +9779,7 @@ __metadata:
97199779
"@shopify/flash-list": "npm:1.7.6"
97209780
"@testing-library/react-hooks": "npm:^8.0.1"
97219781
"@testing-library/react-native": "npm:^11.5.1"
9782+
"@topcli/spinner": "patch:@topcli/spinner@npm%3A2.1.2#./.yarn/patches/@topcli-spinner-npm-2.1.2-262b584167.patch"
97229783
"@types/hoist-non-react-statics": "npm:^3.3.1"
97239784
"@types/jest": "npm:^29.5.13"
97249785
"@types/lodash": "npm:^4.0.0"
@@ -9730,9 +9791,11 @@ __metadata:
97309791
"@typescript-eslint/eslint-plugin": "npm:^5.3.1"
97319792
"@typescript-eslint/parser": "npm:^5.3.1"
97329793
"@welldone-software/why-did-you-render": "npm:^3.2.1"
9794+
"@yarnpkg/types": "npm:^4.0.1"
97339795
babel-plugin-lodash: "npm:^3.3.4"
97349796
babel-plugin-module-resolver: "npm:^5.0.0"
97359797
babel-plugin-transform-inline-environment-variables: "npm:^0.0.2"
9798+
chalk: "npm:^4.1.2"
97369799
color: "npm:^3.1.0"
97379800
commons-validator-js: "npm:^1.0.237"
97389801
date-fns: "npm:^2.29.3"
@@ -10228,6 +10291,16 @@ __metadata:
1022810291
languageName: node
1022910292
linkType: hard
1023010293

10294+
"restore-cursor@npm:^4.0.0":
10295+
version: 4.0.0
10296+
resolution: "restore-cursor@npm:4.0.0"
10297+
dependencies:
10298+
onetime: "npm:^5.1.0"
10299+
signal-exit: "npm:^3.0.2"
10300+
checksum: 10c0/6f7da8c5e422ac26aa38354870b1afac09963572cf2879443540449068cb43476e9cbccf6f8de3e0171e0d6f7f533c2bc1a0a008003c9a525bbc098e89041318
10301+
languageName: node
10302+
linkType: hard
10303+
1023110304
"retry@npm:^0.12.0":
1023210305
version: 0.12.0
1023310306
resolution: "retry@npm:0.12.0"
@@ -10916,12 +10989,12 @@ __metadata:
1091610989
languageName: node
1091710990
linkType: hard
1091810991

10919-
"strip-ansi@npm:^7.0.1":
10920-
version: 7.1.0
10921-
resolution: "strip-ansi@npm:7.1.0"
10992+
"strip-ansi@npm:^7.0.1, strip-ansi@npm:^7.1.0":
10993+
version: 7.1.2
10994+
resolution: "strip-ansi@npm:7.1.2"
1092210995
dependencies:
1092310996
ansi-regex: "npm:^6.0.1"
10924-
checksum: 10c0/a198c3762e8832505328cbf9e8c8381de14a4fa50a4f9b2160138158ea88c0f5549fb50cb13c651c3088f47e63a108b34622ec18c0499b6c8c3a5ddf6b305ac4
10997+
checksum: 10c0/0d6d7a023de33368fd042aab0bf48f4f4077abdfd60e5393e73c7c411e85e1b3a83507c11af2e656188511475776215df9ca589b4da2295c9455cc399ce1858b
1092510998
languageName: node
1092610999
linkType: hard
1092711000

0 commit comments

Comments
 (0)