Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): add dlx to pm commands #19743

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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