@caryhu/codemine-forge 0.0.1-alpha.1 → 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/dist/build-pipeline/browser-bundle.d.ts +2 -1
- package/dist/build-pipeline/browser-bundle.js +384 -24
- package/dist/build-pipeline/diagnostics.js +1 -1
- package/dist/build-pipeline/index.d.ts +1 -1
- package/dist/build-pipeline/pipeline.js +28 -30
- package/dist/build-pipeline/types.d.ts +18 -0
- 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 +246 -32
- package/dist/dev-server-preview/types.d.ts +38 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -2
- package/package.json +2 -2
|
@@ -7,12 +7,8 @@ const virtual_file_system_1 = require("../virtual-file-system");
|
|
|
7
7
|
const diagnostics_1 = require("./diagnostics");
|
|
8
8
|
const browser_bundle_1 = require("./browser-bundle");
|
|
9
9
|
const types_1 = require("./types");
|
|
10
|
+
const vite_config_1 = require("./vite-config");
|
|
10
11
|
const BUILD_MANIFEST_PATH = "/.forge/build/build-manifest.json";
|
|
11
|
-
const VITE_CONFIG_PATHS = [
|
|
12
|
-
"/vite.config.js",
|
|
13
|
-
"/vite.config.mjs",
|
|
14
|
-
"/vite.config.ts",
|
|
15
|
-
];
|
|
16
12
|
const DEFAULT_ENTRY_CANDIDATES = [
|
|
17
13
|
"/src/main.tsx",
|
|
18
14
|
"/src/main.jsx",
|
|
@@ -32,10 +28,12 @@ class DefaultBuildPipeline {
|
|
|
32
28
|
if (initialCancellation !== undefined) {
|
|
33
29
|
return this.failure(mode, [initialCancellation], timingStart);
|
|
34
30
|
}
|
|
35
|
-
const
|
|
31
|
+
const viteConfigRead = await (0, vite_config_1.readViteConfigMetadata)(this.options.fileSystem);
|
|
32
|
+
const warningDiagnostics = createViteConfigDiagnostics(viteConfigRead.detectedPaths);
|
|
33
|
+
const viteConfig = viteConfigRead.metadata;
|
|
36
34
|
const configCancellation = getCancellationDiagnostic(request.signal);
|
|
37
35
|
if (configCancellation !== undefined) {
|
|
38
|
-
return this.failure(mode, [configCancellation, ...warningDiagnostics], timingStart);
|
|
36
|
+
return this.failure(mode, [configCancellation, ...warningDiagnostics], timingStart, viteConfig);
|
|
39
37
|
}
|
|
40
38
|
let manifest;
|
|
41
39
|
try {
|
|
@@ -43,34 +41,34 @@ class DefaultBuildPipeline {
|
|
|
43
41
|
}
|
|
44
42
|
catch (error) {
|
|
45
43
|
if (error instanceof package_resolution_1.ForgePackageResolutionError) {
|
|
46
|
-
return this.failure(mode, [error.diagnostic, ...error.warnings, ...warningDiagnostics], timingStart);
|
|
44
|
+
return this.failure(mode, [error.diagnostic, ...error.warnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
47
45
|
}
|
|
48
46
|
throw error;
|
|
49
47
|
}
|
|
50
48
|
const buildScript = manifest.scripts.build;
|
|
51
49
|
if (buildScript === undefined) {
|
|
52
|
-
return this.failure(mode, [(0, diagnostics_1.createMissingBuildScriptDiagnostic)(), ...warningDiagnostics], timingStart);
|
|
50
|
+
return this.failure(mode, [(0, diagnostics_1.createMissingBuildScriptDiagnostic)(), ...warningDiagnostics], timingStart, viteConfig);
|
|
53
51
|
}
|
|
54
52
|
if (!isSupportedViteBuildScript(buildScript)) {
|
|
55
53
|
return this.failure(mode, [
|
|
56
54
|
(0, diagnostics_1.createUnsupportedBuildScriptDiagnostic)(buildScript),
|
|
57
55
|
...warningDiagnostics,
|
|
58
|
-
], timingStart);
|
|
56
|
+
], timingStart, viteConfig);
|
|
59
57
|
}
|
|
60
58
|
const manifestCancellation = getCancellationDiagnostic(request.signal);
|
|
61
59
|
if (manifestCancellation !== undefined) {
|
|
62
|
-
return this.failure(mode, [manifestCancellation, ...warningDiagnostics], timingStart);
|
|
60
|
+
return this.failure(mode, [manifestCancellation, ...warningDiagnostics], timingStart, viteConfig);
|
|
63
61
|
}
|
|
64
62
|
const entry = await this.resolveEntry(request.entry);
|
|
65
63
|
if (entry === undefined) {
|
|
66
|
-
return this.failure(mode, [(0, diagnostics_1.createMissingEntryDiagnostic)(), ...warningDiagnostics], timingStart);
|
|
64
|
+
return this.failure(mode, [(0, diagnostics_1.createMissingEntryDiagnostic)(), ...warningDiagnostics], timingStart, viteConfig);
|
|
67
65
|
}
|
|
68
66
|
try {
|
|
69
67
|
const packageResolution = await this.options.packageResolver.resolve();
|
|
70
68
|
const packageWarnings = packageResolution.warnings;
|
|
71
69
|
const packageCancellation = getCancellationDiagnostic(request.signal);
|
|
72
70
|
if (packageCancellation !== undefined) {
|
|
73
|
-
return this.failure(mode, [packageCancellation, ...packageWarnings, ...warningDiagnostics], timingStart);
|
|
71
|
+
return this.failure(mode, [packageCancellation, ...packageWarnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
74
72
|
}
|
|
75
73
|
const sourceFiles = await collectSourceFiles(this.options.fileSystem);
|
|
76
74
|
const browserBundleResult = await (0, browser_bundle_1.createBrowserBundle)({
|
|
@@ -78,38 +76,39 @@ class DefaultBuildPipeline {
|
|
|
78
76
|
fileSystem: this.options.fileSystem,
|
|
79
77
|
packageResolution,
|
|
80
78
|
scriptTransformer: createEsbuildWorkerScriptTransformer(this.options.esbuildWorker),
|
|
79
|
+
viteConfig,
|
|
81
80
|
});
|
|
82
81
|
if (browserBundleResult.diagnostics.length > 0) {
|
|
83
82
|
return this.failure(mode, [
|
|
84
83
|
...browserBundleResult.diagnostics,
|
|
85
84
|
...packageWarnings,
|
|
86
85
|
...warningDiagnostics,
|
|
87
|
-
], timingStart);
|
|
86
|
+
], timingStart, viteConfig);
|
|
88
87
|
}
|
|
89
88
|
if (browserBundleResult.browserBundle === undefined) {
|
|
90
89
|
throw new Error("Browser bundle output was missing after a successful build.");
|
|
91
90
|
}
|
|
92
91
|
const bundleCancellation = getCancellationDiagnostic(request.signal);
|
|
93
92
|
if (bundleCancellation !== undefined) {
|
|
94
|
-
return this.failure(mode, [bundleCancellation, ...packageWarnings, ...warningDiagnostics], timingStart);
|
|
93
|
+
return this.failure(mode, [bundleCancellation, ...packageWarnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
95
94
|
}
|
|
96
|
-
const buildManifest = createBuildManifest(entry, mode, sourceFiles, packageResolution, browserBundleResult.browserBundle);
|
|
95
|
+
const buildManifest = createBuildManifest(entry, mode, sourceFiles, packageResolution, browserBundleResult.browserBundle, viteConfig);
|
|
97
96
|
const outputFiles = [
|
|
98
97
|
createBuildManifestOutput(buildManifest),
|
|
99
98
|
...browserBundleResult.outputFiles,
|
|
100
99
|
];
|
|
101
100
|
const outputCancellation = getCancellationDiagnostic(request.signal);
|
|
102
101
|
if (outputCancellation !== undefined) {
|
|
103
|
-
return this.failure(mode, [outputCancellation, ...packageWarnings, ...warningDiagnostics], timingStart);
|
|
102
|
+
return this.failure(mode, [outputCancellation, ...packageWarnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
104
103
|
}
|
|
105
104
|
const outputWriteDiagnostic = await writeBuildOutputFilesAtomically(this.options.fileSystem, outputFiles);
|
|
106
105
|
if (outputWriteDiagnostic !== undefined) {
|
|
107
|
-
return this.failure(mode, [outputWriteDiagnostic, ...packageWarnings, ...warningDiagnostics], timingStart);
|
|
106
|
+
return this.failure(mode, [outputWriteDiagnostic, ...packageWarnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
108
107
|
}
|
|
109
108
|
const buildCacheWarnings = await this.writeBuildCacheRecord(entry, mode, buildManifest, browserBundleResult.browserBundle, outputFiles);
|
|
110
109
|
const cacheCancellation = getCancellationDiagnostic(request.signal);
|
|
111
110
|
if (cacheCancellation !== undefined) {
|
|
112
|
-
return this.failure(mode, [cacheCancellation, ...packageWarnings, ...buildCacheWarnings, ...warningDiagnostics], timingStart);
|
|
111
|
+
return this.failure(mode, [cacheCancellation, ...packageWarnings, ...buildCacheWarnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
113
112
|
}
|
|
114
113
|
return this.complete({
|
|
115
114
|
success: true,
|
|
@@ -124,12 +123,13 @@ class DefaultBuildPipeline {
|
|
|
124
123
|
...warningDiagnostics,
|
|
125
124
|
],
|
|
126
125
|
packageResolution,
|
|
126
|
+
viteConfig,
|
|
127
127
|
timing: completeTiming(timingStart, this.now()),
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
130
|
catch (error) {
|
|
131
131
|
if (error instanceof package_resolution_1.ForgePackageResolutionError) {
|
|
132
|
-
return this.failure(mode, [error.diagnostic, ...error.warnings, ...warningDiagnostics], timingStart);
|
|
132
|
+
return this.failure(mode, [error.diagnostic, ...error.warnings, ...warningDiagnostics], timingStart, viteConfig);
|
|
133
133
|
}
|
|
134
134
|
throw error;
|
|
135
135
|
}
|
|
@@ -153,12 +153,13 @@ class DefaultBuildPipeline {
|
|
|
153
153
|
}
|
|
154
154
|
return undefined;
|
|
155
155
|
}
|
|
156
|
-
failure(mode, diagnostics, timingStart) {
|
|
156
|
+
failure(mode, diagnostics, timingStart, viteConfig) {
|
|
157
157
|
return this.complete({
|
|
158
158
|
success: false,
|
|
159
159
|
mode,
|
|
160
160
|
outputFiles: [],
|
|
161
161
|
diagnostics,
|
|
162
|
+
viteConfig,
|
|
162
163
|
timing: completeTiming(timingStart, this.now()),
|
|
163
164
|
});
|
|
164
165
|
}
|
|
@@ -255,14 +256,8 @@ function createEsbuildWorkerScriptTransformer(esbuildWorker) {
|
|
|
255
256
|
};
|
|
256
257
|
};
|
|
257
258
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
for (const path of VITE_CONFIG_PATHS) {
|
|
261
|
-
if (await fileSystem.exists(path)) {
|
|
262
|
-
diagnostics.push((0, diagnostics_1.createViteConfigNotExecutedDiagnostic)(path));
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return diagnostics;
|
|
259
|
+
function createViteConfigDiagnostics(paths) {
|
|
260
|
+
return paths.map((path) => (0, diagnostics_1.createViteConfigNotExecutedDiagnostic)(path));
|
|
266
261
|
}
|
|
267
262
|
function createBuildPipeline(options) {
|
|
268
263
|
return new DefaultBuildPipeline(options);
|
|
@@ -309,13 +304,14 @@ async function collectSourceFiles(fileSystem, path = "/") {
|
|
|
309
304
|
}
|
|
310
305
|
return files.sort((left, right) => left.localeCompare(right));
|
|
311
306
|
}
|
|
312
|
-
function createBuildManifest(entry, mode, sourceFiles, packageResolution, browserBundle) {
|
|
307
|
+
function createBuildManifest(entry, mode, sourceFiles, packageResolution, browserBundle, viteConfig) {
|
|
313
308
|
return {
|
|
314
309
|
entry,
|
|
315
310
|
mode,
|
|
316
311
|
sourceFiles,
|
|
317
312
|
packageNames: packageResolution.packages.map((record) => record.name),
|
|
318
313
|
packageResolutionMode: packageResolution.lock.resolutionMode,
|
|
314
|
+
viteConfig,
|
|
319
315
|
browserBundle: browserBundle === undefined
|
|
320
316
|
? undefined
|
|
321
317
|
: {
|
|
@@ -323,7 +319,9 @@ function createBuildManifest(entry, mode, sourceFiles, packageResolution, browse
|
|
|
323
319
|
format: browserBundle.format,
|
|
324
320
|
importMapPath: browserBundle.importMapPath,
|
|
325
321
|
moduleCount: browserBundle.moduleCount,
|
|
322
|
+
modules: browserBundle.modules,
|
|
326
323
|
outputPaths: browserBundle.outputPaths,
|
|
324
|
+
viteConfig: browserBundle.viteConfig,
|
|
327
325
|
},
|
|
328
326
|
};
|
|
329
327
|
}
|
|
@@ -23,6 +23,12 @@ export interface ForgeBuildOutputFile {
|
|
|
23
23
|
readonly contentType: string;
|
|
24
24
|
readonly size: number;
|
|
25
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
|
+
}
|
|
26
32
|
export interface ForgeBuildManifest {
|
|
27
33
|
readonly entry: string;
|
|
28
34
|
readonly mode: ForgeBuildMode;
|
|
@@ -30,13 +36,22 @@ export interface ForgeBuildManifest {
|
|
|
30
36
|
readonly packageNames: readonly string[];
|
|
31
37
|
readonly packageResolutionMode: string;
|
|
32
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;
|
|
33
46
|
}
|
|
34
47
|
export interface ForgeBrowserBundleManifest {
|
|
35
48
|
readonly entryOutputPath: string;
|
|
36
49
|
readonly format: "esm";
|
|
37
50
|
readonly importMapPath: string;
|
|
38
51
|
readonly moduleCount: number;
|
|
52
|
+
readonly modules: readonly ForgeBrowserBundleModule[];
|
|
39
53
|
readonly outputPaths: readonly string[];
|
|
54
|
+
readonly viteConfig?: ForgeViteConfigMetadata;
|
|
40
55
|
}
|
|
41
56
|
export interface ForgeBrowserBundle {
|
|
42
57
|
readonly entry: string;
|
|
@@ -45,7 +60,9 @@ export interface ForgeBrowserBundle {
|
|
|
45
60
|
readonly importMap: ForgeImportMap;
|
|
46
61
|
readonly importMapPath: string;
|
|
47
62
|
readonly moduleCount: number;
|
|
63
|
+
readonly modules: readonly ForgeBrowserBundleModule[];
|
|
48
64
|
readonly outputPaths: readonly string[];
|
|
65
|
+
readonly viteConfig?: ForgeViteConfigMetadata;
|
|
49
66
|
}
|
|
50
67
|
export interface ForgeBuildTiming {
|
|
51
68
|
readonly startedAt: string;
|
|
@@ -61,6 +78,7 @@ export interface ForgeBuildResult {
|
|
|
61
78
|
readonly outputFiles: readonly ForgeBuildOutputFile[];
|
|
62
79
|
readonly diagnostics: readonly ForgeBuildDiagnostic[];
|
|
63
80
|
readonly packageResolution?: ForgePackageResolutionResult;
|
|
81
|
+
readonly viteConfig?: ForgeViteConfigMetadata;
|
|
64
82
|
readonly timing: ForgeBuildTiming;
|
|
65
83
|
}
|
|
66
84
|
export interface ForgeBuildPipelineOptions {
|
|
@@ -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;
|