diff --git a/packages/angular/src/generators/utils/storybook-ast/storybook-inputs.ts b/packages/angular/src/generators/utils/storybook-ast/storybook-inputs.ts index 7ed20c2b6f..24fabadbc3 100644 --- a/packages/angular/src/generators/utils/storybook-ast/storybook-inputs.ts +++ b/packages/angular/src/generators/utils/storybook-ast/storybook-inputs.ts @@ -1,6 +1,6 @@ import type { Tree } from '@nrwl/devkit'; import { findNodes } from 'nx/src/utils/typescript'; -import { getSourceNodes } from '@nrwl/workspace/src/utilities/typescript/get-source-nodes'; +import { getSourceNodes } from '@nrwl/js'; import type { PropertyDeclaration } from 'typescript'; import { getTsSourceFile } from '../../../utils/nx-devkit/ast-utils'; import { ensureTypescript } from '@nrwl/js/src/utils/typescript/ensure-typescript'; @@ -8,6 +8,7 @@ import { ensureTypescript } from '@nrwl/js/src/utils/typescript/ensure-typescrip let tsModule: typeof import('typescript'); export type KnobType = 'text' | 'boolean' | 'number' | 'select'; + export interface InputDescriptor { name: string; type: KnobType; diff --git a/packages/angular/src/utils/nx-devkit/ast-utils.ts b/packages/angular/src/utils/nx-devkit/ast-utils.ts index 71219ba8ca..bc5f74b282 100644 --- a/packages/angular/src/utils/nx-devkit/ast-utils.ts +++ b/packages/angular/src/utils/nx-devkit/ast-utils.ts @@ -1,6 +1,6 @@ import type * as ts from 'typescript'; import { findNodes } from 'nx/src/utils/typescript'; -import { getSourceNodes } from '@nrwl/workspace/src/utilities/typescript/get-source-nodes'; +import { getSourceNodes } from '@nrwl/js'; import { dirname, join } from 'path'; import { names, readProjectConfiguration, Tree } from '@nrwl/devkit'; import { diff --git a/packages/js/src/index.ts b/packages/js/src/index.ts index 3602ce2de9..07ff1e6c97 100644 --- a/packages/js/src/index.ts +++ b/packages/js/src/index.ts @@ -1,6 +1,7 @@ export * from './utils/typescript/load-ts-transformers'; export * from './utils/typescript/print-diagnostics'; export * from './utils/typescript/run-type-check'; +export * from './utils/typescript/get-source-nodes'; export * from './utils/compiler-helper-dependency'; export * from './utils/typescript/ts-config'; export * from './utils/typescript/create-ts-config'; diff --git a/packages/js/src/utils/typescript/get-source-nodes.ts b/packages/js/src/utils/typescript/get-source-nodes.ts new file mode 100644 index 0000000000..b3b321e60d --- /dev/null +++ b/packages/js/src/utils/typescript/get-source-nodes.ts @@ -0,0 +1,19 @@ +import type * as ts from 'typescript'; + +export function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[] { + const nodes: ts.Node[] = [sourceFile]; + const result = []; + + while (nodes.length > 0) { + const node = nodes.shift(); + + if (node) { + result.push(node); + if (node.getChildCount(sourceFile) >= 0) { + nodes.unshift(...node.getChildren()); + } + } + } + + return result; +} diff --git a/packages/workspace/src/utilities/typescript/get-source-nodes.ts b/packages/workspace/src/utilities/typescript/get-source-nodes.ts index b3b321e60d..227c0c0f3a 100644 --- a/packages/workspace/src/utilities/typescript/get-source-nodes.ts +++ b/packages/workspace/src/utilities/typescript/get-source-nodes.ts @@ -1,5 +1,8 @@ import type * as ts from 'typescript'; +/** + * @deprecated This function will be removed from @nrwl/workspace in version 17. Prefer importing from @nrwl/js. + */ export function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[] { const nodes: ts.Node[] = [sourceFile]; const result = [];