feat(linter): add internal rules to prevent deep nx imports (#16430)
This commit is contained in:
parent
bef152d94e
commit
bc0bbb0b4b
@ -9,7 +9,18 @@
|
|||||||
"extends": [],
|
"extends": [],
|
||||||
"rules": {
|
"rules": {
|
||||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||||
"no-restricted-imports": ["error", "create-nx-workspace"]
|
"no-restricted-imports": ["error", "create-nx-workspace"],
|
||||||
|
"@typescript-eslint/no-restricted-imports": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"patterns": [
|
||||||
|
{
|
||||||
|
"group": ["nx/src/plugins/js*"],
|
||||||
|
"message": "Imports from 'nx/src/plugins/js' are not allowed. Use '@nx/js' instead"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"overrides": [
|
"overrides": [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { DependencyType } from '@nx/devkit';
|
|||||||
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/plugins/js/project-graph/build-dependencies/target-project-locator';
|
import { TargetProjectLocator } from '@nx/js/src/internal';
|
||||||
import enforceModuleBoundaries, {
|
import enforceModuleBoundaries, {
|
||||||
RULE_NAME as enforceModuleBoundariesRuleName,
|
RULE_NAME as enforceModuleBoundariesRuleName,
|
||||||
} from '../../src/rules/enforce-module-boundaries';
|
} from '../../src/rules/enforce-module-boundaries';
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import {
|
|||||||
ProjectGraphProjectNode,
|
ProjectGraphProjectNode,
|
||||||
readJsonFile,
|
readJsonFile,
|
||||||
} from '@nx/devkit';
|
} from '@nx/devkit';
|
||||||
import { findNodes } from 'nx/src/plugins/js/utils/typescript';
|
import { findNodes } from '@nx/js';
|
||||||
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');
|
||||||
|
|||||||
@ -12,11 +12,14 @@ export * from './utils/package-json/update-package-json';
|
|||||||
export { libraryGenerator } from './generators/library/library';
|
export { libraryGenerator } from './generators/library/library';
|
||||||
export { initGenerator } from './generators/init/init';
|
export { initGenerator } from './generators/init/init';
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||||
export {
|
export {
|
||||||
createLockFile,
|
createLockFile,
|
||||||
getLockFileName,
|
getLockFileName,
|
||||||
} from 'nx/src/plugins/js/lock-file/lock-file';
|
} from 'nx/src/plugins/js/lock-file/lock-file';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||||
export { createPackageJson } from 'nx/src/plugins/js/package-json/create-package-json';
|
export { createPackageJson } from 'nx/src/plugins/js/package-json/create-package-json';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||||
export {
|
export {
|
||||||
findNodes,
|
findNodes,
|
||||||
getRootTsConfigPath,
|
getRootTsConfigPath,
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||||
export { resolveModuleByImport } from 'nx/src/plugins/js/utils/typescript';
|
export { resolveModuleByImport } from 'nx/src/plugins/js/utils/typescript';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||||
export {
|
export {
|
||||||
registerTsProject,
|
registerTsProject,
|
||||||
registerTsConfigPaths,
|
registerTsConfigPaths,
|
||||||
} from 'nx/src/plugins/js/utils/register';
|
} from 'nx/src/plugins/js/utils/register';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||||
export { TargetProjectLocator } from 'nx/src/plugins/js/project-graph/build-dependencies/target-project-locator';
|
export { TargetProjectLocator } from 'nx/src/plugins/js/project-graph/build-dependencies/target-project-locator';
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||||
import {
|
import {
|
||||||
createLockFile,
|
createLockFile,
|
||||||
getLockFileName,
|
getLockFileName,
|
||||||
} from 'nx/src/plugins/js/lock-file/lock-file';
|
} from 'nx/src/plugins/js/lock-file/lock-file';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||||
import { createPackageJson } from 'nx/src/plugins/js/package-json/create-package-json';
|
import { createPackageJson } from 'nx/src/plugins/js/package-json/create-package-json';
|
||||||
import {
|
import {
|
||||||
ExecutorContext,
|
ExecutorContext,
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import type { Tree } from '@nx/devkit';
|
|||||||
import type * as ts from 'typescript';
|
import type * as ts from 'typescript';
|
||||||
// TODO(colum): replace when https://github.com/nrwl/nx/pull/15497 is merged
|
// TODO(colum): replace when https://github.com/nrwl/nx/pull/15497 is merged
|
||||||
import { getSourceNodes } from '@nx/workspace/src/utilities/typescript';
|
import { getSourceNodes } from '@nx/workspace/src/utilities/typescript';
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||||
import { findNodes } from 'nx/src/plugins/js/utils/typescript';
|
import { findNodes } from 'nx/src/plugins/js/utils/typescript';
|
||||||
import { ensureTypescript } from './ensure-typescript';
|
import { ensureTypescript } from './ensure-typescript';
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,12 @@
|
|||||||
"message": "TypeScript is an optional dependency for Nx. If you need to use it, make sure its installed first with ensureTypescript.",
|
"message": "TypeScript is an optional dependency for Nx. If you need to use it, make sure its installed first with ensureTypescript.",
|
||||||
"allowTypeImports": true
|
"allowTypeImports": true
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"patterns": [
|
||||||
|
{
|
||||||
|
"group": ["nx/*"],
|
||||||
|
"message": "Circular import in 'nx' found. Use relative path."
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -50,7 +50,7 @@ import {
|
|||||||
ExecutorsJson,
|
ExecutorsJson,
|
||||||
TaskGraphExecutor,
|
TaskGraphExecutor,
|
||||||
} from '../config/misc-interfaces';
|
} from '../config/misc-interfaces';
|
||||||
import { readPluginPackageJson } from 'nx/src/utils/nx-plugin';
|
import { readPluginPackageJson } from '../utils/nx-plugin';
|
||||||
|
|
||||||
class WrappedWorkspaceNodeModulesArchitectHost extends WorkspaceNodeModulesArchitectHost {
|
class WrappedWorkspaceNodeModulesArchitectHost extends WorkspaceNodeModulesArchitectHost {
|
||||||
private workspaces = new Workspaces(this.root);
|
private workspaces = new Workspaces(this.root);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { basename, dirname, join, relative } from 'path';
|
import { basename, join, relative } from 'path';
|
||||||
import {
|
import {
|
||||||
ProjectConfiguration,
|
ProjectConfiguration,
|
||||||
ProjectsConfigurations,
|
ProjectsConfigurations,
|
||||||
@ -18,7 +18,7 @@ import { readJson, writeJson } from './json';
|
|||||||
import { PackageJson } from '../../utils/package-json';
|
import { PackageJson } from '../../utils/package-json';
|
||||||
import { readNxJson } from './nx-json';
|
import { readNxJson } from './nx-json';
|
||||||
import { output } from '../../utils/output';
|
import { output } from '../../utils/output';
|
||||||
import { getNxRequirePaths } from 'nx/src/utils/installation-directory';
|
import { getNxRequirePaths } from '../../utils/installation-directory';
|
||||||
|
|
||||||
export { readNxJson, updateNxJson } from './nx-json';
|
export { readNxJson, updateNxJson } from './nx-json';
|
||||||
export {
|
export {
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import {
|
|||||||
import { dirname } from 'path';
|
import { dirname } from 'path';
|
||||||
import { readJson, writeJson } from '../../generators/utils/json';
|
import { readJson, writeJson } from '../../generators/utils/json';
|
||||||
import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available';
|
import { formatChangedFilesWithPrettierIfAvailable } from '../../generators/internal-utils/format-changed-files-with-prettier-if-available';
|
||||||
import { getNxRequirePaths } from 'nx/src/utils/installation-directory';
|
import { getNxRequirePaths } from '../../utils/installation-directory';
|
||||||
|
|
||||||
export default async function (tree: Tree) {
|
export default async function (tree: Tree) {
|
||||||
const nxJson = readNxJson(tree);
|
const nxJson = readNxJson(tree);
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
import {
|
import {
|
||||||
addProjectConfiguration,
|
addProjectConfiguration,
|
||||||
getProjects,
|
|
||||||
readNxJson,
|
readNxJson,
|
||||||
readProjectConfiguration,
|
readProjectConfiguration,
|
||||||
} from '../../generators/utils/project-configuration';
|
} from '../../generators/utils/project-configuration';
|
||||||
import { Tree } from '../../generators/tree';
|
|
||||||
|
|
||||||
import update from './update-depends-on-to-tokens';
|
import update from './update-depends-on-to-tokens';
|
||||||
import { updateJson, writeJson } from 'nx/src/devkit-exports';
|
import { updateJson, writeJson } from '../../generators/utils/json';
|
||||||
import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace';
|
import { createTreeWithEmptyWorkspace } from '../../generators/testing-utils/create-tree-with-empty-workspace';
|
||||||
|
|
||||||
describe('update-depends-on-to-tokens', () => {
|
describe('update-depends-on-to-tokens', () => {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { parsePnpmLockfile, stringifyPnpmLockfile } from './pnpm-parser';
|
|||||||
import { ProjectGraph } from '../../../config/project-graph';
|
import { ProjectGraph } from '../../../config/project-graph';
|
||||||
import { vol } from 'memfs';
|
import { vol } from 'memfs';
|
||||||
import { pruneProjectGraph } from './project-graph-pruning';
|
import { pruneProjectGraph } from './project-graph-pruning';
|
||||||
import { ProjectGraphBuilder } from 'nx/src/project-graph/project-graph-builder';
|
import { ProjectGraphBuilder } from '../../../project-graph/project-graph-builder';
|
||||||
|
|
||||||
jest.mock('fs', () => require('memfs').fs);
|
jest.mock('fs', () => require('memfs').fs);
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { ProjectGraphProjectNode } from 'nx/src/config/project-graph';
|
import { ProjectGraphProjectNode } from '../../config/project-graph';
|
||||||
import { normalizeImplicitDependencies } from './workspace-projects';
|
import { normalizeImplicitDependencies } from './workspace-projects';
|
||||||
|
|
||||||
describe('workspace-projects', () => {
|
describe('workspace-projects', () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user