Skip to content

Commit 793c138

Browse files
authored
chore(scripts): replace tsc by esbuild (#3425)
1 parent 8171dd3 commit 793c138

File tree

15 files changed

+597
-249
lines changed

15 files changed

+597
-249
lines changed

eslint/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"name": "eslint-plugin-automation-custom",
33
"version": "1.0.0",
44
"description": "Custom rules for eslint",
5-
"main": "dist/src/index.js",
5+
"main": "dist/index.js",
66
"files": [
77
"src/**.ts"
88
],
99
"scripts": {
10-
"build": "rm -rf dist/ && tsc",
10+
"build": "esbuild --bundle --minify --platform=node --outdir=dist --log-level=error src/index.ts",
1111
"lint": "eslint --ext=ts .",
1212
"lint:fix": "eslint --ext=ts --fix .",
1313
"test": "jest"
@@ -17,6 +17,7 @@
1717
"@babel/preset-env": "7.24.8",
1818
"@babel/preset-typescript": "7.24.7",
1919
"@types/jest": "29.5.12",
20+
"esbuild": "0.23.0",
2021
"eslint": "8.57.0",
2122
"jest": "29.7.0",
2223
"typescript": "5.5.3"

scripts/ci/actions/restore-artifacts/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ inputs:
1111
List of languages to restore (use the pipe character to put each language on its own line)
1212
runs:
1313
using: 'node20'
14-
main: './builddir/index.js'
14+
main: './builddir/index.cjs'

scripts/ci/actions/restore-artifacts/builddir/index.cjs

Lines changed: 256 additions & 0 deletions
Large diffs are not rendered by default.

scripts/ci/actions/restore-artifacts/builddir/index.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

scripts/ci/actions/restore-artifacts/builddir/index.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/ci/actions/restore-artifacts/builddir/package.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

scripts/ci/actions/restore-artifacts/builddir/sourcemap-register.cjs

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/ci/githubActions/createMatrix.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import { setOutput } from '@actions/core';
44
import { CLIENTS, createClientName, GENERATORS, LANGUAGES } from '../../common.js';
55
import { getLanguageFolder, getTestExtension, getTestOutputFolder } from '../../config.js';
66

7-
import { COMMON_DEPENDENCIES, DEPENDENCIES } from './setRunVariables.js';
87
import type { ClientMatrix, CreateMatrix, ToRunMatrix } from './types.js';
9-
import { isBaseChanged } from './utils.js';
8+
import { COMMON_DEPENDENCIES, DEPENDENCIES, isBaseChanged } from './utils.js';
109

1110
// This empty matrix is required by the CI, otherwise it throws
1211
const EMPTY_MATRIX = { client: ['no-run'] };

scripts/ci/githubActions/setRunVariables.ts

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,7 @@
11
/* eslint-disable no-console */
22
import * as core from '@actions/core';
33

4-
import { LANGUAGES } from '../../common.js';
5-
import { getLanguageFolder } from '../../config.js';
6-
import type { Language } from '../../types.js';
7-
8-
import { isBaseChanged } from './utils.js';
9-
10-
export const COMMON_DEPENDENCIES = {
11-
GITHUB_ACTIONS_CHANGED: ['.github/actions', '.github/workflows'],
12-
SCRIPTS_CHANGED: [
13-
'scripts',
14-
'eslint',
15-
'yarn.lock',
16-
'.eslintrc.cjs',
17-
'config/generation.config.mjs',
18-
'config/clients.config.json',
19-
'config/release.config.json',
20-
'generators',
21-
'tests/CTS',
22-
'.nvmrc',
23-
],
24-
COMMON_SPECS_CHANGED: ['specs/common'],
25-
};
26-
27-
export function getVersionFileForLanguage(lang: Language): string {
28-
// js rely on the nvmrc of the repo
29-
if (lang === 'javascript') {
30-
return '.nvmrc';
31-
}
32-
33-
// jvm lang rely on the same java version
34-
if (lang === 'kotlin' || lang === 'java' || lang === 'scala') {
35-
return 'config/.java-version';
36-
}
37-
38-
return `config/.${lang}-version`;
39-
}
40-
41-
/**
42-
* This dependency array is generated to match the "external" dependencies of a generated client.
43-
*
44-
* Those variables are used to determine if jobs should run, based on the changes
45-
* made in their respective dependencies.
46-
*
47-
* Negative paths should start with `:!`.
48-
*
49-
* The variable will be accessible in the CI via `steps.diff.outputs.<name>`.
50-
*
51-
* Variables starting by `LANGUAGENAME_` will be used in the `createMatrix` to determine
52-
* if a job should be added.
53-
*/
54-
export const DEPENDENCIES = LANGUAGES.reduce(
55-
(finalDependencies, lang) => {
56-
const key = `${lang.toUpperCase()}_CLIENT_CHANGED`;
57-
const langFolder = getLanguageFolder(lang);
58-
59-
finalDependencies[key] = [
60-
':!**node_modules',
61-
`templates/${lang}`,
62-
// language related files
63-
langFolder,
64-
getVersionFileForLanguage(lang),
65-
`:!${langFolder}/.github`,
66-
`:!${langFolder}/README.md`,
67-
];
68-
69-
return finalDependencies;
70-
},
71-
{ ...COMMON_DEPENDENCIES } as Record<string, string[]>,
72-
);
4+
import { DEPENDENCIES, isBaseChanged } from './utils.js';
735

746
/**
757
* Outputs variables used in the CI to determine if a job should run.

scripts/ci/githubActions/utils.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,75 @@
11
/* eslint-disable no-console */
22
import * as core from '@actions/core';
33

4+
import { LANGUAGES } from '../../common.js';
5+
import { getLanguageFolder } from '../../config.js';
6+
import type { Language } from '../../types.js';
47
import { getNbGitDiff } from '../utils.js';
58

9+
export const COMMON_DEPENDENCIES = {
10+
GITHUB_ACTIONS_CHANGED: ['.github/actions', '.github/workflows'],
11+
SCRIPTS_CHANGED: [
12+
'scripts',
13+
'eslint',
14+
'yarn.lock',
15+
'.eslintrc.cjs',
16+
'config/generation.config.mjs',
17+
'config/clients.config.json',
18+
'config/release.config.json',
19+
'generators',
20+
'tests/CTS',
21+
'.nvmrc',
22+
],
23+
COMMON_SPECS_CHANGED: ['specs/common'],
24+
};
25+
26+
/**
27+
* This dependency array is generated to match the "external" dependencies of a generated client.
28+
*
29+
* Those variables are used to determine if jobs should run, based on the changes
30+
* made in their respective dependencies.
31+
*
32+
* Negative paths should start with `:!`.
33+
*
34+
* The variable will be accessible in the CI via `steps.diff.outputs.<name>`.
35+
*
36+
* Variables starting by `LANGUAGENAME_` will be used in the `createMatrix` to determine
37+
* if a job should be added.
38+
*/
39+
export const DEPENDENCIES = LANGUAGES.reduce(
40+
(finalDependencies, lang) => {
41+
const key = `${lang.toUpperCase()}_CLIENT_CHANGED`;
42+
const langFolder = getLanguageFolder(lang);
43+
44+
finalDependencies[key] = [
45+
':!**node_modules',
46+
`templates/${lang}`,
47+
// language related files
48+
langFolder,
49+
getVersionFileForLanguage(lang),
50+
`:!${langFolder}/.github`,
51+
`:!${langFolder}/README.md`,
52+
];
53+
54+
return finalDependencies;
55+
},
56+
{ ...COMMON_DEPENDENCIES } as Record<string, string[]>,
57+
);
58+
59+
function getVersionFileForLanguage(lang: Language): string {
60+
// js rely on the nvmrc of the repo
61+
if (lang === 'javascript') {
62+
return '.nvmrc';
63+
}
64+
65+
// jvm lang rely on the same java version
66+
if (lang === 'kotlin' || lang === 'java' || lang === 'scala') {
67+
return 'config/.java-version';
68+
}
69+
70+
return `config/.${lang}-version`;
71+
}
72+
673
/**
774
* Determines if changes have been found in the `dependencies`, compared to the `baseBranch`.
875
*

scripts/configReplacer.cjs

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts/install.sh

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@
1212
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
1313

1414
apic() {
15-
(cd $ROOT/scripts && NODE_NO_WARNINGS=1 node dist/scripts/cli/index.js $*)
16-
}
17-
18-
apicb() {
19-
(cd $ROOT/scripts && yarn build:cli && NODE_NO_WARNINGS=1 node dist/scripts/cli/index.js $*)
15+
# this is the same as `yarn build:cli && yarn start` but without the overhead of yarn
16+
(cd $ROOT/scripts && cd $ROOT/scripts && cat package.json | jq '.scripts."build:cli"' | xargs -I{} sh -c "eval '../node_modules/.bin/{}'" && NODE_NO_WARNINGS=1 node --enable-source-maps dist/cli/index.js $* || true)
2017
}
2118

2219
export apic
23-
export apicb
2420

2521
_list_languages() {
2622
cat $ROOT/config/clients.config.json | jq -r 'keys[]'
@@ -112,4 +108,3 @@ _apic_complete() {
112108
}
113109

114110
complete -F _apic_complete apic
115-
complete -F _apic_complete apicb

scripts/package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
"type": "module",
55
"scripts": {
66
"build": "yarn build:cli & yarn build:actions",
7-
"build:actions": "cd ci/actions/restore-artifacts && ncc build src/index.ts --source-map --transpile-only --minify -o builddir",
8-
"build:cli": "tsc && tsc-alias",
9-
"createMatrix": "NODE_NO_WARNINGS=1 node dist/scripts/ci/githubActions/createMatrix.js",
7+
"build:actions": "cd ci/actions/restore-artifacts && esbuild --bundle --format=cjs --minify --platform=node --outfile=builddir/index.cjs --log-level=error src/index.ts",
8+
"build:cli": "esbuild --bundle --format=esm --sourcemap --platform=node --packages=external --outdir=dist --log-level=error cli/index.ts ci/codegen/*.ts ci/githubActions/*.ts",
9+
"createMatrix": "yarn runScript dist/ci/githubActions/createMatrix.js",
1010
"lint": "eslint --ext=ts,js,mjs,cjs .",
1111
"lint:deadcode": "knip",
1212
"pre-commit": "node ./ci/husky/pre-commit.mjs",
13-
"pushGeneratedCode": "NODE_NO_WARNINGS=1 node dist/scripts/ci/codegen/pushGeneratedCode.js",
14-
"pushToAlgoliaDoc": "NODE_NO_WARNINGS=1 node dist/scripts/ci/codegen/pushToAlgoliaDoc.js",
15-
"setRunVariables": "NODE_NO_WARNINGS=1 node dist/scripts/ci/githubActions/setRunVariables.js",
16-
"spreadGeneration": "NODE_NO_WARNINGS=1 node dist/scripts/ci/codegen/spreadGeneration.js",
17-
"start": "NODE_NO_WARNINGS=1 node dist/scripts/cli/index.js",
13+
"pushGeneratedCode": "yarn runScript dist/ci/codegen/pushGeneratedCode.js",
14+
"pushToAlgoliaDoc": "yarn runScript dist/ci/codegen/pushToAlgoliaDoc.js",
15+
"runScript": "NODE_NO_WARNINGS=1 node --enable-source-maps",
16+
"setRunVariables": "yarn runScript dist/ci/githubActions/setRunVariables.js",
17+
"spreadGeneration": "yarn runScript dist/ci/codegen/spreadGeneration.js",
18+
"start": "yarn runScript dist/cli/index.js",
1819
"test": "vitest",
19-
"waitForAllReleases": "NODE_NO_WARNINGS=1 node dist/scripts/ci/codegen/waitForAllReleases.js"
20+
"waitForAllReleases": "yarn runScript dist/ci/codegen/waitForAllReleases.js"
2021
},
2122
"devDependencies": {
2223
"@actions/artifact": "2.1.8",
@@ -33,12 +34,12 @@
3334
"@types/node": "20.14.11",
3435
"@types/semver": "7.5.8",
3536
"@types/spinnies": "0.5.3",
36-
"@vercel/ncc": "0.38.1",
3737
"chai": "5.1.1",
3838
"chalk": "5.3.0",
3939
"commander": "12.1.0",
4040
"crc": "4.3.2",
4141
"dotenv": "16.4.5",
42+
"esbuild": "0.23.0",
4243
"eslint": "8.57.0",
4344
"eslint-import-resolver-typescript": "3.6.1",
4445
"eslint-plugin-import": "2.29.1",
@@ -51,7 +52,6 @@
5152
"micromatch": "4.0.7",
5253
"semver": "7.6.3",
5354
"spinnies": "0.5.1",
54-
"tsc-alias": "1.8.10",
5555
"typescript": "5.5.3",
5656
"vitest": "2.0.3"
5757
}

scripts/tsconfig.json

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
"lib": ["esnext", "dom"],
99
"outDir": "dist"
1010
},
11-
"tsc-alias": {
12-
"resolveFullPaths": true,
13-
"replacers": {
14-
"configReplacer": {
15-
"enabled": true,
16-
"file": "configReplacer.cjs"
17-
}
18-
}
19-
},
2011
"include": ["**/*.ts", "./**.cjs", "**/*.mjs"],
2112
"exclude": ["dist", "*.json", "node_modules", "**/*.test.ts"]
2213
}

0 commit comments

Comments
 (0)