@caryhu/codemine-forge 0.0.1-alpha.0 → 0.0.1-alpha.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/README.md +8 -4
- package/dist/build-pipeline/browser-bundle.d.ts +2 -1
- package/dist/build-pipeline/browser-bundle.js +384 -24
- package/dist/build-pipeline/diagnostics.d.ts +1 -0
- package/dist/build-pipeline/diagnostics.js +11 -2
- package/dist/build-pipeline/index.d.ts +2 -2
- package/dist/build-pipeline/index.js +2 -1
- package/dist/build-pipeline/pipeline.d.ts +2 -0
- package/dist/build-pipeline/pipeline.js +149 -28
- package/dist/build-pipeline/types.d.ts +24 -2
- package/dist/build-pipeline/vite-config.d.ts +8 -0
- package/dist/build-pipeline/vite-config.js +215 -0
- package/dist/dev-server-preview/index.d.ts +2 -2
- package/dist/dev-server-preview/index.js +2 -1
- package/dist/dev-server-preview/preview-document.d.ts +2 -1
- package/dist/dev-server-preview/preview-document.js +203 -1
- package/dist/dev-server-preview/server.d.ts +8 -1
- package/dist/dev-server-preview/server.js +248 -33
- package/dist/dev-server-preview/types.d.ts +40 -1
- package/dist/forge-controller.js +1 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +16 -2
- package/dist/package-resolution/diagnostics.d.ts +1 -0
- package/dist/package-resolution/diagnostics.js +10 -1
- package/dist/package-resolution/errors.d.ts +2 -1
- package/dist/package-resolution/errors.js +2 -1
- package/dist/package-resolution/index.d.ts +2 -2
- package/dist/package-resolution/index.js +2 -1
- package/dist/package-resolution/resolver.d.ts +3 -0
- package/dist/package-resolution/resolver.js +123 -29
- package/dist/package-resolution/types.d.ts +7 -1
- package/dist/telemetry/index.d.ts +68 -0
- package/dist/telemetry/index.js +65 -0
- package/dist/terminal-commands/npm-build.js +3 -1
- package/dist/terminal-commands/npm-dev.js +3 -1
- package/dist/terminal-commands/npm-install.js +7 -2
- package/dist/terminal-commands/terminal.d.ts +1 -0
- package/dist/terminal-commands/terminal.js +1 -0
- package/dist/terminal-commands/types.d.ts +2 -0
- package/dist/virtual-file-system/diagnostics.d.ts +1 -0
- package/dist/virtual-file-system/diagnostics.js +9 -1
- package/dist/virtual-file-system/index.d.ts +4 -2
- package/dist/virtual-file-system/index.js +7 -1
- package/dist/virtual-file-system/snapshot-serialization.d.ts +3 -0
- package/dist/virtual-file-system/snapshot-serialization.js +242 -0
- package/dist/virtual-file-system/storage.d.ts +1 -1
- package/dist/virtual-file-system/storage.js +41 -18
- package/dist/virtual-file-system/types.d.ts +28 -1
- package/dist/virtual-file-system/types.js +2 -0
- package/package.json +2 -2
|
@@ -2,16 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isSupportedViteBuildScript = exports.createBuildPipeline = exports.DefaultBuildPipeline = void 0;
|
|
4
4
|
const package_resolution_1 = require("../package-resolution");
|
|
5
|
+
const telemetry_1 = require("../telemetry");
|
|
5
6
|
const virtual_file_system_1 = require("../virtual-file-system");
|
|
6
7
|
const diagnostics_1 = require("./diagnostics");
|
|
7
8
|
const browser_bundle_1 = require("./browser-bundle");
|
|
8
9
|
const types_1 = require("./types");
|
|
10
|
+
const vite_config_1 = require("./vite-config");
|
|
9
11
|
const BUILD_MANIFEST_PATH = "/.forge/build/build-manifest.json";
|
|
10
|
-
const VITE_CONFIG_PATHS = [
|
|
11
|
-
"/vite.config.js",
|
|
12
|
-
"/vite.config.mjs",
|
|
13
|
-
"/vite.config.ts",
|
|
14
|
-
];
|
|
15
12
|
const DEFAULT_ENTRY_CANDIDATES = [
|
|
16
13
|
"/src/main.tsx",
|
|
17
14
|
"/src/main.jsx",
|
|
@@ -27,64 +24,112 @@ class DefaultBuildPipeline {
|
|
|
27
24
|
async build(request = {}) {
|
|
28
25
|
const timingStart = createTimingStart(this.now());
|
|
29
26
|
const mode = "production";
|
|
30
|
-
const
|
|
27
|
+
const initialCancellation = getCancellationDiagnostic(request.signal);
|
|
28
|
+
if (initialCancellation !== undefined) {
|
|
29
|
+
return this.failure(mode, [initialCancellation], timingStart);
|
|
30
|
+
}
|
|
31
|
+
const viteConfigRead = await (0, vite_config_1.readViteConfigMetadata)(this.options.fileSystem);
|
|
32
|
+
const warningDiagnostics = createViteConfigDiagnostics(viteConfigRead.detectedPaths);
|
|
33
|
+
const viteConfig = viteConfigRead.metadata;
|
|
34
|
+
const configCancellation = getCancellationDiagnostic(request.signal);
|
|
35
|
+
if (configCancellation !== undefined) {
|
|
36
|
+
return this.failure(mode, [configCancellation, ...warningDiagnostics], timingStart, viteConfig);
|
|
37
|
+
}
|
|
31
38
|
let manifest;
|
|
32
39
|
try {
|
|
33
40
|
manifest = await (0, package_resolution_1.readPackageManifest)(this.options.fileSystem);
|
|
34
41
|
}
|
|
35
42
|
catch (error) {
|
|
36
43
|
if (error instanceof package_resolution_1.ForgePackageResolutionError) {
|
|
37
|
-
return this.failure(mode, [error.diagnostic, ...warningDiagnostics], timingStart);
|
|
44
|
+
return this.failure(mode, [error.diagnostic, ...error.warnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
38
45
|
}
|
|
39
46
|
throw error;
|
|
40
47
|
}
|
|
41
48
|
const buildScript = manifest.scripts.build;
|
|
42
49
|
if (buildScript === undefined) {
|
|
43
|
-
return this.failure(mode, [(0, diagnostics_1.createMissingBuildScriptDiagnostic)(), ...warningDiagnostics], timingStart);
|
|
50
|
+
return this.failure(mode, [(0, diagnostics_1.createMissingBuildScriptDiagnostic)(), ...warningDiagnostics], timingStart, viteConfig);
|
|
44
51
|
}
|
|
45
52
|
if (!isSupportedViteBuildScript(buildScript)) {
|
|
46
53
|
return this.failure(mode, [
|
|
47
54
|
(0, diagnostics_1.createUnsupportedBuildScriptDiagnostic)(buildScript),
|
|
48
55
|
...warningDiagnostics,
|
|
49
|
-
], timingStart);
|
|
56
|
+
], timingStart, viteConfig);
|
|
57
|
+
}
|
|
58
|
+
const manifestCancellation = getCancellationDiagnostic(request.signal);
|
|
59
|
+
if (manifestCancellation !== undefined) {
|
|
60
|
+
return this.failure(mode, [manifestCancellation, ...warningDiagnostics], timingStart, viteConfig);
|
|
50
61
|
}
|
|
51
62
|
const entry = await this.resolveEntry(request.entry);
|
|
52
63
|
if (entry === undefined) {
|
|
53
|
-
return this.failure(mode, [(0, diagnostics_1.createMissingEntryDiagnostic)(), ...warningDiagnostics], timingStart);
|
|
64
|
+
return this.failure(mode, [(0, diagnostics_1.createMissingEntryDiagnostic)(), ...warningDiagnostics], timingStart, viteConfig);
|
|
54
65
|
}
|
|
55
66
|
try {
|
|
56
67
|
const packageResolution = await this.options.packageResolver.resolve();
|
|
68
|
+
const packageWarnings = packageResolution.warnings;
|
|
69
|
+
const packageCancellation = getCancellationDiagnostic(request.signal);
|
|
70
|
+
if (packageCancellation !== undefined) {
|
|
71
|
+
return this.failure(mode, [packageCancellation, ...packageWarnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
72
|
+
}
|
|
57
73
|
const sourceFiles = await collectSourceFiles(this.options.fileSystem);
|
|
58
74
|
const browserBundleResult = await (0, browser_bundle_1.createBrowserBundle)({
|
|
59
75
|
entry,
|
|
60
76
|
fileSystem: this.options.fileSystem,
|
|
61
77
|
packageResolution,
|
|
62
78
|
scriptTransformer: createEsbuildWorkerScriptTransformer(this.options.esbuildWorker),
|
|
79
|
+
viteConfig,
|
|
63
80
|
});
|
|
64
81
|
if (browserBundleResult.diagnostics.length > 0) {
|
|
65
|
-
return this.failure(mode, [
|
|
82
|
+
return this.failure(mode, [
|
|
83
|
+
...browserBundleResult.diagnostics,
|
|
84
|
+
...packageWarnings,
|
|
85
|
+
...warningDiagnostics,
|
|
86
|
+
], timingStart, viteConfig);
|
|
87
|
+
}
|
|
88
|
+
if (browserBundleResult.browserBundle === undefined) {
|
|
89
|
+
throw new Error("Browser bundle output was missing after a successful build.");
|
|
66
90
|
}
|
|
67
|
-
const
|
|
91
|
+
const bundleCancellation = getCancellationDiagnostic(request.signal);
|
|
92
|
+
if (bundleCancellation !== undefined) {
|
|
93
|
+
return this.failure(mode, [bundleCancellation, ...packageWarnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
94
|
+
}
|
|
95
|
+
const buildManifest = createBuildManifest(entry, mode, sourceFiles, packageResolution, browserBundleResult.browserBundle, viteConfig);
|
|
68
96
|
const outputFiles = [
|
|
69
97
|
createBuildManifestOutput(buildManifest),
|
|
70
98
|
...browserBundleResult.outputFiles,
|
|
71
99
|
];
|
|
72
|
-
|
|
73
|
-
|
|
100
|
+
const outputCancellation = getCancellationDiagnostic(request.signal);
|
|
101
|
+
if (outputCancellation !== undefined) {
|
|
102
|
+
return this.failure(mode, [outputCancellation, ...packageWarnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
103
|
+
}
|
|
104
|
+
const outputWriteDiagnostic = await writeBuildOutputFilesAtomically(this.options.fileSystem, outputFiles);
|
|
105
|
+
if (outputWriteDiagnostic !== undefined) {
|
|
106
|
+
return this.failure(mode, [outputWriteDiagnostic, ...packageWarnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
107
|
+
}
|
|
108
|
+
const buildCacheWarnings = await this.writeBuildCacheRecord(entry, mode, buildManifest, browserBundleResult.browserBundle, outputFiles);
|
|
109
|
+
const cacheCancellation = getCancellationDiagnostic(request.signal);
|
|
110
|
+
if (cacheCancellation !== undefined) {
|
|
111
|
+
return this.failure(mode, [cacheCancellation, ...packageWarnings, ...buildCacheWarnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
112
|
+
}
|
|
113
|
+
return this.complete({
|
|
74
114
|
success: true,
|
|
75
115
|
mode,
|
|
76
116
|
entry,
|
|
77
117
|
browserBundle: browserBundleResult.browserBundle,
|
|
78
118
|
manifest: buildManifest,
|
|
79
119
|
outputFiles,
|
|
80
|
-
diagnostics:
|
|
120
|
+
diagnostics: [
|
|
121
|
+
...packageWarnings,
|
|
122
|
+
...buildCacheWarnings,
|
|
123
|
+
...warningDiagnostics,
|
|
124
|
+
],
|
|
81
125
|
packageResolution,
|
|
126
|
+
viteConfig,
|
|
82
127
|
timing: completeTiming(timingStart, this.now()),
|
|
83
|
-
};
|
|
128
|
+
});
|
|
84
129
|
}
|
|
85
130
|
catch (error) {
|
|
86
131
|
if (error instanceof package_resolution_1.ForgePackageResolutionError) {
|
|
87
|
-
return this.failure(mode, [error.diagnostic, ...warningDiagnostics], timingStart);
|
|
132
|
+
return this.failure(mode, [error.diagnostic, ...error.warnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
88
133
|
}
|
|
89
134
|
throw error;
|
|
90
135
|
}
|
|
@@ -108,17 +153,70 @@ class DefaultBuildPipeline {
|
|
|
108
153
|
}
|
|
109
154
|
return undefined;
|
|
110
155
|
}
|
|
111
|
-
failure(mode, diagnostics, timingStart) {
|
|
112
|
-
return {
|
|
156
|
+
failure(mode, diagnostics, timingStart, viteConfig) {
|
|
157
|
+
return this.complete({
|
|
113
158
|
success: false,
|
|
114
159
|
mode,
|
|
115
160
|
outputFiles: [],
|
|
116
161
|
diagnostics,
|
|
162
|
+
viteConfig,
|
|
117
163
|
timing: completeTiming(timingStart, this.now()),
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
complete(result) {
|
|
167
|
+
(0, telemetry_1.emitForgeTelemetry)(this.options.telemetry, {
|
|
168
|
+
operation: "build",
|
|
169
|
+
outcome: result.success ? "success" : "failure",
|
|
170
|
+
startedAt: result.timing.startedAt,
|
|
171
|
+
endedAt: result.timing.endedAt,
|
|
172
|
+
durationMs: result.timing.durationMs,
|
|
173
|
+
mode: result.mode,
|
|
174
|
+
entry: result.entry,
|
|
175
|
+
outputFileCount: result.outputFiles.length,
|
|
176
|
+
packageCount: result.packageResolution?.packages.length,
|
|
177
|
+
diagnostics: (0, telemetry_1.summarizeForgeTelemetryDiagnostics)(result.diagnostics),
|
|
178
|
+
});
|
|
179
|
+
return result;
|
|
180
|
+
}
|
|
181
|
+
async writeBuildCacheRecord(entry, mode, manifest, browserBundle, outputFiles) {
|
|
182
|
+
if (this.options.storage === undefined) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
const value = {
|
|
186
|
+
browserBundle,
|
|
187
|
+
entry,
|
|
188
|
+
manifest,
|
|
189
|
+
mode,
|
|
190
|
+
outputFiles: outputFiles.map((outputFile) => ({
|
|
191
|
+
contentType: outputFile.contentType,
|
|
192
|
+
path: outputFile.path,
|
|
193
|
+
size: outputFile.size,
|
|
194
|
+
})),
|
|
118
195
|
};
|
|
196
|
+
const encoded = new TextEncoder().encode(JSON.stringify(value));
|
|
197
|
+
try {
|
|
198
|
+
await this.options.storage.putBuildCacheRecord({
|
|
199
|
+
key: `build:${mode}:${entry}`,
|
|
200
|
+
size: encoded.byteLength,
|
|
201
|
+
updatedAt: this.now(),
|
|
202
|
+
value,
|
|
203
|
+
});
|
|
204
|
+
return [];
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
if (isLimitExceededError(error)) {
|
|
208
|
+
return [toWarningDiagnostic(error.diagnostic)];
|
|
209
|
+
}
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
119
212
|
}
|
|
120
213
|
}
|
|
121
214
|
exports.DefaultBuildPipeline = DefaultBuildPipeline;
|
|
215
|
+
function getCancellationDiagnostic(signal) {
|
|
216
|
+
return signal?.aborted === true
|
|
217
|
+
? (0, diagnostics_1.createBuildCancelledDiagnostic)(signal.reason)
|
|
218
|
+
: undefined;
|
|
219
|
+
}
|
|
122
220
|
function createEsbuildWorkerScriptTransformer(esbuildWorker) {
|
|
123
221
|
if (esbuildWorker === undefined) {
|
|
124
222
|
return undefined;
|
|
@@ -158,14 +256,8 @@ function createEsbuildWorkerScriptTransformer(esbuildWorker) {
|
|
|
158
256
|
};
|
|
159
257
|
};
|
|
160
258
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
for (const path of VITE_CONFIG_PATHS) {
|
|
164
|
-
if (await fileSystem.exists(path)) {
|
|
165
|
-
diagnostics.push((0, diagnostics_1.createViteConfigNotExecutedDiagnostic)(path));
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return diagnostics;
|
|
259
|
+
function createViteConfigDiagnostics(paths) {
|
|
260
|
+
return paths.map((path) => (0, diagnostics_1.createViteConfigNotExecutedDiagnostic)(path));
|
|
169
261
|
}
|
|
170
262
|
function createBuildPipeline(options) {
|
|
171
263
|
return new DefaultBuildPipeline(options);
|
|
@@ -212,13 +304,14 @@ async function collectSourceFiles(fileSystem, path = "/") {
|
|
|
212
304
|
}
|
|
213
305
|
return files.sort((left, right) => left.localeCompare(right));
|
|
214
306
|
}
|
|
215
|
-
function createBuildManifest(entry, mode, sourceFiles, packageResolution, browserBundle) {
|
|
307
|
+
function createBuildManifest(entry, mode, sourceFiles, packageResolution, browserBundle, viteConfig) {
|
|
216
308
|
return {
|
|
217
309
|
entry,
|
|
218
310
|
mode,
|
|
219
311
|
sourceFiles,
|
|
220
312
|
packageNames: packageResolution.packages.map((record) => record.name),
|
|
221
313
|
packageResolutionMode: packageResolution.lock.resolutionMode,
|
|
314
|
+
viteConfig,
|
|
222
315
|
browserBundle: browserBundle === undefined
|
|
223
316
|
? undefined
|
|
224
317
|
: {
|
|
@@ -226,7 +319,9 @@ function createBuildManifest(entry, mode, sourceFiles, packageResolution, browse
|
|
|
226
319
|
format: browserBundle.format,
|
|
227
320
|
importMapPath: browserBundle.importMapPath,
|
|
228
321
|
moduleCount: browserBundle.moduleCount,
|
|
322
|
+
modules: browserBundle.modules,
|
|
229
323
|
outputPaths: browserBundle.outputPaths,
|
|
324
|
+
viteConfig: browserBundle.viteConfig,
|
|
230
325
|
},
|
|
231
326
|
};
|
|
232
327
|
}
|
|
@@ -248,6 +343,22 @@ async function writeBuildOutputFiles(fileSystem, outputFiles) {
|
|
|
248
343
|
});
|
|
249
344
|
}
|
|
250
345
|
}
|
|
346
|
+
async function writeBuildOutputFilesAtomically(fileSystem, outputFiles) {
|
|
347
|
+
const rollbackSnapshot = await fileSystem.snapshot({
|
|
348
|
+
includeGeneratedFiles: true,
|
|
349
|
+
});
|
|
350
|
+
try {
|
|
351
|
+
await writeBuildOutputFiles(fileSystem, outputFiles);
|
|
352
|
+
return undefined;
|
|
353
|
+
}
|
|
354
|
+
catch (error) {
|
|
355
|
+
if (isLimitExceededError(error)) {
|
|
356
|
+
await fileSystem.restore(rollbackSnapshot);
|
|
357
|
+
return error.diagnostic;
|
|
358
|
+
}
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
251
362
|
async function ensureDirectory(fileSystem, path) {
|
|
252
363
|
await fileSystem.mkdir(path, {
|
|
253
364
|
recursive: true,
|
|
@@ -271,3 +382,13 @@ function completeTiming(start, endedAt) {
|
|
|
271
382
|
durationMs: Math.max(0, Date.now() - start.startedMs),
|
|
272
383
|
};
|
|
273
384
|
}
|
|
385
|
+
function isLimitExceededError(error) {
|
|
386
|
+
return (error instanceof virtual_file_system_1.ForgeFileSystemError &&
|
|
387
|
+
error.diagnostic.code === "limit_exceeded");
|
|
388
|
+
}
|
|
389
|
+
function toWarningDiagnostic(diagnostic) {
|
|
390
|
+
return {
|
|
391
|
+
...diagnostic,
|
|
392
|
+
severity: "warning",
|
|
393
|
+
};
|
|
394
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { ForgeImportMap, ForgePackageDiagnostic, ForgePackageResolutionResult, ForgePackageResolver } from "../package-resolution";
|
|
2
2
|
import type { ForgeEsbuildWasmWorkerDiagnostic, ForgeEsbuildWasmWorkerService } from "../esbuild-wasm-worker";
|
|
3
|
-
import type { ForgeVirtualFileSystem } from "../virtual-file-system";
|
|
3
|
+
import type { ForgeVirtualFileSystem, ForgeVirtualFileSystemStorage } from "../virtual-file-system";
|
|
4
|
+
import type { ForgeTelemetryReporter } from "../telemetry";
|
|
4
5
|
export declare const BUILD_PIPELINE_CAPABILITY: "build-pipeline";
|
|
5
6
|
export type ForgeBuildMode = "production";
|
|
6
|
-
export type ForgeBuildPipelineDiagnosticCode = "esbuild_worker_transform_failed" | "missing_build_script" | "missing_entry" | "unresolved_import" | "unsupported_build_script" | "vite_config_not_executed";
|
|
7
|
+
export type ForgeBuildPipelineDiagnosticCode = "build_cancelled" | "esbuild_worker_transform_failed" | "missing_build_script" | "missing_entry" | "unresolved_import" | "unsupported_build_script" | "vite_config_not_executed";
|
|
7
8
|
export interface ForgeBuildPipelineDiagnostic {
|
|
8
9
|
readonly code: ForgeBuildPipelineDiagnosticCode;
|
|
9
10
|
readonly severity: "error" | "warning";
|
|
@@ -22,6 +23,12 @@ export interface ForgeBuildOutputFile {
|
|
|
22
23
|
readonly contentType: string;
|
|
23
24
|
readonly size: number;
|
|
24
25
|
}
|
|
26
|
+
export interface ForgeViteConfigMetadata {
|
|
27
|
+
readonly path: string;
|
|
28
|
+
readonly aliases: Readonly<Record<string, string>>;
|
|
29
|
+
readonly define: Readonly<Record<string, string>>;
|
|
30
|
+
readonly base?: string;
|
|
31
|
+
}
|
|
25
32
|
export interface ForgeBuildManifest {
|
|
26
33
|
readonly entry: string;
|
|
27
34
|
readonly mode: ForgeBuildMode;
|
|
@@ -29,13 +36,22 @@ export interface ForgeBuildManifest {
|
|
|
29
36
|
readonly packageNames: readonly string[];
|
|
30
37
|
readonly packageResolutionMode: string;
|
|
31
38
|
readonly browserBundle?: ForgeBrowserBundleManifest;
|
|
39
|
+
readonly viteConfig?: ForgeViteConfigMetadata;
|
|
40
|
+
}
|
|
41
|
+
export type ForgeBrowserBundleModuleOrigin = "package" | "workspace";
|
|
42
|
+
export interface ForgeBrowserBundleModule {
|
|
43
|
+
readonly origin: ForgeBrowserBundleModuleOrigin;
|
|
44
|
+
readonly outputPath: string;
|
|
45
|
+
readonly sourcePath: string;
|
|
32
46
|
}
|
|
33
47
|
export interface ForgeBrowserBundleManifest {
|
|
34
48
|
readonly entryOutputPath: string;
|
|
35
49
|
readonly format: "esm";
|
|
36
50
|
readonly importMapPath: string;
|
|
37
51
|
readonly moduleCount: number;
|
|
52
|
+
readonly modules: readonly ForgeBrowserBundleModule[];
|
|
38
53
|
readonly outputPaths: readonly string[];
|
|
54
|
+
readonly viteConfig?: ForgeViteConfigMetadata;
|
|
39
55
|
}
|
|
40
56
|
export interface ForgeBrowserBundle {
|
|
41
57
|
readonly entry: string;
|
|
@@ -44,7 +60,9 @@ export interface ForgeBrowserBundle {
|
|
|
44
60
|
readonly importMap: ForgeImportMap;
|
|
45
61
|
readonly importMapPath: string;
|
|
46
62
|
readonly moduleCount: number;
|
|
63
|
+
readonly modules: readonly ForgeBrowserBundleModule[];
|
|
47
64
|
readonly outputPaths: readonly string[];
|
|
65
|
+
readonly viteConfig?: ForgeViteConfigMetadata;
|
|
48
66
|
}
|
|
49
67
|
export interface ForgeBuildTiming {
|
|
50
68
|
readonly startedAt: string;
|
|
@@ -60,16 +78,20 @@ export interface ForgeBuildResult {
|
|
|
60
78
|
readonly outputFiles: readonly ForgeBuildOutputFile[];
|
|
61
79
|
readonly diagnostics: readonly ForgeBuildDiagnostic[];
|
|
62
80
|
readonly packageResolution?: ForgePackageResolutionResult;
|
|
81
|
+
readonly viteConfig?: ForgeViteConfigMetadata;
|
|
63
82
|
readonly timing: ForgeBuildTiming;
|
|
64
83
|
}
|
|
65
84
|
export interface ForgeBuildPipelineOptions {
|
|
66
85
|
readonly fileSystem: ForgeVirtualFileSystem;
|
|
67
86
|
readonly packageResolver: ForgePackageResolver;
|
|
68
87
|
readonly esbuildWorker?: ForgeEsbuildWasmWorkerService;
|
|
88
|
+
readonly telemetry?: ForgeTelemetryReporter;
|
|
69
89
|
readonly now?: () => string;
|
|
90
|
+
readonly storage?: ForgeVirtualFileSystemStorage;
|
|
70
91
|
}
|
|
71
92
|
export interface ForgeBuildRequest {
|
|
72
93
|
readonly entry?: string;
|
|
94
|
+
readonly signal?: AbortSignal;
|
|
73
95
|
}
|
|
74
96
|
export interface ForgeBuildPipeline {
|
|
75
97
|
readonly capability: typeof BUILD_PIPELINE_CAPABILITY;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ForgeVirtualFileSystem } from "../virtual-file-system";
|
|
2
|
+
import type { ForgeViteConfigMetadata } from "./types";
|
|
3
|
+
export declare const VITE_CONFIG_PATHS: readonly ["/vite.config.js", "/vite.config.mjs", "/vite.config.ts"];
|
|
4
|
+
export interface ForgeViteConfigReadResult {
|
|
5
|
+
readonly detectedPaths: readonly string[];
|
|
6
|
+
readonly metadata?: ForgeViteConfigMetadata;
|
|
7
|
+
}
|
|
8
|
+
export declare function readViteConfigMetadata(fileSystem: ForgeVirtualFileSystem): Promise<ForgeViteConfigReadResult>;
|
|
@@ -0,0 +1,215 @@
|
|
|
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.readViteConfigMetadata = exports.VITE_CONFIG_PATHS = void 0;
|
|
27
|
+
const ts = __importStar(require("typescript"));
|
|
28
|
+
const virtual_file_system_1 = require("../virtual-file-system");
|
|
29
|
+
exports.VITE_CONFIG_PATHS = [
|
|
30
|
+
"/vite.config.js",
|
|
31
|
+
"/vite.config.mjs",
|
|
32
|
+
"/vite.config.ts",
|
|
33
|
+
];
|
|
34
|
+
async function readViteConfigMetadata(fileSystem) {
|
|
35
|
+
const detectedPaths = [];
|
|
36
|
+
for (const path of exports.VITE_CONFIG_PATHS) {
|
|
37
|
+
if (await fileSystem.exists(path)) {
|
|
38
|
+
detectedPaths.push(path);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const selectedPath = detectedPaths[0];
|
|
42
|
+
if (selectedPath === undefined) {
|
|
43
|
+
return {
|
|
44
|
+
detectedPaths,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
detectedPaths,
|
|
49
|
+
metadata: parseViteConfigMetadata(selectedPath, await fileSystem.readText(selectedPath)),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
exports.readViteConfigMetadata = readViteConfigMetadata;
|
|
53
|
+
function parseViteConfigMetadata(path, source) {
|
|
54
|
+
const sourceFile = ts.createSourceFile(path, source, ts.ScriptTarget.Latest, true, scriptKindForPath(path));
|
|
55
|
+
const configObject = findDefaultConfigObject(sourceFile);
|
|
56
|
+
if (configObject === undefined) {
|
|
57
|
+
return {
|
|
58
|
+
aliases: {},
|
|
59
|
+
define: {},
|
|
60
|
+
path,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
aliases: parseAliasMap(configObject),
|
|
65
|
+
base: parseBase(configObject),
|
|
66
|
+
define: parseDefineMap(configObject),
|
|
67
|
+
path,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function findDefaultConfigObject(sourceFile) {
|
|
71
|
+
for (const statement of sourceFile.statements) {
|
|
72
|
+
if (!ts.isExportAssignment(statement)) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
return unwrapConfigObject(statement.expression);
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
function unwrapConfigObject(expression) {
|
|
80
|
+
const unwrapped = unwrapExpression(expression);
|
|
81
|
+
if (ts.isObjectLiteralExpression(unwrapped)) {
|
|
82
|
+
return unwrapped;
|
|
83
|
+
}
|
|
84
|
+
if (ts.isCallExpression(unwrapped) &&
|
|
85
|
+
unwrapped.arguments.length > 0) {
|
|
86
|
+
return unwrapConfigObject(unwrapped.arguments[0]);
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
function unwrapExpression(expression) {
|
|
91
|
+
if (ts.isParenthesizedExpression(expression)) {
|
|
92
|
+
return unwrapExpression(expression.expression);
|
|
93
|
+
}
|
|
94
|
+
if (ts.isAsExpression(expression) || ts.isTypeAssertionExpression(expression)) {
|
|
95
|
+
return unwrapExpression(expression.expression);
|
|
96
|
+
}
|
|
97
|
+
if (ts.isSatisfiesExpression(expression)) {
|
|
98
|
+
return unwrapExpression(expression.expression);
|
|
99
|
+
}
|
|
100
|
+
return expression;
|
|
101
|
+
}
|
|
102
|
+
function parseAliasMap(configObject) {
|
|
103
|
+
const resolveObject = getObjectProperty(configObject, "resolve");
|
|
104
|
+
const aliasObject = resolveObject === undefined ? undefined : getObjectProperty(resolveObject, "alias");
|
|
105
|
+
if (aliasObject === undefined) {
|
|
106
|
+
return {};
|
|
107
|
+
}
|
|
108
|
+
const aliases = {};
|
|
109
|
+
for (const property of aliasObject.properties) {
|
|
110
|
+
if (!ts.isPropertyAssignment(property)) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
const key = getPropertyNameText(property.name);
|
|
114
|
+
const value = getStringLiteralText(property.initializer);
|
|
115
|
+
const normalizedValue = value === undefined ? undefined : normalizeAliasReplacement(value);
|
|
116
|
+
if (key !== undefined && normalizedValue !== undefined) {
|
|
117
|
+
aliases[key] = normalizedValue;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return sortRecord(aliases);
|
|
121
|
+
}
|
|
122
|
+
function parseDefineMap(configObject) {
|
|
123
|
+
const defineObject = getObjectProperty(configObject, "define");
|
|
124
|
+
if (defineObject === undefined) {
|
|
125
|
+
return {};
|
|
126
|
+
}
|
|
127
|
+
const define = {};
|
|
128
|
+
for (const property of defineObject.properties) {
|
|
129
|
+
if (!ts.isPropertyAssignment(property)) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const key = getPropertyNameText(property.name);
|
|
133
|
+
const value = getDefineValueText(property.initializer);
|
|
134
|
+
if (key !== undefined && value !== undefined) {
|
|
135
|
+
define[key] = value;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return sortRecord(define);
|
|
139
|
+
}
|
|
140
|
+
function parseBase(configObject) {
|
|
141
|
+
const baseProperty = getProperty(configObject, "base");
|
|
142
|
+
return baseProperty === undefined
|
|
143
|
+
? undefined
|
|
144
|
+
: getStringLiteralText(baseProperty.initializer);
|
|
145
|
+
}
|
|
146
|
+
function getObjectProperty(object, propertyName) {
|
|
147
|
+
const property = getProperty(object, propertyName);
|
|
148
|
+
if (property === undefined) {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
const initializer = unwrapExpression(property.initializer);
|
|
152
|
+
return ts.isObjectLiteralExpression(initializer) ? initializer : undefined;
|
|
153
|
+
}
|
|
154
|
+
function getProperty(object, propertyName) {
|
|
155
|
+
for (const property of object.properties) {
|
|
156
|
+
if (!ts.isPropertyAssignment(property)) {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if (getPropertyNameText(property.name) === propertyName) {
|
|
160
|
+
return property;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
function getPropertyNameText(name) {
|
|
166
|
+
if (ts.isIdentifier(name) || ts.isStringLiteral(name) || ts.isNumericLiteral(name)) {
|
|
167
|
+
return name.text;
|
|
168
|
+
}
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
function getStringLiteralText(expression) {
|
|
172
|
+
const unwrapped = unwrapExpression(expression);
|
|
173
|
+
if (ts.isStringLiteral(unwrapped) || ts.isNoSubstitutionTemplateLiteral(unwrapped)) {
|
|
174
|
+
return unwrapped.text;
|
|
175
|
+
}
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
function getDefineValueText(expression) {
|
|
179
|
+
const unwrapped = unwrapExpression(expression);
|
|
180
|
+
const stringText = getStringLiteralText(unwrapped);
|
|
181
|
+
if (stringText !== undefined) {
|
|
182
|
+
return stringText;
|
|
183
|
+
}
|
|
184
|
+
if (unwrapped.kind === ts.SyntaxKind.TrueKeyword) {
|
|
185
|
+
return "true";
|
|
186
|
+
}
|
|
187
|
+
if (unwrapped.kind === ts.SyntaxKind.FalseKeyword) {
|
|
188
|
+
return "false";
|
|
189
|
+
}
|
|
190
|
+
if (unwrapped.kind === ts.SyntaxKind.NullKeyword) {
|
|
191
|
+
return "null";
|
|
192
|
+
}
|
|
193
|
+
if (ts.isNumericLiteral(unwrapped)) {
|
|
194
|
+
return unwrapped.text;
|
|
195
|
+
}
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
function normalizeAliasReplacement(value) {
|
|
199
|
+
const path = value.startsWith("/")
|
|
200
|
+
? value
|
|
201
|
+
: value.startsWith("./")
|
|
202
|
+
? value.slice(1)
|
|
203
|
+
: undefined;
|
|
204
|
+
if (path === undefined) {
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
const normalized = (0, virtual_file_system_1.normalizeForgePath)(path);
|
|
208
|
+
return normalized.ok ? normalized.path : undefined;
|
|
209
|
+
}
|
|
210
|
+
function scriptKindForPath(path) {
|
|
211
|
+
return path.endsWith(".ts") ? ts.ScriptKind.TS : ts.ScriptKind.JS;
|
|
212
|
+
}
|
|
213
|
+
function sortRecord(record) {
|
|
214
|
+
return Object.fromEntries(Object.entries(record).sort(([left], [right]) => left.localeCompare(right)));
|
|
215
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { createMissingDevScriptDiagnostic, createSessionNotFoundDiagnostic, createSessionStoppedDiagnostic, createUnsupportedDevScriptDiagnostic, } from "./diagnostics";
|
|
2
|
-
export { createForgePreviewDocument } from "./preview-document";
|
|
2
|
+
export { createForgePreviewDocument, createForgePreviewErrorOverlayDocument, } from "./preview-document";
|
|
3
3
|
export { createDevServerPreview, DefaultDevServerPreview, isSupportedViteDevScript, } from "./server";
|
|
4
|
-
export { DEV_SERVER_PREVIEW_CAPABILITY, type ForgeCreatePreviewDocumentOptions, type ForgeDevServerPreview, type ForgeDevServerPreviewDiagnostic, type ForgeDevServerPreviewDiagnosticCode, type ForgeDevServerPreviewEvent, type ForgeDevServerPreviewEventListener, type ForgeDevServerPreviewOptions, type ForgeDevSession, type ForgeDevSessionDiagnostic, type ForgeDevSessionFailedEvent, type ForgeDevSessionFileChange, type ForgeDevSessionRefreshResult, type ForgeDevSessionStartedEvent, type ForgeDevSessionStartResult, type ForgeDevSessionStatus, type ForgeDevSessionStoppedEvent, type ForgeDevSessionStopResult, type ForgePreviewDocument, type ForgePreviewRefreshedEvent, type ForgeRebuildDevSessionOptions, type ForgeStartDevSessionOptions, } from "./types";
|
|
4
|
+
export { DEV_SERVER_PREVIEW_CAPABILITY, type ForgeCreatePreviewDocumentOptions, type ForgeDevServerAdapterFramework, type ForgeDevServerAdapterHmrMode, type ForgeDevServerAdapterMetadata, type ForgeDevServerAdapterName, type ForgeDevServerPreview, type ForgeDevServerPreviewDiagnostic, type ForgeDevServerPreviewDiagnosticCode, type ForgeDevServerPreviewEvent, type ForgeDevServerPreviewEventListener, type ForgeDevServerPreviewOptions, type ForgeDevSession, type ForgeDevSessionDiagnostic, type ForgeDevSessionFailedEvent, type ForgeDevSessionFileChange, type ForgeDevSessionRefreshResult, type ForgeDevSessionStartedEvent, type ForgeDevSessionStartResult, type ForgeDevSessionStatus, type ForgeDevSessionStoppedEvent, type ForgeDevSessionStopResult, type ForgePreviewDocument, type ForgePreviewModuleUpdate, type ForgePreviewModuleUpdatedEvent, type ForgePreviewRefreshedEvent, type ForgePreviewStyleUpdate, type ForgePreviewStyleUpdatedEvent, type ForgeRebuildDevSessionOptions, type ForgeStartDevSessionOptions, } from "./types";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEV_SERVER_PREVIEW_CAPABILITY = exports.isSupportedViteDevScript = exports.DefaultDevServerPreview = exports.createDevServerPreview = exports.createForgePreviewDocument = exports.createUnsupportedDevScriptDiagnostic = exports.createSessionStoppedDiagnostic = exports.createSessionNotFoundDiagnostic = exports.createMissingDevScriptDiagnostic = void 0;
|
|
3
|
+
exports.DEV_SERVER_PREVIEW_CAPABILITY = exports.isSupportedViteDevScript = exports.DefaultDevServerPreview = exports.createDevServerPreview = exports.createForgePreviewErrorOverlayDocument = exports.createForgePreviewDocument = exports.createUnsupportedDevScriptDiagnostic = exports.createSessionStoppedDiagnostic = exports.createSessionNotFoundDiagnostic = exports.createMissingDevScriptDiagnostic = void 0;
|
|
4
4
|
var diagnostics_1 = require("./diagnostics");
|
|
5
5
|
Object.defineProperty(exports, "createMissingDevScriptDiagnostic", { enumerable: true, get: function () { return diagnostics_1.createMissingDevScriptDiagnostic; } });
|
|
6
6
|
Object.defineProperty(exports, "createSessionNotFoundDiagnostic", { enumerable: true, get: function () { return diagnostics_1.createSessionNotFoundDiagnostic; } });
|
|
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "createSessionStoppedDiagnostic", { enumerable: t
|
|
|
8
8
|
Object.defineProperty(exports, "createUnsupportedDevScriptDiagnostic", { enumerable: true, get: function () { return diagnostics_1.createUnsupportedDevScriptDiagnostic; } });
|
|
9
9
|
var preview_document_1 = require("./preview-document");
|
|
10
10
|
Object.defineProperty(exports, "createForgePreviewDocument", { enumerable: true, get: function () { return preview_document_1.createForgePreviewDocument; } });
|
|
11
|
+
Object.defineProperty(exports, "createForgePreviewErrorOverlayDocument", { enumerable: true, get: function () { return preview_document_1.createForgePreviewErrorOverlayDocument; } });
|
|
11
12
|
var server_1 = require("./server");
|
|
12
13
|
Object.defineProperty(exports, "createDevServerPreview", { enumerable: true, get: function () { return server_1.createDevServerPreview; } });
|
|
13
14
|
Object.defineProperty(exports, "DefaultDevServerPreview", { enumerable: true, get: function () { return server_1.DefaultDevServerPreview; } });
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { ForgeCreatePreviewDocumentOptions, ForgePreviewDocument } from "./types";
|
|
1
|
+
import type { ForgeCreatePreviewDocumentOptions, ForgeDevSessionDiagnostic, ForgePreviewDocument } from "./types";
|
|
2
2
|
export declare function createForgePreviewDocument(options: ForgeCreatePreviewDocumentOptions): ForgePreviewDocument;
|
|
3
|
+
export declare function createForgePreviewErrorOverlayDocument(previewDocument: ForgePreviewDocument, diagnostics: readonly ForgeDevSessionDiagnostic[]): ForgePreviewDocument;
|