forked from denoland/fresh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ea8b0d
commit c797716
Showing
3 changed files
with
28 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ export { | |
toFileUrl, | ||
} from "https://deno.land/[email protected]/path/mod.ts"; | ||
export { escape as regexpEscape } from "https://deno.land/[email protected]/regexp/escape.ts"; | ||
export { denoPlugins } from "https://deno.land/x/esbuild_deno_loader@0.9.0/mod.ts"; | ||
export { denoPlugins } from "jsr:@luca/esbuild-deno-loader@0.10.3"; | ||
export { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { | |
type BuildOptions, | ||
type OnLoadOptions, | ||
type Plugin, | ||
} from "https://deno.land/x/esbuild@v0.19.11/mod.js"; | ||
} from "https://deno.land/x/esbuild@v0.20.2/mod.js"; | ||
import { denoPlugins, fromFileUrl, regexpEscape, relative } from "./deps.ts"; | ||
import { Builder, BuildSnapshot } from "./mod.ts"; | ||
|
||
|
@@ -23,6 +23,30 @@ export interface EsbuildBuilderOptions { | |
basePath?: string; | ||
} | ||
|
||
let esbuild: typeof import("https://deno.land/x/[email protected]/mod.js"); | ||
|
||
export async function initializeEsbuild() { | ||
esbuild = | ||
// deno-lint-ignore no-deprecated-deno-api | ||
Deno.run === undefined || | ||
Deno.env.get("FRESH_ESBUILD_LOADER") === "portable" | ||
? await import("https://deno.land/x/[email protected]/wasm.js") | ||
: await import("https://deno.land/x/[email protected]/mod.js"); | ||
const esbuildWasmURL = | ||
new URL("./esbuild_v0.20.2.wasm", import.meta.url).href; | ||
|
||
// deno-lint-ignore no-deprecated-deno-api | ||
if (Deno.run === undefined) { | ||
await esbuild.initialize({ | ||
wasmURL: esbuildWasmURL, | ||
worker: false, | ||
}); | ||
} else { | ||
await esbuild.initialize({}); | ||
} | ||
return esbuild; | ||
} | ||
|
||
export class EsbuildBuilder implements Builder { | ||
#options: EsbuildBuilderOptions; | ||
|
||
|
@@ -34,25 +58,7 @@ export class EsbuildBuilder implements Builder { | |
const opts = this.#options; | ||
|
||
// Lazily initialize esbuild | ||
// @deno-types="https://deno.land/x/[email protected]/mod.d.ts" | ||
const esbuild = | ||
// deno-lint-ignore no-deprecated-deno-api | ||
Deno.run === undefined || | ||
Deno.env.get("FRESH_ESBUILD_LOADER") === "portable" | ||
? await import("https://deno.land/x/[email protected]/wasm.js") | ||
: await import("https://deno.land/x/[email protected]/mod.js"); | ||
const esbuildWasmURL = | ||
new URL("./esbuild_v0.19.11.wasm", import.meta.url).href; | ||
|
||
// deno-lint-ignore no-deprecated-deno-api | ||
if (Deno.run === undefined) { | ||
await esbuild.initialize({ | ||
wasmURL: esbuildWasmURL, | ||
worker: false, | ||
}); | ||
} else { | ||
await esbuild.initialize({}); | ||
} | ||
const esbuild = await initializeEsbuild(); | ||
|
||
try { | ||
const absWorkingDir = opts.absoluteWorkingDir; | ||
|
@@ -129,7 +135,7 @@ export class EsbuildBuilder implements Builder { | |
|
||
return new EsbuildSnapshot(files, dependencies); | ||
} finally { | ||
esbuild.stop(); | ||
await esbuild.stop(); | ||
} | ||
} | ||
} | ||
|
Binary file not shown.