From 48b08a14d298b2f2a17066e04b0a57b91c843569 Mon Sep 17 00:00:00 2001 From: Miroslav Jonas Date: Mon, 3 Apr 2023 17:53:02 +0200 Subject: [PATCH] feat(core): include PR review notes --- docs/generated/devkit/nrwl_devkit.md | 9 ++++----- .../packages/devkit/documents/nrwl_devkit.md | 9 ++++----- .../src/create-nx-workspace-npm.test.ts | 13 +++++-------- packages/devkit/src/utils/package-json.ts | 18 +++++++++--------- packages/nx/src/utils/package-manager.ts | 6 ++---- 5 files changed, 24 insertions(+), 31 deletions(-) diff --git a/docs/generated/devkit/nrwl_devkit.md b/docs/generated/devkit/nrwl_devkit.md index 71c85e0c724a16..a253317955679d 100644 --- a/docs/generated/devkit/nrwl_devkit.md +++ b/docs/generated/devkit/nrwl_devkit.md @@ -1433,7 +1433,7 @@ Returns the list of outputs that will be cached. ### getPackageManagerCommand -▸ **getPackageManagerCommand**(`packageManager?`, `root?`): `PackageManagerCommands` +▸ **getPackageManagerCommand**(`packageManager?`): `PackageManagerCommands` Returns commands for the package manager used in the workspace. By default, the package manager is derived based on the lock file, @@ -1447,10 +1447,9 @@ execSync(`${getPackageManagerCommand().addDev} my-dev-package`); #### Parameters -| Name | Type | Default value | -| :--------------- | :-------------------------------------------------------------------- | :-------------- | -| `packageManager` | [`PackageManager`](../../devkit/documents/nrwl_devkit#packagemanager) | `undefined` | -| `root` | `string` | `workspaceRoot` | +| Name | Type | +| :--------------- | :-------------------------------------------------------------------- | +| `packageManager` | [`PackageManager`](../../devkit/documents/nrwl_devkit#packagemanager) | #### Returns diff --git a/docs/generated/packages/devkit/documents/nrwl_devkit.md b/docs/generated/packages/devkit/documents/nrwl_devkit.md index 71c85e0c724a16..a253317955679d 100644 --- a/docs/generated/packages/devkit/documents/nrwl_devkit.md +++ b/docs/generated/packages/devkit/documents/nrwl_devkit.md @@ -1433,7 +1433,7 @@ Returns the list of outputs that will be cached. ### getPackageManagerCommand -▸ **getPackageManagerCommand**(`packageManager?`, `root?`): `PackageManagerCommands` +▸ **getPackageManagerCommand**(`packageManager?`): `PackageManagerCommands` Returns commands for the package manager used in the workspace. By default, the package manager is derived based on the lock file, @@ -1447,10 +1447,9 @@ execSync(`${getPackageManagerCommand().addDev} my-dev-package`); #### Parameters -| Name | Type | Default value | -| :--------------- | :-------------------------------------------------------------------- | :-------------- | -| `packageManager` | [`PackageManager`](../../devkit/documents/nrwl_devkit#packagemanager) | `undefined` | -| `root` | `string` | `workspaceRoot` | +| Name | Type | +| :--------------- | :-------------------------------------------------------------------- | +| `packageManager` | [`PackageManager`](../../devkit/documents/nrwl_devkit#packagemanager) | #### Returns diff --git a/e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts b/e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts index 2bda0d9fecd001..98c5e134478478 100644 --- a/e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts +++ b/e2e/workspace-create-npm/src/create-nx-workspace-npm.test.ts @@ -1,8 +1,6 @@ import { checkFilesExist, cleanupProject, - e2eCwd, - getPackageManagerCommand, getSelectedPackageManager, packageInstall, readJson, @@ -11,15 +9,16 @@ import { runCreateWorkspace, uniq, } from '@nrwl/e2e/utils'; -import { execSync } from 'child_process'; describe('create-nx-workspace --preset=npm', () => { const wsName = uniq('npm'); - let originalVerbose; + let originalVerbose, originalDaemon; beforeAll(() => { originalVerbose = process.env.NX_VERBOSE_LOGGING; + originalDaemon = process.env.NX_DAEMON; process.env.NX_VERBOSE_LOGGING = 'true'; + process.env.NX_DAEMON = 'false'; runCreateWorkspace(wsName, { preset: 'npm', packageManager: getSelectedPackageManager(), @@ -28,14 +27,12 @@ describe('create-nx-workspace --preset=npm', () => { afterEach(() => { runCommand(`git reset --hard HEAD`); - execSync(`${getPackageManagerCommand().runNx} reset`, { - cwd: `${e2eCwd}/${wsName}`, - stdio: 'pipe', - }); + runCommand(`git clean -fdx`); }); afterAll(() => { process.env.NX_VERBOSE_LOGGING = originalVerbose; + process.env.NX_DAEMON = originalDaemon; cleanupProject({ skipReset: true }); }); diff --git a/packages/devkit/src/utils/package-json.ts b/packages/devkit/src/utils/package-json.ts index 8a427e627975c9..8632ba5dc22523 100644 --- a/packages/devkit/src/utils/package-json.ts +++ b/packages/devkit/src/utils/package-json.ts @@ -454,15 +454,15 @@ export function ensurePackage( console.log(`Fetching ${pkg}...`); const isVerbose = process.env.NX_VERBOSE_LOGGING === 'true'; - execSync( - `${ - getPackageManagerCommand(detectPackageManager(), tempDir).addDev - } ${pkg}@${requiredVersion}`, - { - cwd: tempDir, - stdio: isVerbose ? 'inherit' : 'ignore', - } - ); + const packageManager = detectPackageManager(); + const addCommand = + packageManager === 'pnpm' + ? 'pnpm add -D' + : getPackageManagerCommand(packageManager).addDev; + execSync(`${addCommand} ${pkg}@${requiredVersion}`, { + cwd: tempDir, + stdio: isVerbose ? 'inherit' : 'ignore', + }); addToNodePath(join(workspaceRoot, 'node_modules')); addToNodePath(join(tempDir, 'node_modules')); diff --git a/packages/nx/src/utils/package-manager.ts b/packages/nx/src/utils/package-manager.ts index 6156b422de4901..c41165b979aee2 100644 --- a/packages/nx/src/utils/package-manager.ts +++ b/packages/nx/src/utils/package-manager.ts @@ -7,7 +7,6 @@ import { promisify } from 'util'; import { writeJsonFile } from './fileutils'; import { readModulePackageJson } from './package-json'; import { gte, lt } from 'semver'; -import { workspaceRoot } from './workspace-root'; const execAsync = promisify(exec); @@ -47,8 +46,7 @@ export function detectPackageManager(dir: string = ''): PackageManager { * ``` */ export function getPackageManagerCommand( - packageManager: PackageManager = detectPackageManager(), - root: string = workspaceRoot + packageManager: PackageManager = detectPackageManager() ): PackageManagerCommands { const commands: { [pm in PackageManager]: () => PackageManagerCommands } = { yarn: () => { @@ -72,7 +70,7 @@ export function getPackageManagerCommand( const pnpmVersion = getPackageManagerVersion('pnpm'); const useExec = gte(pnpmVersion, '6.13.0'); const includeDoubleDashBeforeArgs = lt(pnpmVersion, '7.0.0'); - const isPnpmWorkspace = existsSync(join(root, 'pnpm-workspace.yaml')); + const isPnpmWorkspace = existsSync('pnpm-workspace.yaml'); return { install: 'pnpm install --no-frozen-lockfile', // explicitly disable in case of CI