Skip to content

chore: refactor nx target graph to better include ast-spec copy #4657

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 1 commit into from
Mar 9, 2022
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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 27 additions & 0 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
6 changes: 3 additions & 3 deletions packages/types/src/ts-estree.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Expand All @@ -18,4 +18,4 @@ declare module './ast-spec' {
*/
}

export * as TSESTree from './ast-spec';
export * as TSESTree from './generated/ast-spec';
8 changes: 4 additions & 4 deletions packages/types/tools/copy-ast-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `\
/**********************************************
Expand Down
3 changes: 1 addition & 2 deletions packages/typescript-estree/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down