@ecopages/core 0.2.0-alpha.53 → 0.2.0-alpha.55

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 (58) hide show
  1. package/README.md +2 -3
  2. package/package.json +34 -14
  3. package/src/adapters/bun/server-adapter.d.ts +7 -0
  4. package/src/adapters/bun/server-adapter.js +8 -3
  5. package/src/adapters/node/server-adapter.d.ts +1 -1
  6. package/src/adapters/node/server-adapter.js +2 -4
  7. package/src/build/README.md +57 -73
  8. package/src/build/browser-runtime-plugin-helpers.d.ts +26 -0
  9. package/src/build/browser-runtime-plugin-helpers.js +14 -0
  10. package/src/build/browser-runtime-plugin.d.ts +78 -0
  11. package/src/build/{browser-runtime-import-rewrite-plugin.js → browser-runtime-plugin.js} +49 -42
  12. package/src/build/build-adapter.d.ts +350 -93
  13. package/src/build/build-adapter.js +61 -492
  14. package/src/build/build-manifest.js +3 -6
  15. package/src/build/build-types.d.ts +2 -2
  16. package/src/build/rolldown-build-adapter.d.ts +32 -0
  17. package/src/build/rolldown-build-adapter.js +260 -0
  18. package/src/build/rolldown-plugin-bridge.d.ts +50 -0
  19. package/src/build/rolldown-plugin-bridge.js +194 -0
  20. package/src/build/runtime-build-executor.d.ts +14 -7
  21. package/src/build/runtime-build-executor.js +8 -11
  22. package/src/build/runtime-build-output-normalizer.d.ts +3 -0
  23. package/src/build/runtime-build-output-normalizer.js +111 -0
  24. package/src/build/serialized-build-executor.d.ts +64 -0
  25. package/src/build/serialized-build-executor.js +63 -0
  26. package/src/build/server-side-css-shim-plugin.d.ts +41 -0
  27. package/src/build/server-side-css-shim-plugin.js +35 -0
  28. package/src/cache/index.d.ts +6 -0
  29. package/src/cache/index.js +6 -0
  30. package/src/cache/module-parse-cache.d.ts +65 -0
  31. package/src/cache/module-parse-cache.js +75 -0
  32. package/src/config/README.md +1 -1
  33. package/src/config/config-builder.d.ts +3 -3
  34. package/src/config/config-builder.js +5 -14
  35. package/src/eco/eco.types.d.ts +2 -5
  36. package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -2
  37. package/src/hmr/strategies/js-hmr-strategy.js +2 -2
  38. package/src/plugins/alias-resolver-cache.d.ts +68 -0
  39. package/src/plugins/alias-resolver-cache.js +106 -0
  40. package/src/plugins/alias-resolver-plugin.d.ts +4 -1
  41. package/src/plugins/alias-resolver-plugin.js +9 -5
  42. package/src/plugins/eco-component-meta-plugin.js +2 -2
  43. package/src/plugins/foreign-jsx-override-plugin.d.ts +1 -1
  44. package/src/route-renderer/orchestration/render-output.utils.d.ts +1 -1
  45. package/src/services/assets/browser-bundle.service.d.ts +1 -1
  46. package/src/services/module-loading/app-module-loader.service.d.ts +1 -1
  47. package/src/services/module-loading/app-server-module-transpiler.service.js +8 -29
  48. package/src/services/module-loading/page-module-import.service.js +2 -0
  49. package/src/types/internal-types.d.ts +1 -1
  50. package/src/build/browser-runtime-import-rewrite-plugin.d.ts +0 -26
  51. package/src/build/dev-build-coordinator.d.ts +0 -72
  52. package/src/build/dev-build-coordinator.js +0 -154
  53. package/src/build/esbuild-build-adapter.d.ts +0 -79
  54. package/src/build/esbuild-build-adapter.js +0 -521
  55. package/src/build/runtime-specifier-alias-plugin.d.ts +0 -15
  56. package/src/build/runtime-specifier-alias-plugin.js +0 -31
  57. package/src/services/module-loading/node-bootstrap-plugin.d.ts +0 -38
  58. package/src/services/module-loading/node-bootstrap-plugin.js +0 -215
@@ -1,521 +0,0 @@
1
- import { readFileSync, readdirSync, writeFileSync } from "node:fs";
2
- import { createRequire } from "node:module";
3
- import path from "node:path";
4
- import { pathToFileURL } from "node:url";
5
- import { fileSystem } from "@ecopages/file-system";
6
- import {
7
- collectBrowserRuntimeImportRewriteMap,
8
- rewriteBrowserRuntimeImports
9
- } from "./browser-runtime-import-rewrite-plugin.js";
10
- const moduleRequire = createRequire(import.meta.url);
11
- const esbuildPath = moduleRequire.resolve("esbuild");
12
- const workspaceNodePathsCache = /* @__PURE__ */ new Map();
13
- function transpileProfileToOptions(profile) {
14
- switch (profile) {
15
- case "browser-script":
16
- return {
17
- target: "browser",
18
- format: "esm",
19
- sourcemap: "none"
20
- };
21
- case "hmr-runtime":
22
- return {
23
- target: "browser",
24
- format: "esm",
25
- sourcemap: "none"
26
- };
27
- case "hmr-entrypoint":
28
- return {
29
- target: "browser",
30
- format: "esm",
31
- sourcemap: "none"
32
- };
33
- }
34
- }
35
- const ESBUILD_ADAPTER_BRAND = /* @__PURE__ */ Symbol.for("EsbuildBuildAdapter");
36
- class EsbuildBuildAdapter {
37
- ownership = "bun-native";
38
- [ESBUILD_ADAPTER_BRAND] = true;
39
- getJavaScriptOutExtension(options) {
40
- if (options.target === "browser") {
41
- return void 0;
42
- }
43
- if (options.format === "cjs") {
44
- return ".cjs";
45
- }
46
- if (options.format === "esm") {
47
- return ".mjs";
48
- }
49
- return void 0;
50
- }
51
- collectWorkspaceNodePaths(scanRoot, maxDepth = 3) {
52
- const normalizedRoot = path.resolve(scanRoot);
53
- const cached = workspaceNodePathsCache.get(normalizedRoot);
54
- if (cached) {
55
- return cached;
56
- }
57
- const nodePaths = /* @__PURE__ */ new Set();
58
- const skippedDirectoryNames = /* @__PURE__ */ new Set([".git", ".turbo", "dist", "node_modules", "test-results"]);
59
- const visit = (dirPath, depth) => {
60
- if (depth > maxDepth) {
61
- return;
62
- }
63
- const packageJsonPath = path.join(dirPath, "package.json");
64
- const nodeModulesPath = path.join(dirPath, "node_modules");
65
- if (fileSystem.exists(packageJsonPath) && fileSystem.exists(nodeModulesPath)) {
66
- nodePaths.add(nodeModulesPath);
67
- }
68
- if (depth === maxDepth) {
69
- return;
70
- }
71
- for (const entry of readdirSync(dirPath, { withFileTypes: true })) {
72
- if (!entry.isDirectory()) {
73
- continue;
74
- }
75
- if (skippedDirectoryNames.has(entry.name) || entry.name.startsWith(".")) {
76
- continue;
77
- }
78
- visit(path.join(dirPath, entry.name), depth + 1);
79
- }
80
- };
81
- if (fileSystem.exists(normalizedRoot) && fileSystem.isDirectory(normalizedRoot)) {
82
- visit(normalizedRoot, 0);
83
- }
84
- const resolvedNodePaths = Array.from(nodePaths);
85
- workspaceNodePathsCache.set(normalizedRoot, resolvedNodePaths);
86
- return resolvedNodePaths;
87
- }
88
- getFallbackNodePaths(contextRoot) {
89
- const nodePaths = /* @__PURE__ */ new Set();
90
- const contextNodeModulesPath = path.join(contextRoot, "node_modules");
91
- if (fileSystem.exists(contextNodeModulesPath)) {
92
- nodePaths.add(contextNodeModulesPath);
93
- }
94
- for (const workspaceNodePath of this.collectWorkspaceNodePaths(process.cwd())) {
95
- nodePaths.add(workspaceNodePath);
96
- }
97
- return Array.from(nodePaths);
98
- }
99
- rewriteBrowserRuntimeImportsInOutputs(result, plugins) {
100
- if (!result.success || result.outputs.length === 0) {
101
- return result;
102
- }
103
- const specifierMap = collectBrowserRuntimeImportRewriteMap(plugins);
104
- if (specifierMap.size === 0) {
105
- return result;
106
- }
107
- for (const output of result.outputs) {
108
- if (!/\.(?:[cm]?js)$/u.test(output.path)) {
109
- continue;
110
- }
111
- const code = readFileSync(output.path, "utf-8");
112
- const rewritten = rewriteBrowserRuntimeImports(code, specifierMap, output.path);
113
- if (rewritten !== code) {
114
- writeFileSync(output.path, rewritten);
115
- }
116
- }
117
- return result;
118
- }
119
- escapeRegExp(value) {
120
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
121
- }
122
- getPluginsForBuild(additionalPlugins) {
123
- const byName = /* @__PURE__ */ new Map();
124
- for (const plugin of additionalPlugins ?? []) {
125
- if (!byName.has(plugin.name)) {
126
- byName.set(plugin.name, plugin);
127
- }
128
- }
129
- return Array.from(byName.values());
130
- }
131
- normalizeEsbuildLoader(loader) {
132
- switch (loader) {
133
- case "base64":
134
- case "binary":
135
- case "copy":
136
- case "css":
137
- case "dataurl":
138
- case "empty":
139
- case "file":
140
- case "global-css":
141
- case "js":
142
- case "json":
143
- case "jsx":
144
- case "local-css":
145
- case "text":
146
- case "ts":
147
- case "tsx":
148
- return loader;
149
- default:
150
- return void 0;
151
- }
152
- }
153
- inferEsbuildLoaderFromPath(filePath) {
154
- const extension = path.extname(filePath).toLowerCase();
155
- switch (extension) {
156
- case ".ts":
157
- return "ts";
158
- case ".tsx":
159
- return "tsx";
160
- case ".jsx":
161
- return "jsx";
162
- case ".json":
163
- return "json";
164
- case ".css":
165
- return "css";
166
- default:
167
- return "js";
168
- }
169
- }
170
- convertLoadResultToModuleSource(result) {
171
- if (!result || typeof result !== "object") {
172
- return void 0;
173
- }
174
- const candidate = result;
175
- if (typeof candidate.contents === "string") {
176
- return candidate.contents;
177
- }
178
- if (candidate.loader === "object" && candidate.exports && typeof candidate.exports === "object") {
179
- const entries = Object.entries(candidate.exports).map(
180
- ([key, value]) => key === "default" ? `export default ${JSON.stringify(value)};` : `export const ${key} = ${JSON.stringify(value)};`
181
- ).join("\n");
182
- return entries;
183
- }
184
- return void 0;
185
- }
186
- convertPluginOnLoadResult(args, result) {
187
- if (!result || typeof result !== "object") {
188
- return void 0;
189
- }
190
- const candidate = result;
191
- const sourceFromExports = candidate.loader === "object" && candidate.exports && typeof candidate.exports === "object" ? this.convertLoadResultToModuleSource(candidate) : void 0;
192
- if (sourceFromExports) {
193
- return {
194
- contents: sourceFromExports,
195
- loader: "js",
196
- resolveDir: path.dirname(args.path)
197
- };
198
- }
199
- if (typeof candidate.contents === "string" || candidate.contents instanceof Uint8Array) {
200
- return {
201
- contents: candidate.contents,
202
- loader: this.normalizeEsbuildLoader(candidate.loader) ?? this.inferEsbuildLoaderFromPath(args.path),
203
- resolveDir: typeof candidate.resolveDir === "string" ? candidate.resolveDir : path.dirname(args.path)
204
- };
205
- }
206
- return void 0;
207
- }
208
- resolvePluginPath(value, args, contextRoot) {
209
- if (path.isAbsolute(value)) {
210
- return value;
211
- }
212
- if (value.startsWith(".") || value.startsWith("..")) {
213
- const baseDir = args.importer ? path.dirname(args.importer) : contextRoot;
214
- return path.resolve(baseDir, value);
215
- }
216
- return value;
217
- }
218
- /**
219
- * Creates an esbuild plugin bridge compatible with the existing Ecopages
220
- * plugin API shape.
221
- *
222
- * **Plugin ordering is semantically significant.**
223
- *
224
- * Esbuild applies `onResolve` and `onLoad` hooks in the order they are
225
- * registered: the first handler whose filter matches wins for `onResolve`,
226
- * and the first handler that returns a non-`undefined` result wins for
227
- * `onLoad`. Because we call `plugin.setup(bridge)` sequentially here, the
228
- * position of each plugin in the `plugins` array determines its priority:
229
- *
230
- * - **Index 0** has the highest priority (its hooks run first).
231
- * - **Last index** has the lowest priority (its hooks only run if no earlier
232
- * plugin claimed the path).
233
- *
234
- * When adding new integrations or processors, ensure security-critical plugins
235
- * (e.g. `ecopages-client-graph-boundary`) are placed **before** general-purpose
236
- * loaders in the array so they always get first refusal on every source file.
237
- *
238
- * There is currently no priority system or validation — correct ordering is
239
- * the caller's responsibility.
240
- */
241
- createEcoPluginBridge(plugins, contextRoot) {
242
- return {
243
- name: "ecopages-plugin-bridge",
244
- setup: async (build) => {
245
- let moduleCounter = 0;
246
- const bridge = {
247
- onResolve: (options, callback) => {
248
- build.onResolve(options, async (args) => {
249
- const result = await callback({
250
- path: args.path,
251
- importer: args.importer,
252
- namespace: args.namespace
253
- });
254
- if (!result || typeof result !== "object") {
255
- return void 0;
256
- }
257
- const candidate = result;
258
- const resolveResult = {};
259
- if (typeof candidate.path === "string") {
260
- resolveResult.path = this.resolvePluginPath(candidate.path, args, contextRoot);
261
- }
262
- if (typeof candidate.namespace === "string") {
263
- resolveResult.namespace = candidate.namespace;
264
- }
265
- if (typeof candidate.external === "boolean") {
266
- resolveResult.external = candidate.external;
267
- }
268
- return Object.keys(resolveResult).length > 0 ? resolveResult : void 0;
269
- });
270
- },
271
- onLoad: (options, callback) => {
272
- build.onLoad(options, async (args) => {
273
- const result = await callback({
274
- path: args.path,
275
- namespace: args.namespace
276
- });
277
- return this.convertPluginOnLoadResult(args, result);
278
- });
279
- },
280
- module: (specifier, callback) => {
281
- const namespace = `ecopages-module-${moduleCounter}`;
282
- moduleCounter += 1;
283
- const filter = new RegExp(`^${this.escapeRegExp(specifier)}$`);
284
- build.onResolve({ filter }, () => ({
285
- path: specifier,
286
- namespace
287
- }));
288
- build.onLoad({ filter, namespace }, async (args) => {
289
- const result = await callback();
290
- return this.convertPluginOnLoadResult(args, result);
291
- });
292
- }
293
- };
294
- for (const plugin of plugins) {
295
- await plugin.setup(bridge);
296
- }
297
- }
298
- };
299
- }
300
- async loadEsbuildModule(moduleGeneration = 0) {
301
- const importedModule = await import("esbuild");
302
- const esbuildModule = typeof importedModule.build === "function" ? importedModule : importedModule.default ?? importedModule;
303
- if (moduleGeneration > 0 && !this.isMockedEsbuildModule(esbuildModule)) {
304
- const freshModule = await import(
305
- /* @vite-ignore */
306
- `${pathToFileURL(esbuildPath).href}?ecopages_esbuild=${moduleGeneration}`
307
- );
308
- const normalizedFreshModule = typeof freshModule.build === "function" ? freshModule : freshModule.default ?? freshModule;
309
- if (typeof normalizedFreshModule.build === "function") {
310
- return normalizedFreshModule;
311
- }
312
- }
313
- if (typeof esbuildModule.build !== "function") {
314
- throw new Error("esbuild is not available. Install esbuild to use Node bundling.");
315
- }
316
- return esbuildModule;
317
- }
318
- isMockedEsbuildModule(esbuildModule) {
319
- const build = esbuildModule.build;
320
- const stop = esbuildModule.stop;
321
- return typeof build?.mock === "object" || typeof stop?.mock === "object";
322
- }
323
- /**
324
- * Detects the subset of runtime faults that indicate esbuild's worker
325
- * protocol is corrupted rather than a normal build error.
326
- */
327
- isEsbuildProtocolError(error) {
328
- if (!(error instanceof Error)) {
329
- return false;
330
- }
331
- return ["Unexpected end of JSON input", "Unexpected EOF", "parseJSON", "buildResponseToResult"].some(
332
- (fragment) => error.message.includes(fragment) || error.stack?.includes(fragment)
333
- );
334
- }
335
- async stopEsbuildService(moduleGeneration = 0) {
336
- const esbuild = await this.loadEsbuildModule(moduleGeneration);
337
- if (typeof esbuild.stop === "function") {
338
- esbuild.stop();
339
- }
340
- }
341
- async buildOrThrow(options, moduleGeneration = 0) {
342
- const esbuild = await this.loadEsbuildModule(moduleGeneration);
343
- const contextRoot = options.root ? path.resolve(options.root) : process.cwd();
344
- const outdir = path.resolve(options.outdir ?? "dist/assets");
345
- const tsconfigPath = path.join(contextRoot, "tsconfig.json");
346
- const tsconfigExists = fileSystem.exists(tsconfigPath);
347
- const nodePaths = this.getFallbackNodePaths(contextRoot);
348
- const plugins = this.getPluginsForBuild(options.plugins);
349
- const esbuildPlugins = [
350
- ...plugins.length > 0 ? [this.createEcoPluginBridge(plugins, contextRoot)] : []
351
- ];
352
- const transpileTarget = "es2022";
353
- const usesTemplatedNaming = this.hasTemplateTokens(options.naming);
354
- const outfile = options.naming && !usesTemplatedNaming ? path.join(outdir, options.naming) : void 0;
355
- if (outfile) {
356
- fileSystem.ensureDir(path.dirname(outfile));
357
- }
358
- const outputOptions = outfile ? { outfile } : {
359
- outdir,
360
- ...options.outbase ? { outbase: path.resolve(options.outbase) } : {},
361
- entryNames: usesTemplatedNaming ? this.toEntryNamePattern(options.naming) : "[name]",
362
- chunkNames: "[name]-[hash]",
363
- assetNames: "[name]-[hash]"
364
- };
365
- const result = await esbuild.build({
366
- absWorkingDir: contextRoot,
367
- ...nodePaths.length > 0 ? { nodePaths } : {},
368
- entryPoints: options.entrypoints,
369
- bundle: options.bundle ?? true,
370
- ...outputOptions,
371
- ...options.conditions ? { conditions: options.conditions } : {},
372
- ...options.define ? { define: options.define } : {},
373
- format: this.mapEsbuildFormat(options.format),
374
- platform: options.target === "browser" ? "browser" : "node",
375
- sourcemap: this.mapEsbuildSourcemap(options.sourcemap),
376
- splitting: outfile ? false : !!options.splitting,
377
- minify: !!options.minify,
378
- ...typeof options.treeshaking === "boolean" ? { treeShaking: options.treeshaking } : {},
379
- external: options.external,
380
- ...options.target !== "browser" && options.externalPackages !== false ? { packages: "external" } : {},
381
- target: transpileTarget,
382
- ...this.getJavaScriptOutExtension(options) ? { outExtension: { ".js": this.getJavaScriptOutExtension(options) } } : {},
383
- metafile: true,
384
- write: true,
385
- plugins: esbuildPlugins,
386
- jsx: "automatic",
387
- tsconfig: tsconfigExists ? tsconfigPath : void 0,
388
- logLevel: "silent"
389
- });
390
- const outputs = Object.keys(result.metafile.outputs).map((outputPath) => ({
391
- path: path.isAbsolute(outputPath) ? outputPath : path.join(contextRoot, outputPath)
392
- }));
393
- const logs = result.warnings.map((warning) => ({ message: warning.text }));
394
- const dependencyGraph = this.extractDependencyGraph(result.metafile, contextRoot);
395
- return this.rewriteBrowserRuntimeImportsInOutputs(
396
- {
397
- success: true,
398
- logs,
399
- outputs,
400
- dependencyGraph
401
- },
402
- plugins
403
- );
404
- }
405
- mapEsbuildSourcemap(value) {
406
- switch (value) {
407
- case "none":
408
- return false;
409
- case "inline":
410
- return "inline";
411
- case "both":
412
- return "both";
413
- case "external":
414
- return "external";
415
- default:
416
- return "linked";
417
- }
418
- }
419
- mapEsbuildFormat(value) {
420
- switch (value) {
421
- case "cjs":
422
- return "cjs";
423
- case "iife":
424
- return "iife";
425
- default:
426
- return "esm";
427
- }
428
- }
429
- hasTemplateTokens(value) {
430
- return typeof value === "string" && /\[[^\]]+\]/.test(value);
431
- }
432
- toEntryNamePattern(value) {
433
- if (!value) {
434
- return "[name]";
435
- }
436
- const pattern = value.replaceAll(/\.?\[ext\]/g, "");
437
- return pattern.length > 0 ? pattern : "[name]";
438
- }
439
- normalizeMetafilePath(value, contextRoot) {
440
- if (path.isAbsolute(value)) {
441
- return path.normalize(value);
442
- }
443
- return path.normalize(path.resolve(contextRoot, value));
444
- }
445
- extractDependencyGraph(metafile, contextRoot) {
446
- const entrypoints = /* @__PURE__ */ new Map();
447
- for (const outputMeta of Object.values(metafile.outputs)) {
448
- if (!outputMeta.entryPoint) {
449
- continue;
450
- }
451
- const entrypointPath = this.normalizeMetafilePath(outputMeta.entryPoint, contextRoot);
452
- const dependencies = entrypoints.get(entrypointPath) ?? /* @__PURE__ */ new Set();
453
- dependencies.add(entrypointPath);
454
- for (const inputPath of Object.keys(outputMeta.inputs ?? {})) {
455
- dependencies.add(this.normalizeMetafilePath(inputPath, contextRoot));
456
- }
457
- entrypoints.set(entrypointPath, dependencies);
458
- }
459
- return {
460
- entrypoints: Object.fromEntries(
461
- Array.from(entrypoints.entries(), ([entrypointPath, dependencies]) => [
462
- entrypointPath,
463
- Array.from(dependencies)
464
- ])
465
- )
466
- };
467
- }
468
- /**
469
- * Normalizes esbuild errors into Ecopages `BuildLog` entries.
470
- */
471
- toBuildLogs(error) {
472
- if (error && typeof error === "object") {
473
- const candidate = error;
474
- if (Array.isArray(candidate.errors) && candidate.errors.length > 0) {
475
- return candidate.errors.map((entry) => {
476
- const locationPrefix = entry.location?.file ? `${entry.location.file}:${entry.location.line ?? 0}:${entry.location.column ?? 0} ` : "";
477
- return {
478
- message: `${locationPrefix}${entry.text ?? "Unknown esbuild error"}`
479
- };
480
- });
481
- }
482
- if (typeof candidate.message === "string") {
483
- return [{ message: candidate.message }];
484
- }
485
- }
486
- return [{ message: "Unknown esbuild error" }];
487
- }
488
- createFailureResult(error) {
489
- return {
490
- success: false,
491
- logs: this.toBuildLogs(error),
492
- outputs: []
493
- };
494
- }
495
- /**
496
- * Bundles entrypoints using esbuild for Node runtime builds.
497
- */
498
- async build(options) {
499
- try {
500
- return await this.buildOrThrow(options);
501
- } catch (error) {
502
- return this.createFailureResult(error);
503
- }
504
- }
505
- /**
506
- * Resolves module specifiers from a project root.
507
- */
508
- resolve(importPath, rootDir) {
509
- return moduleRequire.resolve(importPath, { paths: [rootDir] });
510
- }
511
- /**
512
- * Returns transpile defaults for a known transpile profile.
513
- */
514
- getTranspileOptions(profile) {
515
- return transpileProfileToOptions(profile);
516
- }
517
- }
518
- export {
519
- ESBUILD_ADAPTER_BRAND,
520
- EsbuildBuildAdapter
521
- };
@@ -1,15 +0,0 @@
1
- import type { EcoBuildPlugin } from './build-types.js';
2
- type RuntimeSpecifierMap = ReadonlyMap<string, string> | Record<string, string>;
3
- /**
4
- * Creates a build plugin that aliases runtime bare specifiers to concrete URLs.
5
- *
6
- * @remarks
7
- * This helper is used when browser-target builds must preserve integration-owned
8
- * runtime specifier semantics while letting the bundler treat the mapped URLs as
9
- * external runtime assets.
10
- */
11
- export declare function createRuntimeSpecifierAliasPlugin(specifierMapInput: RuntimeSpecifierMap, options?: {
12
- name?: string;
13
- external?: boolean;
14
- }): EcoBuildPlugin | null;
15
- export {};
@@ -1,31 +0,0 @@
1
- function toRuntimeSpecifierMap(specifierMap) {
2
- return specifierMap instanceof Map ? specifierMap : new Map(Object.entries(specifierMap));
3
- }
4
- function escapeRegExp(value) {
5
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
6
- }
7
- function createRuntimeSpecifierAliasPlugin(specifierMapInput, options) {
8
- const specifierMap = toRuntimeSpecifierMap(specifierMapInput);
9
- if (specifierMap.size === 0) {
10
- return null;
11
- }
12
- const filter = new RegExp(`^(${Array.from(specifierMap.keys()).map(escapeRegExp).join("|")})$`);
13
- return {
14
- name: options?.name ?? "runtime-specifier-alias",
15
- setup(build) {
16
- build.onResolve({ filter }, (args) => {
17
- const mappedPath = specifierMap.get(args.path);
18
- if (!mappedPath) {
19
- return void 0;
20
- }
21
- return {
22
- path: mappedPath,
23
- external: options?.external ?? true
24
- };
25
- });
26
- }
27
- };
28
- }
29
- export {
30
- createRuntimeSpecifierAliasPlugin
31
- };
@@ -1,38 +0,0 @@
1
- import type { EcoBuildOnResolveArgs, EcoBuildOnResolveResult, EcoBuildPlugin } from '../../build/build-types.js';
2
- import type { EcoPagesAppConfig } from '../../types/internal-types.js';
3
- /**
4
- * Returns the app-local node_modules directory used by framework-owned Node
5
- * bootstrap loads outside the thin-host manifest path.
6
- */
7
- export declare function getAppRuntimeNodeModulesDir(appConfig: Pick<EcoPagesAppConfig, 'rootDir' | 'workDir' | 'absolutePaths'>): string;
8
- export interface NodeBootstrapResolutionOptions {
9
- /**
10
- * App root used as the fallback package boundary when an importer does not
11
- * live under a more specific package.json.
12
- */
13
- projectDir: string;
14
- /**
15
- * Runtime-local node_modules directory retained for backwards-compatible
16
- * option shape. Third-party packages now resolve through native Node lookup.
17
- */
18
- runtimeNodeModulesDir: string;
19
- }
20
- /**
21
- * Builds the user-facing error for Bun-native imports that cannot run on the
22
- * Node bootstrap transpile path.
23
- */
24
- export declare function getNodeUnsupportedBuiltinError(specifier: string, importer?: string): string;
25
- export declare function resolveNodeBootstrapDependency(args: Pick<EcoBuildOnResolveArgs, 'path' | 'importer'>, options: NodeBootstrapResolutionOptions): EcoBuildOnResolveResult | undefined;
26
- /**
27
- * Creates the Node bootstrap plugin used by app-owned server module loads.
28
- *
29
- * The resolver keeps third-party imports external so native Node package
30
- * semantics decide exports, subpaths, and CommonJS interop at runtime.
31
- */
32
- export declare function createNodeBootstrapPlugin(options: NodeBootstrapResolutionOptions): EcoBuildPlugin;
33
- /**
34
- * Creates the default Node bootstrap plugin for one Ecopages app runtime.
35
- *
36
- * This binds the shared resolution policy to one Ecopages app runtime.
37
- */
38
- export declare function createAppNodeBootstrapPlugin(appConfig: Pick<EcoPagesAppConfig, 'rootDir' | 'workDir' | 'absolutePaths'>): EcoBuildPlugin;