prunelle 0.0.0-stage → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/llms.txt +245 -0
- package/package.json +62 -4
- package/src/a11y/declaration.ts +373 -0
- package/src/a11y/index.ts +477 -0
- package/src/a11y/rgaa-map.ts +230 -0
- package/src/ambient.d.ts +6 -0
- package/src/attrs.ts +43 -0
- package/src/build/bundle.ts +661 -0
- package/src/build/byte-size.ts +11 -0
- package/src/build/carry.ts +57 -0
- package/src/build/client-entries.ts +107 -0
- package/src/build/client-plugin.ts +175 -0
- package/src/build/client-prune.ts +168 -0
- package/src/build/compile.ts +130 -0
- package/src/build/ecoindex.ts +238 -0
- package/src/build/files.ts +171 -0
- package/src/build/first-load.ts +235 -0
- package/src/build/graph.ts +237 -0
- package/src/build/index.ts +678 -0
- package/src/build/is-inside.ts +12 -0
- package/src/build/island-promote.ts +311 -0
- package/src/build/islands.ts +452 -0
- package/src/build/manifest.ts +204 -0
- package/src/build/output.ts +81 -0
- package/src/build/plugin-host.ts +294 -0
- package/src/build/precompress.ts +139 -0
- package/src/build/prerender.ts +288 -0
- package/src/build/reach.ts +200 -0
- package/src/build/render-rules.ts +205 -0
- package/src/build/report.ts +290 -0
- package/src/build/resolve.ts +52 -0
- package/src/build/routes.ts +342 -0
- package/src/build/server-entry.ts +38 -0
- package/src/build/static-headers.ts +112 -0
- package/src/build/static.ts +209 -0
- package/src/build/status-pages.ts +127 -0
- package/src/build/style-bundles.ts +526 -0
- package/src/cli/check-forms.ts +636 -0
- package/src/cli/check-imports.ts +31 -0
- package/src/cli/check-links.ts +632 -0
- package/src/cli/check-security.ts +64 -0
- package/src/cli/check.ts +409 -0
- package/src/cli/commands.ts +372 -0
- package/src/cli/docs.ts +403 -0
- package/src/cli/index.ts +70 -0
- package/src/cli/inspect.ts +406 -0
- package/src/cli/mcp-tools.ts +492 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +52 -0
- package/src/cli/render.ts +416 -0
- package/src/cli/upgrade-names.ts +209 -0
- package/src/cli/upgrade.ts +367 -0
- package/src/compiler/analyze.ts +651 -0
- package/src/compiler/ast.ts +82 -0
- package/src/compiler/browser-globals.ts +250 -0
- package/src/compiler/cacheability-private.ts +566 -0
- package/src/compiler/cacheability.ts +335 -0
- package/src/compiler/compliance-eco.ts +71 -0
- package/src/compiler/compliance-rgaa.ts +614 -0
- package/src/compiler/compliance-urls.ts +148 -0
- package/src/compiler/compliance.ts +653 -0
- package/src/compiler/data-keys.ts +302 -0
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +452 -0
- package/src/compiler/dom.ts +641 -0
- package/src/compiler/emit.ts +131 -0
- package/src/compiler/expr-context.ts +587 -0
- package/src/compiler/foreign-imports.ts +88 -0
- package/src/compiler/index.ts +8 -0
- package/src/compiler/interactivity.ts +366 -0
- package/src/compiler/mistakes.ts +520 -0
- package/src/compiler/node-env.ts +50 -0
- package/src/compiler/patch.ts +97 -0
- package/src/compiler/props-body.ts +60 -0
- package/src/compiler/props.ts +511 -0
- package/src/compiler/scope.ts +635 -0
- package/src/compiler/server-only.ts +365 -0
- package/src/compiler/shared.ts +397 -0
- package/src/compiler/signal-reads.ts +246 -0
- package/src/compiler/slots.ts +227 -0
- package/src/compiler/spread-handlers.ts +295 -0
- package/src/compiler/ssr-helpers.ts +555 -0
- package/src/compiler/ssr-island.ts +90 -0
- package/src/compiler/ssr-prunelle-tags.ts +69 -0
- package/src/compiler/ssr.ts +525 -0
- package/src/context.ts +199 -0
- package/src/dev/child.ts +30 -0
- package/src/dev/error-log.ts +177 -0
- package/src/dev/host-check.ts +32 -0
- package/src/dev/index.ts +268 -0
- package/src/dev/modules.ts +68 -0
- package/src/dev/open-editor.ts +228 -0
- package/src/dev/protocol.ts +24 -0
- package/src/dev/queue.ts +79 -0
- package/src/dev/reload.ts +159 -0
- package/src/dev/supervisor.ts +212 -0
- package/src/dev/watchers.ts +276 -0
- package/src/dom/action.ts +187 -0
- package/src/dom/attrs.ts +84 -0
- package/src/dom/claim.ts +120 -0
- package/src/dom/extras.ts +579 -0
- package/src/dom/index.ts +329 -0
- package/src/dom/island.ts +318 -0
- package/src/dom/loop.ts +484 -0
- package/src/dom/revive.ts +36 -0
- package/src/eco/declaration.ts +328 -0
- package/src/eco/index.ts +69 -0
- package/src/index.ts +22 -0
- package/src/jsx-runtime.ts +566 -0
- package/src/plugins/config.ts +92 -0
- package/src/plugins/context.ts +109 -0
- package/src/plugins/index.ts +14 -0
- package/src/plugins/load.ts +90 -0
- package/src/plugins/order.ts +148 -0
- package/src/plugins/public.ts +15 -0
- package/src/plugins/requires.ts +47 -0
- package/src/plugins/services.ts +119 -0
- package/src/plugins/types.ts +278 -0
- package/src/reactivity/graph.ts +259 -0
- package/src/reactivity/index.ts +541 -0
- package/src/reactivity/selector.ts +78 -0
- package/src/reactivity/store.ts +252 -0
- package/src/server/action-flash.ts +158 -0
- package/src/server/action-protect.ts +199 -0
- package/src/server/action-registry.ts +78 -0
- package/src/server/action.ts +511 -0
- package/src/server/app-entry.ts +23 -0
- package/src/server/app-secret.ts +63 -0
- package/src/server/assets.ts +168 -0
- package/src/server/compress.ts +646 -0
- package/src/server/consent.ts +290 -0
- package/src/server/cookies.ts +153 -0
- package/src/server/document.ts +286 -0
- package/src/server/env.ts +47 -0
- package/src/server/errors.ts +396 -0
- package/src/server/form-schema.ts +337 -0
- package/src/server/health.ts +275 -0
- package/src/server/http.ts +588 -0
- package/src/server/index.ts +615 -0
- package/src/server/lifecycle.ts +75 -0
- package/src/server/loader.ts +131 -0
- package/src/server/page.ts +122 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +267 -0
- package/src/server/prerendered.ts +71 -0
- package/src/server/public.ts +20 -0
- package/src/server/rate-limit.ts +199 -0
- package/src/server/region.ts +96 -0
- package/src/server/request-body.ts +27 -0
- package/src/server/request-path.ts +73 -0
- package/src/server/request-scope.ts +22 -0
- package/src/server/route-cache.ts +541 -0
- package/src/server/route-table.ts +424 -0
- package/src/server/router.ts +261 -0
- package/src/server/routing.ts +388 -0
- package/src/server/sanitize-html.ts +309 -0
- package/src/server/security.ts +550 -0
- package/src/server/serve-handlers.ts +93 -0
- package/src/server/served-file.ts +128 -0
- package/src/server/standard-schema.ts +104 -0
- package/src/server/start.ts +143 -0
- package/src/server/static-dir.ts +246 -0
- package/src/server/stream.ts +233 -0
- package/src/ssr/consent-banner.ts +58 -0
- package/src/ssr/context.ts +399 -0
- package/src/ssr/index.ts +624 -0
- package/src/ssr/navigation.ts +96 -0
- package/src/ssr/region.ts +192 -0
- package/src/style.ts +96 -0
- package/src/test/browser.ts +201 -0
- package/src/test/index.ts +262 -0
- package/src/ts-plugin/diagnostics.ts +505 -0
- package/src/ts-plugin/fixes.ts +364 -0
- package/src/ts-plugin/index.ts +194 -0
- package/src/unrenderable.ts +35 -0
- package/templates/_shared/AGENTS.md +10 -0
- package/templates/_shared/CLAUDE.md +1 -0
- package/templates/_shared/gitignore +8 -0
- package/templates/_shared/mcp.json +11 -0
- package/templates/_shared/public/robots.txt +2 -0
- package/templates/_shared/src/routes/legal.tsx +22 -0
- package/templates/_shared/tsconfig.json +25 -0
- package/templates/app/.env.example +8 -0
- package/templates/app/package.json +22 -0
- package/templates/app/prunelle.config.ts +13 -0
- package/templates/app/src/auth.ts +12 -0
- package/templates/app/src/mail.ts +4 -0
- package/templates/app/src/routes/_layout.tsx +40 -0
- package/templates/app/src/routes/dashboard/_middleware.ts +3 -0
- package/templates/app/src/routes/dashboard/index.tsx +47 -0
- package/templates/app/src/routes/index.tsx +15 -0
- package/templates/app/src/routes/login.tsx +53 -0
- package/templates/app/src/routes/privacy.tsx +25 -0
- package/templates/app/src/styles/app.css +14 -0
- package/templates/app/tests/app.test.ts +73 -0
- package/templates/blog/content/posts/welcome.md +9 -0
- package/templates/blog/package.json +22 -0
- package/templates/blog/prunelle.config.ts +23 -0
- package/templates/blog/src/posts.ts +26 -0
- package/templates/blog/src/routes/_layout.tsx +25 -0
- package/templates/blog/src/routes/blog/[slug].tsx +31 -0
- package/templates/blog/src/routes/index.tsx +33 -0
- package/templates/blog/src/styles/app.css +15 -0
- package/templates/fullstack/package.json +19 -0
- package/templates/fullstack/prunelle.config.ts +6 -0
- package/templates/fullstack/src/actions/greet.ts +19 -0
- package/templates/fullstack/src/components/Counter.tsx +10 -0
- package/templates/fullstack/src/components/GreetForm.tsx +28 -0
- package/templates/fullstack/src/routes/_layout.tsx +18 -0
- package/templates/fullstack/src/routes/api/health.ts +5 -0
- package/templates/fullstack/src/routes/index.tsx +13 -0
- package/templates/fullstack/src/styles/app.css +39 -0
- package/templates/fullstack/tests/app.test.ts +37 -0
- package/templates/minimal/package.json +19 -0
- package/templates/minimal/prunelle.config.ts +6 -0
- package/templates/minimal/src/components/Counter.tsx +10 -0
- package/templates/minimal/src/routes/_layout.tsx +18 -0
- package/templates/minimal/src/routes/index.tsx +11 -0
- package/templates/minimal/src/styles/app.css +32 -0
- package/ts-plugin.cjs +4277 -0
- package/README.md +0 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Path confinement, on its own so the server can check a path without loading the build's file helpers and `node:zlib` with them.
|
|
2
|
+
|
|
3
|
+
import { isAbsolute, relative } from 'node:path'
|
|
4
|
+
|
|
5
|
+
/** Whether `target` lies under `dir`, or is `dir` itself with `orSame`. Paths are compared as written: realpath both first to follow symlinks. */
|
|
6
|
+
export function isInside(dir: string, target: string, options: { orSame?: boolean } = {}): boolean {
|
|
7
|
+
const rel = relative(dir, target)
|
|
8
|
+
if (rel === '')
|
|
9
|
+
return options.orSame === true
|
|
10
|
+
// `..x` is a name inside `dir`; only `..` itself, as a whole segment, leaves it.
|
|
11
|
+
return rel !== '..' && !rel.startsWith('../') && !rel.startsWith('..\\') && !isAbsolute(rel)
|
|
12
|
+
}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
// Which modules run in the browser: following re-exports to the binding they name, and promoting what reads an interactive import.
|
|
2
|
+
|
|
3
|
+
import type { ModuleAnalysis } from '../compiler/analyze'
|
|
4
|
+
import type { ComplianceConfig } from '../compiler/compliance'
|
|
5
|
+
import type { CompilerWarning } from '../compiler/mistakes'
|
|
6
|
+
import type { IslandIssue } from './islands'
|
|
7
|
+
import type { ModuleGraph } from './graph'
|
|
8
|
+
import { wholeLoadShippedWarning } from '../compiler/analyze'
|
|
9
|
+
import { isIgnoredAt, isRuleIgnored, parsePrunelleIgnores } from '../compiler/compliance'
|
|
10
|
+
import { withStateReads } from '../compiler/interactivity'
|
|
11
|
+
import { walkScoped } from '../compiler/scope'
|
|
12
|
+
import { formatDiagnostic, formatLoc } from '../compiler/shared'
|
|
13
|
+
import { isInNodeModules, isTsFile, relPosix } from './files'
|
|
14
|
+
|
|
15
|
+
export type LoadModule = (file: string) => ModuleAnalysis | undefined
|
|
16
|
+
|
|
17
|
+
export const MAX_REEXPORT_DEPTH = 8
|
|
18
|
+
|
|
19
|
+
/** Follows `export { x } from './y'` and `export * from './y'` chains using `load` so parse errors are never swallowed. */
|
|
20
|
+
export function resolveExportTarget(
|
|
21
|
+
graph: ModuleGraph,
|
|
22
|
+
load: LoadModule,
|
|
23
|
+
file: string,
|
|
24
|
+
exportName: string,
|
|
25
|
+
depth = 0,
|
|
26
|
+
seen = new Set<string>(),
|
|
27
|
+
): { file: string, exportName: string } | undefined {
|
|
28
|
+
if (depth > MAX_REEXPORT_DEPTH)
|
|
29
|
+
return { file, exportName }
|
|
30
|
+
const key = `${file}\0${exportName}`
|
|
31
|
+
if (seen.has(key))
|
|
32
|
+
return { file, exportName }
|
|
33
|
+
seen.add(key)
|
|
34
|
+
|
|
35
|
+
const analysis = load(file)
|
|
36
|
+
if (analysis === undefined)
|
|
37
|
+
return undefined
|
|
38
|
+
const direct = analysis.reexports.find(r => r.exported === exportName)
|
|
39
|
+
if (direct !== undefined) {
|
|
40
|
+
const next = graph.resolve(file, direct.source)
|
|
41
|
+
if (next !== undefined && isTsFile(next))
|
|
42
|
+
return resolveExportTarget(graph, load, next, direct.local, depth + 1, seen)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (analysis.exportedNames.includes(exportName))
|
|
46
|
+
return { file, exportName }
|
|
47
|
+
|
|
48
|
+
// Follow `export * from './y'` barrel re-exports (named exports only, per ESM spec `export *` never re-exports `default`).
|
|
49
|
+
if (exportName !== 'default') {
|
|
50
|
+
for (const re of analysis.reexports) {
|
|
51
|
+
if (re.exported !== '*')
|
|
52
|
+
continue
|
|
53
|
+
const next = graph.resolve(file, re.source)
|
|
54
|
+
if (next === undefined || !isTsFile(next))
|
|
55
|
+
continue
|
|
56
|
+
const candidate = resolveExportTarget(graph, load, next, exportName, depth + 1, seen)
|
|
57
|
+
if (candidate !== undefined && load(candidate.file)?.exportedNames.includes(candidate.exportName))
|
|
58
|
+
return candidate
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { file, exportName }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function moduleHasInteractiveExport(graph: ModuleGraph, load: LoadModule, file: string, seen = new Set<string>()): boolean {
|
|
66
|
+
if (seen.has(file))
|
|
67
|
+
return false
|
|
68
|
+
seen.add(file)
|
|
69
|
+
const analysis = graph.analyses.get(file) ?? load(file)
|
|
70
|
+
if (analysis === undefined)
|
|
71
|
+
return false
|
|
72
|
+
if (analysis.stateExports.length > 0 || [...analysis.exports.values()].some(e => e.interactive))
|
|
73
|
+
return true
|
|
74
|
+
for (const re of analysis.reexports) {
|
|
75
|
+
const next = graph.resolve(file, re.source)
|
|
76
|
+
if (next === undefined || !isTsFile(next))
|
|
77
|
+
continue
|
|
78
|
+
if (re.exported === '*') {
|
|
79
|
+
if (moduleHasInteractiveExport(graph, load, next, seen))
|
|
80
|
+
return true
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const target = resolveExportTarget(graph, load, next, re.local)
|
|
84
|
+
const targetAnalysis = target === undefined ? undefined : (graph.analyses.get(target.file) ?? load(target.file))
|
|
85
|
+
if (target !== undefined && (targetAnalysis?.stateExports.includes(target.exportName) === true || targetAnalysis?.exports.get(target.exportName)?.interactive === true))
|
|
86
|
+
return true
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return false
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function collectExportedSignals(graph: ModuleGraph, load: LoadModule, file: string, out: Set<string>, seen = new Set<string>()): void {
|
|
93
|
+
if (seen.has(file))
|
|
94
|
+
return
|
|
95
|
+
seen.add(file)
|
|
96
|
+
const analysis = graph.analyses.get(file) ?? load(file)
|
|
97
|
+
if (analysis === undefined)
|
|
98
|
+
return
|
|
99
|
+
for (const name of analysis.signalExports)
|
|
100
|
+
out.add(name)
|
|
101
|
+
for (const re of analysis.reexports) {
|
|
102
|
+
const next = graph.resolve(file, re.source)
|
|
103
|
+
if (next === undefined || !isTsFile(next))
|
|
104
|
+
continue
|
|
105
|
+
if (re.exported === '*') {
|
|
106
|
+
collectExportedSignals(graph, load, next, out, seen)
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const target = resolveExportTarget(graph, load, next, re.local)
|
|
110
|
+
if (target !== undefined && (graph.analyses.get(target.file) ?? load(target.file))?.signalExports.includes(target.exportName) === true)
|
|
111
|
+
out.add(re.exported)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function interactivityChanged(prev: ModuleAnalysis, next: { isInteractive: boolean, exports: Map<string, { interactive: boolean }>, localIslands: Map<string, unknown> }): boolean {
|
|
117
|
+
if (prev.isInteractive !== next.isInteractive)
|
|
118
|
+
return true
|
|
119
|
+
for (const [name, fact] of next.exports) {
|
|
120
|
+
if (prev.exports.get(name)?.interactive !== fact.interactive)
|
|
121
|
+
return true
|
|
122
|
+
}
|
|
123
|
+
return next.localIslands.size !== prev.localIslands.size || [...next.localIslands.keys()].some(name => !prev.localIslands.has(name))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** An imported island a module reads as a value (`const D = Counter`, `{ C: Counter }`, `c={Counter}`), which makes what holds it an island. */
|
|
127
|
+
export interface IslandValueUse { file: string, offset: number, offsets?: readonly number[] | undefined, name: string }
|
|
128
|
+
|
|
129
|
+
/** A compiler warning that only applies once a module is promoted to an island across files. */
|
|
130
|
+
export interface PromotedWarning { file: string, warning: CompilerWarning }
|
|
131
|
+
|
|
132
|
+
const COMPONENT_NAME_RE = /^[A-Z]/
|
|
133
|
+
|
|
134
|
+
// Every binding's value read of `local`, in source order.
|
|
135
|
+
const allValueReads = (analysis: ModuleAnalysis, local: string): number[] =>
|
|
136
|
+
analysis.bindings.map(b => b.valueRefs.get(local)).filter((offset): offset is number => offset !== undefined)
|
|
137
|
+
|
|
138
|
+
// All unshadowed non-JSX value reads of `local` in `analysis.program`, used only when a line-ignore hides the first recorded offset.
|
|
139
|
+
function allProgramValueReads(analysis: ModuleAnalysis, local: string): number[] {
|
|
140
|
+
const offsets: number[] = []
|
|
141
|
+
for (const stmt of analysis.program.body) {
|
|
142
|
+
if (stmt.type === 'ImportDeclaration' || stmt.type === 'ExportAllDeclaration')
|
|
143
|
+
continue
|
|
144
|
+
const target = stmt.type === 'ExportNamedDeclaration' ? stmt.declaration : stmt
|
|
145
|
+
if (target === null)
|
|
146
|
+
continue
|
|
147
|
+
walkScoped(target, {
|
|
148
|
+
onIdentifier(id) {
|
|
149
|
+
if (id.name === local)
|
|
150
|
+
offsets.push(id.start)
|
|
151
|
+
},
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
return offsets
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** Formats `[rgesn/island-by-value]` warnings for `prunelle check` and production `prunelle build`, honoring `compliance.ignore` and `prunelle-ignore`. */
|
|
158
|
+
export function formatIslandValueWarnings(
|
|
159
|
+
uses: readonly IslandValueUse[],
|
|
160
|
+
root: string,
|
|
161
|
+
graph: Pick<ModuleGraph, 'analyses'>,
|
|
162
|
+
sourceOf: (file: string) => string,
|
|
163
|
+
compliance: ComplianceConfig | undefined,
|
|
164
|
+
): string[] {
|
|
165
|
+
const rule = 'rgesn/island-by-value'
|
|
166
|
+
if (uses.length === 0 || isRuleIgnored(rule, compliance))
|
|
167
|
+
return []
|
|
168
|
+
const ignoresByFile = new Map<string, ReturnType<typeof parsePrunelleIgnores>>()
|
|
169
|
+
const warnings: string[] = []
|
|
170
|
+
for (const use of uses) {
|
|
171
|
+
const code = sourceOf(use.file)
|
|
172
|
+
let ignores = ignoresByFile.get(use.file)
|
|
173
|
+
if (ignores === undefined) {
|
|
174
|
+
ignores = parsePrunelleIgnores(code)
|
|
175
|
+
ignoresByFile.set(use.file, ignores)
|
|
176
|
+
}
|
|
177
|
+
if (ignores.fileRules.has(rule))
|
|
178
|
+
continue
|
|
179
|
+
const recorded = use.offsets ?? [use.offset]
|
|
180
|
+
let offset = recorded.find(o => !isIgnoredAt(ignores, rule, o))
|
|
181
|
+
if (offset === undefined) {
|
|
182
|
+
const analysis = graph.analyses.get(use.file)
|
|
183
|
+
if (analysis !== undefined)
|
|
184
|
+
offset = allProgramValueReads(analysis, use.name).find(o => !isIgnoredAt(ignores, rule, o))
|
|
185
|
+
}
|
|
186
|
+
if (offset === undefined)
|
|
187
|
+
continue
|
|
188
|
+
const rel = relPosix(root, use.file)
|
|
189
|
+
warnings.push(formatDiagnostic(formatLoc(rel, code, offset), `[${rule}] ${use.name} is an island read as a value, not rendered as <${use.name} />, so what holds it hydrates as an island and ships its code too: render <${use.name} /> itself where it shows, or // prunelle-ignore ${rule} when the whole component should hydrate.`, 'warning'))
|
|
190
|
+
}
|
|
191
|
+
return warnings
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function createPromoter(
|
|
195
|
+
graph: ModuleGraph,
|
|
196
|
+
load: LoadModule,
|
|
197
|
+
issues: IslandIssue[],
|
|
198
|
+
valueUses: IslandValueUse[] = [],
|
|
199
|
+
promotedWarnings: PromotedWarning[] = [],
|
|
200
|
+
): { promoteAll: () => void, loadPromoted: LoadModule } {
|
|
201
|
+
const initialAsyncInteractive = new Set<string>()
|
|
202
|
+
const initialServerOnly = new Set<string>()
|
|
203
|
+
const reportedAsync = new Set<string>()
|
|
204
|
+
const reportedServerOnly = new Set<string>()
|
|
205
|
+
const reportedWholeLoad = new Set<string>()
|
|
206
|
+
|
|
207
|
+
const recordInitial = (file: string, a: ModuleAnalysis): void => {
|
|
208
|
+
if (a.hasAsyncDefault && a.exports.get('default')?.interactive === true)
|
|
209
|
+
initialAsyncInteractive.add(file)
|
|
210
|
+
if (a.serverOnly !== undefined)
|
|
211
|
+
initialServerOnly.add(file)
|
|
212
|
+
}
|
|
213
|
+
for (const [file, a] of graph.analyses)
|
|
214
|
+
recordInitial(file, a)
|
|
215
|
+
|
|
216
|
+
// What an import names: reactive state, an interactive export (a component or a hook), or neither.
|
|
217
|
+
const interactiveKind = (file: string, source: string, imported: string): 'state' | 'export' | undefined => {
|
|
218
|
+
const resolved = graph.resolve(file, source)
|
|
219
|
+
if (resolved === undefined || !isTsFile(resolved))
|
|
220
|
+
return undefined
|
|
221
|
+
if (imported === '*')
|
|
222
|
+
return moduleHasInteractiveExport(graph, load, resolved) ? 'export' : undefined
|
|
223
|
+
const target = resolveExportTarget(graph, load, resolved, imported)
|
|
224
|
+
if (target === undefined)
|
|
225
|
+
return undefined
|
|
226
|
+
const targetAnalysis = graph.analyses.get(target.file) ?? load(target.file)
|
|
227
|
+
if (targetAnalysis?.stateExports.includes(target.exportName) === true)
|
|
228
|
+
return 'state'
|
|
229
|
+
return targetAnalysis?.exports.get(target.exportName)?.interactive === true ? 'export' : undefined
|
|
230
|
+
}
|
|
231
|
+
const isInteractiveTarget = (file: string, source: string, imported: string): boolean => interactiveKind(file, source, imported) !== undefined
|
|
232
|
+
|
|
233
|
+
const reportedValueUses = new Set<string>()
|
|
234
|
+
const recordValueUses = (file: string, analysis: ModuleAnalysis): void => {
|
|
235
|
+
for (const imp of analysis.imports) {
|
|
236
|
+
for (const spec of imp.specifiers) {
|
|
237
|
+
const offsets = spec.imported === '*' || !COMPONENT_NAME_RE.test(spec.local) ? [] : allValueReads(analysis, spec.local)
|
|
238
|
+
if (offsets.length === 0 || reportedValueUses.has(`${file}#${spec.local}`) || interactiveKind(file, imp.source, spec.imported) !== 'export')
|
|
239
|
+
continue
|
|
240
|
+
reportedValueUses.add(`${file}#${spec.local}`)
|
|
241
|
+
valueUses.push({ file, offset: offsets[0]!, offsets, name: spec.local })
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const promoteOne = (file: string): boolean => {
|
|
247
|
+
if (isInNodeModules(file) || !isTsFile(file))
|
|
248
|
+
return false
|
|
249
|
+
const analysis = graph.analyses.get(file)
|
|
250
|
+
if (analysis === undefined)
|
|
251
|
+
return false
|
|
252
|
+
const promoted = withStateReads(analysis, (imp, imported) => isInteractiveTarget(file, imp.source, imported))
|
|
253
|
+
if (promoted === undefined)
|
|
254
|
+
return false
|
|
255
|
+
const page = promoted.exports.get('default')
|
|
256
|
+
if (analysis.hasAsyncDefault && page?.interactive === true) {
|
|
257
|
+
if (!initialAsyncInteractive.has(file) && !reportedAsync.has(file)) {
|
|
258
|
+
reportedAsync.add(file)
|
|
259
|
+
issues.push({ kind: 'async-interactive', file, offset: page.offset ?? 0, reason: page.reason })
|
|
260
|
+
}
|
|
261
|
+
return false
|
|
262
|
+
}
|
|
263
|
+
if (promoted.serverOnly !== undefined) {
|
|
264
|
+
if (!initialServerOnly.has(file) && !reportedServerOnly.has(file)) {
|
|
265
|
+
reportedServerOnly.add(file)
|
|
266
|
+
issues.push({ kind: 'server-only-tag', file, serverOnly: promoted.serverOnly })
|
|
267
|
+
}
|
|
268
|
+
return false
|
|
269
|
+
}
|
|
270
|
+
if (!interactivityChanged(analysis, promoted))
|
|
271
|
+
return false
|
|
272
|
+
recordValueUses(file, analysis)
|
|
273
|
+
let nextWarnings = analysis.warnings
|
|
274
|
+
if (analysis.exports.get('default')?.interactive !== true && page?.interactive === true && analysis.hasLoadExport && analysis.defaultDataKeys === undefined && !analysis.exportedNames.includes('clientData') && !reportedWholeLoad.has(file)) {
|
|
275
|
+
reportedWholeLoad.add(file)
|
|
276
|
+
const defaultName = analysis.exportLocals.get('default')
|
|
277
|
+
const start = analysis.bindings.find(b => b.name === defaultName)?.start ?? page.offset ?? 0
|
|
278
|
+
const warning = wholeLoadShippedWarning(file, start)
|
|
279
|
+
promotedWarnings.push({ file, warning })
|
|
280
|
+
nextWarnings = [...analysis.warnings, warning]
|
|
281
|
+
}
|
|
282
|
+
Object.assign(analysis, promoted, { warnings: nextWarnings })
|
|
283
|
+
return true
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const promoteAll = (): void => {
|
|
287
|
+
for (let pass = 0; pass < MAX_REEXPORT_DEPTH; pass++) {
|
|
288
|
+
let changed = false
|
|
289
|
+
for (const file of [...graph.analyses.keys()]) {
|
|
290
|
+
if (promoteOne(file))
|
|
291
|
+
changed = true
|
|
292
|
+
}
|
|
293
|
+
if (!changed)
|
|
294
|
+
break
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const loadPromoted: LoadModule = (file: string): ModuleAnalysis | undefined => {
|
|
299
|
+
const existed = graph.analyses.has(file)
|
|
300
|
+
const analysis = graph.analyses.get(file) ?? load(file)
|
|
301
|
+
if (analysis === undefined)
|
|
302
|
+
return undefined
|
|
303
|
+
if (!existed) {
|
|
304
|
+
recordInitial(file, analysis)
|
|
305
|
+
promoteAll()
|
|
306
|
+
}
|
|
307
|
+
return graph.analyses.get(file) ?? analysis
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return { promoteAll, loadPromoted }
|
|
311
|
+
}
|