@ecopages/core 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +14 -4
- package/src/adapters/node/create-app.d.ts +5 -5
- package/src/adapters/node/create-app.js +1 -1
- package/src/adapters/node/server-adapter.d.ts +1 -0
- package/src/adapters/node/server-adapter.js +4 -1
- package/src/adapters/shared/hmr/hmr-manager.d.ts +2 -0
- package/src/adapters/shared/hmr/hmr-manager.js +8 -4
- package/src/adapters/shared/http/api-request-pipeline.d.ts +16 -3
- package/src/adapters/shared/http/api-request-pipeline.js +23 -16
- package/src/adapters/shared/http/define-api-handler.d.ts +8 -8
- package/src/adapters/shared/http/explicit-static-route-matcher.js +8 -4
- package/src/adapters/shared/http/file-route-middleware-pipeline.d.ts +10 -11
- package/src/adapters/shared/http/file-route-middleware-pipeline.js +5 -6
- package/src/adapters/shared/http/fs-server-response-matcher.js +12 -4
- package/src/adapters/shared/http/run-middleware-chain.d.ts +29 -2
- package/src/adapters/shared/http/run-middleware-chain.js +108 -10
- package/src/adapters/shared/runtime/render-context.d.ts +2 -0
- package/src/adapters/shared/runtime/render-context.js +6 -21
- package/src/adapters/shared/runtime/server-request-pipeline.d.ts +2 -2
- package/src/adapters/shared/runtime/server-request-pipeline.js +4 -3
- package/src/adapters/shared/runtime/server-static-builder.js +4 -1
- package/src/adapters/shared/runtime/unattached-scripts.d.ts +17 -0
- package/src/adapters/shared/runtime/unattached-scripts.js +57 -0
- package/src/adapters/shared/ws/node-http-websocket-upgrades.js +3 -2
- package/src/adapters/shared/ws/ws-pattern-matcher.d.ts +14 -1
- package/src/adapters/shared/ws/ws-pattern-matcher.js +14 -13
- package/src/assets/app-browser-client-build.js +3 -0
- package/src/assets/asset-processing-service/asset-processing.service.d.ts +9 -0
- package/src/assets/asset-processing-service/asset-processing.service.js +19 -0
- package/src/assets/asset-processing-service/processed-asset-ledger.d.ts +16 -2
- package/src/assets/asset-processing-service/processed-asset-ledger.js +31 -3
- package/src/build/build-graph.d.ts +19 -2
- package/src/build/build-graph.js +19 -18
- package/src/build/cache/pages-unified-graph-build.d.ts +4 -6
- package/src/build/cache/pages-unified-graph-build.js +14 -51
- package/src/build/cache/server-module-entries.d.ts +5 -9
- package/src/build/cache/server-module-entries.js +5 -58
- package/src/build/contracts/build-contracts.d.ts +15 -0
- package/src/build/contracts.d.ts +1 -1
- package/src/build/contracts.js +1 -1
- package/src/build/production-asset-ledger.d.ts +1 -1
- package/src/build/production-asset-ledger.js +4 -2
- package/src/build/rolldown/file-role-grammar-plugin.d.ts +11 -0
- package/src/build/rolldown/file-role-grammar-plugin.js +32 -0
- package/src/build/rolldown/rolldown-adapter-helpers.d.ts +11 -0
- package/src/build/rolldown/rolldown-adapter-helpers.js +79 -10
- package/src/build/rolldown/ssr-script-entries-plugin.d.ts +31 -0
- package/src/build/rolldown/ssr-script-entries-plugin.js +104 -0
- package/src/build/runtime/build-request-policy.js +4 -1
- package/src/build/server/server-modules-manifest.d.ts +6 -1
- package/src/build/server/server-modules-manifest.js +10 -1
- package/src/build/server/view-reference.d.ts +9 -0
- package/src/build/server/view-reference.js +11 -0
- package/src/build.d.ts +3 -1
- package/src/build.js +3 -1
- package/src/cli.d.ts +14 -0
- package/src/cli.js +14 -0
- package/src/config/assembly/app-runtime.d.ts +13 -0
- package/src/config/assembly/app-runtime.js +2 -0
- package/src/config/assembly/finalize-config.js +13 -8
- package/src/config/internal-types.d.ts +0 -12
- package/src/config/resolve-eco-config-path.d.ts +2 -0
- package/src/config/resolve-eco-config-path.js +2 -1
- package/src/config/server-config-bundle.d.ts +0 -1
- package/src/config/server-config-bundle.js +1 -1
- package/src/config/user-config-types.d.ts +0 -12
- package/src/declarations.d.ts +2 -0
- package/src/dev/invalidation/development-invalidation.service.d.ts +0 -2
- package/src/dev/invalidation/development-invalidation.service.js +1 -11
- package/src/dev/transform-server/dev-transform-vendor-registry.js +33 -19
- package/src/eco/discovered-dependencies.d.ts +5 -0
- package/src/eco/discovered-dependencies.js +9 -0
- package/src/eco/eco.browser.js +6 -26
- package/src/eco/eco.js +24 -16
- package/src/eco/migration-docs.d.ts +7 -0
- package/src/eco/migration-docs.js +7 -0
- package/src/eco/page-data-hooks.d.ts +27 -0
- package/src/eco/page-data-hooks.js +64 -0
- package/src/eco/page-layout-normalization.d.ts +2 -2
- package/src/hmr/client/hmr-runtime.js +1 -1
- package/src/hmr/strategies/js-hmr-strategy.d.ts +0 -2
- package/src/hmr/strategies/server-rendered-template-hmr-strategy.d.ts +2 -1
- package/src/hmr/strategies/server-rendered-template-hmr-strategy.js +4 -3
- package/src/html/html-rewriter.d.ts +9 -7
- package/src/html/html-rewriter.js +26 -41
- package/src/html/html-transformer.service.d.ts +2 -2
- package/src/html/html-transformer.service.js +21 -15
- package/src/html-pages/html-page-module-scripts.js +2 -1
- package/src/html-pages/html-pages.plugin.d.ts +1 -1
- package/src/html-pages/html-pages.plugin.js +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/integration.d.ts +2 -2
- package/src/integration.js +2 -2
- package/src/islands/island-host.d.ts +16 -5
- package/src/islands/island-host.js +8 -1
- package/src/middleware/create-middleware.d.ts +41 -0
- package/src/middleware/create-middleware.js +72 -0
- package/src/plugins/component-import-discovery.d.ts +14 -1
- package/src/plugins/component-import-discovery.js +36 -16
- package/src/plugins/eco-component-meta-plugin.d.ts +38 -0
- package/src/plugins/eco-component-meta-plugin.js +208 -44
- package/src/plugins/ecopages-virtual-imports.d.ts +15 -0
- package/src/plugins/ecopages-virtual-imports.js +25 -0
- package/src/plugins/integration-plugin.d.ts +1 -1
- package/src/plugins/integration-plugin.js +1 -1
- package/src/plugins/tsconfig-import-resolver.d.ts +2 -0
- package/src/plugins/tsconfig-import-resolver.js +7 -5
- package/src/route-renderer/error-pages/error-page-renderer.js +32 -3
- package/src/route-renderer/explicit-view-render-preparation.d.ts +28 -3
- package/src/route-renderer/explicit-view-render-preparation.js +63 -11
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.d.ts +15 -5
- package/src/route-renderer/orchestration/document-shell/layout-shell-props.service.js +27 -15
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +24 -9
- package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +73 -50
- package/src/route-renderer/orchestration/integration-renderer.d.ts +42 -11
- package/src/route-renderer/orchestration/integration-renderer.js +83 -43
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.builder.js +0 -3
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.d.ts +36 -11
- package/src/route-renderer/orchestration/route-pipeline/route-render-orchestrator.js +74 -62
- package/src/route-renderer/page-declaration.d.ts +25 -0
- package/src/route-renderer/page-declaration.js +39 -0
- package/src/route-renderer/page-loading/component-declarations.d.ts +65 -0
- package/src/route-renderer/page-loading/component-declarations.js +77 -0
- package/src/route-renderer/page-loading/component-dependency-collection.d.ts +4 -16
- package/src/route-renderer/page-loading/component-dependency-collection.js +36 -105
- package/src/route-renderer/page-loading/declared-asset-collection.d.ts +19 -14
- package/src/route-renderer/page-loading/declared-asset-collection.js +66 -67
- package/src/route-renderer/page-loading/dependency-resolver.d.ts +18 -10
- package/src/route-renderer/page-loading/dependency-resolver.js +58 -99
- package/src/route-renderer/page-loading/lazy-entry-collection.d.ts +19 -26
- package/src/route-renderer/page-loading/lazy-entry-collection.js +53 -64
- package/src/route-renderer/page-loading/module-declaration-aggregation.d.ts +17 -3
- package/src/route-renderer/page-loading/module-declaration-aggregation.js +14 -13
- package/src/route-renderer/page-loading/page-module-loader.d.ts +31 -12
- package/src/route-renderer/page-loading/page-module-loader.js +66 -35
- package/src/route-renderer/page-loading/resolved-page-dependencies.js +14 -9
- package/src/router/server/pages-dir.d.ts +7 -0
- package/src/router/server/pages-dir.js +7 -0
- package/src/router/server/route-registry.d.ts +22 -10
- package/src/router/server/route-registry.js +54 -23
- package/src/router/server/segment-path-matcher.d.ts +29 -5
- package/src/router/server/segment-path-matcher.js +22 -19
- package/src/static-site-generator/production-page-browser-graph-prebuild.d.ts +2 -2
- package/src/static-site-generator/production-page-browser-graph-prebuild.js +5 -5
- package/src/static-site-generator/static-site-generator.d.ts +17 -2
- package/src/static-site-generator/static-site-generator.js +52 -18
- package/src/types/contracts.d.ts +216 -160
- package/src/types/eco-api-types.d.ts +86 -51
- package/src/types/locals-brand.d.ts +9 -0
- package/src/types/locals-brand.js +9 -0
- package/src/types/middleware-types.d.ts +143 -0
- package/src/types/middleware-types.js +1 -0
- package/src/types/public-types.d.ts +3 -2
- package/src/utils/file-roles.d.ts +48 -0
- package/src/utils/file-roles.js +85 -0
- package/src/utils/node-builtin.d.ts +10 -0
- package/src/utils/node-builtin.js +13 -0
- package/src/watchers/project-watcher.js +2 -2
- package/src/build/contracts/server-only-specifier.d.ts +0 -8
- package/src/build/contracts/server-only-specifier.js +0 -11
- package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.d.ts +0 -5
- package/src/route-renderer/orchestration/route-pipeline/marker-artifact.utils.js +0 -11
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.d.ts +0 -4
- package/src/route-renderer/orchestration/route-pipeline/route-prepared-options.utils.js +0 -30
- package/src/route-renderer/page-loading/ecopages-virtual-imports.d.ts +0 -12
- package/src/route-renderer/page-loading/ecopages-virtual-imports.js +0 -100
- package/src/utils/endpoint-file-extensions.d.ts +0 -11
- package/src/utils/endpoint-file-extensions.js +0 -13
- package/src/utils/locals-utils.d.ts +0 -15
- package/src/utils/locals-utils.js +0 -34
|
@@ -11,7 +11,7 @@ import { escapeRegExp } from '../utils/regex-escaping.js';
|
|
|
11
11
|
import { toPackagePath } from '../utils/package-path.js';
|
|
12
12
|
import { formatPackageStylesheetEntry } from '../eco/discovered-dependency-paths.js';
|
|
13
13
|
import { toRootRelativePath } from '../utils/root-relative-path.js';
|
|
14
|
-
import { collectStaticImports, createDiscoveryCache, createUndeliverableStylesheetError, declaresEcoFactory,
|
|
14
|
+
import { collectStaticImports, createDiscoveryCache, createUndeliverableStylesheetError, declaresEcoFactory, forgetCanonicalDiscoveryOwner, discoverComponentImports, isDeliveredStylesheetImport, isReachedByDiscovery, } from './component-import-discovery.js';
|
|
15
15
|
import { loadTsconfigPathPrefixes } from './tsconfig-import-resolver.js';
|
|
16
16
|
import { findIntegrationForFile } from './find-integration-for-file.js';
|
|
17
17
|
function applySourceEdits(contents, edits, filePath, options = {}) {
|
|
@@ -42,11 +42,6 @@ function applySourceEdits(contents, edits, filePath, options = {}) {
|
|
|
42
42
|
};
|
|
43
43
|
return createMappedSourceTransformResult(contents, filePath, editSource);
|
|
44
44
|
}
|
|
45
|
-
/**
|
|
46
|
-
* Matches the text of a side-effect import such as `import 'swiper/css'`, which can name a package stylesheet
|
|
47
|
-
* without a `.css` suffix.
|
|
48
|
-
*/
|
|
49
|
-
const SIDE_EFFECT_IMPORT = /(?:^|[;}\s])import\s*['"]/m;
|
|
50
45
|
function isAstNode(value) {
|
|
51
46
|
return typeof value === 'object' && value !== null;
|
|
52
47
|
}
|
|
@@ -109,24 +104,29 @@ function walkEcoFactoryCalls(node, binding, visit) {
|
|
|
109
104
|
* real module ids the bundler reports. A file not on disk, such as a virtual module, takes the real path of its
|
|
110
105
|
* folder.
|
|
111
106
|
*/
|
|
112
|
-
function createSourceKeyResolver(projectRoot) {
|
|
107
|
+
function createSourceKeyResolver(projectRoot, canonicalProjectRoot) {
|
|
113
108
|
const toRealPath = (file) => {
|
|
114
109
|
if (fileSystem.exists(file))
|
|
115
110
|
return fileSystem.realpath(file);
|
|
116
111
|
const dir = path.dirname(file);
|
|
117
112
|
return fileSystem.exists(dir) ? path.join(fileSystem.realpath(dir), path.basename(file)) : path.resolve(file);
|
|
118
113
|
};
|
|
119
|
-
const realRoot = toRealPath(projectRoot);
|
|
120
|
-
return
|
|
114
|
+
const realRoot = canonicalProjectRoot ?? toRealPath(projectRoot);
|
|
115
|
+
return {
|
|
116
|
+
toSourceKey: (file) => toRootRelativePath(realRoot, toRealPath(file)),
|
|
117
|
+
toCanonicalSourceKey: (file) => toRootRelativePath(realRoot, file),
|
|
118
|
+
};
|
|
121
119
|
}
|
|
122
120
|
/**
|
|
123
121
|
* @remarks
|
|
124
122
|
* `file` is the root-relative source key and `id` hashes it, so an emitted module names its source the same
|
|
125
123
|
* wherever the app was built and keeps working after the app folder moves.
|
|
126
124
|
*/
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
function createIdentity(identitySource, sourceKey, integration) {
|
|
126
|
+
return { id: BigInt(`0x${contentHash(identitySource, 16)}`).toString(36), file: sourceKey, integration };
|
|
127
|
+
}
|
|
128
|
+
function createIdentityLiteral({ id, file, integration }) {
|
|
129
|
+
return `{ id: ${JSON.stringify(id)}, file: ${JSON.stringify(file)}, integration: ${JSON.stringify(integration)} }`;
|
|
130
130
|
}
|
|
131
131
|
function createNamedImportEdit(program, sourceModule, importedName) {
|
|
132
132
|
const importedNames = typeof importedName === 'string' ? [importedName] : [...importedName];
|
|
@@ -213,6 +213,7 @@ function serializeDiscoveryArgument(discovered, toSourceKey, plainModuleComponen
|
|
|
213
213
|
discovered.stylesheets.length === 0 &&
|
|
214
214
|
discovered.plainModuleStylesheets.length === 0 &&
|
|
215
215
|
discovered.plainModuleComponents.length === 0 &&
|
|
216
|
+
discovered.virtualImports.length === 0 &&
|
|
216
217
|
discovered.watchFiles.length === 0)) {
|
|
217
218
|
return '';
|
|
218
219
|
}
|
|
@@ -233,7 +234,8 @@ function serializeDiscoveryArgument(discovered, toSourceKey, plainModuleComponen
|
|
|
233
234
|
const watchFiles = discovered.watchFiles.length > 0
|
|
234
235
|
? `, watchFiles: ${JSON.stringify(discovered.watchFiles.map(toSourceKey))}`
|
|
235
236
|
: '';
|
|
236
|
-
|
|
237
|
+
const virtualImports = discovered.virtualImports.length > 0 ? `, virtualImports: ${JSON.stringify(discovered.virtualImports)}` : '';
|
|
238
|
+
return `, { components: () => [${components}], stylesheets: ${JSON.stringify(stylesheets)}${plain}${packages}${virtualImports}${watchFiles} }`;
|
|
237
239
|
}
|
|
238
240
|
/**
|
|
239
241
|
* Whether the component meta transform moves the side-effect stylesheet imports of `filePath`
|
|
@@ -281,9 +283,22 @@ function stripPlainModuleStylesheetImports(program, filePath, options) {
|
|
|
281
283
|
}
|
|
282
284
|
return edits;
|
|
283
285
|
}
|
|
284
|
-
/**
|
|
285
|
-
function
|
|
286
|
-
|
|
286
|
+
/** The first argument of each `eco.*()` call not yet bound, with the identity literal to bind it to. */
|
|
287
|
+
function collectFactoryArguments(program, sourceKey, integration) {
|
|
288
|
+
const factoryArguments = [];
|
|
289
|
+
for (const [call, identity] of collectCallIdentities(program, sourceKey, integration)) {
|
|
290
|
+
const firstArgument = Array.isArray(call.arguments) ? call.arguments[0] : undefined;
|
|
291
|
+
if (!isAstNode(firstArgument) || isIdentityBinding(firstArgument))
|
|
292
|
+
continue;
|
|
293
|
+
if (typeof firstArgument.start !== 'number' || typeof firstArgument.end !== 'number')
|
|
294
|
+
continue;
|
|
295
|
+
factoryArguments.push({
|
|
296
|
+
start: firstArgument.start,
|
|
297
|
+
end: firstArgument.end,
|
|
298
|
+
identityLiteral: createIdentityLiteral(identity),
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
return factoryArguments;
|
|
287
302
|
}
|
|
288
303
|
/**
|
|
289
304
|
* Attributes real `eco.*()` factory calls with canonical component identity.
|
|
@@ -302,7 +317,7 @@ export function attributeComponentIdentity(contents, filePath, options) {
|
|
|
302
317
|
? createJsxImportSourcePragma(jsxImportSource)
|
|
303
318
|
: undefined;
|
|
304
319
|
const mayDeclare = integration !== undefined && contents.includes('eco.');
|
|
305
|
-
if (!mayDeclare && !
|
|
320
|
+
if (!mayDeclare && !contents.includes('import')) {
|
|
306
321
|
return applySourceEdits(contents, [], filePath, { prepend: pragma });
|
|
307
322
|
}
|
|
308
323
|
let program;
|
|
@@ -313,7 +328,7 @@ export function attributeComponentIdentity(contents, filePath, options) {
|
|
|
313
328
|
return applySourceEdits(contents, [], filePath, { prepend: pragma });
|
|
314
329
|
}
|
|
315
330
|
if (!mayDeclare || !declaresEcoFactory(program)) {
|
|
316
|
-
|
|
331
|
+
forgetCanonicalDiscoveryOwner(projectRoot, filePath);
|
|
317
332
|
const edits = options.stripPlainModuleStylesheets === false
|
|
318
333
|
? []
|
|
319
334
|
: stripPlainModuleStylesheetImports(program, filePath, options);
|
|
@@ -321,26 +336,9 @@ export function attributeComponentIdentity(contents, filePath, options) {
|
|
|
321
336
|
prepend: pragma,
|
|
322
337
|
});
|
|
323
338
|
}
|
|
324
|
-
const
|
|
325
|
-
const sourceKey =
|
|
326
|
-
const factoryArguments =
|
|
327
|
-
const bindingOccurrences = new Map();
|
|
328
|
-
walkEcoFactoryCalls(program, '', (node, binding) => {
|
|
329
|
-
const occurrence = bindingOccurrences.get(binding) ?? 0;
|
|
330
|
-
bindingOccurrences.set(binding, occurrence + 1);
|
|
331
|
-
if (!Array.isArray(node.arguments))
|
|
332
|
-
return;
|
|
333
|
-
const firstArgument = node.arguments[0];
|
|
334
|
-
if (!isAstNode(firstArgument) || isIdentityBinding(firstArgument))
|
|
335
|
-
return;
|
|
336
|
-
if (typeof firstArgument.start !== 'number' || typeof firstArgument.end !== 'number')
|
|
337
|
-
return;
|
|
338
|
-
factoryArguments.push({
|
|
339
|
-
start: firstArgument.start,
|
|
340
|
-
end: firstArgument.end,
|
|
341
|
-
identityLiteral: createIdentityLiteral(`${sourceKey}:${binding}:${occurrence}`, sourceKey, integration),
|
|
342
|
-
});
|
|
343
|
-
});
|
|
339
|
+
const { toCanonicalSourceKey } = createSourceKeyResolver(projectRoot, options.canonicalProjectRoot);
|
|
340
|
+
const sourceKey = toCanonicalSourceKey(filePath);
|
|
341
|
+
const factoryArguments = collectFactoryArguments(program, sourceKey, integration);
|
|
344
342
|
if (factoryArguments.length === 0) {
|
|
345
343
|
return applySourceEdits(contents, [], filePath, { prepend: pragma });
|
|
346
344
|
}
|
|
@@ -350,8 +348,10 @@ export function attributeComponentIdentity(contents, filePath, options) {
|
|
|
350
348
|
cache: options.discoveryCache,
|
|
351
349
|
stylesheets: options.stylesheets,
|
|
352
350
|
});
|
|
353
|
-
const plainModuleImports =
|
|
354
|
-
|
|
351
|
+
const plainModuleImports = options.plainModuleComponentImports === false
|
|
352
|
+
? { locals: [], code: '' }
|
|
353
|
+
: createPlainModuleComponentImports(discovered);
|
|
354
|
+
const discoveryArgument = serializeDiscoveryArgument(discovered, toCanonicalSourceKey, plainModuleImports.locals);
|
|
355
355
|
const edits = factoryArguments.map((firstArgument) => ({
|
|
356
356
|
start: firstArgument.start,
|
|
357
357
|
end: firstArgument.end,
|
|
@@ -406,6 +406,148 @@ function buildMdxIdentityAppend(options) {
|
|
|
406
406
|
appended += `attachDiscoveredDependencies(config);\nif (typeof MDXContent === 'function') MDXContent.config = config;\n`;
|
|
407
407
|
return appended;
|
|
408
408
|
}
|
|
409
|
+
/** The expression under TypeScript `as`, `satisfies` and non-null wrappers, and parentheses. */
|
|
410
|
+
function unwrapExpression(value) {
|
|
411
|
+
let current = node(value);
|
|
412
|
+
while (current &&
|
|
413
|
+
(current.type === 'TSAsExpression' ||
|
|
414
|
+
current.type === 'TSSatisfiesExpression' ||
|
|
415
|
+
current.type === 'TSNonNullExpression' ||
|
|
416
|
+
current.type === 'ParenthesizedExpression')) {
|
|
417
|
+
current = node(current.expression);
|
|
418
|
+
}
|
|
419
|
+
return current;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Reads, without transforming the module, the identity of each export whose value is an `eco.*()` call.
|
|
423
|
+
*
|
|
424
|
+
* @remarks
|
|
425
|
+
* The identities are the ones {@link attributeComponentIdentity} binds when it builds the same source, so a
|
|
426
|
+
* browser graph can name a Component another Integration owns without importing its module. An export counts only
|
|
427
|
+
* when its value is the call itself: `export const X = eco.component(...)`, `export default eco.component(...)`, or
|
|
428
|
+
* a top-level `const` holding the call that an `export { local as name }` or `export default local` names. A value
|
|
429
|
+
* a function returns, or any other expression, has no entry, and so does a module that does not parse. A call whose
|
|
430
|
+
* options are not an object literal, or set `integration` or spread another object, has no entry either, since its
|
|
431
|
+
* Component may belong to another Integration than the file.
|
|
432
|
+
* `filePath` is compared as given, so pass the real path the bundler reports.
|
|
433
|
+
*/
|
|
434
|
+
export function readExportedComponentIdentities(contents, filePath, options) {
|
|
435
|
+
if (!contents.includes('eco.'))
|
|
436
|
+
return new Map();
|
|
437
|
+
let program;
|
|
438
|
+
try {
|
|
439
|
+
program = parseModuleSource(filePath, contents, { sourceType: 'module' }).program;
|
|
440
|
+
}
|
|
441
|
+
catch {
|
|
442
|
+
return new Map();
|
|
443
|
+
}
|
|
444
|
+
const sourceKey = createSourceKeyResolver(options.projectRoot).toCanonicalSourceKey(filePath);
|
|
445
|
+
const callIdentities = collectCallIdentities(program, sourceKey, options.integration);
|
|
446
|
+
if (callIdentities.size === 0)
|
|
447
|
+
return new Map();
|
|
448
|
+
const identityOf = (value) => {
|
|
449
|
+
const expression = unwrapExpression(value);
|
|
450
|
+
return expression && ownedByFile(expression) ? callIdentities.get(expression) : undefined;
|
|
451
|
+
};
|
|
452
|
+
const statements = nodes(program.body);
|
|
453
|
+
return collectExportIdentities(statements, identityOf, collectConstIdentities(statements, identityOf));
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* The identity each `eco.*()` call gets, in source order.
|
|
457
|
+
*
|
|
458
|
+
* @remarks
|
|
459
|
+
* The one place calls are numbered: {@link attributeComponentIdentity} binds these identities and
|
|
460
|
+
* {@link readExportedComponentIdentities} reads them, so the two cannot disagree.
|
|
461
|
+
*/
|
|
462
|
+
function collectCallIdentities(program, sourceKey, integration) {
|
|
463
|
+
const identities = new Map();
|
|
464
|
+
const bindingOccurrences = new Map();
|
|
465
|
+
walkEcoFactoryCalls(program, '', (call, binding) => {
|
|
466
|
+
const occurrence = bindingOccurrences.get(binding) ?? 0;
|
|
467
|
+
bindingOccurrences.set(binding, occurrence + 1);
|
|
468
|
+
identities.set(call, createIdentity(`${sourceKey}:${binding}:${occurrence}`, sourceKey, integration));
|
|
469
|
+
});
|
|
470
|
+
return identities;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Whether an `eco.*()` call's Component belongs to the Integration that owns its file: its options are an object
|
|
474
|
+
* literal with neither an `integration` property nor a spread that could carry one.
|
|
475
|
+
*/
|
|
476
|
+
function ownedByFile(call) {
|
|
477
|
+
const options = Array.isArray(call.arguments) ? node(call.arguments[0]) : undefined;
|
|
478
|
+
if (options?.type !== 'ObjectExpression')
|
|
479
|
+
return false;
|
|
480
|
+
return !nodes(options.properties).some((property) => {
|
|
481
|
+
if ((property.type !== 'Property' && property.type !== 'ObjectProperty') || property.computed)
|
|
482
|
+
return true;
|
|
483
|
+
const key = node(property.key);
|
|
484
|
+
return key !== undefined && (key.name ?? key.value) === 'integration';
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
/** The identity of each top-level `const`, exported or not, whose initializer is an `eco.*()` call. */
|
|
488
|
+
function collectConstIdentities(statements, identityOf) {
|
|
489
|
+
const identities = new Map();
|
|
490
|
+
for (const statement of statements) {
|
|
491
|
+
const declaration = statement.type === 'ExportNamedDeclaration' ? node(statement.declaration) : statement;
|
|
492
|
+
if (declaration?.type !== 'VariableDeclaration' || declaration.kind !== 'const')
|
|
493
|
+
continue;
|
|
494
|
+
for (const declarator of nodes(declaration.declarations)) {
|
|
495
|
+
const id = node(declarator.id);
|
|
496
|
+
const identity = identityOf(declarator.init);
|
|
497
|
+
if (id?.type === 'Identifier' && identity)
|
|
498
|
+
identities.set(String(id.name), identity);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return identities;
|
|
502
|
+
}
|
|
503
|
+
function exportedName(value) {
|
|
504
|
+
const exported = node(value);
|
|
505
|
+
if (!exported)
|
|
506
|
+
return undefined;
|
|
507
|
+
return exported.type === 'Identifier' ? String(exported.name) : String(exported.value);
|
|
508
|
+
}
|
|
509
|
+
/** The names a local `export` statement gives a top-level `const`, with the const's name. */
|
|
510
|
+
function localExportNames(statement) {
|
|
511
|
+
const names = [];
|
|
512
|
+
const declaration = node(statement.declaration);
|
|
513
|
+
if (declaration?.type === 'VariableDeclaration') {
|
|
514
|
+
for (const declarator of nodes(declaration.declarations)) {
|
|
515
|
+
const id = node(declarator.id);
|
|
516
|
+
if (id?.type === 'Identifier')
|
|
517
|
+
names.push([String(id.name), String(id.name)]);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
for (const specifier of nodes(statement.specifiers)) {
|
|
521
|
+
const local = node(specifier.local);
|
|
522
|
+
const exported = exportedName(specifier.exported);
|
|
523
|
+
if (specifier.exportKind !== 'type' && local?.type === 'Identifier' && exported) {
|
|
524
|
+
names.push([exported, String(local.name)]);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return names;
|
|
528
|
+
}
|
|
529
|
+
/** The identity of each export whose value is an `eco.*()` call, directly or through a top-level `const`. */
|
|
530
|
+
function collectExportIdentities(statements, identityOf, constIdentities) {
|
|
531
|
+
const identities = new Map();
|
|
532
|
+
for (const statement of statements) {
|
|
533
|
+
if (statement.type === 'ExportDefaultDeclaration') {
|
|
534
|
+
const declaration = node(statement.declaration);
|
|
535
|
+
const local = declaration?.type === 'Identifier' ? constIdentities.get(String(declaration.name)) : undefined;
|
|
536
|
+
const identity = identityOf(declaration) ?? local;
|
|
537
|
+
if (identity)
|
|
538
|
+
identities.set('default', identity);
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
if (statement.type !== 'ExportNamedDeclaration' || statement.source || statement.exportKind === 'type')
|
|
542
|
+
continue;
|
|
543
|
+
for (const [exported, local] of localExportNames(statement)) {
|
|
544
|
+
const identity = constIdentities.get(local);
|
|
545
|
+
if (identity)
|
|
546
|
+
identities.set(exported, identity);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return identities;
|
|
550
|
+
}
|
|
409
551
|
/**
|
|
410
552
|
* Attributes a compiled MDX module with canonical component identity and discovered dependencies.
|
|
411
553
|
*
|
|
@@ -433,9 +575,9 @@ export function attributeMdxComponentIdentity(contents, filePath, integration, p
|
|
|
433
575
|
return { code: contents, map: previousMap };
|
|
434
576
|
}
|
|
435
577
|
const discovered = discoverComponentImports(program, filePath, projectRoot, { stylesheets });
|
|
436
|
-
const toSourceKey = createSourceKeyResolver(projectRoot);
|
|
578
|
+
const { toSourceKey } = createSourceKeyResolver(projectRoot);
|
|
437
579
|
const sourceKey = toSourceKey(filePath);
|
|
438
|
-
const identityLiteral = createIdentityLiteral(sourceKey, sourceKey, integration);
|
|
580
|
+
const identityLiteral = createIdentityLiteral(createIdentity(sourceKey, sourceKey, integration));
|
|
439
581
|
const plainModuleImports = createPlainModuleComponentImports(discovered);
|
|
440
582
|
const discoveryArgument = serializeDiscoveryArgument(discovered, toSourceKey, plainModuleImports.locals);
|
|
441
583
|
const edits = buildMdxConfigIdentityEdits({
|
|
@@ -477,6 +619,19 @@ function createComponentMetaFilter(config) {
|
|
|
477
619
|
}
|
|
478
620
|
return new RegExp(`(${extensions.map(escapeRegExp).join('|')})(\\?.*)?$`);
|
|
479
621
|
}
|
|
622
|
+
/**
|
|
623
|
+
* Builds the test for whether a module's text can name a stylesheet of `kinds`.
|
|
624
|
+
*
|
|
625
|
+
* @remarks
|
|
626
|
+
* A module no Integration owns is only ever stripped of stylesheet imports, so one whose text names no
|
|
627
|
+
* stylesheet extension needs neither a parse nor the path checks that decide whether it is stripped. The
|
|
628
|
+
* test is a superset of `kinds.isStylesheet`, which compares lowercased names, so it never skips an import
|
|
629
|
+
* that would be stripped.
|
|
630
|
+
*/
|
|
631
|
+
function createStylesheetMentionTest(kinds) {
|
|
632
|
+
const pattern = new RegExp(kinds.extensions.map(escapeRegExp).join('|'), 'i');
|
|
633
|
+
return (code) => pattern.test(code);
|
|
634
|
+
}
|
|
480
635
|
/**
|
|
481
636
|
* Creates the build plugin that attributes component identity in every Integration's script files and
|
|
482
637
|
* removes the stylesheet imports discovery delivers from every local script module.
|
|
@@ -489,24 +644,31 @@ function createComponentMetaFilter(config) {
|
|
|
489
644
|
* discovery has reached it, and it never fails the reach check. A build can transform a
|
|
490
645
|
* plain module before the declaration that imports it, so the check that a declaration reached each
|
|
491
646
|
* module that lost a stylesheet import runs once the whole build is transformed.
|
|
647
|
+
*
|
|
648
|
+
* A transform id is the bundler's resolved module path, so symbolic links are already resolved and the app-root
|
|
649
|
+
* check compares it as it is.
|
|
492
650
|
*/
|
|
493
651
|
export function createEcoComponentMetaPlugin(options) {
|
|
494
652
|
const { integrations, rootDir } = options.config;
|
|
495
653
|
const integrationOf = (file) => findIntegrationForFile(integrations, file);
|
|
496
654
|
const stylesheets = getStylesheetKinds(options.config);
|
|
655
|
+
const mentionsStylesheet = createStylesheetMentionTest(stylesheets);
|
|
497
656
|
return {
|
|
498
657
|
name: 'eco-component-identity-attribution',
|
|
499
658
|
setup(build) {
|
|
500
659
|
const strippedStylesheets = new Map();
|
|
501
660
|
const discoveryCache = createDiscoveryCache();
|
|
502
|
-
const
|
|
661
|
+
const canonicalRoot = fileSystem.exists(rootDir) ? fileSystem.realpath(rootDir) : path.resolve(rootDir);
|
|
662
|
+
const appRoot = `${canonicalRoot}/`;
|
|
503
663
|
build.transform({ filter: /\.[cm]?[jt]sx?(\?.*)?$/ }, (code, rawId) => {
|
|
504
664
|
const id = rawId.replace(/[?#].*$/, '');
|
|
505
665
|
if (id.includes('/node_modules/')) {
|
|
506
666
|
return { code };
|
|
507
667
|
}
|
|
508
668
|
const integration = findIntegrationForFile(integrations, id);
|
|
509
|
-
|
|
669
|
+
if (!integration && !mentionsStylesheet(code))
|
|
670
|
+
return { code };
|
|
671
|
+
const insideApp = id.startsWith(appRoot);
|
|
510
672
|
const stripPlainModuleStylesheets = insideApp || isReachedByDiscovery(rootDir, id);
|
|
511
673
|
if (!integration && !stripPlainModuleStylesheets) {
|
|
512
674
|
return { code };
|
|
@@ -514,6 +676,8 @@ export function createEcoComponentMetaPlugin(options) {
|
|
|
514
676
|
return attributeComponentIdentity(code, id, {
|
|
515
677
|
integration: integration?.name,
|
|
516
678
|
projectRoot: rootDir,
|
|
679
|
+
canonicalProjectRoot: canonicalRoot,
|
|
680
|
+
plainModuleComponentImports: options.environment !== 'browser',
|
|
517
681
|
jsxImportSource: integration?.jsxImportSource,
|
|
518
682
|
integrationOf,
|
|
519
683
|
stripPlainModuleStylesheets,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StaticImport } from './component-import-discovery.js';
|
|
2
|
+
/** One `ecopages:` virtual module a module imports, with its named imports or none for the namespace. */
|
|
3
|
+
export type EcopagesVirtualImport = {
|
|
4
|
+
from: string;
|
|
5
|
+
imports: string[] | undefined;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Lists the `ecopages:` virtual modules among a module's static imports, once each.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Server-only ones are listed too; rendering leaves them out of the browser modules it declares.
|
|
12
|
+
* A module imported for its namespace, its default export or its side effects is listed without named imports,
|
|
13
|
+
* and that wins over named imports of the same module, so module generation imports the whole namespace.
|
|
14
|
+
*/
|
|
15
|
+
export declare function collectEcopagesVirtualImports(imports: readonly StaticImport[]): EcopagesVirtualImport[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lists the `ecopages:` virtual modules among a module's static imports, once each.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Server-only ones are listed too; rendering leaves them out of the browser modules it declares.
|
|
6
|
+
* A module imported for its namespace, its default export or its side effects is listed without named imports,
|
|
7
|
+
* and that wins over named imports of the same module, so module generation imports the whole namespace.
|
|
8
|
+
*/
|
|
9
|
+
export function collectEcopagesVirtualImports(imports) {
|
|
10
|
+
const found = new Map();
|
|
11
|
+
for (const { source, bindings } of imports) {
|
|
12
|
+
if (!source.startsWith('ecopages:') || found.get(source) === null)
|
|
13
|
+
continue;
|
|
14
|
+
const named = bindings.filter(({ imported }) => imported !== 'default').map(({ imported }) => imported);
|
|
15
|
+
if (named.length === 0) {
|
|
16
|
+
found.set(source, null);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const known = found.get(source) ?? new Set();
|
|
20
|
+
for (const name of named)
|
|
21
|
+
known.add(name);
|
|
22
|
+
found.set(source, known);
|
|
23
|
+
}
|
|
24
|
+
return [...found].map(([from, names]) => ({ from, imports: names ? [...names] : undefined }));
|
|
25
|
+
}
|
|
@@ -98,7 +98,7 @@ export declare abstract class IntegrationPlugin<C = EcoPagesElement> {
|
|
|
98
98
|
* filenames.
|
|
99
99
|
*
|
|
100
100
|
* @remarks
|
|
101
|
-
* An Integration whose Pages cannot
|
|
101
|
+
* An Integration whose Pages cannot declare `paths` or read params overrides it with
|
|
102
102
|
* `false`, and route discovery then rejects those filenames instead of failing at render.
|
|
103
103
|
* It describes the Integration, so it is a class member rather than a user option.
|
|
104
104
|
*/
|
|
@@ -33,7 +33,7 @@ export class IntegrationPlugin {
|
|
|
33
33
|
* filenames.
|
|
34
34
|
*
|
|
35
35
|
* @remarks
|
|
36
|
-
* An Integration whose Pages cannot
|
|
36
|
+
* An Integration whose Pages cannot declare `paths` or read params overrides it with
|
|
37
37
|
* `false`, and route discovery then rejects those filenames instead of failing at render.
|
|
38
38
|
* It describes the Integration, so it is a class member rather than a user option.
|
|
39
39
|
*/
|
|
@@ -62,6 +62,8 @@ export declare function resolveRelativeModulePath(fromFile: string, specifier: s
|
|
|
62
62
|
*
|
|
63
63
|
* @remarks
|
|
64
64
|
* A query or hash on the specifier, such as a module variant, is not part of the file and is dropped.
|
|
65
|
+
* oxc-resolver returns native paths, so a result is converted to forward slashes like every other path core
|
|
66
|
+
* compares; it is already real, since the resolver follows symbolic links.
|
|
65
67
|
*/
|
|
66
68
|
export declare function resolveProjectModulePath(projectRoot: string, fromFile: string, moduleSpecifier: string, options?: {
|
|
67
69
|
preserveBarrel?: boolean;
|
|
@@ -300,6 +300,8 @@ export function resolveRelativeModulePath(fromFile, specifier) {
|
|
|
300
300
|
*
|
|
301
301
|
* @remarks
|
|
302
302
|
* A query or hash on the specifier, such as a module variant, is not part of the file and is dropped.
|
|
303
|
+
* oxc-resolver returns native paths, so a result is converted to forward slashes like every other path core
|
|
304
|
+
* compares; it is already real, since the resolver follows symbolic links.
|
|
303
305
|
*/
|
|
304
306
|
export function resolveProjectModulePath(projectRoot, fromFile, moduleSpecifier, options) {
|
|
305
307
|
const specifier = moduleSpecifier.replace(/[?#].*$/u, '');
|
|
@@ -313,13 +315,13 @@ export function resolveProjectModulePath(projectRoot, fromFile, moduleSpecifier,
|
|
|
313
315
|
if (resolver) {
|
|
314
316
|
const result = resolver.sync(path.dirname(fromFile), specifier);
|
|
315
317
|
if (result.path) {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
: resolveAliasedBarrelTarget(fileSystem.realpath(result.path));
|
|
318
|
+
const resolved = path.fromNative(result.path);
|
|
319
|
+
return options?.preserveBarrel ? resolved : resolveAliasedBarrelTarget(resolved);
|
|
319
320
|
}
|
|
320
321
|
}
|
|
321
322
|
if (isRelative) {
|
|
322
|
-
|
|
323
|
+
const relativePath = resolveRelativeModulePath(fromFile, specifier);
|
|
324
|
+
return relativePath && options?.preserveBarrel ? fileSystem.realpath(relativePath) : relativePath;
|
|
323
325
|
}
|
|
324
326
|
return undefined;
|
|
325
327
|
}
|
|
@@ -380,5 +382,5 @@ const packageModuleResolver = new ResolverFactory({
|
|
|
380
382
|
*/
|
|
381
383
|
export function resolvePackageModulePath(fromFile, specifier) {
|
|
382
384
|
const result = packageModuleResolver.sync(path.dirname(fromFile), specifier);
|
|
383
|
-
return result.path ?
|
|
385
|
+
return result.path ? path.fromNative(result.path) : undefined;
|
|
384
386
|
}
|
|
@@ -4,6 +4,7 @@ import { ensureIntegrationRuntimeReady } from '../../build/app-build-manifest-ru
|
|
|
4
4
|
import { hasProductionServerModule } from '../../build/server/server-modules-manifest.js';
|
|
5
5
|
import { findIntegrationForFile } from '../../plugins/find-integration-for-file.js';
|
|
6
6
|
import { prepareExplicitStaticRender } from '../explicit-view-render-preparation.js';
|
|
7
|
+
import { isDynamicPage } from '../../eco/page-data-hooks.js';
|
|
7
8
|
import { ERROR_PAGE_STATUS_BY_KIND, kindForStatus } from '../../errors/http-error-page-contract.js';
|
|
8
9
|
import { buildDefaultErrorHtml, getDefaultServerErrorDetails, getPublicErrorMessage, } from './default-error-pages.js';
|
|
9
10
|
const ERROR_PAGE_RENDER_ERRORS = {
|
|
@@ -17,6 +18,29 @@ function resolveRenderTarget(input) {
|
|
|
17
18
|
kind: input.kind ?? kindForStatus(status),
|
|
18
19
|
};
|
|
19
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Fails for an error page that needs the request pipeline it does not get.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* An error page renders outside the failed request's pipeline, with no request and no middleware, so a Dynamic
|
|
26
|
+
* Page's `props` hook, which is a request handler, cannot run and a `middleware` list would never guard it. Without
|
|
27
|
+
* this check the hook fails deep in render preparation with a message that names no file.
|
|
28
|
+
* @throws When the page is a Dynamic Page that declares `props`, or declares `middleware`.
|
|
29
|
+
*/
|
|
30
|
+
function assertErrorPageRendersWithoutRequest(status, source, page) {
|
|
31
|
+
if (isDynamicPage(page) && hasDeclared(page, 'props')) {
|
|
32
|
+
throw new Error(`[ecopages] The ${status} error page ${source} has cache: 'dynamic' and props, but an error page renders without a request, so its props hook cannot run. Remove props and render from the error page props (status, message), or drop cache: 'dynamic'.`);
|
|
33
|
+
}
|
|
34
|
+
if (hasDeclared(page, 'middleware')) {
|
|
35
|
+
throw new Error(`[ecopages] The ${status} error page ${source} declares middleware, but an error page renders without a request, so no middleware would run. Remove the middleware from the error page.`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function hasDeclared(page, option) {
|
|
39
|
+
if (typeof page !== 'function' || !(option in page))
|
|
40
|
+
return false;
|
|
41
|
+
const value = Reflect.get(page, option);
|
|
42
|
+
return Array.isArray(value) ? value.length > 0 : value !== undefined;
|
|
43
|
+
}
|
|
20
44
|
/**
|
|
21
45
|
* Owns error-page source precedence and rendering for runtime and static paths.
|
|
22
46
|
*
|
|
@@ -86,7 +110,10 @@ export class ErrorPageRenderer {
|
|
|
86
110
|
integrationName: integration.name,
|
|
87
111
|
});
|
|
88
112
|
}
|
|
89
|
-
const
|
|
113
|
+
const renderer = this.routeRendererFactory.getPageRenderer(templatePath);
|
|
114
|
+
const pageModule = await renderer.loadPageModule(templatePath);
|
|
115
|
+
assertErrorPageRendersWithoutRequest(props.status, templatePath, pageModule.default);
|
|
116
|
+
const result = await renderer.execute({
|
|
90
117
|
file: templatePath,
|
|
91
118
|
props,
|
|
92
119
|
locals: {},
|
|
@@ -98,16 +125,18 @@ export class ErrorPageRenderer {
|
|
|
98
125
|
throw new Error(`No route renderer available for __error__/${status}`);
|
|
99
126
|
}
|
|
100
127
|
const view = (await loader()).default;
|
|
101
|
-
|
|
128
|
+
assertErrorPageRendersWithoutRequest(status, loader.filePath ?? `__error__/${status}`, view);
|
|
129
|
+
const { renderer, props: hookProps, view: renderableView, } = await prepareExplicitStaticRender({
|
|
102
130
|
routePath: `__error__/${status}`,
|
|
103
131
|
view,
|
|
132
|
+
viewFile: loader.filePath,
|
|
104
133
|
params: {},
|
|
105
134
|
appConfig: this.appConfig,
|
|
106
135
|
runtimeOrigin: this.appConfig.baseUrl,
|
|
107
136
|
routeRendererFactory: this.routeRendererFactory,
|
|
108
137
|
errors: ERROR_PAGE_RENDER_ERRORS,
|
|
109
138
|
});
|
|
110
|
-
const response = await renderer.renderExplicitView(renderableView, { ...
|
|
139
|
+
const response = await renderer.renderExplicitView(renderableView, { ...hookProps, ...props }, { status });
|
|
111
140
|
return { body: await response.text() };
|
|
112
141
|
}
|
|
113
142
|
getTemplatePath(kind) {
|
|
@@ -7,15 +7,35 @@ type ExplicitStaticRenderPreparationResult = {
|
|
|
7
7
|
view: EcoFunctionComponent<Record<string, unknown>, any>;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Fails for a view that a render without a request cannot serve: one that declares `middleware`, or a Dynamic Page
|
|
11
|
+
* that declares `props`.
|
|
11
12
|
*
|
|
12
13
|
* @remarks
|
|
13
|
-
*
|
|
14
|
+
* `app.static()`, error pages and static generation render a view with no request, so no middleware runs, its
|
|
15
|
+
* layout factories receive no locals, and a Dynamic Page's `props` hook, which is a request handler, cannot run.
|
|
16
|
+
* Ignoring the list would serve the view unguarded while its types promise the locals the guard provides, and a
|
|
17
|
+
* skipped Dynamic Page would build and then fail on every request. Static generation calls this before it skips a
|
|
18
|
+
* Dynamic Page, so both fail the build. `view` is `EcoPageComponent<any>` for the reason given on
|
|
19
|
+
* `readViewPropsWithoutRequest`: a View loader erases the props type.
|
|
20
|
+
* @throws When the view declares a non-empty `middleware` list, or has `cache: 'dynamic'` and `props`, naming the
|
|
21
|
+
* route and the view's file.
|
|
22
|
+
*/
|
|
23
|
+
export declare function assertViewRendersWithoutRequest(routePath: string, view: EcoPageComponent<any>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Resolves the renderer for one explicit view without reading its `props` hook.
|
|
26
|
+
*
|
|
27
|
+
* @remarks
|
|
28
|
+
* Static export planning calls this so a dynamic route whose `props`
|
|
14
29
|
* reads params is not invoked before a slug exists.
|
|
15
30
|
*/
|
|
16
31
|
export declare function resolveExplicitViewRenderer(input: {
|
|
17
32
|
routePath: string;
|
|
18
33
|
view: EcoPageComponent<any>;
|
|
34
|
+
/** Source file the view was loaded from and the app root, when known; the view must declare its Page there. */
|
|
35
|
+
declaredIn?: {
|
|
36
|
+
file: string;
|
|
37
|
+
rootDir: string;
|
|
38
|
+
};
|
|
19
39
|
routeRendererFactory: ExplicitViewRendererResolver;
|
|
20
40
|
errors: {
|
|
21
41
|
missingIntegration(routePath: string): string;
|
|
@@ -26,12 +46,17 @@ export declare function resolveExplicitViewRenderer(input: {
|
|
|
26
46
|
view: EcoFunctionComponent<Record<string, unknown>, any>;
|
|
27
47
|
};
|
|
28
48
|
/**
|
|
29
|
-
* Resolves the renderer and
|
|
49
|
+
* Resolves the renderer and props needed to render one explicit static
|
|
30
50
|
* view at runtime or during static generation.
|
|
51
|
+
*
|
|
52
|
+
* @remarks
|
|
53
|
+
* No request exists here, so the view's `props` hook receives the build context.
|
|
31
54
|
*/
|
|
32
55
|
export declare function prepareExplicitStaticRender(input: {
|
|
33
56
|
routePath: string;
|
|
34
57
|
view: EcoPageComponent<any>;
|
|
58
|
+
/** Source file the view was loaded from, when known. */
|
|
59
|
+
viewFile?: string;
|
|
35
60
|
params: Record<string, string | string[]>;
|
|
36
61
|
appConfig: EcoPagesAppConfig;
|
|
37
62
|
runtimeOrigin: string;
|