Skip to content

Commit

Permalink
feat: add support for Bun (#631)
Browse files Browse the repository at this point in the history
fix #576
  • Loading branch information
agdimech authored Nov 2, 2023
1 parent d76ffc5 commit ae0177e
Show file tree
Hide file tree
Showing 13 changed files with 2,388 additions and 571 deletions.
5 changes: 1 addition & 4 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 8 additions & 5 deletions packages/monorepo/src/projects/typescript/monorepo-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ export class MonorepoTsProject
devDeps: ["nx@^16", "@aws/pdk@^0", ...(options.devDeps || [])],
deps: [
"aws-cdk-lib",
"constructs",
"cdk-nag",
"@aws-cdk/aws-cognito-identitypool-alpha",
"@aws-cdk/aws-cognito-identitypool-alpha@latest",
...(options.deps || []),
],
});
Expand All @@ -190,6 +189,10 @@ export class MonorepoTsProject
// engines
this.package.addEngine("node", ">=16");
switch (this.package.packageManager) {
case NodePackageManager.BUN: {
this.package.addEngine("bun", ">=1");
break;
}
case NodePackageManager.PNPM: {
// https://pnpm.io/package_json
// https://github.com/pnpm/pnpm/releases/tag/v8.0.0
Expand Down Expand Up @@ -408,9 +411,9 @@ export class MonorepoTsProject
public addWorkspacePackages(...packageGlobs: string[]) {
// Any subprojects that were added since the last call to this method need to be added first, in order to ensure
// we add the workspace packages in a sane order.
const relativeSubProjectWorkspacePackages = this.sortedSubProjects.map(
(project) => path.relative(this.outdir, project.outdir)
);
const relativeSubProjectWorkspacePackages = this.sortedSubProjects
.filter((s) => ProjectUtils.isNamedInstanceOf(s, NodeProject))
.map((project) => path.relative(this.outdir, project.outdir));
const existingWorkspacePackages = new Set(this.workspacePackages);
this.workspacePackages.push(
...relativeSubProjectWorkspacePackages.filter(
Expand Down
35 changes: 12 additions & 23 deletions packages/monorepo/src/utils/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ export namespace NodePackageUtils {
return withArgs("yarn run", args);
case NodePackageManager.PNPM:
return withArgs("pnpm run", args);
case NodePackageManager.BUN:
return withArgs("bun run", args);
default:
return withArgs("npm run", args);
}
Expand Down Expand Up @@ -156,6 +158,8 @@ export namespace NodePackageUtils {
return withArgs("yarn exec", args);
case NodePackageManager.PNPM:
return withArgs("pnpm exec", args);
case NodePackageManager.BUN:
return withArgs("bun x", args);
default:
return withArgs("npx", args);
}
Expand All @@ -174,6 +178,8 @@ export namespace NodePackageUtils {
return withArgs("yarn dlx", args);
case NodePackageManager.PNPM:
return withArgs("pnpm dlx", args);
case NodePackageManager.BUN:
return withArgs("bun x", args);
default:
return withArgs("npx", args);
}
Expand All @@ -193,6 +199,8 @@ export namespace NodePackageUtils {
return withArgs("yarn install", args);
case NodePackageManager.PNPM:
return withArgs("pnpm i", args);
case NodePackageManager.BUN:
return withArgs("bun install", args);
default:
return withArgs("npm install", args);
}
Expand All @@ -213,33 +221,13 @@ export namespace NodePackageUtils {
return withArgs("yarn", args);
case NodePackageManager.PNPM:
return withArgs("pnpm", args);
case NodePackageManager.BUN:
return withArgs("bun", args);
default:
return withArgs("npm", args);
}
}

export function execInWorkspace(
packageManager: NodePackageManager,
packageName: string,
...args: string[]
) {
switch (packageManager) {
case NodePackageManager.YARN:
case NodePackageManager.YARN2:
case NodePackageManager.YARN_CLASSIC:
case NodePackageManager.YARN_BERRY:
return withArgs("yarn workspace", [packageName, ...args]);
case NodePackageManager.PNPM:
return withArgs("pnpm", [
`--filter "${packageName}"`,
"exec",
...args,
]);
default:
return withArgs("npx", ["-p", packageName, ...args]);
}
}

/**
* Get bash command for executing an executable in the package manager /bin dir.
* Example: `$(yarn bin)/${cmd}`
Expand All @@ -256,8 +244,9 @@ export namespace NodePackageUtils {
return `$(yarn bin)/${_cmd}`;
case NodePackageManager.PNPM:
return `$(pnpm bin)/${_cmd}`;
case NodePackageManager.BUN:
default:
return `$(npm bin)/${_cmd}`;
return `$(npm root)/.bin/${_cmd}`;
}
}
}
Expand Down
Loading

0 comments on commit ae0177e

Please sign in to comment.