fix(core): pnpm should not error when fetching migrations with install

This commit is contained in:
AgentEnder 2023-05-18 11:58:39 -04:00 committed by Victor Savkin
parent d786fae2d0
commit faba24995d
4 changed files with 17 additions and 11 deletions

View File

@ -1351,7 +1351,7 @@ Returns the list of outputs that will be cached.
### getPackageManagerCommand ### getPackageManagerCommand
**getPackageManagerCommand**(`packageManager?`): `PackageManagerCommands` **getPackageManagerCommand**(`packageManager?`, `root?`): `PackageManagerCommands`
Returns commands for the package manager used in the workspace. Returns commands for the package manager used in the workspace.
By default, the package manager is derived based on the lock file, By default, the package manager is derived based on the lock file,
@ -1365,9 +1365,10 @@ execSync(`${getPackageManagerCommand().addDev} my-dev-package`);
#### Parameters #### Parameters
| Name | Type | | Name | Type | Default value | Description |
| :--------------- | :------------------------------------------------------------------ | | :--------------- | :------------------------------------------------------------------ | :-------------- | :------------------------------------------------------------------------------------------ |
| `packageManager` | [`PackageManager`](../../devkit/documents/nx_devkit#packagemanager) | | `packageManager` | [`PackageManager`](../../devkit/documents/nx_devkit#packagemanager) | `undefined` | The package manager to use. If not provided, it will be detected based on the lock file. |
| `root` | `string` | `workspaceRoot` | The directory the commands will be ran inside of. Defaults to the current workspace's root. |
#### Returns #### Returns

View File

@ -1351,7 +1351,7 @@ Returns the list of outputs that will be cached.
### getPackageManagerCommand ### getPackageManagerCommand
**getPackageManagerCommand**(`packageManager?`): `PackageManagerCommands` **getPackageManagerCommand**(`packageManager?`, `root?`): `PackageManagerCommands`
Returns commands for the package manager used in the workspace. Returns commands for the package manager used in the workspace.
By default, the package manager is derived based on the lock file, By default, the package manager is derived based on the lock file,
@ -1365,9 +1365,10 @@ execSync(`${getPackageManagerCommand().addDev} my-dev-package`);
#### Parameters #### Parameters
| Name | Type | | Name | Type | Default value | Description |
| :--------------- | :------------------------------------------------------------------ | | :--------------- | :------------------------------------------------------------------ | :-------------- | :------------------------------------------------------------------------------------------ |
| `packageManager` | [`PackageManager`](../../devkit/documents/nx_devkit#packagemanager) | | `packageManager` | [`PackageManager`](../../devkit/documents/nx_devkit#packagemanager) | `undefined` | The package manager to use. If not provided, it will be detected based on the lock file. |
| `root` | `string` | `workspaceRoot` | The directory the commands will be ran inside of. Defaults to the current workspace's root. |
#### Returns #### Returns

View File

@ -1028,7 +1028,7 @@ async function getPackageMigrationsUsingInstall(
let result: ResolvedMigrationConfiguration; let result: ResolvedMigrationConfiguration;
try { try {
const pmc = getPackageManagerCommand(detectPackageManager(dir)); const pmc = getPackageManagerCommand(detectPackageManager(dir), dir);
await execAsync(`${pmc.add} ${packageName}@${packageVersion}`, { await execAsync(`${pmc.add} ${packageName}@${packageVersion}`, {
cwd: dir, cwd: dir,

View File

@ -50,9 +50,13 @@ export function detectPackageManager(dir: string = ''): PackageManager {
* ```javascript * ```javascript
* execSync(`${getPackageManagerCommand().addDev} my-dev-package`); * execSync(`${getPackageManagerCommand().addDev} my-dev-package`);
* ``` * ```
*
* @param packageManager The package manager to use. If not provided, it will be detected based on the lock file.
* @param root The directory the commands will be ran inside of. Defaults to the current workspace's root.
*/ */
export function getPackageManagerCommand( export function getPackageManagerCommand(
packageManager: PackageManager = detectPackageManager() packageManager: PackageManager = detectPackageManager(),
root: string = workspaceRoot
): PackageManagerCommands { ): PackageManagerCommands {
const commands: { [pm in PackageManager]: () => PackageManagerCommands } = { const commands: { [pm in PackageManager]: () => PackageManagerCommands } = {
yarn: () => { yarn: () => {
@ -76,7 +80,7 @@ export function getPackageManagerCommand(
const pnpmVersion = getPackageManagerVersion('pnpm'); const pnpmVersion = getPackageManagerVersion('pnpm');
const useExec = gte(pnpmVersion, '6.13.0'); const useExec = gte(pnpmVersion, '6.13.0');
const includeDoubleDashBeforeArgs = lt(pnpmVersion, '7.0.0'); const includeDoubleDashBeforeArgs = lt(pnpmVersion, '7.0.0');
const isPnpmWorkspace = existsSync('pnpm-workspace.yaml'); const isPnpmWorkspace = existsSync(join(root, 'pnpm-workspace.yaml'));
return { return {
install: 'pnpm install --no-frozen-lockfile', // explicitly disable in case of CI install: 'pnpm install --no-frozen-lockfile', // explicitly disable in case of CI