Skip to content

Commit f51c30b

Browse files
committed
fix: externalized deps
1 parent 20ea485 commit f51c30b

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

.changeset/metal-frogs-kneel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bomb.sh/tools": patch
3+
---
4+
5+
Fixes externalized dependency bundling and properly handles rewriting for local `.ts` modules

src/commands/build.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { rm } from "node:fs/promises";
2-
import { build as esbuild } from "esbuild";
2+
import { type Plugin, build as esbuild } from "esbuild";
33
import type { CommandContext } from "../context.ts";
44
import { getPackageJSON } from "../utils.ts";
55

@@ -8,6 +8,7 @@ export async function build(ctx: CommandContext) {
88
await rm("dist", { recursive: true, force: true });
99
await esbuild({
1010
entryPoints: ["src/*", "src/**/*"],
11+
plugins: [ts()],
1112
outdir: "dist",
1213
platform: "node",
1314
format: "esm",
@@ -21,3 +22,15 @@ export async function build(ctx: CommandContext) {
2122
process.exit(1);
2223
});
2324
}
25+
26+
function ts(): Plugin {
27+
return {
28+
name: 'ts',
29+
setup(build) {
30+
build.onResolve({ filter: /\.tsx?$/ }, args => {
31+
return { path: args.path.replace(/\.tsx?$/, '.js'), external: true }
32+
})
33+
},
34+
}
35+
}
36+

src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { cwd } from "node:process";
12
import { fileURLToPath, pathToFileURL } from "node:url";
23
import escalade from "escalade";
34

@@ -8,7 +9,7 @@ export function local(file: string) {
89
}
910

1011
export async function getPackageJSON() {
11-
const pkg = await escalade(fileURLToPath(import.meta.url), (dir, files) => {
12+
const pkg = await escalade(cwd(), (dir, files) => {
1213
return files.find((file) => file === "package.json");
1314
});
1415
if (!pkg) {

0 commit comments

Comments
 (0)