Skip to content

Commit ce28263

Browse files
committed
feat(bundle): re-use deno bundle !
1 parent 2601d8e commit ce28263

2 files changed

Lines changed: 300 additions & 46 deletions

File tree

bundle.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import * as esbuild from "npm:esbuild@0.20.2";
2-
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@0.11.0";
31

4-
5-
6-
const bundleFolderExists = (folder: string) =>
2+
const bundleFolderExists = (folder: string): Promise<boolean> =>
73
Deno.stat(folder)
84
.then(() => true)
95
.catch(() => false);
@@ -12,22 +8,25 @@ export const bundleProject = async (
128
options: { entrypoint: string, bundlePath?: string},
139
name: string,
1410
) => {
15-
if (!options.bundlePath)
16-
options.bundlePath = './bundle';
11+
if (!options.bundlePath)
12+
options.bundlePath = './bundle';
1713
if (await bundleFolderExists(options.bundlePath)) {
1814
await Deno.remove(options.bundlePath, { recursive: true });
1915
}
2016

2117
await Deno.mkdir(options.bundlePath);
2218

23-
await esbuild.build({
24-
plugins: [...denoPlugins({ loader: 'native'})],
25-
entryPoints: [options.entrypoint],
26-
outfile: `${options.bundlePath}/${name}`,
27-
bundle: true,
28-
format: "esm",
29-
tsconfig: "tsconfig.json",
19+
20+
const bundleCommand = new Deno.Command("deno", {
21+
args: [ 'bundle', options.entrypoint],
22+
stdout: "piped",
3023
});
24+
const child = bundleCommand.spawn();
25+
26+
// open a file and pipe the subprocess output to it.
27+
child.stdout.pipeTo(
28+
Deno.openSync(`${options.bundlePath}/${name}`, { write: true, create: true }).writable,
29+
);
3130

32-
esbuild.stop();
31+
await child.status;
3332
};

0 commit comments

Comments
 (0)