From d65c3362e291dd810ceddacf14864611f801d44a Mon Sep 17 00:00:00 2001 From: spalger Date: Mon, 19 Dec 2022 20:16:50 -0700 Subject: [PATCH] fix(core): find imports in `export type` statements The "analyzeSourceFiles" functionality which automatically detects deps does not currently file "import" requests in statements using the relatively new `export type ... from "..."` syntax. This is happening because the scanner does not find an asterick or curly-bracket after the `export` keyword, so it strips that export statement from the code. --- packages/nx/src/utils/strip-source-code.spec.ts | 2 ++ packages/nx/src/utils/strip-source-code.ts | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/nx/src/utils/strip-source-code.spec.ts b/packages/nx/src/utils/strip-source-code.spec.ts index fd047848889fa..e50468be58301 100644 --- a/packages/nx/src/utils/strip-source-code.spec.ts +++ b/packages/nx/src/utils/strip-source-code.spec.ts @@ -47,6 +47,7 @@ import('./module.ts')`; } from './a'; export { B } from './b'; + export type { B } from './b'; export { C as D } from './c'; @@ -58,6 +59,7 @@ export { A } from './a' export { B } from './b' +export type { B } from './b' export { C as D } from './c'`; expect(stripSourceCode(scanner, input)).toEqual(expected); diff --git a/packages/nx/src/utils/strip-source-code.ts b/packages/nx/src/utils/strip-source-code.ts index 9597957f4d16c..a22ecbdd49d9f 100644 --- a/packages/nx/src/utils/strip-source-code.ts +++ b/packages/nx/src/utils/strip-source-code.ts @@ -1,6 +1,6 @@ import type { Scanner } from 'typescript'; -let SyntaxKind; +let SyntaxKind: typeof import('typescript').SyntaxKind; export function stripSourceCode(scanner: Scanner, contents: string): string { if (!SyntaxKind) { SyntaxKind = require('typescript').SyntaxKind; @@ -68,7 +68,8 @@ export function stripSourceCode(scanner: Scanner, contents: string): string { } if ( token === SyntaxKind.OpenBraceToken || - token === SyntaxKind.AsteriskToken + token === SyntaxKind.AsteriskToken || + token === SyntaxKind.TypeKeyword ) { start = potentialStart; }