@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,215 +0,0 @@
1
- import path from "node:path";
2
- import { existsSync, readFileSync } from "node:fs";
3
- import { createRequire } from "node:module";
4
- import { fileURLToPath, pathToFileURL } from "node:url";
5
- import { resolveInternalExecutionDir } from "../../utils/resolve-work-dir.js";
6
- function getAppRuntimeNodeModulesDir(appConfig) {
7
- return path.join(resolveInternalExecutionDir(appConfig), "node_modules");
8
- }
9
- function getPackageNameFromSpecifier(specifier) {
10
- if (specifier.startsWith("@")) {
11
- const [scope, name] = specifier.split("/");
12
- return `${scope}/${name}`;
13
- }
14
- return specifier.split("/")[0] ?? specifier;
15
- }
16
- function getNodeUnsupportedBuiltinError(specifier, importer) {
17
- return `Node bootstrap transpilation does not support Bun builtin specifier ${JSON.stringify(specifier)}${importer ? ` imported from ${importer}` : ""}.`;
18
- }
19
- function resolveSpecifier(specifier, parentPath) {
20
- try {
21
- return createRequire(parentPath).resolve(specifier);
22
- } catch {
23
- return fileURLToPath(import.meta.resolve(specifier, pathToFileURL(parentPath).href));
24
- }
25
- }
26
- function resolveFromCore(specifier) {
27
- return createRequire(import.meta.url).resolve(specifier);
28
- }
29
- function readPackageManifest(packageDir) {
30
- const packageJsonPath = path.join(packageDir, "package.json");
31
- if (!existsSync(packageJsonPath)) {
32
- return void 0;
33
- }
34
- try {
35
- return JSON.parse(readFileSync(packageJsonPath, "utf8"));
36
- } catch {
37
- return void 0;
38
- }
39
- }
40
- function findInstalledPackageDir(packageName, parentPath) {
41
- let currentPath = path.dirname(parentPath);
42
- const packageSegments = packageName.split("/");
43
- while (true) {
44
- const candidateDir = path.join(currentPath, "node_modules", ...packageSegments);
45
- if (existsSync(path.join(candidateDir, "package.json"))) {
46
- return candidateDir;
47
- }
48
- const nextPath = path.dirname(currentPath);
49
- if (nextPath === currentPath) {
50
- return void 0;
51
- }
52
- currentPath = nextPath;
53
- }
54
- }
55
- function resolvePackageExportTarget(packageDir, target) {
56
- if (typeof target === "string") {
57
- return path.resolve(packageDir, target);
58
- }
59
- if (Array.isArray(target)) {
60
- for (const candidate of target) {
61
- const resolvedTarget = resolvePackageExportTarget(packageDir, candidate);
62
- if (resolvedTarget) {
63
- return resolvedTarget;
64
- }
65
- }
66
- return void 0;
67
- }
68
- if (!target || typeof target !== "object") {
69
- return void 0;
70
- }
71
- const record = target;
72
- return resolvePackageExportTarget(packageDir, record.import) ?? resolvePackageExportTarget(packageDir, record.default) ?? resolvePackageExportTarget(packageDir, record.require);
73
- }
74
- function shouldRewriteProjectImportMeta(filePath, projectDir) {
75
- const normalizedFilePath = path.normalize(filePath);
76
- const normalizedProjectDir = path.normalize(projectDir);
77
- return (normalizedFilePath === normalizedProjectDir || normalizedFilePath.startsWith(`${normalizedProjectDir}${path.sep}`)) && !normalizedFilePath.includes(`${path.sep}node_modules${path.sep}`);
78
- }
79
- function getLoaderForPath(filePath) {
80
- const extension = path.extname(filePath).toLowerCase();
81
- if (extension === ".tsx") return "tsx";
82
- if (extension === ".ts") return "ts";
83
- if (extension === ".jsx") return "jsx";
84
- return "js";
85
- }
86
- function resolveInstalledPackageTarget(specifier, parentPath) {
87
- const packageName = getPackageNameFromSpecifier(specifier);
88
- const packageDir = findInstalledPackageDir(packageName, parentPath);
89
- if (!packageDir) {
90
- return void 0;
91
- }
92
- const manifest = readPackageManifest(packageDir);
93
- if (!manifest) {
94
- return void 0;
95
- }
96
- const subpath = specifier === packageName ? "." : `./${specifier.slice(packageName.length + 1)}`;
97
- const exportsField = manifest.exports;
98
- if (exportsField !== void 0) {
99
- const exportsRecord = exportsField;
100
- const hasSubpathKeys = typeof exportsField === "object" && exportsField !== null && Object.keys(exportsRecord).some((key) => key.startsWith("."));
101
- const exportTarget = hasSubpathKeys ? resolvePackageExportTarget(packageDir, exportsRecord[subpath]) : subpath === "." ? resolvePackageExportTarget(packageDir, exportsField) : void 0;
102
- if (exportTarget && existsSync(exportTarget)) {
103
- return exportTarget;
104
- }
105
- }
106
- if (subpath !== ".") {
107
- return void 0;
108
- }
109
- const mainTarget = manifest.module ?? manifest.main ?? "index.js";
110
- const resolvedMainTarget = path.resolve(packageDir, mainTarget);
111
- return existsSync(resolvedMainTarget) ? resolvedMainTarget : void 0;
112
- }
113
- function findResolutionParent(importer, projectDir) {
114
- if (!importer || !path.isAbsolute(importer)) {
115
- return path.join(projectDir, "package.json");
116
- }
117
- let currentPath = path.dirname(importer);
118
- while (true) {
119
- const packageJsonPath = path.join(currentPath, "package.json");
120
- if (existsSync(packageJsonPath)) {
121
- return packageJsonPath;
122
- }
123
- const parentPath = path.dirname(currentPath);
124
- if (parentPath === currentPath) {
125
- return path.join(projectDir, "package.json");
126
- }
127
- currentPath = parentPath;
128
- }
129
- }
130
- function resolveNodeBootstrapDependency(args, options) {
131
- if (args.path.startsWith("./") || args.path.startsWith("../") || args.path.startsWith("@/") || args.path.startsWith("/") || args.path.startsWith("node:")) {
132
- return void 0;
133
- }
134
- const resolveParent = findResolutionParent(args.importer, options.projectDir);
135
- if (args.path.startsWith("@ecopages/")) {
136
- const packageName = getPackageNameFromSpecifier(args.path);
137
- const isBareWorkspacePackage = args.path === packageName;
138
- const installedResolvedPath = resolveInstalledPackageTarget(args.path, resolveParent);
139
- if (installedResolvedPath) {
140
- return { path: installedResolvedPath };
141
- }
142
- if (!isBareWorkspacePackage) {
143
- const resolvedSubpath = resolveSpecifier(args.path, resolveParent);
144
- return { path: resolvedSubpath };
145
- }
146
- let resolvedPath;
147
- try {
148
- resolvedPath = resolveFromCore(args.path);
149
- } catch {
150
- try {
151
- resolvedPath = resolveSpecifier(args.path, resolveParent);
152
- } catch {
153
- const candidatePath = path.join(options.projectDir, "node_modules", packageName);
154
- const candidatePackageJson = path.join(candidatePath, "package.json");
155
- if (existsSync(candidatePackageJson)) {
156
- return { path: args.path, external: true };
157
- }
158
- }
159
- }
160
- if (!resolvedPath) {
161
- return void 0;
162
- }
163
- if (resolvedPath.includes(`${path.sep}node_modules${path.sep}`)) {
164
- return {
165
- path: args.path,
166
- external: true
167
- };
168
- }
169
- return { path: resolvedPath };
170
- }
171
- return {
172
- path: args.path,
173
- external: true
174
- };
175
- }
176
- function createNodeBootstrapPlugin(options) {
177
- return {
178
- name: "node-bootstrap-plugin",
179
- setup(build) {
180
- build.onResolve({ filter: /^bun:/ }, (args) => {
181
- throw new Error(getNodeUnsupportedBuiltinError(args.path, args.importer));
182
- });
183
- build.onLoad({ filter: /\.[cm]?[jt]sx?$/ }, (args) => {
184
- if (!shouldRewriteProjectImportMeta(args.path, options.projectDir)) {
185
- return void 0;
186
- }
187
- const originalContents = readFileSync(args.path, "utf8");
188
- const contents = originalContents.replaceAll("import.meta.env", "process.env").replaceAll("import.meta.dirname", JSON.stringify(path.dirname(args.path))).replaceAll("import.meta.filename", JSON.stringify(args.path)).replaceAll("import.meta.dir", JSON.stringify(path.dirname(args.path))).replaceAll("import.meta.path", JSON.stringify(args.path));
189
- if (contents === originalContents) {
190
- return void 0;
191
- }
192
- return {
193
- contents,
194
- loader: getLoaderForPath(args.path)
195
- };
196
- });
197
- build.onResolve({ filter: /^[@A-Za-z0-9][^:]*$/ }, (args) => {
198
- return resolveNodeBootstrapDependency(args, options);
199
- });
200
- }
201
- };
202
- }
203
- function createAppNodeBootstrapPlugin(appConfig) {
204
- return createNodeBootstrapPlugin({
205
- projectDir: appConfig.rootDir,
206
- runtimeNodeModulesDir: getAppRuntimeNodeModulesDir(appConfig)
207
- });
208
- }
209
- export {
210
- createAppNodeBootstrapPlugin,
211
- createNodeBootstrapPlugin,
212
- getAppRuntimeNodeModulesDir,
213
- getNodeUnsupportedBuiltinError,
214
- resolveNodeBootstrapDependency
215
- };