@caryhu/codemine-forge 0.0.1-alpha.0
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/README.md +108 -0
- package/dist/build-pipeline/browser-bundle.d.ts +31 -0
- package/dist/build-pipeline/browser-bundle.js +584 -0
- package/dist/build-pipeline/diagnostics.d.ts +7 -0
- package/dist/build-pipeline/diagnostics.js +68 -0
- package/dist/build-pipeline/index.d.ts +3 -0
- package/dist/build-pipeline/index.js +16 -0
- package/dist/build-pipeline/pipeline.d.ts +12 -0
- package/dist/build-pipeline/pipeline.js +273 -0
- package/dist/build-pipeline/types.d.ts +77 -0
- package/dist/build-pipeline/types.js +4 -0
- package/dist/dev-server-preview/diagnostics.d.ts +5 -0
- package/dist/dev-server-preview/diagnostics.js +40 -0
- package/dist/dev-server-preview/index.d.ts +4 -0
- package/dist/dev-server-preview/index.js +16 -0
- package/dist/dev-server-preview/preview-document.d.ts +2 -0
- package/dist/dev-server-preview/preview-document.js +153 -0
- package/dist/dev-server-preview/server.d.ts +26 -0
- package/dist/dev-server-preview/server.js +279 -0
- package/dist/dev-server-preview/types.d.ts +105 -0
- package/dist/dev-server-preview/types.js +4 -0
- package/dist/esbuild-wasm-worker/diagnostics.d.ts +12 -0
- package/dist/esbuild-wasm-worker/diagnostics.js +53 -0
- package/dist/esbuild-wasm-worker/index.d.ts +4 -0
- package/dist/esbuild-wasm-worker/index.js +18 -0
- package/dist/esbuild-wasm-worker/service.d.ts +26 -0
- package/dist/esbuild-wasm-worker/service.js +260 -0
- package/dist/esbuild-wasm-worker/types.d.ts +139 -0
- package/dist/esbuild-wasm-worker/types.js +5 -0
- package/dist/esbuild-wasm-worker/worker-adapter.d.ts +38 -0
- package/dist/esbuild-wasm-worker/worker-adapter.js +165 -0
- package/dist/esbuild-wasm-worker/worker.d.ts +1 -0
- package/dist/esbuild-wasm-worker/worker.js +4 -0
- package/dist/forge-controller.d.ts +38 -0
- package/dist/forge-controller.js +79 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +88 -0
- package/dist/package-resolution/cdn-source.d.ts +11 -0
- package/dist/package-resolution/cdn-source.js +164 -0
- package/dist/package-resolution/diagnostics.d.ts +15 -0
- package/dist/package-resolution/diagnostics.js +51 -0
- package/dist/package-resolution/errors.d.ts +5 -0
- package/dist/package-resolution/errors.js +11 -0
- package/dist/package-resolution/index.d.ts +6 -0
- package/dist/package-resolution/index.js +23 -0
- package/dist/package-resolution/manifest.d.ts +5 -0
- package/dist/package-resolution/manifest.js +128 -0
- package/dist/package-resolution/resolver.d.ts +17 -0
- package/dist/package-resolution/resolver.js +172 -0
- package/dist/package-resolution/types.d.ts +98 -0
- package/dist/package-resolution/types.js +4 -0
- package/dist/terminal-commands/diagnostics.d.ts +3 -0
- package/dist/terminal-commands/diagnostics.js +21 -0
- package/dist/terminal-commands/index.d.ts +7 -0
- package/dist/terminal-commands/index.js +22 -0
- package/dist/terminal-commands/npm-build.d.ts +7 -0
- package/dist/terminal-commands/npm-build.js +63 -0
- package/dist/terminal-commands/npm-dev.d.ts +7 -0
- package/dist/terminal-commands/npm-dev.js +68 -0
- package/dist/terminal-commands/npm-install.d.ts +8 -0
- package/dist/terminal-commands/npm-install.js +56 -0
- package/dist/terminal-commands/parser.d.ts +2 -0
- package/dist/terminal-commands/parser.js +52 -0
- package/dist/terminal-commands/terminal.d.ts +12 -0
- package/dist/terminal-commands/terminal.js +73 -0
- package/dist/terminal-commands/types.d.ts +65 -0
- package/dist/terminal-commands/types.js +4 -0
- package/dist/virtual-file-system/diagnostics.d.ts +14 -0
- package/dist/virtual-file-system/diagnostics.js +55 -0
- package/dist/virtual-file-system/errors.d.ts +5 -0
- package/dist/virtual-file-system/errors.js +11 -0
- package/dist/virtual-file-system/index.d.ts +26 -0
- package/dist/virtual-file-system/index.js +47 -0
- package/dist/virtual-file-system/limits.d.ts +4 -0
- package/dist/virtual-file-system/limits.js +33 -0
- package/dist/virtual-file-system/memory.d.ts +33 -0
- package/dist/virtual-file-system/memory.js +551 -0
- package/dist/virtual-file-system/path.d.ts +9 -0
- package/dist/virtual-file-system/path.js +47 -0
- package/dist/virtual-file-system/storage.d.ts +32 -0
- package/dist/virtual-file-system/storage.js +194 -0
- package/dist/virtual-file-system/types.d.ts +165 -0
- package/dist/virtual-file-system/types.js +2 -0
- package/package.json +43 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEsbuildWasmWorkerService = exports.DefaultEsbuildWasmWorkerService = void 0;
|
|
4
|
+
const diagnostics_1 = require("./diagnostics");
|
|
5
|
+
const types_1 = require("./types");
|
|
6
|
+
const DEFAULT_REQUEST_TIMEOUT_MS = 5000;
|
|
7
|
+
class DefaultEsbuildWasmWorkerService {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.capability = types_1.ESBUILD_WASM_WORKER_CAPABILITY;
|
|
10
|
+
this.pendingRequests = new Map();
|
|
11
|
+
this.nextRequestId = 1;
|
|
12
|
+
this.handleMessage = (event) => {
|
|
13
|
+
const message = event.data;
|
|
14
|
+
if (!isWorkerResponseMessage(message)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const pending = this.pendingRequests.get(message.id);
|
|
18
|
+
if (pending === undefined) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.pendingRequests.delete(message.id);
|
|
22
|
+
clearTimeout(pending.timeoutId);
|
|
23
|
+
pending.resolve(message);
|
|
24
|
+
};
|
|
25
|
+
this.handleError = (event) => {
|
|
26
|
+
const diagnostic = (0, diagnostics_1.createWorkerStartupFailureDiagnostic)({
|
|
27
|
+
workerScriptUrl: stringifyUrl(this.workerScriptUrl),
|
|
28
|
+
cause: getEventCause(event),
|
|
29
|
+
causeCategory: "message_channel",
|
|
30
|
+
});
|
|
31
|
+
this.failPendingRequests([diagnostic]);
|
|
32
|
+
};
|
|
33
|
+
this.workerScriptUrl = options.workerScriptUrl;
|
|
34
|
+
this.wasmAssetUrl = options.wasmAssetUrl;
|
|
35
|
+
this.requestTimeoutMs =
|
|
36
|
+
options.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
37
|
+
this.workerFactory = options.workerFactory ?? createDefaultWorker;
|
|
38
|
+
}
|
|
39
|
+
async initialize(request = {}) {
|
|
40
|
+
if (this.initializedResult !== undefined) {
|
|
41
|
+
return this.initializedResult;
|
|
42
|
+
}
|
|
43
|
+
if (this.initializePromise !== undefined) {
|
|
44
|
+
return this.initializePromise;
|
|
45
|
+
}
|
|
46
|
+
this.initializePromise = this.initializeWorker(request);
|
|
47
|
+
const result = await this.initializePromise;
|
|
48
|
+
if (result.success) {
|
|
49
|
+
this.initializedResult = result;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
this.initializePromise = undefined;
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
async transform(request) {
|
|
57
|
+
if (this.initializedResult === undefined) {
|
|
58
|
+
return {
|
|
59
|
+
success: false,
|
|
60
|
+
diagnostics: [(0, diagnostics_1.createWorkerNotInitializedDiagnostic)()],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const id = this.createRequestId();
|
|
64
|
+
const message = {
|
|
65
|
+
protocol: types_1.ESBUILD_WASM_WORKER_PROTOCOL,
|
|
66
|
+
id,
|
|
67
|
+
type: "transform",
|
|
68
|
+
payload: request,
|
|
69
|
+
};
|
|
70
|
+
const response = await this.requestWorker(message, (diagnostics) => ({
|
|
71
|
+
protocol: types_1.ESBUILD_WASM_WORKER_PROTOCOL,
|
|
72
|
+
id,
|
|
73
|
+
type: "transform:result",
|
|
74
|
+
success: false,
|
|
75
|
+
diagnostics,
|
|
76
|
+
}));
|
|
77
|
+
if (!response.success) {
|
|
78
|
+
return {
|
|
79
|
+
success: false,
|
|
80
|
+
diagnostics: response.diagnostics,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
success: true,
|
|
85
|
+
outputText: response.payload.outputText,
|
|
86
|
+
warnings: response.payload.warnings,
|
|
87
|
+
diagnostics: [],
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
unsupportedOperation(operation) {
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
operation,
|
|
94
|
+
diagnostics: [(0, diagnostics_1.createUnsupportedOperationDiagnostic)(operation)],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
dispose() {
|
|
98
|
+
this.failPendingRequests([
|
|
99
|
+
(0, diagnostics_1.createWorkerStartupFailureDiagnostic)({
|
|
100
|
+
workerScriptUrl: stringifyUrl(this.workerScriptUrl),
|
|
101
|
+
cause: "Worker service disposed.",
|
|
102
|
+
causeCategory: "message_channel",
|
|
103
|
+
}),
|
|
104
|
+
]);
|
|
105
|
+
if (this.worker === undefined) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
this.worker.removeEventListener("message", this.handleMessage);
|
|
109
|
+
this.worker.removeEventListener("error", this.handleError);
|
|
110
|
+
this.worker.terminate?.();
|
|
111
|
+
this.worker = undefined;
|
|
112
|
+
this.initializePromise = undefined;
|
|
113
|
+
this.initializedResult = undefined;
|
|
114
|
+
}
|
|
115
|
+
async initializeWorker(request) {
|
|
116
|
+
const workerResult = this.ensureWorker();
|
|
117
|
+
if (!workerResult.ok) {
|
|
118
|
+
return {
|
|
119
|
+
success: false,
|
|
120
|
+
diagnostics: [workerResult.diagnostic],
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const id = this.createRequestId();
|
|
124
|
+
const wasmAssetUrl = stringifyUrl(request.wasmAssetUrl ?? this.wasmAssetUrl);
|
|
125
|
+
const message = {
|
|
126
|
+
protocol: types_1.ESBUILD_WASM_WORKER_PROTOCOL,
|
|
127
|
+
id,
|
|
128
|
+
type: "initialize",
|
|
129
|
+
payload: {
|
|
130
|
+
wasmAssetUrl,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
const response = await this.requestWorker(message, (diagnostics) => ({
|
|
134
|
+
protocol: types_1.ESBUILD_WASM_WORKER_PROTOCOL,
|
|
135
|
+
id,
|
|
136
|
+
type: "initialize:result",
|
|
137
|
+
success: false,
|
|
138
|
+
diagnostics,
|
|
139
|
+
}));
|
|
140
|
+
if (!response.success) {
|
|
141
|
+
return {
|
|
142
|
+
success: false,
|
|
143
|
+
diagnostics: response.diagnostics,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
success: true,
|
|
148
|
+
metadata: response.payload,
|
|
149
|
+
diagnostics: [],
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
requestWorker(message, createFailureResponse) {
|
|
153
|
+
const workerResult = this.ensureWorker();
|
|
154
|
+
if (!workerResult.ok) {
|
|
155
|
+
return Promise.resolve(createFailureResponse([workerResult.diagnostic]));
|
|
156
|
+
}
|
|
157
|
+
return new Promise((resolve) => {
|
|
158
|
+
const timeoutId = setTimeout(() => {
|
|
159
|
+
this.pendingRequests.delete(message.id);
|
|
160
|
+
resolve(createFailureResponse([
|
|
161
|
+
(0, diagnostics_1.createWorkerStartupFailureDiagnostic)({
|
|
162
|
+
workerScriptUrl: stringifyUrl(this.workerScriptUrl),
|
|
163
|
+
cause: `No worker response within ${this.requestTimeoutMs}ms.`,
|
|
164
|
+
causeCategory: "message_channel",
|
|
165
|
+
}),
|
|
166
|
+
]));
|
|
167
|
+
}, this.requestTimeoutMs);
|
|
168
|
+
this.pendingRequests.set(message.id, {
|
|
169
|
+
resolve: (response) => resolve(response),
|
|
170
|
+
fail: (diagnostics) => resolve(createFailureResponse(diagnostics)),
|
|
171
|
+
timeoutId,
|
|
172
|
+
});
|
|
173
|
+
try {
|
|
174
|
+
workerResult.worker.postMessage(message);
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
const pending = this.pendingRequests.get(message.id);
|
|
178
|
+
if (pending !== undefined) {
|
|
179
|
+
this.pendingRequests.delete(message.id);
|
|
180
|
+
clearTimeout(pending.timeoutId);
|
|
181
|
+
}
|
|
182
|
+
resolve(createFailureResponse([
|
|
183
|
+
(0, diagnostics_1.createWorkerStartupFailureDiagnostic)({
|
|
184
|
+
workerScriptUrl: stringifyUrl(this.workerScriptUrl),
|
|
185
|
+
cause: error,
|
|
186
|
+
causeCategory: "message_channel",
|
|
187
|
+
}),
|
|
188
|
+
]));
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
ensureWorker() {
|
|
193
|
+
if (this.worker !== undefined) {
|
|
194
|
+
return {
|
|
195
|
+
ok: true,
|
|
196
|
+
worker: this.worker,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
try {
|
|
200
|
+
const worker = this.workerFactory(this.workerScriptUrl);
|
|
201
|
+
worker.addEventListener("message", this.handleMessage);
|
|
202
|
+
worker.addEventListener("error", this.handleError);
|
|
203
|
+
this.worker = worker;
|
|
204
|
+
return {
|
|
205
|
+
ok: true,
|
|
206
|
+
worker,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
return {
|
|
211
|
+
ok: false,
|
|
212
|
+
diagnostic: (0, diagnostics_1.createWorkerStartupFailureDiagnostic)({
|
|
213
|
+
workerScriptUrl: stringifyUrl(this.workerScriptUrl),
|
|
214
|
+
cause: error,
|
|
215
|
+
causeCategory: "worker_script_load",
|
|
216
|
+
}),
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
failPendingRequests(diagnostics) {
|
|
221
|
+
const pendingRequests = Array.from(this.pendingRequests.values());
|
|
222
|
+
this.pendingRequests.clear();
|
|
223
|
+
for (const pending of pendingRequests) {
|
|
224
|
+
clearTimeout(pending.timeoutId);
|
|
225
|
+
pending.fail(diagnostics);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
createRequestId() {
|
|
229
|
+
const id = `esbuild-wasm-${this.nextRequestId}`;
|
|
230
|
+
this.nextRequestId += 1;
|
|
231
|
+
return id;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
exports.DefaultEsbuildWasmWorkerService = DefaultEsbuildWasmWorkerService;
|
|
235
|
+
function createEsbuildWasmWorkerService(options) {
|
|
236
|
+
return new DefaultEsbuildWasmWorkerService(options);
|
|
237
|
+
}
|
|
238
|
+
exports.createEsbuildWasmWorkerService = createEsbuildWasmWorkerService;
|
|
239
|
+
function createDefaultWorker(workerScriptUrl) {
|
|
240
|
+
return new Worker(workerScriptUrl, {
|
|
241
|
+
type: "module",
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function isWorkerResponseMessage(message) {
|
|
245
|
+
if (message === null || typeof message !== "object") {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
const candidate = message;
|
|
249
|
+
return (candidate.protocol === types_1.ESBUILD_WASM_WORKER_PROTOCOL &&
|
|
250
|
+
typeof candidate.id === "string" &&
|
|
251
|
+
(candidate.type === "initialize:result" ||
|
|
252
|
+
candidate.type === "transform:result"));
|
|
253
|
+
}
|
|
254
|
+
function stringifyUrl(url) {
|
|
255
|
+
return typeof url === "string" ? url : url.toString();
|
|
256
|
+
}
|
|
257
|
+
function getEventCause(event) {
|
|
258
|
+
const maybeErrorEvent = event;
|
|
259
|
+
return maybeErrorEvent.error ?? maybeErrorEvent.message ?? event.type;
|
|
260
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
export declare const ESBUILD_WASM_WORKER_CAPABILITY: "esbuild-wasm-worker";
|
|
2
|
+
export declare const ESBUILD_WASM_WORKER_PROTOCOL: "forge.esbuild-wasm-worker.v1";
|
|
3
|
+
export type ForgeEsbuildWasmUrl = string | URL;
|
|
4
|
+
export type ForgeEsbuildWasmWorkerDiagnosticCode = "worker_startup_failed" | "wasm_initialization_failed" | "worker_not_initialized" | "unsupported_operation" | "transform_failed";
|
|
5
|
+
export type ForgeEsbuildWasmDiagnosticCauseCategory = "message_channel" | "runtime_initialization" | "transform" | "worker_script_load";
|
|
6
|
+
export interface ForgeEsbuildWasmWorkerDiagnostic {
|
|
7
|
+
readonly code: ForgeEsbuildWasmWorkerDiagnosticCode;
|
|
8
|
+
readonly severity: "error";
|
|
9
|
+
readonly message: string;
|
|
10
|
+
readonly cause?: unknown;
|
|
11
|
+
readonly causeCategory?: ForgeEsbuildWasmDiagnosticCauseCategory;
|
|
12
|
+
readonly operation?: ForgeEsbuildWasmUnsupportedOperation;
|
|
13
|
+
readonly path?: string;
|
|
14
|
+
readonly wasmAssetUrl?: string;
|
|
15
|
+
readonly workerScriptUrl?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ForgeEsbuildWasmRuntimeMetadata {
|
|
18
|
+
readonly capability: typeof ESBUILD_WASM_WORKER_CAPABILITY;
|
|
19
|
+
readonly initialized: true;
|
|
20
|
+
readonly wasmAssetUrl: string;
|
|
21
|
+
readonly esbuildVersion?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ForgeEsbuildWasmInitializeRequest {
|
|
24
|
+
readonly wasmAssetUrl?: ForgeEsbuildWasmUrl;
|
|
25
|
+
}
|
|
26
|
+
export interface ForgeEsbuildWasmInitializeSuccessResult {
|
|
27
|
+
readonly success: true;
|
|
28
|
+
readonly metadata: ForgeEsbuildWasmRuntimeMetadata;
|
|
29
|
+
readonly diagnostics: readonly [];
|
|
30
|
+
}
|
|
31
|
+
export interface ForgeEsbuildWasmInitializeFailureResult {
|
|
32
|
+
readonly success: false;
|
|
33
|
+
readonly diagnostics: readonly ForgeEsbuildWasmWorkerDiagnostic[];
|
|
34
|
+
}
|
|
35
|
+
export type ForgeEsbuildWasmInitializeResult = ForgeEsbuildWasmInitializeSuccessResult | ForgeEsbuildWasmInitializeFailureResult;
|
|
36
|
+
export type ForgeEsbuildWasmTransformLoader = "ts" | "tsx";
|
|
37
|
+
export interface ForgeEsbuildWasmTransformRequest {
|
|
38
|
+
readonly sourceText: string;
|
|
39
|
+
readonly loader: ForgeEsbuildWasmTransformLoader;
|
|
40
|
+
readonly sourcePath: string;
|
|
41
|
+
readonly target?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface ForgeEsbuildWasmTransformWarning {
|
|
44
|
+
readonly text: string;
|
|
45
|
+
readonly location?: {
|
|
46
|
+
readonly file: string;
|
|
47
|
+
readonly line: number;
|
|
48
|
+
readonly column: number;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface ForgeEsbuildWasmTransformSuccessResult {
|
|
52
|
+
readonly success: true;
|
|
53
|
+
readonly outputText: string;
|
|
54
|
+
readonly warnings: readonly ForgeEsbuildWasmTransformWarning[];
|
|
55
|
+
readonly diagnostics: readonly [];
|
|
56
|
+
}
|
|
57
|
+
export interface ForgeEsbuildWasmTransformFailureResult {
|
|
58
|
+
readonly success: false;
|
|
59
|
+
readonly diagnostics: readonly ForgeEsbuildWasmWorkerDiagnostic[];
|
|
60
|
+
}
|
|
61
|
+
export type ForgeEsbuildWasmTransformResult = ForgeEsbuildWasmTransformSuccessResult | ForgeEsbuildWasmTransformFailureResult;
|
|
62
|
+
export type ForgeEsbuildWasmUnsupportedOperation = "hmr" | "package_bundling" | "registry_resolution" | "vite_config_loading";
|
|
63
|
+
export interface ForgeEsbuildWasmUnsupportedOperationResult {
|
|
64
|
+
readonly success: false;
|
|
65
|
+
readonly operation: ForgeEsbuildWasmUnsupportedOperation;
|
|
66
|
+
readonly diagnostics: readonly ForgeEsbuildWasmWorkerDiagnostic[];
|
|
67
|
+
}
|
|
68
|
+
export interface ForgeEsbuildWasmWorkerServiceOptions {
|
|
69
|
+
readonly workerScriptUrl: ForgeEsbuildWasmUrl;
|
|
70
|
+
readonly wasmAssetUrl: ForgeEsbuildWasmUrl;
|
|
71
|
+
readonly requestTimeoutMs?: number;
|
|
72
|
+
readonly workerFactory?: ForgeEsbuildWasmWorkerFactory;
|
|
73
|
+
}
|
|
74
|
+
export interface ForgeEsbuildWasmWorkerService {
|
|
75
|
+
readonly capability: typeof ESBUILD_WASM_WORKER_CAPABILITY;
|
|
76
|
+
initialize(request?: ForgeEsbuildWasmInitializeRequest): Promise<ForgeEsbuildWasmInitializeResult>;
|
|
77
|
+
transform(request: ForgeEsbuildWasmTransformRequest): Promise<ForgeEsbuildWasmTransformResult>;
|
|
78
|
+
unsupportedOperation(operation: ForgeEsbuildWasmUnsupportedOperation): ForgeEsbuildWasmUnsupportedOperationResult;
|
|
79
|
+
dispose(): void;
|
|
80
|
+
}
|
|
81
|
+
export type ForgeEsbuildWasmWorkerFactory = (workerScriptUrl: ForgeEsbuildWasmUrl) => ForgeEsbuildWasmWorkerPort;
|
|
82
|
+
export interface ForgeEsbuildWasmWorkerMessageEvent {
|
|
83
|
+
readonly data: ForgeEsbuildWasmWorkerResponseMessage;
|
|
84
|
+
}
|
|
85
|
+
export interface ForgeEsbuildWasmWorkerPort {
|
|
86
|
+
postMessage(message: ForgeEsbuildWasmWorkerRequestMessage): void;
|
|
87
|
+
addEventListener(type: "message", listener: (event: ForgeEsbuildWasmWorkerMessageEvent) => void): void;
|
|
88
|
+
addEventListener(type: "error", listener: (event: Event) => void): void;
|
|
89
|
+
removeEventListener(type: "message", listener: (event: ForgeEsbuildWasmWorkerMessageEvent) => void): void;
|
|
90
|
+
removeEventListener(type: "error", listener: (event: Event) => void): void;
|
|
91
|
+
terminate?(): void;
|
|
92
|
+
}
|
|
93
|
+
export interface ForgeEsbuildWasmInitializeWorkerRequest {
|
|
94
|
+
readonly protocol: typeof ESBUILD_WASM_WORKER_PROTOCOL;
|
|
95
|
+
readonly id: string;
|
|
96
|
+
readonly type: "initialize";
|
|
97
|
+
readonly payload: {
|
|
98
|
+
readonly wasmAssetUrl: string;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export interface ForgeEsbuildWasmTransformWorkerRequest {
|
|
102
|
+
readonly protocol: typeof ESBUILD_WASM_WORKER_PROTOCOL;
|
|
103
|
+
readonly id: string;
|
|
104
|
+
readonly type: "transform";
|
|
105
|
+
readonly payload: ForgeEsbuildWasmTransformRequest;
|
|
106
|
+
}
|
|
107
|
+
export type ForgeEsbuildWasmWorkerRequestMessage = ForgeEsbuildWasmInitializeWorkerRequest | ForgeEsbuildWasmTransformWorkerRequest;
|
|
108
|
+
export interface ForgeEsbuildWasmInitializeWorkerSuccessResponse {
|
|
109
|
+
readonly protocol: typeof ESBUILD_WASM_WORKER_PROTOCOL;
|
|
110
|
+
readonly id: string;
|
|
111
|
+
readonly type: "initialize:result";
|
|
112
|
+
readonly success: true;
|
|
113
|
+
readonly payload: ForgeEsbuildWasmRuntimeMetadata;
|
|
114
|
+
}
|
|
115
|
+
export interface ForgeEsbuildWasmInitializeWorkerFailureResponse {
|
|
116
|
+
readonly protocol: typeof ESBUILD_WASM_WORKER_PROTOCOL;
|
|
117
|
+
readonly id: string;
|
|
118
|
+
readonly type: "initialize:result";
|
|
119
|
+
readonly success: false;
|
|
120
|
+
readonly diagnostics: readonly ForgeEsbuildWasmWorkerDiagnostic[];
|
|
121
|
+
}
|
|
122
|
+
export interface ForgeEsbuildWasmTransformWorkerSuccessResponse {
|
|
123
|
+
readonly protocol: typeof ESBUILD_WASM_WORKER_PROTOCOL;
|
|
124
|
+
readonly id: string;
|
|
125
|
+
readonly type: "transform:result";
|
|
126
|
+
readonly success: true;
|
|
127
|
+
readonly payload: {
|
|
128
|
+
readonly outputText: string;
|
|
129
|
+
readonly warnings: readonly ForgeEsbuildWasmTransformWarning[];
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export interface ForgeEsbuildWasmTransformWorkerFailureResponse {
|
|
133
|
+
readonly protocol: typeof ESBUILD_WASM_WORKER_PROTOCOL;
|
|
134
|
+
readonly id: string;
|
|
135
|
+
readonly type: "transform:result";
|
|
136
|
+
readonly success: false;
|
|
137
|
+
readonly diagnostics: readonly ForgeEsbuildWasmWorkerDiagnostic[];
|
|
138
|
+
}
|
|
139
|
+
export type ForgeEsbuildWasmWorkerResponseMessage = ForgeEsbuildWasmInitializeWorkerSuccessResponse | ForgeEsbuildWasmInitializeWorkerFailureResponse | ForgeEsbuildWasmTransformWorkerSuccessResponse | ForgeEsbuildWasmTransformWorkerFailureResponse;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ESBUILD_WASM_WORKER_PROTOCOL = exports.ESBUILD_WASM_WORKER_CAPABILITY = void 0;
|
|
4
|
+
exports.ESBUILD_WASM_WORKER_CAPABILITY = "esbuild-wasm-worker";
|
|
5
|
+
exports.ESBUILD_WASM_WORKER_PROTOCOL = "forge.esbuild-wasm-worker.v1";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ForgeEsbuildWasmWorkerRequestMessage, type ForgeEsbuildWasmWorkerResponseMessage } from "./types";
|
|
2
|
+
export interface ForgeEsbuildWasmRuntime {
|
|
3
|
+
readonly version?: string;
|
|
4
|
+
initialize(options: {
|
|
5
|
+
readonly wasmURL: string;
|
|
6
|
+
readonly worker: false;
|
|
7
|
+
}): Promise<void>;
|
|
8
|
+
transform(sourceText: string, options: {
|
|
9
|
+
readonly loader: "ts" | "tsx";
|
|
10
|
+
readonly sourcefile: string;
|
|
11
|
+
readonly target?: string;
|
|
12
|
+
readonly format: "esm";
|
|
13
|
+
}): Promise<{
|
|
14
|
+
readonly code: string;
|
|
15
|
+
readonly warnings: readonly EsbuildTransformWarning[];
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
interface EsbuildTransformWarning {
|
|
19
|
+
readonly text?: string;
|
|
20
|
+
readonly location?: {
|
|
21
|
+
readonly file?: string;
|
|
22
|
+
readonly line?: number;
|
|
23
|
+
readonly column?: number;
|
|
24
|
+
} | null;
|
|
25
|
+
}
|
|
26
|
+
export interface ForgeEsbuildWasmWorkerAdapterOptions {
|
|
27
|
+
readonly runtime?: ForgeEsbuildWasmRuntime;
|
|
28
|
+
readonly postMessage?: (message: ForgeEsbuildWasmWorkerResponseMessage) => void;
|
|
29
|
+
}
|
|
30
|
+
export interface ForgeEsbuildWasmWorkerGlobalScope {
|
|
31
|
+
postMessage(message: ForgeEsbuildWasmWorkerResponseMessage): void;
|
|
32
|
+
addEventListener(type: "message", listener: (event: MessageEvent<ForgeEsbuildWasmWorkerRequestMessage>) => void): void;
|
|
33
|
+
}
|
|
34
|
+
export declare function createEsbuildWasmWorkerMessageHandler(options?: ForgeEsbuildWasmWorkerAdapterOptions): (event: {
|
|
35
|
+
readonly data: ForgeEsbuildWasmWorkerRequestMessage;
|
|
36
|
+
}) => void;
|
|
37
|
+
export declare function installEsbuildWasmWorker(scope?: ForgeEsbuildWasmWorkerGlobalScope): void;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.installEsbuildWasmWorker = exports.createEsbuildWasmWorkerMessageHandler = void 0;
|
|
27
|
+
const esbuild = __importStar(require("esbuild-wasm/lib/browser"));
|
|
28
|
+
const diagnostics_1 = require("./diagnostics");
|
|
29
|
+
const types_1 = require("./types");
|
|
30
|
+
function createEsbuildWasmWorkerMessageHandler(options = {}) {
|
|
31
|
+
const runtime = options.runtime ?? esbuild;
|
|
32
|
+
const postMessage = options.postMessage ??
|
|
33
|
+
((message) => {
|
|
34
|
+
self.postMessage(message);
|
|
35
|
+
});
|
|
36
|
+
let initializedMetadata;
|
|
37
|
+
let initializePromise;
|
|
38
|
+
return (event) => {
|
|
39
|
+
const message = event.data;
|
|
40
|
+
if (!isWorkerRequestMessage(message)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
void handleMessage(message);
|
|
44
|
+
};
|
|
45
|
+
async function handleMessage(message) {
|
|
46
|
+
if (message.type === "initialize") {
|
|
47
|
+
await handleInitialize(message);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
await handleTransform(message);
|
|
51
|
+
}
|
|
52
|
+
async function handleInitialize(message) {
|
|
53
|
+
try {
|
|
54
|
+
if (initializedMetadata === undefined) {
|
|
55
|
+
if (initializePromise === undefined) {
|
|
56
|
+
initializePromise = initializeRuntime(message.payload.wasmAssetUrl);
|
|
57
|
+
}
|
|
58
|
+
initializedMetadata = await initializePromise;
|
|
59
|
+
}
|
|
60
|
+
postMessage({
|
|
61
|
+
protocol: types_1.ESBUILD_WASM_WORKER_PROTOCOL,
|
|
62
|
+
id: message.id,
|
|
63
|
+
type: "initialize:result",
|
|
64
|
+
success: true,
|
|
65
|
+
payload: initializedMetadata,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
initializePromise = undefined;
|
|
70
|
+
postMessage({
|
|
71
|
+
protocol: types_1.ESBUILD_WASM_WORKER_PROTOCOL,
|
|
72
|
+
id: message.id,
|
|
73
|
+
type: "initialize:result",
|
|
74
|
+
success: false,
|
|
75
|
+
diagnostics: [
|
|
76
|
+
(0, diagnostics_1.createWasmInitializationFailureDiagnostic)(message.payload.wasmAssetUrl, error),
|
|
77
|
+
],
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function initializeRuntime(wasmAssetUrl) {
|
|
82
|
+
await runtime.initialize({
|
|
83
|
+
wasmURL: wasmAssetUrl,
|
|
84
|
+
worker: false,
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
capability: types_1.ESBUILD_WASM_WORKER_CAPABILITY,
|
|
88
|
+
initialized: true,
|
|
89
|
+
wasmAssetUrl,
|
|
90
|
+
esbuildVersion: runtime.version,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
async function handleTransform(message) {
|
|
94
|
+
if (initializedMetadata === undefined) {
|
|
95
|
+
postMessage({
|
|
96
|
+
protocol: types_1.ESBUILD_WASM_WORKER_PROTOCOL,
|
|
97
|
+
id: message.id,
|
|
98
|
+
type: "transform:result",
|
|
99
|
+
success: false,
|
|
100
|
+
diagnostics: [(0, diagnostics_1.createWorkerNotInitializedDiagnostic)()],
|
|
101
|
+
});
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const transform = await runtime.transform(message.payload.sourceText, {
|
|
106
|
+
loader: message.payload.loader,
|
|
107
|
+
sourcefile: message.payload.sourcePath,
|
|
108
|
+
target: message.payload.target,
|
|
109
|
+
format: "esm",
|
|
110
|
+
});
|
|
111
|
+
postMessage({
|
|
112
|
+
protocol: types_1.ESBUILD_WASM_WORKER_PROTOCOL,
|
|
113
|
+
id: message.id,
|
|
114
|
+
type: "transform:result",
|
|
115
|
+
success: true,
|
|
116
|
+
payload: {
|
|
117
|
+
outputText: transform.code,
|
|
118
|
+
warnings: mapTransformWarnings(transform.warnings),
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
postMessage({
|
|
124
|
+
protocol: types_1.ESBUILD_WASM_WORKER_PROTOCOL,
|
|
125
|
+
id: message.id,
|
|
126
|
+
type: "transform:result",
|
|
127
|
+
success: false,
|
|
128
|
+
diagnostics: [
|
|
129
|
+
(0, diagnostics_1.createTransformFailureDiagnostic)(message.payload.sourcePath, error),
|
|
130
|
+
],
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.createEsbuildWasmWorkerMessageHandler = createEsbuildWasmWorkerMessageHandler;
|
|
136
|
+
function installEsbuildWasmWorker(scope = self) {
|
|
137
|
+
scope.addEventListener("message", createEsbuildWasmWorkerMessageHandler({
|
|
138
|
+
postMessage: (message) => scope.postMessage(message),
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
exports.installEsbuildWasmWorker = installEsbuildWasmWorker;
|
|
142
|
+
function isWorkerRequestMessage(message) {
|
|
143
|
+
if (message === null || typeof message !== "object") {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
const candidate = message;
|
|
147
|
+
return (candidate.protocol === types_1.ESBUILD_WASM_WORKER_PROTOCOL &&
|
|
148
|
+
typeof candidate.id === "string" &&
|
|
149
|
+
(candidate.type === "initialize" || candidate.type === "transform"));
|
|
150
|
+
}
|
|
151
|
+
function mapTransformWarnings(warnings) {
|
|
152
|
+
return warnings.map((warning) => {
|
|
153
|
+
const location = warning.location;
|
|
154
|
+
return {
|
|
155
|
+
text: warning.text ?? "Esbuild transform warning.",
|
|
156
|
+
location: location === null || location === undefined
|
|
157
|
+
? undefined
|
|
158
|
+
: {
|
|
159
|
+
file: location.file ?? "",
|
|
160
|
+
line: location.line ?? 0,
|
|
161
|
+
column: location.column ?? 0,
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
});
|
|
165
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ForgeBuildPipeline, type ForgeBuildPipelineOptions } from "./build-pipeline";
|
|
2
|
+
import { type ForgeDevServerPreview, type ForgeDevServerPreviewOptions, type ForgeDevSessionRefreshResult, type ForgeDevSessionStartResult, type ForgeDevSessionStopResult, type ForgeRebuildDevSessionOptions, type ForgeStartDevSessionOptions } from "./dev-server-preview";
|
|
3
|
+
import { type ForgeVirtualFileSystem, type ForgeOpenVirtualFileSystemOptions } from "./virtual-file-system";
|
|
4
|
+
import { type ForgePackageResolver, type ForgePackageResolverOptions } from "./package-resolution";
|
|
5
|
+
import { type ForgeCommandResult, type ForgeTerminal, type ForgeTerminalExecuteOptions, type ForgeTerminalOptions } from "./terminal-commands";
|
|
6
|
+
type ForgeControllerPackageResolutionOptions = Omit<ForgePackageResolverOptions, "fileSystem">;
|
|
7
|
+
type ForgeOpenControllerPackageResolutionOptions = Omit<ForgePackageResolverOptions, "fileSystem" | "storage">;
|
|
8
|
+
type ForgeControllerTerminalOptions = Omit<ForgeTerminalOptions, "buildPipeline" | "packageResolver">;
|
|
9
|
+
type ForgeControllerBuildPipelineOptions = Omit<ForgeBuildPipelineOptions, "fileSystem" | "packageResolver">;
|
|
10
|
+
type ForgeControllerDevServerPreviewOptions = Omit<ForgeDevServerPreviewOptions, "fileSystem" | "buildPipeline">;
|
|
11
|
+
export interface ForgeControllerOptions {
|
|
12
|
+
readonly fileSystem?: ForgeVirtualFileSystem;
|
|
13
|
+
readonly buildPipeline?: ForgeBuildPipeline;
|
|
14
|
+
readonly buildPipelineOptions?: ForgeControllerBuildPipelineOptions;
|
|
15
|
+
readonly devServerPreview?: ForgeDevServerPreview;
|
|
16
|
+
readonly devServerPreviewOptions?: ForgeControllerDevServerPreviewOptions;
|
|
17
|
+
readonly packageResolver?: ForgePackageResolver;
|
|
18
|
+
readonly packageResolution?: ForgeControllerPackageResolutionOptions;
|
|
19
|
+
readonly terminal?: ForgeTerminal;
|
|
20
|
+
readonly terminalOptions?: ForgeControllerTerminalOptions;
|
|
21
|
+
}
|
|
22
|
+
export interface ForgeOpenControllerOptions extends ForgeOpenVirtualFileSystemOptions {
|
|
23
|
+
readonly packageResolution?: ForgeOpenControllerPackageResolutionOptions;
|
|
24
|
+
}
|
|
25
|
+
export interface ForgeController {
|
|
26
|
+
readonly fileSystem: ForgeVirtualFileSystem;
|
|
27
|
+
readonly buildPipeline: ForgeBuildPipeline;
|
|
28
|
+
readonly devServerPreview: ForgeDevServerPreview;
|
|
29
|
+
readonly packageResolver: ForgePackageResolver;
|
|
30
|
+
readonly terminal: ForgeTerminal;
|
|
31
|
+
executeCommand(commandText: string, options?: ForgeTerminalExecuteOptions): Promise<ForgeCommandResult>;
|
|
32
|
+
rebuildDevSession(sessionId: string, options?: ForgeRebuildDevSessionOptions): Promise<ForgeDevSessionRefreshResult>;
|
|
33
|
+
startDevSession(options?: ForgeStartDevSessionOptions): Promise<ForgeDevSessionStartResult>;
|
|
34
|
+
stopDevSession(sessionId: string): Promise<ForgeDevSessionStopResult>;
|
|
35
|
+
}
|
|
36
|
+
export declare function createForgeController(options?: ForgeControllerOptions): ForgeController;
|
|
37
|
+
export declare function openForgeController(options: ForgeOpenControllerOptions): Promise<ForgeController>;
|
|
38
|
+
export {};
|