Skip to content

Commit

Permalink
fix(js): add dlx to pm commands (#19743)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav authored Oct 30, 2023
1 parent 44f2f0c commit 936b814
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions packages/nx/src/utils/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface PackageManagerCommands {
addDev: string;
rm: string;
exec: string;
dlx: string;
list: string;
run: (script: string, args: string) => string;
}
Expand Down Expand Up @@ -74,13 +75,14 @@ export function getPackageManagerCommand(
addDev: useBerry ? 'yarn add -D' : 'yarn add -D -W',
rm: 'yarn remove',
exec: 'yarn',
dlx: useBerry ? 'yarn dlx' : 'yarn',
run: (script: string, args: string) => `yarn ${script} ${args}`,
list: useBerry ? 'yarn info --name-only' : 'yarn list',
};
},
pnpm: () => {
const pnpmVersion = getPackageManagerVersion('pnpm', root);
const useExec = gte(pnpmVersion, '6.13.0');
const modernPnpm = gte(pnpmVersion, '6.13.0');
const includeDoubleDashBeforeArgs = lt(pnpmVersion, '7.0.0');
const isPnpmWorkspace = existsSync(join(root, 'pnpm-workspace.yaml'));

Expand All @@ -90,7 +92,8 @@ export function getPackageManagerCommand(
add: isPnpmWorkspace ? 'pnpm add -w' : 'pnpm add',
addDev: isPnpmWorkspace ? 'pnpm add -Dw' : 'pnpm add -D',
rm: 'pnpm rm',
exec: useExec ? 'pnpm exec' : 'pnpx',
exec: modernPnpm ? 'pnpm exec' : 'pnpx',
dlx: modernPnpm ? 'pnpm dlx' : 'pnpx',
run: (script: string, args: string) =>
includeDoubleDashBeforeArgs
? `pnpm run ${script} -- ${args}`
Expand All @@ -109,6 +112,7 @@ export function getPackageManagerCommand(
addDev: 'npm install -D',
rm: 'npm rm',
exec: 'npx',
dlx: 'npx',
run: (script: string, args: string) => `npm run ${script} -- ${args}`,
list: 'npm ls',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function callUpgrade(schema: Schema): 1 | Buffer {
});

execSync(
`${pm.exec} storybook@latest upgrade ${
`${pm.dlx} storybook@latest upgrade ${
schema.autoAcceptAllPrompts ? '--yes' : ''
}`,
{
Expand Down Expand Up @@ -73,7 +73,7 @@ export function callAutomigrate(
Object.entries(allStorybookProjects).forEach(
([projectName, storybookProjectInfo]) => {
const pm = getPackageManagerCommand();
const commandToRun = `${pm.exec} storybook@latest automigrate --config-dir ${storybookProjectInfo.configDir} --renderer ${storybookProjectInfo.uiFramework}`;
const commandToRun = `${pm.dlx} storybook@latest automigrate --config-dir ${storybookProjectInfo.configDir} --renderer ${storybookProjectInfo.uiFramework}`;
try {
output.log({
title: `Calling sb automigrate for ${projectName}`,
Expand Down

0 comments on commit 936b814

Please sign in to comment.