Skip to content

chore(scripts): replace tsc by esbuild #3425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"name": "eslint-plugin-automation-custom",
"version": "1.0.0",
"description": "Custom rules for eslint",
"main": "dist/src/index.js",
"main": "dist/index.js",
"files": [
"src/**.ts"
],
"scripts": {
"build": "rm -rf dist/ && tsc",
"build": "esbuild --bundle --minify --platform=node --outdir=dist --log-level=error src/index.ts",
"lint": "eslint --ext=ts .",
"lint:fix": "eslint --ext=ts --fix .",
"test": "jest"
Expand All @@ -17,6 +17,7 @@
"@babel/preset-env": "7.24.8",
"@babel/preset-typescript": "7.24.7",
"@types/jest": "29.5.12",
"esbuild": "0.23.0",
"eslint": "8.57.0",
"jest": "29.7.0",
"typescript": "5.5.3"
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/actions/restore-artifacts/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ inputs:
List of languages to restore (use the pipe character to put each language on its own line)
runs:
using: 'node20'
main: './builddir/index.js'
main: './builddir/index.cjs'
256 changes: 256 additions & 0 deletions scripts/ci/actions/restore-artifacts/builddir/index.cjs

Large diffs are not rendered by default.

81 changes: 0 additions & 81 deletions scripts/ci/actions/restore-artifacts/builddir/index.js

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions scripts/ci/actions/restore-artifacts/builddir/package.json

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions scripts/ci/githubActions/createMatrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import { setOutput } from '@actions/core';
import { CLIENTS, createClientName, GENERATORS, LANGUAGES } from '../../common.js';
import { getLanguageFolder, getTestExtension, getTestOutputFolder } from '../../config.js';

import { COMMON_DEPENDENCIES, DEPENDENCIES } from './setRunVariables.js';
import type { ClientMatrix, CreateMatrix, ToRunMatrix } from './types.js';
import { isBaseChanged } from './utils.js';
import { COMMON_DEPENDENCIES, DEPENDENCIES, isBaseChanged } from './utils.js';

// This empty matrix is required by the CI, otherwise it throws
const EMPTY_MATRIX = { client: ['no-run'] };
Expand Down
70 changes: 1 addition & 69 deletions scripts/ci/githubActions/setRunVariables.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,7 @@
/* eslint-disable no-console */
import * as core from '@actions/core';

import { LANGUAGES } from '../../common.js';
import { getLanguageFolder } from '../../config.js';
import type { Language } from '../../types.js';

import { isBaseChanged } from './utils.js';

export const COMMON_DEPENDENCIES = {
GITHUB_ACTIONS_CHANGED: ['.github/actions', '.github/workflows'],
SCRIPTS_CHANGED: [
'scripts',
'eslint',
'yarn.lock',
'.eslintrc.cjs',
'config/generation.config.mjs',
'config/clients.config.json',
'config/release.config.json',
'generators',
'tests/CTS',
'.nvmrc',
],
COMMON_SPECS_CHANGED: ['specs/common'],
};

export function getVersionFileForLanguage(lang: Language): string {
// js rely on the nvmrc of the repo
if (lang === 'javascript') {
return '.nvmrc';
}

// jvm lang rely on the same java version
if (lang === 'kotlin' || lang === 'java' || lang === 'scala') {
return 'config/.java-version';
}

return `config/.${lang}-version`;
}

/**
* This dependency array is generated to match the "external" dependencies of a generated client.
*
* Those variables are used to determine if jobs should run, based on the changes
* made in their respective dependencies.
*
* Negative paths should start with `:!`.
*
* The variable will be accessible in the CI via `steps.diff.outputs.<name>`.
*
* Variables starting by `LANGUAGENAME_` will be used in the `createMatrix` to determine
* if a job should be added.
*/
export const DEPENDENCIES = LANGUAGES.reduce(
(finalDependencies, lang) => {
const key = `${lang.toUpperCase()}_CLIENT_CHANGED`;
const langFolder = getLanguageFolder(lang);

finalDependencies[key] = [
':!**node_modules',
`templates/${lang}`,
// language related files
langFolder,
getVersionFileForLanguage(lang),
`:!${langFolder}/.github`,
`:!${langFolder}/README.md`,
];

return finalDependencies;
},
{ ...COMMON_DEPENDENCIES } as Record<string, string[]>,
);
import { DEPENDENCIES, isBaseChanged } from './utils.js';

/**
* Outputs variables used in the CI to determine if a job should run.
Expand Down
67 changes: 67 additions & 0 deletions scripts/ci/githubActions/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,75 @@
/* eslint-disable no-console */
import * as core from '@actions/core';

import { LANGUAGES } from '../../common.js';
import { getLanguageFolder } from '../../config.js';
import type { Language } from '../../types.js';
import { getNbGitDiff } from '../utils.js';

export const COMMON_DEPENDENCIES = {
GITHUB_ACTIONS_CHANGED: ['.github/actions', '.github/workflows'],
SCRIPTS_CHANGED: [
'scripts',
'eslint',
'yarn.lock',
'.eslintrc.cjs',
'config/generation.config.mjs',
'config/clients.config.json',
'config/release.config.json',
'generators',
'tests/CTS',
'.nvmrc',
],
COMMON_SPECS_CHANGED: ['specs/common'],
};

/**
* This dependency array is generated to match the "external" dependencies of a generated client.
*
* Those variables are used to determine if jobs should run, based on the changes
* made in their respective dependencies.
*
* Negative paths should start with `:!`.
*
* The variable will be accessible in the CI via `steps.diff.outputs.<name>`.
*
* Variables starting by `LANGUAGENAME_` will be used in the `createMatrix` to determine
* if a job should be added.
*/
export const DEPENDENCIES = LANGUAGES.reduce(
(finalDependencies, lang) => {
const key = `${lang.toUpperCase()}_CLIENT_CHANGED`;
const langFolder = getLanguageFolder(lang);

finalDependencies[key] = [
':!**node_modules',
`templates/${lang}`,
// language related files
langFolder,
getVersionFileForLanguage(lang),
`:!${langFolder}/.github`,
`:!${langFolder}/README.md`,
];

return finalDependencies;
},
{ ...COMMON_DEPENDENCIES } as Record<string, string[]>,
);

function getVersionFileForLanguage(lang: Language): string {
// js rely on the nvmrc of the repo
if (lang === 'javascript') {
return '.nvmrc';
}

// jvm lang rely on the same java version
if (lang === 'kotlin' || lang === 'java' || lang === 'scala') {
return 'config/.java-version';
}

return `config/.${lang}-version`;
}

/**
* Determines if changes have been found in the `dependencies`, compared to the `baseBranch`.
*
Expand Down
1 change: 0 additions & 1 deletion scripts/configReplacer.cjs

This file was deleted.

9 changes: 2 additions & 7 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"

apic() {
(cd $ROOT/scripts && NODE_NO_WARNINGS=1 node dist/scripts/cli/index.js $*)
}

apicb() {
(cd $ROOT/scripts && yarn build:cli && NODE_NO_WARNINGS=1 node dist/scripts/cli/index.js $*)
# this is the same as `yarn build:cli && yarn start` but without the overhead of yarn
(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)
}

export apic
export apicb

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

complete -F _apic_complete apic
complete -F _apic_complete apicb
22 changes: 11 additions & 11 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@
"type": "module",
"scripts": {
"build": "yarn build:cli & yarn build:actions",
"build:actions": "cd ci/actions/restore-artifacts && ncc build src/index.ts --source-map --transpile-only --minify -o builddir",
"build:cli": "tsc && tsc-alias",
"createMatrix": "NODE_NO_WARNINGS=1 node dist/scripts/ci/githubActions/createMatrix.js",
"build:actions": "cd ci/actions/restore-artifacts && esbuild --bundle --format=cjs --minify --platform=node --outfile=builddir/index.cjs --log-level=error src/index.ts",
"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",
"createMatrix": "yarn runScript dist/ci/githubActions/createMatrix.js",
"lint": "eslint --ext=ts,js,mjs,cjs .",
"lint:deadcode": "knip",
"pre-commit": "node ./ci/husky/pre-commit.mjs",
"pushGeneratedCode": "NODE_NO_WARNINGS=1 node dist/scripts/ci/codegen/pushGeneratedCode.js",
"pushToAlgoliaDoc": "NODE_NO_WARNINGS=1 node dist/scripts/ci/codegen/pushToAlgoliaDoc.js",
"setRunVariables": "NODE_NO_WARNINGS=1 node dist/scripts/ci/githubActions/setRunVariables.js",
"spreadGeneration": "NODE_NO_WARNINGS=1 node dist/scripts/ci/codegen/spreadGeneration.js",
"start": "NODE_NO_WARNINGS=1 node dist/scripts/cli/index.js",
"pushGeneratedCode": "yarn runScript dist/ci/codegen/pushGeneratedCode.js",
"pushToAlgoliaDoc": "yarn runScript dist/ci/codegen/pushToAlgoliaDoc.js",
"runScript": "NODE_NO_WARNINGS=1 node --enable-source-maps",
"setRunVariables": "yarn runScript dist/ci/githubActions/setRunVariables.js",
"spreadGeneration": "yarn runScript dist/ci/codegen/spreadGeneration.js",
"start": "yarn runScript dist/cli/index.js",
"test": "vitest",
"waitForAllReleases": "NODE_NO_WARNINGS=1 node dist/scripts/ci/codegen/waitForAllReleases.js"
"waitForAllReleases": "yarn runScript dist/ci/codegen/waitForAllReleases.js"
},
"devDependencies": {
"@actions/artifact": "2.1.8",
Expand All @@ -33,12 +34,12 @@
"@types/node": "20.14.11",
"@types/semver": "7.5.8",
"@types/spinnies": "0.5.3",
"@vercel/ncc": "0.38.1",
"chai": "5.1.1",
"chalk": "5.3.0",
"commander": "12.1.0",
"crc": "4.3.2",
"dotenv": "16.4.5",
"esbuild": "0.23.0",
"eslint": "8.57.0",
"eslint-import-resolver-typescript": "3.6.1",
"eslint-plugin-import": "2.29.1",
Expand All @@ -51,7 +52,6 @@
"micromatch": "4.0.7",
"semver": "7.6.3",
"spinnies": "0.5.1",
"tsc-alias": "1.8.10",
"typescript": "5.5.3",
"vitest": "2.0.3"
}
Expand Down
9 changes: 0 additions & 9 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@
"lib": ["esnext", "dom"],
"outDir": "dist"
},
"tsc-alias": {
"resolveFullPaths": true,
"replacers": {
"configReplacer": {
"enabled": true,
"file": "configReplacer.cjs"
}
}
},
"include": ["**/*.ts", "./**.cjs", "**/*.mjs"],
"exclude": ["dist", "*.json", "node_modules", "**/*.test.ts"]
}
Loading
Loading