From bb4dadf6f48269a333cc0f046f07a7ba5f5f915c Mon Sep 17 00:00:00 2001 From: James Henry Date: Wed, 9 Mar 2022 18:47:15 +0400 Subject: [PATCH] chore: refactor nx target graph to better include ast-spec copy (#4657) --- .eslintignore | 2 +- .gitignore | 2 +- nx.json | 2 +- package.json | 2 +- packages/types/package.json | 27 +++++++++++++++++++++++ packages/types/src/index.ts | 3 +-- packages/types/src/ts-estree.ts | 6 ++--- packages/types/tools/copy-ast-spec.ts | 8 +++---- packages/typescript-estree/src/convert.ts | 3 +-- 9 files changed, 40 insertions(+), 15 deletions(-) diff --git a/.eslintignore b/.eslintignore index b9323511dcb..62feb1dc327 100644 --- a/.eslintignore +++ b/.eslintignore @@ -17,4 +17,4 @@ packages/website-eslint/**/*.js packages/website-eslint/**/*.d.ts # Files copied as part of the build -packages/types/src/ast-spec.ts +packages/types/src/generated/**/*.ts diff --git a/.gitignore b/.gitignore index 6de4772a76c..5159aa25e16 100644 --- a/.gitignore +++ b/.gitignore @@ -77,4 +77,4 @@ _ts3.4 .rollup.cache # Files copied as part of the build -packages/types/src/ast-spec.ts +packages/types/src/generated/**/*.ts diff --git a/nx.json b/nx.json index de51f9a5cc8..7b001c0f790 100644 --- a/nx.json +++ b/nx.json @@ -17,7 +17,7 @@ "default": { "runner": "@nrwl/nx-cloud", "options": { - "cacheableOperations": ["build", "test", "package", "prepare"], + "cacheableOperations": ["build", "test", "package", "prebuild"], "accessToken": "YjFjNTBhOWUtY2JmNy00ZDhiLWE5N2UtZjliNDAwNmIzOTdjfHJlYWQtd3JpdGU=", "canTrackAnalytics": false, "showUsageWarnings": true, diff --git a/package.json b/package.json index 4d52775a141..0420f968b8c 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "url": "https://github.com/typescript-eslint/typescript-eslint/issues" }, "scripts": { - "build": "npx nx prebuild @typescript-eslint/types && nx run-many --target=build --all --parallel --exclude website", + "build": "nx run-many --target=build --all --parallel --exclude website", "check-clean-workspace-after-install": "git diff --quiet --exit-code", "check-configs": "nx run-many --target=check-configs --all --parallel", "check-docs": "nx run-many --target=check-docs --all --parallel", diff --git a/packages/types/package.json b/packages/types/package.json index 751b77b0275..5f6e8fc3aec 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -38,6 +38,33 @@ "lint": "eslint . --ext .js,.ts --ignore-path='../../.eslintignore'", "typecheck": "tsc -p tsconfig.json --noEmit" }, + "nx": { + "targets": { + "prebuild": { + "dependsOn": [ + { + "target": "build", + "projects": "dependencies" + } + ], + "outputs": [ + "packages/types/src/generated" + ] + }, + "build": { + "dependsOn": [ + { + "target": "build", + "projects": "dependencies" + }, + { + "target": "prebuild", + "projects": "self" + } + ] + } + } + }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 4bda24b1381..bb733d5275a 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1,5 +1,4 @@ -export { AST_NODE_TYPES } from './ast-spec'; -export { AST_TOKEN_TYPES } from './ast-spec'; +export { AST_NODE_TYPES, AST_TOKEN_TYPES } from './generated/ast-spec'; export * from './lib'; export * from './parser-options'; export * from './ts-estree'; diff --git a/packages/types/src/ts-estree.ts b/packages/types/src/ts-estree.ts index 037bd3f92c9..5f46887c44a 100644 --- a/packages/types/src/ts-estree.ts +++ b/packages/types/src/ts-estree.ts @@ -1,7 +1,7 @@ -import * as TSESTree from './ast-spec'; +import * as TSESTree from './generated/ast-spec'; // augment to add the parent property, which isn't part of the spec -declare module './ast-spec' { +declare module './generated/ast-spec' { interface BaseNode { parent?: TSESTree.Node; } @@ -18,4 +18,4 @@ declare module './ast-spec' { */ } -export * as TSESTree from './ast-spec'; +export * as TSESTree from './generated/ast-spec'; diff --git a/packages/types/tools/copy-ast-spec.ts b/packages/types/tools/copy-ast-spec.ts index 59bbf1e4b93..bd1a0b1120c 100644 --- a/packages/types/tools/copy-ast-spec.ts +++ b/packages/types/tools/copy-ast-spec.ts @@ -8,10 +8,10 @@ const writeFile = promisify(fs.writeFile); const execAsync = promisify(chlidProcess.exec); const AST_SPEC_PATH = path.resolve(__dirname, '../../ast-spec'); -const OUTPUT_PATH = path.join(path.resolve(__dirname, '../src/')); - -// ensure the package is built -chlidProcess.execSync('yarn build', { cwd: AST_SPEC_PATH, stdio: 'inherit' }); +const OUTPUT_PATH = path.join(path.resolve(__dirname, '../src/generated')); +if (!fs.existsSync(OUTPUT_PATH)) { + fs.mkdirSync(OUTPUT_PATH); +} const HEADER = `\ /********************************************** diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index f0fb7d3cf58..9c53232a530 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -35,7 +35,6 @@ import { TSNode, } from './ts-estree'; import { typescriptVersionIsAtLeast } from './version-check'; -import { Expression } from '@typescript-eslint/types/src/ast-spec'; const SyntaxKind = ts.SyntaxKind; @@ -1925,7 +1924,7 @@ export class Converter { expressions: [], }); - const left = this.convertChild(node.left) as Expression; + const left = this.convertChild(node.left) as TSESTree.Expression; if ( left.type === AST_NODE_TYPES.SequenceExpression && node.left.kind !== SyntaxKind.ParenthesizedExpression