sandlot 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/bundler.d.ts +8 -0
- package/dist/browser/bundler.d.ts.map +1 -1
- package/dist/browser/iframe-executor.d.ts +82 -0
- package/dist/browser/iframe-executor.d.ts.map +1 -0
- package/dist/browser/index.d.ts +4 -2
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +205 -9
- package/dist/browser/main-thread-executor.d.ts +46 -0
- package/dist/browser/main-thread-executor.d.ts.map +1 -0
- package/dist/browser/preset.d.ts +7 -2
- package/dist/browser/preset.d.ts.map +1 -1
- package/dist/core/executor.d.ts.map +1 -1
- package/dist/core/sandlot.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/node/bundler.d.ts +5 -0
- package/dist/node/bundler.d.ts.map +1 -1
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +174 -8
- package/dist/node/preset.d.ts +16 -1
- package/dist/node/preset.d.ts.map +1 -1
- package/dist/node/wasm-bundler.d.ts +86 -0
- package/dist/node/wasm-bundler.d.ts.map +1 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/browser/bundler.ts +17 -0
- package/src/browser/iframe-executor.ts +320 -0
- package/src/browser/index.ts +9 -2
- package/src/browser/preset.ts +30 -6
- package/src/core/executor.ts +8 -7
- package/src/core/sandlot.ts +7 -0
- package/src/node/bundler.ts +11 -0
- package/src/node/index.ts +10 -0
- package/src/node/preset.ts +59 -5
- package/src/node/wasm-bundler.ts +299 -0
- package/src/types.ts +27 -0
- /package/src/browser/{executor.ts → main-thread-executor.ts} +0 -0
package/dist/node/index.js
CHANGED
|
@@ -342,6 +342,12 @@ class EsbuildNativeBundler {
|
|
|
342
342
|
}
|
|
343
343
|
return this.esbuild;
|
|
344
344
|
}
|
|
345
|
+
async dispose() {
|
|
346
|
+
if (this.esbuild) {
|
|
347
|
+
await this.esbuild.stop();
|
|
348
|
+
this.esbuild = null;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
345
351
|
async bundle(options) {
|
|
346
352
|
await this.initialize();
|
|
347
353
|
const esbuild = this.getEsbuild();
|
|
@@ -419,6 +425,142 @@ class EsbuildNativeBundler {
|
|
|
419
425
|
function createEsbuildNativeBundler(options) {
|
|
420
426
|
return new EsbuildNativeBundler(options);
|
|
421
427
|
}
|
|
428
|
+
// src/node/wasm-bundler.ts
|
|
429
|
+
var GLOBAL_KEY = "__sandlot_esbuild_wasm_node__";
|
|
430
|
+
function getGlobalState() {
|
|
431
|
+
const g = globalThis;
|
|
432
|
+
if (!g[GLOBAL_KEY]) {
|
|
433
|
+
g[GLOBAL_KEY] = {
|
|
434
|
+
esbuild: null,
|
|
435
|
+
initialized: false,
|
|
436
|
+
initPromise: null
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
return g[GLOBAL_KEY];
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
class EsbuildWasmNodeBundler {
|
|
443
|
+
options;
|
|
444
|
+
constructor(options = {}) {
|
|
445
|
+
this.options = {
|
|
446
|
+
cdnBaseUrl: "https://esm.sh",
|
|
447
|
+
...options
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
async initialize() {
|
|
451
|
+
const state = getGlobalState();
|
|
452
|
+
if (state.initialized && state.esbuild) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (state.initPromise) {
|
|
456
|
+
await state.initPromise;
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
state.initPromise = this.doInitialize(state);
|
|
460
|
+
await state.initPromise;
|
|
461
|
+
}
|
|
462
|
+
async doInitialize(state) {
|
|
463
|
+
const esbuild = await import("esbuild-wasm");
|
|
464
|
+
if (typeof esbuild?.initialize !== "function") {
|
|
465
|
+
throw new Error("Failed to load esbuild-wasm: initialize function not found");
|
|
466
|
+
}
|
|
467
|
+
await esbuild.initialize({});
|
|
468
|
+
state.esbuild = esbuild;
|
|
469
|
+
state.initialized = true;
|
|
470
|
+
}
|
|
471
|
+
getEsbuild() {
|
|
472
|
+
const state = getGlobalState();
|
|
473
|
+
if (!state.esbuild) {
|
|
474
|
+
throw new Error("esbuild not initialized - call initialize() first");
|
|
475
|
+
}
|
|
476
|
+
return state.esbuild;
|
|
477
|
+
}
|
|
478
|
+
async dispose() {
|
|
479
|
+
const state = getGlobalState();
|
|
480
|
+
if (state.esbuild) {
|
|
481
|
+
await state.esbuild.stop();
|
|
482
|
+
state.esbuild = null;
|
|
483
|
+
state.initialized = false;
|
|
484
|
+
state.initPromise = null;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
async bundle(options) {
|
|
488
|
+
await this.initialize();
|
|
489
|
+
const esbuild = this.getEsbuild();
|
|
490
|
+
const {
|
|
491
|
+
fs,
|
|
492
|
+
entryPoint,
|
|
493
|
+
installedPackages = {},
|
|
494
|
+
sharedModules = [],
|
|
495
|
+
sharedModuleRegistry,
|
|
496
|
+
external = [],
|
|
497
|
+
format = "esm",
|
|
498
|
+
minify = false,
|
|
499
|
+
sourcemap = false,
|
|
500
|
+
target = ["es2020"]
|
|
501
|
+
} = options;
|
|
502
|
+
const normalizedEntry = entryPoint.startsWith("/") ? entryPoint : `/${entryPoint}`;
|
|
503
|
+
if (!fs.exists(normalizedEntry)) {
|
|
504
|
+
return {
|
|
505
|
+
success: false,
|
|
506
|
+
errors: [{ text: `Entry point not found: ${normalizedEntry}` }],
|
|
507
|
+
warnings: []
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
const includedFiles = new Set;
|
|
511
|
+
const plugin = createVfsPlugin({
|
|
512
|
+
fs,
|
|
513
|
+
entryPoint: normalizedEntry,
|
|
514
|
+
installedPackages,
|
|
515
|
+
sharedModules: new Set(sharedModules),
|
|
516
|
+
sharedModuleRegistry: sharedModuleRegistry ?? null,
|
|
517
|
+
cdnBaseUrl: this.options.cdnBaseUrl,
|
|
518
|
+
includedFiles,
|
|
519
|
+
bundleCdnImports: true
|
|
520
|
+
});
|
|
521
|
+
try {
|
|
522
|
+
const result = await esbuild.build({
|
|
523
|
+
entryPoints: [normalizedEntry],
|
|
524
|
+
bundle: true,
|
|
525
|
+
write: false,
|
|
526
|
+
format,
|
|
527
|
+
minify,
|
|
528
|
+
sourcemap: sourcemap ? "inline" : false,
|
|
529
|
+
target,
|
|
530
|
+
external,
|
|
531
|
+
plugins: [plugin],
|
|
532
|
+
jsx: "automatic"
|
|
533
|
+
});
|
|
534
|
+
const code = result.outputFiles?.[0]?.text ?? "";
|
|
535
|
+
const warnings = result.warnings.map((w) => convertEsbuildMessage(w));
|
|
536
|
+
return {
|
|
537
|
+
success: true,
|
|
538
|
+
code,
|
|
539
|
+
warnings,
|
|
540
|
+
includedFiles: Array.from(includedFiles)
|
|
541
|
+
};
|
|
542
|
+
} catch (err) {
|
|
543
|
+
if (isEsbuildBuildFailure(err)) {
|
|
544
|
+
const errors = err.errors.map((e) => convertEsbuildMessage(e));
|
|
545
|
+
const warnings = err.warnings.map((w) => convertEsbuildMessage(w));
|
|
546
|
+
return {
|
|
547
|
+
success: false,
|
|
548
|
+
errors,
|
|
549
|
+
warnings
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
553
|
+
return {
|
|
554
|
+
success: false,
|
|
555
|
+
errors: [{ text: message }],
|
|
556
|
+
warnings: []
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function createEsbuildWasmNodeBundler(options) {
|
|
562
|
+
return new EsbuildWasmNodeBundler(options);
|
|
563
|
+
}
|
|
422
564
|
// src/core/typechecker.ts
|
|
423
565
|
import ts from "typescript";
|
|
424
566
|
var TS_VERSION = "5.9.3";
|
|
@@ -771,23 +913,18 @@ function createBasicExecutor(loadModule, options = {}) {
|
|
|
771
913
|
const formatArgs = (...args) => args.map((v) => typeof v === "object" ? JSON.stringify(v) : String(v)).join(" ");
|
|
772
914
|
const captureLog = (...args) => {
|
|
773
915
|
logs.push(formatArgs(...args));
|
|
774
|
-
originalConsole.log.apply(console, args);
|
|
775
916
|
};
|
|
776
917
|
const captureWarn = (...args) => {
|
|
777
918
|
logs.push(`[warn] ${formatArgs(...args)}`);
|
|
778
|
-
originalConsole.warn.apply(console, args);
|
|
779
919
|
};
|
|
780
920
|
const captureError = (...args) => {
|
|
781
921
|
logs.push(`[error] ${formatArgs(...args)}`);
|
|
782
|
-
originalConsole.error.apply(console, args);
|
|
783
922
|
};
|
|
784
923
|
const captureInfo = (...args) => {
|
|
785
924
|
logs.push(`[info] ${formatArgs(...args)}`);
|
|
786
|
-
originalConsole.info.apply(console, args);
|
|
787
925
|
};
|
|
788
926
|
const captureDebug = (...args) => {
|
|
789
927
|
logs.push(`[debug] ${formatArgs(...args)}`);
|
|
790
|
-
originalConsole.debug.apply(console, args);
|
|
791
928
|
};
|
|
792
929
|
const restoreConsole = () => {
|
|
793
930
|
console.log = originalConsole.log;
|
|
@@ -814,10 +951,16 @@ function createBasicExecutor(loadModule, options = {}) {
|
|
|
814
951
|
}
|
|
815
952
|
};
|
|
816
953
|
if (timeout > 0) {
|
|
954
|
+
let timeoutId;
|
|
817
955
|
const timeoutPromise = new Promise((_, reject) => {
|
|
818
|
-
setTimeout(() => reject(new Error(`Execution timed out after ${timeout}ms`)), timeout);
|
|
956
|
+
timeoutId = setTimeout(() => reject(new Error(`Execution timed out after ${timeout}ms`)), timeout);
|
|
819
957
|
});
|
|
820
|
-
|
|
958
|
+
try {
|
|
959
|
+
await Promise.race([executeExport(), timeoutPromise]);
|
|
960
|
+
} finally {
|
|
961
|
+
if (timeoutId)
|
|
962
|
+
clearTimeout(timeoutId);
|
|
963
|
+
}
|
|
821
964
|
} else {
|
|
822
965
|
await executeExport();
|
|
823
966
|
}
|
|
@@ -2415,6 +2558,11 @@ function createSandlot(options) {
|
|
|
2415
2558
|
},
|
|
2416
2559
|
get sharedModules() {
|
|
2417
2560
|
return sharedModuleRegistry;
|
|
2561
|
+
},
|
|
2562
|
+
async dispose() {
|
|
2563
|
+
if (bundler.dispose) {
|
|
2564
|
+
await bundler.dispose();
|
|
2565
|
+
}
|
|
2418
2566
|
}
|
|
2419
2567
|
};
|
|
2420
2568
|
}
|
|
@@ -2608,7 +2756,7 @@ function escapeRegex(str) {
|
|
|
2608
2756
|
// src/node/preset.ts
|
|
2609
2757
|
async function createNodeSandlot(options = {}) {
|
|
2610
2758
|
const { bundler, typechecker, typesResolver, executor, ...rest } = options;
|
|
2611
|
-
const bundlerInstance =
|
|
2759
|
+
const bundlerInstance = createBundlerInstance(bundler);
|
|
2612
2760
|
await bundlerInstance.initialize();
|
|
2613
2761
|
const typecheckerInstance = typechecker === false ? undefined : isTypechecker(typechecker) ? typechecker : new Typechecker(typechecker);
|
|
2614
2762
|
const typesResolverInstance = typesResolver === false ? undefined : isTypesResolver(typesResolver) ? typesResolver : new EsmTypesResolver(typesResolver);
|
|
@@ -2621,6 +2769,22 @@ async function createNodeSandlot(options = {}) {
|
|
|
2621
2769
|
executor: executorInstance
|
|
2622
2770
|
});
|
|
2623
2771
|
}
|
|
2772
|
+
function createBundlerInstance(bundler) {
|
|
2773
|
+
if (isBundler(bundler)) {
|
|
2774
|
+
return bundler;
|
|
2775
|
+
}
|
|
2776
|
+
if (bundler === "wasm") {
|
|
2777
|
+
return new EsbuildWasmNodeBundler;
|
|
2778
|
+
}
|
|
2779
|
+
if (isWasmBundlerOptions(bundler)) {
|
|
2780
|
+
const { wasm: _, ...wasmOptions } = bundler;
|
|
2781
|
+
return new EsbuildWasmNodeBundler(wasmOptions);
|
|
2782
|
+
}
|
|
2783
|
+
return new EsbuildNativeBundler(bundler);
|
|
2784
|
+
}
|
|
2785
|
+
function isWasmBundlerOptions(value) {
|
|
2786
|
+
return typeof value === "object" && value !== null && "wasm" in value && value.wasm === true;
|
|
2787
|
+
}
|
|
2624
2788
|
function isBundler(value) {
|
|
2625
2789
|
return typeof value === "object" && value !== null && "bundle" in value && typeof value.bundle === "function";
|
|
2626
2790
|
}
|
|
@@ -2637,8 +2801,10 @@ export {
|
|
|
2637
2801
|
createTypechecker,
|
|
2638
2802
|
createNodeSandlot,
|
|
2639
2803
|
createNodeExecutor,
|
|
2804
|
+
createEsbuildWasmNodeBundler,
|
|
2640
2805
|
createEsbuildNativeBundler,
|
|
2641
2806
|
Typechecker,
|
|
2642
2807
|
NodeExecutor,
|
|
2808
|
+
EsbuildWasmNodeBundler,
|
|
2643
2809
|
EsbuildNativeBundler
|
|
2644
2810
|
};
|
package/dist/node/preset.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import { type EsmTypesResolverOptions } from "../core/esm-types-resolver";
|
|
2
2
|
import type { Sandlot, SandlotOptions } from "../types";
|
|
3
3
|
import { type EsbuildNativeBundlerOptions } from "./bundler";
|
|
4
|
+
import { type EsbuildWasmNodeBundlerOptions } from "./wasm-bundler";
|
|
4
5
|
import { type TypecheckerOptions } from "../core/typechecker";
|
|
5
6
|
import { type NodeExecutorOptions } from "./executor";
|
|
6
7
|
export interface CreateNodeSandlotOptions extends Omit<SandlotOptions, "bundler" | "typechecker" | "typesResolver" | "executor"> {
|
|
7
8
|
/**
|
|
8
9
|
* Custom bundler options, or a pre-configured bundler instance.
|
|
10
|
+
*
|
|
11
|
+
* Set to `"wasm"` to use the WASM bundler (for testing consistency with browser).
|
|
12
|
+
* You can also pass `{ wasm: true, ...options }` for WASM bundler with custom options.
|
|
13
|
+
*
|
|
14
|
+
* @default EsbuildNativeBundler (fastest, uses native esbuild binary)
|
|
9
15
|
*/
|
|
10
|
-
bundler?: EsbuildNativeBundlerOptions |
|
|
16
|
+
bundler?: EsbuildNativeBundlerOptions | (EsbuildWasmNodeBundlerOptions & {
|
|
17
|
+
wasm: true;
|
|
18
|
+
}) | SandlotOptions["bundler"] | "wasm";
|
|
11
19
|
/**
|
|
12
20
|
* Custom typechecker options, or a pre-configured typechecker instance.
|
|
13
21
|
* Set to `false` to disable type checking.
|
|
@@ -57,6 +65,13 @@ export interface CreateNodeSandlotOptions extends Omit<SandlotOptions, "bundler"
|
|
|
57
65
|
* typechecker: false,
|
|
58
66
|
* });
|
|
59
67
|
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example Use WASM bundler for testing consistency with browser
|
|
70
|
+
* ```ts
|
|
71
|
+
* const sandlot = await createNodeSandlot({
|
|
72
|
+
* bundler: "wasm",
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
60
75
|
*/
|
|
61
76
|
export declare function createNodeSandlot(options?: CreateNodeSandlotOptions): Promise<Sandlot>;
|
|
62
77
|
//# sourceMappingURL=preset.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset.d.ts","sourceRoot":"","sources":["../../src/node/preset.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAwB,KAAK,2BAA2B,EAAE,MAAM,WAAW,CAAC;AACnF,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,wBACf,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,aAAa,GAAG,eAAe,GAAG,UAAU,CAAC;IACtF
|
|
1
|
+
{"version":3,"file":"preset.d.ts","sourceRoot":"","sources":["../../src/node/preset.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAwB,KAAK,2BAA2B,EAAE,MAAM,WAAW,CAAC;AACnF,OAAO,EAEL,KAAK,6BAA6B,EACnC,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,KAAK,kBAAkB,EACxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,wBACf,SAAQ,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,aAAa,GAAG,eAAe,GAAG,UAAU,CAAC;IACtF;;;;;;;OAOG;IACH,OAAO,CAAC,EACJ,2BAA2B,GAC3B,CAAC,6BAA6B,GAAG;QAAE,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC,GAChD,cAAc,CAAC,SAAS,CAAC,GACzB,MAAM,CAAC;IAEX;;;OAGG;IACH,WAAW,CAAC,EACV,kBAAkB,GAClB,cAAc,CAAC,aAAa,CAAC,GAC7B,KAAK,CAAC;IAER;;;OAGG;IACH,aAAa,CAAC,EACZ,uBAAuB,GACvB,cAAc,CAAC,eAAe,CAAC,GAC/B,KAAK,CAAC;IAER;;;;OAIG;IACH,QAAQ,CAAC,EACP,mBAAmB,GACnB,cAAc,CAAC,UAAU,CAAC,GAC1B,KAAK,CAAC;CACT;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,OAAO,CAAC,CA8ClB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node/Bun/Deno bundler implementation using esbuild-wasm.
|
|
3
|
+
*
|
|
4
|
+
* This bundler uses the same WebAssembly-based esbuild as the browser bundler,
|
|
5
|
+
* but runs in Node.js/Bun/Deno environments. It's primarily useful for:
|
|
6
|
+
*
|
|
7
|
+
* 1. Testing consistency with the browser bundler
|
|
8
|
+
* 2. Ensuring identical import resolution behavior
|
|
9
|
+
* 3. Validating that bundled output matches between browser and server
|
|
10
|
+
*
|
|
11
|
+
* For production use, prefer EsbuildNativeBundler which is ~3-5x faster.
|
|
12
|
+
*/
|
|
13
|
+
import type { IBundler, BundleOptions, BundleResult } from "../types";
|
|
14
|
+
export interface EsbuildWasmNodeBundlerOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Base URL for CDN imports.
|
|
17
|
+
* npm imports like "lodash" are rewritten to "{cdnBaseUrl}/lodash@{version}".
|
|
18
|
+
* @default "https://esm.sh"
|
|
19
|
+
*/
|
|
20
|
+
cdnBaseUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Bundler implementation using esbuild-wasm for Node.js/Bun/Deno.
|
|
24
|
+
*
|
|
25
|
+
* Uses the same WebAssembly-based esbuild as the browser bundler,
|
|
26
|
+
* making it ideal for testing consistency between browser and server builds.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* const bundler = new EsbuildWasmNodeBundler();
|
|
31
|
+
* await bundler.initialize();
|
|
32
|
+
*
|
|
33
|
+
* const result = await bundler.bundle({
|
|
34
|
+
* fs: myFilesystem,
|
|
35
|
+
* entryPoint: "/src/index.ts",
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @example Testing consistency with native bundler
|
|
40
|
+
* ```ts
|
|
41
|
+
* const native = new EsbuildNativeBundler();
|
|
42
|
+
* const wasm = new EsbuildWasmNodeBundler();
|
|
43
|
+
*
|
|
44
|
+
* await native.initialize();
|
|
45
|
+
* await wasm.initialize();
|
|
46
|
+
*
|
|
47
|
+
* const nativeResult = await native.bundle(options);
|
|
48
|
+
* const wasmResult = await wasm.bundle(options);
|
|
49
|
+
*
|
|
50
|
+
* // Results should be equivalent (modulo minor formatting differences)
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare class EsbuildWasmNodeBundler implements IBundler {
|
|
54
|
+
private options;
|
|
55
|
+
constructor(options?: EsbuildWasmNodeBundlerOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Initialize the esbuild WASM module.
|
|
58
|
+
* Called automatically on first bundle() if not already initialized.
|
|
59
|
+
*
|
|
60
|
+
* Uses a global singleton pattern since esbuild-wasm can only be
|
|
61
|
+
* initialized once per process.
|
|
62
|
+
*/
|
|
63
|
+
initialize(): Promise<void>;
|
|
64
|
+
private doInitialize;
|
|
65
|
+
/**
|
|
66
|
+
* Get the initialized esbuild instance.
|
|
67
|
+
*/
|
|
68
|
+
private getEsbuild;
|
|
69
|
+
/**
|
|
70
|
+
* Dispose of the esbuild WASM service.
|
|
71
|
+
* This stops the esbuild service and allows the process to exit.
|
|
72
|
+
*
|
|
73
|
+
* Note: Since esbuild-wasm uses a global singleton, this affects all
|
|
74
|
+
* instances. After dispose(), you'll need to create a new bundler.
|
|
75
|
+
*/
|
|
76
|
+
dispose(): Promise<void>;
|
|
77
|
+
bundle(options: BundleOptions): Promise<BundleResult>;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Create an esbuild-wasm bundler for Node.js/Bun/Deno.
|
|
81
|
+
*
|
|
82
|
+
* This is primarily useful for testing consistency with the browser bundler.
|
|
83
|
+
* For production use, prefer createEsbuildNativeBundler() which is ~3-5x faster.
|
|
84
|
+
*/
|
|
85
|
+
export declare function createEsbuildWasmNodeBundler(options?: EsbuildWasmNodeBundlerOptions): EsbuildWasmNodeBundler;
|
|
86
|
+
//# sourceMappingURL=wasm-bundler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasm-bundler.d.ts","sourceRoot":"","sources":["../../src/node/wasm-bundler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EACV,QAAQ,EACR,aAAa,EACb,YAAY,EAGb,MAAM,UAAU,CAAC;AAoClB,MAAM,WAAW,6BAA6B;IAC5C;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,sBAAuB,YAAW,QAAQ;IACrD,OAAO,CAAC,OAAO,CAAgC;gBAEnC,OAAO,GAAE,6BAAkC;IAOvD;;;;;;OAMG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;YAmBnB,YAAY;IAoB1B;;OAEG;IACH,OAAO,CAAC,UAAU;IAQlB;;;;;;OAMG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAUxB,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;CA0G5D;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,CAAC,EAAE,6BAA6B,GACtC,sBAAsB,CAExB"}
|
package/dist/types.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export interface IBundler {
|
|
|
11
11
|
* Bundle source files from a filesystem into a single output
|
|
12
12
|
*/
|
|
13
13
|
bundle(options: BundleOptions): Promise<BundleResult>;
|
|
14
|
+
/**
|
|
15
|
+
* Dispose of resources held by the bundler (optional).
|
|
16
|
+
* Called by Sandlot.dispose() to clean up background services.
|
|
17
|
+
*/
|
|
18
|
+
dispose?(): Promise<void>;
|
|
14
19
|
}
|
|
15
20
|
export interface BundleOptions {
|
|
16
21
|
fs: Filesystem;
|
|
@@ -524,5 +529,25 @@ export interface Sandlot {
|
|
|
524
529
|
* The shared module registry (if shared modules were provided)
|
|
525
530
|
*/
|
|
526
531
|
readonly sharedModules: ISharedModuleRegistry | null;
|
|
532
|
+
/**
|
|
533
|
+
* Dispose of resources held by this Sandlot instance.
|
|
534
|
+
*
|
|
535
|
+
* This should be called when you're done using Sandlot to allow
|
|
536
|
+
* the process to exit cleanly. It stops any background services
|
|
537
|
+
* like the esbuild child process.
|
|
538
|
+
*
|
|
539
|
+
* After calling dispose(), this instance should not be used.
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```ts
|
|
543
|
+
* const sandlot = await createNodeSandlot();
|
|
544
|
+
* const sandbox = await sandlot.createSandbox();
|
|
545
|
+
*
|
|
546
|
+
* // ... do work ...
|
|
547
|
+
*
|
|
548
|
+
* await sandlot.dispose(); // Allow process to exit
|
|
549
|
+
* ```
|
|
550
|
+
*/
|
|
551
|
+
dispose(): Promise<void>;
|
|
527
552
|
}
|
|
528
553
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAM5C,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACtE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAM5C;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAM5C,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACtE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAM5C;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB;;OAEG;IACH,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAEtD;;;OAGG;IACH,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,UAAU,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MA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AAI,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,CAAC;IAM9E;;;;;;;;;;OAUG;IACH,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAErD;;;;;;OAMG;IACH,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAEzD;;;;;;;OAOG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAE3D;;;;;;OAMG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE,uBAAuB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,GAAG,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CAC/C;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAMD,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,aAAa,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAE1D;;OAEG;IACH,QAAQ,CAAC,aAAa,EAAE,qBAAqB,GAAG,IAAI,CAAC;IAErD;;;;;;;;;;;;;;;;;;OAkBG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
|
package/package.json
CHANGED
package/src/browser/bundler.ts
CHANGED
|
@@ -177,6 +177,23 @@ export class EsbuildWasmBundler implements IBundler {
|
|
|
177
177
|
return state.esbuild;
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Dispose of the esbuild WASM service.
|
|
182
|
+
* This stops the esbuild service and allows the process to exit.
|
|
183
|
+
*
|
|
184
|
+
* Note: Since esbuild-wasm uses a global singleton, this affects all
|
|
185
|
+
* instances. After dispose(), you'll need to create a new bundler.
|
|
186
|
+
*/
|
|
187
|
+
async dispose(): Promise<void> {
|
|
188
|
+
const state = getGlobalState();
|
|
189
|
+
if (state.esbuild) {
|
|
190
|
+
await state.esbuild.stop();
|
|
191
|
+
state.esbuild = null;
|
|
192
|
+
state.initialized = false;
|
|
193
|
+
state.initPromise = null;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
180
197
|
private checkCrossOriginIsolation(): void {
|
|
181
198
|
if (typeof window === "undefined") return;
|
|
182
199
|
|