@ecopages/core 0.2.0-alpha.50 → 0.2.0-alpha.52
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 +0 -1
- package/package.json +18 -10
- package/src/adapters/node/server-adapter.js +0 -1
- package/src/adapters/shared/shared-hmr-manager.js +1 -0
- package/src/build/browser-runtime-import-rewrite-plugin.d.ts +26 -0
- package/src/build/browser-runtime-import-rewrite-plugin.js +165 -0
- package/src/build/browser-runtime-manifest.d.ts +31 -0
- package/src/build/browser-runtime-manifest.js +61 -0
- package/src/build/build-adapter.d.ts +2 -2
- package/src/build/build-adapter.js +32 -24
- package/src/build/build-manifest.d.ts +6 -0
- package/src/build/build-manifest.js +24 -2
- package/src/build/esbuild-build-adapter.d.ts +1 -1
- package/src/build/esbuild-build-adapter.js +9 -6
- package/src/build/runtime-specifier-alias-plugin.js +15 -19
- package/src/plugins/integration-plugin.d.ts +11 -1
- package/src/plugins/integration-plugin.js +12 -0
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +2 -0
- package/src/types/public-types.d.ts +5 -0
- package/src/build/runtime-specifier-aliases.d.ts +0 -5
- package/src/build/runtime-specifier-aliases.js +0 -95
package/README.md
CHANGED
|
@@ -280,7 +280,6 @@ Use these entrypoints only when implementing host adapters or framework-owned bu
|
|
|
280
280
|
- `@ecopages/core/build/build-adapter`
|
|
281
281
|
- `@ecopages/core/build/build-types`
|
|
282
282
|
- `@ecopages/core/build/runtime-specifier-alias-plugin`
|
|
283
|
-
- `@ecopages/core/build/runtime-specifier-aliases`
|
|
284
283
|
- `@ecopages/core/plugins/foreign-jsx-override-plugin`
|
|
285
284
|
|
|
286
285
|
These host-facing entrypoints are narrower compatibility seams. App code and most extensions should prefer the app-authoring or extension-authoring surfaces.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/core",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.52",
|
|
4
4
|
"description": "Core package for Ecopages",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"directory": "packages/core"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@ecopages/file-system": "0.2.0-alpha.
|
|
20
|
+
"@ecopages/file-system": "0.2.0-alpha.52",
|
|
21
21
|
"@ecopages/logger": "^0.2.3",
|
|
22
22
|
"@ecopages/scripts-injector": "^0.1.5",
|
|
23
23
|
"@worker-tools/html-rewriter": "0.1.0-pre.19",
|
|
@@ -115,14 +115,18 @@
|
|
|
115
115
|
"types": "./src/build/build-adapter.d.ts",
|
|
116
116
|
"default": "./src/build/build-adapter.js"
|
|
117
117
|
},
|
|
118
|
+
"./build/browser-runtime-manifest": {
|
|
119
|
+
"types": "./src/build/browser-runtime-manifest.d.ts",
|
|
120
|
+
"default": "./src/build/browser-runtime-manifest.js"
|
|
121
|
+
},
|
|
122
|
+
"./build/browser-runtime-import-rewrite-plugin": {
|
|
123
|
+
"types": "./src/build/browser-runtime-import-rewrite-plugin.d.ts",
|
|
124
|
+
"default": "./src/build/browser-runtime-import-rewrite-plugin.js"
|
|
125
|
+
},
|
|
118
126
|
"./build/runtime-specifier-alias-plugin": {
|
|
119
127
|
"types": "./src/build/runtime-specifier-alias-plugin.d.ts",
|
|
120
128
|
"default": "./src/build/runtime-specifier-alias-plugin.js"
|
|
121
129
|
},
|
|
122
|
-
"./build/runtime-specifier-aliases": {
|
|
123
|
-
"types": "./src/build/runtime-specifier-aliases.d.ts",
|
|
124
|
-
"default": "./src/build/runtime-specifier-aliases.js"
|
|
125
|
-
},
|
|
126
130
|
"./plugins/foreign-jsx-override-plugin": {
|
|
127
131
|
"types": "./src/plugins/foreign-jsx-override-plugin.d.ts",
|
|
128
132
|
"default": "./src/plugins/foreign-jsx-override-plugin.js"
|
|
@@ -226,14 +230,18 @@
|
|
|
226
230
|
"types": "./src/build/build-adapter.d.ts",
|
|
227
231
|
"default": "./src/build/build-adapter.js"
|
|
228
232
|
},
|
|
233
|
+
"./build/browser-runtime-manifest.ts": {
|
|
234
|
+
"types": "./src/build/browser-runtime-manifest.d.ts",
|
|
235
|
+
"default": "./src/build/browser-runtime-manifest.js"
|
|
236
|
+
},
|
|
237
|
+
"./build/browser-runtime-import-rewrite-plugin.ts": {
|
|
238
|
+
"types": "./src/build/browser-runtime-import-rewrite-plugin.d.ts",
|
|
239
|
+
"default": "./src/build/browser-runtime-import-rewrite-plugin.js"
|
|
240
|
+
},
|
|
229
241
|
"./build/runtime-specifier-alias-plugin.ts": {
|
|
230
242
|
"types": "./src/build/runtime-specifier-alias-plugin.d.ts",
|
|
231
243
|
"default": "./src/build/runtime-specifier-alias-plugin.js"
|
|
232
244
|
},
|
|
233
|
-
"./build/runtime-specifier-aliases.ts": {
|
|
234
|
-
"types": "./src/build/runtime-specifier-aliases.d.ts",
|
|
235
|
-
"default": "./src/build/runtime-specifier-aliases.js"
|
|
236
|
-
},
|
|
237
245
|
"./plugins/foreign-jsx-override-plugin.ts": {
|
|
238
246
|
"types": "./src/plugins/foreign-jsx-override-plugin.d.ts",
|
|
239
247
|
"default": "./src/plugins/foreign-jsx-override-plugin.js"
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createServer } from "node:http";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { WebSocketServer } from "ws";
|
|
4
3
|
import { fileSystem } from "@ecopages/file-system";
|
|
5
4
|
import { getAppBrowserBuildPlugins, setupAppRuntimePlugins } from "../../build/build-adapter.js";
|
|
6
5
|
import { installAppRuntimeBuildExecutor } from "../../build/runtime-build-executor.js";
|
|
@@ -177,6 +177,7 @@ class SharedHmrManager {
|
|
|
177
177
|
getPagesDir: () => this.appConfig.absolutePaths.pagesDir,
|
|
178
178
|
getBuildExecutor: () => getAppBuildExecutor(this.appConfig),
|
|
179
179
|
getBrowserBundleService: () => this.browserBundleService,
|
|
180
|
+
getEntrypointDependencyGraph: () => this.entrypointDependencyGraph,
|
|
180
181
|
importServerModule: async (filePath) => await this.serverModuleTranspiler.importModule({
|
|
181
182
|
filePath,
|
|
182
183
|
outdir: path.join(resolveInternalExecutionDir(this.appConfig), ".server-modules"),
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { EcoBuildPlugin } from './build-types.js';
|
|
2
|
+
import { type BrowserRuntimeManifest } from './browser-runtime-manifest.js';
|
|
3
|
+
export declare const DEFAULT_BROWSER_RUNTIME_IMPORT_REWRITE_PLUGIN_NAME = "browser-runtime-import-rewrite";
|
|
4
|
+
export type CreateBrowserRuntimeImportRewritePluginOptions = {
|
|
5
|
+
/** Stable build plugin name used for deduplication and selective exclusion. */
|
|
6
|
+
name?: string;
|
|
7
|
+
/** Manifest containing specifier-to-public-URL runtime asset mappings. */
|
|
8
|
+
manifest: BrowserRuntimeManifest;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Rewrites static ESM import/export specifiers and string-literal dynamic imports
|
|
12
|
+
* from manifest-owned runtime specifiers to concrete browser public URLs.
|
|
13
|
+
*/
|
|
14
|
+
export declare function rewriteBrowserRuntimeImports(code: string, specifierMap: ReadonlyMap<string, string>, filePath?: string): string;
|
|
15
|
+
export declare function getBrowserRuntimeImportRewriteMap(plugin: EcoBuildPlugin): ReadonlyMap<string, string> | undefined;
|
|
16
|
+
export declare function collectBrowserRuntimeImportRewriteMap(plugins: EcoBuildPlugin[] | undefined): ReadonlyMap<string, string>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates a build plugin that applies browser runtime manifest import rewrites
|
|
19
|
+
* before the bundler resolves source modules.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* This is the migration path away from browser import-map-style runtime aliases:
|
|
23
|
+
* generated and authored browser modules can keep importing manifest-owned
|
|
24
|
+
* specifiers, while the build turns those specifiers into concrete public URLs.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createBrowserRuntimeImportRewritePlugin(options: CreateBrowserRuntimeImportRewritePluginOptions): EcoBuildPlugin | null;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { parseSync } from "oxc-parser";
|
|
4
|
+
import { getBrowserRuntimeSpecifierMap } from "./browser-runtime-manifest.js";
|
|
5
|
+
const BROWSER_RUNTIME_IMPORT_REWRITE_MAP = /* @__PURE__ */ Symbol.for("ecopages.browserRuntimeImportRewriteMap");
|
|
6
|
+
const DEFAULT_BROWSER_RUNTIME_IMPORT_REWRITE_PLUGIN_NAME = "browser-runtime-import-rewrite";
|
|
7
|
+
function isRecord(value) {
|
|
8
|
+
return Boolean(value) && typeof value === "object";
|
|
9
|
+
}
|
|
10
|
+
function inferLoaderFromPath(filePath) {
|
|
11
|
+
const extension = path.extname(filePath).toLowerCase();
|
|
12
|
+
switch (extension) {
|
|
13
|
+
case ".mts":
|
|
14
|
+
case ".cts":
|
|
15
|
+
case ".ts":
|
|
16
|
+
return "ts";
|
|
17
|
+
case ".tsx":
|
|
18
|
+
return "tsx";
|
|
19
|
+
case ".jsx":
|
|
20
|
+
return "jsx";
|
|
21
|
+
default:
|
|
22
|
+
return "js";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function escapeRegExp(value) {
|
|
26
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
27
|
+
}
|
|
28
|
+
function queueReplacement(options) {
|
|
29
|
+
if (!isRecord(options.source) || typeof options.source.value !== "string") {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const mappedPath = options.specifierMap.get(options.source.value);
|
|
33
|
+
if (!mappedPath || typeof options.source.start !== "number" || typeof options.source.end !== "number") {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const quote = options.code[options.source.start] === "'" ? "'" : '"';
|
|
37
|
+
options.edits.push({
|
|
38
|
+
start: options.source.start,
|
|
39
|
+
end: options.source.end,
|
|
40
|
+
replacement: `${quote}${mappedPath}${quote}`
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function rewriteBrowserRuntimeImports(code, specifierMap, filePath = "browser-runtime-imports.js") {
|
|
44
|
+
if (specifierMap.size === 0) {
|
|
45
|
+
return code;
|
|
46
|
+
}
|
|
47
|
+
const edits = [];
|
|
48
|
+
try {
|
|
49
|
+
const result = parseSync(filePath, code, {
|
|
50
|
+
sourceType: "module",
|
|
51
|
+
lang: path.extname(filePath).endsWith("x") ? "tsx" : "ts"
|
|
52
|
+
});
|
|
53
|
+
const walk = (node) => {
|
|
54
|
+
if (!isRecord(node)) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (node.type === "ImportDeclaration" || node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") {
|
|
58
|
+
queueReplacement({ code, source: node.source, specifierMap, edits });
|
|
59
|
+
}
|
|
60
|
+
if (node.type === "ImportExpression" && isRecord(node.source)) {
|
|
61
|
+
if (node.source.type === "StringLiteral" || node.source.type === "Literal") {
|
|
62
|
+
queueReplacement({ code, source: node.source, specifierMap, edits });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const value of Object.values(node)) {
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
for (const child of value) {
|
|
68
|
+
walk(child);
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
walk(value);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
walk(result.program);
|
|
76
|
+
} catch {
|
|
77
|
+
return code;
|
|
78
|
+
}
|
|
79
|
+
if (edits.length === 0) {
|
|
80
|
+
return code;
|
|
81
|
+
}
|
|
82
|
+
edits.sort((left, right) => right.start - left.start);
|
|
83
|
+
let rewritten = code;
|
|
84
|
+
for (const edit of edits) {
|
|
85
|
+
rewritten = rewritten.slice(0, edit.start) + edit.replacement + rewritten.slice(edit.end);
|
|
86
|
+
}
|
|
87
|
+
return rewritten;
|
|
88
|
+
}
|
|
89
|
+
function getBrowserRuntimeImportRewriteMap(plugin) {
|
|
90
|
+
return plugin[BROWSER_RUNTIME_IMPORT_REWRITE_MAP];
|
|
91
|
+
}
|
|
92
|
+
function collectBrowserRuntimeImportRewriteMap(plugins) {
|
|
93
|
+
const merged = /* @__PURE__ */ new Map();
|
|
94
|
+
for (const plugin of plugins ?? []) {
|
|
95
|
+
const specifierMap = getBrowserRuntimeImportRewriteMap(plugin);
|
|
96
|
+
if (!specifierMap) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
for (const [specifier, publicPath] of specifierMap.entries()) {
|
|
100
|
+
if (!merged.has(specifier)) {
|
|
101
|
+
merged.set(specifier, publicPath);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return merged;
|
|
106
|
+
}
|
|
107
|
+
function createBrowserRuntimeImportRewritePlugin(options) {
|
|
108
|
+
const specifierMap = getBrowserRuntimeSpecifierMap(options.manifest);
|
|
109
|
+
const publicPathSet = new Set(specifierMap.values());
|
|
110
|
+
const specifierFilter = new RegExp(`^(${Array.from(specifierMap.keys()).map(escapeRegExp).join("|")})$`);
|
|
111
|
+
if (specifierMap.size === 0) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
const plugin = {
|
|
115
|
+
name: options.name ?? DEFAULT_BROWSER_RUNTIME_IMPORT_REWRITE_PLUGIN_NAME,
|
|
116
|
+
setup(build) {
|
|
117
|
+
build.onResolve({ filter: specifierFilter }, (args) => {
|
|
118
|
+
const mappedPath = specifierMap.get(args.path);
|
|
119
|
+
if (!mappedPath) {
|
|
120
|
+
return void 0;
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
path: mappedPath,
|
|
124
|
+
external: true
|
|
125
|
+
};
|
|
126
|
+
});
|
|
127
|
+
build.onResolve({ filter: /^\// }, (args) => {
|
|
128
|
+
if (!publicPathSet.has(args.path)) {
|
|
129
|
+
return void 0;
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
path: args.path,
|
|
133
|
+
external: true
|
|
134
|
+
};
|
|
135
|
+
});
|
|
136
|
+
build.onLoad({ filter: /\.[cm]?[jt]sx?$/ }, (args) => {
|
|
137
|
+
if (!path.isAbsolute(args.path) || !existsSync(args.path)) {
|
|
138
|
+
return void 0;
|
|
139
|
+
}
|
|
140
|
+
const code = readFileSync(args.path, "utf-8");
|
|
141
|
+
if (!Array.from(specifierMap.keys()).some((specifier) => code.includes(specifier))) {
|
|
142
|
+
return void 0;
|
|
143
|
+
}
|
|
144
|
+
const rewritten = rewriteBrowserRuntimeImports(code, specifierMap, args.path);
|
|
145
|
+
if (rewritten === code) {
|
|
146
|
+
return void 0;
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
contents: rewritten,
|
|
150
|
+
loader: inferLoaderFromPath(args.path),
|
|
151
|
+
resolveDir: path.dirname(args.path)
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
plugin[BROWSER_RUNTIME_IMPORT_REWRITE_MAP] = specifierMap;
|
|
157
|
+
return plugin;
|
|
158
|
+
}
|
|
159
|
+
export {
|
|
160
|
+
DEFAULT_BROWSER_RUNTIME_IMPORT_REWRITE_PLUGIN_NAME,
|
|
161
|
+
collectBrowserRuntimeImportRewriteMap,
|
|
162
|
+
createBrowserRuntimeImportRewritePlugin,
|
|
163
|
+
getBrowserRuntimeImportRewriteMap,
|
|
164
|
+
rewriteBrowserRuntimeImports
|
|
165
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type BrowserRuntimeMode = 'development' | 'production';
|
|
2
|
+
export type BrowserRuntimeAssetDeclaration = {
|
|
3
|
+
/** Bare or virtual specifier used by authored/generated browser modules. */
|
|
4
|
+
specifier: string;
|
|
5
|
+
/** Integration, processor, or core subsystem that owns this runtime asset. */
|
|
6
|
+
owner: string;
|
|
7
|
+
/** Source import path used to build or resolve the runtime asset. */
|
|
8
|
+
importPath: string;
|
|
9
|
+
/** Concrete browser URL emitted or served for this runtime asset. */
|
|
10
|
+
publicPath: string;
|
|
11
|
+
/** Runtime mode this declaration applies to. Omit when the URL is mode-independent. */
|
|
12
|
+
mode?: BrowserRuntimeMode;
|
|
13
|
+
/** Specifiers that should be treated as external while building this runtime asset. */
|
|
14
|
+
externals?: readonly string[];
|
|
15
|
+
};
|
|
16
|
+
export type BrowserRuntimeAsset = BrowserRuntimeAssetDeclaration & {
|
|
17
|
+
externals: readonly string[];
|
|
18
|
+
};
|
|
19
|
+
export type BrowserRuntimeManifest = {
|
|
20
|
+
assets: readonly BrowserRuntimeAsset[];
|
|
21
|
+
bySpecifier: ReadonlyMap<string, BrowserRuntimeAsset>;
|
|
22
|
+
};
|
|
23
|
+
export declare class BrowserRuntimeManifestConflictError extends Error {
|
|
24
|
+
readonly specifier: string;
|
|
25
|
+
readonly existing: BrowserRuntimeAsset;
|
|
26
|
+
readonly incoming: BrowserRuntimeAsset;
|
|
27
|
+
constructor(specifier: string, existing: BrowserRuntimeAsset, incoming: BrowserRuntimeAsset);
|
|
28
|
+
}
|
|
29
|
+
export declare function createBrowserRuntimeManifest(declarations?: readonly BrowserRuntimeAssetDeclaration[]): BrowserRuntimeManifest;
|
|
30
|
+
export declare function mergeBrowserRuntimeManifests(...manifests: Array<BrowserRuntimeManifest | undefined>): BrowserRuntimeManifest;
|
|
31
|
+
export declare function getBrowserRuntimeSpecifierMap(manifest: BrowserRuntimeManifest): ReadonlyMap<string, string>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
class BrowserRuntimeManifestConflictError extends Error {
|
|
2
|
+
specifier;
|
|
3
|
+
existing;
|
|
4
|
+
incoming;
|
|
5
|
+
constructor(specifier, existing, incoming) {
|
|
6
|
+
super(
|
|
7
|
+
`Browser runtime asset conflict for ${specifier}: ${existing.owner} maps to ${existing.publicPath}, ${incoming.owner} maps to ${incoming.publicPath}`
|
|
8
|
+
);
|
|
9
|
+
this.name = "BrowserRuntimeManifestConflictError";
|
|
10
|
+
this.specifier = specifier;
|
|
11
|
+
this.existing = existing;
|
|
12
|
+
this.incoming = incoming;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function normalizeDeclaration(declaration) {
|
|
16
|
+
return {
|
|
17
|
+
...declaration,
|
|
18
|
+
externals: declaration.externals ?? []
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function hasCompatibleRuntimeAsset(existing, incoming) {
|
|
22
|
+
return existing.owner === incoming.owner && existing.importPath === incoming.importPath && existing.publicPath === incoming.publicPath && existing.mode === incoming.mode && arrayEquals(existing.externals, incoming.externals);
|
|
23
|
+
}
|
|
24
|
+
function arrayEquals(left, right) {
|
|
25
|
+
if (left.length !== right.length) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return left.every((value, index) => value === right[index]);
|
|
29
|
+
}
|
|
30
|
+
function createBrowserRuntimeManifest(declarations = []) {
|
|
31
|
+
const assets = [];
|
|
32
|
+
const bySpecifier = /* @__PURE__ */ new Map();
|
|
33
|
+
for (const declaration of declarations) {
|
|
34
|
+
const asset = normalizeDeclaration(declaration);
|
|
35
|
+
const existing = bySpecifier.get(asset.specifier);
|
|
36
|
+
if (existing) {
|
|
37
|
+
if (!hasCompatibleRuntimeAsset(existing, asset)) {
|
|
38
|
+
throw new BrowserRuntimeManifestConflictError(asset.specifier, existing, asset);
|
|
39
|
+
}
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
assets.push(asset);
|
|
43
|
+
bySpecifier.set(asset.specifier, asset);
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
assets,
|
|
47
|
+
bySpecifier
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function mergeBrowserRuntimeManifests(...manifests) {
|
|
51
|
+
return createBrowserRuntimeManifest(manifests.flatMap((manifest) => manifest?.assets ?? []));
|
|
52
|
+
}
|
|
53
|
+
function getBrowserRuntimeSpecifierMap(manifest) {
|
|
54
|
+
return new Map(manifest.assets.map((asset) => [asset.specifier, asset.publicPath]));
|
|
55
|
+
}
|
|
56
|
+
export {
|
|
57
|
+
BrowserRuntimeManifestConflictError,
|
|
58
|
+
createBrowserRuntimeManifest,
|
|
59
|
+
getBrowserRuntimeSpecifierMap,
|
|
60
|
+
mergeBrowserRuntimeManifests
|
|
61
|
+
};
|
|
@@ -123,9 +123,9 @@ export declare class BunBuildAdapter implements BuildAdapter {
|
|
|
123
123
|
private resolveTemplatedOutputPath;
|
|
124
124
|
private relocateOutputFile;
|
|
125
125
|
private hasJavaScriptExtension;
|
|
126
|
+
private rewriteBrowserRuntimeImportsInOutputs;
|
|
126
127
|
private findOutputMatchForEntrypoint;
|
|
127
128
|
private normalizeBunOutputs;
|
|
128
|
-
private rewriteAliasedRuntimeSpecifiers;
|
|
129
129
|
build(options: BuildOptions): Promise<BuildResult>;
|
|
130
130
|
resolve(importPath: string, rootDir: string): string;
|
|
131
131
|
getTranspileOptions(profile: BuildTranspileProfile): BuildTranspileOptions;
|
|
@@ -198,7 +198,7 @@ export declare function updateAppBuildManifest(appConfig: EcoPagesAppConfig, inp
|
|
|
198
198
|
* as HMR registration, cache prewarming, and runtime-origin wiring belong to
|
|
199
199
|
* the startup path and must not be triggered here.
|
|
200
200
|
*/
|
|
201
|
-
export declare function collectConfiguredAppBuildManifestContributions(appConfig: EcoPagesAppConfig): Promise<Pick<AppBuildManifest, 'runtimePlugins' | 'browserBundlePlugins'>>;
|
|
201
|
+
export declare function collectConfiguredAppBuildManifestContributions(appConfig: EcoPagesAppConfig): Promise<Pick<AppBuildManifest, 'runtimePlugins' | 'browserBundlePlugins' | 'browserRuntimeManifest'>>;
|
|
202
202
|
/**
|
|
203
203
|
* Runs runtime-only processor and integration setup against an already sealed
|
|
204
204
|
* app manifest.
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
import { mergeBrowserRuntimeManifests } from "./browser-runtime-manifest.js";
|
|
2
|
+
import {
|
|
3
|
+
collectBrowserRuntimeImportRewriteMap,
|
|
4
|
+
rewriteBrowserRuntimeImports
|
|
5
|
+
} from "./browser-runtime-import-rewrite-plugin.js";
|
|
1
6
|
import {
|
|
2
7
|
createAppBuildManifest,
|
|
3
8
|
getBrowserBuildPlugins,
|
|
4
9
|
getServerBuildPlugins
|
|
5
10
|
} from "./build-manifest.js";
|
|
6
11
|
import { EsbuildBuildAdapter } from "./esbuild-build-adapter.js";
|
|
7
|
-
import { collectRuntimeSpecifierAliasMap, rewriteRuntimeSpecifierAliases } from "./runtime-specifier-aliases.js";
|
|
8
12
|
import { getBunRuntime } from "../utils/runtime.js";
|
|
9
13
|
import fs from "node:fs";
|
|
10
14
|
import path from "node:path";
|
|
@@ -325,6 +329,26 @@ class BunBuildAdapter {
|
|
|
325
329
|
hasJavaScriptExtension(outputPath) {
|
|
326
330
|
return /\.(?:[cm]?js)$/u.test(outputPath);
|
|
327
331
|
}
|
|
332
|
+
rewriteBrowserRuntimeImportsInOutputs(result, plugins) {
|
|
333
|
+
if (!result.success || result.outputs.length === 0) {
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
const specifierMap = collectBrowserRuntimeImportRewriteMap(plugins);
|
|
337
|
+
if (specifierMap.size === 0) {
|
|
338
|
+
return result;
|
|
339
|
+
}
|
|
340
|
+
for (const output of result.outputs) {
|
|
341
|
+
if (!this.hasJavaScriptExtension(output.path) || !fs.existsSync(output.path)) {
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
const code = fs.readFileSync(output.path, "utf-8");
|
|
345
|
+
const rewritten = rewriteBrowserRuntimeImports(code, specifierMap, output.path);
|
|
346
|
+
if (rewritten !== code) {
|
|
347
|
+
fs.writeFileSync(output.path, rewritten);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
328
352
|
findOutputMatchForEntrypoint(options, entrypointPath, outputs, usedOutputIndexes) {
|
|
329
353
|
const expectedOutputPath = this.resolveTemplatedOutputPath(options, entrypointPath);
|
|
330
354
|
if (!expectedOutputPath) {
|
|
@@ -401,26 +425,6 @@ class BunBuildAdapter {
|
|
|
401
425
|
})
|
|
402
426
|
};
|
|
403
427
|
}
|
|
404
|
-
rewriteAliasedRuntimeSpecifiers(result, plugins) {
|
|
405
|
-
if (!result.success || result.outputs.length === 0) {
|
|
406
|
-
return result;
|
|
407
|
-
}
|
|
408
|
-
const aliasMap = collectRuntimeSpecifierAliasMap(plugins);
|
|
409
|
-
if (aliasMap.size === 0) {
|
|
410
|
-
return result;
|
|
411
|
-
}
|
|
412
|
-
for (const output of result.outputs) {
|
|
413
|
-
if (!/\.(?:[cm]?js)$/u.test(output.path) || !fs.existsSync(output.path)) {
|
|
414
|
-
continue;
|
|
415
|
-
}
|
|
416
|
-
const code = fs.readFileSync(output.path, "utf-8");
|
|
417
|
-
const rewritten = rewriteRuntimeSpecifierAliases(code, aliasMap);
|
|
418
|
-
if (rewritten !== code) {
|
|
419
|
-
fs.writeFileSync(output.path, rewritten);
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
return result;
|
|
423
|
-
}
|
|
424
428
|
async build(options) {
|
|
425
429
|
const bun = getBunRuntime();
|
|
426
430
|
if (!bun) {
|
|
@@ -449,7 +453,7 @@ class BunBuildAdapter {
|
|
|
449
453
|
jsx: options.jsx,
|
|
450
454
|
plugins: plugins.length > 0 ? [this.createEcoPluginBridge(plugins, contextRoot)] : void 0
|
|
451
455
|
});
|
|
452
|
-
return this.
|
|
456
|
+
return this.rewriteBrowserRuntimeImportsInOutputs(
|
|
453
457
|
this.normalizeBunOutputs(
|
|
454
458
|
{
|
|
455
459
|
success: result.success,
|
|
@@ -554,7 +558,8 @@ function createConfiguredAppBuildManifest(appConfig, input) {
|
|
|
554
558
|
return createAppBuildManifest({
|
|
555
559
|
loaderPlugins: input?.loaderPlugins ?? Array.from(appConfig.loaders.values()),
|
|
556
560
|
runtimePlugins: input?.runtimePlugins,
|
|
557
|
-
browserBundlePlugins: input?.browserBundlePlugins
|
|
561
|
+
browserBundlePlugins: input?.browserBundlePlugins,
|
|
562
|
+
browserRuntimeManifest: input?.browserRuntimeManifest
|
|
558
563
|
});
|
|
559
564
|
}
|
|
560
565
|
function updateAppBuildManifest(appConfig, input) {
|
|
@@ -563,6 +568,7 @@ function updateAppBuildManifest(appConfig, input) {
|
|
|
563
568
|
async function collectConfiguredAppBuildManifestContributions(appConfig) {
|
|
564
569
|
const runtimePlugins = [];
|
|
565
570
|
const browserBundlePlugins = [];
|
|
571
|
+
const browserRuntimeManifests = [];
|
|
566
572
|
for (const processor of appConfig.processors.values()) {
|
|
567
573
|
await processor.prepareBuildContributions();
|
|
568
574
|
if (processor.plugins) {
|
|
@@ -577,10 +583,12 @@ async function collectConfiguredAppBuildManifestContributions(appConfig) {
|
|
|
577
583
|
await integration.prepareBuildContributions();
|
|
578
584
|
runtimePlugins.push(...integration.plugins ?? []);
|
|
579
585
|
browserBundlePlugins.push(...integration.browserBuildPlugins ?? []);
|
|
586
|
+
browserRuntimeManifests.push(integration.browserRuntimeManifest);
|
|
580
587
|
}
|
|
581
588
|
return {
|
|
582
589
|
runtimePlugins,
|
|
583
|
-
browserBundlePlugins
|
|
590
|
+
browserBundlePlugins,
|
|
591
|
+
browserRuntimeManifest: mergeBrowserRuntimeManifests(...browserRuntimeManifests)
|
|
584
592
|
};
|
|
585
593
|
}
|
|
586
594
|
async function setupAppRuntimePlugins(options) {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { EcoBuildPlugin } from './build-types.js';
|
|
2
|
+
import { type BrowserRuntimeManifest } from './browser-runtime-manifest.js';
|
|
2
3
|
export interface AppBuildManifest {
|
|
3
4
|
loaderPlugins: EcoBuildPlugin[];
|
|
4
5
|
runtimePlugins: EcoBuildPlugin[];
|
|
5
6
|
browserBundlePlugins: EcoBuildPlugin[];
|
|
7
|
+
browserRuntimeManifest: BrowserRuntimeManifest;
|
|
6
8
|
}
|
|
7
9
|
/**
|
|
8
10
|
* Merges plugin lists while preserving first-registration precedence by name.
|
|
@@ -17,6 +19,10 @@ export declare function mergeEcoBuildPlugins(...pluginLists: Array<EcoBuildPlugi
|
|
|
17
19
|
* Creates one app-owned build manifest from the supplied plugin buckets.
|
|
18
20
|
*/
|
|
19
21
|
export declare function createAppBuildManifest(input?: Partial<AppBuildManifest>): AppBuildManifest;
|
|
22
|
+
/**
|
|
23
|
+
* Returns the shared browser runtime asset manifest sealed into the app build manifest.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getBrowserRuntimeManifest(manifest: AppBuildManifest): BrowserRuntimeManifest;
|
|
20
26
|
/**
|
|
21
27
|
* Returns the plugin list used for server-oriented builds.
|
|
22
28
|
*/
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createBrowserRuntimeImportRewritePlugin,
|
|
3
|
+
DEFAULT_BROWSER_RUNTIME_IMPORT_REWRITE_PLUGIN_NAME
|
|
4
|
+
} from "./browser-runtime-import-rewrite-plugin.js";
|
|
5
|
+
import {
|
|
6
|
+
createBrowserRuntimeManifest,
|
|
7
|
+
mergeBrowserRuntimeManifests
|
|
8
|
+
} from "./browser-runtime-manifest.js";
|
|
1
9
|
function mergeEcoBuildPlugins(...pluginLists) {
|
|
2
10
|
const byName = /* @__PURE__ */ new Map();
|
|
3
11
|
for (const plugins of pluginLists) {
|
|
@@ -13,18 +21,32 @@ function createAppBuildManifest(input) {
|
|
|
13
21
|
return {
|
|
14
22
|
loaderPlugins: mergeEcoBuildPlugins(input?.loaderPlugins),
|
|
15
23
|
runtimePlugins: mergeEcoBuildPlugins(input?.runtimePlugins),
|
|
16
|
-
browserBundlePlugins: mergeEcoBuildPlugins(input?.browserBundlePlugins)
|
|
24
|
+
browserBundlePlugins: mergeEcoBuildPlugins(input?.browserBundlePlugins),
|
|
25
|
+
browserRuntimeManifest: mergeBrowserRuntimeManifests(input?.browserRuntimeManifest)
|
|
17
26
|
};
|
|
18
27
|
}
|
|
28
|
+
function getBrowserRuntimeManifest(manifest) {
|
|
29
|
+
return manifest.browserRuntimeManifest ?? createBrowserRuntimeManifest();
|
|
30
|
+
}
|
|
19
31
|
function getServerBuildPlugins(manifest) {
|
|
20
32
|
return mergeEcoBuildPlugins(manifest.loaderPlugins, manifest.runtimePlugins);
|
|
21
33
|
}
|
|
22
34
|
function getBrowserBuildPlugins(manifest) {
|
|
23
|
-
|
|
35
|
+
const runtimeRewritePlugin = createBrowserRuntimeImportRewritePlugin({
|
|
36
|
+
name: DEFAULT_BROWSER_RUNTIME_IMPORT_REWRITE_PLUGIN_NAME,
|
|
37
|
+
manifest: getBrowserRuntimeManifest(manifest)
|
|
38
|
+
});
|
|
39
|
+
return mergeEcoBuildPlugins(
|
|
40
|
+
manifest.loaderPlugins,
|
|
41
|
+
manifest.runtimePlugins,
|
|
42
|
+
runtimeRewritePlugin ? [runtimeRewritePlugin] : [],
|
|
43
|
+
manifest.browserBundlePlugins
|
|
44
|
+
);
|
|
24
45
|
}
|
|
25
46
|
export {
|
|
26
47
|
createAppBuildManifest,
|
|
27
48
|
getBrowserBuildPlugins,
|
|
49
|
+
getBrowserRuntimeManifest,
|
|
28
50
|
getServerBuildPlugins,
|
|
29
51
|
mergeEcoBuildPlugins
|
|
30
52
|
};
|
|
@@ -12,7 +12,7 @@ export declare class EsbuildBuildAdapter implements BuildAdapter {
|
|
|
12
12
|
private getJavaScriptOutExtension;
|
|
13
13
|
private collectWorkspaceNodePaths;
|
|
14
14
|
private getFallbackNodePaths;
|
|
15
|
-
private
|
|
15
|
+
private rewriteBrowserRuntimeImportsInOutputs;
|
|
16
16
|
private escapeRegExp;
|
|
17
17
|
private getPluginsForBuild;
|
|
18
18
|
private normalizeEsbuildLoader;
|
|
@@ -3,7 +3,10 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { fileSystem } from "@ecopages/file-system";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
collectBrowserRuntimeImportRewriteMap,
|
|
8
|
+
rewriteBrowserRuntimeImports
|
|
9
|
+
} from "./browser-runtime-import-rewrite-plugin.js";
|
|
7
10
|
const moduleRequire = createRequire(import.meta.url);
|
|
8
11
|
const esbuildPath = moduleRequire.resolve("esbuild");
|
|
9
12
|
const workspaceNodePathsCache = /* @__PURE__ */ new Map();
|
|
@@ -93,12 +96,12 @@ class EsbuildBuildAdapter {
|
|
|
93
96
|
}
|
|
94
97
|
return Array.from(nodePaths);
|
|
95
98
|
}
|
|
96
|
-
|
|
99
|
+
rewriteBrowserRuntimeImportsInOutputs(result, plugins) {
|
|
97
100
|
if (!result.success || result.outputs.length === 0) {
|
|
98
101
|
return result;
|
|
99
102
|
}
|
|
100
|
-
const
|
|
101
|
-
if (
|
|
103
|
+
const specifierMap = collectBrowserRuntimeImportRewriteMap(plugins);
|
|
104
|
+
if (specifierMap.size === 0) {
|
|
102
105
|
return result;
|
|
103
106
|
}
|
|
104
107
|
for (const output of result.outputs) {
|
|
@@ -106,7 +109,7 @@ class EsbuildBuildAdapter {
|
|
|
106
109
|
continue;
|
|
107
110
|
}
|
|
108
111
|
const code = readFileSync(output.path, "utf-8");
|
|
109
|
-
const rewritten =
|
|
112
|
+
const rewritten = rewriteBrowserRuntimeImports(code, specifierMap, output.path);
|
|
110
113
|
if (rewritten !== code) {
|
|
111
114
|
writeFileSync(output.path, rewritten);
|
|
112
115
|
}
|
|
@@ -389,7 +392,7 @@ class EsbuildBuildAdapter {
|
|
|
389
392
|
}));
|
|
390
393
|
const logs = result.warnings.map((warning) => ({ message: warning.text }));
|
|
391
394
|
const dependencyGraph = this.extractDependencyGraph(result.metafile, contextRoot);
|
|
392
|
-
return this.
|
|
395
|
+
return this.rewriteBrowserRuntimeImportsInOutputs(
|
|
393
396
|
{
|
|
394
397
|
success: true,
|
|
395
398
|
logs,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { attachRuntimeSpecifierAliasMap } from "./runtime-specifier-aliases.js";
|
|
2
1
|
function toRuntimeSpecifierMap(specifierMap) {
|
|
3
2
|
return specifierMap instanceof Map ? specifierMap : new Map(Object.entries(specifierMap));
|
|
4
3
|
}
|
|
@@ -11,24 +10,21 @@ function createRuntimeSpecifierAliasPlugin(specifierMapInput, options) {
|
|
|
11
10
|
return null;
|
|
12
11
|
}
|
|
13
12
|
const filter = new RegExp(`^(${Array.from(specifierMap.keys()).map(escapeRegExp).join("|")})$`);
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
specifierMap
|
|
31
|
-
);
|
|
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
|
+
};
|
|
32
28
|
}
|
|
33
29
|
export {
|
|
34
30
|
createRuntimeSpecifierAliasPlugin
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { EcoBuildPlugin } from '../build/build-types.js';
|
|
2
|
+
import { type BrowserRuntimeManifest } from '../build/browser-runtime-manifest.js';
|
|
2
3
|
import type { EcoPagesAppConfig, IHmrManager } from '../types/internal-types.js';
|
|
3
4
|
import type { HmrStrategy } from '../hmr/hmr-strategy.js';
|
|
4
5
|
import type { EcoPagesElement } from '../types/public-types.js';
|
|
@@ -114,6 +115,15 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
|
|
|
114
115
|
* do not affect server bundles or static-page module generation.
|
|
115
116
|
*/
|
|
116
117
|
get browserBuildPlugins(): EcoBuildPlugin[];
|
|
118
|
+
/**
|
|
119
|
+
* Returns shared browser runtime asset declarations owned by this integration.
|
|
120
|
+
*
|
|
121
|
+
* @remarks
|
|
122
|
+
* Core seals these declarations into the app build manifest so app-owned browser
|
|
123
|
+
* bundle paths can rewrite manifest-owned imports even when a specific build
|
|
124
|
+
* request does not install an integration-local runtime rewrite plugin.
|
|
125
|
+
*/
|
|
126
|
+
get browserRuntimeManifest(): BrowserRuntimeManifest;
|
|
117
127
|
/**
|
|
118
128
|
* Creates the integration with static declaration-only configuration.
|
|
119
129
|
*
|
|
@@ -144,7 +154,7 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
|
|
|
144
154
|
* ```typescript
|
|
145
155
|
* getHmrStrategy(): HmrStrategy {
|
|
146
156
|
* const context = this.hmrManager!.getDefaultContext();
|
|
147
|
-
* return new ReactHmrStrategy({ context, pageMetadataCache,
|
|
157
|
+
* return new ReactHmrStrategy({ context, pageMetadataCache, runtimeManifest });
|
|
148
158
|
* }
|
|
149
159
|
* ```
|
|
150
160
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createBrowserRuntimeManifest } from "../build/browser-runtime-manifest.js";
|
|
1
2
|
import { AssetProcessingService } from "../services/assets/asset-processing-service/asset-processing.service.js";
|
|
2
3
|
import { deepMerge } from "../utils/deep-merge.js";
|
|
3
4
|
import { invariant } from "../utils/invariant.js";
|
|
@@ -36,6 +37,17 @@ class IntegrationPlugin {
|
|
|
36
37
|
get browserBuildPlugins() {
|
|
37
38
|
return [];
|
|
38
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Returns shared browser runtime asset declarations owned by this integration.
|
|
42
|
+
*
|
|
43
|
+
* @remarks
|
|
44
|
+
* Core seals these declarations into the app build manifest so app-owned browser
|
|
45
|
+
* bundle paths can rewrite manifest-owned imports even when a specific build
|
|
46
|
+
* request does not install an integration-local runtime rewrite plugin.
|
|
47
|
+
*/
|
|
48
|
+
get browserRuntimeManifest() {
|
|
49
|
+
return createBrowserRuntimeManifest();
|
|
50
|
+
}
|
|
39
51
|
/**
|
|
40
52
|
* Creates the integration with static declaration-only configuration.
|
|
41
53
|
*
|
|
@@ -25,6 +25,7 @@ export declare function createBrowserRuntimeScriptAsset(options: {
|
|
|
25
25
|
define?: Record<string, string>;
|
|
26
26
|
minify?: boolean;
|
|
27
27
|
external?: string[];
|
|
28
|
+
excludeAppBuildPlugins?: string[];
|
|
28
29
|
naming?: string;
|
|
29
30
|
plugins?: EcoBuildPlugin[];
|
|
30
31
|
};
|
|
@@ -48,6 +49,7 @@ export declare function createBrowserRuntimeModuleAsset(options: {
|
|
|
48
49
|
define?: Record<string, string>;
|
|
49
50
|
minify?: boolean;
|
|
50
51
|
external?: string[];
|
|
52
|
+
excludeAppBuildPlugins?: string[];
|
|
51
53
|
naming?: string;
|
|
52
54
|
plugins?: EcoBuildPlugin[];
|
|
53
55
|
};
|
|
@@ -10,6 +10,7 @@ import type { BrowserBundleExecutor } from '../services/assets/browser-bundle.se
|
|
|
10
10
|
import type { AssetDefinition, ProcessedAsset } from '../services/assets/asset-processing-service/assets.types.js';
|
|
11
11
|
import type { CacheStats, CacheStrategy } from '../services/cache/cache.types.js';
|
|
12
12
|
import type { InteractionEventsString as ScriptsInjectorInteractionEventsString } from '@ecopages/scripts-injector/types';
|
|
13
|
+
import type { EntrypointDependencyGraph } from '../services/runtime-state/entrypoint-dependency-graph.service.js';
|
|
13
14
|
export type { EcoPagesAppConfig } from './internal-types.js';
|
|
14
15
|
export type { EcoPageComponent } from '../eco/eco.types.js';
|
|
15
16
|
export type { ProcessedAsset } from '../services/assets/asset-processing-service/assets.types.js';
|
|
@@ -128,6 +129,10 @@ export interface DefaultHmrContext {
|
|
|
128
129
|
* Server-side module loader owned by the active app/runtime.
|
|
129
130
|
*/
|
|
130
131
|
importServerModule<T = unknown>(filePath: string | URL): Promise<T>;
|
|
132
|
+
/**
|
|
133
|
+
* Entrypoint dependency graph for selective HMR invalidation.
|
|
134
|
+
*/
|
|
135
|
+
getEntrypointDependencyGraph(): EntrypointDependencyGraph;
|
|
131
136
|
}
|
|
132
137
|
/**
|
|
133
138
|
* Represents an event broadcast to connected clients via the ClientBridge.
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { EcoBuildPlugin } from './build-types.js';
|
|
2
|
-
export declare function attachRuntimeSpecifierAliasMap(plugin: EcoBuildPlugin, specifierMap: ReadonlyMap<string, string>): EcoBuildPlugin;
|
|
3
|
-
export declare function getRuntimeSpecifierAliasMap(plugin: EcoBuildPlugin): ReadonlyMap<string, string> | undefined;
|
|
4
|
-
export declare function collectRuntimeSpecifierAliasMap(plugins: EcoBuildPlugin[] | undefined): ReadonlyMap<string, string>;
|
|
5
|
-
export declare function rewriteRuntimeSpecifierAliases(code: string, specifierMap: ReadonlyMap<string, string>): string;
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { parseSync } from "oxc-parser";
|
|
2
|
-
const RUNTIME_SPECIFIER_ALIAS_MAP = /* @__PURE__ */ Symbol.for("ecopages.runtimeSpecifierAliasMap");
|
|
3
|
-
function attachRuntimeSpecifierAliasMap(plugin, specifierMap) {
|
|
4
|
-
plugin[RUNTIME_SPECIFIER_ALIAS_MAP] = specifierMap;
|
|
5
|
-
return plugin;
|
|
6
|
-
}
|
|
7
|
-
function getRuntimeSpecifierAliasMap(plugin) {
|
|
8
|
-
return plugin[RUNTIME_SPECIFIER_ALIAS_MAP];
|
|
9
|
-
}
|
|
10
|
-
function collectRuntimeSpecifierAliasMap(plugins) {
|
|
11
|
-
const merged = /* @__PURE__ */ new Map();
|
|
12
|
-
for (const plugin of plugins ?? []) {
|
|
13
|
-
const specifierMap = getRuntimeSpecifierAliasMap(plugin);
|
|
14
|
-
if (!specifierMap) {
|
|
15
|
-
continue;
|
|
16
|
-
}
|
|
17
|
-
for (const [specifier, mappedPath] of specifierMap.entries()) {
|
|
18
|
-
if (!merged.has(specifier)) {
|
|
19
|
-
merged.set(specifier, mappedPath);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return merged;
|
|
24
|
-
}
|
|
25
|
-
function rewriteRuntimeSpecifierAliases(code, specifierMap) {
|
|
26
|
-
if (specifierMap.size === 0) {
|
|
27
|
-
return code;
|
|
28
|
-
}
|
|
29
|
-
const edits = [];
|
|
30
|
-
try {
|
|
31
|
-
const result = parseSync("runtime-alias-output.js", code, {
|
|
32
|
-
sourceType: "module",
|
|
33
|
-
lang: "js"
|
|
34
|
-
});
|
|
35
|
-
const queueReplacement = (source) => {
|
|
36
|
-
if (typeof source.value !== "string") {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const mappedPath = specifierMap.get(source.value);
|
|
40
|
-
if (!mappedPath) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const quote = code[source.start] === "'" ? "'" : '"';
|
|
44
|
-
edits.push({
|
|
45
|
-
start: source.start,
|
|
46
|
-
end: source.end,
|
|
47
|
-
replacement: `${quote}${mappedPath}${quote}`
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
const walk = (node) => {
|
|
51
|
-
if (!node || typeof node !== "object") {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (Array.isArray(node)) {
|
|
55
|
-
for (const child of node) {
|
|
56
|
-
walk(child);
|
|
57
|
-
}
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
const candidate = node;
|
|
61
|
-
if (candidate.type === "ImportDeclaration" || candidate.type === "ExportNamedDeclaration" || candidate.type === "ExportAllDeclaration") {
|
|
62
|
-
if (candidate.source) {
|
|
63
|
-
queueReplacement(candidate.source);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
if (candidate.type === "ImportExpression") {
|
|
67
|
-
const importNode = candidate;
|
|
68
|
-
if (importNode.source?.type === "StringLiteral" || importNode.source?.type === "Literal") {
|
|
69
|
-
queueReplacement(importNode.source);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
for (const value of Object.values(candidate)) {
|
|
73
|
-
walk(value);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
walk(result.program);
|
|
77
|
-
} catch {
|
|
78
|
-
return code;
|
|
79
|
-
}
|
|
80
|
-
if (edits.length === 0) {
|
|
81
|
-
return code;
|
|
82
|
-
}
|
|
83
|
-
edits.sort((left, right) => right.start - left.start);
|
|
84
|
-
let rewritten = code;
|
|
85
|
-
for (const edit of edits) {
|
|
86
|
-
rewritten = rewritten.slice(0, edit.start) + edit.replacement + rewritten.slice(edit.end);
|
|
87
|
-
}
|
|
88
|
-
return rewritten;
|
|
89
|
-
}
|
|
90
|
-
export {
|
|
91
|
-
attachRuntimeSpecifierAliasMap,
|
|
92
|
-
collectRuntimeSpecifierAliasMap,
|
|
93
|
-
getRuntimeSpecifierAliasMap,
|
|
94
|
-
rewriteRuntimeSpecifierAliases
|
|
95
|
-
};
|