Skip to content

Commit c82ba4e

Browse files
authoredMar 8, 2023
feat(js): add getSourceNodes to nrwl/js package (#15497)
1 parent 47c9a7e commit c82ba4e

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed
 

‎packages/angular/src/generators/utils/storybook-ast/storybook-inputs.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { Tree } from '@nrwl/devkit';
22
import { findNodes } from 'nx/src/utils/typescript';
3-
import { getSourceNodes } from '@nrwl/workspace/src/utilities/typescript/get-source-nodes';
3+
import { getSourceNodes } from '@nrwl/js';
44
import type { PropertyDeclaration } from 'typescript';
55
import { getTsSourceFile } from '../../../utils/nx-devkit/ast-utils';
66
import { ensureTypescript } from '@nrwl/js/src/utils/typescript/ensure-typescript';
77

88
let tsModule: typeof import('typescript');
99

1010
export type KnobType = 'text' | 'boolean' | 'number' | 'select';
11+
1112
export interface InputDescriptor {
1213
name: string;
1314
type: KnobType;

‎packages/angular/src/utils/nx-devkit/ast-utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type * as ts from 'typescript';
22
import { findNodes } from 'nx/src/utils/typescript';
3-
import { getSourceNodes } from '@nrwl/workspace/src/utilities/typescript/get-source-nodes';
3+
import { getSourceNodes } from '@nrwl/js';
44
import { dirname, join } from 'path';
55
import { names, readProjectConfiguration, Tree } from '@nrwl/devkit';
66
import {

‎packages/js/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export * from './utils/typescript/load-ts-transformers';
22
export * from './utils/typescript/print-diagnostics';
33
export * from './utils/typescript/run-type-check';
4+
export * from './utils/typescript/get-source-nodes';
45
export * from './utils/compiler-helper-dependency';
56
export * from './utils/typescript/ts-config';
67
export * from './utils/typescript/create-ts-config';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type * as ts from 'typescript';
2+
3+
export function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[] {
4+
const nodes: ts.Node[] = [sourceFile];
5+
const result = [];
6+
7+
while (nodes.length > 0) {
8+
const node = nodes.shift();
9+
10+
if (node) {
11+
result.push(node);
12+
if (node.getChildCount(sourceFile) >= 0) {
13+
nodes.unshift(...node.getChildren());
14+
}
15+
}
16+
}
17+
18+
return result;
19+
}

‎packages/workspace/src/utilities/typescript/get-source-nodes.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type * as ts from 'typescript';
22

3+
/**
4+
* @deprecated This function will be removed from @nrwl/workspace in version 17. Prefer importing from @nrwl/js.
5+
*/
36
export function getSourceNodes(sourceFile: ts.SourceFile): ts.Node[] {
47
const nodes: ts.Node[] = [sourceFile];
58
const result = [];

0 commit comments

Comments
 (0)