Skip to content

Commit

Permalink
fix(monorepo): ensure bun local deps resolve to workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
agdimech committed Nov 6, 2023
1 parent 3b6509f commit ca373d0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
40 changes: 40 additions & 0 deletions packages/monorepo/src/projects/typescript/monorepo-ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ export class MonorepoTsProject
this.validateSubProjects();
this.updateWorkspace();
this.installNonNodeDependencies();
this.resolveLocalBunDependencies();

// Disable node warnings if configured
if (this._options.disableNodeWarnings) {
Expand Down Expand Up @@ -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}`
);
}
});
}
});
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/pdk/_scripts/exec-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
Expand All @@ -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") {
Expand Down

0 comments on commit ca373d0

Please sign in to comment.