@kayjs/kay 1.105.0 → 1.106.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 +435 -120
- package/editors/zed/extension.toml +2 -2
- package/llms/action-protection.md +1 -1
- package/llms/actions-from-islands.md +2 -2
- package/llms/actions.md +22 -19
- package/llms/analytics.md +1 -1
- package/llms/api-from-islands.md +1 -1
- package/llms/api-routes.md +6 -6
- package/llms/check-and-tools.md +1 -1
- package/llms/code-lints.md +2 -2
- package/llms/compiler-api.md +1 -1
- package/llms/component-libraries.md +1 -0
- package/llms/content-cms.md +1 -1
- package/llms/content-markdown-to-caching.md +1 -1
- package/llms/content-preview.md +2 -2
- package/llms/content.md +21 -21
- package/llms/deprecated-lints-1-105-libraries.md +2 -0
- package/llms/deprecated-lints-1-105.md +3 -3
- package/llms/deprecated-lints.md +3 -2
- package/llms/dev-tool.md +2 -2
- package/llms/environment.md +22 -22
- package/llms/files.md +5 -5
- package/llms/islands-state-to-ids.md +2 -1
- package/llms/local-collections.md +2 -2
- package/llms/mcp.md +2 -1
- package/llms/navigation-from-code.md +1 -1
- package/llms/notifications.md +4 -2
- package/llms/project.md +1 -1
- package/llms/rate-limits.md +1 -1
- package/llms/recipes.md +16 -16
- package/llms/rooms.md +4 -4
- package/llms/routing-endpoints-and-base.md +1 -1
- package/llms/routing.md +5 -5
- package/llms/schemas.md +10 -5
- package/llms/server.md +7 -7
- package/llms/site.md +9 -9
- package/llms/sitemap-search-fonts.md +2 -0
- package/llms/styles-and-assets.md +2 -1
- package/llms/templates-elements-slots-snippets.md +2 -2
- package/llms/testing-browser.md +20 -0
- package/llms/testing.md +1 -1
- package/llms/upgrading-1-105-config.md +2 -2
- package/llms/upgrading.md +18 -3
- package/llms/whats-new-archive.md +35 -66
- package/llms/whats-new.md +34 -28
- package/llms.txt +1 -1
- package/package.json +15 -11
- package/src/add.ts +1 -1
- package/src/build/class-table.ts +2 -2
- package/src/build/client.ts +7 -6
- package/src/build/plugin.ts +14 -11
- package/src/build/styles.ts +3 -3
- package/src/build/transform.ts +3 -1
- package/src/build/ui-layers.ts +30 -0
- package/src/build/ui.ts +108 -11
- package/src/build/variants.ts +119 -43
- package/src/build/worker-bundle.ts +6 -0
- package/src/check/boot.ts +22 -1
- package/src/check/call-result.ts +242 -0
- package/src/check/config-objects.ts +17 -2
- package/src/check/diagnose.ts +22 -0
- package/src/check/handler-events.ts +149 -0
- package/src/check/index.ts +6 -2
- package/src/check/link-flag-tests.ts +130 -0
- package/src/check/project.ts +4 -3
- package/src/check/refusal-calls.ts +2 -2
- package/src/check/regroup.ts +5 -3
- package/src/check/renamed-packages.ts +58 -14
- package/src/check/schema-builders.ts +256 -0
- package/src/check/secret-keys.ts +15 -2
- package/src/check/shadow-types.ts +2 -0
- package/src/check/template-hints.ts +1 -1
- package/src/check/tool-labels.ts +11 -9
- package/src/check/ui-types.ts +4 -3
- package/src/check/ui.ts +14 -11
- package/src/commands/env-declare.ts +18 -6
- package/src/commands/routes.ts +1 -1
- package/src/compiler/a11y.ts +8 -1
- package/src/compiler/ast.ts +1 -1
- package/src/compiler/bound-props.ts +1 -1
- package/src/compiler/codegen.ts +6 -6
- package/src/compiler/deprecated-lints-1-106.ts +14 -0
- package/src/compiler/deprecated-lints.ts +10 -5
- package/src/compiler/deprecated-typed-lints.ts +23 -0
- package/src/compiler/dom-here.ts +72 -0
- package/src/compiler/dom.ts +23 -23
- package/src/compiler/fence-checks.ts +12 -11
- package/src/compiler/field-described.ts +2 -2
- package/src/compiler/helper-imports.ts +1 -1
- package/src/compiler/html-fields.ts +92 -0
- package/src/compiler/html-initial.ts +5 -3
- package/src/compiler/html.ts +14 -31
- package/src/compiler/index.ts +3 -1
- package/src/compiler/items.ts +5 -5
- package/src/compiler/link-flags.ts +6 -5
- package/src/compiler/lints.ts +12 -12
- package/src/compiler/rest-omits.ts +15 -0
- package/src/config-loader.ts +10 -2
- package/src/config-resolve.ts +3 -1
- package/src/config-shape.ts +2 -2
- package/src/config.ts +20 -4
- package/src/content/markdown.ts +2 -3
- package/src/generate-resource.ts +9 -9
- package/src/generate.ts +1 -1
- package/src/mcp/guards.ts +1 -1
- package/src/mcp/tools.ts +1 -1
- package/src/migrate/content.ts +61 -55
- package/src/runtime/action-shared.ts +2 -2
- package/src/runtime/action.ts +6 -2
- package/src/runtime/form-types.ts +99 -0
- package/src/runtime/form.ts +22 -7
- package/src/runtime/html.ts +36 -5
- package/src/runtime/markdown-autolink.ts +69 -0
- package/src/runtime/markdown-render.client.ts +39 -3
- package/src/runtime/markdown.client.ts +6 -3
- package/src/runtime/markdown.server.ts +6 -3
- package/src/runtime/markdown.ts +125 -1
- package/src/runtime/navigate-api.ts +10 -5
- package/src/runtime/persist.ts +7 -7
- package/src/runtime/query-param.ts +1 -1
- package/src/runtime/reactive.ts +14 -0
- package/src/runtime/sanitize.ts +3 -1
- package/src/runtime/schema-record.ts +31 -0
- package/src/runtime/schema.client.ts +1 -4
- package/src/runtime/schema.ts +321 -26
- package/src/runtime/swap-focus.ts +59 -11
- package/src/server/action-module.ts +16 -0
- package/src/server/actions.ts +6 -14
- package/src/server/api-modules.ts +1 -1
- package/src/server/api.ts +13 -1
- package/src/server/app-stages.ts +23 -18
- package/src/server/dev-ui.ts +2 -2
- package/src/server/env-state.ts +1 -1
- package/src/server/env.ts +11 -3
- package/src/server/favicon.ts +47 -1
- package/src/server/image-metadata-bmff.ts +1 -1
- package/src/server/kept-pages.ts +3 -3
- package/src/server/library.ts +2 -0
- package/src/server/mcp.ts +13 -12
- package/src/server/notifications.ts +4 -2
- package/src/server/offline.ts +24 -7
- package/src/server/push-settings.ts +16 -2
- package/src/server/push.ts +12 -4
- package/src/server/query.ts +13 -6
- package/src/server/render.ts +1 -1
- package/src/server/scope.ts +20 -13
- package/src/server/signals.ts +4 -4
- package/src/template-ws.ts +1 -1
- package/src/test/a11y-dom.ts +70 -0
- package/src/test/html-snapshot.ts +103 -0
- package/src/test/index.ts +2 -1
- package/src/test/mount.ts +8 -1
- package/src/test/page-checks.ts +12 -0
- package/src/test/screenshot-match.ts +2 -2
- package/src/test/shared-modules.ts +27 -5
- package/src/test/site-types.ts +5 -1
- package/types/build/class-table.d.ts +1 -1
- package/types/build/class-table.d.ts.map +1 -1
- package/types/build/client.d.ts.map +1 -1
- package/types/build/plugin.d.ts.map +1 -1
- package/types/build/transform.d.ts +1 -0
- package/types/build/transform.d.ts.map +1 -1
- package/types/build/ui-layers.d.ts +5 -0
- package/types/build/ui-layers.d.ts.map +1 -0
- package/types/build/ui.d.ts +7 -0
- package/types/build/ui.d.ts.map +1 -1
- package/types/build/variants.d.ts +1 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/build/worker-bundle.d.ts +1 -0
- package/types/build/worker-bundle.d.ts.map +1 -1
- package/types/check/boot.d.ts.map +1 -1
- package/types/check/call-result.d.ts +7 -0
- package/types/check/call-result.d.ts.map +1 -0
- package/types/check/config-objects.d.ts.map +1 -1
- package/types/check/diagnose.d.ts.map +1 -1
- package/types/check/handler-events.d.ts +9 -0
- package/types/check/handler-events.d.ts.map +1 -0
- package/types/check/index.d.ts +1 -0
- package/types/check/index.d.ts.map +1 -1
- package/types/check/link-flag-tests.d.ts +4 -0
- package/types/check/link-flag-tests.d.ts.map +1 -0
- package/types/check/project.d.ts.map +1 -1
- package/types/check/regroup.d.ts +1 -1
- package/types/check/regroup.d.ts.map +1 -1
- package/types/check/renamed-packages.d.ts +1 -0
- package/types/check/renamed-packages.d.ts.map +1 -1
- package/types/check/schema-builders.d.ts +3 -0
- package/types/check/schema-builders.d.ts.map +1 -0
- package/types/check/secret-keys.d.ts.map +1 -1
- package/types/check/shadow-types.d.ts.map +1 -1
- package/types/check/template-hints.d.ts +1 -0
- package/types/check/template-hints.d.ts.map +1 -1
- package/types/check/tool-labels.d.ts.map +1 -1
- package/types/check/ui-types.d.ts.map +1 -1
- package/types/check/ui.d.ts.map +1 -1
- package/types/commands/env-declare.d.ts.map +1 -1
- package/types/compiler/a11y.d.ts.map +1 -1
- package/types/compiler/bound-props.d.ts +1 -0
- package/types/compiler/bound-props.d.ts.map +1 -1
- package/types/compiler/codegen.d.ts +1 -0
- package/types/compiler/codegen.d.ts.map +1 -1
- package/types/compiler/deprecated-lints-1-106.d.ts +12 -0
- package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -0
- package/types/compiler/deprecated-lints.d.ts +32 -5
- package/types/compiler/deprecated-lints.d.ts.map +1 -1
- package/types/compiler/deprecated-typed-lints.d.ts +21 -0
- package/types/compiler/deprecated-typed-lints.d.ts.map +1 -0
- package/types/compiler/dom-here.d.ts +14 -0
- package/types/compiler/dom-here.d.ts.map +1 -0
- package/types/compiler/dom.d.ts +1 -0
- package/types/compiler/dom.d.ts.map +1 -1
- package/types/compiler/fence-checks.d.ts.map +1 -1
- package/types/compiler/field-described.d.ts +1 -1
- package/types/compiler/field-described.d.ts.map +1 -1
- package/types/compiler/html-fields.d.ts +19 -0
- package/types/compiler/html-fields.d.ts.map +1 -0
- package/types/compiler/html-initial.d.ts +3 -2
- package/types/compiler/html-initial.d.ts.map +1 -1
- package/types/compiler/html.d.ts.map +1 -1
- package/types/compiler/index.d.ts +1 -0
- package/types/compiler/index.d.ts.map +1 -1
- package/types/compiler/items.d.ts +4 -1
- package/types/compiler/items.d.ts.map +1 -1
- package/types/compiler/link-flags.d.ts +6 -0
- package/types/compiler/link-flags.d.ts.map +1 -1
- package/types/compiler/lints.d.ts +44 -17
- package/types/compiler/lints.d.ts.map +1 -1
- package/types/compiler/rest-omits.d.ts +4 -0
- package/types/compiler/rest-omits.d.ts.map +1 -0
- package/types/config-loader.d.ts.map +1 -1
- package/types/config-resolve.d.ts.map +1 -1
- package/types/config.d.ts +15 -2
- package/types/config.d.ts.map +1 -1
- package/types/content/markdown.d.ts.map +1 -1
- package/types/migrate/content.d.ts.map +1 -1
- package/types/runtime/action-shared.d.ts +1 -1
- package/types/runtime/action-shared.d.ts.map +1 -1
- package/types/runtime/action.d.ts +3 -0
- package/types/runtime/action.d.ts.map +1 -1
- package/types/runtime/form-types.d.ts +6 -0
- package/types/runtime/form-types.d.ts.map +1 -0
- package/types/runtime/form.d.ts +3 -1
- package/types/runtime/form.d.ts.map +1 -1
- package/types/runtime/html.d.ts +3 -0
- package/types/runtime/html.d.ts.map +1 -1
- package/types/runtime/markdown-autolink.d.ts +11 -0
- package/types/runtime/markdown-autolink.d.ts.map +1 -0
- package/types/runtime/markdown-render.client.d.ts +2 -1
- package/types/runtime/markdown-render.client.d.ts.map +1 -1
- package/types/runtime/markdown.client.d.ts +3 -1
- package/types/runtime/markdown.client.d.ts.map +1 -1
- package/types/runtime/markdown.d.ts +11 -0
- package/types/runtime/markdown.d.ts.map +1 -1
- package/types/runtime/markdown.server.d.ts +3 -1
- package/types/runtime/markdown.server.d.ts.map +1 -1
- package/types/runtime/navigate-api.d.ts +1 -1
- package/types/runtime/navigate-api.d.ts.map +1 -1
- package/types/runtime/persist.d.ts +2 -2
- package/types/runtime/persist.d.ts.map +1 -1
- package/types/runtime/reactive.d.ts +3 -0
- package/types/runtime/reactive.d.ts.map +1 -1
- package/types/runtime/sanitize.d.ts.map +1 -1
- package/types/runtime/schema-record.d.ts +9 -0
- package/types/runtime/schema-record.d.ts.map +1 -0
- package/types/runtime/schema.client.d.ts.map +1 -1
- package/types/runtime/schema.d.ts +94 -10
- package/types/runtime/schema.d.ts.map +1 -1
- package/types/runtime/swap-focus.d.ts.map +1 -1
- package/types/server/action-module.d.ts +2 -0
- package/types/server/action-module.d.ts.map +1 -0
- package/types/server/actions.d.ts +1 -0
- package/types/server/actions.d.ts.map +1 -1
- package/types/server/api.d.ts.map +1 -1
- package/types/server/app-stages.d.ts +3 -2
- package/types/server/app-stages.d.ts.map +1 -1
- package/types/server/env-state.d.ts.map +1 -1
- package/types/server/env.d.ts +5 -1
- package/types/server/env.d.ts.map +1 -1
- package/types/server/favicon.d.ts +3 -1
- package/types/server/favicon.d.ts.map +1 -1
- package/types/server/kept-pages.d.ts +1 -1
- package/types/server/kept-pages.d.ts.map +1 -1
- package/types/server/library.d.ts +2 -0
- package/types/server/library.d.ts.map +1 -1
- package/types/server/mcp.d.ts +1 -1
- package/types/server/mcp.d.ts.map +1 -1
- package/types/server/notifications.d.ts +2 -1
- package/types/server/notifications.d.ts.map +1 -1
- package/types/server/offline.d.ts.map +1 -1
- package/types/server/push-settings.d.ts +1 -1
- package/types/server/push-settings.d.ts.map +1 -1
- package/types/server/push.d.ts +1 -0
- package/types/server/push.d.ts.map +1 -1
- package/types/server/query.d.ts.map +1 -1
- package/types/server/scope.d.ts +1 -1
- package/types/server/scope.d.ts.map +1 -1
- package/types/test/a11y-dom.d.ts +20 -0
- package/types/test/a11y-dom.d.ts.map +1 -0
- package/types/test/html-snapshot.d.ts +4 -0
- package/types/test/html-snapshot.d.ts.map +1 -0
- package/types/test/index.d.ts.map +1 -1
- package/types/test/mount.d.ts +3 -0
- package/types/test/mount.d.ts.map +1 -1
- package/types/test/page-checks.d.ts +6 -0
- package/types/test/page-checks.d.ts.map +1 -0
- package/types/test/screenshot-match.d.ts +1 -1
- package/types/test/screenshot-match.d.ts.map +1 -1
- package/types/test/shared-modules.d.ts.map +1 -1
- package/types/test/site-types.d.ts +3 -1
- package/types/test/site-types.d.ts.map +1 -1
package/src/build/variants.ts
CHANGED
|
@@ -3,10 +3,11 @@ import { readdirSync } from 'node:fs'
|
|
|
3
3
|
import { stat } from 'node:fs/promises'
|
|
4
4
|
import { dirname, join } from 'node:path'
|
|
5
5
|
import { elementsIn } from '../compiler/ast'
|
|
6
|
+
import { changeName } from '../compiler/bound-props'
|
|
6
7
|
import { parseExpanded } from '../compiler/markdown-block'
|
|
7
8
|
|
|
8
9
|
// 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`.
|
|
9
|
-
const USES_CALL = /\buses\(\s*'(\w+)'\s*\)/y
|
|
10
|
+
const USES_CALL = /\buses\(\s*'(\w+)'(\s*,\s*true)?\s*\)/y
|
|
10
11
|
const KAY_IMPORT = /^import\s+(\w+)\s+from\s+(["'])([^"'\n]+\.kay)\2/gm
|
|
11
12
|
const USES_IMPORT = /^import\s*\{[^}]*\buses\b[^}]*\}\s*from\s*(["'])([^"'\n]+)\1/m
|
|
12
13
|
// The marker module, by where the library keeps it: an app's own `uses` is another function.
|
|
@@ -19,8 +20,9 @@ const IDENTIFIER_CHAR = /[\w$.]/
|
|
|
19
20
|
const BACKSLASH = /\\/g
|
|
20
21
|
|
|
21
22
|
// 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.
|
|
22
|
-
|
|
23
|
-
const
|
|
23
|
+
// `~` and the props the call sites write follow when the project reads them all: the props a spread may carry are not known.
|
|
24
|
+
export const USES_QUERY = /\.kay\?uses=([\w-]*)(?:~([\w-]*))?$/
|
|
25
|
+
const VARIANT_INPUT = /^kay-variant:|\?uses=[\w~-]*$/g
|
|
24
26
|
|
|
25
27
|
// A path the bundler names for a variant, as the file it is made from.
|
|
26
28
|
export function variantFile(input: string): string {
|
|
@@ -56,7 +58,7 @@ function opensRegex(before: string, last: string): boolean {
|
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
// `text` with each marker call outside comments, strings and regular expressions replaced by what `answer` says of its feature. The code in a template literal's `${}` counts.
|
|
59
|
-
function replaceCalls(text: string, answer: (feature: string) => string): string {
|
|
61
|
+
function replaceCalls(text: string, answer: (feature: string, onByDefault: boolean) => string): string {
|
|
60
62
|
let out = ''
|
|
61
63
|
let quote = ''
|
|
62
64
|
let at = 0
|
|
@@ -150,7 +152,7 @@ function replaceCalls(text: string, answer: (feature: string) => string): string
|
|
|
150
152
|
const call = USES_CALL.exec(text)
|
|
151
153
|
|
|
152
154
|
if (call !== null) {
|
|
153
|
-
out += answer(call[1]
|
|
155
|
+
out += answer(call[1]!, call[2] !== undefined)
|
|
154
156
|
at += call[0].length
|
|
155
157
|
last = ')'
|
|
156
158
|
|
|
@@ -168,54 +170,69 @@ function replaceCalls(text: string, answer: (feature: string) => string): string
|
|
|
168
170
|
return out
|
|
169
171
|
}
|
|
170
172
|
|
|
171
|
-
|
|
173
|
+
// The features a component names, and which of them are on when the prop is left out: `uses('sortable', true)`.
|
|
174
|
+
interface Declared {
|
|
175
|
+
names: string[]
|
|
176
|
+
defaults: ReadonlySet<string>
|
|
177
|
+
}
|
|
172
178
|
|
|
173
|
-
|
|
174
|
-
|
|
179
|
+
const NONE: Declared = { names: [], defaults: new Set() }
|
|
180
|
+
const featuresOf = new Map<string, { stamp: number, declared: Promise<Declared> }>()
|
|
181
|
+
|
|
182
|
+
function usesIn(source: string, file: string): Declared {
|
|
175
183
|
if (file !== '' && !importsMarker(source, file))
|
|
176
|
-
return
|
|
184
|
+
return NONE
|
|
177
185
|
|
|
178
186
|
const found = new Set<string>()
|
|
187
|
+
const defaults = new Set<string>()
|
|
179
188
|
|
|
180
|
-
replaceCalls(source, (feature) => {
|
|
189
|
+
replaceCalls(source, (feature, onByDefault) => {
|
|
181
190
|
found.add(feature)
|
|
182
191
|
|
|
192
|
+
if (onByDefault)
|
|
193
|
+
defaults.add(feature)
|
|
194
|
+
|
|
183
195
|
return ''
|
|
184
196
|
})
|
|
185
197
|
|
|
186
|
-
return [...found]
|
|
198
|
+
return { names: [...found], defaults }
|
|
187
199
|
}
|
|
188
200
|
|
|
189
|
-
|
|
201
|
+
// The features a text names: the `uses('x')` of a file importing the marker, none otherwise.
|
|
202
|
+
export function usesNames(source: string, file = ''): string[] {
|
|
203
|
+
return usesIn(source, file).names
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async function readNames(path: string): Promise<Declared> {
|
|
190
207
|
try {
|
|
191
|
-
return
|
|
208
|
+
return usesIn(await Bun.file(path).text(), path)
|
|
192
209
|
}
|
|
193
210
|
catch {
|
|
194
|
-
return
|
|
211
|
+
return NONE
|
|
195
212
|
}
|
|
196
213
|
}
|
|
197
214
|
|
|
198
215
|
// The features a component file names, read again when the file changes: none when it has no marker call or cannot be read.
|
|
199
|
-
async function declaredFeatures(path: string): Promise<
|
|
216
|
+
async function declaredFeatures(path: string): Promise<Declared> {
|
|
200
217
|
let stamp = 0
|
|
201
218
|
|
|
202
219
|
try {
|
|
203
220
|
stamp = (await stat(path)).mtimeMs
|
|
204
221
|
}
|
|
205
222
|
catch {
|
|
206
|
-
return
|
|
223
|
+
return NONE
|
|
207
224
|
}
|
|
208
225
|
|
|
209
226
|
const kept = featuresOf.get(path)
|
|
210
227
|
|
|
211
228
|
if (kept?.stamp === stamp)
|
|
212
|
-
return kept.
|
|
229
|
+
return kept.declared
|
|
213
230
|
|
|
214
|
-
const
|
|
231
|
+
const declared = readNames(path)
|
|
215
232
|
|
|
216
|
-
featuresOf.set(path, { stamp,
|
|
233
|
+
featuresOf.set(path, { stamp, declared })
|
|
217
234
|
|
|
218
|
-
return
|
|
235
|
+
return declared
|
|
219
236
|
}
|
|
220
237
|
|
|
221
238
|
// Whether a condition made of `true`, `false` and anything else, joined by `&&` and `||`, is `false` whatever the rest holds.
|
|
@@ -280,7 +297,31 @@ function splitTop(text: string, operator: '&&' | '||'): string[] | undefined {
|
|
|
280
297
|
return parts
|
|
281
298
|
}
|
|
282
299
|
|
|
283
|
-
//
|
|
300
|
+
// A destructured default that only an absent feature reads, `label = uses('x') ? wording('a', 'A') : ''` once the call is false: the closure it would make is left out.
|
|
301
|
+
const ABSENT_DEFAULT = / = false(?: \|\| false)* \? wording\([^()]*\) : ''/g
|
|
302
|
+
const DEAD_SPREAD = /^(\s*)\.\.\.\(false(?: \|\| false)*\)\s*$/
|
|
303
|
+
|
|
304
|
+
// A recipe part group `...(uses('x')) ? { ... } : {}` whose condition is false, written on lines like that, is blanked.
|
|
305
|
+
function blankDeadSpreads(lines: string[], from: number): void {
|
|
306
|
+
for (let at = 0; at < from; at++) {
|
|
307
|
+
const hit = DEAD_SPREAD.exec(lines[at]!)
|
|
308
|
+
|
|
309
|
+
if (hit === null)
|
|
310
|
+
continue
|
|
311
|
+
|
|
312
|
+
const end = lines.findIndex((line, index) => index > at && line === `${hit[1]} : {},`)
|
|
313
|
+
|
|
314
|
+
if (end === -1)
|
|
315
|
+
continue
|
|
316
|
+
|
|
317
|
+
for (let blank = at; blank <= end; blank++)
|
|
318
|
+
lines[blank] = ''
|
|
319
|
+
|
|
320
|
+
at = end
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// The source with each `uses('x')` of its script and of its template lines as `true` when `x` is among `present`, `false` otherwise, and a template `if` that cannot hold with them reduced to `if false` with its lines blanked: the block keeps its markers for the server markup the island hydrates, and the lines keep their numbers for the source map. An `else` after a blanked block still follows it. A `file` that does not import the marker is returned as it is.
|
|
284
325
|
export function specializedSource(source: string, present: ReadonlySet<string>, file = ''): string {
|
|
285
326
|
if (file !== '' && !importsMarker(source, file))
|
|
286
327
|
return source
|
|
@@ -291,13 +332,19 @@ export function specializedSource(source: string, present: ReadonlySet<string>,
|
|
|
291
332
|
const template = lines.findLastIndex(line => FENCE.test(line)) + 1
|
|
292
333
|
|
|
293
334
|
// The script as one text, so a comment or a template literal over several lines is read as one; the answers hold no newline, so the lines keep their numbers.
|
|
294
|
-
lines.splice(0, template, ...replaced(lines.slice(0, template).join('\n')).split('\n'))
|
|
335
|
+
lines.splice(0, template, ...replaced(lines.slice(0, template).join('\n')).replace(ABSENT_DEFAULT, '').split('\n'))
|
|
336
|
+
blankDeadSpreads(lines, template)
|
|
295
337
|
|
|
296
338
|
for (let at = template; at < lines.length; at++) {
|
|
297
339
|
const hit = USES_IF.exec(lines[at]!)
|
|
298
340
|
|
|
299
|
-
if (hit === null)
|
|
341
|
+
if (hit === null) {
|
|
342
|
+
// A call in an attribute or a text expression is folded as one in the script.
|
|
343
|
+
if (lines[at]!.includes('uses('))
|
|
344
|
+
lines[at] = replaced(lines[at]!)
|
|
345
|
+
|
|
300
346
|
continue
|
|
347
|
+
}
|
|
301
348
|
|
|
302
349
|
const condition = replaced(hit[3]!)
|
|
303
350
|
|
|
@@ -328,8 +375,12 @@ export function specializedSource(source: string, present: ReadonlySet<string>,
|
|
|
328
375
|
// Stands for every prop of a component: it is called with a spread or read as a value, so any may be written.
|
|
329
376
|
export const ANY = Symbol('any')
|
|
330
377
|
|
|
331
|
-
//
|
|
332
|
-
|
|
378
|
+
// 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`.
|
|
379
|
+
const ON_PREFIX = '+'
|
|
380
|
+
const PROP_NAME = /^\w+$/
|
|
381
|
+
|
|
382
|
+
// 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`.
|
|
383
|
+
export function propsWritten(source: string, locals: readonly string[], defaults: ReadonlyMap<string, ReadonlySet<string>> = new Map()): Map<string, Set<string> | typeof ANY> {
|
|
333
384
|
const { file } = parseExpanded(source)
|
|
334
385
|
const written = new Map<string, Set<string>>()
|
|
335
386
|
const calls = new Map<string, number>()
|
|
@@ -345,18 +396,38 @@ export function propsWritten(source: string, locals: readonly string[]): Map<str
|
|
|
345
396
|
|
|
346
397
|
written.set(element.name, props)
|
|
347
398
|
|
|
399
|
+
const off = new Set<string>()
|
|
400
|
+
|
|
348
401
|
for (const attribute of element.attributes) {
|
|
349
|
-
if (attribute.kind === 'spread')
|
|
402
|
+
if (attribute.kind === 'spread') {
|
|
350
403
|
open.delete(element.name)
|
|
351
|
-
|
|
352
|
-
|
|
404
|
+
|
|
405
|
+
continue
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
const name = source.slice(attribute.name.start, attribute.name.end)
|
|
409
|
+
|
|
410
|
+
// A `bind:x` hands the component `x` and `onXChange`, as the compiler writes them.
|
|
411
|
+
if (name.startsWith('bind:') && name.length > 5) {
|
|
412
|
+
props.add(name.slice(5))
|
|
413
|
+
props.add(changeName(name.slice(5)))
|
|
414
|
+
|
|
415
|
+
continue
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
props.add(name)
|
|
419
|
+
|
|
420
|
+
if (attribute.kind === 'expression' && source.slice(attribute.expression.start, attribute.expression.end).trim() === 'false')
|
|
421
|
+
off.add(name)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
for (const feature of defaults.get(element.name) ?? []) {
|
|
425
|
+
if (!off.has(feature))
|
|
426
|
+
props.add(ON_PREFIX + feature)
|
|
353
427
|
}
|
|
354
428
|
|
|
355
429
|
for (const child of element.children) {
|
|
356
|
-
|
|
357
|
-
props.add(source.slice(child.name.start, child.name.end))
|
|
358
|
-
else
|
|
359
|
-
props.add('children')
|
|
430
|
+
props.add(child.kind === 'slot' ? source.slice(child.name.start, child.name.end) : 'children')
|
|
360
431
|
}
|
|
361
432
|
}
|
|
362
433
|
|
|
@@ -374,6 +445,7 @@ interface Candidate {
|
|
|
374
445
|
specifier: string
|
|
375
446
|
path: string
|
|
376
447
|
features: string[]
|
|
448
|
+
defaults: ReadonlySet<string>
|
|
377
449
|
}
|
|
378
450
|
|
|
379
451
|
// The `.kay` components a file imports that name features.
|
|
@@ -390,10 +462,10 @@ async function candidatesOf(code: string, file: string): Promise<Candidate[]> {
|
|
|
390
462
|
continue
|
|
391
463
|
}
|
|
392
464
|
|
|
393
|
-
const features = await declaredFeatures(path)
|
|
465
|
+
const { names: features, defaults } = await declaredFeatures(path)
|
|
394
466
|
|
|
395
467
|
if (features.length > 0)
|
|
396
|
-
found.push({ local: local!, specifier: specifier!, path, features })
|
|
468
|
+
found.push({ local: local!, specifier: specifier!, path, features, defaults })
|
|
397
469
|
}
|
|
398
470
|
|
|
399
471
|
return found
|
|
@@ -439,7 +511,7 @@ export class VariantIndex {
|
|
|
439
511
|
let written: ReturnType<typeof propsWritten>
|
|
440
512
|
|
|
441
513
|
try {
|
|
442
|
-
written = propsWritten(source, candidates.map(candidate => candidate.local))
|
|
514
|
+
written = propsWritten(source, candidates.map(candidate => candidate.local), new Map(candidates.map(candidate => [candidate.local, candidate.defaults])))
|
|
443
515
|
}
|
|
444
516
|
catch {
|
|
445
517
|
written = new Map(candidates.map(candidate => [candidate.local, ANY]))
|
|
@@ -453,22 +525,26 @@ export class VariantIndex {
|
|
|
453
525
|
}
|
|
454
526
|
}
|
|
455
527
|
|
|
456
|
-
|
|
528
|
+
// The query of a variant: its features, then the props written.
|
|
529
|
+
private usedOf(path: string, features: string[], defaults: ReadonlySet<string>): string {
|
|
457
530
|
const props = this.union.get(path) ?? new Set<string>()
|
|
458
531
|
|
|
459
|
-
|
|
532
|
+
if (props === ANY)
|
|
533
|
+
return [...features].sort().join('-')
|
|
534
|
+
|
|
535
|
+
return `${features.filter(feature => props.has(defaults.has(feature) ? ON_PREFIX + feature : feature)).toSorted().join('-')}~${[...props].filter(name => PROP_NAME.test(name)).sort().join('-')}`
|
|
460
536
|
}
|
|
461
537
|
|
|
462
538
|
// An island entry that is a component with features, as the variant the project's call sites need; any other file as it is.
|
|
463
539
|
async entry(path: string): Promise<string> {
|
|
464
|
-
const
|
|
540
|
+
const { names, defaults } = await declaredFeatures(path)
|
|
465
541
|
|
|
466
|
-
if (
|
|
542
|
+
if (names.length === 0)
|
|
467
543
|
return path
|
|
468
544
|
|
|
469
545
|
await this.scanned()
|
|
470
546
|
|
|
471
|
-
return `${path}?uses=${this.usedOf(path,
|
|
547
|
+
return `${path}?uses=${this.usedOf(path, names, defaults)}`
|
|
472
548
|
}
|
|
473
549
|
|
|
474
550
|
// The imports of the compiled `code` of `file` that name a component with features, pointed at the one variant the project's call sites need: `import Table from './table.kay'` as `./table.kay?uses=pageSize`. `source` is the file's own, for one the scan did not meet.
|
|
@@ -483,10 +559,10 @@ export class VariantIndex {
|
|
|
483
559
|
|
|
484
560
|
let result = code
|
|
485
561
|
|
|
486
|
-
for (const { specifier, path, features } of candidates) {
|
|
487
|
-
const used = this.usedOf(path, features)
|
|
562
|
+
for (const { specifier, path, features, defaults } of candidates) {
|
|
563
|
+
const used = this.usedOf(path, features, defaults)
|
|
488
564
|
|
|
489
|
-
result = result.replace(new RegExp(`^(import\\s+\\w+\\s+from\\s+)(["'])${RegExp.escape(specifier)}\\2`, 'm'), (_import, head: string, quote: string) => `${head}${quote}${specifier}?uses=${used
|
|
565
|
+
result = result.replace(new RegExp(`^(import\\s+\\w+\\s+from\\s+)(["'])${RegExp.escape(specifier)}\\2`, 'm'), (_import, head: string, quote: string) => `${head}${quote}${specifier}?uses=${used}${quote}`)
|
|
490
566
|
}
|
|
491
567
|
|
|
492
568
|
return result
|
|
@@ -5,6 +5,7 @@ import process from 'node:process'
|
|
|
5
5
|
import { apiStubs } from '../server/api-modules'
|
|
6
6
|
import { kayPlugin } from './plugin'
|
|
7
7
|
import { withoutStyles } from './styles'
|
|
8
|
+
import { setUiLayers } from './ui-layers'
|
|
8
9
|
|
|
9
10
|
// What a browser build hands the process bundling one of its workers.
|
|
10
11
|
export interface WorkerBundle {
|
|
@@ -15,6 +16,8 @@ export interface WorkerBundle {
|
|
|
15
16
|
options: KayPluginOptions
|
|
16
17
|
// The modules started as workers on the way to this one, itself last.
|
|
17
18
|
workers: string[]
|
|
19
|
+
// The `ui` files of the project's extensions, which the worker's components are compiled with as the app's are.
|
|
20
|
+
uiLayers: string[]
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
// What the process prints: the name of the worker's file, every file the bundle wrote and every file it read.
|
|
@@ -38,6 +41,9 @@ function readText(file: string): string | undefined {
|
|
|
38
41
|
// Bun cannot start a build while a plugin of another waits, so a worker is bundled by a process of its own, which prints its file's name.
|
|
39
42
|
if (import.meta.main) {
|
|
40
43
|
const bundle = JSON.parse(await Bun.stdin.text()) as WorkerBundle
|
|
44
|
+
|
|
45
|
+
setUiLayers(bundle.options.root ?? process.cwd(), bundle.uiLayers.map(ui => ({ ui })))
|
|
46
|
+
|
|
41
47
|
const out = await Bun.build({
|
|
42
48
|
entrypoints: [bundle.entry],
|
|
43
49
|
outdir: bundle.outdir,
|
package/src/check/boot.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { basePath } from '../server/base'
|
|
|
16
16
|
import { checkRequestIdHeader, checkTimeZone, healthTimeoutMs, imageLimits, liveLimits, loadBudgetMs, remoteLimits, shutdownSeconds, timeoutMs } from '../server/config-limits'
|
|
17
17
|
import { claimEndpoints } from '../server/endpoint-claims'
|
|
18
18
|
import { PUBLIC_ENV_PATH } from '../server/env-state'
|
|
19
|
-
import { faviconSource, svgFaviconProblems } from '../server/favicon'
|
|
19
|
+
import { faviconSource, shareActionProblem, svgFaviconProblems } from '../server/favicon'
|
|
20
20
|
import { defaultLocaleTranslations, localeSettings, refuseLocaleClashes } from '../server/i18n'
|
|
21
21
|
import { mcpKeySetting } from '../server/mcp-key'
|
|
22
22
|
import { pageFlags } from '../server/page-flags'
|
|
@@ -179,6 +179,8 @@ export async function bootProblems(root: string, options: CheckOptions, feeds: C
|
|
|
179
179
|
|
|
180
180
|
diagnostics.push(...await actionClashes(root, [...new Set(routes.flatMap(route => [...route.layouts, ...route.actionModules ?? [], route.file]))]))
|
|
181
181
|
|
|
182
|
+
diagnostics.push(...await shareTargetProblems(root, options, config, [...new Set(routes.flatMap(route => [...route.layouts, ...route.actionModules ?? [], route.file]))]))
|
|
183
|
+
|
|
182
184
|
diagnostics.push(...await queryClashes(routes))
|
|
183
185
|
|
|
184
186
|
diagnostics.push(...await pageHeadLints(options, routes, routesDir, publicDir, listed))
|
|
@@ -209,6 +211,25 @@ export async function actionClashes(root: string, files: string[]): Promise<Chec
|
|
|
209
211
|
return diagnostics
|
|
210
212
|
}
|
|
211
213
|
|
|
214
|
+
// A manifest share target naming a page file that is no page of the app, or an export that is no action of it, which the server refuses to boot on.
|
|
215
|
+
async function shareTargetProblems(root: string, options: CheckOptions, config: string, files: string[]): Promise<CheckDiagnostic[]> {
|
|
216
|
+
const share = options.assets?.manifest?.shareTarget
|
|
217
|
+
|
|
218
|
+
if (share === undefined)
|
|
219
|
+
return []
|
|
220
|
+
|
|
221
|
+
const actions = new Set<string>()
|
|
222
|
+
|
|
223
|
+
for (const file of files) {
|
|
224
|
+
for (const name of serverFacts(file, await Bun.file(file).text()).server?.actionNames ?? [])
|
|
225
|
+
actions.add(actionUrl(islandId(file, root), name))
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const problem = shareActionProblem(share, actions, new Set(files.map(file => islandId(file, root))))
|
|
229
|
+
|
|
230
|
+
return problem === undefined ? [] : [{ file: config, line: 1, column: 1, message: problem, help: 'name a page file and the action it exports, as `src/routes/share.kay#receive`, or a path of the site' }]
|
|
231
|
+
}
|
|
232
|
+
|
|
212
233
|
// What a page lists in `prerender`, as its source writes it.
|
|
213
234
|
async function prerenderOf(file: string): Promise<string | undefined> {
|
|
214
235
|
return (await pageFlags(file)).prerender?.trim()
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import type { CheckDiagnostic } from '.'
|
|
2
|
+
import type { Span } from '../compiler/ast'
|
|
3
|
+
import type { Node, Program } from '../compiler/estree'
|
|
4
|
+
import type { LintLevels } from '../compiler/lints'
|
|
5
|
+
import type { OldFormLint } from './handler-events'
|
|
6
|
+
import { parseProgram } from '../compiler/estree'
|
|
7
|
+
import { lintLevels } from '../compiler/lints'
|
|
8
|
+
import { offsetAt } from '../compiler/mapping'
|
|
9
|
+
import { parseKay } from '../compiler/parser'
|
|
10
|
+
import { childrenOf } from './ast'
|
|
11
|
+
|
|
12
|
+
// A result narrowed by a read of `ok` is named by its members, `{ ok: true; data: ... }`.
|
|
13
|
+
const MISSING = /^Property '[^']+' does not exist on type '(?:CallResult<|\{ ok: (?:true|false); )/
|
|
14
|
+
const MODULE = /\.[cm]?tsx?$/
|
|
15
|
+
const MISMATCH = /^(?:Type|Argument of type) 'CallResult</
|
|
16
|
+
// What a result has of its own: a use of one of these means the code already reads a `CallResult`.
|
|
17
|
+
const RESULT_KEYS = new Set(['ok', 'data', 'error', 'errors', 'status', 'message', 'orThrow'])
|
|
18
|
+
|
|
19
|
+
// The spans of a `.kay` file's script, server and module fences, or the whole file for a module.
|
|
20
|
+
function codeSpans(source: string, kay: boolean): Span[] {
|
|
21
|
+
if (!kay)
|
|
22
|
+
return [{ start: 0, end: source.length }]
|
|
23
|
+
|
|
24
|
+
const file = parseKay(source)
|
|
25
|
+
|
|
26
|
+
return [file.script, file.server, file.module].filter(span => span !== undefined)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function parsed(source: string, kay: boolean, at: number): Program | undefined {
|
|
30
|
+
const span = codeSpans(source, kay).find(({ start, end }) => at >= start && at <= end)
|
|
31
|
+
|
|
32
|
+
return span === undefined ? undefined : parseProgram(source.slice(span.start, span.end), { lang: kay ? 'tsx' : 'ts', recover: true, offset: span.start }).program
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface Walked {
|
|
36
|
+
node: Node
|
|
37
|
+
parent: Node | undefined
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function nodes(program: Program): Walked[] {
|
|
41
|
+
const found: Walked[] = []
|
|
42
|
+
const visit = (node: Node, parent: Node | undefined): void => {
|
|
43
|
+
found.push({ node, parent })
|
|
44
|
+
|
|
45
|
+
for (const child of childrenOf(node))
|
|
46
|
+
visit(child, node)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
visit(program, undefined)
|
|
50
|
+
|
|
51
|
+
return found
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// The names the program imports, which a call written on one of them is a kay call.
|
|
55
|
+
function importedNames(program: Program): Set<string> {
|
|
56
|
+
const names = new Set<string>()
|
|
57
|
+
|
|
58
|
+
for (const statement of program.body) {
|
|
59
|
+
if (statement.type === 'ImportDeclaration') {
|
|
60
|
+
for (const specifier of statement.specifiers) {
|
|
61
|
+
names.add(specifier.local.name)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return names
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function rootName(callee: Node): string | undefined {
|
|
70
|
+
let node = callee
|
|
71
|
+
|
|
72
|
+
while (node.type === 'MemberExpression')
|
|
73
|
+
node = node.object
|
|
74
|
+
|
|
75
|
+
return node.type === 'Identifier' ? node.name : undefined
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// The `await` a read of the result is made on: written there, or in a `const` the name was bound by.
|
|
79
|
+
function awaitedBy(all: Walked[], subject: Node, at: number): Node | undefined {
|
|
80
|
+
if (subject.type === 'AwaitExpression')
|
|
81
|
+
return subject
|
|
82
|
+
|
|
83
|
+
if (subject.type !== 'Identifier')
|
|
84
|
+
return undefined
|
|
85
|
+
|
|
86
|
+
const declarations = all.filter(({ node }) => node.type === 'VariableDeclarator' && node.id.type === 'Identifier' && node.id.name === subject.name && node.end <= at).map(({ node }) => node)
|
|
87
|
+
const declarator = declarations.at(-1)
|
|
88
|
+
|
|
89
|
+
return declarator?.type === 'VariableDeclarator' && declarator.init?.type === 'AwaitExpression' ? declarator.init : undefined
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// The nodes that bind a name: a declaration, a parameter, a destructured name or a catch parameter.
|
|
93
|
+
function bindingNodes(all: Walked[]): Set<Node> {
|
|
94
|
+
const found = new Set<Node>()
|
|
95
|
+
const add = (node: Node | null | undefined): void => {
|
|
96
|
+
if (node)
|
|
97
|
+
found.add(node)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
for (const { node } of all) {
|
|
101
|
+
const holder = node as unknown as { params?: Node[], param?: Node, left?: Node, argument?: Node, elements?: (Node | null)[], properties?: Node[] }
|
|
102
|
+
|
|
103
|
+
if (node.type === 'VariableDeclarator') {
|
|
104
|
+
add(node.id)
|
|
105
|
+
}
|
|
106
|
+
else if (node.type === 'ObjectPattern') {
|
|
107
|
+
for (const property of holder.properties ?? [])
|
|
108
|
+
add(property.type === 'Property' ? property.value : property)
|
|
109
|
+
}
|
|
110
|
+
else if (node.type === 'ArrayPattern') {
|
|
111
|
+
for (const element of holder.elements ?? [])
|
|
112
|
+
add(element)
|
|
113
|
+
}
|
|
114
|
+
else if (node.type === 'AssignmentPattern') {
|
|
115
|
+
add(holder.left)
|
|
116
|
+
}
|
|
117
|
+
else if (node.type === 'RestElement') {
|
|
118
|
+
add(holder.argument)
|
|
119
|
+
}
|
|
120
|
+
else if (node.type === 'CatchClause') {
|
|
121
|
+
add(holder.param)
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
for (const param of holder.params ?? [])
|
|
125
|
+
add(param)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return found
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Whether the name is bound more than once in the file, so a read of it may be of another binding than the nearest declaration.
|
|
133
|
+
function boundTwice(all: Walked[], name: string): boolean {
|
|
134
|
+
const bindings = bindingNodes(all)
|
|
135
|
+
|
|
136
|
+
return all.filter(({ node }) => node.type === 'Identifier' && node.name === name && bindings.has(node)).length > 1
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Whether the code uses the name the `await` is bound to in any way but reading a field a result has no key of (`list.items`), or the pattern it is destructured by names a result's key: `list.ok`, `list['ok']`, `list[key]`, `const { ok } = list` or `list` handed on, so `.orThrow()` could take away what is read.
|
|
140
|
+
function readsResult(all: Walked[], bound: Node | undefined): boolean {
|
|
141
|
+
if (bound === undefined)
|
|
142
|
+
return false
|
|
143
|
+
|
|
144
|
+
if (bound.type === 'Identifier') {
|
|
145
|
+
const bindings = bindingNodes(all)
|
|
146
|
+
|
|
147
|
+
return all.some(({ node, parent }) => {
|
|
148
|
+
if (node.type !== 'Identifier' || node.name !== bound.name || node === bound || bindings.has(node))
|
|
149
|
+
return false
|
|
150
|
+
|
|
151
|
+
if (parent?.type === 'MemberExpression' && parent.property === node && !parent.computed)
|
|
152
|
+
return false
|
|
153
|
+
|
|
154
|
+
if (parent?.type === 'Property' && parent.key === node && !parent.computed && !parent.shorthand)
|
|
155
|
+
return false
|
|
156
|
+
|
|
157
|
+
return !(parent?.type === 'MemberExpression' && parent.object === node && !parent.computed && parent.property.type === 'Identifier' && !RESULT_KEYS.has(parent.property.name))
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return bound.type === 'ObjectPattern' && bound.properties.some(property => property.type !== 'Property' || property.computed || (property.key.type === 'Identifier' && RESULT_KEYS.has(property.key.name)))
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// A read on a call's answer that is no field of a `CallResult`, an island call awaited as data as it was before 1.105: the answer is `{ ok: true, data }` or `{ ok: false, error }` since, so `.orThrow()` after the call gives the data and throws a refusal as it did.
|
|
165
|
+
// Fixed where the call is written on a name the file imports and nothing reads `ok`, `data` or `error` of the answer; offered, not applied, otherwise.
|
|
166
|
+
export function callResultLint(message: string, source: string, span: Span | undefined, kay: boolean): OldFormLint | undefined {
|
|
167
|
+
const missing = MISSING.test(message)
|
|
168
|
+
|
|
169
|
+
if (span === undefined || (!missing && !MISMATCH.test(message)))
|
|
170
|
+
return undefined
|
|
171
|
+
|
|
172
|
+
const program = parsed(source, kay, span.start)
|
|
173
|
+
|
|
174
|
+
if (program === undefined)
|
|
175
|
+
return undefined
|
|
176
|
+
|
|
177
|
+
const all = nodes(program)
|
|
178
|
+
let subject: Node | undefined
|
|
179
|
+
let bound: Node | undefined
|
|
180
|
+
|
|
181
|
+
for (const { node, parent } of all) {
|
|
182
|
+
if (missing && node.type === 'MemberExpression' && !node.computed && node.property.start === span.start) {
|
|
183
|
+
subject = node.object
|
|
184
|
+
bound = node.object
|
|
185
|
+
}
|
|
186
|
+
else if (missing && node.type === 'Property' && parent?.type === 'ObjectPattern' && node.key.start === span.start) {
|
|
187
|
+
const declarator = all.find(({ node: other }) => other.type === 'VariableDeclarator' && other.id === parent)?.node
|
|
188
|
+
|
|
189
|
+
subject = declarator?.type === 'VariableDeclarator' ? declarator.init ?? undefined : undefined
|
|
190
|
+
bound = parent
|
|
191
|
+
}
|
|
192
|
+
else if (!missing && (node.type === 'AwaitExpression' || node.type === 'Identifier') && node.start === span.start) {
|
|
193
|
+
subject = node
|
|
194
|
+
bound = node
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (subject !== undefined)
|
|
198
|
+
break
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const awaited = subject === undefined ? undefined : awaitedBy(all, subject, span.start)
|
|
202
|
+
const call = awaited?.type === 'AwaitExpression' && awaited.argument.type === 'CallExpression' ? awaited.argument : undefined
|
|
203
|
+
const report = {
|
|
204
|
+
message: 'An island\'s call answers a `CallResult` since 1.105, `{ ok: true, data }` or `{ ok: false, error }`, not its data',
|
|
205
|
+
help: 'read `data` after checking `ok`, or write `.orThrow()` after the call: it resolves with the data and throws a refusal as the call did before 1.105',
|
|
206
|
+
span,
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (call === undefined)
|
|
210
|
+
return report
|
|
211
|
+
|
|
212
|
+
const known = importedNames(program)
|
|
213
|
+
const name = rootName(call.callee)
|
|
214
|
+
const safe = name !== undefined && known.has(name) && !readsResult(all, bound) && !(bound?.type === 'Identifier' && boundTwice(all, bound.name))
|
|
215
|
+
|
|
216
|
+
return { ...report, fixes: [{ title: 'Write `.orThrow()` after the call', safe, edits: [{ start: call.end, end: call.end, text: '.orThrow()' }] }] }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// The same for a type error in a module of the project, which has no shadow file: the message tells what it is, and the file is read for the call it names.
|
|
220
|
+
export async function moduleCallResult(diagnostic: CheckDiagnostic, levels: LintLevels | undefined): Promise<Pick<CheckDiagnostic, 'code' | 'severity' | 'message' | 'help' | 'fixes'> | undefined> {
|
|
221
|
+
if (!(MISSING.test(diagnostic.message) || MISMATCH.test(diagnostic.message)) || !MODULE.test(diagnostic.file))
|
|
222
|
+
return undefined
|
|
223
|
+
|
|
224
|
+
let source: string
|
|
225
|
+
|
|
226
|
+
try {
|
|
227
|
+
source = await Bun.file(diagnostic.file).text()
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
return undefined
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const start = offsetAt(source, diagnostic)
|
|
234
|
+
const found = callResultLint(diagnostic.message, source, { start, end: start + 1 }, false)
|
|
235
|
+
|
|
236
|
+
if (found === undefined)
|
|
237
|
+
return undefined
|
|
238
|
+
|
|
239
|
+
const level = lintLevels(source, levels)('deprecated-call-result', start)
|
|
240
|
+
|
|
241
|
+
return level === 'allow' ? undefined : { code: 'deprecated-call-result', severity: level === 'warn' ? 'warning' : 'error', message: found.message, help: found.help, ...found.fixes && { fixes: found.fixes } }
|
|
242
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { Node, NodeOfType, Program } from '../compiler/estree'
|
|
|
2
2
|
import type { Property } from './regroup'
|
|
3
3
|
import { basename } from 'node:path'
|
|
4
4
|
import { constBindings, exportedObject, keyName, objectOf } from '../compiler/object-literal'
|
|
5
|
-
import { importsOf, walk } from './ast'
|
|
5
|
+
import { importedName, importsOf, walk } from './ast'
|
|
6
6
|
import { nameOf } from './regroup'
|
|
7
7
|
|
|
8
8
|
type ObjectExpression = NodeOfType<'ObjectExpression'>
|
|
@@ -38,7 +38,12 @@ export function featureProperties(object: ObjectExpression, bindings: ReturnType
|
|
|
38
38
|
return [...propertiesOf(object, name).slice(0, 1), ...held === undefined ? [] : propertiesOf(held, name).slice(0, 1)]
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
//
|
|
41
|
+
// Whether a file names the `KayExtension` type, as one writing an extension does.
|
|
42
|
+
function namesExtension(ast: Program): boolean {
|
|
43
|
+
return ast.body.some(statement => statement.type === 'ImportDeclaration' && statement.specifiers.some(specifier => specifier.type === 'ImportSpecifier' && importedName(specifier) === 'KayExtension'))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The objects of a file that are written as config: kay.config.ts's export, the `config` of an extension a file typed `KayExtension` writes, and in any file the options handed to `pages()` or `testSite()` with the `config` object of each.
|
|
42
47
|
export function configObjects(file: string, ast: Program): ConfigObject[] {
|
|
43
48
|
const bindings = constBindings(ast)
|
|
44
49
|
const found: ConfigObject[] = []
|
|
@@ -50,6 +55,16 @@ export function configObjects(file: string, ast: Program): ConfigObject[] {
|
|
|
50
55
|
found.push({ object: exported, others: [] })
|
|
51
56
|
}
|
|
52
57
|
|
|
58
|
+
if (namesExtension(ast)) {
|
|
59
|
+
walk(ast, (node) => {
|
|
60
|
+
const config = node.type === 'ObjectExpression' && propertyOf(node, 'name') !== undefined ? propertyOf(node, 'config') : undefined
|
|
61
|
+
const inner = config === undefined ? undefined : objectOf(config.value, bindings)
|
|
62
|
+
|
|
63
|
+
if (inner !== undefined && inner === config?.value)
|
|
64
|
+
found.push({ object: inner, others: [] })
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
53
68
|
const calls = (['pages', 'testSite'] as const).map(name => ({ name, ...importsOf(ast, name === 'pages' ? FROM_SERVER : FROM_TEST, name) })).filter(call => call.locals.size > 0 || call.namespaces.size > 0)
|
|
54
69
|
|
|
55
70
|
if (calls.length === 0)
|