feat(core): move runtime-lint-utils to eslint plugin (#13222)
This commit is contained in:
parent
e971ffba71
commit
ab6f62a9b5
@ -21,7 +21,7 @@ import {
|
|||||||
stripIndents,
|
stripIndents,
|
||||||
workspaceRoot,
|
workspaceRoot,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import { mapProjectGraphFiles } from '@nrwl/workspace/src/utils/runtime-lint-utils';
|
import { mapProjectGraphFiles } from 'nx/src/utils/target-project-locator';
|
||||||
import { lstatSync, mkdirSync, writeFileSync } from 'fs';
|
import { lstatSync, mkdirSync, writeFileSync } from 'fs';
|
||||||
import { dirname, join, relative } from 'path';
|
import { dirname, join, relative } from 'path';
|
||||||
import type { BrowserBuilderSchema } from '../src/builders/webpack-browser/webpack-browser.impl';
|
import type { BrowserBuilderSchema } from '../src/builders/webpack-browser/webpack-browser.impl';
|
||||||
@ -74,7 +74,7 @@ ${e.stack ? e.stack : e}`
|
|||||||
const buildTarget = getBuildableTarget(ctContext);
|
const buildTarget = getBuildableTarget(ctContext);
|
||||||
|
|
||||||
if (!buildTarget.project && !graph.nodes?.[buildTarget.project]?.data) {
|
if (!buildTarget.project && !graph.nodes?.[buildTarget.project]?.data) {
|
||||||
throw new Error(stripIndents`Unable to find project configuration for build target.
|
throw new Error(stripIndents`Unable to find project configuration for build target.
|
||||||
Project Name? ${buildTarget.project}
|
Project Name? ${buildTarget.project}
|
||||||
Has project config? ${!!graph.nodes?.[buildTarget.project]?.data}`);
|
Has project config? ${!!graph.nodes?.[buildTarget.project]?.data}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import type { Tree } from '@nrwl/devkit';
|
import type { Tree } from '@nrwl/devkit';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import type { PropertyAssignment } from 'typescript';
|
import type { PropertyAssignment } from 'typescript';
|
||||||
import { SyntaxKind } from 'typescript';
|
import { SyntaxKind } from 'typescript';
|
||||||
import {
|
import {
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import {
|
|||||||
stripIndents,
|
stripIndents,
|
||||||
visitNotIgnoredFiles,
|
visitNotIgnoredFiles,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import { tsquery } from '@phenomnomnominal/tsquery';
|
import { tsquery } from '@phenomnomnominal/tsquery';
|
||||||
import { extname } from 'path';
|
import { extname } from 'path';
|
||||||
import type {
|
import type {
|
||||||
|
|||||||
@ -1,8 +1,7 @@
|
|||||||
import type { Tree } from '@nrwl/devkit';
|
import type { Tree } from '@nrwl/devkit';
|
||||||
import {
|
import { getSourceNodes } from '@nrwl/workspace/src/utilities/typescript';
|
||||||
findNodes,
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
getSourceNodes,
|
|
||||||
} from '@nrwl/workspace/src/utilities/typescript';
|
|
||||||
import type { PropertyDeclaration } from 'typescript';
|
import type { PropertyDeclaration } from 'typescript';
|
||||||
import { SyntaxKind } from 'typescript';
|
import { SyntaxKind } from 'typescript';
|
||||||
import { getTsSourceFile } from '../../../utils/nx-devkit/ast-utils';
|
import { getTsSourceFile } from '../../../utils/nx-devkit/ast-utils';
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript/find-nodes';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import { getSourceNodes } from '@nrwl/workspace/src/utilities/typescript/get-source-nodes';
|
import { getSourceNodes } from '@nrwl/workspace/src/utilities/typescript/get-source-nodes';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { names, readProjectConfiguration, Tree } from '@nrwl/devkit';
|
import { names, readProjectConfiguration, Tree } from '@nrwl/devkit';
|
||||||
|
|||||||
@ -8,8 +8,8 @@ import {
|
|||||||
TargetConfiguration,
|
TargetConfiguration,
|
||||||
workspaceRoot,
|
workspaceRoot,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import { mapProjectGraphFiles } from '@nrwl/workspace/src/utils/runtime-lint-utils';
|
|
||||||
import { readProjectsConfigurationFromProjectGraph } from 'nx/src/project-graph/project-graph';
|
import { readProjectsConfigurationFromProjectGraph } from 'nx/src/project-graph/project-graph';
|
||||||
|
import { mapProjectGraphFiles } from 'nx/src/utils/target-project-locator';
|
||||||
import { dirname, extname, join, relative } from 'path';
|
import { dirname, extname, join, relative } from 'path';
|
||||||
import { lstatSync } from 'fs';
|
import { lstatSync } from 'fs';
|
||||||
|
|
||||||
@ -98,8 +98,8 @@ export function getProjectConfigByPath(
|
|||||||
!graph.nodes[componentTestingProjectName]?.data
|
!graph.nodes[componentTestingProjectName]?.data
|
||||||
) {
|
) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
stripIndents`Unable to find the project configuration that includes ${normalizedPathFromWorkspaceRoot}.
|
stripIndents`Unable to find the project configuration that includes ${normalizedPathFromWorkspaceRoot}.
|
||||||
Found project name? ${componentTestingProjectName}.
|
Found project name? ${componentTestingProjectName}.
|
||||||
Graph has data? ${!!graph.nodes[componentTestingProjectName]?.data}`
|
Graph has data? ${!!graph.nodes[componentTestingProjectName]?.data}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
"rules": {
|
"rules": {
|
||||||
"no-restricted-imports": [
|
"no-restricted-imports": [
|
||||||
"error",
|
"error",
|
||||||
"@nrwl/workspace",
|
|
||||||
"@angular-devkit/core",
|
"@angular-devkit/core",
|
||||||
"@angular-devkit/architect",
|
"@angular-devkit/architect",
|
||||||
"@angular-devkit/schematics"
|
"@angular-devkit/schematics"
|
||||||
|
|||||||
@ -34,7 +34,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@nrwl/devkit": "file:../devkit",
|
"@nrwl/devkit": "file:../devkit",
|
||||||
"@nrwl/workspace": "file:../workspace",
|
|
||||||
"@typescript-eslint/utils": "^5.36.1",
|
"@typescript-eslint/utils": "^5.36.1",
|
||||||
"chalk": "4.1.0",
|
"chalk": "4.1.0",
|
||||||
"confusing-browser-globals": "^1.0.9",
|
"confusing-browser-globals": "^1.0.9",
|
||||||
|
|||||||
@ -1,13 +1,15 @@
|
|||||||
import type { FileData, ProjectGraph } from '@nrwl/devkit';
|
import type { FileData, ProjectGraph } from '@nrwl/devkit';
|
||||||
import { DependencyType } from '@nrwl/devkit';
|
import { DependencyType } from '@nrwl/devkit';
|
||||||
import { mapProjectGraphFiles } from '@nrwl/workspace/src/utils/runtime-lint-utils';
|
|
||||||
import * as parser from '@typescript-eslint/parser';
|
import * as parser from '@typescript-eslint/parser';
|
||||||
import { TSESLint } from '@typescript-eslint/utils';
|
import { TSESLint } from '@typescript-eslint/utils';
|
||||||
import { vol } from 'memfs';
|
import { vol } from 'memfs';
|
||||||
import { TargetProjectLocator } from 'nx/src/utils/target-project-locator';
|
import {
|
||||||
|
TargetProjectLocator,
|
||||||
|
mapProjectGraphFiles,
|
||||||
|
} from 'nx/src/utils/target-project-locator';
|
||||||
import enforceModuleBoundaries, {
|
import enforceModuleBoundaries, {
|
||||||
RULE_NAME as enforceModuleBoundariesRuleName,
|
RULE_NAME as enforceModuleBoundariesRuleName,
|
||||||
} from '../../src/rules/enforce-module-boundaries';
|
} from './enforce-module-boundaries';
|
||||||
|
|
||||||
jest.mock('fs', () => require('memfs').fs);
|
jest.mock('fs', () => require('memfs').fs);
|
||||||
|
|
||||||
|
|||||||
@ -5,11 +5,11 @@ import {
|
|||||||
ProjectGraphProjectNode,
|
ProjectGraphProjectNode,
|
||||||
workspaceRoot,
|
workspaceRoot,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import { isRelativePath } from '@nrwl/workspace/src/utilities/fileutils';
|
import { isRelativePath } from 'nx/src/utils/fileutils';
|
||||||
import {
|
import {
|
||||||
checkCircularPath,
|
checkCircularPath,
|
||||||
findFilesInCircularPath,
|
findFilesInCircularPath,
|
||||||
} from '@nrwl/workspace/src/utils/graph-utils';
|
} from '../utils/graph-utils';
|
||||||
import {
|
import {
|
||||||
DepConstraint,
|
DepConstraint,
|
||||||
findConstraintsFor,
|
findConstraintsFor,
|
||||||
@ -31,7 +31,7 @@ import {
|
|||||||
matchImportWithWildcard,
|
matchImportWithWildcard,
|
||||||
onlyLoadChildren,
|
onlyLoadChildren,
|
||||||
stringifyTags,
|
stringifyTags,
|
||||||
} from '@nrwl/workspace/src/utils/runtime-lint-utils';
|
} from '../utils/runtime-lint-utils';
|
||||||
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
|
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
|
||||||
import { TargetProjectLocator } from 'nx/src/utils/target-project-locator';
|
import { TargetProjectLocator } from 'nx/src/utils/target-project-locator';
|
||||||
import { basename, dirname, relative } from 'path';
|
import { basename, dirname, relative } from 'path';
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
findSourceProject,
|
findSourceProject,
|
||||||
getSourceFilePath,
|
getSourceFilePath,
|
||||||
} from '@nrwl/workspace/src/utils/runtime-lint-utils';
|
} from '../utils/runtime-lint-utils';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { registerTsProject } from 'nx/src/utils/register';
|
import { registerTsProject } from 'nx/src/utils/register';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import {
|
|||||||
ProjectGraphProjectNode,
|
ProjectGraphProjectNode,
|
||||||
readJsonFile,
|
readJsonFile,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import { existsSync, readFileSync } from 'fs';
|
import { existsSync, readFileSync } from 'fs';
|
||||||
import { dirname } from 'path';
|
import { dirname } from 'path';
|
||||||
import ts = require('typescript');
|
import ts = require('typescript');
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import { readCachedProjectGraph, readNxJson } from '@nrwl/devkit';
|
import { readCachedProjectGraph, readNxJson } from '@nrwl/devkit';
|
||||||
import {
|
import {
|
||||||
isTerminalRun,
|
|
||||||
MappedProjectGraph,
|
|
||||||
mapProjectGraphFiles,
|
mapProjectGraphFiles,
|
||||||
} from '@nrwl/workspace/src/utils/runtime-lint-utils';
|
MappedProjectGraph,
|
||||||
|
} from 'nx/src/utils/target-project-locator';
|
||||||
|
import { isTerminalRun } from './runtime-lint-utils';
|
||||||
import * as chalk from 'chalk';
|
import * as chalk from 'chalk';
|
||||||
|
|
||||||
export function ensureGlobalProjectGraph(ruleName: string) {
|
export function ensureGlobalProjectGraph(ruleName: string) {
|
||||||
|
|||||||
@ -14,11 +14,11 @@ import { join } from 'path';
|
|||||||
import { getPath, pathExists } from './graph-utils';
|
import { getPath, pathExists } from './graph-utils';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { readFileIfExisting } from 'nx/src/project-graph/file-utils';
|
import { readFileIfExisting } from 'nx/src/project-graph/file-utils';
|
||||||
import { TargetProjectLocator } from 'nx/src/utils/target-project-locator';
|
import {
|
||||||
|
TargetProjectLocator,
|
||||||
export type MappedProjectGraph<T = any> = ProjectGraph<T> & {
|
MappedProjectGraph,
|
||||||
allFiles: Record<string, string>;
|
removeExt,
|
||||||
};
|
} from 'nx/src/utils/target-project-locator';
|
||||||
|
|
||||||
export type Deps = { [projectName: string]: ProjectGraphDependency[] };
|
export type Deps = { [projectName: string]: ProjectGraphDependency[] };
|
||||||
export type DepConstraint = {
|
export type DepConstraint = {
|
||||||
@ -70,10 +70,6 @@ function hasTag(proj: ProjectGraphProjectNode, tag: string) {
|
|||||||
return tag === '*' || (proj.data.tags || []).indexOf(tag) > -1;
|
return tag === '*' || (proj.data.tags || []).indexOf(tag) > -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeExt(file: string): string {
|
|
||||||
return file.replace(/(?<!(^|\/))\.[^/.]+$/, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
export function matchImportWithWildcard(
|
export function matchImportWithWildcard(
|
||||||
// This may or may not contain wildcards ("*")
|
// This may or may not contain wildcards ("*")
|
||||||
allowableImport: string,
|
allowableImport: string,
|
||||||
@ -353,28 +349,6 @@ export function hasBuildExecutor(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function mapProjectGraphFiles<T>(
|
|
||||||
projectGraph: ProjectGraph<T>
|
|
||||||
): MappedProjectGraph | null {
|
|
||||||
if (!projectGraph) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
const allFiles: Record<string, string> = {};
|
|
||||||
Object.entries(
|
|
||||||
projectGraph.nodes as Record<string, ProjectGraphProjectNode>
|
|
||||||
).forEach(([name, node]) => {
|
|
||||||
node.data.files.forEach(({ file }) => {
|
|
||||||
const fileName = removeExt(file);
|
|
||||||
allFiles[fileName] = name;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
...projectGraph,
|
|
||||||
allFiles,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const ESLINT_REGEX = /node_modules.*[\/\\]eslint$/;
|
const ESLINT_REGEX = /node_modules.*[\/\\]eslint$/;
|
||||||
const JEST_REGEX = /node_modules\/.bin\/jest$/; // when we run unit tests in jest
|
const JEST_REGEX = /node_modules\/.bin\/jest$/; // when we run unit tests in jest
|
||||||
const NRWL_CLI_REGEX = /nx[\/\\]bin[\/\\]run-executor\.js$/;
|
const NRWL_CLI_REGEX = /nx[\/\\]bin[\/\\]run-executor\.js$/;
|
||||||
@ -1,4 +1,4 @@
|
|||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import { ChangeType, StringChange } from '@nrwl/devkit';
|
import { ChangeType, StringChange } from '@nrwl/devkit';
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
|
||||||
import type { NextBuildBuilderOptions } from '../../../utils/types';
|
import type { NextBuildBuilderOptions } from '../../../utils/types';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
|
|
||||||
export function createNextConfigFile(
|
export function createNextConfigFile(
|
||||||
options: NextBuildBuilderOptions,
|
options: NextBuildBuilderOptions,
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { isRelativePath, readJsonFile } from './fileutils';
|
|||||||
import { dirname, join, posix } from 'path';
|
import { dirname, join, posix } from 'path';
|
||||||
import { workspaceRoot } from './workspace-root';
|
import { workspaceRoot } from './workspace-root';
|
||||||
import {
|
import {
|
||||||
|
ProjectGraph,
|
||||||
ProjectGraphExternalNode,
|
ProjectGraphExternalNode,
|
||||||
ProjectGraphProjectNode,
|
ProjectGraphProjectNode,
|
||||||
} from '../config/project-graph';
|
} from '../config/project-graph';
|
||||||
@ -198,6 +199,11 @@ function filterRootExternalDependencies(
|
|||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapps the project root paths to the project name
|
||||||
|
* @param nodes
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
export function createProjectRootMappings(
|
export function createProjectRootMappings(
|
||||||
nodes: Record<string, ProjectGraphProjectNode>
|
nodes: Record<string, ProjectGraphProjectNode>
|
||||||
) {
|
) {
|
||||||
@ -212,6 +218,47 @@ export function createProjectRootMappings(
|
|||||||
return projectRootMappings;
|
return projectRootMappings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type MappedProjectGraph<T = any> = ProjectGraph<T> & {
|
||||||
|
allFiles: Record<string, string>;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strips the file extension from the file path
|
||||||
|
* @param file
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function removeExt(file: string): string {
|
||||||
|
return file.replace(/(?<!(^|\/))\.[^/.]+$/, '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the project graph to a format that makes it easier to find the project
|
||||||
|
* based on the file path.
|
||||||
|
* @param projectGraph
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function mapProjectGraphFiles<T>(
|
||||||
|
projectGraph: ProjectGraph<T>
|
||||||
|
): MappedProjectGraph | null {
|
||||||
|
if (!projectGraph) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const allFiles: Record<string, string> = {};
|
||||||
|
Object.entries(
|
||||||
|
projectGraph.nodes as Record<string, ProjectGraphProjectNode>
|
||||||
|
).forEach(([name, node]) => {
|
||||||
|
node.data.files.forEach(({ file }) => {
|
||||||
|
const fileName = removeExt(file);
|
||||||
|
allFiles[fileName] = name;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
...projectGraph,
|
||||||
|
allFiles,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locates a project in projectRootMap based on a file within it
|
* Locates a project in projectRootMap based on a file within it
|
||||||
* @param filePath path that is inside of projectName
|
* @param filePath path that is inside of projectName
|
||||||
|
|||||||
@ -104,3 +104,38 @@ export function getRootTsConfigPath(): string | null {
|
|||||||
|
|
||||||
return tsConfigFileName ? join(workspaceRoot, tsConfigFileName) : null;
|
return tsConfigFileName ? join(workspaceRoot, tsConfigFileName) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function findNodes(
|
||||||
|
node: ts.Node,
|
||||||
|
kind: ts.SyntaxKind | ts.SyntaxKind[],
|
||||||
|
max = Infinity
|
||||||
|
): ts.Node[] {
|
||||||
|
if (!node || max == 0) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const arr: ts.Node[] = [];
|
||||||
|
const hasMatch = Array.isArray(kind)
|
||||||
|
? kind.includes(node.kind)
|
||||||
|
: node.kind === kind;
|
||||||
|
if (hasMatch) {
|
||||||
|
arr.push(node);
|
||||||
|
max--;
|
||||||
|
}
|
||||||
|
if (max > 0) {
|
||||||
|
for (const child of node.getChildren()) {
|
||||||
|
findNodes(child, kind, max).forEach((node) => {
|
||||||
|
if (max > 0) {
|
||||||
|
arr.push(node);
|
||||||
|
}
|
||||||
|
max--;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (max <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import { ChangeType, StringChange } from '@nrwl/devkit';
|
import { ChangeType, StringChange } from '@nrwl/devkit';
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import {
|
|||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
|
|
||||||
import ts = require('typescript');
|
import ts = require('typescript');
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript/find-nodes';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
|
|
||||||
export async function migrateToWebPack5(tree: Tree) {
|
export async function migrateToWebPack5(tree: Tree) {
|
||||||
allReactProjectsWithStorybookConfiguration(tree).forEach((project) => {
|
allReactProjectsWithStorybookConfiguration(tree).forEach((project) => {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import {
|
|||||||
Tree,
|
Tree,
|
||||||
formatFiles,
|
formatFiles,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript/find-nodes';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
|
|
||||||
export async function update(tree: Tree) {
|
export async function update(tree: Tree) {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import { ChangeType, StringChange } from '@nrwl/devkit';
|
import { ChangeType, StringChange } from '@nrwl/devkit';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript/find-nodes';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import {
|
import {
|
||||||
addImport,
|
addImport,
|
||||||
findClosestOpening,
|
findClosestOpening,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript/find-nodes';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import {
|
import {
|
||||||
ChangeType,
|
ChangeType,
|
||||||
logger,
|
logger,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { ExecutorContext, joinPathFragments, logger } from '@nrwl/devkit';
|
import { ExecutorContext, joinPathFragments, logger } from '@nrwl/devkit';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript/find-nodes';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import { existsSync, readFileSync } from 'fs';
|
import { existsSync, readFileSync } from 'fs';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
@ -58,9 +58,9 @@ function reactWebpack5Check(options: CommonNxStorybookConfig) {
|
|||||||
It looks like you use Webpack 5 but your Storybook setup is not configured to leverage that
|
It looks like you use Webpack 5 but your Storybook setup is not configured to leverage that
|
||||||
and thus falls back to Webpack 4.
|
and thus falls back to Webpack 4.
|
||||||
Make sure you upgrade your Storybook config to use Webpack 5.
|
Make sure you upgrade your Storybook config to use Webpack 5.
|
||||||
|
|
||||||
- https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#upgrade
|
- https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#upgrade
|
||||||
|
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {
|
|||||||
applyChangesToString,
|
applyChangesToString,
|
||||||
ChangeType,
|
ChangeType,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript/find-nodes';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import { getTsSourceFile } from '../../utils/utilities';
|
import { getTsSourceFile } from '../../utils/utilities';
|
||||||
import ts = require('typescript');
|
import ts = require('typescript');
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {
|
|||||||
import { joinPathFragments, writeJson } from '@nrwl/devkit';
|
import { joinPathFragments, writeJson } from '@nrwl/devkit';
|
||||||
import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing';
|
import { createTreeWithEmptyV1Workspace } from '@nrwl/devkit/testing';
|
||||||
import { storybookVersion } from '@nrwl/storybook';
|
import { storybookVersion } from '@nrwl/storybook';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utils/ast-utils';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import { SyntaxKind } from 'typescript';
|
import { SyntaxKind } from 'typescript';
|
||||||
import { nxVersion } from '../../../utils/versions';
|
import { nxVersion } from '../../../utils/versions';
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import {
|
|||||||
visitNotIgnoredFiles,
|
visitNotIgnoredFiles,
|
||||||
} from '@nrwl/devkit';
|
} from '@nrwl/devkit';
|
||||||
import { fileExists } from '@nrwl/workspace/src/utilities/fileutils';
|
import { fileExists } from '@nrwl/workspace/src/utilities/fileutils';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript/find-nodes';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import { join, normalize } from 'path';
|
import { join, normalize } from 'path';
|
||||||
import { SyntaxKind } from 'typescript';
|
import { SyntaxKind } from 'typescript';
|
||||||
import { getTsSourceFile } from '../../../utils/utilities';
|
import { getTsSourceFile } from '../../../utils/utilities';
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import { StorybookConfig } from '../executors/models';
|
|||||||
import { constants, copyFileSync, mkdtempSync, statSync } from 'fs';
|
import { constants, copyFileSync, mkdtempSync, statSync } from 'fs';
|
||||||
import { tmpdir } from 'os';
|
import { tmpdir } from 'os';
|
||||||
import { basename, join, sep } from 'path';
|
import { basename, join, sep } from 'path';
|
||||||
import { findNodes } from '@nrwl/workspace/src/utilities/typescript/find-nodes';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import ts = require('typescript');
|
import ts = require('typescript');
|
||||||
|
|
||||||
export const Constants = {
|
export const Constants = {
|
||||||
|
|||||||
@ -21,6 +21,7 @@ export {
|
|||||||
readPackageJson,
|
readPackageJson,
|
||||||
} from 'nx/src/project-graph/file-utils';
|
} from 'nx/src/project-graph/file-utils';
|
||||||
export { ProjectGraphCache } from 'nx/src/project-graph/nx-deps-cache';
|
export { ProjectGraphCache } from 'nx/src/project-graph/nx-deps-cache';
|
||||||
|
export { findNodes } from 'nx/src/utils/typescript';
|
||||||
export {
|
export {
|
||||||
readJsonInTree,
|
readJsonInTree,
|
||||||
updateJsonInTree,
|
updateJsonInTree,
|
||||||
@ -34,7 +35,6 @@ export {
|
|||||||
getProjectConfig,
|
getProjectConfig,
|
||||||
addParameterToConstructor,
|
addParameterToConstructor,
|
||||||
createOrUpdate,
|
createOrUpdate,
|
||||||
findNodes,
|
|
||||||
updatePackageJsonDependencies,
|
updatePackageJsonDependencies,
|
||||||
readWorkspace,
|
readWorkspace,
|
||||||
renameSyncInTree,
|
renameSyncInTree,
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import {
|
|||||||
import { getImportPath } from 'nx/src/utils/path';
|
import { getImportPath } from 'nx/src/utils/path';
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import { getRootTsConfigPathInTree } from '../../../utilities/typescript';
|
import { getRootTsConfigPathInTree } from '../../../utilities/typescript';
|
||||||
import { findNodes } from '../../../utilities/typescript/find-nodes';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import { NormalizedSchema } from '../schema';
|
import { NormalizedSchema } from '../schema';
|
||||||
import { normalizeSlashes } from './utils';
|
import { normalizeSlashes } from './utils';
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import type { Tree } from '@nrwl/devkit';
|
import type { Tree } from '@nrwl/devkit';
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import { getSourceNodes } from './typescript';
|
import { getSourceNodes } from './typescript';
|
||||||
import { findNodes } from './typescript/find-nodes';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
|
|
||||||
function nodesByPosition(first: ts.Node, second: ts.Node): number {
|
function nodesByPosition(first: ts.Node, second: ts.Node): number {
|
||||||
return first.getStart() - second.getStart();
|
return first.getStart() - second.getStart();
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import { dirname, join } from 'path';
|
|||||||
import type * as ts from 'typescript';
|
import type * as ts from 'typescript';
|
||||||
export { compileTypeScript } from './typescript/compilation';
|
export { compileTypeScript } from './typescript/compilation';
|
||||||
export type { TypeScriptCompilationOptions } from './typescript/compilation';
|
export type { TypeScriptCompilationOptions } from './typescript/compilation';
|
||||||
export { findNodes } from './typescript/find-nodes';
|
|
||||||
export { getSourceNodes } from './typescript/get-source-nodes';
|
export { getSourceNodes } from './typescript/get-source-nodes';
|
||||||
|
|
||||||
const normalizedAppRoot = workspaceRoot.replace(/\\/g, '/');
|
const normalizedAppRoot = workspaceRoot.replace(/\\/g, '/');
|
||||||
|
|||||||
@ -1,36 +0,0 @@
|
|||||||
import * as ts from 'typescript';
|
|
||||||
|
|
||||||
export function findNodes(
|
|
||||||
node: ts.Node,
|
|
||||||
kind: ts.SyntaxKind | ts.SyntaxKind[],
|
|
||||||
max = Infinity
|
|
||||||
): ts.Node[] {
|
|
||||||
if (!node || max == 0) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const arr: ts.Node[] = [];
|
|
||||||
const hasMatch = Array.isArray(kind)
|
|
||||||
? kind.includes(node.kind)
|
|
||||||
: node.kind === kind;
|
|
||||||
if (hasMatch) {
|
|
||||||
arr.push(node);
|
|
||||||
max--;
|
|
||||||
}
|
|
||||||
if (max > 0) {
|
|
||||||
for (const child of node.getChildren()) {
|
|
||||||
findNodes(child, kind, max).forEach((node) => {
|
|
||||||
if (max > 0) {
|
|
||||||
arr.push(node);
|
|
||||||
}
|
|
||||||
max--;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (max <= 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
@ -18,17 +18,12 @@ import {
|
|||||||
Tree,
|
Tree,
|
||||||
} from '@angular-devkit/schematics';
|
} from '@angular-devkit/schematics';
|
||||||
import * as ts from 'typescript';
|
import * as ts from 'typescript';
|
||||||
import {
|
import { parseJson, serializeJson, FileData } from '@nrwl/devkit';
|
||||||
parseJson,
|
|
||||||
ProjectConfiguration,
|
|
||||||
serializeJson,
|
|
||||||
FileData,
|
|
||||||
} from '@nrwl/devkit';
|
|
||||||
import { getWorkspacePath } from './cli-config-utils';
|
import { getWorkspacePath } from './cli-config-utils';
|
||||||
import { extname, join, normalize, Path } from '@angular-devkit/core';
|
import { extname, join, normalize, Path } from '@angular-devkit/core';
|
||||||
import type { NxJsonConfiguration, ProjectsConfigurations } from '@nrwl/devkit';
|
import type { NxJsonConfiguration } from '@nrwl/devkit';
|
||||||
import { addInstallTask } from './rules/add-install-task';
|
import { addInstallTask } from './rules/add-install-task';
|
||||||
import { findNodes } from '../utilities/typescript/find-nodes';
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import { getSourceNodes } from '../utilities/typescript/get-source-nodes';
|
import { getSourceNodes } from '../utilities/typescript/get-source-nodes';
|
||||||
|
|
||||||
function nodesByPosition(first: ts.Node, second: ts.Node): number {
|
function nodesByPosition(first: ts.Node, second: ts.Node): number {
|
||||||
@ -71,7 +66,6 @@ export function sortObjectByKeys(obj: unknown) {
|
|||||||
}, {});
|
}, {});
|
||||||
}
|
}
|
||||||
|
|
||||||
export { findNodes } from '../utilities/typescript/find-nodes';
|
|
||||||
export { getSourceNodes } from '../utilities/typescript/get-source-nodes';
|
export { getSourceNodes } from '../utilities/typescript/get-source-nodes';
|
||||||
|
|
||||||
export interface Change {
|
export interface Change {
|
||||||
|
|||||||
@ -7,7 +7,8 @@ import {
|
|||||||
} from '@angular-devkit/schematics';
|
} from '@angular-devkit/schematics';
|
||||||
import { getWorkspace } from '../workspace';
|
import { getWorkspace } from '../workspace';
|
||||||
import { visitNotIgnoredFiles } from './visit-not-ignored-files';
|
import { visitNotIgnoredFiles } from './visit-not-ignored-files';
|
||||||
import { findNodes, insert, ReplaceChange } from '../ast-utils';
|
import { insert, ReplaceChange } from '../ast-utils';
|
||||||
|
import { findNodes } from 'nx/src/utils/typescript';
|
||||||
import { normalize } from '@angular-devkit/core';
|
import { normalize } from '@angular-devkit/core';
|
||||||
|
|
||||||
export interface PackageNameMapping {
|
export interface PackageNameMapping {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user