feat(js): add getSourceNodes to nrwl/js package (#15497)
This commit is contained in:
parent
47c9a7e148
commit
c82ba4e9d4
@ -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;
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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';
|
||||
|
||||
19
packages/js/src/utils/typescript/get-source-nodes.ts
Normal file
19
packages/js/src/utils/typescript/get-source-nodes.ts
Normal 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;
|
||||
}
|
||||
@ -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 = [];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user