@ecopages/core 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +3 -3
- package/src/adapters/node/create-app.d.ts +40 -11
- package/src/adapters/node/create-app.js +95 -69
- package/src/adapters/node/dev-session.js +0 -1
- package/src/adapters/node/http-request-bridge.d.ts +4 -0
- package/src/adapters/node/http-request-bridge.js +9 -1
- package/src/adapters/node/runtime-host.d.ts +28 -6
- package/src/adapters/node/runtime-host.js +35 -9
- package/src/adapters/node/server-adapter.d.ts +10 -35
- package/src/adapters/node/server-adapter.js +21 -58
- package/src/adapters/shared/hmr/hmr-manager.d.ts +21 -7
- package/src/adapters/shared/hmr/hmr-manager.js +58 -70
- package/src/adapters/shared/http/api-request-pipeline.d.ts +3 -12
- package/src/adapters/shared/http/api-request-pipeline.js +7 -7
- package/src/adapters/shared/http/dist-file-handler.d.ts +16 -0
- package/src/adapters/shared/http/dist-file-handler.js +172 -0
- package/src/adapters/shared/http/explicit-static-route-matcher.js +2 -1
- package/src/adapters/shared/http/fs-server-response-matcher.js +3 -2
- package/src/adapters/shared/runtime/bind-runtime-server.d.ts +5 -7
- package/src/adapters/shared/runtime/bind-runtime-server.js +8 -12
- package/src/adapters/shared/runtime/copy-runtime-public-dir.js +10 -9
- package/src/adapters/shared/runtime/port-manager.d.ts +8 -11
- package/src/adapters/shared/runtime/port-manager.js +19 -30
- package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +6 -9
- package/src/adapters/shared/runtime/runtime-server-lifecycle.js +2 -5
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +1 -3
- package/src/adapters/shared/runtime/server-request-pipeline.js +1 -5
- package/src/adapters/shared/runtime/server-static-builder.d.ts +3 -3
- package/src/adapters/shared/runtime/server-static-builder.js +3 -3
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +2 -1
- package/src/adapters/shared/ws/websocket-lifecycle.d.ts +5 -6
- package/src/adapters/shared/ws/websocket-lifecycle.js +1 -2
- package/src/assets/app-browser-client-build.js +1 -2
- package/src/assets/asset-processing-service/browser-runtime-entry-resolution.js +8 -8
- package/src/assets/asset-processing-service/browser-runtime-entry.factory.js +4 -4
- package/src/assets/asset-processing-service/processors/script/file-script.processor.d.ts +12 -8
- package/src/assets/asset-processing-service/processors/script/file-script.processor.js +36 -16
- package/src/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +11 -6
- package/src/assets/browser-asset-output.d.ts +19 -0
- package/src/assets/browser-asset-output.js +30 -0
- package/src/assets/hashed-browser-asset.d.ts +8 -6
- package/src/assets/hashed-browser-asset.js +8 -6
- package/src/build/build-adapter.d.ts +2 -19
- package/src/build/build-adapter.js +0 -21
- package/src/build/build-graph.js +2 -2
- package/src/build/cache/cache-keys.d.ts +0 -3
- package/src/build/cache/cache-keys.js +0 -14
- package/src/build/cache/pages-unified-graph-build.js +2 -17
- package/src/build/contracts/build-contracts.d.ts +0 -3
- package/src/build/preserve-import-meta-transform.js +2 -2
- package/src/build/rolldown/app-package-declarations.js +3 -3
- package/src/build/rolldown/rolldown-adapter-helpers.js +3 -3
- package/src/build/rolldown/rolldown-build-adapter.d.ts +0 -1
- package/src/build/rolldown/rolldown-build-adapter.js +1 -2
- package/src/build/rolldown/rolldown-build-invocation-metrics.d.ts +1 -2
- package/src/build/rolldown/rolldown-build-invocation-metrics.js +5 -12
- package/src/build/rolldown/server-side-css-shim-plugin.js +3 -3
- package/src/build/runtime/build-queue.d.ts +8 -13
- package/src/build/runtime/build-queue.js +6 -17
- package/src/build/server/app-module-loader.service.d.ts +1 -1
- package/src/build/server/app-module-loader.service.js +0 -2
- package/src/build/server/page-module-import.service.d.ts +2 -3
- package/src/build/server/page-module-import.service.js +3 -4
- package/src/build/server-bundle-deploy-manifest.d.ts +5 -0
- package/src/build/server-bundle-deploy-manifest.js +15 -1
- package/src/build/server-bundle-publication.js +4 -5
- package/src/build.d.ts +2 -2
- package/src/build.js +2 -2
- package/src/config/assembly/app-runtime.d.ts +2 -2
- package/src/config/assembly/app-runtime.js +2 -2
- package/src/config/assembly/finalize-config.d.ts +4 -4
- package/src/config/assembly/finalize-config.js +4 -5
- package/src/config/config-module-files.js +2 -3
- package/src/config/internal-types.d.ts +0 -7
- package/src/config/user-config-types.d.ts +0 -4
- package/src/diagnostics/request-pipeline-metrics.d.ts +3 -3
- package/src/diagnostics/request-pipeline-metrics.js +4 -4
- package/src/diagnostics/startup-trace.js +2 -5
- package/src/errors/http-error.d.ts +2 -2
- package/src/errors/http-error.js +4 -4
- package/src/hmr/client/hmr-runtime.js +16 -7
- package/src/hmr/client/module-update.d.ts +7 -0
- package/src/hmr/client/module-update.js +21 -4
- package/src/hmr/hmr-strategy.d.ts +0 -3
- package/src/hmr/hmr-strategy.js +0 -3
- package/src/hmr/strategies/js-hmr-strategy.d.ts +2 -3
- package/src/hmr/strategies/js-hmr-strategy.js +3 -6
- package/src/html-pages/html-page-module-scripts.js +4 -3
- package/src/html-pages/html-page-renderer.js +2 -3
- package/src/plugins/alias-resolver-cache.d.ts +4 -3
- package/src/plugins/alias-resolver-cache.js +4 -3
- package/src/plugins/component-import-discovery.js +4 -4
- package/src/plugins/eco-component-meta-plugin.d.ts +10 -1
- package/src/plugins/eco-component-meta-plugin.js +66 -10
- package/src/plugins/foreign-jsx-override-plugin.js +4 -3
- package/src/plugins/tsconfig-import-resolver.js +12 -12
- package/src/route-renderer/error-pages/default-error-pages.js +2 -1
- package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -1
- package/src/route-renderer/orchestration/foreign-child/render-session.d.ts +0 -1
- package/src/route-renderer/orchestration/integration-renderer.d.ts +10 -5
- package/src/route-renderer/orchestration/integration-renderer.js +13 -14
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -23
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +0 -29
- package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph.service.js +10 -32
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +2 -2
- package/src/route-renderer/page-loading/page-dependency-bundling.js +5 -5
- package/src/route-renderer/page-loading/page-module-loader.js +1 -1
- package/src/route-renderer/route-renderer.d.ts +2 -5
- package/src/route-renderer/route-renderer.js +2 -4
- package/src/router/client/link-navigation-policy.d.ts +4 -1
- package/src/router/client/link-navigation-policy.js +20 -6
- package/src/router/server/route-registry.d.ts +0 -1
- package/src/router/server/route-registry.js +3 -13
- package/src/router/server/segment-path-matcher.d.ts +12 -0
- package/src/router/server/segment-path-matcher.js +30 -0
- package/src/static-site-generator/static-site-generator.d.ts +0 -5
- package/src/static-site-generator/static-site-generator.js +2 -15
- package/src/types/contracts.d.ts +17 -27
- package/src/types/public-types.d.ts +1 -1
- package/src/utils/format-error-chain.d.ts +9 -0
- package/src/utils/format-error-chain.js +20 -0
- package/src/utils/invariant.d.ts +6 -1
- package/src/utils/invariant.js +7 -2
- package/src/watchers/project-watcher.d.ts +20 -1
- package/src/watchers/project-watcher.js +40 -9
- package/src/watchers/workspace-package-watch-roots.js +5 -5
- package/src/adapters/README.md +0 -58
- package/src/adapters/shared/hmr/hmr-manager.test-helpers.d.ts +0 -28
- package/src/adapters/shared/hmr/hmr-manager.test-helpers.js +0 -53
- package/src/adapters/shared/runtime/runtime-host.d.ts +0 -15
- package/src/adapters/shared/runtime/runtime-host.js +0 -1
- package/src/assets/README.md +0 -35
- package/src/build/README.md +0 -298
- package/src/build/server/README.md +0 -50
- package/src/cache/README.md +0 -5
- package/src/client/README.md +0 -5
- package/src/client/navigation-scripts/navigation-scripts.test.browser.d.ts +0 -1
- package/src/client/navigation-scripts/navigation-scripts.test.browser.js +0 -111
- package/src/client/scroll.test.browser.d.ts +0 -1
- package/src/client/scroll.test.browser.js +0 -31
- package/src/client/view-transitions.test.browser.d.ts +0 -1
- package/src/client/view-transitions.test.browser.js +0 -53
- package/src/config/README.md +0 -58
- package/src/config/constants.d.ts +0 -1
- package/src/config/constants.js +0 -1
- package/src/dev/README.md +0 -61
- package/src/dev/invalidation/README.md +0 -11
- package/src/dev-toolbar/README.md +0 -66
- package/src/diagnostics/README.md +0 -11
- package/src/eco/README.md +0 -776
- package/src/errors/README.md +0 -5
- package/src/global/README.md +0 -5
- package/src/hmr/README.md +0 -64
- package/src/hmr/client/build-error-overlay.test.browser.d.ts +0 -1
- package/src/hmr/client/build-error-overlay.test.browser.js +0 -48
- package/src/hmr/client/hmr-runtime.test.browser.d.ts +0 -1
- package/src/hmr/client/hmr-runtime.test.browser.js +0 -32
- package/src/hmr/entrypoint-dependency-graph.d.ts +0 -12
- package/src/hmr/entrypoint-dependency-graph.js +0 -27
- package/src/hmr/hmr-file-change-prep.d.ts +0 -9
- package/src/hmr/hmr-file-change-prep.js +0 -11
- package/src/html/README.md +0 -15
- package/src/html-pages/README.md +0 -104
- package/src/islands/README.md +0 -44
- package/src/page-cache/README.md +0 -17
- package/src/plugins/README.md +0 -53
- package/src/route-renderer/GRAPH.md +0 -142
- package/src/route-renderer/README.md +0 -160
- package/src/route-renderer/error-pages/README.md +0 -11
- package/src/route-renderer/orchestration/custom-element-scripts/README.md +0 -15
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.d.ts +0 -39
- package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +0 -94
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.d.ts +0 -35
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.test-fixtures.js +0 -69
- package/src/router/README.md +0 -160
- package/src/router/client/link-intent.test.browser.d.ts +0 -1
- package/src/router/client/link-intent.test.browser.js +0 -33
- package/src/router/client/link-navigation-policy.test.browser.d.ts +0 -1
- package/src/router/client/link-navigation-policy.test.browser.js +0 -142
- package/src/router/client/navigation-commit.test.browser.d.ts +0 -1
- package/src/router/client/navigation-commit.test.browser.js +0 -116
- package/src/router/client/navigation-document.test.browser.d.ts +0 -1
- package/src/router/client/navigation-document.test.browser.js +0 -77
- package/src/router/client/navigation-head.test.browser.d.ts +0 -1
- package/src/router/client/navigation-head.test.browser.js +0 -101
- package/src/router/client/navigation-lifecycle.test.browser.d.ts +0 -1
- package/src/router/client/navigation-lifecycle.test.browser.js +0 -97
- package/src/router/client/navigation-view-transition.test.browser.d.ts +0 -1
- package/src/router/client/navigation-view-transition.test.browser.js +0 -189
- package/src/router/client/staged-stylesheets.test-fixtures.d.ts +0 -18
- package/src/router/client/staged-stylesheets.test-fixtures.js +0 -31
- package/src/static-site-generator/README.md +0 -67
- package/src/static-site-generator/static-site-generator.test-utils.d.ts +0 -2
- package/src/static-site-generator/static-site-generator.test-utils.js +0 -41
- package/src/types/README.md +0 -5
- package/src/utils/README.md +0 -7
- package/src/validation/README.md +0 -9
- package/src/watchers/README.md +0 -15
- package/src/watchers/project-watcher.test-helpers.d.ts +0 -60
- package/src/watchers/project-watcher.test-helpers.js +0 -108
|
@@ -176,12 +176,5 @@ export type EcoPagesAppConfig = {
|
|
|
176
176
|
*/
|
|
177
177
|
package?: string;
|
|
178
178
|
};
|
|
179
|
-
/**
|
|
180
|
-
* Experimental features.
|
|
181
|
-
*/
|
|
182
|
-
experimental?: {
|
|
183
|
-
/** Escape hatch for short-lived private toggles. No validation or IntelliSense. */
|
|
184
|
-
unsafe?: Record<string, unknown>;
|
|
185
|
-
};
|
|
186
179
|
};
|
|
187
180
|
export type { ClientBridgeEvent, DefaultHmrContext, HmrFileChangeOptions, IHmrManager, IClientBridge, } from '../types/contracts.js';
|
|
@@ -125,10 +125,6 @@ export type EcoPagesUserConfig = {
|
|
|
125
125
|
* Development toolbar configuration and toggle options.
|
|
126
126
|
*/
|
|
127
127
|
devToolbar?: EcoPagesAppConfig['devToolbar'];
|
|
128
|
-
/**
|
|
129
|
-
* Experimental runtime or compiler feature flags.
|
|
130
|
-
*/
|
|
131
|
-
experimental?: EcoPagesAppConfig['experimental'];
|
|
132
128
|
};
|
|
133
129
|
/** Produces fresh plugin instances when one config module creates multiple apps in a process. */
|
|
134
130
|
export type EcoPagesUserConfigFactory = () => EcoPagesUserConfig;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Benchmarks and structural invariant tests read the snapshot via
|
|
7
7
|
* {@link getRequestPipelineMetricsSnapshot}.
|
|
8
8
|
*/
|
|
9
|
-
export type PageModuleLoadOutcome = 'import-cache-hit' | '
|
|
9
|
+
export type PageModuleLoadOutcome = 'import-cache-hit' | 'route-module-cache-hit' | 'cold-build' | 'host-loader' | 'unified-graph';
|
|
10
10
|
export type RouteRenderPhase = 'resolve-route-inputs' | 'ownership-validation' | 'resolve-dependencies' | 'page-browser-graph' | 'render-body' | 'transform-response';
|
|
11
11
|
export type RouteRenderPhaseRecord = {
|
|
12
12
|
count: number;
|
|
@@ -19,7 +19,7 @@ export type RequestPipelineMetricsSnapshot = {
|
|
|
19
19
|
pageModuleBuilds: number;
|
|
20
20
|
pageModuleCacheHits: number;
|
|
21
21
|
hostLoaderLoads: number;
|
|
22
|
-
|
|
22
|
+
routeModuleCacheHits: number;
|
|
23
23
|
routeModuleArtifacts: number;
|
|
24
24
|
mdxTransforms: number;
|
|
25
25
|
collectionBuilds: number;
|
|
@@ -30,7 +30,7 @@ export type RequestPipelineMetricsState = {
|
|
|
30
30
|
pageModuleBuilds: number;
|
|
31
31
|
pageModuleCacheHits: number;
|
|
32
32
|
hostLoaderLoads: number;
|
|
33
|
-
|
|
33
|
+
routeModuleCacheHits: number;
|
|
34
34
|
routeModuleArtifacts: number;
|
|
35
35
|
mdxTransforms: number;
|
|
36
36
|
collectionBuilds: number;
|
|
@@ -15,7 +15,7 @@ export function createRequestPipelineMetricsState() {
|
|
|
15
15
|
pageModuleBuilds: 0,
|
|
16
16
|
pageModuleCacheHits: 0,
|
|
17
17
|
hostLoaderLoads: 0,
|
|
18
|
-
|
|
18
|
+
routeModuleCacheHits: 0,
|
|
19
19
|
routeModuleArtifacts: 0,
|
|
20
20
|
mdxTransforms: 0,
|
|
21
21
|
collectionBuilds: 0,
|
|
@@ -39,8 +39,8 @@ export function recordPageModuleLoad(state, outcome, artifactCount = 0) {
|
|
|
39
39
|
case 'import-cache-hit':
|
|
40
40
|
state.pageModuleCacheHits += 1;
|
|
41
41
|
break;
|
|
42
|
-
case '
|
|
43
|
-
state.
|
|
42
|
+
case 'route-module-cache-hit':
|
|
43
|
+
state.routeModuleCacheHits += 1;
|
|
44
44
|
break;
|
|
45
45
|
case 'cold-build':
|
|
46
46
|
state.pageModuleBuilds += 1;
|
|
@@ -101,7 +101,7 @@ export function getRequestPipelineMetricsSnapshot(state) {
|
|
|
101
101
|
pageModuleBuilds: state.pageModuleBuilds,
|
|
102
102
|
pageModuleCacheHits: state.pageModuleCacheHits,
|
|
103
103
|
hostLoaderLoads: state.hostLoaderLoads,
|
|
104
|
-
|
|
104
|
+
routeModuleCacheHits: state.routeModuleCacheHits,
|
|
105
105
|
routeModuleArtifacts: state.routeModuleArtifacts,
|
|
106
106
|
mdxTransforms: state.mdxTransforms,
|
|
107
107
|
collectionBuilds: state.collectionBuilds,
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { mkdirSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
1
|
import { fileSystem } from '@ecopages/file-system';
|
|
4
2
|
import { resolveBuildParallelism } from '../build/build-parallelism.js';
|
|
5
3
|
import { getProcessRuntime } from '../utils/runtime.js';
|
|
@@ -133,7 +131,7 @@ class StartupTrace {
|
|
|
133
131
|
for (const output of outputs) {
|
|
134
132
|
try {
|
|
135
133
|
if (fileSystem.exists(output.path)) {
|
|
136
|
-
this.firstRequestClientBytes +=
|
|
134
|
+
this.firstRequestClientBytes += fileSystem.stat(output.path).size;
|
|
137
135
|
}
|
|
138
136
|
}
|
|
139
137
|
catch {
|
|
@@ -210,8 +208,7 @@ class StartupTrace {
|
|
|
210
208
|
return;
|
|
211
209
|
}
|
|
212
210
|
const report = this.createReport();
|
|
213
|
-
|
|
214
|
-
writeFileSync(outputPath, JSON.stringify(report, null, 2), 'utf-8');
|
|
211
|
+
fileSystem.write(outputPath, JSON.stringify(report, null, 2));
|
|
215
212
|
}
|
|
216
213
|
createReport() {
|
|
217
214
|
const phases = {};
|
|
@@ -13,7 +13,7 @@ export interface HttpErrorJson {
|
|
|
13
13
|
export declare class HttpError extends Error {
|
|
14
14
|
readonly status: number;
|
|
15
15
|
readonly details?: HttpErrorDetails;
|
|
16
|
-
constructor(status: number, message: string, details?: HttpErrorDetails);
|
|
16
|
+
constructor(status: number, message: string, details?: HttpErrorDetails, options?: ErrorOptions);
|
|
17
17
|
/**
|
|
18
18
|
* Detects HttpError across bundle boundaries where `instanceof` can fail.
|
|
19
19
|
*
|
|
@@ -35,5 +35,5 @@ export declare class HttpError extends Error {
|
|
|
35
35
|
static Forbidden(message?: string): HttpError;
|
|
36
36
|
static NotFound(message?: string): HttpError;
|
|
37
37
|
static Conflict(message?: string, details?: HttpErrorDetails): HttpError;
|
|
38
|
-
static InternalServerError(message?: string): HttpError;
|
|
38
|
+
static InternalServerError(message?: string, options?: ErrorOptions): HttpError;
|
|
39
39
|
}
|
package/src/errors/http-error.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
export class HttpError extends Error {
|
|
6
6
|
status;
|
|
7
7
|
details;
|
|
8
|
-
constructor(status, message, details) {
|
|
9
|
-
super(message);
|
|
8
|
+
constructor(status, message, details, options) {
|
|
9
|
+
super(message, options);
|
|
10
10
|
this.name = 'HttpError';
|
|
11
11
|
this.status = status;
|
|
12
12
|
this.details = details;
|
|
@@ -61,7 +61,7 @@ export class HttpError extends Error {
|
|
|
61
61
|
static Conflict(message = 'Conflict', details) {
|
|
62
62
|
return new HttpError(409, message, details);
|
|
63
63
|
}
|
|
64
|
-
static InternalServerError(message = 'Internal Server Error') {
|
|
65
|
-
return new HttpError(500, message);
|
|
64
|
+
static InternalServerError(message = 'Internal Server Error', options) {
|
|
65
|
+
return new HttpError(500, message, undefined, options);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -50,13 +50,7 @@ import { resetBuildErrors, reportBuildError } from './build-error-presentation.j
|
|
|
50
50
|
break;
|
|
51
51
|
case 'layout-update': {
|
|
52
52
|
await waitForNavigationToSettle(navigationRuntime);
|
|
53
|
-
|
|
54
|
-
clearCache: true,
|
|
55
|
-
moduleUrl: getActiveHmrModuleUrl(),
|
|
56
|
-
})) {
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
location.reload();
|
|
53
|
+
await reloadPage();
|
|
60
54
|
break;
|
|
61
55
|
}
|
|
62
56
|
case 'error':
|
|
@@ -83,8 +77,23 @@ import { resetBuildErrors, reportBuildError } from './build-error-presentation.j
|
|
|
83
77
|
reloadCurrentPage: async (request) => Boolean(await navigationRuntime.reloadCurrentPage(request)),
|
|
84
78
|
importModule: (url) => import(url),
|
|
85
79
|
waitForSettled: async () => waitForNavigationToSettle(navigationRuntime),
|
|
80
|
+
reloadPage,
|
|
86
81
|
}, timestamp);
|
|
87
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* @remarks
|
|
85
|
+
* Prefers a soft reload by the navigation owner and falls back to a full document reload when none handles it.
|
|
86
|
+
*/
|
|
87
|
+
async function reloadPage() {
|
|
88
|
+
const navigationRuntime = getEcoNavigationRuntime(window);
|
|
89
|
+
const handled = await navigationRuntime.reloadCurrentPage({
|
|
90
|
+
clearCache: true,
|
|
91
|
+
moduleUrl: getActiveHmrModuleUrl(),
|
|
92
|
+
});
|
|
93
|
+
if (!handled) {
|
|
94
|
+
location.reload();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
88
97
|
function getActiveHmrModuleUrl() {
|
|
89
98
|
return resolveActiveModuleUrl(window.__ECO_PAGES__?.hmrHandlers ?? {}, window.__ECO_PAGES__?.page?.module);
|
|
90
99
|
}
|
|
@@ -8,6 +8,13 @@ export type ApplyModuleUpdateContext = {
|
|
|
8
8
|
}) => Promise<boolean>;
|
|
9
9
|
importModule: (url: string) => Promise<unknown>;
|
|
10
10
|
waitForSettled: () => Promise<void>;
|
|
11
|
+
reloadPage: () => Promise<void>;
|
|
11
12
|
};
|
|
12
13
|
export declare function resolveActiveModuleUrl(handlers: HmrModuleHandlers, pageModule?: string): string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* @remarks
|
|
16
|
+
* A hot update that cannot be applied leaves the page running stale modules, so every failure path ends in
|
|
17
|
+
* `reloadPage`: a handler or import that throws, an active page module the navigation owner does not reload, and a
|
|
18
|
+
* module without a handler. Thrown errors are still logged.
|
|
19
|
+
*/
|
|
13
20
|
export declare function applyModuleUpdate(path: string, context: ApplyModuleUpdateContext, timestamp?: number): Promise<void>;
|
|
@@ -15,25 +15,42 @@ export function resolveActiveModuleUrl(handlers, pageModule) {
|
|
|
15
15
|
}
|
|
16
16
|
return handlerPaths[handlerPaths.length - 1];
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* @remarks
|
|
20
|
+
* A hot update that cannot be applied leaves the page running stale modules, so every failure path ends in
|
|
21
|
+
* `reloadPage`: a handler or import that throws, an active page module the navigation owner does not reload, and a
|
|
22
|
+
* module without a handler. Thrown errors are still logged.
|
|
23
|
+
*/
|
|
18
24
|
export async function applyModuleUpdate(path, context, timestamp) {
|
|
19
25
|
const basePath = stripModuleUrlQuery(path);
|
|
20
26
|
const url = withModuleCacheBust(basePath, timestamp);
|
|
21
27
|
const handlers = context.getHandlers();
|
|
22
28
|
await context.waitForSettled();
|
|
29
|
+
try {
|
|
30
|
+
if (await applyHotUpdate(basePath, url, handlers, context)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.error(`[ecopages] HMR update failed for ${basePath}:`, error);
|
|
36
|
+
}
|
|
37
|
+
await context.reloadPage();
|
|
38
|
+
}
|
|
39
|
+
async function applyHotUpdate(basePath, url, handlers, context) {
|
|
23
40
|
const handler = handlers?.[basePath];
|
|
24
41
|
if (handler) {
|
|
25
42
|
await handler(url);
|
|
26
|
-
return;
|
|
43
|
+
return true;
|
|
27
44
|
}
|
|
28
45
|
if (isDevTransformModuleUrl(basePath)) {
|
|
29
46
|
const activePageModule = context.getActivePageModule?.();
|
|
30
47
|
const isActivePageModule = activePageModule !== undefined && stripModuleUrlQuery(activePageModule) === basePath;
|
|
31
48
|
if (isActivePageModule) {
|
|
32
|
-
|
|
33
|
-
return;
|
|
49
|
+
return context.reloadCurrentPage({ clearCache: false, moduleUrl: url });
|
|
34
50
|
}
|
|
35
51
|
await context.importModule(url);
|
|
36
|
-
return;
|
|
52
|
+
return true;
|
|
37
53
|
}
|
|
38
54
|
console.warn(`[ecopages] No HMR handler for module update: ${basePath}`);
|
|
55
|
+
return false;
|
|
39
56
|
}
|
|
@@ -51,9 +51,6 @@ export declare const HmrStrategyType: {
|
|
|
51
51
|
readonly FALLBACK: 0;
|
|
52
52
|
};
|
|
53
53
|
export type HmrStrategyType = (typeof HmrStrategyType)[keyof typeof HmrStrategyType];
|
|
54
|
-
/**
|
|
55
|
-
* Represents an action to be taken after processing a file change.
|
|
56
|
-
*/
|
|
57
54
|
/**
|
|
58
55
|
* Base class for HMR strategies.
|
|
59
56
|
*
|
package/src/hmr/hmr-strategy.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* JavaScript HMR Strategy
|
|
3
3
|
*
|
|
4
4
|
* Handles hot module replacement for JavaScript and TypeScript entrypoints.
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
5
|
+
* Decides whether the browser can hot-accept the change or must reload; `HmrManager`
|
|
6
|
+
* has already invalidated the affected dev-transform modules.
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
@@ -29,7 +29,6 @@ export interface JsHmrContext extends HmrRegisteredEntrypointsContext {
|
|
|
29
29
|
* dependency changes.
|
|
30
30
|
*/
|
|
31
31
|
shouldProcessEntrypoint?(entrypointPath: string): boolean;
|
|
32
|
-
invalidateDevTransformSource?(sourcePath: string): void;
|
|
33
32
|
consumeRegisteredScriptReloadRequired?(filePath: string): boolean;
|
|
34
33
|
}
|
|
35
34
|
/**
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* JavaScript HMR Strategy
|
|
3
3
|
*
|
|
4
4
|
* Handles hot module replacement for JavaScript and TypeScript entrypoints.
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
5
|
+
* Decides whether the browser can hot-accept the change or must reload; `HmrManager`
|
|
6
|
+
* has already invalidated the affected dev-transform modules.
|
|
7
7
|
*
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
@@ -11,7 +11,6 @@ import path from 'node:path';
|
|
|
11
11
|
import { HmrStrategy, HmrStrategyType } from '../hmr-strategy.js';
|
|
12
12
|
import { appLogger } from '../../global/app-logger.js';
|
|
13
13
|
import { isRegisteredDevTransformEntrypoint, isRegisteredScriptEntrypoint } from '../hmr-entrypoint-output.js';
|
|
14
|
-
import { isDevTransformModuleUrl } from '../hmr-asset-paths.js';
|
|
15
14
|
/**
|
|
16
15
|
* Strategy for handling JavaScript/TypeScript file changes with hot reloading.
|
|
17
16
|
*/
|
|
@@ -65,11 +64,9 @@ export class JsHmrStrategy extends HmrStrategy {
|
|
|
65
64
|
for (const entrypoint of buildableEntrypoints) {
|
|
66
65
|
const resolvedEntrypoint = path.resolve(entrypoint);
|
|
67
66
|
const outputUrl = watchedFiles.get(resolvedEntrypoint);
|
|
68
|
-
if (!outputUrl
|
|
69
|
-
appLogger.debug(`[JsHmrStrategy] Skipping non-dev-transform entrypoint ${resolvedEntrypoint}: ${outputUrl ?? 'unregistered'}`);
|
|
67
|
+
if (!outputUrl) {
|
|
70
68
|
continue;
|
|
71
69
|
}
|
|
72
|
-
this.context.invalidateDevTransformSource?.(resolvedEntrypoint);
|
|
73
70
|
if (isRegisteredScriptEntrypoint(registeredEntrypoints, resolvedEntrypoint)) {
|
|
74
71
|
if (this.context.consumeRegisteredScriptReloadRequired?.(resolvedEntrypoint)) {
|
|
75
72
|
devTransformReloadRequired = true;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { contentHash } from '../utils/content-hash.js';
|
|
2
|
-
import { readdirSync, realpathSync } from 'node:fs';
|
|
3
2
|
import { getBuildEntryOutput } from '../build/build-graph.js';
|
|
4
3
|
import { assertBuildSucceeded } from '../build/build-log.js';
|
|
5
4
|
import { createRequire } from 'node:module';
|
|
@@ -200,7 +199,9 @@ export function scanModuleScript(appConfig, script) {
|
|
|
200
199
|
function listHtmlFiles(appConfig) {
|
|
201
200
|
const { pagesDir, htmlTemplatePath } = appConfig.absolutePaths;
|
|
202
201
|
const pages = fileSystem.exists(pagesDir)
|
|
203
|
-
?
|
|
202
|
+
? fileSystem
|
|
203
|
+
.readdir(pagesDir, { recursive: true })
|
|
204
|
+
.map((entry) => entry.name)
|
|
204
205
|
.filter((name) => name.endsWith('.html'))
|
|
205
206
|
.map((name) => path.join(pagesDir, name))
|
|
206
207
|
.sort()
|
|
@@ -287,7 +288,7 @@ async function buildModuleScripts(appConfig, referencedScripts) {
|
|
|
287
288
|
for (const script of scripts) {
|
|
288
289
|
const output = getBuildEntryOutput(result, script, appConfig.rootDir);
|
|
289
290
|
if (output)
|
|
290
|
-
urls.set(
|
|
291
|
+
urls.set(fileSystem.realpath(script), `/${path.relative(distDir, output).split(path.sep).join('/')}`);
|
|
291
292
|
}
|
|
292
293
|
return urls;
|
|
293
294
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { realpathSync } from 'node:fs';
|
|
2
1
|
import path from 'node:path';
|
|
3
2
|
import { fileSystem } from '@ecopages/file-system';
|
|
4
3
|
import { AssetFactory } from '../assets/asset-processing-service/asset.factory.js';
|
|
@@ -237,7 +236,7 @@ export class HtmlPageRenderer extends StringMarkupRenderer {
|
|
|
237
236
|
if (asset.kind === 'module-script') {
|
|
238
237
|
const hmr = this.assetProcessingService.getHmrManager()?.isEnabled() === true;
|
|
239
238
|
if (!hmr) {
|
|
240
|
-
const url = (await getHtmlPageModuleScriptUrls(this.appConfig)).get(
|
|
239
|
+
const url = (await getHtmlPageModuleScriptUrls(this.appConfig)).get(fileSystem.realpath(asset.filepath));
|
|
241
240
|
if (url !== undefined)
|
|
242
241
|
return url;
|
|
243
242
|
}
|
|
@@ -265,7 +264,7 @@ export class HtmlPageRenderer extends StringMarkupRenderer {
|
|
|
265
264
|
const found = scanModuleScript(this.appConfig, script).stylesheetImport;
|
|
266
265
|
if (!found)
|
|
267
266
|
return;
|
|
268
|
-
const real = (target) => (fileSystem.exists(target) ?
|
|
267
|
+
const real = (target) => (fileSystem.exists(target) ? fileSystem.realpath(target) : target);
|
|
269
268
|
const rootDir = real(this.appConfig.rootDir);
|
|
270
269
|
const show = (target) => path.isAbsolute(target) ? path.relative(rootDir, real(target)).split(path.sep).join('/') : target;
|
|
271
270
|
const stylesheet = real(found.stylesheet);
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* concrete file paths using the app's tsconfig `paths`. Each resolution goes
|
|
7
7
|
* through oxc-resolver and may read barrel re-export targets.
|
|
8
8
|
*
|
|
9
|
-
* This cache memoizes the result keyed by `(projectRoot, specifier)`.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* This cache memoizes the result keyed by `(projectRoot, specifier)`. Each
|
|
10
|
+
* plugin instance owns one, and the request policy creates the plugin for
|
|
11
|
+
* every build request, so a cached resolution lasts one build and needs no
|
|
12
|
+
* watcher invalidation.
|
|
12
13
|
*/
|
|
13
14
|
export declare class AliasResolverCache {
|
|
14
15
|
private readonly entries;
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* concrete file paths using the app's tsconfig `paths`. Each resolution goes
|
|
7
7
|
* through oxc-resolver and may read barrel re-export targets.
|
|
8
8
|
*
|
|
9
|
-
* This cache memoizes the result keyed by `(projectRoot, specifier)`.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* This cache memoizes the result keyed by `(projectRoot, specifier)`. Each
|
|
10
|
+
* plugin instance owns one, and the request policy creates the plugin for
|
|
11
|
+
* every build request, so a cached resolution lasts one build and needs no
|
|
12
|
+
* watcher invalidation.
|
|
12
13
|
*/
|
|
13
14
|
const DEFAULT_MAX_ENTRIES = 2_000;
|
|
14
15
|
export class AliasResolverCache {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import {
|
|
2
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
3
3
|
import { parseModuleSource } from '../cache/module-parse-cache.js';
|
|
4
4
|
import { loadTsconfigPathPrefixes, matchesTsconfigPathPrefix, resolveProjectModulePath, } from './tsconfig-import-resolver.js';
|
|
5
5
|
function node(value) {
|
|
@@ -89,7 +89,7 @@ function indexModuleExports(file, cache) {
|
|
|
89
89
|
const cached = cache.get(file);
|
|
90
90
|
if (cached)
|
|
91
91
|
return cached;
|
|
92
|
-
const source = readFileSync(file
|
|
92
|
+
const source = fileSystem.readFileSync(file);
|
|
93
93
|
const parsed = parseModuleSource(file, source, { sourceType: 'module' });
|
|
94
94
|
const body = nodes(parsed.program.body);
|
|
95
95
|
const { declared, factories } = collectDeclaredFactoryBindings(body);
|
|
@@ -155,7 +155,7 @@ function resolveStylesheetImportPath(source, ownerFile, projectRoot, pathPrefixe
|
|
|
155
155
|
}
|
|
156
156
|
if (isRelative) {
|
|
157
157
|
const candidate = path.resolve(path.dirname(ownerFile), source);
|
|
158
|
-
return
|
|
158
|
+
return fileSystem.exists(candidate) ? fileSystem.realpath(candidate) : undefined;
|
|
159
159
|
}
|
|
160
160
|
return resolveProjectModulePath(projectRoot, ownerFile, source, { preserveBarrel: true });
|
|
161
161
|
}
|
|
@@ -171,7 +171,7 @@ function tryRecordSideEffectStylesheetImport(statement, source, ownerFile, proje
|
|
|
171
171
|
}
|
|
172
172
|
return false;
|
|
173
173
|
}
|
|
174
|
-
if (!
|
|
174
|
+
if (!fileSystem.exists(resolved)) {
|
|
175
175
|
throw new Error(`[ecopages] Cannot resolve stylesheet import ${JSON.stringify(source)} from ${ownerFile}`);
|
|
176
176
|
}
|
|
177
177
|
result.stylesheets.push(resolved);
|
|
@@ -15,7 +15,16 @@ export interface EcoComponentDirPluginOptions {
|
|
|
15
15
|
* into its Component Dependencies, removing them from the module.
|
|
16
16
|
*/
|
|
17
17
|
export declare function stripsSideEffectStylesheetImports(config: EcoPagesAppConfig, filePath: string, contents: string): boolean;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Attributes real `eco.*()` factory calls with canonical component identity.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Each call gets its own `id`, hashed from the file, the declaration name, and how many earlier calls in the
|
|
23
|
+
* file share that name. Server and browser builds of one source derive the same id, and a named declaration
|
|
24
|
+
* keeps it while other code in the file changes. Calls bound to no name (an inline argument, a call inside an
|
|
25
|
+
* anonymous function) are numbered in source order, so adding or removing another unnamed call before them
|
|
26
|
+
* changes their id. `file` stays the module path for every call in the file.
|
|
27
|
+
*/
|
|
19
28
|
export declare function attributeComponentIdentity(contents: string, filePath: string, integration: string, projectRoot?: string, jsxImportSource?: string): EcoBuildOnTransformResult;
|
|
20
29
|
/**
|
|
21
30
|
* Attributes a compiled MDX module with canonical component identity and discovered dependencies.
|
|
@@ -4,6 +4,7 @@ import { composeSourceMaps, isUsableSourceMap } from '../build/source-maps.js';
|
|
|
4
4
|
import { createCoreTransformPlugin, createMappedSourceTransformResult } from '../build/mapped-source-transform.js';
|
|
5
5
|
import { parseModuleSource } from '../cache/module-parse-cache.js';
|
|
6
6
|
import { contentHash } from '../utils/content-hash.js';
|
|
7
|
+
import { escapeRegExp } from '../utils/regex-escaping.js';
|
|
7
8
|
import { discoverComponentImports } from './component-import-discovery.js';
|
|
8
9
|
import { findIntegrationForFile } from './find-integration-for-file.js';
|
|
9
10
|
function applySourceEdits(contents, edits, filePath, options = {}) {
|
|
@@ -72,6 +73,37 @@ function walkAst(node, visit) {
|
|
|
72
73
|
for (const value of Object.values(node))
|
|
73
74
|
walkAst(value, visit);
|
|
74
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Visits each `eco.*()` call with the name of the declaration it belongs to.
|
|
78
|
+
*
|
|
79
|
+
* @remarks
|
|
80
|
+
* The name is the nearest enclosing variable or function binding, or `default` inside `export default`; a call
|
|
81
|
+
* bound to neither gets an empty name.
|
|
82
|
+
*/
|
|
83
|
+
function walkEcoFactoryCalls(node, binding, visit) {
|
|
84
|
+
if (Array.isArray(node)) {
|
|
85
|
+
for (const child of node)
|
|
86
|
+
walkEcoFactoryCalls(child, binding, visit);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!isAstNode(node))
|
|
90
|
+
return;
|
|
91
|
+
if (isEcoFactoryCall(node))
|
|
92
|
+
visit(node, binding);
|
|
93
|
+
let scope = binding;
|
|
94
|
+
if (node.type === 'ExportDefaultDeclaration')
|
|
95
|
+
scope = 'default';
|
|
96
|
+
if ((node.type === 'VariableDeclarator' || node.type === 'FunctionDeclaration') && isAstNode(node.id)) {
|
|
97
|
+
if (node.id.type === 'Identifier')
|
|
98
|
+
scope = String(node.id.name);
|
|
99
|
+
}
|
|
100
|
+
for (const value of Object.values(node))
|
|
101
|
+
walkEcoFactoryCalls(value, scope, visit);
|
|
102
|
+
}
|
|
103
|
+
function createIdentityLiteral(identitySource, filePath, integration) {
|
|
104
|
+
const id = BigInt(`0x${contentHash(identitySource, 16)}`).toString(36);
|
|
105
|
+
return `{ id: ${JSON.stringify(id)}, file: ${JSON.stringify(filePath)}, integration: ${JSON.stringify(integration)} }`;
|
|
106
|
+
}
|
|
75
107
|
function createNamedImportEdit(program, sourceModule, importedName) {
|
|
76
108
|
const importedNames = typeof importedName === 'string' ? [importedName] : [...importedName];
|
|
77
109
|
const imports = program.body.filter((node) => isAstNode(node) &&
|
|
@@ -147,7 +179,16 @@ export function stripsSideEffectStylesheetImports(config, filePath, contents) {
|
|
|
147
179
|
return false;
|
|
148
180
|
}
|
|
149
181
|
}
|
|
150
|
-
/**
|
|
182
|
+
/**
|
|
183
|
+
* Attributes real `eco.*()` factory calls with canonical component identity.
|
|
184
|
+
*
|
|
185
|
+
* @remarks
|
|
186
|
+
* Each call gets its own `id`, hashed from the file, the declaration name, and how many earlier calls in the
|
|
187
|
+
* file share that name. Server and browser builds of one source derive the same id, and a named declaration
|
|
188
|
+
* keeps it while other code in the file changes. Calls bound to no name (an inline argument, a call inside an
|
|
189
|
+
* anonymous function) are numbered in source order, so adding or removing another unnamed call before them
|
|
190
|
+
* changes their id. `file` stays the module path for every call in the file.
|
|
191
|
+
*/
|
|
151
192
|
export function attributeComponentIdentity(contents, filePath, integration, projectRoot, jsxImportSource) {
|
|
152
193
|
const pragma = jsxImportSource && !contents.includes('@jsxImportSource')
|
|
153
194
|
? createJsxImportSourcePragma(jsxImportSource)
|
|
@@ -162,20 +203,26 @@ export function attributeComponentIdentity(contents, filePath, integration, proj
|
|
|
162
203
|
catch {
|
|
163
204
|
return applySourceEdits(contents, [], filePath, { prepend: pragma });
|
|
164
205
|
}
|
|
165
|
-
const identityLiteral = `{ id: ${JSON.stringify(BigInt(`0x${contentHash(filePath, 16)}`).toString(36))}, file: ${JSON.stringify(filePath)}, integration: ${JSON.stringify(integration)} }`;
|
|
166
206
|
if (!hasEcoFactoryCall(program)) {
|
|
167
207
|
return applySourceEdits(contents, [], filePath, { prepend: pragma });
|
|
168
208
|
}
|
|
169
209
|
const factoryArguments = [];
|
|
170
|
-
|
|
171
|
-
|
|
210
|
+
const bindingOccurrences = new Map();
|
|
211
|
+
walkEcoFactoryCalls(program, '', (node, binding) => {
|
|
212
|
+
const occurrence = bindingOccurrences.get(binding) ?? 0;
|
|
213
|
+
bindingOccurrences.set(binding, occurrence + 1);
|
|
214
|
+
if (!Array.isArray(node.arguments))
|
|
172
215
|
return;
|
|
173
216
|
const firstArgument = node.arguments[0];
|
|
174
217
|
if (!isAstNode(firstArgument) || isIdentityBinding(firstArgument))
|
|
175
218
|
return;
|
|
176
219
|
if (typeof firstArgument.start !== 'number' || typeof firstArgument.end !== 'number')
|
|
177
220
|
return;
|
|
178
|
-
factoryArguments.push({
|
|
221
|
+
factoryArguments.push({
|
|
222
|
+
start: firstArgument.start,
|
|
223
|
+
end: firstArgument.end,
|
|
224
|
+
identityLiteral: createIdentityLiteral(`${filePath}:${binding}:${occurrence}`, filePath, integration),
|
|
225
|
+
});
|
|
179
226
|
});
|
|
180
227
|
if (factoryArguments.length === 0) {
|
|
181
228
|
return applySourceEdits(contents, [], filePath, { prepend: pragma });
|
|
@@ -185,7 +232,7 @@ export function attributeComponentIdentity(contents, filePath, integration, proj
|
|
|
185
232
|
const edits = factoryArguments.map((firstArgument) => ({
|
|
186
233
|
start: firstArgument.start,
|
|
187
234
|
end: firstArgument.end,
|
|
188
|
-
prefix: `bindComponentIdentity(${identityLiteral}, `,
|
|
235
|
+
prefix: `bindComponentIdentity(${firstArgument.identityLiteral}, `,
|
|
189
236
|
suffix: `${discoveryArgument})`,
|
|
190
237
|
}));
|
|
191
238
|
edits.push(...(discovered?.removals ?? []));
|
|
@@ -257,7 +304,7 @@ export function attributeMdxComponentIdentity(contents, filePath, integration, p
|
|
|
257
304
|
return { code: contents, map: previousMap };
|
|
258
305
|
}
|
|
259
306
|
const discovered = discoverComponentImports(program, filePath, projectRoot);
|
|
260
|
-
const identityLiteral =
|
|
307
|
+
const identityLiteral = createIdentityLiteral(filePath, filePath, integration);
|
|
261
308
|
const discoveryArgument = serializeDiscoveryArgument(discovered);
|
|
262
309
|
const edits = buildMdxConfigIdentityEdits({
|
|
263
310
|
contents,
|
|
@@ -283,12 +330,21 @@ export function attributeMdxComponentIdentity(contents, filePath, integration, p
|
|
|
283
330
|
: transformed.map,
|
|
284
331
|
};
|
|
285
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* Matches the ids of modules with a script extension that an Integration owns, before an optional query.
|
|
335
|
+
*
|
|
336
|
+
* @remarks
|
|
337
|
+
* With no such extension it matches no id, so the hook filter skips every module rather than an empty
|
|
338
|
+
* alternation matching all of them, `node_modules` included.
|
|
339
|
+
*/
|
|
286
340
|
function createComponentMetaFilter(config) {
|
|
287
341
|
const extensions = config.integrations
|
|
288
342
|
.flatMap((integration) => integration.extensions)
|
|
289
|
-
.filter((extension) => ['.ts', '.tsx', '.js', '.jsx'].some((suffix) => extension.endsWith(suffix)))
|
|
290
|
-
|
|
291
|
-
|
|
343
|
+
.filter((extension) => ['.ts', '.tsx', '.js', '.jsx'].some((suffix) => extension.endsWith(suffix)));
|
|
344
|
+
if (extensions.length === 0) {
|
|
345
|
+
return /(?!)/;
|
|
346
|
+
}
|
|
347
|
+
return new RegExp(`(${extensions.map(escapeRegExp).join('|')})(\\?.*)?$`);
|
|
292
348
|
}
|
|
293
349
|
/**
|
|
294
350
|
* Creates the build plugin that attributes component identity in every Integration's script files.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fileSystem } from '@ecopages/file-system';
|
|
2
|
+
import { escapeRegExp } from '../utils/regex-escaping.js';
|
|
2
3
|
import { createJsxImportSourcePragma, filterJsxSourceExtensions } from './jsx-import-source.utils.js';
|
|
3
4
|
/**
|
|
4
5
|
* Build plugin that prepends a `@jsxImportSource` pragma to foreign integration
|
|
@@ -28,7 +29,7 @@ export function createForeignJsxOverridePlugin(options) {
|
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
const pragma = createJsxImportSourcePragma(options.hostJsxImportSource);
|
|
31
|
-
const filter = new RegExp(`(${extensions.map(
|
|
32
|
+
const filter = new RegExp(`(${extensions.map(escapeRegExp).join('|')})$`);
|
|
32
33
|
return {
|
|
33
34
|
name: options.name ?? 'foreign-jsx-override',
|
|
34
35
|
cacheKey: JSON.stringify([options.hostJsxImportSource, extensions, excludedExtensions]),
|
|
@@ -37,7 +38,7 @@ export function createForeignJsxOverridePlugin(options) {
|
|
|
37
38
|
if (excludedExtensions.some((extension) => args.path.endsWith(extension))) {
|
|
38
39
|
return undefined;
|
|
39
40
|
}
|
|
40
|
-
const source = readFileSync(args.path
|
|
41
|
+
const source = fileSystem.readFileSync(args.path);
|
|
41
42
|
const loader = args.path.endsWith('.jsx') ? 'jsx' : 'tsx';
|
|
42
43
|
if (source.includes('@jsxImportSource')) {
|
|
43
44
|
return undefined;
|