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

Feat support bun pack #29426

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
37 changes: 23 additions & 14 deletions packages/nx/src/utils/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface PackageManagerCommands {
exec: string;
dlx: string;
list: string;
pack: string;
run: (script: string, args?: string) => string;
// Make this required once bun adds programatically support for reading config https://github.com/oven-sh/bun/issues/7140
getRegistryUrl?: string;
Expand Down Expand Up @@ -130,6 +131,15 @@ export function getPackageManagerCommand(
getRegistryUrl: useBerry
? 'yarn config get npmRegistryServer'
: 'yarn config get registry',
/**
* `(p)npm pack` will download a tarball of the specified version,
* whereas `yarn` pack creates a tarball of the active workspace, so it
* does not work for getting the content of a library.
*
* @see https://github.com/nrwl/nx/pull/9667#discussion_r842553994
*
*/
pack: 'npm pack',
};
},
pnpm: () => {
Expand Down Expand Up @@ -163,6 +173,7 @@ export function getPackageManagerCommand(
}`,
list: 'pnpm ls --depth 100',
getRegistryUrl: 'pnpm config get registry',
pack: 'pnpm pack',
};
},
npm: () => {
Expand All @@ -182,9 +193,18 @@ export function getPackageManagerCommand(
`npm run ${script}${args ? ' -- ' + args : ''}`,
list: 'npm ls',
getRegistryUrl: 'npm config get registry',
pack: 'npm pack',
};
},
bun: () => {
let supportPack: boolean;
try {
const bunVersion = getPackageManagerVersion('bun', root);
supportPack = gte(bunVersion, '1.1.27');
} catch {
// as its just been release lets fallback on npm
supportPack = false;
}
// bun doesn't current support programatically reading config https://github.com/oven-sh/bun/issues/7140
return {
install: 'bun install',
Expand All @@ -197,6 +217,7 @@ export function getPackageManagerCommand(
dlx: 'bunx',
run: (script: string, args: string) => `bun run ${script} -- ${args}`,
list: 'bun pm ls',
pack: supportPack ? 'bun pm pack' : 'npm pack',
};
},
};
Expand Down Expand Up @@ -471,21 +492,9 @@ export async function packageRegistryPack(
pkg: string,
version: string
): Promise<{ tarballPath: string }> {
let pm = detectPackageManager();
if (pm === 'yarn' || pm === 'bun') {
/**
* `(p)npm pack` will download a tarball of the specified version,
* whereas `yarn` pack creates a tarball of the active workspace, so it
* does not work for getting the content of a library.
*
* @see https://github.com/nrwl/nx/pull/9667#discussion_r842553994
*
* bun doesn't currently support pack
*/
pm = 'npm';
}
const pmc = getPackageManagerCommand();

const { stdout } = await execAsync(`${pm} pack ${pkg}@${version}`, {
const { stdout } = await execAsync(`${pmc.pack} ${pkg}@${version}`, {
cwd,
windowsHide: true,
});
Expand Down
Loading