@kayjs/kay 1.109.0 → 1.111.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/dist/eslint.js +488 -75
- package/editors/zed/extension.toml +2 -2
- package/llms/actions-from-islands.md +1 -1
- package/llms/build-and-start.md +1 -1
- package/llms/checks.md +1 -0
- package/llms/component-libraries.md +1 -1
- package/llms/components.md +1 -1
- package/llms/deprecated-lints.md +1 -1
- package/llms/dev-tool.md +1 -1
- package/llms/effects.md +1 -0
- package/llms/head.md +1 -1
- package/llms/images.md +2 -0
- package/llms/island-and-form-lints.md +2 -1
- package/llms/islands-lazy-components.md +23 -0
- package/llms/islands.md +4 -14
- package/llms/lints.md +1 -1
- package/llms/live-values.md +1 -1
- package/llms/navigation-from-code.md +1 -1
- package/llms/navigation.md +5 -3
- package/llms/performance-lints.md +1 -0
- package/llms/prerendering.md +1 -1
- package/llms/project-new-and-add.md +1 -1
- package/llms/project.md +1 -1
- package/llms/templates-elements-slots-snippets.md +4 -4
- package/llms/upgrading-archive.md +121 -42
- package/llms/upgrading.md +17 -133
- package/llms/whats-new-archive.md +31 -31
- package/llms/whats-new.md +45 -30
- package/llms.txt +3 -2
- package/package.json +11 -11
- package/src/build/client.ts +10 -8
- package/src/build/island-images.ts +277 -0
- package/src/build/pipeline.ts +10 -4
- package/src/build/static.ts +99 -24
- package/src/build/variants.ts +132 -18
- package/src/check/env-types.ts +1 -1
- package/src/check/project.ts +4 -0
- package/src/check/schema-builders.ts +230 -26
- package/src/check/shadow-types.ts +3 -3
- package/src/commands/upgrade.ts +2 -1
- package/src/compiler/allow-comments.ts +38 -2
- package/src/compiler/ast.ts +4 -4
- package/src/compiler/codegen.ts +4 -4
- package/src/compiler/deprecated-lints-1-106.ts +2 -2
- package/src/compiler/dom.ts +4 -3
- package/src/compiler/hand-parts.ts +36 -8
- package/src/compiler/handed-data.ts +15 -0
- package/src/compiler/helper-imports.ts +2 -2
- package/src/compiler/html.ts +3 -7
- package/src/compiler/index.ts +7 -4
- package/src/compiler/island-arguments.ts +9 -0
- package/src/compiler/island-lints.ts +7 -0
- package/src/compiler/items.ts +174 -0
- package/src/compiler/jsx.ts +10 -11
- package/src/compiler/kay-exports.ts +1 -0
- package/src/compiler/lints.ts +6 -7
- package/src/compiler/markup.ts +26 -24
- package/src/compiler/names.ts +1 -1
- package/src/compiler/removed-lints.ts +90 -0
- package/src/compiler/rewrite-types.ts +2 -0
- package/src/compiler/rewrite.ts +4 -2
- package/src/compiler/route-lints.ts +8 -0
- package/src/compiler/signal-from-prop.ts +141 -0
- package/src/compiler/template-reads.ts +16 -0
- package/src/compiler/template-walk.ts +2 -1
- package/src/config-shape.ts +4 -1
- package/src/config.ts +2 -2
- package/src/new.ts +16 -4
- package/src/project.ts +3 -3
- package/src/runtime/await.server.ts +4 -2
- package/src/runtime/checks.ts +14 -2
- package/src/runtime/client.ts +5 -9
- package/src/runtime/dev-tab-env.ts +28 -3
- package/src/runtime/dom-loop.ts +2 -4
- package/src/runtime/dom.ts +2 -2
- package/src/runtime/html.ts +53 -7
- package/src/runtime/image.ts +24 -23
- package/src/runtime/index.ts +2 -2
- package/src/runtime/island.server.ts +41 -11
- package/src/runtime/navigate.ts +14 -0
- package/src/runtime/navigation.ts +9 -1
- package/src/runtime/page-swap.ts +6 -3
- package/src/runtime/reactive.ts +72 -0
- package/src/runtime/row-key.ts +4 -0
- package/src/runtime/swap-flight.ts +10 -10
- package/src/runtime/swap-focus.ts +56 -9
- package/src/runtime/swap-kept.ts +97 -29
- package/src/runtime/swap-morph.ts +49 -9
- package/src/runtime/text-hash.ts +17 -0
- package/src/runtime/uid.server.ts +6 -4
- package/src/runtime/values.ts +12 -0
- package/src/server/client.ts +3 -0
- package/src/server/dev.ts +2 -0
- package/src/server/image.ts +1 -1
- package/src/server/kept-exports.ts +1 -0
- package/src/server/render-document.ts +11 -8
- package/src/server/render.ts +3 -3
- package/types/build/client.d.ts +6 -0
- package/types/build/client.d.ts.map +1 -1
- package/types/build/island-images.d.ts +45 -0
- package/types/build/island-images.d.ts.map +1 -0
- package/types/build/pipeline.d.ts.map +1 -1
- package/types/build/static.d.ts.map +1 -1
- package/types/build/variants.d.ts +9 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/check/project.d.ts.map +1 -1
- package/types/check/schema-builders.d.ts.map +1 -1
- package/types/commands/upgrade.d.ts.map +1 -1
- package/types/compiler/allow-comments.d.ts +2 -0
- package/types/compiler/allow-comments.d.ts.map +1 -1
- package/types/compiler/ast.d.ts +1 -1
- package/types/compiler/ast.d.ts.map +1 -1
- package/types/compiler/deprecated-lints-1-106.d.ts +2 -2
- package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -1
- package/types/compiler/deprecated-lints.d.ts +2 -2
- package/types/compiler/dom.d.ts.map +1 -1
- package/types/compiler/hand-parts.d.ts +6 -3
- package/types/compiler/hand-parts.d.ts.map +1 -1
- package/types/compiler/handed-data.d.ts +5 -0
- package/types/compiler/handed-data.d.ts.map +1 -0
- package/types/compiler/html.d.ts.map +1 -1
- package/types/compiler/index.d.ts.map +1 -1
- package/types/compiler/island-arguments.d.ts +5 -0
- package/types/compiler/island-arguments.d.ts.map +1 -1
- package/types/compiler/island-lints.d.ts +7 -0
- package/types/compiler/island-lints.d.ts.map +1 -1
- package/types/compiler/items.d.ts +14 -0
- package/types/compiler/items.d.ts.map +1 -1
- package/types/compiler/jsx.d.ts.map +1 -1
- package/types/compiler/kay-exports.d.ts.map +1 -1
- package/types/compiler/lints.d.ts +20 -5
- package/types/compiler/lints.d.ts.map +1 -1
- package/types/compiler/markup.d.ts +3 -1
- package/types/compiler/markup.d.ts.map +1 -1
- package/types/compiler/names.d.ts.map +1 -1
- package/types/compiler/removed-lints.d.ts +3 -0
- package/types/compiler/removed-lints.d.ts.map +1 -0
- package/types/compiler/rewrite-types.d.ts +1 -0
- package/types/compiler/rewrite-types.d.ts.map +1 -1
- package/types/compiler/route-lints.d.ts +8 -0
- package/types/compiler/route-lints.d.ts.map +1 -1
- package/types/compiler/signal-from-prop.d.ts +4 -0
- package/types/compiler/signal-from-prop.d.ts.map +1 -0
- package/types/compiler/template-reads.d.ts +1 -0
- package/types/compiler/template-reads.d.ts.map +1 -1
- package/types/compiler/template-walk.d.ts.map +1 -1
- package/types/config-shape.d.ts.map +1 -1
- package/types/config.d.ts +3 -1
- package/types/config.d.ts.map +1 -1
- package/types/new.d.ts.map +1 -1
- package/types/project.d.ts +2 -2
- package/types/project.d.ts.map +1 -1
- package/types/runtime/await.server.d.ts.map +1 -1
- package/types/runtime/checks.d.ts +8 -2
- package/types/runtime/checks.d.ts.map +1 -1
- package/types/runtime/client.d.ts.map +1 -1
- package/types/runtime/dev-tab-env.d.ts.map +1 -1
- package/types/runtime/dom-loop.d.ts +2 -1
- package/types/runtime/dom-loop.d.ts.map +1 -1
- package/types/runtime/dom.d.ts +2 -2
- package/types/runtime/dom.d.ts.map +1 -1
- package/types/runtime/html.d.ts +6 -3
- package/types/runtime/html.d.ts.map +1 -1
- package/types/runtime/image.d.ts.map +1 -1
- package/types/runtime/index.d.ts +2 -2
- package/types/runtime/index.d.ts.map +1 -1
- package/types/runtime/island.server.d.ts +1 -0
- package/types/runtime/island.server.d.ts.map +1 -1
- package/types/runtime/navigate.d.ts.map +1 -1
- package/types/runtime/navigation.d.ts +4 -0
- package/types/runtime/navigation.d.ts.map +1 -1
- package/types/runtime/reactive.d.ts +5 -0
- package/types/runtime/reactive.d.ts.map +1 -1
- package/types/runtime/row-key.d.ts +2 -0
- package/types/runtime/row-key.d.ts.map +1 -0
- package/types/runtime/swap-flight.d.ts +1 -1
- package/types/runtime/swap-flight.d.ts.map +1 -1
- package/types/runtime/swap-focus.d.ts +2 -0
- package/types/runtime/swap-focus.d.ts.map +1 -1
- package/types/runtime/swap-kept.d.ts.map +1 -1
- package/types/runtime/swap-morph.d.ts.map +1 -1
- package/types/runtime/text-hash.d.ts +2 -0
- package/types/runtime/text-hash.d.ts.map +1 -0
- package/types/runtime/uid.server.d.ts.map +1 -1
- package/types/runtime/values.d.ts +4 -0
- package/types/runtime/values.d.ts.map +1 -1
- package/types/server/app-stages.d.ts +3 -1
- package/types/server/app-stages.d.ts.map +1 -1
- package/types/server/app.d.ts +3 -1
- package/types/server/app.d.ts.map +1 -1
- package/types/server/client.d.ts +2 -0
- package/types/server/client.d.ts.map +1 -1
- package/types/server/dev.d.ts +1 -0
- package/types/server/dev.d.ts.map +1 -1
- package/types/server/kept-exports.d.ts.map +1 -1
- package/types/server/render-document.d.ts +1 -1
- package/types/server/render-document.d.ts.map +1 -1
- package/types/server/render.d.ts +2 -2
- package/types/server/render.d.ts.map +1 -1
package/src/build/static.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Project } from '../project'
|
|
|
3
3
|
import type { ClientBuild } from '../server/client'
|
|
4
4
|
import type { Redirects } from '../server/redirects'
|
|
5
5
|
import { existsSync } from 'node:fs'
|
|
6
|
-
import { cp, mkdir, readdir, rm } from 'node:fs/promises'
|
|
6
|
+
import { cp, mkdir, readdir, rename, rm } from 'node:fs/promises'
|
|
7
7
|
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
8
8
|
import process from 'node:process'
|
|
9
9
|
import { Elysia } from 'elysia'
|
|
@@ -71,14 +71,36 @@ function inside(out: string, name: string): string {
|
|
|
71
71
|
return file
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
// Writes the whole site to `outdir
|
|
74
|
+
// Writes the whole site to a folder beside `outdir` and moves it over `outdir` once it is complete, so a host serving `outdir` always finds a whole export: the last one until the new one is in place, and still the last one when the export fails.
|
|
75
|
+
// The site is what any static host serves: every prerendered page, the browser build under `/_kay/`, the public files, the sitemap, feeds and favicons, `404.html`, and a page for each redirect.
|
|
75
76
|
// Each page goes in as `about.html` and `about/index.html`, which every host finds for `/about` and `/about/` alike, beside the compressed copies a host may send as they are.
|
|
76
77
|
export async function exportStatic(project: Project, client: ClientBuild, outdir: string): Promise<StaticExport> {
|
|
77
|
-
|
|
78
|
+
// Files still being written when one fails, which finish before the staged folder is removed.
|
|
79
|
+
const pending = new Set<Promise<unknown>>()
|
|
78
80
|
const out = resolve(outdir)
|
|
79
81
|
|
|
80
|
-
refuseStaticConfig(config)
|
|
81
|
-
await
|
|
82
|
+
refuseStaticConfig(project.config)
|
|
83
|
+
await checkOutput(project.root, out)
|
|
84
|
+
await removeLeftovers(out)
|
|
85
|
+
await mkdir(stagingOf(out), { recursive: true })
|
|
86
|
+
// Marked first, so the folder is one an export wrote once it is in place, and a later export may clear it.
|
|
87
|
+
await Bun.write(join(stagingOf(out), MARKER), '')
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
const site = await writeSite(project, client, stagingOf(out), pending)
|
|
91
|
+
|
|
92
|
+
await swapIn(out)
|
|
93
|
+
|
|
94
|
+
return site
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
await Promise.allSettled(pending)
|
|
98
|
+
await rm(stagingOf(out), { recursive: true, force: true })
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function writeSite(project: Project, client: ClientBuild, out: string, pending: Set<Promise<unknown>>): Promise<StaticExport> {
|
|
103
|
+
const { root, config, paths: { public: publicDir, output } } = project
|
|
82
104
|
|
|
83
105
|
const pagesDir = join(output, PRERENDERED_DIR)
|
|
84
106
|
const built = [...client.pages]
|
|
@@ -90,19 +112,25 @@ export async function exportStatic(project: Project, client: ClientBuild, outdir
|
|
|
90
112
|
const limit = limiter(FILES_AT_ONCE)
|
|
91
113
|
let failed = false
|
|
92
114
|
// The first failure stops the files still waiting for their turn, as a loop stopped at it.
|
|
93
|
-
const writing = async <T>(task: () => Promise<T>): Promise<T | undefined> =>
|
|
94
|
-
|
|
95
|
-
|
|
115
|
+
const writing = async <T>(task: () => Promise<T>): Promise<T | undefined> => {
|
|
116
|
+
const running = limit(async () => {
|
|
117
|
+
if (failed)
|
|
118
|
+
return undefined
|
|
96
119
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
120
|
+
try {
|
|
121
|
+
return await task()
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
failed = true
|
|
102
125
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
126
|
+
throw error
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
pending.add(running)
|
|
131
|
+
|
|
132
|
+
return running
|
|
133
|
+
}
|
|
106
134
|
|
|
107
135
|
await Promise.all(built.flatMap(([path, page]) => pageFiles(path).flatMap(target => ['', ...COPIES].map(async copy => writing(async () => {
|
|
108
136
|
const source = join(pagesDir, `${page.file}${copy}`)
|
|
@@ -236,24 +264,71 @@ function overProject(root: string, out: string): boolean {
|
|
|
236
264
|
return out === root || root.startsWith(out + sep) || out.startsWith(join(root, 'src') + sep) || out === join(root, 'src')
|
|
237
265
|
}
|
|
238
266
|
|
|
239
|
-
//
|
|
267
|
+
// Where an export is written before it replaces `out`, and where the last one waits to be removed: beside it, so the move is a rename on one filesystem.
|
|
268
|
+
function stagingOf(out: string): string {
|
|
269
|
+
return `${out}.kay-staging`
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function asideOf(out: string): string {
|
|
273
|
+
return `${out}.kay-old`
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// What an export killed halfway left beside `out`.
|
|
277
|
+
async function removeLeftovers(out: string): Promise<void> {
|
|
278
|
+
await Promise.all([stagingOf(out), asideOf(out)].map(async folder => rm(folder, { recursive: true, force: true })))
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Whether git ignores the folder, which Tailwind then leaves out of its scan of the project.
|
|
282
|
+
async function ignoredByGit(root: string, out: string): Promise<boolean> {
|
|
283
|
+
try {
|
|
284
|
+
const check = Bun.spawn(['git', '-C', root, 'check-ignore', '-q', '--', `${out}/`], { stdout: 'ignore', stderr: 'ignore', stdin: 'ignore' })
|
|
285
|
+
|
|
286
|
+
return await check.exited === 0
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
return false
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// The last export, which a build removes first when Tailwind would scan its pages as sources of the stylesheets: only a folder an export wrote, and none git ignores, which stays for a host to serve until the new export replaces it.
|
|
240
294
|
export async function removeLastExport(root: string, out: string): Promise<void> {
|
|
241
|
-
if (
|
|
295
|
+
if (overProject(root, out))
|
|
296
|
+
return
|
|
297
|
+
|
|
298
|
+
await removeLeftovers(out)
|
|
299
|
+
|
|
300
|
+
if (existsSync(join(out, MARKER)) && !await ignoredByGit(root, out))
|
|
242
301
|
await rm(out, { recursive: true, force: true })
|
|
243
302
|
}
|
|
244
303
|
|
|
304
|
+
// The staged export in place of the last one: that one moved aside, the new one renamed in, the old one removed.
|
|
305
|
+
async function swapIn(out: string): Promise<void> {
|
|
306
|
+
const aside = asideOf(out)
|
|
307
|
+
|
|
308
|
+
if (existsSync(out))
|
|
309
|
+
await rename(out, aside)
|
|
310
|
+
|
|
311
|
+
try {
|
|
312
|
+
await rename(stagingOf(out), out)
|
|
313
|
+
}
|
|
314
|
+
catch (error) {
|
|
315
|
+
// The last export goes back, so a failed move leaves it in place.
|
|
316
|
+
if (existsSync(aside))
|
|
317
|
+
await rename(aside, out)
|
|
318
|
+
|
|
319
|
+
throw error
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
await rm(aside, { recursive: true, force: true })
|
|
323
|
+
}
|
|
324
|
+
|
|
245
325
|
// A directory kay may write to: never the project or what holds it, and one with files in it only when an export wrote them.
|
|
246
|
-
async function
|
|
326
|
+
async function checkOutput(root: string, out: string): Promise<void> {
|
|
247
327
|
if (overProject(root, out))
|
|
248
328
|
throw new KayError('export-output-dir', `kay: a static export into ${relative(process.cwd(), out) || '.'} would write over the project; give it a directory of its own, such as dist`)
|
|
249
329
|
|
|
250
330
|
if (existsSync(out) && (await readdir(out)).length > 0 && !existsSync(join(out, MARKER)))
|
|
251
331
|
throw new KayError('export-output-dir', `kay: ${relative(process.cwd(), out)} holds files a static export did not write; empty it or give another directory`)
|
|
252
|
-
|
|
253
|
-
await rm(out, { recursive: true, force: true })
|
|
254
|
-
await mkdir(out, { recursive: true })
|
|
255
|
-
// Marked first, so an export failing halfway leaves a directory the next one may clear.
|
|
256
|
-
await Bun.write(join(out, MARKER), '')
|
|
257
332
|
}
|
|
258
333
|
|
|
259
334
|
// The files a page path is written to: `/` as `index.html`, any other both ways.
|
package/src/build/variants.ts
CHANGED
|
@@ -5,10 +5,13 @@ import { dirname, join } from 'node:path'
|
|
|
5
5
|
import { elementsIn } from '../compiler/ast'
|
|
6
6
|
import { changeName } from '../compiler/bound-props'
|
|
7
7
|
import { parseExpanded } from '../compiler/markdown-block'
|
|
8
|
+
import { analyzeScript } from '../compiler/script'
|
|
8
9
|
|
|
9
10
|
// A component names the features an app may leave out with `uses('selectable')`, the `uses` it imports from kayjs-ui's marker module: a call that is true while the prop is there to be written, and that a browser build replaces with `true` or `false` once it has read the props the files of the project write at their call sites. See `specializedSource`.
|
|
10
11
|
const USES_CALL = /\buses\(\s*'(\w+)'(\s*,\s*true)?\s*\)/y
|
|
11
12
|
const KAY_IMPORT = /^import\s+(\w+)\s+from\s+(["'])([^"'\n]+\.kay)\2/gm
|
|
13
|
+
// Whether a file imports a `.kay` component, one that may hand its rest props on to a component with features.
|
|
14
|
+
const HAS_KAY_IMPORT = /^import\s+\w+\s+from\s+(["'])[^"'\n]+\.kay\1/m
|
|
12
15
|
// A component the compiler imports lazily, `KayLazy(key, () => import("./it.kay"))`.
|
|
13
16
|
const LAZY_IMPORT = /\bimport\(\s*(["'])([^"'\n]+\.kay)\1\s*\)/g
|
|
14
17
|
const USES_IMPORT = /^import\s*\{[^}]*\buses\b[^}]*\}\s*from\s*(["'])([^"'\n]+)\1/m
|
|
@@ -20,6 +23,7 @@ const FENCE = /^---(?:\s|$)/
|
|
|
20
23
|
const USES_IF = /^([ \t]*)((?:else )?if) (.*\buses\(.*)$/
|
|
21
24
|
const IDENTIFIER_CHAR = /[\w$.]/
|
|
22
25
|
const BACKSLASH = /\\/g
|
|
26
|
+
const COMMENT_LINE = /^[ \t]*\/\/.*$/gm
|
|
23
27
|
|
|
24
28
|
// The suffix an import of a variant carries: the features, joined by dashes (a dot would end the stem of the file name the bundler gives an entry), the call sites of the project use.
|
|
25
29
|
// `~` and the props the call sites write follow when the project reads them all: the props a spread may carry are not known.
|
|
@@ -176,14 +180,18 @@ function replaceCalls(text: string, answer: (feature: string, onByDefault: boole
|
|
|
176
180
|
interface Declared {
|
|
177
181
|
names: string[]
|
|
178
182
|
defaults: ReadonlySet<string>
|
|
183
|
+
// Whether the file imports a `.kay` component, so its callers' props may reach a feature through it.
|
|
184
|
+
imports?: boolean
|
|
179
185
|
}
|
|
180
186
|
|
|
181
187
|
const NONE: Declared = { names: [], defaults: new Set() }
|
|
182
188
|
const featuresOf = new Map<string, { stamp: number, declared: Promise<Declared> }>()
|
|
183
189
|
|
|
184
190
|
function usesIn(source: string, file: string): Declared {
|
|
191
|
+
const imports = HAS_KAY_IMPORT.test(source)
|
|
192
|
+
|
|
185
193
|
if (file !== '' && !importsMarker(source, file))
|
|
186
|
-
return NONE
|
|
194
|
+
return imports ? { ...NONE, imports } : NONE
|
|
187
195
|
|
|
188
196
|
const found = new Set<string>()
|
|
189
197
|
const defaults = new Set<string>()
|
|
@@ -197,7 +205,7 @@ function usesIn(source: string, file: string): Declared {
|
|
|
197
205
|
return ''
|
|
198
206
|
})
|
|
199
207
|
|
|
200
|
-
return { names: [...found], defaults }
|
|
208
|
+
return { names: [...found], defaults, imports }
|
|
201
209
|
}
|
|
202
210
|
|
|
203
211
|
// The features a text names: the `uses('x')` of a file importing the marker, none otherwise.
|
|
@@ -466,12 +474,18 @@ export function specializedSource(source: string, present: ReadonlySet<string>,
|
|
|
466
474
|
// Stands for every prop of a component: it is called with a spread or read as a value, so any may be written.
|
|
467
475
|
export const ANY = Symbol('any')
|
|
468
476
|
|
|
477
|
+
// Stands in a call's props for a spread of the file's own rest props: what the file's callers write reaches the component, minus the props the file takes by name.
|
|
478
|
+
const PASSED = '...'
|
|
479
|
+
// Starts what stands in the props for `name={prop}`, `prop` a prop the file takes by name with no default: `name` is written when the file's callers write `prop`.
|
|
480
|
+
const FORWARDED = '>'
|
|
481
|
+
|
|
469
482
|
// What stands for a call that leaves a feature on by default (`uses('x', true)`) on: the prop left out or written with anything but a literal `false`.
|
|
470
483
|
const ON_PREFIX = '+'
|
|
471
484
|
const PROP_NAME = /^\w+$/
|
|
472
485
|
|
|
473
486
|
// The props the call sites of each `.kay` component a file imports write, by the name the file gives it; `defaults` names, by local, the features on when the prop is left out, which a call keeps on by adding `+name`.
|
|
474
|
-
|
|
487
|
+
// A spread of `rest.name`, the file's own rest props, hands its callers' props on instead of any: `PASSED` stands in the props for it. An attribute written as a prop `rest.forwards` names is written when that prop is.
|
|
488
|
+
export function propsWritten(source: string, locals: readonly string[], defaults: ReadonlyMap<string, ReadonlySet<string>> = new Map(), rest?: Pick<Rest, 'name' | 'forwards'>): Map<string, Set<string> | typeof ANY> {
|
|
475
489
|
const { file } = parseExpanded(source)
|
|
476
490
|
const written = new Map<string, Set<string>>()
|
|
477
491
|
const calls = new Map<string, number>()
|
|
@@ -488,10 +502,17 @@ export function propsWritten(source: string, locals: readonly string[], defaults
|
|
|
488
502
|
written.set(element.name, props)
|
|
489
503
|
|
|
490
504
|
const off = new Set<string>()
|
|
505
|
+
let passed = false
|
|
491
506
|
|
|
492
507
|
for (const attribute of element.attributes) {
|
|
493
508
|
if (attribute.kind === 'spread') {
|
|
494
|
-
|
|
509
|
+
if (rest !== undefined && source.slice(attribute.expression.start, attribute.expression.end).trim() === rest.name) {
|
|
510
|
+
props.add(PASSED)
|
|
511
|
+
passed = true
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
open.delete(element.name)
|
|
515
|
+
}
|
|
495
516
|
|
|
496
517
|
continue
|
|
497
518
|
}
|
|
@@ -506,14 +527,18 @@ export function propsWritten(source: string, locals: readonly string[], defaults
|
|
|
506
527
|
continue
|
|
507
528
|
}
|
|
508
529
|
|
|
509
|
-
|
|
530
|
+
const value = attribute.kind === 'expression' ? source.slice(attribute.expression.start, attribute.expression.end).trim() : undefined
|
|
531
|
+
const forwarded = value === undefined ? undefined : rest?.forwards.get(value)
|
|
532
|
+
|
|
533
|
+
props.add(forwarded === undefined ? name : `${FORWARDED}${name}=${forwarded}`)
|
|
510
534
|
|
|
511
|
-
if (
|
|
535
|
+
if (value === 'false')
|
|
512
536
|
off.add(name)
|
|
513
537
|
}
|
|
514
538
|
|
|
515
539
|
for (const feature of defaults.get(element.name) ?? []) {
|
|
516
|
-
|
|
540
|
+
// A spread may bring the prop back on, whatever was written before it.
|
|
541
|
+
if (passed || !off.has(feature))
|
|
517
542
|
props.add(ON_PREFIX + feature)
|
|
518
543
|
}
|
|
519
544
|
|
|
@@ -522,15 +547,42 @@ export function propsWritten(source: string, locals: readonly string[], defaults
|
|
|
522
547
|
}
|
|
523
548
|
}
|
|
524
549
|
|
|
550
|
+
// A comment line naming the component is no read of it.
|
|
551
|
+
const code = source.replace(COMMENT_LINE, '')
|
|
552
|
+
|
|
525
553
|
for (const local of locals) {
|
|
526
554
|
// The import names it once, each call once more.
|
|
527
|
-
if ((
|
|
555
|
+
if ((code.match(new RegExp(`\\b${local}\\b`, 'g'))?.length ?? 0) !== 1 + (calls.get(local) ?? 0))
|
|
528
556
|
open.delete(local)
|
|
529
557
|
}
|
|
530
558
|
|
|
531
559
|
return new Map(locals.map(local => [local, open.has(local) ? written.get(local) ?? new Set<string>() : ANY]))
|
|
532
560
|
}
|
|
533
561
|
|
|
562
|
+
// The name of a file's rest props (none when it has none), the props it takes by name (which its spread of the rest does not hand on) and, of those with no default, the key by the name the file reads it as.
|
|
563
|
+
interface Rest {
|
|
564
|
+
name: string
|
|
565
|
+
taken: Set<string>
|
|
566
|
+
forwards: Map<string, string>
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function restOf(source: string): Rest | undefined {
|
|
570
|
+
try {
|
|
571
|
+
const { file } = parseExpanded(source)
|
|
572
|
+
const { props } = analyzeScript(file.source, file.script, [], file.module)
|
|
573
|
+
|
|
574
|
+
if (props === undefined)
|
|
575
|
+
return undefined
|
|
576
|
+
|
|
577
|
+
const forwards = new Map(props.bindings.filter(binding => binding.fallback === undefined).map(binding => [file.source.slice(binding.local.start, binding.local.end), binding.key]))
|
|
578
|
+
|
|
579
|
+
return { name: props.rest === undefined ? '' : file.source.slice(props.rest.start, props.rest.end), taken: new Set(props.bindings.map(binding => binding.key)), forwards }
|
|
580
|
+
}
|
|
581
|
+
catch {
|
|
582
|
+
return undefined
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
534
586
|
interface Candidate {
|
|
535
587
|
local: string
|
|
536
588
|
specifier: string
|
|
@@ -539,8 +591,8 @@ interface Candidate {
|
|
|
539
591
|
defaults: ReadonlySet<string>
|
|
540
592
|
}
|
|
541
593
|
|
|
542
|
-
// The `.kay` components a file imports that name features.
|
|
543
|
-
async function candidatesOf(code: string, file: string): Promise<Candidate[]> {
|
|
594
|
+
// The `.kay` components a file imports that name features, and with `passing` those importing a component too, whose callers may reach a feature through them.
|
|
595
|
+
async function candidatesOf(code: string, file: string, passing = false): Promise<Candidate[]> {
|
|
544
596
|
const found: Candidate[] = []
|
|
545
597
|
|
|
546
598
|
for (const [local, specifier] of [...code.matchAll(KAY_IMPORT).map(([, name, , from]) => [name!, from!] as const), ...code.matchAll(LAZY_IMPORT).map(([, , from]) => ['', from!] as const)]) {
|
|
@@ -553,9 +605,9 @@ async function candidatesOf(code: string, file: string): Promise<Candidate[]> {
|
|
|
553
605
|
continue
|
|
554
606
|
}
|
|
555
607
|
|
|
556
|
-
const { names: features, defaults } = await declaredFeatures(path)
|
|
608
|
+
const { names: features, defaults, imports } = await declaredFeatures(path)
|
|
557
609
|
|
|
558
|
-
if (features.length > 0)
|
|
610
|
+
if (features.length > 0 || (passing && imports === true))
|
|
559
611
|
found.push({ local, specifier, path, features, defaults })
|
|
560
612
|
}
|
|
561
613
|
|
|
@@ -565,6 +617,8 @@ async function candidatesOf(code: string, file: string): Promise<Candidate[]> {
|
|
|
565
617
|
// What the `.kay` files of a project write of each component with features, all of them together: a component has one variant, so the chunks of two islands using a Table share it.
|
|
566
618
|
export class VariantIndex {
|
|
567
619
|
private readonly union = new Map<string, Set<string> | typeof ANY>()
|
|
620
|
+
// The files handing their rest props on to a component, by its path: what their own callers write reaches it.
|
|
621
|
+
private readonly through = new Map<string, { from: string, taken: ReadonlySet<string>, forwards: [name: string, key: string][] }[]>()
|
|
568
622
|
private readonly indexed = new Map<string, Promise<void>>()
|
|
569
623
|
private scan: Promise<void> | undefined
|
|
570
624
|
|
|
@@ -594,15 +648,16 @@ export class VariantIndex {
|
|
|
594
648
|
}
|
|
595
649
|
|
|
596
650
|
private async read(file: string, source: string): Promise<void> {
|
|
597
|
-
const candidates = (await candidatesOf(source, file)).filter(candidate => candidate.local !== '')
|
|
651
|
+
const candidates = (await candidatesOf(source, file, true)).filter(candidate => candidate.local !== '')
|
|
598
652
|
|
|
599
653
|
if (candidates.length === 0)
|
|
600
654
|
return
|
|
601
655
|
|
|
602
656
|
let written: ReturnType<typeof propsWritten>
|
|
657
|
+
const rest = restOf(source)
|
|
603
658
|
|
|
604
659
|
try {
|
|
605
|
-
written = propsWritten(source, candidates.map(candidate => candidate.local), new Map(candidates.map(candidate => [candidate.local, candidate.defaults])))
|
|
660
|
+
written = propsWritten(source, candidates.map(candidate => candidate.local), new Map(candidates.map(candidate => [candidate.local, candidate.defaults])), rest)
|
|
606
661
|
}
|
|
607
662
|
catch {
|
|
608
663
|
written = new Map(candidates.map(candidate => [candidate.local, ANY]))
|
|
@@ -612,13 +667,62 @@ export class VariantIndex {
|
|
|
612
667
|
const props = written.get(local) ?? new Set<string>()
|
|
613
668
|
const before = this.union.get(path)
|
|
614
669
|
|
|
670
|
+
if (props !== ANY && rest !== undefined) {
|
|
671
|
+
const forwards = [...props].filter(name => name.startsWith(FORWARDED)).map(name => name.slice(1).split('=') as [string, string])
|
|
672
|
+
|
|
673
|
+
for (const name of [...props].filter(name => name.startsWith(FORWARDED)))
|
|
674
|
+
props.delete(name)
|
|
675
|
+
|
|
676
|
+
if (props.delete(PASSED) || forwards.length > 0)
|
|
677
|
+
this.through.set(path, [...this.through.get(path) ?? [], { from: realFile(file), taken: rest.taken, forwards }])
|
|
678
|
+
}
|
|
679
|
+
|
|
615
680
|
this.union.set(path, before === ANY || props === ANY ? ANY : new Set([...before ?? [], ...props]))
|
|
616
681
|
}
|
|
617
682
|
}
|
|
618
683
|
|
|
684
|
+
// What the call sites of a component write, the ones handing their rest props on counted by what their own callers write.
|
|
685
|
+
private writtenOf(path: string, seen = new Set<string>()): Set<string> | typeof ANY {
|
|
686
|
+
const own = this.union.get(path)
|
|
687
|
+
|
|
688
|
+
if (own === ANY)
|
|
689
|
+
return ANY
|
|
690
|
+
|
|
691
|
+
const links = this.through.get(path)
|
|
692
|
+
|
|
693
|
+
if (links === undefined || seen.has(path))
|
|
694
|
+
return own ?? new Set<string>()
|
|
695
|
+
|
|
696
|
+
const all = new Set(own)
|
|
697
|
+
|
|
698
|
+
seen.add(path)
|
|
699
|
+
|
|
700
|
+
for (const { from, taken, forwards } of links) {
|
|
701
|
+
// A file no scanned call site writes is called from where the scan does not look (a route, a layout, a `.ts` module, a package), so what reaches it is unknown.
|
|
702
|
+
const outer = this.union.has(from) || this.through.has(from) ? this.writtenOf(from, seen) : ANY
|
|
703
|
+
|
|
704
|
+
if (outer === ANY)
|
|
705
|
+
return ANY
|
|
706
|
+
|
|
707
|
+
for (const [name, key] of forwards) {
|
|
708
|
+
if (outer.has(key))
|
|
709
|
+
all.add(name)
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
for (const name of outer) {
|
|
713
|
+
if (!name.startsWith(ON_PREFIX) && !taken.has(name))
|
|
714
|
+
all.add(name)
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
seen.delete(path)
|
|
719
|
+
|
|
720
|
+
return all
|
|
721
|
+
}
|
|
722
|
+
|
|
619
723
|
// The query of a variant: its features, then the props written.
|
|
620
724
|
private usedOf(path: string, features: string[], defaults: ReadonlySet<string>): string {
|
|
621
|
-
const props = this.
|
|
725
|
+
const props = this.writtenOf(path)
|
|
622
726
|
|
|
623
727
|
if (props === ANY)
|
|
624
728
|
return [...features].sort().join('-')
|
|
@@ -642,12 +746,12 @@ export class VariantIndex {
|
|
|
642
746
|
async variantImports(code: string, file: string, source: string): Promise<string> {
|
|
643
747
|
const candidates = await candidatesOf(code, file)
|
|
644
748
|
|
|
645
|
-
if (candidates.length === 0)
|
|
646
|
-
return code
|
|
647
|
-
|
|
648
749
|
await this.scanned()
|
|
649
750
|
await this.add(file, source)
|
|
650
751
|
|
|
752
|
+
if (candidates.length === 0)
|
|
753
|
+
return code
|
|
754
|
+
|
|
651
755
|
let result = code
|
|
652
756
|
|
|
653
757
|
for (const { specifier, path, features, defaults } of candidates) {
|
|
@@ -661,6 +765,16 @@ export class VariantIndex {
|
|
|
661
765
|
}
|
|
662
766
|
}
|
|
663
767
|
|
|
768
|
+
// A file by the path its importers resolve it to.
|
|
769
|
+
function realFile(file: string): string {
|
|
770
|
+
try {
|
|
771
|
+
return Bun.resolveSync(file, dirname(file))
|
|
772
|
+
}
|
|
773
|
+
catch {
|
|
774
|
+
return file
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
664
778
|
// The `.kay` files under a directory, leaving out what a project installs and builds.
|
|
665
779
|
export function kayFiles(dir: string): string[] {
|
|
666
780
|
const found: string[] = []
|
package/src/check/env-types.ts
CHANGED
|
@@ -182,7 +182,7 @@ function environment(patterns: string[], files: string[], api: { mount: string,
|
|
|
182
182
|
' function KayFormError<Target extends string | Action>(target: Target, field?: FieldName<Target>): null',
|
|
183
183
|
' function KayProp<Component>(component: Component): <Value>(value: Value & IslandProp<Component, Value>) => Value',
|
|
184
184
|
' function KayPlainProp<Component>(component: Component): <Value>(value: Value & PlainIslandProp<Component, Value>) => Value',
|
|
185
|
-
' function KayFunctionProp<Component
|
|
185
|
+
' function KayFunctionProp<Component, Names extends object = Record<string, unknown>>(component: Component, names?: Names): (attribute: FunctionProp<Component, Names>) => Record<never, never>',
|
|
186
186
|
' function KayHandsPart<Component>(component: Component): <Name extends string>(name: Name & HandsPart<Component, Name>) => Record<never, never>',
|
|
187
187
|
' function KayBound<Component>(component: Component): <Key extends string, Value>(key: Key & BoundProp<Component, Key>, value: Value, write: (value: BoundValue<Component, Key>) => unknown) => Value',
|
|
188
188
|
' function KayList<Each extends Iterable<any> | null | undefined | false>(each: Each): Each',
|
package/src/check/project.ts
CHANGED
|
@@ -19,6 +19,7 @@ import { importedSignals } from '../build/signals'
|
|
|
19
19
|
import { browserRole, onceReadChecks } from '../compiler'
|
|
20
20
|
import { moduleChecks, turnsCaptchaOff } from '../compiler/fence-checks'
|
|
21
21
|
import { isLaunchLint, isLint, isLintGroup, LEVELS, lintLevel, lintLevels } from '../compiler/lints'
|
|
22
|
+
import { REMOVED_LINTS } from '../compiler/removed-lints'
|
|
22
23
|
import { CONFIG_FILE } from '../config'
|
|
23
24
|
import { EXTENSIONS_MARKER, FEEDS_MARKER, PROBLEMS_MARKER, ROUTES_MARKER, USES_MARKER } from '../content/claims'
|
|
24
25
|
import { projectPaths } from '../project'
|
|
@@ -295,6 +296,9 @@ function lintConfigProblems(root: string, lints: LintLevels = {}): CheckDiagnost
|
|
|
295
296
|
return levelEntries(lints).flatMap(([name, level]) => {
|
|
296
297
|
const at = { file, ...locate(['lints', name]) }
|
|
297
298
|
|
|
299
|
+
if ((REMOVED_LINTS as readonly string[]).includes(name))
|
|
300
|
+
return [{ ...at, severity: 'warning' as const, message: `\`lints\` names \`${name}\`, a lint kay has removed with the form it reported`, help: 'remove the entry: it changes nothing' }]
|
|
301
|
+
|
|
298
302
|
if (!isLint(name) && !isLintGroup(name))
|
|
299
303
|
return [{ ...at, message: `\`lints\` names \`${name}\`, which is no lint or group`, help: '`kay explain` lists them' }]
|
|
300
304
|
|