Skip to content

Commit

Permalink
chore: refactor nx target graph to better include ast-spec copy (#4657)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry committed Mar 9, 2022
1 parent 82a8c4e commit bb4dadf
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
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
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
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
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
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
@@ -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
@@ -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
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
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

0 comments on commit bb4dadf

Please sign in to comment.