diff --git a/packages/monorepo/src/projects/typescript/monorepo-ts.ts b/packages/monorepo/src/projects/typescript/monorepo-ts.ts index 747307a04..a62e52cf4 100644 --- a/packages/monorepo/src/projects/typescript/monorepo-ts.ts +++ b/packages/monorepo/src/projects/typescript/monorepo-ts.ts @@ -514,6 +514,7 @@ export class MonorepoTsProject this.validateSubProjects(); this.updateWorkspace(); this.installNonNodeDependencies(); + this.resolveLocalBunDependencies(); // Disable node warnings if configured if (this._options.disableNodeWarnings) { @@ -689,6 +690,45 @@ export class MonorepoTsProject subProject.tasks.addEnvironment("NODE_NO_WARNINGS", "1") ); } + + /** + * Resolve all local workspace dependencies to keep bun happy. + */ + private resolveLocalBunDependencies(): void { + if (this.package.packageManager !== NodePackageManager.BUN) { + return; + } + + const nodeSubProjectNames = new Set( + this.subprojects + .filter((s) => NodePackageUtils.isNodeProject(s)) + .map((s) => (s as NodeProject).package.packageName) + ); + + this.subprojects.forEach((subProject) => { + if (NodePackageUtils.isNodeProject(subProject)) { + subProject.deps.all + .filter((dep) => nodeSubProjectNames.has(dep.name)) + .forEach((d) => { + switch (d.type) { + case DependencyType.RUNTIME: + subProject.addDeps(`${d.name}@workspace:*`); + break; + case DependencyType.BUILD: + subProject.addDevDeps(`${d.name}@workspace:*`); + break; + case DependencyType.PEER: + subProject.addPeerDeps(`${d.name}@workspace:*`); + break; + default: + console.warn( + `Cannot update local dependency due to unsupported type: ${d.type}` + ); + } + }); + } + }); + } } /** diff --git a/packages/pdk/_scripts/exec-command.js b/packages/pdk/_scripts/exec-command.js index 62634b0f0..1e8780dbb 100755 --- a/packages/pdk/_scripts/exec-command.js +++ b/packages/pdk/_scripts/exec-command.js @@ -6,6 +6,7 @@ const { sync } = require("find-up"); process.argv.splice(0, 2); const isSynth = process.argv.filter(p => !p.startsWith("--")).length === 0; +const isInstall = process.argv[0] === "install"; if (process.argv[0] == "new") { execa.commandSync(`npx --yes projen@latest new --from @aws/pdk ${process.argv.slice(1).join(" ")}`, { stdio: "inherit" }); @@ -27,7 +28,7 @@ const engines = JSON.parse( ).engines; if (engines) { - let pkgMgrCmd = engines.pnpm ? "pnpm" : engines.yarn ? "yarn" : engines.bun ? "bun" : "npm run"; + let pkgMgrCmd = engines.pnpm ? "pnpm" : engines.yarn ? "yarn" : engines.bun ? `bun${isInstall ? '' : ' run'}` : "npm run"; // Deploy is a pnpm command, but it's more likely users want to run the deploy task if (engines.pnpm && process.argv[0] === "deploy") {