@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.
Files changed (84) hide show
  1. package/README.md +108 -0
  2. package/dist/build-pipeline/browser-bundle.d.ts +31 -0
  3. package/dist/build-pipeline/browser-bundle.js +584 -0
  4. package/dist/build-pipeline/diagnostics.d.ts +7 -0
  5. package/dist/build-pipeline/diagnostics.js +68 -0
  6. package/dist/build-pipeline/index.d.ts +3 -0
  7. package/dist/build-pipeline/index.js +16 -0
  8. package/dist/build-pipeline/pipeline.d.ts +12 -0
  9. package/dist/build-pipeline/pipeline.js +273 -0
  10. package/dist/build-pipeline/types.d.ts +77 -0
  11. package/dist/build-pipeline/types.js +4 -0
  12. package/dist/dev-server-preview/diagnostics.d.ts +5 -0
  13. package/dist/dev-server-preview/diagnostics.js +40 -0
  14. package/dist/dev-server-preview/index.d.ts +4 -0
  15. package/dist/dev-server-preview/index.js +16 -0
  16. package/dist/dev-server-preview/preview-document.d.ts +2 -0
  17. package/dist/dev-server-preview/preview-document.js +153 -0
  18. package/dist/dev-server-preview/server.d.ts +26 -0
  19. package/dist/dev-server-preview/server.js +279 -0
  20. package/dist/dev-server-preview/types.d.ts +105 -0
  21. package/dist/dev-server-preview/types.js +4 -0
  22. package/dist/esbuild-wasm-worker/diagnostics.d.ts +12 -0
  23. package/dist/esbuild-wasm-worker/diagnostics.js +53 -0
  24. package/dist/esbuild-wasm-worker/index.d.ts +4 -0
  25. package/dist/esbuild-wasm-worker/index.js +18 -0
  26. package/dist/esbuild-wasm-worker/service.d.ts +26 -0
  27. package/dist/esbuild-wasm-worker/service.js +260 -0
  28. package/dist/esbuild-wasm-worker/types.d.ts +139 -0
  29. package/dist/esbuild-wasm-worker/types.js +5 -0
  30. package/dist/esbuild-wasm-worker/worker-adapter.d.ts +38 -0
  31. package/dist/esbuild-wasm-worker/worker-adapter.js +165 -0
  32. package/dist/esbuild-wasm-worker/worker.d.ts +1 -0
  33. package/dist/esbuild-wasm-worker/worker.js +4 -0
  34. package/dist/forge-controller.d.ts +38 -0
  35. package/dist/forge-controller.js +79 -0
  36. package/dist/index.d.ts +7 -0
  37. package/dist/index.js +88 -0
  38. package/dist/package-resolution/cdn-source.d.ts +11 -0
  39. package/dist/package-resolution/cdn-source.js +164 -0
  40. package/dist/package-resolution/diagnostics.d.ts +15 -0
  41. package/dist/package-resolution/diagnostics.js +51 -0
  42. package/dist/package-resolution/errors.d.ts +5 -0
  43. package/dist/package-resolution/errors.js +11 -0
  44. package/dist/package-resolution/index.d.ts +6 -0
  45. package/dist/package-resolution/index.js +23 -0
  46. package/dist/package-resolution/manifest.d.ts +5 -0
  47. package/dist/package-resolution/manifest.js +128 -0
  48. package/dist/package-resolution/resolver.d.ts +17 -0
  49. package/dist/package-resolution/resolver.js +172 -0
  50. package/dist/package-resolution/types.d.ts +98 -0
  51. package/dist/package-resolution/types.js +4 -0
  52. package/dist/terminal-commands/diagnostics.d.ts +3 -0
  53. package/dist/terminal-commands/diagnostics.js +21 -0
  54. package/dist/terminal-commands/index.d.ts +7 -0
  55. package/dist/terminal-commands/index.js +22 -0
  56. package/dist/terminal-commands/npm-build.d.ts +7 -0
  57. package/dist/terminal-commands/npm-build.js +63 -0
  58. package/dist/terminal-commands/npm-dev.d.ts +7 -0
  59. package/dist/terminal-commands/npm-dev.js +68 -0
  60. package/dist/terminal-commands/npm-install.d.ts +8 -0
  61. package/dist/terminal-commands/npm-install.js +56 -0
  62. package/dist/terminal-commands/parser.d.ts +2 -0
  63. package/dist/terminal-commands/parser.js +52 -0
  64. package/dist/terminal-commands/terminal.d.ts +12 -0
  65. package/dist/terminal-commands/terminal.js +73 -0
  66. package/dist/terminal-commands/types.d.ts +65 -0
  67. package/dist/terminal-commands/types.js +4 -0
  68. package/dist/virtual-file-system/diagnostics.d.ts +14 -0
  69. package/dist/virtual-file-system/diagnostics.js +55 -0
  70. package/dist/virtual-file-system/errors.d.ts +5 -0
  71. package/dist/virtual-file-system/errors.js +11 -0
  72. package/dist/virtual-file-system/index.d.ts +26 -0
  73. package/dist/virtual-file-system/index.js +47 -0
  74. package/dist/virtual-file-system/limits.d.ts +4 -0
  75. package/dist/virtual-file-system/limits.js +33 -0
  76. package/dist/virtual-file-system/memory.d.ts +33 -0
  77. package/dist/virtual-file-system/memory.js +551 -0
  78. package/dist/virtual-file-system/path.d.ts +9 -0
  79. package/dist/virtual-file-system/path.js +47 -0
  80. package/dist/virtual-file-system/storage.d.ts +32 -0
  81. package/dist/virtual-file-system/storage.js +194 -0
  82. package/dist/virtual-file-system/types.d.ts +165 -0
  83. package/dist/virtual-file-system/types.js +2 -0
  84. package/package.json +43 -0
@@ -0,0 +1,584 @@
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.createBrowserBundle = void 0;
27
+ const ts = __importStar(require("typescript"));
28
+ const virtual_file_system_1 = require("../virtual-file-system");
29
+ const diagnostics_1 = require("./diagnostics");
30
+ const BROWSER_IMPORT_MAP_PATH = "/.forge/build/browser-import-map.json";
31
+ const DEFAULT_RESOLVE_EXTENSIONS = [
32
+ "",
33
+ ".tsx",
34
+ ".ts",
35
+ ".jsx",
36
+ ".js",
37
+ ".json",
38
+ ".css",
39
+ ];
40
+ const INDEX_RESOLVE_EXTENSIONS = [
41
+ "/index.tsx",
42
+ "/index.ts",
43
+ "/index.jsx",
44
+ "/index.js",
45
+ "/index.json",
46
+ "/index.css",
47
+ ];
48
+ const SCRIPT_EXTENSIONS = new Set([".js", ".jsx", ".ts", ".tsx"]);
49
+ async function createBrowserBundle(options) {
50
+ const diagnostics = [];
51
+ const packageImports = new Map();
52
+ const modules = new Map();
53
+ const packageModules = new Map();
54
+ const visiting = new Set();
55
+ const visitingPackageModules = new Set();
56
+ async function visitWorkspaceModule(sourcePath) {
57
+ if (modules.has(sourcePath)) {
58
+ return;
59
+ }
60
+ if (visiting.has(sourcePath)) {
61
+ return;
62
+ }
63
+ visiting.add(sourcePath);
64
+ const extension = getExtension(sourcePath);
65
+ if (!SCRIPT_EXTENSIONS.has(extension) &&
66
+ extension !== ".css" &&
67
+ extension !== ".json") {
68
+ modules.set(sourcePath, {
69
+ outputPath: createModuleOutputPath(sourcePath),
70
+ sourcePath,
71
+ transformedSource: createAssetModule(sourcePath, await options.fileSystem.readFile(sourcePath)),
72
+ });
73
+ visiting.delete(sourcePath);
74
+ return;
75
+ }
76
+ const source = await options.fileSystem.readText(sourcePath);
77
+ const imports = extractImportReferences(source).map((reference) => reference.specifier);
78
+ const rewrites = new Map();
79
+ for (const specifier of imports) {
80
+ if (isExternalUrl(specifier)) {
81
+ continue;
82
+ }
83
+ if (isLocalSpecifier(specifier)) {
84
+ const resolvedPath = await resolveLocalImport(options.fileSystem, sourcePath, specifier);
85
+ if (resolvedPath === undefined) {
86
+ diagnostics.push((0, diagnostics_1.createUnresolvedImportDiagnostic)(specifier, sourcePath));
87
+ continue;
88
+ }
89
+ rewrites.set(specifier, createModuleOutputPath(resolvedPath));
90
+ await visitWorkspaceModule(resolvedPath);
91
+ continue;
92
+ }
93
+ const packageImport = resolvePackageImport(options.packageResolution.packages, specifier);
94
+ if (packageImport === undefined) {
95
+ diagnostics.push((0, diagnostics_1.createUnresolvedImportDiagnostic)(specifier, sourcePath));
96
+ continue;
97
+ }
98
+ packageImports.set(specifier, packageImport.kind === "external"
99
+ ? packageImport.url
100
+ : packageImport.outputPath);
101
+ if (packageImport.kind === "package-file") {
102
+ await visitPackageModule(packageImport.packageRecord, packageImport.filePath);
103
+ }
104
+ }
105
+ const transformResult = await transformWorkspaceModule(sourcePath, source, options.scriptTransformer);
106
+ if (!transformResult.success) {
107
+ diagnostics.push(...transformResult.diagnostics);
108
+ visiting.delete(sourcePath);
109
+ return;
110
+ }
111
+ const transformedSource = rewriteModuleSpecifiers(transformResult.outputText, rewrites);
112
+ modules.set(sourcePath, {
113
+ outputPath: createModuleOutputPath(sourcePath),
114
+ sourcePath,
115
+ transformedSource,
116
+ });
117
+ visiting.delete(sourcePath);
118
+ }
119
+ async function visitPackageModule(packageRecord, filePath) {
120
+ const normalizedFilePath = normalizePackageFilePath(filePath);
121
+ const key = createPackageModuleKey(packageRecord, normalizedFilePath);
122
+ if (packageModules.has(key)) {
123
+ return;
124
+ }
125
+ if (visitingPackageModules.has(key)) {
126
+ return;
127
+ }
128
+ visitingPackageModules.add(key);
129
+ const packageFile = readPackageFile(packageRecord, normalizedFilePath);
130
+ const importer = createPackageImporterPath(packageRecord, normalizedFilePath);
131
+ if (packageFile === undefined || packageFile.content === undefined) {
132
+ diagnostics.push((0, diagnostics_1.createUnresolvedImportDiagnostic)(normalizedFilePath, importer));
133
+ visitingPackageModules.delete(key);
134
+ return;
135
+ }
136
+ const content = packageFile.content;
137
+ const source = typeof content === "string" ? content : undefined;
138
+ const imports = source === undefined
139
+ ? []
140
+ : extractImportReferences(source).map((reference) => reference.specifier);
141
+ const rewrites = new Map();
142
+ for (const specifier of imports) {
143
+ if (isExternalUrl(specifier)) {
144
+ continue;
145
+ }
146
+ if (isLocalSpecifier(specifier)) {
147
+ const resolvedPath = resolvePackageFileImport(packageRecord, normalizedFilePath, specifier);
148
+ if (resolvedPath === undefined) {
149
+ diagnostics.push((0, diagnostics_1.createUnresolvedImportDiagnostic)(specifier, importer));
150
+ continue;
151
+ }
152
+ rewrites.set(specifier, createPackageModuleOutputPath(packageRecord, resolvedPath));
153
+ await visitPackageModule(packageRecord, resolvedPath);
154
+ continue;
155
+ }
156
+ const packageImport = resolvePackageImport(options.packageResolution.packages, specifier);
157
+ if (packageImport === undefined) {
158
+ diagnostics.push((0, diagnostics_1.createUnresolvedImportDiagnostic)(specifier, importer));
159
+ continue;
160
+ }
161
+ packageImports.set(specifier, packageImport.kind === "external"
162
+ ? packageImport.url
163
+ : packageImport.outputPath);
164
+ if (packageImport.kind === "package-file") {
165
+ await visitPackageModule(packageImport.packageRecord, packageImport.filePath);
166
+ }
167
+ }
168
+ const transformResult = transformPackageModule(importer, normalizedFilePath, content);
169
+ if (!transformResult.success) {
170
+ diagnostics.push(...transformResult.diagnostics);
171
+ visitingPackageModules.delete(key);
172
+ return;
173
+ }
174
+ packageModules.set(key, {
175
+ filePath: normalizedFilePath,
176
+ outputPath: createPackageModuleOutputPath(packageRecord, normalizedFilePath),
177
+ packageRecord,
178
+ transformedSource: rewriteModuleSpecifiers(transformResult.outputText, rewrites),
179
+ });
180
+ visitingPackageModules.delete(key);
181
+ }
182
+ await visitWorkspaceModule(options.entry);
183
+ if (diagnostics.length > 0) {
184
+ return {
185
+ diagnostics,
186
+ outputFiles: [],
187
+ };
188
+ }
189
+ const outputFiles = Array.from(modules.values())
190
+ .sort((left, right) => left.outputPath.localeCompare(right.outputPath))
191
+ .map((moduleRecord) => createOutputFile(moduleRecord.outputPath, moduleRecord.transformedSource, "text/javascript"));
192
+ const packageOutputFiles = Array.from(packageModules.values())
193
+ .sort((left, right) => left.outputPath.localeCompare(right.outputPath))
194
+ .map((moduleRecord) => createOutputFile(moduleRecord.outputPath, moduleRecord.transformedSource, "text/javascript"));
195
+ const moduleOutputFiles = [...outputFiles, ...packageOutputFiles];
196
+ const localImports = Object.fromEntries(moduleOutputFiles.map((file) => [file.path, file.path]));
197
+ const packageImportEntries = Object.fromEntries(Array.from(packageImports.entries()).sort(([left], [right]) => left.localeCompare(right)));
198
+ const packageEntryImports = createPackageEntryImports(options.packageResolution.packages);
199
+ const importMap = {
200
+ imports: sortRecord({
201
+ ...packageEntryImports,
202
+ ...packageImportEntries,
203
+ ...localImports,
204
+ }),
205
+ };
206
+ const importMapFile = createOutputFile(BROWSER_IMPORT_MAP_PATH, `${JSON.stringify(importMap, null, 2)}\n`, "application/importmap+json");
207
+ const entryOutputPath = createModuleOutputPath(options.entry);
208
+ const allOutputFiles = [...moduleOutputFiles, importMapFile];
209
+ return {
210
+ browserBundle: {
211
+ entry: options.entry,
212
+ entryOutputPath,
213
+ format: "esm",
214
+ importMap,
215
+ importMapPath: BROWSER_IMPORT_MAP_PATH,
216
+ moduleCount: modules.size + packageModules.size,
217
+ outputPaths: allOutputFiles.map((file) => file.path),
218
+ },
219
+ diagnostics: [],
220
+ outputFiles: allOutputFiles,
221
+ };
222
+ }
223
+ exports.createBrowserBundle = createBrowserBundle;
224
+ async function transformWorkspaceModule(sourcePath, source, scriptTransformer) {
225
+ const extension = getExtension(sourcePath);
226
+ if (extension === ".css") {
227
+ return transformSuccess(createCssModule(sourcePath, source));
228
+ }
229
+ if (extension === ".json") {
230
+ return transformSuccess(createJsonModule(source));
231
+ }
232
+ if (!SCRIPT_EXTENSIONS.has(extension)) {
233
+ return transformSuccess(source);
234
+ }
235
+ const loader = scriptLoaderForExtension(extension);
236
+ if (loader !== undefined && scriptTransformer !== undefined) {
237
+ return scriptTransformer({
238
+ loader,
239
+ sourcePath,
240
+ sourceText: source,
241
+ });
242
+ }
243
+ return transformSuccess(ts.transpileModule(source, {
244
+ compilerOptions: {
245
+ esModuleInterop: true,
246
+ importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Remove,
247
+ jsx: ts.JsxEmit.React,
248
+ jsxFactory: "React.createElement",
249
+ jsxFragmentFactory: "React.Fragment",
250
+ module: ts.ModuleKind.ESNext,
251
+ target: ts.ScriptTarget.ES2020,
252
+ },
253
+ fileName: sourcePath,
254
+ reportDiagnostics: false,
255
+ }).outputText);
256
+ }
257
+ function transformSuccess(outputText) {
258
+ return {
259
+ success: true,
260
+ outputText,
261
+ diagnostics: [],
262
+ };
263
+ }
264
+ function transformPackageModule(importer, filePath, content) {
265
+ const extension = getExtension(filePath);
266
+ if (typeof content !== "string" &&
267
+ !SCRIPT_EXTENSIONS.has(extension) &&
268
+ extension !== ".css" &&
269
+ extension !== ".json") {
270
+ return transformSuccess(createAssetModule(filePath, content));
271
+ }
272
+ const source = typeof content === "string" ? content : new TextDecoder().decode(content);
273
+ if (extension === ".css") {
274
+ return transformSuccess(createCssModule(importer, source));
275
+ }
276
+ if (extension === ".json") {
277
+ return transformSuccess(createJsonModule(source));
278
+ }
279
+ if (!SCRIPT_EXTENSIONS.has(extension)) {
280
+ return transformSuccess(source);
281
+ }
282
+ return transformSuccess(ts.transpileModule(source, {
283
+ compilerOptions: {
284
+ esModuleInterop: true,
285
+ importsNotUsedAsValues: ts.ImportsNotUsedAsValues.Remove,
286
+ jsx: ts.JsxEmit.React,
287
+ jsxFactory: "React.createElement",
288
+ jsxFragmentFactory: "React.Fragment",
289
+ module: ts.ModuleKind.ESNext,
290
+ target: ts.ScriptTarget.ES2020,
291
+ },
292
+ fileName: importer,
293
+ reportDiagnostics: false,
294
+ }).outputText);
295
+ }
296
+ function createCssModule(sourcePath, css) {
297
+ return [
298
+ `const css = ${JSON.stringify(css)};`,
299
+ `const id = ${JSON.stringify(`forge-css:${sourcePath}`)};`,
300
+ "const previous = document.querySelector(`style[data-forge-css=\"${id}\"]`);",
301
+ "const style = previous ?? document.createElement('style');",
302
+ "style.setAttribute('data-forge-css', id);",
303
+ "style.textContent = css;",
304
+ "if (previous === null) document.head.append(style);",
305
+ "export default css;",
306
+ "",
307
+ ].join("\n");
308
+ }
309
+ function createJsonModule(json) {
310
+ return `export default ${json.trim()};\n`;
311
+ }
312
+ function createAssetModule(sourcePath, content) {
313
+ const contentType = inferAssetContentType(sourcePath);
314
+ const dataUrl = `data:${contentType};base64,${toBase64(content)}`;
315
+ return `export default ${JSON.stringify(dataUrl)};\n`;
316
+ }
317
+ function rewriteModuleSpecifiers(source, rewrites) {
318
+ if (rewrites.size === 0) {
319
+ return source;
320
+ }
321
+ return source
322
+ .replace(/(\b(?:import|export)\s+(?:[^'"]*?\s+from\s*)?)(["'])([^"']+)\2/g, (match, prefix, quote, specifier) => {
323
+ const replacement = rewrites.get(specifier);
324
+ return replacement === undefined
325
+ ? match
326
+ : `${prefix}${quote}${replacement}${quote}`;
327
+ })
328
+ .replace(/(\bimport\s*\(\s*)(["'])([^"']+)\2/g, (match, prefix, quote, specifier) => {
329
+ const replacement = rewrites.get(specifier);
330
+ return replacement === undefined
331
+ ? match
332
+ : `${prefix}${quote}${replacement}${quote}`;
333
+ });
334
+ }
335
+ function extractImportReferences(source) {
336
+ const references = [];
337
+ const patterns = [
338
+ /\bimport\s+(?:[^'"]*?\s+from\s*)?["']([^"']+)["']/g,
339
+ /\bexport\s+[^'"]*?\s+from\s*["']([^"']+)["']/g,
340
+ /\bimport\s*\(\s*["']([^"']+)["']\s*\)/g,
341
+ ];
342
+ for (const pattern of patterns) {
343
+ for (const match of source.matchAll(pattern)) {
344
+ references.push({ specifier: match[1] });
345
+ }
346
+ }
347
+ return references;
348
+ }
349
+ async function resolveLocalImport(fileSystem, importer, specifier) {
350
+ const basePath = specifier.startsWith("/")
351
+ ? specifier
352
+ : `${dirname(importer)}/${specifier}`;
353
+ const normalized = (0, virtual_file_system_1.normalizeForgePath)(basePath);
354
+ if (!normalized.ok) {
355
+ return undefined;
356
+ }
357
+ for (const suffix of DEFAULT_RESOLVE_EXTENSIONS) {
358
+ const candidate = `${normalized.path}${suffix}`;
359
+ if (await fileSystem.exists(candidate)) {
360
+ return candidate;
361
+ }
362
+ }
363
+ for (const suffix of INDEX_RESOLVE_EXTENSIONS) {
364
+ const candidate = `${normalized.path}${suffix}`;
365
+ if (await fileSystem.exists(candidate)) {
366
+ return candidate;
367
+ }
368
+ }
369
+ return undefined;
370
+ }
371
+ function resolvePackageImport(packages, specifier) {
372
+ const parsed = parsePackageSpecifier(specifier);
373
+ if (parsed === undefined) {
374
+ return undefined;
375
+ }
376
+ const packageRecord = packages.find((record) => record.name === parsed.name);
377
+ if (packageRecord === undefined) {
378
+ return undefined;
379
+ }
380
+ if (packageRecord.entryUrl !== undefined && parsed.subpath === "") {
381
+ return {
382
+ kind: "external",
383
+ url: packageRecord.entryUrl,
384
+ };
385
+ }
386
+ const normalizedEntry = packageRecord.entry.startsWith("/")
387
+ ? packageRecord.entry
388
+ : `/${packageRecord.entry}`;
389
+ const entryWithoutExtension = normalizedEntry.replace(/\.[cm]?[jt]sx?$/i, "");
390
+ if (packageRecord.entryUrl !== undefined &&
391
+ (parsed.subpath === normalizedEntry || parsed.subpath === entryWithoutExtension)) {
392
+ return {
393
+ kind: "external",
394
+ url: packageRecord.entryUrl,
395
+ };
396
+ }
397
+ const filePath = resolvePackageImportFilePath(packageRecord, parsed.subpath);
398
+ return filePath === undefined
399
+ ? undefined
400
+ : {
401
+ kind: "package-file",
402
+ filePath,
403
+ outputPath: createPackageModuleOutputPath(packageRecord, filePath),
404
+ packageRecord,
405
+ };
406
+ }
407
+ function createPackageEntryImports(packages) {
408
+ return Object.fromEntries(packages
409
+ .filter((record) => record.entryUrl !== undefined)
410
+ .map((record) => [record.name, record.entryUrl])
411
+ .sort(([left], [right]) => left.localeCompare(right)));
412
+ }
413
+ function resolvePackageImportFilePath(packageRecord, subpath) {
414
+ const requestedPath = subpath.length === 0 ? packageRecord.entry : normalizePackageFilePath(subpath);
415
+ return resolvePackageFilePath(packageRecord, requestedPath);
416
+ }
417
+ function resolvePackageFileImport(packageRecord, importerPath, specifier) {
418
+ const basePath = specifier.startsWith("/")
419
+ ? specifier
420
+ : `${dirname(importerPath)}/${specifier}`;
421
+ return resolvePackageFilePath(packageRecord, basePath);
422
+ }
423
+ function resolvePackageFilePath(packageRecord, requestedPath) {
424
+ const normalized = normalizePackageFilePath(requestedPath);
425
+ const candidates = [
426
+ ...DEFAULT_RESOLVE_EXTENSIONS.map((suffix) => `${normalized}${suffix}`),
427
+ ...INDEX_RESOLVE_EXTENSIONS.map((suffix) => `${normalized}${suffix}`),
428
+ ];
429
+ for (const candidate of candidates) {
430
+ const candidatePath = normalizePackageFilePath(candidate);
431
+ if (readPackageFile(packageRecord, candidatePath) !== undefined) {
432
+ return candidatePath;
433
+ }
434
+ }
435
+ return undefined;
436
+ }
437
+ function readPackageFile(packageRecord, filePath) {
438
+ const normalized = normalizePackageFilePath(filePath);
439
+ for (const [recordPath, file] of Object.entries(packageRecord.files)) {
440
+ const candidates = [
441
+ recordPath,
442
+ file.path,
443
+ ].map((path) => normalizePackageFilePath(path));
444
+ if (candidates.includes(normalized)) {
445
+ return file;
446
+ }
447
+ }
448
+ return undefined;
449
+ }
450
+ function createPackageModuleKey(packageRecord, filePath) {
451
+ return `${packageRecord.name}@${packageRecord.version}:${normalizePackageFilePath(filePath)}`;
452
+ }
453
+ function createPackageImporterPath(packageRecord, filePath) {
454
+ return `${packageRecord.name}:${normalizePackageFilePath(filePath)}`;
455
+ }
456
+ function createPackageModuleOutputPath(packageRecord, filePath) {
457
+ const packageSegment = `${safePathSegment(packageRecord.name)}@${safePathSegment(packageRecord.version)}`;
458
+ const modulePath = normalizePackageFilePath(filePath)
459
+ .replace(/\.[^.]+$/, ".js")
460
+ .replace(/[^/a-z0-9._~-]+/gi, "-");
461
+ return `/.forge/build/packages/${packageSegment}${modulePath}`;
462
+ }
463
+ function normalizePackageFilePath(path) {
464
+ const input = path.startsWith("/") ? path : `/${path.replace(/^\.\//, "")}`;
465
+ const normalized = (0, virtual_file_system_1.normalizeForgePath)(input);
466
+ return normalized.ok ? normalized.path : input;
467
+ }
468
+ function safePathSegment(value) {
469
+ return value
470
+ .replace(/^@/, "")
471
+ .replace(/\//g, "__")
472
+ .replace(/[^a-z0-9._~-]+/gi, "-")
473
+ .toLowerCase();
474
+ }
475
+ function parsePackageSpecifier(specifier) {
476
+ if (specifier.startsWith("@")) {
477
+ const parts = specifier.split("/");
478
+ if (parts.length < 2) {
479
+ return undefined;
480
+ }
481
+ const name = `${parts[0]}/${parts[1]}`;
482
+ return {
483
+ name,
484
+ subpath: specifier.slice(name.length),
485
+ };
486
+ }
487
+ const [name = ""] = specifier.split("/");
488
+ if (name.length === 0) {
489
+ return undefined;
490
+ }
491
+ return {
492
+ name,
493
+ subpath: specifier.slice(name.length),
494
+ };
495
+ }
496
+ function createModuleOutputPath(sourcePath) {
497
+ const baseName = sourcePath
498
+ .replace(/^\//, "")
499
+ .replace(/\.[^.]+$/, "")
500
+ .replace(/[^a-z0-9]+/gi, "-")
501
+ .replace(/^-+|-+$/g, "")
502
+ .toLowerCase();
503
+ const safeName = baseName.length > 0 ? baseName : "module";
504
+ return `/.forge/build/assets/${safeName}-${hashText(sourcePath)}.js`;
505
+ }
506
+ function createOutputFile(path, content, contentType) {
507
+ return {
508
+ path,
509
+ content,
510
+ contentType,
511
+ size: new TextEncoder().encode(content).byteLength,
512
+ };
513
+ }
514
+ function isLocalSpecifier(specifier) {
515
+ return specifier.startsWith(".") || specifier.startsWith("/");
516
+ }
517
+ function isExternalUrl(specifier) {
518
+ return /^https?:\/\//i.test(specifier) || specifier.startsWith("data:");
519
+ }
520
+ function dirname(path) {
521
+ const index = path.lastIndexOf("/");
522
+ return index <= 0 ? "/" : path.slice(0, index);
523
+ }
524
+ function getExtension(path) {
525
+ const index = path.lastIndexOf(".");
526
+ return index === -1 ? "" : path.slice(index).toLowerCase();
527
+ }
528
+ function scriptLoaderForExtension(extension) {
529
+ switch (extension) {
530
+ case ".ts":
531
+ return "ts";
532
+ case ".tsx":
533
+ return "tsx";
534
+ default:
535
+ return undefined;
536
+ }
537
+ }
538
+ function inferAssetContentType(path) {
539
+ switch (getExtension(path)) {
540
+ case ".gif":
541
+ return "image/gif";
542
+ case ".jpg":
543
+ case ".jpeg":
544
+ return "image/jpeg";
545
+ case ".png":
546
+ return "image/png";
547
+ case ".svg":
548
+ return "image/svg+xml";
549
+ case ".webp":
550
+ return "image/webp";
551
+ case ".woff":
552
+ return "font/woff";
553
+ case ".woff2":
554
+ return "font/woff2";
555
+ default:
556
+ return "application/octet-stream";
557
+ }
558
+ }
559
+ function sortRecord(record) {
560
+ return Object.fromEntries(Object.entries(record).sort(([left], [right]) => left.localeCompare(right)));
561
+ }
562
+ function hashText(text) {
563
+ let hash = 0x811c9dc5;
564
+ for (let index = 0; index < text.length; index += 1) {
565
+ hash ^= text.charCodeAt(index);
566
+ hash = Math.imul(hash, 0x01000193) >>> 0;
567
+ }
568
+ return hash.toString(16).padStart(8, "0");
569
+ }
570
+ function toBase64(bytes) {
571
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
572
+ let output = "";
573
+ for (let index = 0; index < bytes.length; index += 3) {
574
+ const first = bytes[index];
575
+ const second = bytes[index + 1];
576
+ const third = bytes[index + 2];
577
+ const triplet = (first << 16) | ((second ?? 0) << 8) | (third ?? 0);
578
+ output += alphabet[(triplet >> 18) & 63];
579
+ output += alphabet[(triplet >> 12) & 63];
580
+ output += second === undefined ? "=" : alphabet[(triplet >> 6) & 63];
581
+ output += third === undefined ? "=" : alphabet[triplet & 63];
582
+ }
583
+ return output;
584
+ }
@@ -0,0 +1,7 @@
1
+ import type { ForgeBuildPipelineDiagnostic } from "./types";
2
+ export declare function createEsbuildWorkerTransformDiagnostic(path: string, cause: unknown): ForgeBuildPipelineDiagnostic;
3
+ export declare function createMissingBuildScriptDiagnostic(): ForgeBuildPipelineDiagnostic;
4
+ export declare function createUnsupportedBuildScriptDiagnostic(script: string): ForgeBuildPipelineDiagnostic;
5
+ export declare function createMissingEntryDiagnostic(): ForgeBuildPipelineDiagnostic;
6
+ export declare function createUnresolvedImportDiagnostic(importSpecifier: string, importer: string): ForgeBuildPipelineDiagnostic;
7
+ export declare function createViteConfigNotExecutedDiagnostic(path: string): ForgeBuildPipelineDiagnostic;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createViteConfigNotExecutedDiagnostic = exports.createUnresolvedImportDiagnostic = exports.createMissingEntryDiagnostic = exports.createUnsupportedBuildScriptDiagnostic = exports.createMissingBuildScriptDiagnostic = exports.createEsbuildWorkerTransformDiagnostic = void 0;
4
+ function createEsbuildWorkerTransformDiagnostic(path, cause) {
5
+ return {
6
+ code: "esbuild_worker_transform_failed",
7
+ severity: "error",
8
+ message: "Esbuild wasm worker failed to transform a workspace module.",
9
+ path,
10
+ cause,
11
+ workerDiagnostic: isWorkerDiagnostic(cause) ? cause : undefined,
12
+ };
13
+ }
14
+ exports.createEsbuildWorkerTransformDiagnostic = createEsbuildWorkerTransformDiagnostic;
15
+ function createMissingBuildScriptDiagnostic() {
16
+ return {
17
+ code: "missing_build_script",
18
+ severity: "error",
19
+ message: "Package manifest does not define scripts.build.",
20
+ path: "/package.json",
21
+ };
22
+ }
23
+ exports.createMissingBuildScriptDiagnostic = createMissingBuildScriptDiagnostic;
24
+ function createUnsupportedBuildScriptDiagnostic(script) {
25
+ return {
26
+ code: "unsupported_build_script",
27
+ severity: "error",
28
+ message: "Build script is not supported by Forge.",
29
+ path: "/package.json",
30
+ script,
31
+ };
32
+ }
33
+ exports.createUnsupportedBuildScriptDiagnostic = createUnsupportedBuildScriptDiagnostic;
34
+ function createMissingEntryDiagnostic() {
35
+ return {
36
+ code: "missing_entry",
37
+ severity: "error",
38
+ message: "No supported browser app entry was found.",
39
+ };
40
+ }
41
+ exports.createMissingEntryDiagnostic = createMissingEntryDiagnostic;
42
+ function createUnresolvedImportDiagnostic(importSpecifier, importer) {
43
+ return {
44
+ code: "unresolved_import",
45
+ severity: "error",
46
+ message: `Unable to resolve import '${importSpecifier}' from ${importer}.`,
47
+ importSpecifier,
48
+ importer,
49
+ path: importer,
50
+ };
51
+ }
52
+ exports.createUnresolvedImportDiagnostic = createUnresolvedImportDiagnostic;
53
+ function createViteConfigNotExecutedDiagnostic(path) {
54
+ return {
55
+ code: "vite_config_not_executed",
56
+ severity: "warning",
57
+ message: `Forge detected ${path} but did not execute it. ` +
58
+ "Config-driven aliases, plugins, defines, and server options are ignored.",
59
+ path,
60
+ };
61
+ }
62
+ exports.createViteConfigNotExecutedDiagnostic = createViteConfigNotExecutedDiagnostic;
63
+ function isWorkerDiagnostic(cause) {
64
+ return (typeof cause === "object" &&
65
+ cause !== null &&
66
+ "code" in cause &&
67
+ "severity" in cause);
68
+ }
@@ -0,0 +1,3 @@
1
+ export { createEsbuildWorkerTransformDiagnostic, createMissingBuildScriptDiagnostic, createMissingEntryDiagnostic, createUnresolvedImportDiagnostic, createUnsupportedBuildScriptDiagnostic, createViteConfigNotExecutedDiagnostic, } from "./diagnostics";
2
+ export { createBuildPipeline, DefaultBuildPipeline, isSupportedViteBuildScript, } from "./pipeline";
3
+ export { BUILD_PIPELINE_CAPABILITY, type ForgeBrowserBundle, type ForgeBrowserBundleManifest, type ForgeBuildDiagnostic, type ForgeBuildManifest, type ForgeBuildMode, type ForgeBuildOutputFile, type ForgeBuildPipeline, type ForgeBuildPipelineDiagnostic, type ForgeBuildPipelineDiagnosticCode, type ForgeBuildPipelineOptions, type ForgeBuildRequest, type ForgeBuildResult, type ForgeBuildTiming, } from "./types";
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BUILD_PIPELINE_CAPABILITY = exports.isSupportedViteBuildScript = exports.DefaultBuildPipeline = exports.createBuildPipeline = exports.createViteConfigNotExecutedDiagnostic = exports.createUnsupportedBuildScriptDiagnostic = exports.createUnresolvedImportDiagnostic = exports.createMissingEntryDiagnostic = exports.createMissingBuildScriptDiagnostic = exports.createEsbuildWorkerTransformDiagnostic = void 0;
4
+ var diagnostics_1 = require("./diagnostics");
5
+ Object.defineProperty(exports, "createEsbuildWorkerTransformDiagnostic", { enumerable: true, get: function () { return diagnostics_1.createEsbuildWorkerTransformDiagnostic; } });
6
+ Object.defineProperty(exports, "createMissingBuildScriptDiagnostic", { enumerable: true, get: function () { return diagnostics_1.createMissingBuildScriptDiagnostic; } });
7
+ Object.defineProperty(exports, "createMissingEntryDiagnostic", { enumerable: true, get: function () { return diagnostics_1.createMissingEntryDiagnostic; } });
8
+ Object.defineProperty(exports, "createUnresolvedImportDiagnostic", { enumerable: true, get: function () { return diagnostics_1.createUnresolvedImportDiagnostic; } });
9
+ Object.defineProperty(exports, "createUnsupportedBuildScriptDiagnostic", { enumerable: true, get: function () { return diagnostics_1.createUnsupportedBuildScriptDiagnostic; } });
10
+ Object.defineProperty(exports, "createViteConfigNotExecutedDiagnostic", { enumerable: true, get: function () { return diagnostics_1.createViteConfigNotExecutedDiagnostic; } });
11
+ var pipeline_1 = require("./pipeline");
12
+ Object.defineProperty(exports, "createBuildPipeline", { enumerable: true, get: function () { return pipeline_1.createBuildPipeline; } });
13
+ Object.defineProperty(exports, "DefaultBuildPipeline", { enumerable: true, get: function () { return pipeline_1.DefaultBuildPipeline; } });
14
+ Object.defineProperty(exports, "isSupportedViteBuildScript", { enumerable: true, get: function () { return pipeline_1.isSupportedViteBuildScript; } });
15
+ var types_1 = require("./types");
16
+ Object.defineProperty(exports, "BUILD_PIPELINE_CAPABILITY", { enumerable: true, get: function () { return types_1.BUILD_PIPELINE_CAPABILITY; } });