prunelle 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/llms.txt +68 -51
- package/package.json +7 -2
- package/src/a11y/declaration.ts +10 -17
- package/src/a11y/index.ts +69 -125
- package/src/animate.ts +127 -0
- package/src/build/asides.ts +51 -0
- package/src/build/bundle.ts +94 -136
- package/src/build/client-entries.ts +6 -6
- package/src/build/client-outputs.ts +75 -0
- package/src/build/client-plugin.ts +9 -4
- package/src/build/ecoindex.ts +4 -2
- package/src/build/files.ts +18 -0
- package/src/build/graph.ts +14 -6
- package/src/build/index.ts +23 -11
- package/src/build/island-promote.ts +42 -2
- package/src/build/islands.ts +63 -9
- package/src/build/key-types.ts +31 -0
- package/src/build/manifest.ts +117 -1
- package/src/build/plugin-host.ts +13 -1
- package/src/build/prerender.ts +8 -3
- package/src/build/reach.ts +18 -4
- package/src/build/report.ts +1 -1
- package/src/build/resolve.ts +5 -1
- package/src/build/route-types.ts +16 -0
- package/src/build/routes.ts +42 -15
- package/src/build/seed-ids.ts +65 -0
- package/src/build/seed-writes.ts +111 -0
- package/src/build/static-headers.ts +2 -2
- package/src/build/static.ts +1 -1
- package/src/cli/check-cache.ts +51 -0
- package/src/cli/check-consent.ts +95 -0
- package/src/cli/check-forms.ts +10 -2
- package/src/cli/check-links-patterns.ts +101 -0
- package/src/cli/check-links.ts +30 -105
- package/src/cli/check-regions.ts +185 -0
- package/src/cli/check-security.ts +50 -6
- package/src/cli/check.ts +49 -21
- package/src/cli/commands.ts +138 -16
- package/src/cli/docs.ts +21 -2
- package/src/cli/form-opaque-children.ts +40 -0
- package/src/cli/index.ts +1 -1
- package/src/cli/inspect.ts +2 -0
- package/src/cli/mcp-tools.ts +2 -2
- package/src/cli/new.ts +9 -5
- package/src/cli/upgrade-names.ts +14 -2
- package/src/cli/upgrade.ts +3 -0
- package/src/compiler/analyze.ts +22 -16
- package/src/compiler/cacheability-private.ts +13 -3
- package/src/compiler/cacheability.ts +24 -2
- package/src/compiler/compliance-contrast.ts +322 -0
- package/src/compiler/compliance-empty.ts +24 -0
- package/src/compiler/compliance-rgaa-content.ts +95 -0
- package/src/compiler/compliance-rgaa-criteria.ts +45 -0
- package/src/compiler/compliance-rgaa-pages.ts +140 -0
- package/src/compiler/compliance-rgaa.ts +19 -0
- package/src/compiler/compliance-rules.ts +72 -0
- package/src/compiler/compliance-third-party.ts +59 -0
- package/src/compiler/compliance-urls.ts +52 -0
- package/src/compiler/compliance.ts +61 -93
- package/src/compiler/cookie-inventory.ts +119 -0
- package/src/compiler/dom-attrs.ts +178 -22
- package/src/compiler/dom.ts +31 -44
- package/src/compiler/emit.ts +17 -6
- package/src/compiler/expr-context.ts +260 -207
- package/src/compiler/foreign-imports.ts +5 -3
- package/src/compiler/mistakes.ts +18 -9
- package/src/compiler/props-body.ts +263 -21
- package/src/compiler/props-pattern.ts +211 -0
- package/src/compiler/props.ts +324 -343
- package/src/compiler/signal-reads.ts +142 -29
- package/src/compiler/spread-handlers.ts +25 -13
- package/src/compiler/ssr-emit.ts +510 -0
- package/src/compiler/ssr-helpers.ts +165 -121
- package/src/compiler/ssr.ts +28 -441
- package/src/context.ts +14 -1
- package/src/dev/child.ts +1 -1
- package/src/dev/host-check.ts +2 -1
- package/src/dev/hot-islands.ts +71 -0
- package/src/dev/index.ts +31 -18
- package/src/dev/protocol.ts +1 -1
- package/src/dev/queue.ts +3 -2
- package/src/dev/reload.ts +5 -2
- package/src/dev/supervisor.ts +3 -1
- package/src/dev/watchers.ts +6 -2
- package/src/dom/action.ts +97 -14
- package/src/dom/attrs.ts +93 -25
- package/src/dom/extras.ts +91 -50
- package/src/dom/field-marks.ts +32 -0
- package/src/dom/hot.ts +9 -0
- package/src/dom/index.ts +44 -18
- package/src/dom/island-hot.ts +29 -0
- package/src/dom/island.ts +13 -2
- package/src/dom/loop.ts +259 -188
- package/src/dom/prefetch.ts +135 -0
- package/src/dom/regions.ts +515 -0
- package/src/dom/swap.ts +246 -0
- package/src/dom/trusted.ts +22 -0
- package/src/dom/upload.ts +44 -0
- package/src/eco/declaration.ts +44 -41
- package/src/eco/index.ts +8 -5
- package/src/href.ts +31 -0
- package/src/index.ts +12 -5
- package/src/plugins/config.ts +1 -1
- package/src/plugins/context.ts +7 -1
- package/src/plugins/daily.ts +27 -0
- package/src/plugins/index.ts +3 -3
- package/src/plugins/order.ts +1 -1
- package/src/plugins/public.ts +12 -5
- package/src/plugins/services.ts +88 -14
- package/src/plugins/types.ts +128 -10
- package/src/reactivity/graph.ts +244 -41
- package/src/reactivity/hmr.ts +101 -0
- package/src/reactivity/index.ts +243 -239
- package/src/reactivity/resource.ts +129 -0
- package/src/reactivity/seed.ts +141 -0
- package/src/reactivity/selector.ts +85 -47
- package/src/reactivity/server-seed.ts +202 -0
- package/src/reactivity/store.ts +331 -97
- package/src/rgpd/draft.ts +171 -0
- package/src/rgpd/forms.ts +85 -0
- package/src/rgpd/index.ts +57 -0
- package/src/server/action-flash.ts +1 -0
- package/src/server/action-protect.ts +3 -0
- package/src/server/action-registry.ts +11 -9
- package/src/server/action.ts +51 -19
- package/src/server/app-secret.ts +14 -8
- package/src/server/cache-invalidation.ts +97 -0
- package/src/server/compress.ts +55 -18
- package/src/server/consent.ts +21 -5
- package/src/server/cookie-inventory.ts +78 -0
- package/src/server/cookies.ts +77 -8
- package/src/server/cors.ts +98 -0
- package/src/server/csp-report.ts +90 -0
- package/src/server/discard.ts +13 -0
- package/src/server/document.ts +2 -2
- package/src/server/env.ts +1 -1
- package/src/server/errors.ts +9 -2
- package/src/server/field-errors.ts +91 -0
- package/src/server/form-schema.ts +16 -11
- package/src/server/health.ts +41 -11
- package/src/server/http.ts +28 -11
- package/src/server/index.ts +122 -307
- package/src/server/loader.ts +2 -0
- package/src/server/page.ts +3 -9
- package/src/server/plugin-host.ts +66 -16
- package/src/server/plugin-route-shadow.ts +24 -0
- package/src/server/public.ts +14 -3
- package/src/server/rate-limit.ts +49 -10
- package/src/server/region.ts +22 -2
- package/src/server/request-handler.ts +406 -0
- package/src/server/request-log.ts +94 -0
- package/src/server/route-cache.ts +55 -8
- package/src/server/route-input.ts +54 -0
- package/src/server/route-table.ts +53 -27
- package/src/server/router.ts +2 -1
- package/src/server/routing.ts +104 -45
- package/src/server/sanitize-html.ts +4 -2
- package/src/server/security.ts +38 -8
- package/src/server/serve-handlers.ts +16 -6
- package/src/server/served-file.ts +19 -14
- package/src/server/shared-store.ts +323 -0
- package/src/server/start.ts +12 -5
- package/src/server/static-dir.ts +34 -12
- package/src/server/stream.ts +2 -1
- package/src/server/surface.ts +39 -0
- package/src/server/webhook.ts +50 -0
- package/src/server/workers.ts +168 -0
- package/src/ssr/consent-banner.ts +20 -16
- package/src/ssr/consent-texts.ts +40 -0
- package/src/ssr/context.ts +174 -53
- package/src/ssr/cookie-table.ts +75 -0
- package/src/ssr/index.ts +63 -58
- package/src/ssr/navigation.ts +161 -14
- package/src/ssr/region.ts +9 -3
- package/src/style.ts +12 -5
- package/src/test/browser.ts +53 -23
- package/src/test/build-reuse.ts +85 -0
- package/src/test/index.ts +51 -8
- package/src/test/mount.ts +53 -0
- package/src/test/outside.ts +94 -0
- package/src/ts-plugin/diagnostics.ts +56 -18
- package/templates/_shared/AGENTS.md +1 -1
- package/templates/_shared/Dockerfile +22 -0
- package/templates/_shared/dockerignore +9 -0
- package/templates/_shared/gitignore +2 -0
- package/templates/app/.env.example +3 -1
- package/templates/app/compose.yaml +32 -0
- package/templates/app/db/migrations/001_notes.sql +7 -0
- package/templates/app/db/schema.ts +11 -0
- package/templates/app/package.json +1 -0
- package/templates/app/prunelle.config.ts +6 -0
- package/templates/app/src/actions/notes.ts +26 -0
- package/templates/app/src/auth.ts +4 -2
- package/templates/app/src/db.ts +5 -0
- package/templates/app/src/routes/dashboard/index.tsx +26 -1
- package/templates/app/src/routes/privacy.tsx +6 -2
- package/templates/app/tests/app.test.ts +14 -3
- package/templates/plugin/AGENTS.md +11 -0
- package/templates/plugin/CLAUDE.md +1 -0
- package/templates/plugin/README.md +27 -0
- package/templates/plugin/gitignore +2 -0
- package/templates/plugin/llms.txt +19 -0
- package/templates/plugin/package.json +33 -0
- package/templates/plugin/src/index.ts +40 -0
- package/templates/plugin/tests/fixture/prunelle.config.ts +4 -0
- package/templates/plugin/tests/fixture/src/routes/index.tsx +11 -0
- package/templates/plugin/tests/plugin.test.ts +42 -0
- package/templates/plugin/tsconfig.json +19 -0
- package/ts-plugin.cjs +4058 -2246
package/src/build/graph.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// The module graph of one build: every .ts/.tsx file reachable from the routes, analyzed once (and reused across `prunelle dev` rebuilds while mtime and size match).
|
|
2
2
|
|
|
3
3
|
import type { ModuleAnalysis } from '../compiler/index'
|
|
4
|
+
import type { Stats } from 'node:fs'
|
|
4
5
|
import { existsSync, readFileSync, statSync } from 'node:fs'
|
|
5
6
|
import { parseTsx } from '../compiler/analyze'
|
|
6
7
|
import { computeJsxNodes } from '../compiler/ast'
|
|
@@ -98,16 +99,23 @@ export function stampFiles(files: Iterable<string>): Map<string, FileStamp> {
|
|
|
98
99
|
for (const file of files) {
|
|
99
100
|
if (out.has(file))
|
|
100
101
|
continue
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
out.set(file, { mtimeMs: st.mtimeMs, size: st.size })
|
|
105
|
-
}
|
|
106
|
-
catch {}
|
|
102
|
+
const st = statOrUndefined(file)
|
|
103
|
+
if (st?.isFile())
|
|
104
|
+
out.set(file, { mtimeMs: st.mtimeMs, size: st.size })
|
|
107
105
|
}
|
|
108
106
|
return out
|
|
109
107
|
}
|
|
110
108
|
|
|
109
|
+
/** A file that vanished or cannot be read has no stamp: the caller treats it as missing. */
|
|
110
|
+
function statOrUndefined(file: string): Stats | undefined {
|
|
111
|
+
try {
|
|
112
|
+
return statSync(file)
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
return undefined
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
111
119
|
export function stampsMatch(inputStamps: ReadonlyMap<string, FileStamp>): boolean {
|
|
112
120
|
for (const [file, prev] of inputStamps) {
|
|
113
121
|
if (!existsSync(file))
|
package/src/build/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ import { copyFileSync, existsSync, mkdirSync, readdirSync, realpathSync, rmSync,
|
|
|
15
15
|
import { basename, dirname, join, relative, resolve } from 'node:path'
|
|
16
16
|
import { checkAppForms } from '../cli/check-forms'
|
|
17
17
|
import { findCachedRoutePrivateReads } from '../compiler/cacheability'
|
|
18
|
-
import { collectProjectComplianceWarnings, pluginSetsLang, shouldEmitWarning } from '../compiler/compliance'
|
|
18
|
+
import { collectProjectComplianceWarnings, pluginChecksTitle, pluginSetsLang, shouldEmitWarning } from '../compiler/compliance'
|
|
19
19
|
import { formatCodeFrame, formatDiagnostic, formatLoc } from '../compiler/shared'
|
|
20
20
|
import { createAppContext, loadConfig, resolvePlugins, runWithAppContext } from '../plugins/index'
|
|
21
21
|
import { actionHash } from '../server/action'
|
|
@@ -28,7 +28,7 @@ import { ModuleGraph } from './graph'
|
|
|
28
28
|
import { nodeEnvWarning, renderProblems, serverNodeEnvReads } from './render-rules'
|
|
29
29
|
import { formatIslandValueWarnings } from './island-promote'
|
|
30
30
|
import { planIslands } from './islands'
|
|
31
|
-
import { buildActionEntries, buildRouteEntries } from './manifest'
|
|
31
|
+
import { appCookiesOf, buildActionEntries, buildRouteEntries, clientBuildId } from './manifest'
|
|
32
32
|
import { createPluginHost, createPublicFiles } from './plugin-host'
|
|
33
33
|
import { carryPreviousAssets } from './carry'
|
|
34
34
|
import { assertOwnOutDir, processSuffix, removeDeadProcessDirs, removeStaleStages, stageDirFor, swapStage } from './output'
|
|
@@ -38,6 +38,7 @@ import { parseByteSize } from './byte-size'
|
|
|
38
38
|
import { SERVER_ENTRY_FILE, serverEntrySource } from './server-entry'
|
|
39
39
|
import { PRUNELLE_SRC_ROOT, resolvePrunelleSpecifier } from './resolve'
|
|
40
40
|
import { ancestorFiles, assertNoRouteConflicts, discoverRouteMatchers, fileToRoutePath, hasRouteHandlerExport, missingPathsProblem, normalizeRoutePattern, routeExportProblem, routeFileProblem, SPECIAL_ROUTE_FILES } from './routes'
|
|
41
|
+
import { writeRouteTypes } from './route-types'
|
|
41
42
|
import { emitStaticNotFoundPages, exportStatic, normalizeAssetPrefix } from './static'
|
|
42
43
|
import { findUnknownStatusPages } from './status-pages'
|
|
43
44
|
import { consolidateStylesheets } from './style-bundles'
|
|
@@ -82,6 +83,8 @@ export interface BuildOptions {
|
|
|
82
83
|
compile?: string | boolean | undefined
|
|
83
84
|
/** Run in development mode (keeps NODE_ENV as development and skips production client asset precompression; auto-detected via PRUNELLE_DEV=1). */
|
|
84
85
|
dev?: boolean | undefined
|
|
86
|
+
/** Split the server bundle across route chunks (defaults to `dev`; false yields one `_entry.js` for clean `?v=` reloads). */
|
|
87
|
+
splitServer?: boolean | undefined
|
|
85
88
|
/** Explicit NODE_ENV threaded through AppRuntimeContext and client defines without mutating process.env. */
|
|
86
89
|
nodeEnv?: string | undefined
|
|
87
90
|
}
|
|
@@ -209,6 +212,7 @@ export async function build(options: BuildOptions): Promise<BuildManifest> {
|
|
|
209
212
|
}
|
|
210
213
|
}
|
|
211
214
|
|
|
215
|
+
|
|
212
216
|
function emitBuildWarnings(run: BuildRun, graph: ModuleGraph, routeFiles: readonly string[]): void {
|
|
213
217
|
for (const [file, analysis] of graph.analyses) {
|
|
214
218
|
const rel = relPosix(run.root, file)
|
|
@@ -220,7 +224,7 @@ function emitBuildWarnings(run: BuildRun, graph: ModuleGraph, routeFiles: readon
|
|
|
220
224
|
}
|
|
221
225
|
}
|
|
222
226
|
if (!run.isDev) {
|
|
223
|
-
const projectWarnings = collectProjectComplianceWarnings({ root: run.root, srcDir: join(run.root, 'src'), routesDir: run.routesDir, publicDir: run.publicDir, routeFiles, analyses: graph.analyses, compliance: run.compliance, consentMaxAge: run.consentMaxAge, site: run.site, lang: run.lang, langFromPlugin: pluginSetsLang(run.plugins) })
|
|
227
|
+
const projectWarnings = collectProjectComplianceWarnings({ root: run.root, srcDir: join(run.root, 'src'), routesDir: run.routesDir, publicDir: run.publicDir, routeFiles, analyses: graph.analyses, compliance: run.compliance, consentMaxAge: run.consentMaxAge, site: run.site, lang: run.lang, langFromPlugin: pluginSetsLang(run.plugins), titleChecked: pluginChecksTitle(run.plugins) })
|
|
224
228
|
for (const warning of projectWarnings)
|
|
225
229
|
console.warn(warning)
|
|
226
230
|
}
|
|
@@ -275,12 +279,7 @@ function refreshCacheWatches(cache: BuildCache, graph: ModuleGraph, extraFiles:
|
|
|
275
279
|
const recordWatched = (file: string) => {
|
|
276
280
|
if (!existsSync(file))
|
|
277
281
|
return
|
|
278
|
-
|
|
279
|
-
try {
|
|
280
|
-
real = realpathSync(file)
|
|
281
|
-
}
|
|
282
|
-
catch {}
|
|
283
|
-
watched.add(real)
|
|
282
|
+
watched.add(realOrSelf(file))
|
|
284
283
|
}
|
|
285
284
|
for (const f of graph.analyses.keys())
|
|
286
285
|
recordWatched(f)
|
|
@@ -417,6 +416,7 @@ async function runBuild(run: BuildRun): Promise<BuildManifest> {
|
|
|
417
416
|
emitBuildWarnings(run, graph, allRouteFiles)
|
|
418
417
|
|
|
419
418
|
const { pageFiles, customMatchers } = validateRoutesAndMatchers(root, routesDir, allRouteFiles, specialFiles, candidateFiles, graph)
|
|
419
|
+
writeRouteTypes(root, routesDir, pageFiles)
|
|
420
420
|
const customMatcherFiles = [...new Set(customMatchers.values())]
|
|
421
421
|
|
|
422
422
|
const actionsByFile = collectActionsByFile(graph, root, assetPrefix)
|
|
@@ -434,7 +434,7 @@ async function runBuild(run: BuildRun): Promise<BuildManifest> {
|
|
|
434
434
|
.map(c => resolve(root, c))
|
|
435
435
|
.filter(c => existsSync(c))
|
|
436
436
|
const wantsAnalyze = wantsBundleAnalysis(run)
|
|
437
|
-
const env = { root, outDir, clientDir, serverDir, assetPrefix, lang: run.lang, minify: run.minify, isDev, nodeEnv: run.nodeEnv, analyze: wantsAnalyze, graph, cache: options.cache, plugins, actionsByFile, islands }
|
|
437
|
+
const env = { root, outDir, clientDir, serverDir, assetPrefix, lang: run.lang, minify: run.minify, isDev, splitServer: options.splitServer ?? isDev, nodeEnv: run.nodeEnv, analyze: wantsAnalyze, graph, cache: options.cache, plugins, actionsByFile, islands }
|
|
438
438
|
|
|
439
439
|
const routeEntryFiles = new Set([...specialFiles, ...pageFiles])
|
|
440
440
|
const standaloneActionFiles = [...actionsByFile.keys()].filter(f => !routeEntryFiles.has(f))
|
|
@@ -489,7 +489,7 @@ async function runBuild(run: BuildRun): Promise<BuildManifest> {
|
|
|
489
489
|
copyPublicFiles(run.publicDir, outPublicDir, publicFiles, options.copyPublic !== false)
|
|
490
490
|
|
|
491
491
|
const host = createPluginHost({
|
|
492
|
-
plugins, appCtx: run.appCtx, root, outDir, clientDir, outPublicDir, assetPrefix, site: run.site, minify: run.minify,
|
|
492
|
+
plugins, appCtx: run.appCtx, root, routesDir, outDir, clientDir, outPublicDir, assetPrefix, site: run.site, minify: run.minify,
|
|
493
493
|
isStatic, isDev, routes, statusPages, routeSourceFiles, globalSourceFiles, publicFiles, assets, styleUrls: client.styleUrls, globalStyles,
|
|
494
494
|
})
|
|
495
495
|
await host.runBuild()
|
|
@@ -517,7 +517,9 @@ async function runBuild(run: BuildRun): Promise<BuildManifest> {
|
|
|
517
517
|
assets,
|
|
518
518
|
publicFiles: publicFiles.files,
|
|
519
519
|
...(Object.keys(host.pluginData).length > 0 ? { pluginData: host.pluginData } : {}),
|
|
520
|
+
...appCookiesOf(graph),
|
|
520
521
|
}
|
|
522
|
+
manifest.buildId = clientBuildId(manifest)
|
|
521
523
|
const writeManifest = (): void => writeFileSync(join(outDir, 'manifest.json'), JSON.stringify(manifest, null, 2))
|
|
522
524
|
writeManifest()
|
|
523
525
|
const analyzeOrigins = wantsAnalyze
|
|
@@ -675,3 +677,13 @@ function relocateCache(cache: BuildCache | undefined, from: string, to: string):
|
|
|
675
677
|
if (assets !== undefined)
|
|
676
678
|
assets.clientDir = moved(assets.clientDir)
|
|
677
679
|
}
|
|
680
|
+
|
|
681
|
+
// A file removed between the existence check and this call keeps the path it was found at.
|
|
682
|
+
function realOrSelf(file: string): string {
|
|
683
|
+
try {
|
|
684
|
+
return realpathSync(file)
|
|
685
|
+
}
|
|
686
|
+
catch {
|
|
687
|
+
return file
|
|
688
|
+
}
|
|
689
|
+
}
|
|
@@ -62,6 +62,31 @@ export function resolveExportTarget(
|
|
|
62
62
|
return { file, exportName }
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
/** The module a namespace stands for once exported by `file` as `name`: `export * as name from './m'`, or `import * as name from './m'` then `export { name }`, through any re-export chain. */
|
|
66
|
+
export function resolveNamespaceModule(graph: ModuleGraph, load: LoadModule, file: string, name: string, depth = 0): string | undefined {
|
|
67
|
+
if (depth > MAX_REEXPORT_DEPTH)
|
|
68
|
+
return undefined
|
|
69
|
+
const analysis = load(file)
|
|
70
|
+
if (analysis === undefined)
|
|
71
|
+
return undefined
|
|
72
|
+
const direct = analysis.reexports.find(r => r.exported === name)
|
|
73
|
+
if (direct !== undefined) {
|
|
74
|
+
const next = graph.resolve(file, direct.source)
|
|
75
|
+
if (next === undefined || !isTsFile(next))
|
|
76
|
+
return undefined
|
|
77
|
+
return direct.local === '*' ? next : resolveNamespaceModule(graph, load, next, direct.local, depth + 1)
|
|
78
|
+
}
|
|
79
|
+
for (const re of analysis.reexports) {
|
|
80
|
+
if (re.exported !== '*')
|
|
81
|
+
continue
|
|
82
|
+
const next = graph.resolve(file, re.source)
|
|
83
|
+
const found = next !== undefined && isTsFile(next) ? resolveNamespaceModule(graph, load, next, name, depth + 1) : undefined
|
|
84
|
+
if (found !== undefined)
|
|
85
|
+
return found
|
|
86
|
+
}
|
|
87
|
+
return undefined
|
|
88
|
+
}
|
|
89
|
+
|
|
65
90
|
export function moduleHasInteractiveExport(graph: ModuleGraph, load: LoadModule, file: string, seen = new Set<string>()): boolean {
|
|
66
91
|
if (seen.has(file))
|
|
67
92
|
return false
|
|
@@ -75,7 +100,7 @@ export function moduleHasInteractiveExport(graph: ModuleGraph, load: LoadModule,
|
|
|
75
100
|
const next = graph.resolve(file, re.source)
|
|
76
101
|
if (next === undefined || !isTsFile(next))
|
|
77
102
|
continue
|
|
78
|
-
if (re.
|
|
103
|
+
if (re.local === '*') {
|
|
79
104
|
if (moduleHasInteractiveExport(graph, load, next, seen))
|
|
80
105
|
return true
|
|
81
106
|
}
|
|
@@ -135,6 +160,20 @@ const COMPONENT_NAME_RE = /^[A-Z]/
|
|
|
135
160
|
const allValueReads = (analysis: ModuleAnalysis, local: string): number[] =>
|
|
136
161
|
analysis.bindings.map(b => b.valueRefs.get(local)).filter((offset): offset is number => offset !== undefined)
|
|
137
162
|
|
|
163
|
+
// Where `local` is the whole initialiser of an exported `const`, which re-exports it under that name instead of reading it.
|
|
164
|
+
function exportAliasStarts(analysis: ModuleAnalysis, local: string): Set<number> {
|
|
165
|
+
const starts = new Set<number>()
|
|
166
|
+
for (const stmt of analysis.program.body) {
|
|
167
|
+
if (stmt.type !== 'ExportNamedDeclaration' || stmt.declaration?.type !== 'VariableDeclaration')
|
|
168
|
+
continue
|
|
169
|
+
for (const d of stmt.declaration.declarations) {
|
|
170
|
+
if (d.id.type === 'Identifier' && d.init?.type === 'Identifier' && d.init.name === local)
|
|
171
|
+
starts.add(d.init.start)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return starts
|
|
175
|
+
}
|
|
176
|
+
|
|
138
177
|
// All unshadowed non-JSX value reads of `local` in `analysis.program`, used only when a line-ignore hides the first recorded offset.
|
|
139
178
|
function allProgramValueReads(analysis: ModuleAnalysis, local: string): number[] {
|
|
140
179
|
const offsets: number[] = []
|
|
@@ -234,7 +273,8 @@ export function createPromoter(
|
|
|
234
273
|
const recordValueUses = (file: string, analysis: ModuleAnalysis): void => {
|
|
235
274
|
for (const imp of analysis.imports) {
|
|
236
275
|
for (const spec of imp.specifiers) {
|
|
237
|
-
const
|
|
276
|
+
// `export const Y = B` is a re-export under another name, followed like `export { B as Y }`, not a value read.
|
|
277
|
+
const offsets = spec.imported === '*' || !COMPONENT_NAME_RE.test(spec.local) ? [] : allValueReads(analysis, spec.local).filter(o => !exportAliasStarts(analysis, spec.local).has(o))
|
|
238
278
|
if (offsets.length === 0 || reportedValueUses.has(`${file}#${spec.local}`) || interactiveKind(file, imp.source, spec.imported) !== 'export')
|
|
239
279
|
continue
|
|
240
280
|
reportedValueUses.add(`${file}#${spec.local}`)
|
package/src/build/islands.ts
CHANGED
|
@@ -2,17 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import type { ModuleAnalysis } from '../compiler/analyze'
|
|
4
4
|
import type { ServerOnlyInIsland } from '../compiler/interactivity'
|
|
5
|
+
import type { CompilerWarning } from '../compiler/mistakes'
|
|
5
6
|
import type { ModuleGraph } from './graph'
|
|
6
7
|
import type { IslandValueUse, LoadModule, PromotedWarning } from './island-promote'
|
|
7
8
|
import { basename, extname } from 'node:path'
|
|
8
9
|
import { asyncInteractiveError } from '../compiler/analyze'
|
|
9
10
|
import { findCrossFileServerOnly } from '../compiler/interactivity'
|
|
10
11
|
import { collectMistakes, serverOnlyTagError } from '../compiler/mistakes'
|
|
12
|
+
import { checkBodyPropsDestructure } from '../compiler/props-body'
|
|
11
13
|
import { findPrivateEnv, isServerOnlyModule } from '../compiler/server-only'
|
|
12
14
|
import { checkBareSignals } from '../compiler/signal-reads'
|
|
13
15
|
import { clientNeeds, clientView } from './client-prune'
|
|
14
16
|
import { isInNodeModules, isTsFile, relPosix } from './files'
|
|
15
|
-
import { collectExportedSignals, createPromoter, resolveExportTarget } from './island-promote'
|
|
17
|
+
import { collectExportedSignals, createPromoter, resolveExportTarget, resolveNamespaceModule } from './island-promote'
|
|
18
|
+
import { writesModuleState } from './seed-writes'
|
|
16
19
|
|
|
17
20
|
/** A component that is not an island, as a module renders it. */
|
|
18
21
|
export interface StaticTag { async: boolean }
|
|
@@ -59,6 +62,8 @@ export interface IslandPlan {
|
|
|
59
62
|
valueUses: IslandValueUse[]
|
|
60
63
|
/** Compiler warnings triggered once a route is promoted to an island across files. */
|
|
61
64
|
promotedWarnings: PromotedWarning[]
|
|
65
|
+
/** Some module could write a module-level signal or store while an island renders on the server, so the page carries what it wrote. */
|
|
66
|
+
seedsModuleState: boolean
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
export interface AnalyzeIslandsOptions {
|
|
@@ -75,6 +80,7 @@ export interface AnalyzeIslandsOptions {
|
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
const EMPTY_SET = new Set<string>()
|
|
83
|
+
const UNSAFE_ID_CHARS_RE = /[^a-z0-9_.-]/g
|
|
78
84
|
|
|
79
85
|
export function islandKey(target: { file: string, exportName: string }): string {
|
|
80
86
|
return `${target.file}#${target.exportName}`
|
|
@@ -136,6 +142,19 @@ function checkCrossFileServerOnlyTags(graph: ModuleGraph, load: LoadModule, issu
|
|
|
136
142
|
}
|
|
137
143
|
}
|
|
138
144
|
|
|
145
|
+
/** The export a rendered tag stands for when `spec` imports it: `<Counter />`, `<UI.Counter />`, or a namespace exported on, as in `<inner.B />` and `<W.X.B />`. */
|
|
146
|
+
function tagTarget(graph: ModuleGraph, load: LoadModule, spec: { local: string, imported: string }, resolved: string, tag: string): { file: string, exportName: string } | undefined {
|
|
147
|
+
if (tag === spec.local)
|
|
148
|
+
return spec.imported === '*' ? undefined : resolveExportTarget(graph, load, resolved, spec.imported)
|
|
149
|
+
if (!tag.startsWith(`${spec.local}.`))
|
|
150
|
+
return undefined
|
|
151
|
+
const path = tag.slice(spec.local.length + 1).split('.')
|
|
152
|
+
let module: string | undefined = spec.imported === '*' ? resolved : resolveNamespaceModule(graph, load, resolved, spec.imported)
|
|
153
|
+
for (const segment of path.slice(0, -1))
|
|
154
|
+
module = module === undefined ? undefined : resolveNamespaceModule(graph, load, module, segment)
|
|
155
|
+
return module === undefined ? undefined : resolveExportTarget(graph, load, module, path.at(-1)!)
|
|
156
|
+
}
|
|
157
|
+
|
|
139
158
|
function discoverBindings(
|
|
140
159
|
graph: ModuleGraph,
|
|
141
160
|
load: LoadModule,
|
|
@@ -165,11 +184,8 @@ function discoverBindings(
|
|
|
165
184
|
if (resolved === undefined || !isTsFile(resolved))
|
|
166
185
|
continue
|
|
167
186
|
for (const spec of imp.specifiers) {
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
: analysis.staticJsxTags.has(spec.local) ? [[spec.local, spec.imported] as const] : []
|
|
171
|
-
for (const [tag, exportName] of tags) {
|
|
172
|
-
const target = resolveExportTarget(graph, load, resolved, exportName)
|
|
187
|
+
for (const tag of analysis.staticJsxTags) {
|
|
188
|
+
const target = tagTarget(graph, load, spec, resolved, tag)
|
|
173
189
|
const component = target?.file.endsWith('.tsx') === true ? loadPromoted(target.file) : undefined
|
|
174
190
|
if (target === undefined || component === undefined)
|
|
175
191
|
continue
|
|
@@ -329,6 +345,42 @@ function walkIslandReach(
|
|
|
329
345
|
return { reach, clientFiles: visited, cssFiles }
|
|
330
346
|
}
|
|
331
347
|
|
|
348
|
+
function checkCrossFileBrowserWarnings(
|
|
349
|
+
graph: ModuleGraph,
|
|
350
|
+
root: string,
|
|
351
|
+
reach: ReadonlySet<string>,
|
|
352
|
+
clientFiles: ReadonlySet<string>,
|
|
353
|
+
promotedWarnings: PromotedWarning[],
|
|
354
|
+
): void {
|
|
355
|
+
const checked = new Set<string>(clientFiles)
|
|
356
|
+
for (const [file, analysis] of graph.analyses) {
|
|
357
|
+
if (analysis.browserSpans.length > 0)
|
|
358
|
+
checked.add(file)
|
|
359
|
+
}
|
|
360
|
+
for (const file of checked) {
|
|
361
|
+
if (isInNodeModules(file) || !file.endsWith('.tsx'))
|
|
362
|
+
continue
|
|
363
|
+
const analysis = graph.analyses.get(file)
|
|
364
|
+
if (analysis === undefined || !analysis.hasJsx)
|
|
365
|
+
continue
|
|
366
|
+
const code = graph.source(file)
|
|
367
|
+
const spans: readonly [number, number][] = reach.has(file) ? [[0, code.length]] : analysis.browserSpans
|
|
368
|
+
if (spans.length === 0)
|
|
369
|
+
continue
|
|
370
|
+
const rel = relPosix(root, file)
|
|
371
|
+
const existing = new Set(analysis.warnings.map(w => `${w.start}\0${w.message.replaceAll(file, rel)}`))
|
|
372
|
+
const extra: CompilerWarning[] = []
|
|
373
|
+
checkBodyPropsDestructure(analysis.program, code, spans, analysis.jsxNodes, analysis.filename, extra)
|
|
374
|
+
for (const warning of extra) {
|
|
375
|
+
const key = `${warning.start}\0${warning.message.replaceAll(file, rel)}`
|
|
376
|
+
if (!existing.has(key)) {
|
|
377
|
+
existing.add(key)
|
|
378
|
+
promotedWarnings.push({ file, warning })
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
332
384
|
/** Shared island planning and reachability analyzer used by both `prunelle build` and `prunelle check`. */
|
|
333
385
|
export function analyzeIslands(options: AnalyzeIslandsOptions): IslandPlan {
|
|
334
386
|
const { graph, root, pageFiles, specialFiles } = options
|
|
@@ -344,8 +396,9 @@ export function analyzeIslands(options: AnalyzeIslandsOptions): IslandPlan {
|
|
|
344
396
|
const existing = targets.get(key)
|
|
345
397
|
if (existing !== undefined)
|
|
346
398
|
return existing
|
|
347
|
-
|
|
348
|
-
const
|
|
399
|
+
// The id lands in a chunk URL, so a name holding `%`, `#`, `?`, `&` or the like keeps only letters, digits, `_`, `.` and `-`.
|
|
400
|
+
const baseName = basename(file, extname(file)).toLowerCase().replace(UNSAFE_ID_CHARS_RE, '-')
|
|
401
|
+
const expLower = exportName.toLowerCase().replace(UNSAFE_ID_CHARS_RE, '-')
|
|
349
402
|
let id = exportName === 'default' || expLower === baseName ? baseName : `${baseName}-${expLower}`
|
|
350
403
|
// The id names the entry file and the chunk: two islands sharing a basename (or 'runtime') keep it readable and add a hash of their path.
|
|
351
404
|
if (usedIds.has(id))
|
|
@@ -403,7 +456,8 @@ export function analyzeIslands(options: AnalyzeIslandsOptions): IslandPlan {
|
|
|
403
456
|
}
|
|
404
457
|
|
|
405
458
|
const { reach, clientFiles, cssFiles } = walkIslandReach(graph, load, [...rootFiles], clientKeep, options.checkLeaks === true, issues)
|
|
406
|
-
|
|
459
|
+
checkCrossFileBrowserWarnings(graph, root, reach, clientFiles, promotedWarnings)
|
|
460
|
+
return { targets, pageBindings, staticTags, cssFiles, reach, clientFiles, clientKeep, issues, valueUses, promotedWarnings, seedsModuleState: writesModuleState(graph) }
|
|
407
461
|
}
|
|
408
462
|
|
|
409
463
|
function clientKeepOf(targets: Iterable<IslandTarget>, load: LoadModule): Map<string, Set<string>> {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Declaration files that give an interface one key per entry, written beside the app's routes folder: the route patterns, a plugin's message keys.
|
|
2
|
+
// Kept free of the compiler, so `prunelle/config` can export it to plugins.
|
|
3
|
+
|
|
4
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { dirname, join } from 'node:path'
|
|
6
|
+
|
|
7
|
+
export interface KeyTypes {
|
|
8
|
+
/** The file written beside the routes folder, such as `'prunelle-routes.d.ts'`. */
|
|
9
|
+
file: string
|
|
10
|
+
/** The first line, saying what wrote the file and from what. */
|
|
11
|
+
header: string
|
|
12
|
+
/** The module the interface augments, such as `'prunelle/server'`. */
|
|
13
|
+
module: string
|
|
14
|
+
interface: string
|
|
15
|
+
keys: readonly string[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function keyTypesSource({ header, module, interface: name, keys }: KeyTypes): string {
|
|
19
|
+
const entries = [...new Set(keys)].sort().map(key => ` ${JSON.stringify(key)}: true`)
|
|
20
|
+
return [`// ${header} Edits are overwritten.`, 'export {}', '', `declare module '${module}' {`, ` interface ${name} {`, ...entries, ' }', '}', ''].join('\n')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Writes the file beside the routes folder of an app with a tsconfig.json, only when it changed, so a dev rebuild never sets off another. */
|
|
24
|
+
export function writeKeyTypes(root: string, routesDir: string, types: KeyTypes): void {
|
|
25
|
+
if (!existsSync(join(root, 'tsconfig.json')))
|
|
26
|
+
return
|
|
27
|
+
const file = join(dirname(routesDir), types.file)
|
|
28
|
+
const source = keyTypesSource(types)
|
|
29
|
+
if (!existsSync(file) || readFileSync(file, 'utf8') !== source)
|
|
30
|
+
writeFileSync(file, source)
|
|
31
|
+
}
|
package/src/build/manifest.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// The build manifest: its shape, and the per-route entries (islands, styles, layouts, middlewares) computed from the module graph.
|
|
2
2
|
|
|
3
|
+
import type { AppCookie } from '../compiler/cookie-inventory'
|
|
3
4
|
import type { RouteCacheSpec } from '../server/route-cache'
|
|
4
5
|
import type { ModuleGraph } from './graph'
|
|
5
6
|
import type { IslandPlan } from './islands'
|
|
6
7
|
import type { StatusPageManifestEntry } from './status-pages'
|
|
7
8
|
import { join } from 'node:path'
|
|
8
9
|
import { isRouteCacheable } from '../compiler/cacheability'
|
|
10
|
+
import { mergeCookies, scanCookieSets } from '../compiler/cookie-inventory'
|
|
9
11
|
import { isInside } from './is-inside'
|
|
10
12
|
import { createReachWalker } from './reach'
|
|
11
13
|
import { ancestorFiles, fileToRoutePath, MIDDLEWARE_NAMES } from './routes'
|
|
@@ -27,6 +29,8 @@ export interface RouteManifestEntry {
|
|
|
27
29
|
file: string
|
|
28
30
|
layouts: string[]
|
|
29
31
|
middlewares: string[]
|
|
32
|
+
/** True when the route is an API endpoint (exports no `default` page or handles `GET` directly). */
|
|
33
|
+
isApi?: boolean | undefined
|
|
30
34
|
hasLoad?: boolean | undefined
|
|
31
35
|
isIsland?: boolean | undefined
|
|
32
36
|
islandChunk?: string | undefined
|
|
@@ -42,6 +46,10 @@ export interface RouteManifestEntry {
|
|
|
42
46
|
usesRenderContext?: boolean | undefined
|
|
43
47
|
/** The route, a layout or a component it renders imports `<Region>`. */
|
|
44
48
|
usesRegion?: boolean | undefined
|
|
49
|
+
/** `false` when static analysis proves no reachable module can emit `data-pru-keep-scroll`. */
|
|
50
|
+
usesKeepScroll?: boolean | undefined
|
|
51
|
+
/** `false` when static analysis proves no reachable module reads `currentRequest()` or calls a server action. */
|
|
52
|
+
usesRequestScope?: boolean | undefined
|
|
45
53
|
prerender?: boolean | undefined
|
|
46
54
|
/** Prerendered only because `autoPrerender` found it static, so the build may render it at request time instead. */
|
|
47
55
|
autoPrerender?: boolean | undefined
|
|
@@ -55,8 +63,10 @@ export interface RouteManifestEntry {
|
|
|
55
63
|
}
|
|
56
64
|
|
|
57
65
|
export interface BuildManifest {
|
|
66
|
+
/** Names what the browser of this build loads, its hashed scripts and stylesheets: a page from another build cannot take this one's region markup. */
|
|
67
|
+
buildId?: string | undefined
|
|
58
68
|
runtimeScript: string | undefined
|
|
59
|
-
/** The
|
|
69
|
+
/** The core `<Region>` client bundle, loaded by routes with `usesRegion`. */
|
|
60
70
|
regionScript?: string | undefined
|
|
61
71
|
/** The prop revivers, preloaded by a page whose island props hold a Date, Map, Set or another tagged value. */
|
|
62
72
|
reviveScript?: string | undefined
|
|
@@ -81,6 +91,8 @@ export interface BuildManifest {
|
|
|
81
91
|
actions: ActionManifestEntry[]
|
|
82
92
|
islands: Record<string, string>
|
|
83
93
|
assets: string[]
|
|
94
|
+
/** The app's cookies read from its `cookies.set` calls, for `<CookieTable>`. */
|
|
95
|
+
cookies?: AppCookie[] | undefined
|
|
84
96
|
/** The previous build's client files this one dropped, kept one more deploy for pages loaded before it (#3663); never linked from a page. */
|
|
85
97
|
carriedAssets?: string[] | undefined
|
|
86
98
|
publicFiles: string[]
|
|
@@ -101,6 +113,82 @@ export interface RouteEntries {
|
|
|
101
113
|
globalSourceFiles: string[]
|
|
102
114
|
}
|
|
103
115
|
|
|
116
|
+
const JSX_SPREAD_RE = /\{\s*\.\.\./
|
|
117
|
+
const RAW_SPECIFIERS = new Set(['raw', '*'])
|
|
118
|
+
const REQUEST_SCOPE_SPECIFIERS = new Set(['currentRequest', 'action', 'getActionError', 'getLocale', 'ConsentBanner', 'ConsentPreferences', 'CookieTable', '*'])
|
|
119
|
+
|
|
120
|
+
function isKnownSafeExternal(source: string): boolean {
|
|
121
|
+
return source === 'prunelle' || source.startsWith('prunelle/') || source.startsWith('node:') || source === 'bun' || source.endsWith('.css')
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function createRouteFlagScanner(graph: ModuleGraph): (file: string) => { keepScroll: boolean, requestScope: boolean } {
|
|
125
|
+
const memo = new Map<string, { keepScroll: boolean, requestScope: boolean }>()
|
|
126
|
+
return (file: string) => {
|
|
127
|
+
const cached = memo.get(file)
|
|
128
|
+
if (cached !== undefined)
|
|
129
|
+
return cached
|
|
130
|
+
const analysis = graph.analyses.get(file)
|
|
131
|
+
if (analysis === undefined) {
|
|
132
|
+
const unknown = { keepScroll: true, requestScope: true }
|
|
133
|
+
memo.set(file, unknown)
|
|
134
|
+
return unknown
|
|
135
|
+
}
|
|
136
|
+
const code = graph.source(file)
|
|
137
|
+
let keepScroll = code.includes('data-pru-keep-scroll')
|
|
138
|
+
|| code.includes('innerHTML')
|
|
139
|
+
|| code.includes('dangerouslySetInnerHTML')
|
|
140
|
+
|| code.includes('pru.html')
|
|
141
|
+
|| code.includes('require(')
|
|
142
|
+
|| JSX_SPREAD_RE.test(code)
|
|
143
|
+
|| analysis.dynamicImports.length > 0
|
|
144
|
+
let requestScope = code.includes('currentRequest')
|
|
145
|
+
|| code.includes('pru.request')
|
|
146
|
+
|| code.includes('require(')
|
|
147
|
+
|| analysis.dynamicImports.length > 0
|
|
148
|
+
|
|
149
|
+
for (const imp of analysis.imports) {
|
|
150
|
+
if (keepScroll && requestScope)
|
|
151
|
+
break
|
|
152
|
+
if (graph.resolve(file, imp.source) !== undefined)
|
|
153
|
+
continue
|
|
154
|
+
if (!isKnownSafeExternal(imp.source)) {
|
|
155
|
+
keepScroll = true
|
|
156
|
+
requestScope = true
|
|
157
|
+
break
|
|
158
|
+
}
|
|
159
|
+
if (imp.source === 'prunelle' || imp.source.startsWith('prunelle/')) {
|
|
160
|
+
for (const spec of imp.specifiers) {
|
|
161
|
+
if (RAW_SPECIFIERS.has(spec.imported))
|
|
162
|
+
keepScroll = true
|
|
163
|
+
if (REQUEST_SCOPE_SPECIFIERS.has(spec.imported))
|
|
164
|
+
requestScope = true
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if ((!keepScroll || !requestScope) && analysis.reexports !== undefined) {
|
|
169
|
+
for (const re of analysis.reexports) {
|
|
170
|
+
if (graph.resolve(file, re.source) !== undefined)
|
|
171
|
+
continue
|
|
172
|
+
if (!isKnownSafeExternal(re.source)) {
|
|
173
|
+
keepScroll = true
|
|
174
|
+
requestScope = true
|
|
175
|
+
break
|
|
176
|
+
}
|
|
177
|
+
if (re.source === 'prunelle' || re.source.startsWith('prunelle/')) {
|
|
178
|
+
if (re.local === '*' || RAW_SPECIFIERS.has(re.local))
|
|
179
|
+
keepScroll = true
|
|
180
|
+
if (re.local === '*' || REQUEST_SCOPE_SPECIFIERS.has(re.local))
|
|
181
|
+
requestScope = true
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const result = { keepScroll, requestScope }
|
|
187
|
+
memo.set(file, result)
|
|
188
|
+
return result
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
104
192
|
export function buildRouteEntries(options: {
|
|
105
193
|
graph: ModuleGraph
|
|
106
194
|
islands: IslandPlan
|
|
@@ -119,6 +207,7 @@ export function buildRouteEntries(options: {
|
|
|
119
207
|
}): RouteEntries {
|
|
120
208
|
const { graph, islands, islandChunks, routesDir, toOutRel } = options
|
|
121
209
|
const reachOf = createReachWalker(graph, islands, islandChunks, options.srcCssToUrl, options.islandCssUrl)
|
|
210
|
+
const scanFlags = createRouteFlagScanner(graph)
|
|
122
211
|
|
|
123
212
|
const globalPluginStyles = [...new Set(options.pluginCssFiles.map(css => options.srcCssToUrl.get(css)).filter((url): url is string => url !== undefined))]
|
|
124
213
|
const rootLayout = join(routesDir, '_layout.tsx')
|
|
@@ -151,15 +240,28 @@ export function buildRouteEntries(options: {
|
|
|
151
240
|
}
|
|
152
241
|
const routePath = fileToRoutePath(routesDir, file)
|
|
153
242
|
routeSourceFiles.set(routePath, [...reachableFiles])
|
|
243
|
+
let usesKeepScroll = false
|
|
244
|
+
let usesRequestScope = false
|
|
245
|
+
for (const f of reachableFiles) {
|
|
246
|
+
const flags = scanFlags(f)
|
|
247
|
+
if (flags.keepScroll)
|
|
248
|
+
usesKeepScroll = true
|
|
249
|
+
if (flags.requestScope)
|
|
250
|
+
usesRequestScope = true
|
|
251
|
+
if (usesKeepScroll && usesRequestScope)
|
|
252
|
+
break
|
|
253
|
+
}
|
|
154
254
|
const middlewareSrcs = ancestorFiles(routesDir, file, MIDDLEWARE_NAMES)
|
|
155
255
|
const cacheable = isRouteCacheable({ graph, islands, file, layoutSrcs, middlewareCount: middlewareSrcs.length, routePath })
|
|
156
256
|
const cache = analysis?.cache
|
|
157
257
|
const autoPre = options.autoPrerender === true && cacheable && cache === undefined
|
|
258
|
+
const isApi = analysis !== undefined && (!analysis.exportedNames.includes('default') || analysis.exportedNames.includes('GET'))
|
|
158
259
|
return {
|
|
159
260
|
path: routePath,
|
|
160
261
|
file: toOutRel(file),
|
|
161
262
|
layouts: layoutSrcs.map(toOutRel),
|
|
162
263
|
middlewares: middlewareSrcs.map(toOutRel),
|
|
264
|
+
...(isApi ? { isApi: true } : {}),
|
|
163
265
|
hasLoad: analysis?.hasLoadExport,
|
|
164
266
|
isIsland: page?.interactive,
|
|
165
267
|
islandChunk: islandChunks.get(`${file}#default`),
|
|
@@ -170,6 +272,8 @@ export function buildRouteEntries(options: {
|
|
|
170
272
|
styles: [...styles],
|
|
171
273
|
usesRenderContext,
|
|
172
274
|
usesRegion,
|
|
275
|
+
...(usesKeepScroll ? {} : { usesKeepScroll: false }),
|
|
276
|
+
...(usesRequestScope ? {} : { usesRequestScope: false }),
|
|
173
277
|
prerender: analysis?.hasPrerender || options.isStatic || autoPre,
|
|
174
278
|
...(autoPre && analysis?.hasPrerender !== true && !options.isStatic ? { autoPrerender: true } : {}),
|
|
175
279
|
...(cache !== undefined ? { cache } : {}),
|
|
@@ -202,3 +306,15 @@ export function buildActionEntries(actionsByFile: Map<string, { exportName: stri
|
|
|
202
306
|
}
|
|
203
307
|
return entries
|
|
204
308
|
}
|
|
309
|
+
|
|
310
|
+
/** The same for two builds whose pages load the same client files and head tags, each client file being named by its content hash. */
|
|
311
|
+
export function clientBuildId(manifest: BuildManifest): string {
|
|
312
|
+
return Bun.hash(JSON.stringify([manifest.assets.toSorted(), manifest.headTags])).toString(36)
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** What `<CookieTable>` lists of the app's own cookies, from each module's `cookies.set` calls. */
|
|
316
|
+
export function appCookiesOf(graph: ModuleGraph): Pick<BuildManifest, 'cookies'> {
|
|
317
|
+
const files = [...graph.analyses.keys()].sort()
|
|
318
|
+
const cookies = mergeCookies(files.flatMap(file => scanCookieSets(file, graph.source(file), graph.analyses.get(file)!.program)))
|
|
319
|
+
return cookies.length > 0 ? { cookies: cookies.map(({ file: _file, start: _start, ...cookie }) => cookie) } : {}
|
|
320
|
+
}
|
package/src/build/plugin-host.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import type { AppRuntimeContext } from '../plugins/context'
|
|
4
4
|
import type { BuildPluginContext, FinalizeBuildContext, PrunellePlugin } from '../plugins/index'
|
|
5
5
|
import type { RouteManifestEntry, StatusPageManifestEntry } from './manifest'
|
|
6
|
-
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
|
|
7
7
|
import { dirname, join, resolve } from 'node:path'
|
|
8
8
|
import { relPosix } from './files'
|
|
9
9
|
import { isInside } from './is-inside'
|
|
@@ -68,6 +68,7 @@ export interface PluginHostOptions {
|
|
|
68
68
|
plugins: PrunellePlugin[]
|
|
69
69
|
appCtx: AppRuntimeContext
|
|
70
70
|
root: string
|
|
71
|
+
routesDir: string
|
|
71
72
|
outDir: string
|
|
72
73
|
clientDir: string
|
|
73
74
|
outPublicDir: string
|
|
@@ -170,10 +171,19 @@ export function createPluginHost(options: PluginHostOptions) {
|
|
|
170
171
|
const precompressed = new Set<string>()
|
|
171
172
|
const styles = createStyleMutators(styleUrls, globalStyles, routes, statusPages)
|
|
172
173
|
|
|
174
|
+
// A file rewritten after it was precompressed loses its sidecars, so the next precompressOutput() writes them from the final content.
|
|
175
|
+
function dropSidecars(abs: string): void {
|
|
176
|
+
if (precompressed.delete(abs)) {
|
|
177
|
+
rmSync(`${abs}.br`, { force: true })
|
|
178
|
+
rmSync(`${abs}.gz`, { force: true })
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
173
182
|
function emitAsset(plugin: string, relPath: string, content: string | Uint8Array): string {
|
|
174
183
|
const clean = confinedRel(plugin, 'emitAsset', clientDir, relPath)
|
|
175
184
|
const dst = join(clientDir, clean)
|
|
176
185
|
mkdirSync(dirname(dst), { recursive: true })
|
|
186
|
+
dropSidecars(dst)
|
|
177
187
|
writeFileSync(dst, content)
|
|
178
188
|
if (!assetSet.has(clean)) {
|
|
179
189
|
assetSet.add(clean)
|
|
@@ -186,6 +196,7 @@ export function createPluginHost(options: PluginHostOptions) {
|
|
|
186
196
|
const clean = options.publicFiles.register(confinedRel(plugin, 'emitPublic', outPublicDir, relPath))
|
|
187
197
|
const dst = join(outPublicDir, clean)
|
|
188
198
|
mkdirSync(dirname(dst), { recursive: true })
|
|
199
|
+
dropSidecars(dst)
|
|
189
200
|
writeFileSync(dst, content)
|
|
190
201
|
return `/${clean}`
|
|
191
202
|
}
|
|
@@ -197,6 +208,7 @@ export function createPluginHost(options: PluginHostOptions) {
|
|
|
197
208
|
|
|
198
209
|
const shared = {
|
|
199
210
|
root: options.root,
|
|
211
|
+
routesDir: options.routesDir,
|
|
200
212
|
outDir,
|
|
201
213
|
assetPrefix,
|
|
202
214
|
...(options.site !== undefined ? { site: options.site } : {}),
|