-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
`npm:esbuild-wasm` does not actually use WASM when not loaded in a browser. As such, we need to use https://deno.land/x/[email protected]/wasm.js when targeting wasm. This commit decouples esbuild_deno_loader from any specific esbuild version, by bundling the required types for the esbuild plugin API itself.
- Loading branch information
1 parent
1903397
commit 67c529e
Showing
11 changed files
with
151 additions
and
19 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
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 |
---|---|---|
|
@@ -17,7 +17,7 @@ This example bundles an entrypoint into a single ESM output. | |
import * as esbuild from "npm:[email protected]"; | ||
// Import the WASM build on platforms where running subprocesses is not | ||
// permitted, such as Deno Deploy, or when running without `--allow-run`. | ||
// import * as esbuild from "npm:esbuild-wasm@0.20"; | ||
// import * as esbuild from "https://deno.land/x/[email protected].2/wasm.js"; | ||
|
||
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader@^0.10.2"; | ||
|
||
|
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 |
---|---|---|
@@ -1,16 +1,17 @@ | ||
{ | ||
"name": "@luca/esbuild-deno-loader", | ||
"version": "0.10.2", | ||
"exports": "./mod.ts", | ||
"exports": { | ||
".": "./mod.ts", | ||
"./esbuild_types": "./src/esbuild_types.ts" | ||
}, | ||
"imports": { | ||
"@std/assert": "jsr:@std/[email protected]", | ||
"@std/encoding/base32": "jsr:@std/[email protected]/base32", | ||
"@std/encoding": "jsr:@std/[email protected]", | ||
"@std/fs": "jsr:@std/[email protected]", | ||
"@std/jsonc": "jsr:@std/[email protected]", | ||
"@std/path": "jsr:@std/[email protected]", | ||
"esbuild-wasm": "npm:[email protected]", | ||
"esbuild": "npm:[email protected]", | ||
"x/importmap": "./vendor/x/importmap/mod.ts", | ||
"x/importmap/_util.ts": "./vendor/x/importmap/_util.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
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import type esbuild from "esbuild"; | ||
import esbuildNative from "esbuild"; | ||
import esbuildWasm from "esbuild-wasm"; | ||
import esbuildNative from "https://deno.land/x/[email protected]/mod.js"; | ||
import esbuildWasm from "https://deno.land/x/[email protected]/wasm.js"; | ||
import { join } from "@std/path"; | ||
import { assert, assertEquals, assertStringIncludes } from "@std/assert"; | ||
import { | ||
|
@@ -767,7 +766,7 @@ Deno.test("bundle config inline import map with expansion", async (t) => { | |
}); | ||
}); | ||
|
||
const COMPUTED_PLUGIN: esbuild.Plugin = { | ||
const COMPUTED_PLUGIN: esbuildNative.Plugin = { | ||
name: "computed", | ||
setup(build) { | ||
build.onResolve({ filter: /.*/, namespace: "computed" }, (args) => { | ||
|
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 |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/** | ||
* This is a copy of the esbuild types that `deno_esbuild_loader` uses. This is | ||
* necessary because the `esbuild` package is not available on JSR yet. | ||
* | ||
* @module | ||
*/ | ||
|
||
/** the type of import */ | ||
export type ImportKind = | ||
| "entry-point" | ||
// JS | ||
| "import-statement" | ||
| "require-call" | ||
| "dynamic-import" | ||
| "require-resolve" | ||
// CSS | ||
| "import-rule" | ||
| "composes-from" | ||
| "url-token"; | ||
|
||
/** Documentation: https://esbuild.github.io/api/#loader */ | ||
export type Loader = | ||
| "base64" | ||
| "binary" | ||
| "copy" | ||
| "css" | ||
| "dataurl" | ||
| "default" | ||
| "empty" | ||
| "file" | ||
| "js" | ||
| "json" | ||
| "jsx" | ||
| "local-css" | ||
| "text" | ||
| "ts" | ||
| "tsx"; | ||
|
||
/** Documentation: https://esbuild.github.io/plugins */ | ||
export interface Plugin { | ||
name: string; | ||
setup: (build: PluginBuild) => void | Promise<void>; | ||
} | ||
|
||
/** Documentation: https://esbuild.github.io/plugins */ | ||
export interface PluginBuild { | ||
/** Documentation: https://esbuild.github.io/plugins/#build-options */ | ||
initialOptions: BuildOptions; | ||
|
||
/** Documentation: https://esbuild.github.io/plugins/#resolve */ | ||
resolve(path: string, options?: ResolveOptions): Promise<ResolveResult>; | ||
|
||
/** Documentation: https://esbuild.github.io/plugins/#on-start */ | ||
onStart(callback: () => Promise<void>): void; | ||
|
||
/** Documentation: https://esbuild.github.io/plugins/#on-resolve */ | ||
onResolve( | ||
options: OnResolveOptions, | ||
callback: (args: OnResolveArgs) => Promise<OnResolveResult | undefined>, | ||
): void; | ||
|
||
/** Documentation: https://esbuild.github.io/plugins/#on-load */ | ||
onLoad( | ||
options: OnLoadOptions, | ||
callback: (args: OnLoadArgs) => Promise<OnLoadResult | null> | undefined, | ||
): void; | ||
} | ||
|
||
/** Documentation: https://esbuild.github.io/api */ | ||
export interface BuildOptions { | ||
/** Documentation: https://esbuild.github.io/api/#external */ | ||
external?: string[]; | ||
/** Documentation: https://esbuild.github.io/api/#working-directory */ | ||
absWorkingDir?: string; | ||
} | ||
|
||
/** Documentation: https://esbuild.github.io/plugins/#resolve-options */ | ||
export interface ResolveOptions { | ||
importer?: string; | ||
resolveDir?: string; | ||
namespace?: string; | ||
kind?: ImportKind; | ||
} | ||
|
||
/** Documentation: https://esbuild.github.io/plugins/#resolve-results */ | ||
export interface ResolveResult { | ||
path: string; | ||
namespace: string; | ||
} | ||
|
||
/** Documentation: https://esbuild.github.io/plugins/#on-resolve-options */ | ||
export interface OnResolveOptions { | ||
filter: RegExp; | ||
namespace?: string; | ||
} | ||
|
||
/** Documentation: https://esbuild.github.io/plugins/#on-resolve-arguments */ | ||
export interface OnResolveArgs { | ||
path: string; | ||
importer: string; | ||
namespace: string; | ||
resolveDir: string; | ||
kind: ImportKind; | ||
} | ||
|
||
export interface OnResolveResult { | ||
path?: string; | ||
external?: boolean; | ||
namespace?: string; | ||
} | ||
|
||
/** Documentation: https://esbuild.github.io/plugins/#on-load-options */ | ||
export interface OnLoadOptions { | ||
filter: RegExp; | ||
namespace?: string; | ||
} | ||
|
||
/** Documentation: https://esbuild.github.io/plugins/#on-load-arguments */ | ||
export interface OnLoadArgs { | ||
path: string; | ||
namespace: string; | ||
} | ||
|
||
/** Documentation: https://esbuild.github.io/plugins/#on-load-results */ | ||
export interface OnLoadResult { | ||
contents?: string | Uint8Array; | ||
resolveDir?: string; | ||
loader?: Loader; | ||
|
||
watchFiles?: string[]; | ||
} | ||
|
||
/** Documentation: https://esbuild.github.io/plugins/#on-start-results */ | ||
// deno-lint-ignore no-empty-interface | ||
export interface OnStartResult { | ||
} |
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
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
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
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
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