Skip to content

Commit

Permalink
cleanup(core): create more meaningful file structure in nx package (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Mar 31, 2022
1 parent 5b34fa4 commit 428106f
Show file tree
Hide file tree
Showing 190 changed files with 719 additions and 769 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -192,7 +192,7 @@ Please follow the following guidelines:

- Make sure unit tests pass (`nx affected --target=test`)
- Target a specific project with: `nx run proj:test` (i.e. `nx run angular:test` to target `packages/angular`)
- Target a specific unit test file (i.e. `packages/angular/src/utils/ast-utils.spec.ts`) with `npx jest angular/src/utils/ast-utils` or `npx jest packages/angular/src/utils/ast-utils`
- Target a specific unit test file (i.e. `packages/angular/src/utils/ast-command-line-utils.spec.ts`) with `npx jest angular/src/utils/ast-utils` or `npx jest packages/angular/src/utils/ast-utils`
- For more options on running tests - check `npx jest --help` or visit [jestjs.io](https://jestjs.io/)
- Debug with `node --inspect-brk ./node_modules/jest/bin/jest.js build/packages/angular/src/utils/ast-utils.spec.js`
- Make sure e2e tests pass (this can take a while, so you can always let CI check those) (`yarn e2e`)
Expand Down
2 changes: 1 addition & 1 deletion e2e/add-nx-to-monorepo/src/add-nx-to-monorepo.test.ts
Expand Up @@ -7,7 +7,7 @@ import {
getPackageManagerCommand,
getSelectedPackageManager,
} from '@nrwl/e2e/utils';
import { Workspaces } from 'nx/src/shared/workspace';
import { Workspaces } from 'nx/src/config/workspaces';

describe('add-nx-to-monorepo', () => {
const packageManagerCommand = getPackageManagerCommand({
Expand Down
2 changes: 1 addition & 1 deletion e2e/utils/index.ts
Expand Up @@ -28,7 +28,7 @@ import { promisify } from 'util';
import chalk = require('chalk');
import isCI = require('is-ci');
import treeKill = require('tree-kill');
import { Workspaces } from '../../packages/nx/src/shared/workspace';
import { Workspaces } from '../../packages/nx/src/config/workspaces';
import { PackageManager } from 'nx/src/utils/package-manager';

export function detectPackageManager(dir: string = ''): PackageManager {
Expand Down
2 changes: 1 addition & 1 deletion e2e/workspace-core/src/aux-commands.test.ts
Expand Up @@ -42,7 +42,7 @@ describe('workspace-generator', () => {
const workspace = uniq('workspace');

updateFile(
'tools/utils/utils.ts',
'tools/utils/command-line-utils.ts',
`
export const noop = () => {}
`
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/generators/library/library.spec.ts
Expand Up @@ -9,7 +9,7 @@ import {
} from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';
import { Linter } from '@nrwl/linter';
import { toNewFormat } from 'nx/src/shared/workspace';
import { toNewFormat } from 'nx/src/config/workspaces';
import { createApp } from '../../utils/nx-devkit/testing';
import { UnitTestRunner } from '../../utils/test-runners';
import {
Expand Down
5 changes: 2 additions & 3 deletions packages/angular/src/utils/mfe/with-module-federation.spec.ts
@@ -1,11 +1,10 @@
jest.mock('fs');
jest.mock('@nrwl/devkit');
jest.mock('@nrwl/workspace/src/utilities/typescript');
jest.mock('nx/src/core/file-utils');
jest.mock('nx/src/shared/workspace');
jest.mock('nx/src/project-graph/file-utils');
import * as graph from '@nrwl/devkit';
import * as typescriptUtils from '@nrwl/workspace/src/utilities/typescript';
import * as workspace from 'nx/src/core/file-utils';
import * as workspace from 'nx/src/project-graph/file-utils';
import * as fs from 'fs';

import { withModuleFederation } from './with-module-federation';
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/utils/mfe/with-module-federation.ts
Expand Up @@ -15,7 +15,7 @@ import {
readTsConfig,
} from '@nrwl/workspace/src/utilities/typescript';
import { ParsedCommandLine } from 'typescript';
import { readWorkspaceJson } from 'nx/src/core/file-utils';
import { readWorkspaceJson } from 'nx/src/project-graph/file-utils';
import ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin');

export type MFERemotes = string[] | [remoteName: string, remoteUrl: string][];
Expand Down
32 changes: 19 additions & 13 deletions packages/devkit/index.ts
Expand Up @@ -12,7 +12,7 @@
/**
* @category Tree
*/
export type { Tree, FileChange } from 'nx/src/shared/tree';
export type { Tree, FileChange } from 'nx/src/config/tree';

/**
* @category Workspace
Expand All @@ -23,18 +23,24 @@ export type {
TargetConfiguration,
ProjectConfiguration,
ProjectType,
Workspace,
} from 'nx/src/config/workspace-json-project-json';

/**
* @category Workspace
*/
export type {
Generator,
GeneratorCallback,
Executor,
ExecutorContext,
TaskGraphExecutor,
Workspace,
} from 'nx/src/shared/workspace';
} from 'nx/src/config/misc-interfaces';

/**
* @category Workspace
*/
export { Workspaces } from 'nx/src/shared/workspace';
export { Workspaces } from 'nx/src/config/workspaces';

export type {
NxPlugin,
Expand All @@ -44,7 +50,7 @@ export type {
/**
* @category Workspace
*/
export type { Task, TaskGraph } from 'nx/src/shared/tasks';
export type { Task, TaskGraph } from 'nx/src/config/task-graph';

/**
* @category Workspace
Expand All @@ -55,7 +61,7 @@ export type {
NxJsonConfiguration,
NxJsonProjectConfiguration,
NxAffectedConfig,
} from 'nx/src/shared/nx';
} from 'nx/src/config/nx-json';

/**
* @category Logger
Expand Down Expand Up @@ -160,17 +166,17 @@ export type {
ProjectGraphProjectNode,
ProjectGraphExternalNode,
ProjectGraphProcessorContext,
} from 'nx/src/shared/project-graph';
} from 'nx/src/config/project-graph';

/**
* @category Project Graph
*/
export { DependencyType } from 'nx/src/shared/project-graph';
export { DependencyType } from 'nx/src/config/project-graph';

/**
* @category Project Graph
*/
export { ProjectGraphBuilder } from 'nx/src/core/project-graph/project-graph-builder';
export { ProjectGraphBuilder } from 'nx/src/project-graph/project-graph-builder';

/**
* @category Utils
Expand Down Expand Up @@ -270,19 +276,19 @@ export { workspaceRoot, appRootPath } from 'nx/src/utils/app-root';
/**
* @category Utils
*/
export { reverse } from 'nx/src/core/project-graph/operators';
export { reverse } from 'nx/src/project-graph/operators';
/**
* @category Utils
*/
export {
createProjectGraphAsync,
readCachedProjectGraph,
} from 'nx/src/core/project-graph/project-graph';
} from 'nx/src/project-graph/project-graph';

/**
* @category Utils
*/
export { readNxJson, workspaceLayout } from 'nx/src/core/file-utils';
export { readNxJson, workspaceLayout } from 'nx/src/project-graph/file-utils';

/**
* @category Utils
Expand All @@ -301,7 +307,7 @@ export {
/**
* @category Utils
*/
export { Hash, Hasher } from 'nx/src/core/hasher/hasher';
export { Hash, Hasher } from 'nx/src/hasher/hasher';

/**
* @category Utils
Expand Down
4 changes: 2 additions & 2 deletions packages/devkit/src/executors/read-target-options.ts
@@ -1,6 +1,6 @@
import type { Target } from 'nx/src/command-line/run';
import type { ExecutorContext } from 'nx/src/shared/workspace';
import { Workspaces } from 'nx/src/shared/workspace';
import type { ExecutorContext } from 'nx/src/config/misc-interfaces';
import { Workspaces } from 'nx/src/config/workspaces';
import { combineOptionsForExecutor } from 'nx/src/utils/params';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/src/generators/format-files.ts
@@ -1,4 +1,4 @@
import type { Tree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/config/tree';
import * as path from 'path';
import type * as Prettier from 'prettier';
import { getWorkspacePath } from '../utils/get-workspace-layout';
Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/src/generators/generate-files.spec.ts
@@ -1,4 +1,4 @@
import type { Tree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/config/tree';
import { createTree } from '../tests/create-tree';
import { generateFiles } from './generate-files';
import { join } from 'path';
Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/src/generators/generate-files.ts
@@ -1,6 +1,6 @@
import { readFileSync, readdirSync, statSync } from 'fs';
import * as path from 'path';
import type { Tree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/config/tree';
import { logger } from 'nx/src/utils/logger';

const binaryExts = new Set([
Expand Down
4 changes: 2 additions & 2 deletions packages/devkit/src/generators/project-configuration.spec.ts
@@ -1,5 +1,5 @@
import { Tree } from 'nx/src/shared/tree';
import { ProjectConfiguration } from 'nx/src/shared/workspace';
import { Tree } from 'nx/src/config/tree';
import { ProjectConfiguration } from 'nx/src/config/workspace-json-project-json';

import { createTreeWithEmptyWorkspace } from '../tests/create-tree-with-empty-workspace';
import { readJson, updateJson } from '../utils/json';
Expand Down
14 changes: 8 additions & 6 deletions packages/devkit/src/generators/project-configuration.ts
Expand Up @@ -2,12 +2,9 @@ import {
buildWorkspaceConfigurationFromGlobs,
deduplicateProjectFiles,
globForProjectFiles,
ProjectConfiguration,
RawWorkspaceJsonConfiguration,
reformattedWorkspaceJsonOrNull,
toNewFormat,
WorkspaceJsonConfiguration,
} from 'nx/src/shared/workspace';
} from 'nx/src/config/workspaces';
import { basename, dirname, relative } from 'path';

import {
Expand All @@ -16,9 +13,14 @@ import {
} from '../utils/get-workspace-layout';
import { readJson, updateJson, writeJson } from '../utils/json';

import type { Tree } from 'nx/src/shared/tree';
import type { NxJsonConfiguration } from 'nx/src/shared/nx';
import type { Tree } from 'nx/src/config/tree';
import type { NxJsonConfiguration } from 'nx/src/config/nx-json';
import { joinPathFragments } from 'nx/src/utils/path';
import {
ProjectConfiguration,
RawWorkspaceJsonConfiguration,
WorkspaceJsonConfiguration,
} from 'nx/src/config/workspace-json-project-json';

export type WorkspaceConfiguration = Omit<
WorkspaceJsonConfiguration,
Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/src/generators/to-js.ts
@@ -1,4 +1,4 @@
import type { Tree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/config/tree';

/**
* Rename and transpile any new typescript files created to javascript files
Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/src/generators/update-ts-configs-to-js.ts
@@ -1,4 +1,4 @@
import type { Tree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/config/tree';
import { updateJson } from '../utils/json';

export function updateTsConfigsToJs(
Expand Down
@@ -1,5 +1,5 @@
import { createTree } from '../tests/create-tree';
import type { Tree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/config/tree';
import { visitNotIgnoredFiles } from './visit-not-ignored-files';

describe('visitNotIgnoredFiles', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/src/generators/visit-not-ignored-files.ts
@@ -1,4 +1,4 @@
import type { Tree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/config/tree';
import ignore, { Ignore } from 'ignore';
import { join, relative, sep } from 'path';

Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/src/tasks/install-packages-task.ts
@@ -1,4 +1,4 @@
import type { Tree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/config/tree';
import { execSync } from 'child_process';
import { join } from 'path';
import {
Expand Down
4 changes: 2 additions & 2 deletions packages/devkit/src/tests/create-tree-with-empty-workspace.ts
@@ -1,5 +1,5 @@
import { FsTree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/shared/tree';
import { FsTree } from 'nx/src/config/tree';
import type { Tree } from 'nx/src/config/tree';

/**
* Creates a host for testing.
Expand Down
4 changes: 2 additions & 2 deletions packages/devkit/src/tests/create-tree.ts
@@ -1,5 +1,5 @@
import { FsTree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/shared/tree';
import { FsTree } from 'nx/src/config/tree';
import type { Tree } from 'nx/src/config/tree';

/**
* Creates a host for testing.
Expand Down
4 changes: 2 additions & 2 deletions packages/devkit/src/utils/convert-nx-executor.ts
@@ -1,6 +1,6 @@
import type { Observable } from 'rxjs';
import type { Executor, ExecutorContext } from 'nx/src/shared/workspace';
import { Workspaces } from 'nx/src/shared/workspace';
import { Workspaces } from 'nx/src/config/workspaces';
import { Executor, ExecutorContext } from 'nx/src/config/misc-interfaces';

/**
* Convert an Nx Executor into an Angular Devkit Builder
Expand Down
4 changes: 2 additions & 2 deletions packages/devkit/src/utils/get-workspace-layout.ts
@@ -1,9 +1,9 @@
import { RawWorkspaceJsonConfiguration } from 'nx/src/shared/workspace';
import { RawWorkspaceJsonConfiguration } from 'nx/src/config/workspace-json-project-json';

import { readNxJson } from '../generators/project-configuration';
import { readJson } from './json';

import type { Tree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/config/tree';

/**
* Returns workspace defaults. It includes defaults folders for apps and libs,
Expand Down
10 changes: 3 additions & 7 deletions packages/devkit/src/utils/invoke-nx-generator.ts
@@ -1,11 +1,7 @@
import { logger, stripIndent } from 'nx/src/utils/logger';
import type { FileChange, Tree, TreeWriteOptions } from 'nx/src/shared/tree';
import {
Generator,
GeneratorCallback,
toNewFormat,
toOldFormatOrNull,
} from 'nx/src/shared/workspace';
import type { FileChange, Tree, TreeWriteOptions } from 'nx/src/config/tree';
import { toNewFormat, toOldFormatOrNull } from 'nx/src/config/workspaces';
import { Generator, GeneratorCallback } from 'nx/src/config/misc-interfaces';
import { parseJson, serializeJson } from 'nx/src/utils/json';
import { join, relative } from 'path';

Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/src/utils/json.ts
@@ -1,4 +1,4 @@
import type { Tree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/config/tree';
import { parseJson, serializeJson } from 'nx/src/utils/json';
import type { JsonParseOptions, JsonSerializeOptions } from 'nx/src/utils/json';

Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/src/utils/move-dir.ts
@@ -1,4 +1,4 @@
import { Tree } from 'nx/src/shared/tree';
import { Tree } from 'nx/src/config/tree';
import { relative } from 'path';
import { visitNotIgnoredFiles } from '../generators/visit-not-ignored-files';
import { normalizePath } from 'nx/src/utils/path';
Expand Down
2 changes: 1 addition & 1 deletion packages/devkit/src/utils/package-json.spec.ts
@@ -1,4 +1,4 @@
import type { Tree } from 'nx/src/shared/tree';
import type { Tree } from 'nx/src/config/tree';
import { readJson, writeJson } from './json';
import { addDependenciesToPackageJson } from './package-json';
import { createTree } from '../tests/create-tree';
Expand Down
4 changes: 2 additions & 2 deletions packages/devkit/src/utils/package-json.ts
@@ -1,7 +1,7 @@
import { readJson, updateJson } from './json';
import { installPackagesTask } from '../tasks/install-packages-task';
import type { Tree } from 'nx/src/shared/tree';
import type { GeneratorCallback } from 'nx/src/shared/workspace';
import type { Tree } from 'nx/src/config/tree';
import { GeneratorCallback } from 'nx/src/config/misc-interfaces';

/**
* Add Dependencies and Dev Dependencies to package.json
Expand Down
Expand Up @@ -6,7 +6,7 @@ import { vol } from 'memfs';
import enforceModuleBoundaries, {
RULE_NAME as enforceModuleBoundariesRuleName,
} from '../../src/rules/enforce-module-boundaries';
import { TargetProjectLocator } from 'nx/src/core/target-project-locator';
import { TargetProjectLocator } from 'nx/src/utils/target-project-locator';
import { mapProjectGraphFiles } from '@nrwl/workspace/src/utils/runtime-lint-utils';

jest.mock('fs', () => require('memfs').fs);
Expand Down
Expand Up @@ -34,7 +34,7 @@ import {
TSESTree,
} from '@typescript-eslint/experimental-utils';
import { createESLintRule } from '../utils/create-eslint-rule';
import { TargetProjectLocator } from 'nx/src/core/target-project-locator';
import { TargetProjectLocator } from 'nx/src/utils/target-project-locator';
import {
checkCircularPath,
findFilesInCircularPath,
Expand Down
2 changes: 1 addition & 1 deletion packages/jest/src/utils/config/get-jest-projects.spec.ts
@@ -1,5 +1,5 @@
import { getJestProjects } from './get-jest-projects';
import * as Workspace from 'nx/src/core/file-utils';
import * as Workspace from 'nx/src/project-graph/file-utils';
import type { WorkspaceJsonConfiguration } from '@nrwl/devkit';

describe('getJestProjects', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/jest/src/utils/config/get-jest-projects.ts
@@ -1,6 +1,6 @@
import { dirname, join } from 'path';
import type { WorkspaceJsonConfiguration } from '@nrwl/devkit';
import { readWorkspaceConfig } from 'nx/src/core/file-utils';
import { readWorkspaceConfig } from 'nx/src/project-graph/file-utils';

const JEST_RUNNER_TOKEN = '@nrwl/jest:jest';

Expand Down
2 changes: 1 addition & 1 deletion packages/nx/bin/init.ts
@@ -1,4 +1,4 @@
import { createProjectGraphAsync } from '../src/core/project-graph/project-graph';
import { createProjectGraphAsync } from '../src/project-graph/project-graph';

(async () => {
try {
Expand Down

0 comments on commit 428106f

Please sign in to comment.