prunelle 0.1.1 → 0.5.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/llms.txt +23 -19
- package/package.json +8 -2
- package/src/a11y/declaration.ts +335 -0
- package/src/a11y/index.ts +446 -0
- package/src/a11y/rgaa-map.ts +184 -0
- package/src/attrs.ts +11 -3
- package/src/build/bundle.ts +80 -36
- package/src/build/client-entries.ts +3 -2
- package/src/build/client-plugin.ts +8 -4
- package/src/build/client-prune.ts +56 -6
- package/src/build/compile.ts +11 -9
- package/src/build/ecoindex.ts +229 -0
- package/src/build/index.ts +174 -108
- package/src/build/islands.ts +2 -2
- package/src/build/manifest.ts +66 -5
- package/src/build/output.ts +2 -2
- package/src/build/plugin-host.ts +91 -33
- package/src/build/precompress.ts +15 -2
- package/src/build/prerender.ts +128 -46
- package/src/build/report.ts +23 -2
- package/src/build/resolve.ts +8 -6
- package/src/build/routes.ts +175 -10
- package/src/build/static.ts +137 -39
- package/src/build/status-pages.ts +127 -0
- package/src/build/style-bundles.ts +526 -0
- package/src/cli/check-forms.ts +654 -0
- package/src/cli/check-links.ts +619 -0
- package/src/cli/check.ts +52 -5
- package/src/cli/commands.ts +86 -4
- package/src/cli/docs.ts +402 -0
- package/src/cli/inspect.ts +31 -2
- package/src/cli/mcp-tools.ts +480 -0
- package/src/cli/mcp.ts +205 -0
- package/src/cli/new.ts +2 -2
- package/src/cli/render.ts +261 -0
- package/src/cli/upgrade-names.ts +73 -13
- package/src/cli/upgrade.ts +137 -16
- package/src/compiler/analyze.ts +20 -6
- package/src/compiler/cacheability.ts +592 -0
- package/src/compiler/compliance-rgaa.ts +502 -0
- package/src/compiler/compliance.ts +120 -221
- package/src/compiler/dev-source.ts +87 -0
- package/src/compiler/dom-attrs.ts +138 -65
- package/src/compiler/dom.ts +12 -11
- package/src/compiler/expr-context.ts +167 -57
- package/src/compiler/props.ts +87 -36
- package/src/compiler/scope.ts +56 -17
- package/src/compiler/ssr-prunelle-tags.ts +27 -14
- package/src/compiler/ssr.ts +216 -84
- package/src/dev/error-log.ts +151 -0
- package/src/dev/index.ts +84 -34
- package/src/dev/open-editor.ts +204 -0
- package/src/dev/protocol.ts +1 -0
- package/src/dev/reload.ts +5 -3
- package/src/dev/supervisor.ts +42 -25
- package/src/dev/watchers.ts +47 -11
- package/src/dom/action.ts +4 -1
- package/src/dom/attrs.ts +15 -3
- package/src/dom/extras.ts +2 -2
- package/src/dom/island.ts +11 -10
- package/src/plugins/config.ts +4 -4
- package/src/plugins/index.ts +2 -2
- package/src/plugins/public.ts +5 -2
- package/src/plugins/services.ts +62 -0
- package/src/plugins/types.ts +32 -0
- package/src/server/action-protect.ts +198 -0
- package/src/server/action-registry.ts +1 -1
- package/src/server/action.ts +82 -27
- package/src/server/assets.ts +34 -2
- package/src/server/compress.ts +91 -9
- package/src/server/errors.ts +303 -65
- package/src/server/form-schema.ts +343 -0
- package/src/server/health.ts +244 -0
- package/src/server/http.ts +128 -31
- package/src/server/index.ts +230 -260
- package/src/server/loader.ts +5 -0
- package/src/server/param-matchers.ts +112 -0
- package/src/server/plugin-host.ts +123 -88
- package/src/server/public.ts +3 -3
- package/src/server/rate-limit.ts +58 -35
- package/src/server/request-body.ts +1 -1
- package/src/server/route-cache.ts +423 -0
- package/src/server/route-table.ts +339 -8
- package/src/server/router.ts +125 -40
- package/src/server/routing.ts +196 -63
- package/src/server/security.ts +208 -32
- package/src/server/serve-handlers.ts +21 -7
- package/src/server/start.ts +60 -16
- package/src/server/static-dir.ts +61 -8
- package/src/server/stream.ts +41 -22
- package/src/ssr/context.ts +85 -3
- package/src/ssr/index.ts +120 -1
- package/src/ssr/region.ts +31 -19
- package/src/test/browser.ts +6 -0
- package/src/test/index.ts +17 -3
- package/src/ts-plugin/diagnostics.ts +378 -0
- package/src/ts-plugin/fixes.ts +364 -0
- package/src/ts-plugin/index.ts +194 -0
- package/templates/_shared/AGENTS.md +2 -2
- package/templates/_shared/mcp.json +11 -0
- package/templates/_shared/src/routes/legal.tsx +5 -0
- package/templates/_shared/tsconfig.json +5 -0
- package/templates/blog/prunelle.config.ts +1 -1
- package/templates/blog/src/routes/index.tsx +4 -0
- package/ts-plugin.cjs +4277 -0
package/src/cli/upgrade.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
// `prunelle upgrade`: moves an app written for kay v2 (`@kayjs/kay`) onto prunelle: its dependencies, config file, imports, the names it imports and the names the browser receives.
|
|
2
2
|
|
|
3
|
+
import type { Dirent } from 'node:fs'
|
|
3
4
|
import { existsSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
|
4
|
-
import { dirname, join } from 'node:path'
|
|
5
|
+
import { dirname, join, resolve } from 'node:path'
|
|
5
6
|
import pkg from '../../package.json' with { type: 'json' }
|
|
6
7
|
import { isNotSourceDir, relPosix } from '../build/files'
|
|
7
8
|
import { resolvePrunelleSpecifier } from '../build/resolve'
|
|
8
9
|
import { parseTsx } from '../compiler/analyze'
|
|
10
|
+
import { walk } from '../compiler/ast'
|
|
9
11
|
import { renameKayNames } from './upgrade-names'
|
|
10
12
|
|
|
11
13
|
export interface UpgradeResult {
|
|
@@ -17,11 +19,13 @@ export interface UpgradeResult {
|
|
|
17
19
|
|
|
18
20
|
// The specifiers and file names every kind of file may name.
|
|
19
21
|
const PATH_RULES: [RegExp, string][] = [
|
|
22
|
+
// A kay v2 version written beside a package, as notes do, names no prunelle release: the current one replaces it.
|
|
23
|
+
[/(@kayjs\/[\w-]+)@[\^~]?2\.\d+\.\d+[\w.-]*/g, `$1@^${pkg.version}`],
|
|
20
24
|
[/@kayjs\/kay(?![\w-])/g, 'prunelle'],
|
|
21
25
|
[/@kayjs\//g, '@prunellejs/'],
|
|
22
26
|
[/\.kay-(cache|dev)\b/g, '.prunelle-$1'],
|
|
23
27
|
[/\bkay\.config\b/g, 'prunelle.config'],
|
|
24
|
-
[/\bkay v2\b/
|
|
28
|
+
[/\bkay v2\b/gi, 'prunelle'],
|
|
25
29
|
]
|
|
26
30
|
// The names kay sent the browser, as app code and styles may spell them.
|
|
27
31
|
const WIRE_RULES: [RegExp, string][] = [
|
|
@@ -37,19 +41,31 @@ const CLI_RULE: [RegExp, string] = [/(?<![\w.@/-])kay(?![\w.:/-])/g, 'prunelle']
|
|
|
37
41
|
|
|
38
42
|
const SOURCE_FILE_RE = /\.(?:tsx?|mts)$/
|
|
39
43
|
const STYLE_OR_SCRIPT_RE = /\.(?:css|js|mjs)$/
|
|
44
|
+
const TSCONFIG_FILE_RE = /^tsconfig(?:\.[\w-]+)?\.json$/
|
|
40
45
|
const CONFIG_FILE_RE = /^(?:tsconfig(?:\.[\w-]+)?\.json|bunfig\.toml|\.gitignore|\.dockerignore)$/
|
|
41
46
|
const BUILD_FILE_RE = /^(?:Dockerfile(?:\.[\w-]+)?|[\w-]+\.Dockerfile|[Jj]ustfile|Makefile|(?:docker-)?compose(?:\.[\w-]+)?\.ya?ml)$/
|
|
47
|
+
// The agent instructions `prunelle new` writes, which name the llms.txt to read and the CLI to run (#42).
|
|
48
|
+
const AGENT_FILE_RE = /^(?:AGENTS|CLAUDE)\.md$/
|
|
42
49
|
const CI_DIRS = ['.forgejo/workflows', '.github/workflows', '.gitea/workflows']
|
|
43
50
|
const CACHE_DIRS = ['.kay-cache', '.kay-dev']
|
|
44
51
|
const PRUNELLE_SOURCE_RE = /^prunelle(\/.*)?$/
|
|
52
|
+
const NPM_KAY_ALIAS_RE = /^npm:(@kayjs\/[\w-]+)(?:@.*)?$/
|
|
53
|
+
const ESCAPE_RE = /[.*+?^${}()|[\]\\]/g
|
|
54
|
+
const GITIGNORE_CACHE_RE = /(?:^|\/)\.prunelle-cache(?:\/|$|\s)/m
|
|
45
55
|
|
|
46
56
|
const apply = (text: string, rules: readonly [RegExp, string][]): string => rules.reduce((out, [re, to]) => out.replace(re, to), text)
|
|
47
57
|
|
|
48
58
|
/** Rewrites the app at `root` in place, and each package its bun workspace lists; installing the renamed dependencies is the caller's job. */
|
|
49
59
|
export function upgradeProject(root: string): UpgradeResult {
|
|
60
|
+
return upgradeDir(root)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function upgradeDir(root: string, inheritedAliases?: ReadonlyMap<string, string>): UpgradeResult {
|
|
50
64
|
const v1 = kayV1Dependency(root)
|
|
51
65
|
if (v1 !== undefined)
|
|
52
66
|
return { changed: [], manual: [`package.json:1: ${v1} is kay v1: prunelle upgrade moves kay v2 apps, so this one is left as it is.`] }
|
|
67
|
+
const aliases = kayAliases(root, inheritedAliases)
|
|
68
|
+
const isApp = hasKayOrPrunelle(root)
|
|
53
69
|
const changed: string[] = []
|
|
54
70
|
const manual: string[] = []
|
|
55
71
|
const write = (file: string, before: string, after: string): void => {
|
|
@@ -63,9 +79,13 @@ export function upgradeProject(root: string): UpgradeResult {
|
|
|
63
79
|
const text = readFileSync(join(root, file), 'utf8')
|
|
64
80
|
if (file === 'package.json')
|
|
65
81
|
write(file, text, upgradePackageJson(text))
|
|
82
|
+
else if (TSCONFIG_FILE_RE.test(file))
|
|
83
|
+
write(file, text, upgradeTsconfig(text, aliases))
|
|
84
|
+
else if (file === '.gitignore')
|
|
85
|
+
write(file, text, upgradeGitignore(text, isApp))
|
|
66
86
|
else if (CONFIG_FILE_RE.test(file))
|
|
67
87
|
write(file, text, apply(text, PATH_RULES))
|
|
68
|
-
else if (BUILD_FILE_RE.test(file))
|
|
88
|
+
else if (BUILD_FILE_RE.test(file) || AGENT_FILE_RE.test(file))
|
|
69
89
|
write(file, text, apply(apply(text, PATH_RULES), [CLI_RULE]))
|
|
70
90
|
}
|
|
71
91
|
for (const dir of CI_DIRS) {
|
|
@@ -77,9 +97,10 @@ export function upgradeProject(root: string): UpgradeResult {
|
|
|
77
97
|
write(file, text, apply(apply(text, PATH_RULES), [CLI_RULE]))
|
|
78
98
|
}
|
|
79
99
|
}
|
|
80
|
-
|
|
100
|
+
const publicDir = configuredPublicDir(root)
|
|
101
|
+
for (const file of sourceFiles(root, publicDir)) {
|
|
81
102
|
const text = readFileSync(join(root, file), 'utf8')
|
|
82
|
-
const renamed = SOURCE_FILE_RE.test(file) ? renameKayNames(file, text) : text
|
|
103
|
+
const renamed = SOURCE_FILE_RE.test(file) ? renameKayNames(file, text, aliases) : text
|
|
83
104
|
const next = apply(apply(renamed, PATH_RULES), WIRE_RULES)
|
|
84
105
|
write(file, text, next)
|
|
85
106
|
if (SOURCE_FILE_RE.test(file) && next !== text)
|
|
@@ -91,8 +112,9 @@ export function upgradeProject(root: string): UpgradeResult {
|
|
|
91
112
|
changed.push(`${dir}/`)
|
|
92
113
|
}
|
|
93
114
|
}
|
|
94
|
-
|
|
95
|
-
|
|
115
|
+
// A member on neither kay nor prunelle, a plain Bun app or a tool, has nothing to move; one already on prunelle may keep names an earlier upgrade missed.
|
|
116
|
+
for (const member of workspaceMembers(root).filter(m => hasKayOrPrunelle(join(root, m)))) {
|
|
117
|
+
const res = upgradeDir(join(root, member), aliases)
|
|
96
118
|
changed.push(...res.changed.map(file => `${member}/${file}`))
|
|
97
119
|
manual.push(...res.manual.map(line => `${member}/${line}`))
|
|
98
120
|
}
|
|
@@ -102,6 +124,83 @@ export function upgradeProject(root: string): UpgradeResult {
|
|
|
102
124
|
const DEP_FIELDS = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']
|
|
103
125
|
const V1_RANGE_RE = /^[~^>=\s]*1\./
|
|
104
126
|
|
|
127
|
+
const KAY_OR_PRUNELLE_RE = /^(?:npm:)?(?:@kayjs\/|prunelle(?:@|$)|@prunellejs\/)/
|
|
128
|
+
|
|
129
|
+
function hasKayOrPrunelle(root: string): boolean {
|
|
130
|
+
if (!existsSync(join(root, 'package.json')))
|
|
131
|
+
return false
|
|
132
|
+
const json = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as Record<string, Record<string, string> | undefined>
|
|
133
|
+
return DEP_FIELDS.some(field => Object.entries(json[field] ?? {}).some(([name, range]) => KAY_OR_PRUNELLE_RE.test(name) || KAY_OR_PRUNELLE_RE.test(range)))
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function kayTargetPackage(name: string, version: string): string | undefined {
|
|
137
|
+
if (name.startsWith('@kayjs/'))
|
|
138
|
+
return apply(name, PATH_RULES)
|
|
139
|
+
const match = NPM_KAY_ALIAS_RE.exec(version)
|
|
140
|
+
return match === null ? undefined : apply(match[1]!, PATH_RULES)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function kayAliases(root: string, inherited?: ReadonlyMap<string, string>): Map<string, string> {
|
|
144
|
+
const aliases = new Map<string, string>(inherited)
|
|
145
|
+
if (!existsSync(join(root, 'package.json')))
|
|
146
|
+
return aliases
|
|
147
|
+
const json = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8')) as Record<string, Record<string, string> | undefined>
|
|
148
|
+
for (const field of DEP_FIELDS) {
|
|
149
|
+
for (const [name, version] of Object.entries(json[field] ?? {})) {
|
|
150
|
+
if (name.startsWith('@kayjs/'))
|
|
151
|
+
continue
|
|
152
|
+
const match = NPM_KAY_ALIAS_RE.exec(version)
|
|
153
|
+
if (match !== null)
|
|
154
|
+
aliases.set(name, apply(match[1]!, PATH_RULES))
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return aliases
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function upgradeTsconfig(text: string, aliases: ReadonlyMap<string, string>): string {
|
|
161
|
+
let out = apply(text, PATH_RULES)
|
|
162
|
+
for (const [alias, target] of aliases) {
|
|
163
|
+
const escaped = alias.replace(ESCAPE_RE, '\\$&')
|
|
164
|
+
if (target === 'prunelle')
|
|
165
|
+
out = out.replace(new RegExp(`("jsxImportSource"\\s*:\\s*")${escaped}(")`, 'g'), `$1${target}$2`)
|
|
166
|
+
out = out.replace(/"types"\s*:\s*\[[^\]]*\]/g, block =>
|
|
167
|
+
block.replace(new RegExp(`"${escaped}((?:/[^"]*)?)"`, 'g'), `"${target}$1"`))
|
|
168
|
+
}
|
|
169
|
+
return out
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function upgradeGitignore(text: string, addCache: boolean): string {
|
|
173
|
+
const next = apply(text, PATH_RULES)
|
|
174
|
+
if (!addCache || GITIGNORE_CACHE_RE.test(next))
|
|
175
|
+
return next
|
|
176
|
+
const eol = next.includes('\r\n') ? '\r\n' : '\n'
|
|
177
|
+
const sep = next === '' || next.endsWith('\n') ? '' : eol
|
|
178
|
+
return `${next}${sep}.prunelle-cache/${eol}`
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Reads `publicDir` statically from prunelle.config.ts (or kay.config.ts) so built scripts in `public/` are left alone (#43).
|
|
182
|
+
function configuredPublicDir(root: string): string {
|
|
183
|
+
const file = existsSync(join(root, 'prunelle.config.ts'))
|
|
184
|
+
? 'prunelle.config.ts'
|
|
185
|
+
: existsSync(join(root, 'kay.config.ts')) ? 'kay.config.ts' : undefined
|
|
186
|
+
if (file === undefined)
|
|
187
|
+
return resolve(root, 'public')
|
|
188
|
+
const program = parseTsx(file, readFileSync(join(root, file), 'utf8'))
|
|
189
|
+
let value: string | undefined
|
|
190
|
+
walk(program.body, (node) => {
|
|
191
|
+
if (value !== undefined)
|
|
192
|
+
return false
|
|
193
|
+
if (node.type === 'Property' && !node.computed && node.key.type === 'Identifier' && node.key.name === 'publicDir') {
|
|
194
|
+
if (node.value.type === 'Literal' && typeof node.value.value === 'string')
|
|
195
|
+
value = node.value.value
|
|
196
|
+
else if (node.value.type === 'TemplateLiteral' && node.value.expressions.length === 0)
|
|
197
|
+
value = node.value.quasis[0]?.value.cooked ?? node.value.quasis[0]?.value.raw
|
|
198
|
+
}
|
|
199
|
+
return true
|
|
200
|
+
})
|
|
201
|
+
return resolve(root, value ?? 'public')
|
|
202
|
+
}
|
|
203
|
+
|
|
105
204
|
// kay's core at a 1.x range, as `@kayjs/kay` or an `npm:@kayjs/kay@` alias: an app of `.kay` files prunelle cannot take.
|
|
106
205
|
function kayV1Dependency(root: string): string | undefined {
|
|
107
206
|
if (!existsSync(join(root, 'package.json')))
|
|
@@ -149,18 +248,33 @@ function rootFiles(root: string): string[] {
|
|
|
149
248
|
return readdirSync(root, { withFileTypes: true }).filter(e => e.isFile()).map(e => e.name).sort()
|
|
150
249
|
}
|
|
151
250
|
|
|
152
|
-
//
|
|
153
|
-
function
|
|
251
|
+
// The entries of `dir`, none for a folder the user cannot read: a container's data, never source they edit.
|
|
252
|
+
function readableEntries(dir: string): Dirent[] {
|
|
253
|
+
try {
|
|
254
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
if ((err as NodeJS.ErrnoException).code === 'EACCES' || (err as NodeJS.ErrnoException).code === 'EPERM')
|
|
258
|
+
return []
|
|
259
|
+
throw err
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// A folder holding its own package.json is another package, upgraded on its own; `publicDir` holds built static files left untouched (#43).
|
|
264
|
+
function sourceFiles(root: string, publicDir: string, dir = root, out: string[] = []): string[] {
|
|
154
265
|
if (dir !== root && existsSync(join(dir, 'package.json')))
|
|
155
266
|
return out
|
|
156
|
-
for (const entry of
|
|
267
|
+
for (const entry of readableEntries(dir)) {
|
|
157
268
|
if (isNotSourceDir(entry.name))
|
|
158
269
|
continue
|
|
159
270
|
const path = join(dir, entry.name)
|
|
160
|
-
if (entry.isDirectory())
|
|
161
|
-
|
|
162
|
-
|
|
271
|
+
if (entry.isDirectory()) {
|
|
272
|
+
if (resolve(path) !== publicDir)
|
|
273
|
+
sourceFiles(root, publicDir, path, out)
|
|
274
|
+
}
|
|
275
|
+
else if (SOURCE_FILE_RE.test(entry.name) || STYLE_OR_SCRIPT_RE.test(entry.name)) {
|
|
163
276
|
out.push(relPosix(root, path))
|
|
277
|
+
}
|
|
164
278
|
}
|
|
165
279
|
return out.sort()
|
|
166
280
|
}
|
|
@@ -173,10 +287,17 @@ function upgradePackageJson(text: string): string {
|
|
|
173
287
|
const range = `^${pkg.version}`
|
|
174
288
|
for (const field of DEP_FIELDS) {
|
|
175
289
|
const deps = json[field] as Record<string, string> | undefined
|
|
176
|
-
if (deps === undefined || !Object.
|
|
290
|
+
if (deps === undefined || !Object.entries(deps).some(([name, version]) => kayTargetPackage(name, version) !== undefined))
|
|
177
291
|
continue
|
|
178
|
-
const
|
|
179
|
-
|
|
292
|
+
const next = new Map<string, string>()
|
|
293
|
+
for (const [name, version] of Object.entries(deps)) {
|
|
294
|
+
const target = kayTargetPackage(name, version)
|
|
295
|
+
if (target !== undefined)
|
|
296
|
+
next.set(target, range)
|
|
297
|
+
else if (!next.has(name))
|
|
298
|
+
next.set(name, version)
|
|
299
|
+
}
|
|
300
|
+
json[field] = Object.fromEntries([...next.entries()].sort(([a], [b]) => a.localeCompare(b)))
|
|
180
301
|
}
|
|
181
302
|
const scripts = json.scripts as Record<string, string> | undefined
|
|
182
303
|
if (scripts !== undefined)
|
package/src/compiler/analyze.ts
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
import type { CallExpression, ExportNamedDeclaration, Function as OxcFunction, Node, Program, Statement, VariableDeclaration } from 'oxc-parser'
|
|
4
4
|
import { parseSync } from 'oxc-parser'
|
|
5
5
|
import { computeJsxNodes, walk } from './ast'
|
|
6
|
+
import type { RouteCacheSpec } from '../server/route-cache'
|
|
6
7
|
import type { BindingFacts, Interactivity } from './interactivity'
|
|
7
8
|
import type { CompilerWarning } from './mistakes'
|
|
8
9
|
import { checkBrowserGlobals } from './browser-globals'
|
|
10
|
+
import { parseCacheExport } from './cacheability'
|
|
9
11
|
import { analyzeDefaultDataKeys } from './data-keys'
|
|
10
12
|
import { checkCompliance } from './compliance'
|
|
11
13
|
import { resolveInteractivity } from './interactivity'
|
|
@@ -47,6 +49,10 @@ export interface ModuleAnalysis extends Interactivity {
|
|
|
47
49
|
/** Precomputed set of AST nodes containing JSX (itself included), for O(1) subtree checks during codegen. */
|
|
48
50
|
jsxNodes: WeakSet<Node>
|
|
49
51
|
hasPrerender: boolean
|
|
52
|
+
/** True when the module explicitly exports `prerender = false`. */
|
|
53
|
+
prerenderFalse: boolean
|
|
54
|
+
/** Parsed `export const cache = ...` policy when present and valid. */
|
|
55
|
+
cache?: RouteCacheSpec | undefined
|
|
50
56
|
hasPaths: boolean
|
|
51
57
|
usesRenderContext: boolean
|
|
52
58
|
defaultHydrate: string | undefined
|
|
@@ -272,6 +278,7 @@ interface DeclarationScan {
|
|
|
272
278
|
hasLoadExport: boolean
|
|
273
279
|
hasPaths: boolean
|
|
274
280
|
hasPrerender: boolean
|
|
281
|
+
prerenderFalse: boolean
|
|
275
282
|
defaultHydrate: string | undefined
|
|
276
283
|
exportedActions: string[]
|
|
277
284
|
/** The action() calls prunelle gives a URL to: the initialisers of top-level `export const`s. */
|
|
@@ -281,7 +288,7 @@ interface DeclarationScan {
|
|
|
281
288
|
}
|
|
282
289
|
|
|
283
290
|
function scanDeclarations(program: Program, filename: string, imports: ImportScan): DeclarationScan {
|
|
284
|
-
const scan: DeclarationScan = { localInits: new Map(), exportLocals: new Map(), asyncLocals: new Set(), defaultLocal: undefined, hasAsyncDefault: false, hasLoadExport: false, hasPaths: false, hasPrerender: false, defaultHydrate: undefined, exportedActions: [], registeredActions: new Set(), reexports: [], exportedNames: [] }
|
|
291
|
+
const scan: DeclarationScan = { localInits: new Map(), exportLocals: new Map(), asyncLocals: new Set(), defaultLocal: undefined, hasAsyncDefault: false, hasLoadExport: false, hasPaths: false, hasPrerender: false, prerenderFalse: false, defaultHydrate: undefined, exportedActions: [], registeredActions: new Set(), reexports: [], exportedNames: [] }
|
|
285
292
|
const collectInits = (decl: VariableDeclaration): void => {
|
|
286
293
|
for (const d of decl.declarations) {
|
|
287
294
|
if (d.id.type === 'Identifier' && d.init !== null)
|
|
@@ -358,8 +365,12 @@ function scanExportedDeclaration(scan: DeclarationScan, decl: NonNullable<Export
|
|
|
358
365
|
continue
|
|
359
366
|
const name = d.id.name
|
|
360
367
|
addExport(name, name)
|
|
361
|
-
if (name === 'prerender' && d.init?.type === 'Literal'
|
|
362
|
-
|
|
368
|
+
if (name === 'prerender' && d.init?.type === 'Literal') {
|
|
369
|
+
if (d.init.value === true)
|
|
370
|
+
scan.hasPrerender = true
|
|
371
|
+
else if (d.init.value === false)
|
|
372
|
+
scan.prerenderFalse = true
|
|
373
|
+
}
|
|
363
374
|
if (name === 'hydrate' && d.init !== null)
|
|
364
375
|
scan.defaultHydrate = checkExportHydrate(d.init, filename)
|
|
365
376
|
if (d.init !== null && isActionCall(d.init, imports.actionLocalName, imports.serverNamespaces)) {
|
|
@@ -476,9 +487,9 @@ function scanBody(program: Program, filename: string, code: string, imports: Imp
|
|
|
476
487
|
}
|
|
477
488
|
else if (node.type === 'JSXOpeningElement') {
|
|
478
489
|
scanOpeningElement(node, binding, body, imports, filename)
|
|
479
|
-
const
|
|
480
|
-
if (isComponentTag(
|
|
481
|
-
ref(binding,
|
|
490
|
+
const tag = jsxTagName(node.name)
|
|
491
|
+
if (isComponentTag(tag))
|
|
492
|
+
ref(binding, tag.split('.')[0]!, node.start)
|
|
482
493
|
}
|
|
483
494
|
else if (node.type === 'MemberExpression' && !node.computed && node.object.type === 'Identifier' && freeIds.has(node.object.start) && node.property.type === 'Identifier') {
|
|
484
495
|
memberObjStarts.add(node.object.start)
|
|
@@ -584,6 +595,7 @@ export function analyzeModule(filename: string, code: string, program: Program =
|
|
|
584
595
|
if (interactivity.serverOnly !== undefined)
|
|
585
596
|
guarded(interactivity.serverOnly.offset, () => { throw serverOnlyTagError(filename, interactivity.serverOnly!) })
|
|
586
597
|
|
|
598
|
+
const cacheExport = parseCacheExport(program)
|
|
587
599
|
return {
|
|
588
600
|
filename,
|
|
589
601
|
program,
|
|
@@ -594,6 +606,8 @@ export function analyzeModule(filename: string, code: string, program: Program =
|
|
|
594
606
|
hasJsx: body.hasJsx,
|
|
595
607
|
jsxNodes: body.hasJsx ? computeJsxNodes(program) : new WeakSet<Node>(),
|
|
596
608
|
hasPrerender: decls.hasPrerender,
|
|
609
|
+
prerenderFalse: decls.prerenderFalse,
|
|
610
|
+
...(cacheExport.spec !== undefined ? { cache: cacheExport.spec } : {}),
|
|
597
611
|
hasPaths: decls.hasPaths,
|
|
598
612
|
usesRenderContext: body.usesRenderContext,
|
|
599
613
|
defaultHydrate: decls.defaultHydrate,
|