feat(js): add getSourceNodes to nrwl/js package (#15497)

This commit is contained in:
Colum Ferry 2023-03-08 23:27:07 +00:00 committed by GitHub
parent 47c9a7e148
commit c82ba4e9d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 2 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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';

View File

@ -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;
}

View File

@ -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 = [];