From 3b21f4dfeaed2058b1d773c95526ffa6761c251e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Jona=C5=A1?= Date: Wed, 30 Mar 2022 15:15:20 +0200 Subject: [PATCH] fix(core): switch from appRootPath to workspaceRoot (#9600) --- .../src/executors/utilities/tailwindcss.ts | 6 +++--- .../generators/move/lib/update-ng-package.ts | 4 ++-- .../opt-out-testbed-teardown.spec.ts.snap | 4 ++-- .../opt-out-testbed-teardown.spec.ts | 6 +++--- packages/angular/src/utils/mfe/mfe-webpack.ts | 8 +++++--- .../src/configs/typescript.ts | 4 ++-- packages/eslint-plugin-nx/src/constants.ts | 4 ++-- .../rules/enforce-module-boundaries.spec.ts | 2 -- .../src/rules/enforce-module-boundaries.ts | 4 ++-- .../eslint-plugin-nx/src/utils/ast-utils.ts | 4 ++-- packages/next/plugins/with-nx.ts | 4 ++-- packages/next/src/utils/generate-globs.ts | 4 ++-- packages/node/src/utils/node.config.spec.ts | 2 +- packages/node/src/utils/node.config.ts | 4 ++-- .../src/utils/testing-utils/nx-project.ts | 4 ++-- packages/nx/src/adapter/compat.ts | 8 ++++---- packages/nx/src/command-line/dep-graph.ts | 6 +++--- packages/nx/src/command-line/format.ts | 4 ++-- packages/nx/src/command-line/list.ts | 4 ++-- packages/nx/src/command-line/nx-commands.ts | 4 ++-- packages/nx/src/command-line/report.spec.ts | 3 --- packages/nx/src/command-line/report.ts | 6 +++--- .../src/command-line/workspace-generators.ts | 4 ++-- .../affected-project-graph.spec.ts | 1 - packages/nx/src/core/file-utils.ts | 18 ++++++++--------- packages/nx/src/core/hasher/file-hasher.ts | 4 ++-- .../src/core/hasher/git-based-file-hasher.ts | 10 +++++----- packages/nx/src/core/hasher/hasher.spec.ts | 1 - packages/nx/src/core/hasher/hasher.ts | 10 +++++----- ...explicit-package-json-dependencies.spec.ts | 1 - .../explicit-project-dependencies.spec.ts | 1 - .../implict-project-dependencies.spec.ts | 1 - .../project-graph/build-nodes/npm-packages.ts | 4 ++-- .../build-nodes/workspace-projects.ts | 4 ++-- .../project-graph/build-project-graph.spec.ts | 1 - .../core/project-graph/build-project-graph.ts | 4 ++-- .../project-graph/daemon/client/client.ts | 6 +++--- .../project-graph/daemon/server/server.ts | 14 ++++++------- .../daemon/server/shutdown-utils.ts | 4 ++-- .../project-graph/daemon/server/watcher.ts | 20 +++++++++---------- .../src/core/target-project-locator.spec.ts | 1 - .../nx/src/core/target-project-locator.ts | 4 ++-- packages/nx/src/shared/workspace.ts | 8 ++++---- .../nx/src/tasks-runner/batch/run-batch.ts | 8 ++++---- packages/nx/src/tasks-runner/cache.ts | 4 ++-- .../forked-process-task-runner.ts | 10 +++++----- packages/nx/src/tasks-runner/run-command.ts | 4 ++-- .../nx/src/tasks-runner/task-orchestrator.ts | 4 ++-- packages/nx/src/utils/cache-directory.ts | 6 +++--- packages/nx/src/utils/nx-plugin.ts | 20 +++++++++---------- .../src/utils/plugins/plugin-capabilities.ts | 4 ++-- packages/nx/src/utils/typescript.ts | 10 +++++----- .../react-native/plugins/metro-resolver.ts | 8 ++++---- .../react-native/plugins/with-nx-metro.ts | 4 ++-- packages/react/plugins/storybook/index.ts | 12 +++++------ .../move/lib/update-project-root-files.ts | 8 ++++---- .../move/lib/update-storybook-config.ts | 14 +++++++++---- .../nxEnforceModuleBoundariesRule.spec.ts | 1 - .../tslint/nxEnforceModuleBoundariesRule.ts | 4 ++-- .../workspace/src/utilities/generate-globs.ts | 6 +++--- .../utilities/plugins/plugin-capabilities.ts | 4 ++-- .../workspace/src/utilities/typescript.ts | 10 +++++----- packages/workspace/src/utils/app-root.ts | 2 +- .../src/utils/rules/format-files.spec.ts | 10 +++++----- .../workspace/src/utils/rules/format-files.ts | 6 +++--- .../workspace/src/utils/runtime-lint-utils.ts | 4 ++-- 66 files changed, 189 insertions(+), 194 deletions(-) diff --git a/packages/angular/src/executors/utilities/tailwindcss.ts b/packages/angular/src/executors/utilities/tailwindcss.ts index 03c027b4e0771..82f9c2e154011 100644 --- a/packages/angular/src/executors/utilities/tailwindcss.ts +++ b/packages/angular/src/executors/utilities/tailwindcss.ts @@ -1,5 +1,5 @@ import { logger } from '@nrwl/devkit'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import { existsSync } from 'fs'; import { join, relative } from 'path'; import * as postcssImport from 'postcss-import'; @@ -27,7 +27,7 @@ export function getTailwindSetup( if (!tailwindConfigPath) { // Try to find TailwindCSS configuration file in the project or workspace root. const tailwindConfigFile = 'tailwind.config.js'; - for (const path of [basePath, appRootPath]) { + for (const path of [basePath, workspaceRoot]) { const fullPath = join(path, tailwindConfigFile); if (existsSync(fullPath)) { tailwindConfigPath = fullPath; @@ -46,7 +46,7 @@ export function getTailwindSetup( tailwindPackagePath = require.resolve('tailwindcss'); } catch { const relativeTailwindConfigPath = relative( - appRootPath, + workspaceRoot, tailwindConfigPath ); logger.warn( diff --git a/packages/angular/src/generators/move/lib/update-ng-package.ts b/packages/angular/src/generators/move/lib/update-ng-package.ts index 1de18a2c5a0a1..18a241f834845 100644 --- a/packages/angular/src/generators/move/lib/update-ng-package.ts +++ b/packages/angular/src/generators/move/lib/update-ng-package.ts @@ -1,5 +1,5 @@ import { readProjectConfiguration, Tree, updateJson } from '@nrwl/devkit'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import { getNewProjectName } from '@nrwl/workspace/src/generators/move/lib/utils'; import { join, relative } from 'path'; import { Schema } from '../schema'; @@ -17,7 +17,7 @@ export function updateNgPackage(tree: Tree, schema: Schema): void { return; } - const rootOffset = relative(join(appRootPath, project.root), appRootPath); + const rootOffset = relative(join(workspaceRoot, project.root), workspaceRoot); let output = `dist/${project.root}`; if (project.targets?.build?.outputs?.length > 0) { output = project.targets.build.outputs[0]; diff --git a/packages/angular/src/migrations/update-13-2-0/__snapshots__/opt-out-testbed-teardown.spec.ts.snap b/packages/angular/src/migrations/update-13-2-0/__snapshots__/opt-out-testbed-teardown.spec.ts.snap index 9e5ca4aff4ed1..9d15b98c93929 100644 --- a/packages/angular/src/migrations/update-13-2-0/__snapshots__/opt-out-testbed-teardown.spec.ts.snap +++ b/packages/angular/src/migrations/update-13-2-0/__snapshots__/opt-out-testbed-teardown.spec.ts.snap @@ -45,7 +45,7 @@ exports[`opt-out-testbed-teardown migration update configureTestingModule in tes declarations: [AppComponent], teardown: { destroyAfterEach: false } }).compileComponents(); - + expect(true).toBe(true); }); }); @@ -121,7 +121,7 @@ exports[`opt-out-testbed-teardown migration update configureTestingModule in tes declarations: [AppComponent], teardown: { destroyAfterEach: false } }).compileComponents(); - + expect(true).toBe(true); }); }); diff --git a/packages/angular/src/migrations/update-13-2-0/opt-out-testbed-teardown.spec.ts b/packages/angular/src/migrations/update-13-2-0/opt-out-testbed-teardown.spec.ts index c05ab3e1c5daa..1db38ea54fd74 100644 --- a/packages/angular/src/migrations/update-13-2-0/opt-out-testbed-teardown.spec.ts +++ b/packages/angular/src/migrations/update-13-2-0/opt-out-testbed-teardown.spec.ts @@ -7,7 +7,7 @@ describe('opt-out-testbed-teardown migration', () => { beforeEach(() => { tree = createTreeWithEmptyWorkspace(2); - jest.doMock('@nrwl/devkit', () => ({ appRootPath: '' })); + jest.doMock('@nrwl/devkit', () => ({ workspaceRoot: '' })); }); it('should warn when the jestConfig property is not configured', async () => { @@ -668,7 +668,7 @@ describe('opt-out-testbed-teardown migration', () => { await TestBed.configureTestingModule({ declarations: [AppComponent], }).compileComponents(); - + expect(true).toBe(true); }); }); @@ -728,7 +728,7 @@ describe('opt-out-testbed-teardown migration', () => { await TestBed.configureTestingModule({ declarations: [AppComponent], }).compileComponents(); - + expect(true).toBe(true); }); }); diff --git a/packages/angular/src/utils/mfe/mfe-webpack.ts b/packages/angular/src/utils/mfe/mfe-webpack.ts index 2b3fa8f2e8c44..f9be25a621785 100644 --- a/packages/angular/src/utils/mfe/mfe-webpack.ts +++ b/packages/angular/src/utils/mfe/mfe-webpack.ts @@ -1,6 +1,6 @@ import { existsSync, readFileSync } from 'fs'; import { NormalModuleReplacementPlugin } from 'webpack'; -import { normalizePath, joinPathFragments, appRootPath } from '@nrwl/devkit'; +import { normalizePath, joinPathFragments, workspaceRoot } from '@nrwl/devkit'; import { dirname } from 'path'; import { ParsedCommandLine } from 'typescript'; import { @@ -40,7 +40,9 @@ export function shareWorkspaceLibraries( const pathMappings: { name: string; path: string }[] = []; for (const [key, paths] of Object.entries(tsconfigPathAliases)) { if (libraries && libraries.includes(key)) { - const pathToLib = normalizePath(joinPathFragments(appRootPath, paths[0])); + const pathToLib = normalizePath( + joinPathFragments(workspaceRoot, paths[0]) + ); pathMappings.push({ name: key, path: pathToLib, @@ -84,7 +86,7 @@ export function shareWorkspaceLibraries( export function sharePackages( packages: string[] ): Record { - const pkgJsonPath = joinPathFragments(appRootPath, 'package.json'); + const pkgJsonPath = joinPathFragments(workspaceRoot, 'package.json'); if (!existsSync(pkgJsonPath)) { throw new Error( 'NX MFE: Could not find root package.json to determine dependency versions.' diff --git a/packages/eslint-plugin-nx/src/configs/typescript.ts b/packages/eslint-plugin-nx/src/configs/typescript.ts index e019afcec4d13..9d45c250b9b72 100644 --- a/packages/eslint-plugin-nx/src/configs/typescript.ts +++ b/packages/eslint-plugin-nx/src/configs/typescript.ts @@ -1,4 +1,4 @@ -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; /** * This configuration is intended to be applied to ALL .ts and .tsx files @@ -12,7 +12,7 @@ export default { parserOptions: { ecmaVersion: 2020, sourceType: 'module', - tsconfigRootDir: appRootPath, + tsconfigRootDir: workspaceRoot, }, plugins: ['@typescript-eslint'], extends: [ diff --git a/packages/eslint-plugin-nx/src/constants.ts b/packages/eslint-plugin-nx/src/constants.ts index a5b242782f322..16dcca79f219a 100644 --- a/packages/eslint-plugin-nx/src/constants.ts +++ b/packages/eslint-plugin-nx/src/constants.ts @@ -1,7 +1,7 @@ -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import { join } from 'path'; -export const WORKSPACE_PLUGIN_DIR = join(appRootPath, 'tools/eslint-rules'); +export const WORKSPACE_PLUGIN_DIR = join(workspaceRoot, 'tools/eslint-rules'); /** * We add a namespace so that we mitigate the risk of rule name collisions as much as diff --git a/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.spec.ts b/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.spec.ts index 7852ec9ecb1b8..c76ef258d5787 100644 --- a/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.spec.ts +++ b/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.spec.ts @@ -13,12 +13,10 @@ jest.mock('fs', () => require('memfs').fs); jest.mock('@nrwl/devkit', () => ({ ...jest.requireActual('@nrwl/devkit'), - appRootPath: '/root', workspaceRoot: '/root', })); jest.mock('nx/src/utils/app-root', () => ({ - appRootPath: '/root', workspaceRoot: '/root', })); diff --git a/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts b/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts index 33d80697c3791..c8b5fcbde3c79 100644 --- a/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts +++ b/packages/eslint-plugin-nx/src/rules/enforce-module-boundaries.ts @@ -1,5 +1,5 @@ import { - appRootPath, + workspaceRoot, joinPathFragments, normalizePath, ProjectGraphExternalNode, @@ -146,7 +146,7 @@ export default createESLintRule({ * Globally cached info about workspace */ const projectPath = normalizePath( - (global as any).projectPath || appRootPath + (global as any).projectPath || workspaceRoot ); /** * Only reuse graph when running from terminal diff --git a/packages/eslint-plugin-nx/src/utils/ast-utils.ts b/packages/eslint-plugin-nx/src/utils/ast-utils.ts index b26166707fb67..9be4ff0ccf83d 100644 --- a/packages/eslint-plugin-nx/src/utils/ast-utils.ts +++ b/packages/eslint-plugin-nx/src/utils/ast-utils.ts @@ -5,11 +5,11 @@ import { existsSync, readFileSync } from 'fs'; import { dirname } from 'path'; import ts = require('typescript'); import { logger } from '@nrwl/devkit'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; function tryReadBaseJson() { try { - return readJsonFile(joinPathFragments(appRootPath, 'tsconfig.base.json')); + return readJsonFile(joinPathFragments(workspaceRoot, 'tsconfig.base.json')); } catch (e) { logger.warn(`Error reading "tsconfig.base.json": \n${JSON.stringify(e)}`); return null; diff --git a/packages/next/plugins/with-nx.ts b/packages/next/plugins/with-nx.ts index 178faf8c2f29e..87632b14a926f 100644 --- a/packages/next/plugins/with-nx.ts +++ b/packages/next/plugins/with-nx.ts @@ -4,7 +4,7 @@ import type { NextConfig } from 'next/dist/server/config'; import type { WebpackConfigOptions } from '../src/utils/types'; const { join } = require('path'); -const { appRootPath } = require('@nrwl/devkit'); +const { workspaceRoot } = require('@nrwl/devkit'); const { workspaceLayout } = require('@nrwl/devkit'); export interface WithNxOptions extends NextConfig { @@ -44,7 +44,7 @@ function withNx(nextConfig = {} as WithNxOptions) { */ // Include workspace libs in css/sass loaders - const includes = [join(appRootPath, workspaceLayout().libsDir)]; + const includes = [join(workspaceRoot, workspaceLayout().libsDir)]; const nextCssLoaders = config.module.rules.find( (rule) => typeof rule.oneOf === 'object' diff --git a/packages/next/src/utils/generate-globs.ts b/packages/next/src/utils/generate-globs.ts index da2275074eaf6..af4239594c12e 100644 --- a/packages/next/src/utils/generate-globs.ts +++ b/packages/next/src/utils/generate-globs.ts @@ -1,5 +1,5 @@ import { joinPathFragments, logger } from '@nrwl/devkit'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import { getSourceDirOfDependentProjects } from 'nx/src/utils/project-graph-utils'; import { resolve } from 'path'; @@ -19,7 +19,7 @@ export function createGlobPatternsOfDependentProjects( const projectDirs = getSourceDirOfDependentProjects(projectName); return projectDirs.map((sourceDir) => - resolve(appRootPath, joinPathFragments(sourceDir, fileGlobPattern)) + resolve(workspaceRoot, joinPathFragments(sourceDir, fileGlobPattern)) ); } catch (e) { throw new Error( diff --git a/packages/node/src/utils/node.config.spec.ts b/packages/node/src/utils/node.config.spec.ts index c6efedc8298cb..470cf0cf2dea3 100644 --- a/packages/node/src/utils/node.config.spec.ts +++ b/packages/node/src/utils/node.config.spec.ts @@ -5,7 +5,7 @@ import { BuildNodeBuilderOptions } from './types'; jest.mock('tsconfig-paths-webpack-plugin'); jest.mock('@nrwl/devkit', () => ({ - get appRootPath() { + get workspaceRoot() { return join(__dirname, '../../../..'); }, })); diff --git a/packages/node/src/utils/node.config.ts b/packages/node/src/utils/node.config.ts index c267be2a29ad3..1e583b685a0d4 100644 --- a/packages/node/src/utils/node.config.ts +++ b/packages/node/src/utils/node.config.ts @@ -1,4 +1,4 @@ -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import { Configuration } from 'webpack'; import { merge } from 'webpack-merge'; @@ -32,7 +32,7 @@ function getNodePartial(options: BuildNodeBuilderOptions) { } if (options.externalDependencies === 'all') { - const modulesDir = `${appRootPath}/node_modules`; + const modulesDir = `${workspaceRoot}/node_modules`; webpackConfig.externals = [nodeExternals({ modulesDir })]; } else if (Array.isArray(options.externalDependencies)) { webpackConfig.externals = [ diff --git a/packages/nx-plugin/src/utils/testing-utils/nx-project.ts b/packages/nx-plugin/src/utils/testing-utils/nx-project.ts index 5cd0c9ee41f94..6235b9e3917cd 100644 --- a/packages/nx-plugin/src/utils/testing-utils/nx-project.ts +++ b/packages/nx-plugin/src/utils/testing-utils/nx-project.ts @@ -1,4 +1,4 @@ -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import { getPackageManagerCommand, readJsonFile, @@ -31,7 +31,7 @@ export function patchPackageJsonForPlugin( ) { const path = tmpProjPath('package.json'); const json = readJsonFile(path); - json.devDependencies[npmPackageName] = `file:${appRootPath}/${distPath}`; + json.devDependencies[npmPackageName] = `file:${workspaceRoot}/${distPath}`; writeJsonFile(path, json); } diff --git a/packages/nx/src/adapter/compat.ts b/packages/nx/src/adapter/compat.ts index c89aa7d4f12a6..80c2bcc35dd6e 100644 --- a/packages/nx/src/adapter/compat.ts +++ b/packages/nx/src/adapter/compat.ts @@ -4,7 +4,7 @@ import { workspaceConfigName, Workspaces, } from '../shared/workspace'; -import { appRootPath } from '../utils/app-root'; +import { workspaceRoot } from '../utils/app-root'; /* eslint-disable */ const Module = require('module'); @@ -24,7 +24,7 @@ if (!patched) { core._test_addWorkspaceFile('workspace.json', core.WorkspaceFormat.JSON); const originalReadWorkspace = core.readWorkspace; core.readWorkspace = (path, ...rest) => { - const configFile = workspaceConfigName(appRootPath); + const configFile = workspaceConfigName(workspaceRoot); if (!configFile) { path = 'workspace.json'; } @@ -32,7 +32,7 @@ if (!patched) { }; const originalWriteWorkspace = core.writeWorkspace; core.writeWorkspace = (...args) => { - const configFile = workspaceConfigName(appRootPath); + const configFile = workspaceConfigName(workspaceRoot); if (!loggedWriteWorkspaceWarning) { if (configFile) { logger.warn( @@ -68,7 +68,7 @@ if (!patched) { logger.debug( '[NX] Angular devkit readJsonWorkspace fell back to Nx workspaces logic' ); - const w = new Workspaces(appRootPath); + const w = new Workspaces(workspaceRoot); // Read our v1 workspace schema const workspaceConfiguration = resolveOldFormatWithInlineProjects( diff --git a/packages/nx/src/command-line/dep-graph.ts b/packages/nx/src/command-line/dep-graph.ts index 9f5a7e24d6d25..7c23ea1c3baea 100644 --- a/packages/nx/src/command-line/dep-graph.ts +++ b/packages/nx/src/command-line/dep-graph.ts @@ -1,4 +1,4 @@ -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { watch } from 'chokidar'; import { createHash } from 'crypto'; import { existsSync, readFileSync, statSync, writeFileSync } from 'fs'; @@ -211,7 +211,7 @@ export async function generateGraph( graph = filterGraph(graph, args.focus || null, args.exclude || []); if (args.file) { - const workspaceFolder = appRootPath; + const workspaceFolder = workspaceRoot; const ext = extname(args.file); const fullFilePath = isAbsolute(args.file) ? args.file @@ -420,7 +420,7 @@ function getIgnoredGlobs(root: string) { } function startWatcher() { - createFileWatcher(appRootPath, async () => { + createFileWatcher(workspaceRoot, async () => { output.note({ title: 'Recalculating project graph...' }); const newGraphClientResponse = await createDepGraphClientResponse(); diff --git a/packages/nx/src/command-line/format.ts b/packages/nx/src/command-line/format.ts index f54ce6863ddb7..4a9bf58551522 100644 --- a/packages/nx/src/command-line/format.ts +++ b/packages/nx/src/command-line/format.ts @@ -16,7 +16,7 @@ import { workspaceConfigName, WorkspaceJsonConfiguration, } from 'nx/src/shared/workspace'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import * as prettier from 'prettier'; import { sortObjectByKeys } from 'nx/src/utils/object-sort'; import { @@ -43,7 +43,7 @@ export async function format( switch (command) { case 'write': - const workspaceJsonPath = workspaceConfigName(appRootPath); + const workspaceJsonPath = workspaceConfigName(workspaceRoot); if (workspaceJsonPath) { updateWorkspaceJsonToMatchFormatVersion(workspaceJsonPath); sortWorkspaceJson(workspaceJsonPath); diff --git a/packages/nx/src/command-line/list.ts b/packages/nx/src/command-line/list.ts index 0a1df801f36a1..cd7ee88d3e3e2 100644 --- a/packages/nx/src/command-line/list.ts +++ b/packages/nx/src/command-line/list.ts @@ -1,4 +1,4 @@ -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { output } from '../utils/output'; import { fetchCommunityPlugins, @@ -38,7 +38,7 @@ export async function listHandler(args: ListArgs): Promise { }); const installedPlugins = getInstalledPluginsFromPackageJson( - appRootPath, + workspaceRoot, corePlugins, communityPlugins ); diff --git a/packages/nx/src/command-line/nx-commands.ts b/packages/nx/src/command-line/nx-commands.ts index b31416338e6af..79b1caa61f35f 100644 --- a/packages/nx/src/command-line/nx-commands.ts +++ b/packages/nx/src/command-line/nx-commands.ts @@ -5,7 +5,7 @@ import * as yargs from 'yargs'; import { generateDaemonHelpOutput } from '../core/project-graph/daemon/client/generate-help-output'; import { nxVersion } from '../utils/versions'; import { examples } from './examples'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { getPackageManagerCommand } from '../utils/package-manager'; import { writeJsonFile } from 'nx/src/utils/fileutils'; @@ -731,7 +731,7 @@ function nxCliPath() { // Set NODE_PATH so that these modules can be used for module resolution addToNodePath(path.join(tmpDir, 'node_modules')); - addToNodePath(path.join(appRootPath, 'node_modules')); + addToNodePath(path.join(workspaceRoot, 'node_modules')); return path.join(tmpDir, `node_modules`, '.bin', 'nx'); } catch (e) { diff --git a/packages/nx/src/command-line/report.spec.ts b/packages/nx/src/command-line/report.spec.ts index 4de781ea65f9c..e97d4c7007482 100644 --- a/packages/nx/src/command-line/report.spec.ts +++ b/packages/nx/src/command-line/report.spec.ts @@ -1,10 +1,7 @@ -import { findInstalledCommunityPlugins } from './report'; // import * as devkit from '@nrwl/devkit'; import * as fileUtils from '../utils/fileutils'; -import { join } from 'path'; jest.mock('nx/src/utils/app-root', () => ({ - appRootPath: '', workspaceRoot: '', })); diff --git a/packages/nx/src/command-line/report.ts b/packages/nx/src/command-line/report.ts index ce1fd1d2cfe84..ce8602298a2c2 100644 --- a/packages/nx/src/command-line/report.ts +++ b/packages/nx/src/command-line/report.ts @@ -1,5 +1,5 @@ import * as chalk from 'chalk'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { output } from '../utils/output'; import { join } from 'path'; import { @@ -81,7 +81,7 @@ export function reportHandler() { export function readPackageJson(p: string) { try { const packageJsonPath = require.resolve(`${p}/package.json`, { - paths: [appRootPath], + paths: [workspaceRoot], }); return readJsonFile(packageJsonPath); } catch { @@ -98,7 +98,7 @@ export function findInstalledCommunityPlugins(): { version: string; }[] { const { dependencies, devDependencies } = readJsonFile( - join(appRootPath, 'package.json') + join(workspaceRoot, 'package.json') ); const deps = [ Object.keys(dependencies || {}), diff --git a/packages/nx/src/command-line/workspace-generators.ts b/packages/nx/src/command-line/workspace-generators.ts index 4d08c0fff575e..8aadce61b2490 100644 --- a/packages/nx/src/command-line/workspace-generators.ts +++ b/packages/nx/src/command-line/workspace-generators.ts @@ -4,7 +4,7 @@ import { readdirSync, existsSync } from 'fs'; import { copySync, removeSync } from 'fs-extra'; import * as path from 'path'; import * as yargsParser from 'yargs-parser'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { fileExists } from '../utils/fileutils'; import { output } from '../utils/output'; import type { CompilerOptions } from 'typescript'; @@ -14,7 +14,7 @@ import { logger } from 'nx/src/utils/logger'; import { getPackageManagerCommand } from '../utils/package-manager'; import { normalizePath } from '../utils/path'; -const rootDirectory = appRootPath; +const rootDirectory = workspaceRoot; const toolsDir = path.join(rootDirectory, 'tools'); const generatorsDir = path.join(toolsDir, 'generators'); const toolsTsConfigPath = path.join(toolsDir, 'tsconfig.tools.json'); diff --git a/packages/nx/src/core/affected-project-graph/affected-project-graph.spec.ts b/packages/nx/src/core/affected-project-graph/affected-project-graph.spec.ts index 7d34048e537cb..85e2cd7232e20 100644 --- a/packages/nx/src/core/affected-project-graph/affected-project-graph.spec.ts +++ b/packages/nx/src/core/affected-project-graph/affected-project-graph.spec.ts @@ -10,7 +10,6 @@ import { stripIndents } from '../../utils/strip-indents'; jest.mock('fs', () => require('memfs').fs); jest.mock('nx/src/utils/app-root', () => ({ - appRootPath: '/root', workspaceRoot: '/root', })); diff --git a/packages/nx/src/core/file-utils.ts b/packages/nx/src/core/file-utils.ts index 37a7bba41ac82..95b8214fd3b0d 100644 --- a/packages/nx/src/core/file-utils.ts +++ b/packages/nx/src/core/file-utils.ts @@ -7,7 +7,7 @@ import { execSync } from 'child_process'; import { existsSync, readFileSync } from 'fs'; import { extname, join, relative, sep } from 'path'; import type { NxArgs } from '../command-line/utils'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { fileExists } from '../utils/fileutils'; import { jsonDiff } from '../utils/json-diff'; import type { Environment } from './shared-interfaces'; @@ -38,8 +38,8 @@ export function readFileIfExisting(path: string) { function getIgnoredGlobs() { const ig = ignore(); - ig.add(readFileIfExisting(`${appRootPath}/.gitignore`)); - ig.add(readFileIfExisting(`${appRootPath}/.nxignore`)); + ig.add(readFileIfExisting(`${workspaceRoot}/.gitignore`)); + ig.add(readFileIfExisting(`${workspaceRoot}/.nxignore`)); return ig; } @@ -97,7 +97,7 @@ function defaultReadFileAtRevision( revision: void | string ): string { try { - const fileFullPath = `${appRootPath}${sep}${file}`; + const fileFullPath = `${workspaceRoot}${sep}${file}`; const gitRepositoryPath = execSync('git rev-parse --show-toplevel') .toString() .trim(); @@ -119,7 +119,7 @@ function defaultReadFileAtRevision( export function readWorkspaceJson(): WorkspaceJsonConfiguration { return readWorkspaceConfig({ format: 'nx', - path: appRootPath, + path: workspaceRoot, }); } @@ -138,7 +138,7 @@ export function readWorkspaceConfig(opts: { } export function workspaceFileName() { - if (fileExists(`${appRootPath}/angular.json`)) { + if (fileExists(`${workspaceRoot}/angular.json`)) { return 'angular.json'; } else { return 'workspace.json'; @@ -146,11 +146,11 @@ export function workspaceFileName() { } export function defaultFileRead(filePath: string): string | null { - return readFileSync(join(appRootPath, filePath), 'utf-8'); + return readFileSync(join(workspaceRoot, filePath), 'utf-8'); } export function readPackageJson(): any { - return readJsonFile(`${appRootPath}/package.json`); + return readJsonFile(`${workspaceRoot}/package.json`); } /** @@ -159,7 +159,7 @@ export function readPackageJson(): any { * If nx.json extends another config file, it will be inlined here. */ export function readNxJson( - path: string = `${appRootPath}/nx.json` + path: string = `${workspaceRoot}/nx.json` ): NxJsonConfiguration { let config = readJsonFile(path); if (!config.npmScope) { diff --git a/packages/nx/src/core/hasher/file-hasher.ts b/packages/nx/src/core/hasher/file-hasher.ts index dea93c02f7fb8..4988d6547733b 100644 --- a/packages/nx/src/core/hasher/file-hasher.ts +++ b/packages/nx/src/core/hasher/file-hasher.ts @@ -1,12 +1,12 @@ import { GitBasedFileHasher } from './git-based-file-hasher'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { NodeBasedFileHasher } from './node-based-file-hasher'; import { FileHasherBase } from './file-hasher-base'; import { execSync } from 'child_process'; function createFileHasher(): FileHasherBase { // special case for unit tests - if (appRootPath === '/root') { + if (workspaceRoot === '/root') { return new NodeBasedFileHasher(); } try { diff --git a/packages/nx/src/core/hasher/git-based-file-hasher.ts b/packages/nx/src/core/hasher/git-based-file-hasher.ts index 5d9f0744556f4..89f8498055596 100644 --- a/packages/nx/src/core/hasher/git-based-file-hasher.ts +++ b/packages/nx/src/core/hasher/git-based-file-hasher.ts @@ -1,4 +1,4 @@ -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { performance } from 'perf_hooks'; import { getFileHashes, getGitHashForFiles } from './git-hasher'; import { existsSync, readFileSync } from 'fs'; @@ -15,7 +15,7 @@ export class GitBasedFileHasher extends FileHasherBase { performance.mark('init hashing:start'); this.clear(); - const gitResult = await getFileHashes(appRootPath); + const gitResult = await getFileHashes(workspaceRoot); const ignore = getIgnoredGlobs(); gitResult.allFiles.forEach((hash, filename) => { if (!ignore.ignores(filename)) { @@ -32,14 +32,14 @@ export class GitBasedFileHasher extends FileHasherBase { } async hashFiles(files: string[]) { - return (await getGitHashForFiles(files, appRootPath)).hashes; + return (await getGitHashForFiles(files, workspaceRoot)).hashes; } } function getIgnoredGlobs() { - if (existsSync(`${appRootPath}/.nxignore`)) { + if (existsSync(`${workspaceRoot}/.nxignore`)) { const ig = ignore(); - ig.add(readFileSync(`${appRootPath}/.nxignore`, 'utf-8')); + ig.add(readFileSync(`${workspaceRoot}/.nxignore`, 'utf-8')); return ig; } else { return { ignores: (file: string) => false }; diff --git a/packages/nx/src/core/hasher/hasher.spec.ts b/packages/nx/src/core/hasher/hasher.spec.ts index 62755310cf7cf..5d39b679fd489 100644 --- a/packages/nx/src/core/hasher/hasher.spec.ts +++ b/packages/nx/src/core/hasher/hasher.spec.ts @@ -3,7 +3,6 @@ import { DependencyType } from 'nx/src/shared/project-graph'; jest.doMock('../../utils/app-root', () => { return { - appRootPath: '', workspaceRoot: '', }; }); diff --git a/packages/nx/src/core/hasher/hasher.ts b/packages/nx/src/core/hasher/hasher.ts index 5d89be321c034..68fc9f9779b9d 100644 --- a/packages/nx/src/core/hasher/hasher.ts +++ b/packages/nx/src/core/hasher/hasher.ts @@ -8,7 +8,7 @@ import * as minimatch from 'minimatch'; import { join } from 'path'; import { performance } from 'perf_hooks'; import { getRootTsConfigFileName } from '../../utils/typescript'; -import { appRootPath } from '../../utils/app-root'; +import { workspaceRoot } from '../../utils/app-root'; import { workspaceFileName } from '../file-utils'; import { defaultHashing, HashingImpl } from './hashing-impl'; import { ProjectGraph } from 'nx/src/shared/project-graph'; @@ -248,9 +248,9 @@ export class Hasher { const fileHashes = [ ...fileNames .map((maybeRelativePath) => { - // Normalize the path to always be absolute and starting with appRootPath so we can check it exists - if (!maybeRelativePath.startsWith(appRootPath)) { - return join(appRootPath, maybeRelativePath); + // Normalize the path to always be absolute and starting with workspaceRoot so we can check it exists + if (!maybeRelativePath.startsWith(workspaceRoot)) { + return join(workspaceRoot, maybeRelativePath); } return maybeRelativePath; }) @@ -284,7 +284,7 @@ export class Hasher { } private hashNxJson() { - const nxJsonPath = join(appRootPath, 'nx.json'); + const nxJsonPath = join(workspaceRoot, 'nx.json'); if (!existsSync(nxJsonPath)) { return []; } diff --git a/packages/nx/src/core/project-graph/build-dependencies/explicit-package-json-dependencies.spec.ts b/packages/nx/src/core/project-graph/build-dependencies/explicit-package-json-dependencies.spec.ts index 35407dbdbf307..35456f726a28c 100644 --- a/packages/nx/src/core/project-graph/build-dependencies/explicit-package-json-dependencies.spec.ts +++ b/packages/nx/src/core/project-graph/build-dependencies/explicit-package-json-dependencies.spec.ts @@ -10,7 +10,6 @@ import { ProjectGraphBuilder } from '../project-graph-builder'; jest.mock('fs', () => require('memfs').fs); jest.mock('nx/src/utils/app-root', () => ({ - appRootPath: '/root', workspaceRoot: '/root', })); diff --git a/packages/nx/src/core/project-graph/build-dependencies/explicit-project-dependencies.spec.ts b/packages/nx/src/core/project-graph/build-dependencies/explicit-project-dependencies.spec.ts index 869605995d5a9..20c0240bdd5d9 100644 --- a/packages/nx/src/core/project-graph/build-dependencies/explicit-project-dependencies.spec.ts +++ b/packages/nx/src/core/project-graph/build-dependencies/explicit-project-dependencies.spec.ts @@ -2,7 +2,6 @@ import { createProjectFileMap } from 'nx/src/core/file-map-utils'; jest.mock('fs', () => require('memfs').fs); jest.mock('nx/src/utils/app-root', () => ({ - appRootPath: '/root', workspaceRoot: '/root', })); diff --git a/packages/nx/src/core/project-graph/build-dependencies/implict-project-dependencies.spec.ts b/packages/nx/src/core/project-graph/build-dependencies/implict-project-dependencies.spec.ts index 4efebc4764119..0d9b0fb38b9b3 100644 --- a/packages/nx/src/core/project-graph/build-dependencies/implict-project-dependencies.spec.ts +++ b/packages/nx/src/core/project-graph/build-dependencies/implict-project-dependencies.spec.ts @@ -4,7 +4,6 @@ import { buildImplicitProjectDependencies } from './implicit-project-dependencie jest.mock('fs', () => require('memfs').fs); jest.mock('nx/src/utils/app-root', () => ({ - appRootPath: '/root', workspaceRoot: '/root', })); diff --git a/packages/nx/src/core/project-graph/build-nodes/npm-packages.ts b/packages/nx/src/core/project-graph/build-nodes/npm-packages.ts index f8529d04648e2..33ed11d350ede 100644 --- a/packages/nx/src/core/project-graph/build-nodes/npm-packages.ts +++ b/packages/nx/src/core/project-graph/build-nodes/npm-packages.ts @@ -1,10 +1,10 @@ import { join } from 'path'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { readJsonFile } from 'nx/src/utils/fileutils'; import { ProjectGraphBuilder } from '../project-graph-builder'; export function buildNpmPackageNodes(builder: ProjectGraphBuilder) { - const packageJson = readJsonFile(join(appRootPath, 'package.json')); + const packageJson = readJsonFile(join(workspaceRoot, 'package.json')); const deps = { ...packageJson.dependencies, ...packageJson.devDependencies, diff --git a/packages/nx/src/core/project-graph/build-nodes/workspace-projects.ts b/packages/nx/src/core/project-graph/build-nodes/workspace-projects.ts index 5ca7b2a4be0f6..f7f9e0bc84a74 100644 --- a/packages/nx/src/core/project-graph/build-nodes/workspace-projects.ts +++ b/packages/nx/src/core/project-graph/build-nodes/workspace-projects.ts @@ -1,6 +1,6 @@ import { join } from 'path'; import { existsSync } from 'fs'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { loadNxPlugins, mergePluginTargetsWithNxTargets, @@ -16,7 +16,7 @@ export function buildWorkspaceProjectNodes( const toAdd = []; Object.keys(ctx.workspace.projects).forEach((key) => { const p = ctx.workspace.projects[key]; - const projectRoot = join(appRootPath, p.root); + const projectRoot = join(workspaceRoot, p.root); if (existsSync(join(projectRoot, 'package.json'))) { p.targets = mergeNpmScriptsWithTargets(projectRoot, p.targets); } diff --git a/packages/nx/src/core/project-graph/build-project-graph.spec.ts b/packages/nx/src/core/project-graph/build-project-graph.spec.ts index f719cf7e3f65c..1ab1730b2f036 100644 --- a/packages/nx/src/core/project-graph/build-project-graph.spec.ts +++ b/packages/nx/src/core/project-graph/build-project-graph.spec.ts @@ -2,7 +2,6 @@ import { vol, fs } from 'memfs'; jest.mock('fs', () => require('memfs').fs); jest.mock('nx/src/utils/app-root', () => ({ - appRootPath: '/root', workspaceRoot: '/root', })); import { buildProjectGraph } from './build-project-graph'; diff --git a/packages/nx/src/core/project-graph/build-project-graph.ts b/packages/nx/src/core/project-graph/build-project-graph.ts index 5939d71d5f9cb..7d42f7bb676e2 100644 --- a/packages/nx/src/core/project-graph/build-project-graph.ts +++ b/packages/nx/src/core/project-graph/build-project-graph.ts @@ -1,4 +1,4 @@ -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { join } from 'path'; import { performance } from 'perf_hooks'; import { assertWorkspaceValidity } from '../assert-workspace-validity'; @@ -129,7 +129,7 @@ export async function buildProjectGraphUsingProjectFileMap( } function readCombinedDeps() { - const json = readJsonFile(join(appRootPath, 'package.json')); + const json = readJsonFile(join(workspaceRoot, 'package.json')); return { ...json.dependencies, ...json.devDependencies }; } diff --git a/packages/nx/src/core/project-graph/daemon/client/client.ts b/packages/nx/src/core/project-graph/daemon/client/client.ts index bf74e4edc6c64..7bf15adfdc46c 100644 --- a/packages/nx/src/core/project-graph/daemon/client/client.ts +++ b/packages/nx/src/core/project-graph/daemon/client/client.ts @@ -1,4 +1,4 @@ -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { ChildProcess, spawn, spawnSync } from 'child_process'; import { openSync, readFileSync } from 'fs'; import { ensureDirSync, ensureFileSync } from 'fs-extra'; @@ -28,7 +28,7 @@ export async function startInBackground(): Promise { process.execPath, [join(__dirname, '../server/start.js')], { - cwd: appRootPath, + cwd: workspaceRoot, stdio: ['ignore', out, err], detached: true, windowsHide: true, @@ -90,7 +90,7 @@ export function startInCurrentProcess(): void { }); spawnSync(process.execPath, [join(__dirname, '../server/start.js')], { - cwd: appRootPath, + cwd: workspaceRoot, stdio: 'inherit', }); } diff --git a/packages/nx/src/core/project-graph/daemon/server/server.ts b/packages/nx/src/core/project-graph/daemon/server/server.ts index d1dc1ebc46869..5a5304071302a 100644 --- a/packages/nx/src/core/project-graph/daemon/server/server.ts +++ b/packages/nx/src/core/project-graph/daemon/server/server.ts @@ -1,4 +1,4 @@ -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { createServer, Server, Socket } from 'net'; import { join } from 'path'; import { performance, PerformanceObserver } from 'perf_hooks'; @@ -76,7 +76,7 @@ const server = createServer(async (socket) => { if (watcherError) { await respondWithErrorAndExit( socket, - `File watcher error in the workspace '${appRootPath}'.`, + `File watcher error in the workspace '${workspaceRoot}'.`, watcherError ); } @@ -193,9 +193,9 @@ let existingLockHash: string | undefined; function lockFileChanged(): boolean { const hash = new HashingImpl(); const lockHashes = [ - join(appRootPath, 'package-lock.json'), - join(appRootPath, 'yarn.lock'), - join(appRootPath, 'pnpm-lock.yaml'), + join(workspaceRoot, 'package-lock.json'), + join(workspaceRoot, 'yarn.lock'), + join(workspaceRoot, 'pnpm-lock.yaml'), ] .filter((file) => existsSync(file)) .map((file) => hash.hashFile(file)); @@ -253,7 +253,7 @@ const handleWorkspaceChanges: SubscribeToWorkspaceChangesCallback = async ( deletedFiles.push(event.path); } else { try { - const s = statSync(join(appRootPath, event.path)); + const s = statSync(join(workspaceRoot, event.path)); if (!s.isDirectory()) { filesToHash.push(event.path); } @@ -290,7 +290,7 @@ export async function startServer(): Promise { handleWorkspaceChanges ); serverLogger.watcherLog( - `Subscribed to changes within: ${appRootPath}` + `Subscribed to changes within: ${workspaceRoot}` ); } return resolve(server); diff --git a/packages/nx/src/core/project-graph/daemon/server/shutdown-utils.ts b/packages/nx/src/core/project-graph/daemon/server/shutdown-utils.ts index 1379fd6e51489..e6f2efff8e4da 100644 --- a/packages/nx/src/core/project-graph/daemon/server/shutdown-utils.ts +++ b/packages/nx/src/core/project-graph/daemon/server/shutdown-utils.ts @@ -1,4 +1,4 @@ -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import type { Server } from 'net'; import { serverLogger } from './logger'; import type { WatcherSubscription } from './watcher'; @@ -21,7 +21,7 @@ export async function handleServerProcessTermination({ if (watcherSubscription) { await watcherSubscription.unsubscribe(); serverLogger.watcherLog( - `Unsubscribed from changes within: ${appRootPath}` + `Unsubscribed from changes within: ${workspaceRoot}` ); } serverLogger.log(`Server stopped because: "${reason}"`); diff --git a/packages/nx/src/core/project-graph/daemon/server/watcher.ts b/packages/nx/src/core/project-graph/daemon/server/watcher.ts index b42993052d626..28ab11cdae224 100644 --- a/packages/nx/src/core/project-graph/daemon/server/watcher.ts +++ b/packages/nx/src/core/project-graph/daemon/server/watcher.ts @@ -5,7 +5,7 @@ * * See https://github.com/parcel-bundler/watcher for more details. */ -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import type { AsyncSubscription, Event } from '@parcel/watcher'; import { readFileSync } from 'fs'; import { join, relative } from 'path'; @@ -28,16 +28,16 @@ import { normalizePath } from 'nx/src/utils/path'; * https://github.com/parcel-bundler/watcher/issues/64 */ const ALWAYS_IGNORE = [ - join(appRootPath, 'node_modules'), - join(appRootPath, '.git'), + join(workspaceRoot, 'node_modules'), + join(workspaceRoot, '.git'), FULL_OS_SOCKET_PATH, ]; function getIgnoredGlobs() { return [ ...ALWAYS_IGNORE, - ...getIgnoredGlobsFromFile(join(appRootPath, '.nxignore')), - ...getIgnoredGlobsFromFile(join(appRootPath, '.gitignore')), + ...getIgnoredGlobsFromFile(join(workspaceRoot, '.nxignore')), + ...getIgnoredGlobsFromFile(join(workspaceRoot, '.gitignore')), ]; } @@ -47,7 +47,7 @@ function getIgnoredGlobsFromFile(file: string): string[] { .split('\n') .map((i) => i.trim()) .filter((i) => !!i && !i.startsWith('#')) - .map((i) => (i.startsWith('/') ? join(appRootPath, i) : i)); + .map((i) => (i.startsWith('/') ? join(workspaceRoot, i) : i)); } catch (e) { return []; } @@ -62,10 +62,10 @@ export type SubscribeToWorkspaceChangesCallback = ( function configureIgnoreObject() { const ig = ignore(); try { - ig.add(readFileSync(`${appRootPath}/.gitignore`, 'utf-8')); + ig.add(readFileSync(`${workspaceRoot}/.gitignore`, 'utf-8')); } catch {} try { - ig.add(readFileSync(`${appRootPath}/.nxignore`, 'utf-8')); + ig.add(readFileSync(`${workspaceRoot}/.nxignore`, 'utf-8')); } catch {} return ig; } @@ -83,7 +83,7 @@ export async function subscribeToWorkspaceChanges( const ignoreObj = configureIgnoreObject(); const subscription = await watcher.subscribe( - appRootPath, + workspaceRoot, (err, events) => { // Let the consumer handle any errors if (err) { @@ -97,7 +97,7 @@ export async function subscribeToWorkspaceChanges( for (const event of events) { const workspaceRelativeEvent: Event = { type: event.type, - path: normalizePath(relative(appRootPath, event.path)), + path: normalizePath(relative(workspaceRoot, event.path)), }; if ( workspaceRelativeEvent.path === '.gitignore' || diff --git a/packages/nx/src/core/target-project-locator.spec.ts b/packages/nx/src/core/target-project-locator.spec.ts index 8b2f37098a34e..a3411c883f2ee 100644 --- a/packages/nx/src/core/target-project-locator.spec.ts +++ b/packages/nx/src/core/target-project-locator.spec.ts @@ -7,7 +7,6 @@ import { } from 'nx/src/shared/project-graph'; jest.mock('nx/src/utils/app-root', () => ({ - appRootPath: '/root', workspaceRoot: '/root', })); jest.mock('fs', () => require('memfs').fs); diff --git a/packages/nx/src/core/target-project-locator.ts b/packages/nx/src/core/target-project-locator.ts index c433e17661dd0..7d60e8f7bd31a 100644 --- a/packages/nx/src/core/target-project-locator.ts +++ b/packages/nx/src/core/target-project-locator.ts @@ -4,7 +4,7 @@ import { } from '../utils/typescript'; import { isRelativePath } from '../utils/fileutils'; import { dirname, join, posix } from 'path'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { readFileSync } from 'fs'; import { ProjectGraphExternalNode, @@ -168,7 +168,7 @@ export class TargetProjectLocator { } private getAbsolutePath(path: string) { - return join(appRootPath, path); + return join(workspaceRoot, path); } private getRootTsConfig() { diff --git a/packages/nx/src/shared/workspace.ts b/packages/nx/src/shared/workspace.ts index f6dffe34b485f..da5438e65c094 100644 --- a/packages/nx/src/shared/workspace.ts +++ b/packages/nx/src/shared/workspace.ts @@ -5,7 +5,7 @@ import * as path from 'path'; import { basename, dirname, join } from 'path'; import { performance } from 'perf_hooks'; -import { appRootPath } from '../utils/app-root'; +import { workspaceRoot } from '../utils/app-root'; import { readJsonFile } from '../utils/fileutils'; import { logger } from '../utils/logger'; import { loadNxPlugins, readPluginPackageJson } from '../utils/nx-plugin'; @@ -604,7 +604,7 @@ export function toOldFormatOrNull(w: any) { export function resolveOldFormatWithInlineProjects( w: any, - root: string = appRootPath + root: string = workspaceRoot ) { const inlined = inlineProjectConfigurations(w, root); const formatted = toOldFormatOrNull(inlined); @@ -613,12 +613,12 @@ export function resolveOldFormatWithInlineProjects( export function resolveNewFormatWithInlineProjects( w: any, - root: string = appRootPath + root: string = workspaceRoot ) { return toNewFormat(inlineProjectConfigurations(w, root)); } -function inlineProjectConfigurations(w: any, root: string = appRootPath) { +function inlineProjectConfigurations(w: any, root: string = workspaceRoot) { Object.entries(w.projects || {}).forEach( ([project, config]: [string, any]) => { if (typeof config === 'string') { diff --git a/packages/nx/src/tasks-runner/batch/run-batch.ts b/packages/nx/src/tasks-runner/batch/run-batch.ts index 1dac8962e86df..78f81a27706d8 100644 --- a/packages/nx/src/tasks-runner/batch/run-batch.ts +++ b/packages/nx/src/tasks-runner/batch/run-batch.ts @@ -4,25 +4,25 @@ import { BatchMessageType, } from './batch-messages'; import { ExecutorContext, Workspaces } from 'nx/src/shared/workspace'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { combineOptionsForExecutor } from 'nx/src/utils/params'; import { TaskGraph } from 'nx/src/shared/tasks'; function getBatchExecutor(executorName: string) { - const workspace = new Workspaces(appRootPath); + const workspace = new Workspaces(workspaceRoot); const [nodeModule, exportName] = executorName.split(':'); return workspace.readExecutor(nodeModule, exportName); } async function runTasks(executorName: string, taskGraph: TaskGraph) { const input: Record = {}; - const workspace = new Workspaces(appRootPath); + const workspace = new Workspaces(workspaceRoot); const workspaceConfig = workspace.readWorkspaceConfiguration(); const batchExecutor = getBatchExecutor(executorName); const tasks = Object.values(taskGraph.tasks); const context: ExecutorContext = { - root: appRootPath, + root: workspaceRoot, cwd: process.cwd(), workspace: workspaceConfig, isVerbose: false, diff --git a/packages/nx/src/tasks-runner/cache.ts b/packages/nx/src/tasks-runner/cache.ts index 0a3fe0600104d..a0885ef10f359 100644 --- a/packages/nx/src/tasks-runner/cache.ts +++ b/packages/nx/src/tasks-runner/cache.ts @@ -1,4 +1,4 @@ -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { copy, mkdir, @@ -27,7 +27,7 @@ export type CachedResult = { export type TaskWithCachedResult = { task: Task; cachedResult: CachedResult }; export class Cache { - root = appRootPath; + root = workspaceRoot; cachePath = this.createCacheDir(); terminalOutputsDir = this.createTerminalOutputsDir(); latestOutputsHashesDir = this.ensureLatestOutputsHashesDir(); diff --git a/packages/nx/src/tasks-runner/forked-process-task-runner.ts b/packages/nx/src/tasks-runner/forked-process-task-runner.ts index bcf3176d3a82f..427297314e9cf 100644 --- a/packages/nx/src/tasks-runner/forked-process-task-runner.ts +++ b/packages/nx/src/tasks-runner/forked-process-task-runner.ts @@ -1,7 +1,7 @@ import { readFileSync, writeFileSync } from 'fs'; import * as dotenv from 'dotenv'; import { ChildProcess, fork } from 'child_process'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { DefaultTasksRunnerOptions } from './default-tasks-runner'; import { output } from '../utils/output'; import { @@ -22,7 +22,7 @@ import { Task } from '../shared/tasks'; const workerPath = join(__dirname, './batch/run-batch.js'); export class ForkedProcessTaskRunner { - workspaceRoot = appRootPath; + workspaceRoot = workspaceRoot; cliPath = getCliPath(this.workspaceRoot); private processes = new Set(); @@ -209,9 +209,9 @@ export class ForkedProcessTaskRunner { console.log(stripIndents` Unable to print terminal output for Task "${task.id}". Task failed with Exit Code ${code} and Signal "${signal}". - - Received error message: - ${e.message} + + Received error message: + ${e.message} `); } res({ diff --git a/packages/nx/src/tasks-runner/run-command.ts b/packages/nx/src/tasks-runner/run-command.ts index d8391a4eec4e1..9248efff75ea1 100644 --- a/packages/nx/src/tasks-runner/run-command.ts +++ b/packages/nx/src/tasks-runner/run-command.ts @@ -1,6 +1,6 @@ import { TasksRunner, TaskStatus } from './tasks-runner'; import { join } from 'path'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { logger, stripIndent } from 'nx/src/utils/logger'; import { Environment } from '../core/shared-interfaces'; import { NxArgs } from '../command-line/utils'; @@ -497,7 +497,7 @@ export function getRunner( let tasksRunner; if (modulePath) { if (isRelativePath(modulePath)) { - modulePath = join(appRootPath, modulePath); + modulePath = join(workspaceRoot, modulePath); } tasksRunner = require(modulePath); diff --git a/packages/nx/src/tasks-runner/task-orchestrator.ts b/packages/nx/src/tasks-runner/task-orchestrator.ts index e5d1e4aec874a..d7efeebab6e4e 100644 --- a/packages/nx/src/tasks-runner/task-orchestrator.ts +++ b/packages/nx/src/tasks-runner/task-orchestrator.ts @@ -2,7 +2,7 @@ import { Workspaces } from 'nx/src/shared/workspace'; import { performance } from 'perf_hooks'; import { Hasher } from '../core/hasher/hasher'; import { ForkedProcessTaskRunner } from './forked-process-task-runner'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { Cache } from './cache'; import { DefaultTasksRunnerOptions } from './default-tasks-runner'; import { TaskStatus } from './tasks-runner'; @@ -21,7 +21,7 @@ import { Task, TaskGraph } from '../shared/tasks'; export class TaskOrchestrator { private cache = new Cache(this.options); - private workspace = new Workspaces(appRootPath); + private workspace = new Workspaces(workspaceRoot); private forkedProcessTaskRunner = new ForkedProcessTaskRunner(this.options); private tasksSchedule = new TasksSchedule( this.hasher, diff --git a/packages/nx/src/utils/cache-directory.ts b/packages/nx/src/utils/cache-directory.ts index 720cd477b7fc8..6f4e0a1622c41 100644 --- a/packages/nx/src/utils/cache-directory.ts +++ b/packages/nx/src/utils/cache-directory.ts @@ -1,5 +1,5 @@ import { join, isAbsolute } from 'path'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { readJsonFile } from 'nx/src/utils/fileutils'; import { NxJsonConfiguration } from 'nx/src/shared/nx'; @@ -32,6 +32,6 @@ function cacheDirectory(root: string, cacheDirectory: string) { * Path to the directory where Nx stores its cache and daemon-related files. */ export const cacheDir = cacheDirectory( - appRootPath, - readCacheDirectoryProperty(appRootPath) + workspaceRoot, + readCacheDirectoryProperty(workspaceRoot) ); diff --git a/packages/nx/src/utils/nx-plugin.ts b/packages/nx/src/utils/nx-plugin.ts index 6e3a91a02edce..6d2d1dba48080 100644 --- a/packages/nx/src/utils/nx-plugin.ts +++ b/packages/nx/src/utils/nx-plugin.ts @@ -9,7 +9,7 @@ import { Workspaces, } from '../shared/workspace'; -import { appRootPath } from '../utils/app-root'; +import { workspaceRoot } from '../utils/app-root'; import { readJsonFile } from '../utils/fileutils'; import { PackageJson } from './package-json'; import { registerTsProject } from 'nx/src/utils/register'; @@ -40,7 +40,7 @@ export interface NxPlugin { let nxPluginCache: NxPlugin[] = null; export function loadNxPlugins( plugins?: string[], - paths = [appRootPath] + paths = [workspaceRoot] ): NxPlugin[] { return plugins?.length ? nxPluginCache || @@ -56,7 +56,7 @@ export function loadNxPlugins( const main = readPluginMainFromProjectConfiguration( plugin.projectConfig ); - pluginPath = main ? path.join(appRootPath, main) : plugin.path; + pluginPath = main ? path.join(workspaceRoot, main) : plugin.path; } else { throw e; } @@ -87,7 +87,7 @@ export function mergePluginTargetsWithNxTargets( } const projectFiles = sync(`+(${plugin.projectFilePatterns.join('|')})`, { - cwd: path.join(appRootPath, projectRoot), + cwd: path.join(workspaceRoot, projectRoot), }); for (const projectFile of projectFiles) { newTargets = { @@ -101,7 +101,7 @@ export function mergePluginTargetsWithNxTargets( export function readPluginPackageJson( pluginName: string, - paths = [appRootPath] + paths = [workspaceRoot] ): { path: string; json: PackageJson; @@ -141,7 +141,7 @@ const localPluginCache: Record< > = {}; export function resolveLocalNxPlugin( importPath: string, - root = appRootPath + root = workspaceRoot ): { path: string; projectConfig: ProjectConfiguration } | null { localPluginCache[importPath] ??= lookupLocalPlugin(importPath, root); return localPluginCache[importPath]; @@ -150,12 +150,12 @@ export function resolveLocalNxPlugin( let tsNodeAndPathsRegistered = false; function registerTSTranspiler() { if (!tsNodeAndPathsRegistered) { - registerTsProject(appRootPath, 'tsconfig.base.json'); + registerTsProject(workspaceRoot, 'tsconfig.base.json'); } tsNodeAndPathsRegistered = true; } -function lookupLocalPlugin(importPath: string, root = appRootPath) { +function lookupLocalPlugin(importPath: string, root = workspaceRoot) { const workspace = new Workspaces(root).readWorkspaceConfiguration({ _ignorePluginInference: true, }); @@ -175,7 +175,7 @@ function lookupLocalPlugin(importPath: string, root = appRootPath) { function findNxProjectForImportPath( importPath: string, workspace: WorkspaceJsonConfiguration, - root = appRootPath + root = workspaceRoot ): string | null { const tsConfigPaths: Record = readTsConfigPaths(root); const possiblePaths = tsConfigPaths[importPath]?.map((p) => @@ -208,7 +208,7 @@ function findNxProjectForImportPath( } let tsconfigPaths: Record; -function readTsConfigPaths(root: string = appRootPath) { +function readTsConfigPaths(root: string = workspaceRoot) { if (!tsconfigPaths) { const tsconfigPath: string | null = ['tsconfig.base.json', 'tsconfig.json'] .map((x) => path.join(root, x)) diff --git a/packages/nx/src/utils/plugins/plugin-capabilities.ts b/packages/nx/src/utils/plugins/plugin-capabilities.ts index ee4d775c2c9fa..ffb76b89c230b 100644 --- a/packages/nx/src/utils/plugins/plugin-capabilities.ts +++ b/packages/nx/src/utils/plugins/plugin-capabilities.ts @@ -1,4 +1,4 @@ -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import * as chalk from 'chalk'; import { dirname, join } from 'path'; import { output } from '../output'; @@ -52,7 +52,7 @@ export function getPluginCapabilities( } export function listPluginCapabilities(pluginName: string) { - const plugin = getPluginCapabilities(appRootPath, pluginName); + const plugin = getPluginCapabilities(workspaceRoot, pluginName); if (!plugin) { const pmc = getPackageManagerCommand(); diff --git a/packages/nx/src/utils/typescript.ts b/packages/nx/src/utils/typescript.ts index 51a0fb8a03c14..4d3b160f2addc 100644 --- a/packages/nx/src/utils/typescript.ts +++ b/packages/nx/src/utils/typescript.ts @@ -1,9 +1,9 @@ -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { existsSync } from 'fs'; import { dirname, join } from 'path'; import type * as ts from 'typescript'; -const normalizedAppRoot = appRootPath.replace(/\\/g, '/'); +const normalizedAppRoot = workspaceRoot.replace(/\\/g, '/'); let tsModule: any; @@ -82,7 +82,7 @@ function getCompilerHost(tsConfigPath: string) { const options = readTsConfigOptions(tsConfigPath); const host = tsModule.createCompilerHost(options, true); const moduleResolutionCache = tsModule.createModuleResolutionCache( - appRootPath, + workspaceRoot, host.getCanonicalFileName ); return { options, host, moduleResolutionCache }; @@ -90,7 +90,7 @@ function getCompilerHost(tsConfigPath: string) { export function getRootTsConfigFileName(): string | null { for (const tsConfigName of ['tsconfig.base.json', 'tsconfig.json']) { - const tsConfigPath = join(appRootPath, tsConfigName); + const tsConfigPath = join(workspaceRoot, tsConfigName); if (existsSync(tsConfigPath)) { return tsConfigName; } @@ -102,5 +102,5 @@ export function getRootTsConfigFileName(): string | null { export function getRootTsConfigPath(): string | null { const tsConfigFileName = getRootTsConfigFileName(); - return tsConfigFileName ? join(appRootPath, tsConfigFileName) : null; + return tsConfigFileName ? join(workspaceRoot, tsConfigFileName) : null; } diff --git a/packages/react-native/plugins/metro-resolver.ts b/packages/react-native/plugins/metro-resolver.ts index 11825b32f17ac..0efc7583c9877 100644 --- a/packages/react-native/plugins/metro-resolver.ts +++ b/packages/react-native/plugins/metro-resolver.ts @@ -5,7 +5,7 @@ import * as chalk from 'chalk'; import { CachedInputFileSystem, ResolverFactory } from 'enhanced-resolve'; import { dirname, join } from 'path'; import * as fs from 'fs'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; /* * Use tsconfig to resolve additional workspace libs. @@ -81,7 +81,7 @@ function defaultMetroResolver( function pnpmResolver(extensions, context, realModuleName, moduleName) { const DEBUG = process.env.NX_REACT_NATIVE_DEBUG === 'true'; try { - const pnpmResolver = getPnpmResolver(appRootPath, extensions); + const pnpmResolver = getPnpmResolver(workspaceRoot, extensions); const lookupStartPath = dirname(context.originModulePath); const filePath = pnpmResolver.resolveSync( {}, @@ -178,14 +178,14 @@ function getMatcher() { * It is inspired form https://github.com/vjpr/pnpm-expo-example/blob/main/packages/pnpm-expo-helper/util/make-resolver.js. */ let resolver; -function getPnpmResolver(appRootPath: string, extensions: string[]) { +function getPnpmResolver(workspaceRoot: string, extensions: string[]) { if (!resolver) { const fileSystem = new CachedInputFileSystem(fs, 4000); resolver = ResolverFactory.createResolver({ fileSystem, extensions: extensions.map((extension) => '.' + extension), useSyncFileSystemCalls: true, - modules: [join(appRootPath, 'node_modules'), 'node_modules'], + modules: [join(workspaceRoot, 'node_modules'), 'node_modules'], }); } return resolver; diff --git a/packages/react-native/plugins/with-nx-metro.ts b/packages/react-native/plugins/with-nx-metro.ts index e6ce19e440edb..3fc992348bd04 100644 --- a/packages/react-native/plugins/with-nx-metro.ts +++ b/packages/react-native/plugins/with-nx-metro.ts @@ -1,4 +1,4 @@ -import { appRootPath } from '@nrwl/workspace/src/utils/app-root'; +import { workspaceRoot } from '@nrwl/workspace/src/utils/app-root'; import { getResolveRequest } from './metro-resolver'; interface WithNxOptions { @@ -12,7 +12,7 @@ export function withNxMetro(config: any, opts: WithNxOptions = {}) { if (opts.extensions) extensions.push(...opts.extensions); // Set the root to workspace root so we can resolve modules and assets - config.projectRoot = appRootPath; + config.projectRoot = workspaceRoot; // Add support for paths specified by tsconfig config.resolver = { diff --git a/packages/react/plugins/storybook/index.ts b/packages/react/plugins/storybook/index.ts index e0a6c86c3be33..3abf10f9d4027 100644 --- a/packages/react/plugins/storybook/index.ts +++ b/packages/react/plugins/storybook/index.ts @@ -1,5 +1,5 @@ import { joinPathFragments, readJsonFile } from '@nrwl/devkit'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import { getBaseWebpackPartial } from '@nrwl/web/src/utils/config'; import { getStylesPartial } from '@nrwl/web/src/utils/web.config'; import { checkAndCleanWithSemver } from '@nrwl/workspace/src/utilities/version-utils'; @@ -20,7 +20,7 @@ export const babelDefault = (): Record< // Add babel plugin for styled-components or emotion. // We don't have a good way to know when a project uses one or the other, so // add the plugin only if the other style package isn't used. - const packageJson = readJsonFile(join(appRootPath, 'package.json')); + const packageJson = readJsonFile(join(workspaceRoot, 'package.json')); const deps = { ...packageJson.dependencies, ...packageJson.devDependencies }; const hasStyledComponents = !!deps['styled-components']; @@ -94,7 +94,7 @@ export const webpack = async ( // doesn't work with `@emotion/*` >= v11 // this is a workaround to fix that let resolvedEmotionAliases = {}; - const packageJson = readJsonFile(join(appRootPath, 'package.json')); + const packageJson = readJsonFile(join(workspaceRoot, 'package.json')); const deps = { ...packageJson.dependencies, ...packageJson.devDependencies }; const emotionReactVersion = deps['@emotion/react']; @@ -113,17 +113,17 @@ export const webpack = async ( resolve: { alias: { '@emotion/core': joinPathFragments( - appRootPath, + workspaceRoot, 'node_modules', '@emotion/react' ), '@emotion/styled': joinPathFragments( - appRootPath, + workspaceRoot, 'node_modules', '@emotion/styled' ), 'emotion-theming': joinPathFragments( - appRootPath, + workspaceRoot, 'node_modules', '@emotion/react' ), diff --git a/packages/workspace/src/generators/move/lib/update-project-root-files.ts b/packages/workspace/src/generators/move/lib/update-project-root-files.ts index 53d35695d9cac..366ce6cc737bb 100644 --- a/packages/workspace/src/generators/move/lib/update-project-root-files.ts +++ b/packages/workspace/src/generators/move/lib/update-project-root-files.ts @@ -1,5 +1,5 @@ import { ProjectConfiguration, Tree } from '@nrwl/devkit'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import * as path from 'path'; import { extname, join } from 'path'; import { NormalizedSchema } from '../schema'; @@ -18,13 +18,13 @@ export function updateProjectRootFiles( ) { const newRelativeRoot = path .relative( - path.join(appRootPath, schema.relativeToRootDestination), - appRootPath + path.join(workspaceRoot, schema.relativeToRootDestination), + workspaceRoot ) .split(path.sep) .join('/'); const oldRelativeRoot = path - .relative(path.join(appRootPath, project.root), appRootPath) + .relative(path.join(workspaceRoot, project.root), workspaceRoot) .split(path.sep) .join('/'); diff --git a/packages/workspace/src/generators/move/lib/update-storybook-config.ts b/packages/workspace/src/generators/move/lib/update-storybook-config.ts index 4b1e628b14c31..d448b6f9d1892 100644 --- a/packages/workspace/src/generators/move/lib/update-storybook-config.ts +++ b/packages/workspace/src/generators/move/lib/update-storybook-config.ts @@ -1,5 +1,5 @@ import { ProjectConfiguration, Tree } from '@nrwl/devkit'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import * as path from 'path'; import { join } from 'path'; import { NormalizedSchema } from '../schema'; @@ -15,13 +15,19 @@ export function updateStorybookConfig( project: ProjectConfiguration ) { const oldRelativeRoot = path - .relative(path.join(appRootPath, `${project.root}/.storybook`), appRootPath) + .relative( + path.join(workspaceRoot, `${project.root}/.storybook`), + workspaceRoot + ) .split(path.sep) .join('/'); const newRelativeRoot = path .relative( - path.join(appRootPath, `${schema.relativeToRootDestination}/.storybook`), - appRootPath + path.join( + workspaceRoot, + `${schema.relativeToRootDestination}/.storybook` + ), + workspaceRoot ) .split(path.sep) .join('/'); diff --git a/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.spec.ts b/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.spec.ts index e28a6f8bfd19d..c8f606589eade 100644 --- a/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.spec.ts +++ b/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.spec.ts @@ -8,7 +8,6 @@ import { mapProjectGraphFiles } from '@nrwl/workspace/src/utils/runtime-lint-uti jest.mock('fs', () => require('memfs').fs); jest.mock('nx/src/utils/app-root', () => ({ - appRootPath: '/root', workspaceRoot: '/root', })); diff --git a/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.ts b/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.ts index ee481335e14e5..20c3685d64f49 100644 --- a/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.ts +++ b/packages/workspace/src/tslint/nxEnforceModuleBoundariesRule.ts @@ -5,7 +5,7 @@ import type { NxJsonConfiguration, ProjectGraphExternalNode, } from '@nrwl/devkit'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import { DepConstraint, findConstraintsFor, @@ -46,7 +46,7 @@ export class Rule extends Lint.Rules.AbstractRule { super(options); if (!projectPath) { - this.projectPath = normalize(appRootPath); + this.projectPath = normalize(workspaceRoot); if (!(global as any).projectGraph) { const nxJson = readNxJson(); (global as any).npmScope = nxJson.npmScope; diff --git a/packages/workspace/src/utilities/generate-globs.ts b/packages/workspace/src/utilities/generate-globs.ts index 58e05b0fe73b6..06c81ad310456 100644 --- a/packages/workspace/src/utilities/generate-globs.ts +++ b/packages/workspace/src/utilities/generate-globs.ts @@ -1,5 +1,5 @@ import { joinPathFragments } from '@nrwl/devkit'; -import { appRootPath } from 'nx/src/utils/app-root'; +import { workspaceRoot } from 'nx/src/utils/app-root'; import { relative, resolve } from 'path'; import { readCachedProjectGraph } from 'nx/src/core/project-graph/project-graph'; import { @@ -16,7 +16,7 @@ export function createGlobPatternsForDependencies( dirPath: string, fileGlobPattern: string ): string[] { - const filenameRelativeToWorkspaceRoot = relative(appRootPath, dirPath); + const filenameRelativeToWorkspaceRoot = relative(workspaceRoot, dirPath); const projectGraph = readCachedProjectGraph(); // find the project @@ -40,7 +40,7 @@ export function createGlobPatternsForDependencies( ); return projectDirs.map((sourceDir) => - resolve(appRootPath, joinPathFragments(sourceDir, fileGlobPattern)) + resolve(workspaceRoot, joinPathFragments(sourceDir, fileGlobPattern)) ); } catch (e) { throw new Error( diff --git a/packages/workspace/src/utilities/plugins/plugin-capabilities.ts b/packages/workspace/src/utilities/plugins/plugin-capabilities.ts index 40f0e78e61c55..dd5254e037893 100644 --- a/packages/workspace/src/utilities/plugins/plugin-capabilities.ts +++ b/packages/workspace/src/utilities/plugins/plugin-capabilities.ts @@ -1,5 +1,5 @@ import { getPackageManagerCommand, readJsonFile } from '@nrwl/devkit'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import * as chalk from 'chalk'; import { dirname, join } from 'path'; import { output } from '../output'; @@ -51,7 +51,7 @@ export function getPluginCapabilities( } export function listPluginCapabilities(pluginName: string) { - const plugin = getPluginCapabilities(appRootPath, pluginName); + const plugin = getPluginCapabilities(workspaceRoot, pluginName); if (!plugin) { const pmc = getPackageManagerCommand(); diff --git a/packages/workspace/src/utilities/typescript.ts b/packages/workspace/src/utilities/typescript.ts index cb1c002deb518..a01f8ba1c13fb 100644 --- a/packages/workspace/src/utilities/typescript.ts +++ b/packages/workspace/src/utilities/typescript.ts @@ -1,5 +1,5 @@ import { offsetFromRoot, Tree } from '@nrwl/devkit'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import { existsSync } from 'fs'; import { dirname, join } from 'path'; import type * as ts from 'typescript'; @@ -8,7 +8,7 @@ export type { TypeScriptCompilationOptions } from './typescript/compilation'; export { findNodes } from './typescript/find-nodes'; export { getSourceNodes } from './typescript/get-source-nodes'; -const normalizedAppRoot = appRootPath.replace(/\\/g, '/'); +const normalizedAppRoot = workspaceRoot.replace(/\\/g, '/'); let tsModule: typeof import('typescript'); @@ -90,7 +90,7 @@ function getCompilerHost(tsConfigPath: string) { const options = readTsConfigOptions(tsConfigPath); const host = tsModule.createCompilerHost(options, true); const moduleResolutionCache = tsModule.createModuleResolutionCache( - appRootPath, + workspaceRoot, host.getCanonicalFileName ); return { options, host, moduleResolutionCache }; @@ -115,7 +115,7 @@ export function getRelativePathToRootTsConfig( export function getRootTsConfigFileName(): string | null { for (const tsConfigName of ['tsconfig.base.json', 'tsconfig.json']) { - const tsConfigPath = join(appRootPath, tsConfigName); + const tsConfigPath = join(workspaceRoot, tsConfigName); if (existsSync(tsConfigPath)) { return tsConfigName; } @@ -127,5 +127,5 @@ export function getRootTsConfigFileName(): string | null { export function getRootTsConfigPath(): string | null { const tsConfigFileName = getRootTsConfigFileName(); - return tsConfigFileName ? join(appRootPath, tsConfigFileName) : null; + return tsConfigFileName ? join(workspaceRoot, tsConfigFileName) : null; } diff --git a/packages/workspace/src/utils/app-root.ts b/packages/workspace/src/utils/app-root.ts index 2889f75f59298..c80cb178ba075 100644 --- a/packages/workspace/src/utils/app-root.ts +++ b/packages/workspace/src/utils/app-root.ts @@ -1 +1 @@ -export { appRootPath } from 'nx/src/utils/app-root'; +export { appRootPath, workspaceRoot } from 'nx/src/utils/app-root'; diff --git a/packages/workspace/src/utils/rules/format-files.spec.ts b/packages/workspace/src/utils/rules/format-files.spec.ts index de3c31e525e04..5353c785a00c3 100644 --- a/packages/workspace/src/utils/rules/format-files.spec.ts +++ b/packages/workspace/src/utils/rules/format-files.spec.ts @@ -6,7 +6,7 @@ import * as path from 'path'; import * as nxWorkspace from 'nx/src/shared/workspace'; import { formatFiles } from './format-files'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; describe('formatFiles', () => { let tree: Tree; @@ -64,7 +64,7 @@ describe('formatFiles', () => { .toPromise(); expect(prettier.format).toHaveBeenCalledWith('const a=a', { printWidth: 80, - filepath: path.join(appRootPath, 'a.ts'), + filepath: path.join(workspaceRoot, 'a.ts'), }); expect(result.read('a.ts').toString()).toEqual('formatted :: const a=a'); }); @@ -94,7 +94,7 @@ describe('formatFiles', () => { .callRule(formatFiles(), tree) .toPromise(); expect(prettier.format).toHaveBeenCalledWith('const a=b', { - filepath: path.join(appRootPath, 'a.ts'), + filepath: path.join(workspaceRoot, 'a.ts'), }); expect(result.read('a.ts').toString()).toEqual('formatted :: const a=b'); }); @@ -109,7 +109,7 @@ describe('formatFiles', () => { .callRule(formatFiles(), tree) .toPromise(); expect(prettier.format).toHaveBeenCalledWith('const a=a', { - filepath: path.join(appRootPath, 'b.ts'), + filepath: path.join(workspaceRoot, 'b.ts'), }); expect(result.read('b.ts').toString()).toEqual('formatted :: const a=a'); }); @@ -144,7 +144,7 @@ describe('formatFiles', () => { .toPromise(); expect(prettier.format).not.toHaveBeenCalledWith('const a=a', { printWidth: 80, - filepath: `${appRootPath}/a.ts`, + filepath: `${workspaceRoot}/a.ts`, }); expect(result.read('a.ts').toString()).toEqual('const a=a'); }); diff --git a/packages/workspace/src/utils/rules/format-files.ts b/packages/workspace/src/utils/rules/format-files.ts index 9447fc1f396b5..ee5777c17f847 100644 --- a/packages/workspace/src/utils/rules/format-files.ts +++ b/packages/workspace/src/utils/rules/format-files.ts @@ -9,7 +9,7 @@ import { import { from } from 'rxjs'; import { filter, map, mergeMap } from 'rxjs/operators'; import * as path from 'path'; -import { appRootPath } from '@nrwl/devkit'; +import { workspaceRoot } from '@nrwl/devkit'; import { reformattedWorkspaceJsonOrNull, workspaceConfigName, @@ -50,7 +50,7 @@ export function formatFiles( return from(files).pipe( filter((file) => host.exists(file.path)), mergeMap(async (file) => { - const systemPath = path.join(appRootPath, file.path); + const systemPath = path.join(workspaceRoot, file.path); let options: any = { filepath: systemPath, }; @@ -80,7 +80,7 @@ export function formatFiles( } function updateWorkspaceJsonToMatchFormatVersion(host: Tree) { - const workspaceConfigPath = workspaceConfigName(appRootPath); + const workspaceConfigPath = workspaceConfigName(workspaceRoot); try { if (workspaceConfigPath) { diff --git a/packages/workspace/src/utils/runtime-lint-utils.ts b/packages/workspace/src/utils/runtime-lint-utils.ts index 44ed489b720eb..a5367d5bb6239 100644 --- a/packages/workspace/src/utils/runtime-lint-utils.ts +++ b/packages/workspace/src/utils/runtime-lint-utils.ts @@ -11,7 +11,7 @@ import { FileData, } from '@nrwl/devkit'; import { join } from 'path'; -import { appRootPath } from './app-root'; +import { workspaceRoot } from './app-root'; import { getPath, pathExists } from './graph-utils'; import { existsSync } from 'fs'; import { readFileIfExisting } from 'nx/src/core/file-utils'; @@ -236,7 +236,7 @@ export function hasBannedImport( export function isDirectDependency(target: ProjectGraphExternalNode): boolean { const fileName = 'package.json'; - const content = readFileIfExisting(join(appRootPath, fileName)); + const content = readFileIfExisting(join(workspaceRoot, fileName)); if (content) { const { dependencies, devDependencies, peerDependencies } = parseJson(content);