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(core): add support for bun pack #27820

Open
wants to merge 1 commit 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 @@ -26,6 +26,7 @@ export interface PackageManagerCommands {
exec: string;
dlx: string;
list: string;
pack: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been added but i'm not sure if a better name can be used. bun uses bun install at top level and bunx but rest of its package manager commands is at bun pm level

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 @@ -115,6 +116,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 @@ -148,6 +158,7 @@ export function getPackageManagerCommand(
}`,
list: 'pnpm ls --depth 100',
getRegistryUrl: 'pnpm config get registry',
pack: 'pnpm pack',
};
},
npm: () => {
Expand All @@ -167,9 +178,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 @@ -182,6 +202,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 @@ -456,21 +477,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