Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 5e72c0e

Browse files
committed
Fix build/start command
1 parent dbbcab3 commit 5e72c0e

File tree

4 files changed

+83
-8
lines changed

4 files changed

+83
-8
lines changed

cli.ts

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,21 @@ type RunOptions = {
168168

169169
async function run(command: string, options: RunOptions) {
170170
const { version, isCanary, denoConfigFile, importMapFile } = options;
171-
const rwDirs = [".", Deno.env.get("MODULES_CACHE_DIR"), Deno.env.get("ALEPH_DEV_ROOT")].filter(Boolean);
171+
const { esbuildBinDir, esbuildBinPath } = getEsbuildPath("0.14.36");
172+
const rwDirs = [
173+
".",
174+
Deno.env.get("MODULES_CACHE_DIR"),
175+
Deno.env.get("ALEPH_DEV_ROOT"),
176+
esbuildBinDir,
177+
].filter(Boolean);
172178
const cmd: string[] = [
173179
Deno.execPath(),
174180
"run",
175181
"--allow-env",
176182
"--allow-net",
177183
"--allow-read=" + rwDirs.join(","),
178184
"--allow-write=" + rwDirs.join(","),
179-
"--allow-hrtime",
185+
"--allow-run=" + esbuildBinPath,
180186
"--location=http://localhost",
181187
"--no-check",
182188
];
@@ -231,6 +237,70 @@ function fixLine(line: string): string | null {
231237
return line;
232238
}
233239

240+
function getEsbuildPath(version: string) {
241+
let name: string;
242+
let baseDir: string | undefined;
243+
switch (Deno.build.os) {
244+
case "darwin": {
245+
baseDir = Deno.env.get("HOME");
246+
if (baseDir) {
247+
baseDir += "/Library/Caches";
248+
}
249+
break;
250+
}
251+
case "windows": {
252+
baseDir = Deno.env.get("LOCALAPPDATA");
253+
if (!baseDir) {
254+
baseDir = Deno.env.get("USERPROFILE");
255+
if (baseDir) {
256+
baseDir += "/AppData/Local";
257+
}
258+
}
259+
if (baseDir) {
260+
baseDir += "/Cache";
261+
}
262+
break;
263+
}
264+
case "linux": {
265+
const xdg = Deno.env.get("XDG_CACHE_HOME");
266+
if (xdg && xdg[0] === "/") {
267+
baseDir = xdg;
268+
}
269+
break;
270+
}
271+
}
272+
if (!baseDir) {
273+
baseDir = Deno.env.get("HOME");
274+
if (baseDir) {
275+
baseDir += "/.cache";
276+
}
277+
}
278+
if (!baseDir) {
279+
throw new Error("Failed to find cache directory");
280+
}
281+
const platformKey = Deno.build.target;
282+
const knownWindowsPackages: Record<string, string> = {
283+
"x86_64-pc-windows-msvc": "esbuild-windows-64",
284+
};
285+
const knownUnixlikePackages: Record<string, string> = {
286+
"aarch64-apple-darwin": "esbuild-darwin-arm64",
287+
"aarch64-unknown-linux-gnu": "esbuild-linux-arm64",
288+
"x86_64-apple-darwin": "esbuild-darwin-64",
289+
"x86_64-unknown-linux-gnu": "esbuild-linux-64",
290+
};
291+
if (platformKey in knownWindowsPackages) {
292+
name = knownWindowsPackages[platformKey];
293+
} else if (platformKey in knownUnixlikePackages) {
294+
name = knownUnixlikePackages[platformKey];
295+
} else {
296+
throw new Error(`Unsupported platform: ${platformKey}`);
297+
}
298+
299+
const esbuildBinDir = baseDir + `/esbuild/bin`;
300+
const esbuildBinPath = esbuildBinDir + `/${name}@${version}`;
301+
return { esbuildBinDir, esbuildBinPath };
302+
}
303+
234304
if (import.meta.main) {
235305
main();
236306
}

commands/start.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { basename } from "https://deno.land/[email protected]/path/mod.ts";
1+
import { basename, join } from "https://deno.land/[email protected]/path/mod.ts";
22
import { serve as stdServe, serveTls } from "https://deno.land/[email protected]/http/server.ts";
33
import { getFlag, parse, parsePortNumber } from "../lib/flags.ts";
44
import { findFile } from "../lib/fs.ts";
@@ -61,7 +61,7 @@ if (import.meta.main) {
6161
// close the app modules server
6262
ac.abort();
6363

64-
await import(`./dist/server.js`);
64+
await import("file://" + join(Deno.cwd(), "dist/server.js"));
6565
log.info(`Server handler imported from ${blue("dist/server.js")}`);
6666

6767
const handler = (req: Request) => {

server/build.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { basename, dirname, extname, join } from "https://deno.land/[email protected]/path/mod.ts";
22
import { ensureDir } from "https://deno.land/[email protected]/fs/ensure_dir.ts";
3-
import { build as esbuild, type Loader, stop } from "https://deno.land/x/[email protected].34/mod.js";
3+
import { build as esbuild, type Loader, stop } from "https://deno.land/x/[email protected].36/mod.js";
44
import { parseExportNames } from "../compiler/mod.ts";
55
import cache from "../lib/cache.ts";
66
import { existsDir, existsFile } from "../lib/fs.ts";
@@ -30,7 +30,6 @@ export async function build(
3030
}
3131

3232
const workingDir = Deno.cwd();
33-
const tmpDir = await Deno.makeTempDir();
3433
const alephPkgUri = getAlephPkgUri();
3534
const importMap = await loadImportMap();
3635
const jsxCofig = await loadJSXConfig(importMap);
@@ -84,7 +83,7 @@ export async function build(
8483
// since esbuild doesn't support jsx automic transform, we need to manually import jsx runtime
8584
let jsxShimFile: string | null = null;
8685
if (serverEntry && util.endsWithAny(serverEntry, ".jsx", ".tsx") && jsxCofig.jsxImportSource) {
87-
jsxShimFile = join(tmpDir, "jsx-shim.js");
86+
jsxShimFile = join(outputDir, "jsx-shim.js");
8887
await Deno.writeTextFile(
8988
jsxShimFile,
9089
(jsxCofig.jsxRuntime === "preact"
@@ -257,7 +256,9 @@ export async function build(
257256
}
258257

259258
// clean up then exit
260-
await Deno.remove(tmpDir, { recursive: true });
259+
if (jsxShimFile) {
260+
await Deno.remove(jsxShimFile);
261+
}
261262
stop();
262263

263264
return { clientModules };

version.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export const isCanary = false;
66

77
/** `prepublish` will be invoked before publish */
88
export async function prepublish(): Promise<boolean> {
9+
if (!window.confirm("Build compiler wasm ?")) {
10+
return true;
11+
}
12+
913
const p = Deno.run({
1014
cmd: ["deno", "run", "-A", "build.ts"],
1115
cwd: "./compiler",

0 commit comments

Comments
 (0)