@kayjs/kay 1.106.0 → 1.108.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/README.md +2 -2
- package/dist/eslint.js +477 -204
- package/editors/zed/extension.toml +2 -2
- package/llms/action-protection.md +1 -1
- package/llms/actions-from-islands.md +1 -1
- package/llms/actions-refused-fields.md +22 -0
- package/llms/actions.md +2 -22
- package/llms/browser-only.md +1 -1
- package/llms/compiler-api.md +1 -1
- package/llms/component-libraries.md +1 -1
- package/llms/components.md +1 -1
- package/llms/deprecated-lints.md +2 -4
- package/llms/island-and-form-lints.md +1 -0
- package/llms/islands.md +11 -2
- package/llms/project-new-and-add.md +1 -1
- package/llms/project.md +2 -2
- package/llms/schemas.md +6 -4
- package/llms/upgrading.md +25 -1
- package/llms/whats-new-archive.md +36 -1
- package/llms/whats-new.md +18 -35
- package/llms.txt +1 -1
- package/package.json +15 -6
- package/src/build/client.ts +23 -26
- package/src/build/entry-files.ts +19 -0
- package/src/build/icon-slots.ts +140 -0
- package/src/build/lazy-components.ts +130 -0
- package/src/build/lazy-manifest.ts +56 -0
- package/src/build/lazy-stubs.ts +31 -0
- package/src/build/libraries.ts +24 -2
- package/src/build/plugin.ts +13 -1
- package/src/build/runtime-chunk.ts +3 -3
- package/src/build/source-files.ts +8 -3
- package/src/build/transform.ts +17 -7
- package/src/build/variants.ts +97 -5
- package/src/check/action-options.ts +56 -0
- package/src/check/project.ts +4 -4
- package/src/check/renamed-packages.ts +3 -63
- package/src/check/schema-json.ts +226 -0
- package/src/check/shadow-types.ts +15 -27
- package/src/compiler/codegen.ts +7 -17
- package/src/compiler/dead-code.ts +22 -0
- package/src/compiler/deprecated-lints-1-105.ts +41 -0
- package/src/compiler/deprecated-lints-1-106.ts +1 -1
- package/src/compiler/deprecated-lints-1-107.ts +14 -0
- package/src/compiler/deprecated-lints.ts +8 -65
- package/src/compiler/dom-property.ts +23 -0
- package/src/compiler/dom.ts +15 -15
- package/src/compiler/import-edits.ts +15 -0
- package/src/compiler/index.ts +8 -3
- package/src/compiler/island-declaration.ts +15 -0
- package/src/compiler/kay-exports.ts +1 -0
- package/src/compiler/lazy-imports.ts +357 -0
- package/src/compiler/parser.ts +2 -2
- package/src/compiler/route-lints.ts +2 -0
- package/src/compiler/schema-lints.ts +13 -0
- package/src/compiler/script-server.ts +6 -3
- package/src/content/validate.ts +1 -1
- package/src/new.ts +6 -2
- package/src/package-names.ts +1 -1
- package/src/runtime/action-call.ts +39 -327
- package/src/runtime/action-run.ts +357 -0
- package/src/runtime/action.ts +47 -4
- package/src/runtime/client.ts +10 -0
- package/src/runtime/dom-lazy.ts +276 -0
- package/src/runtime/field-errors.ts +58 -0
- package/src/runtime/field-refusal.ts +179 -0
- package/src/runtime/form.ts +3 -2
- package/src/runtime/html.ts +6 -1
- package/src/runtime/index.ts +2 -0
- package/src/runtime/island.server.ts +36 -2
- package/src/runtime/schema-record.ts +2 -1
- package/src/runtime/schema.client.ts +104 -14
- package/src/runtime/schema.ts +9 -2
- package/src/runtime/standard-schema.ts +32 -0
- package/src/runtime/validate-run.client.ts +179 -0
- package/src/runtime/validate.client.ts +11 -0
- package/src/runtime/validate.ts +4 -137
- package/src/server/actions.ts +48 -43
- package/src/server/answer.ts +102 -0
- package/src/server/api-input.ts +166 -0
- package/src/server/api.ts +12 -44
- package/src/server/app-stages.ts +15 -8
- package/src/server/app.ts +5 -2
- package/src/server/client.ts +2 -0
- package/src/server/dev.ts +7 -9
- package/src/server/file-limit.ts +7 -1
- package/src/server/forms.ts +1 -1
- package/src/server/host-allowlist.ts +7 -7
- package/src/server/index.ts +2 -0
- package/src/server/kay-routes.ts +221 -0
- package/src/server/kay-server.ts +228 -0
- package/src/server/kept-exports.ts +1 -0
- package/src/server/library.ts +0 -2
- package/src/server/mcp.ts +1 -1
- package/src/server/openapi.ts +12 -3
- package/src/server/phases.ts +249 -0
- package/src/server/protection.ts +6 -6
- package/src/server/proxy-key.ts +8 -8
- package/src/server/query.ts +4 -25
- package/src/server/receive.ts +43 -0
- package/src/server/render-document.ts +13 -3
- package/src/server/request-context.ts +137 -0
- package/src/server/schema-check.ts +1 -1
- package/src/server/socket.ts +19 -47
- package/src/server/stream.ts +1 -1
- package/src/server/validate.ts +346 -0
- package/src/test/mount.ts +6 -2
- package/types/build/client.d.ts +3 -2
- package/types/build/client.d.ts.map +1 -1
- package/types/build/entry-files.d.ts +4 -0
- package/types/build/entry-files.d.ts.map +1 -0
- package/types/build/icon-slots.d.ts +7 -0
- package/types/build/icon-slots.d.ts.map +1 -0
- package/types/build/lazy-components.d.ts +6 -0
- package/types/build/lazy-components.d.ts.map +1 -0
- package/types/build/lazy-manifest.d.ts +19 -0
- package/types/build/lazy-manifest.d.ts.map +1 -0
- package/types/build/lazy-stubs.d.ts +5 -0
- package/types/build/lazy-stubs.d.ts.map +1 -0
- package/types/build/libraries.d.ts +2 -0
- package/types/build/libraries.d.ts.map +1 -1
- package/types/build/plugin.d.ts +2 -0
- package/types/build/plugin.d.ts.map +1 -1
- package/types/build/source-files.d.ts.map +1 -1
- package/types/build/transform.d.ts +3 -1
- package/types/build/transform.d.ts.map +1 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/check/action-options.d.ts +3 -0
- package/types/check/action-options.d.ts.map +1 -0
- package/types/check/renamed-packages.d.ts +0 -3
- package/types/check/renamed-packages.d.ts.map +1 -1
- package/types/check/schema-json.d.ts +3 -0
- package/types/check/schema-json.d.ts.map +1 -0
- package/types/check/shadow-types.d.ts.map +1 -1
- package/types/compiler/codegen.d.ts +2 -0
- package/types/compiler/codegen.d.ts.map +1 -1
- package/types/compiler/dead-code.d.ts +9 -0
- package/types/compiler/dead-code.d.ts.map +1 -0
- package/types/compiler/deprecated-lints-1-105.d.ts +39 -0
- package/types/compiler/deprecated-lints-1-105.d.ts.map +1 -0
- package/types/compiler/deprecated-lints-1-106.d.ts +1 -1
- package/types/compiler/deprecated-lints-1-106.d.ts.map +1 -1
- package/types/compiler/deprecated-lints-1-107.d.ts +12 -0
- package/types/compiler/deprecated-lints-1-107.d.ts.map +1 -0
- package/types/compiler/deprecated-lints.d.ts +36 -53
- package/types/compiler/deprecated-lints.d.ts.map +1 -1
- package/types/compiler/dom-property.d.ts +9 -0
- package/types/compiler/dom-property.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/import-edits.d.ts +1 -0
- package/types/compiler/import-edits.d.ts.map +1 -1
- package/types/compiler/index.d.ts +2 -0
- package/types/compiler/index.d.ts.map +1 -1
- package/types/compiler/island-declaration.d.ts +5 -0
- package/types/compiler/island-declaration.d.ts.map +1 -1
- package/types/compiler/kay-exports.d.ts.map +1 -1
- package/types/compiler/lazy-imports.d.ts +33 -0
- package/types/compiler/lazy-imports.d.ts.map +1 -0
- package/types/compiler/lints.d.ts +44 -53
- package/types/compiler/lints.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/schema-lints.d.ts +11 -0
- package/types/compiler/schema-lints.d.ts.map +1 -0
- package/types/compiler/script-server.d.ts.map +1 -1
- package/types/new.d.ts +1 -0
- package/types/new.d.ts.map +1 -1
- package/types/runtime/action-call.d.ts.map +1 -1
- package/types/runtime/action-run.d.ts +23 -0
- package/types/runtime/action-run.d.ts.map +1 -0
- package/types/runtime/action.d.ts +26 -1
- package/types/runtime/action.d.ts.map +1 -1
- package/types/runtime/client.d.ts.map +1 -1
- package/types/runtime/dom-lazy.d.ts +6 -0
- package/types/runtime/dom-lazy.d.ts.map +1 -0
- package/types/runtime/field-errors.d.ts +4 -0
- package/types/runtime/field-errors.d.ts.map +1 -0
- package/types/runtime/field-refusal.d.ts +37 -0
- package/types/runtime/field-refusal.d.ts.map +1 -0
- package/types/runtime/form.d.ts +1 -1
- package/types/runtime/form.d.ts.map +1 -1
- package/types/runtime/html.d.ts.map +1 -1
- package/types/runtime/index.d.ts +2 -0
- package/types/runtime/index.d.ts.map +1 -1
- package/types/runtime/island.server.d.ts +2 -0
- package/types/runtime/island.server.d.ts.map +1 -1
- package/types/runtime/schema-record.d.ts.map +1 -1
- package/types/runtime/schema.client.d.ts.map +1 -1
- package/types/runtime/schema.d.ts +6 -1
- package/types/runtime/schema.d.ts.map +1 -1
- package/types/runtime/standard-schema.d.ts +37 -0
- package/types/runtime/standard-schema.d.ts.map +1 -0
- package/types/runtime/validate-run.client.d.ts +4 -0
- package/types/runtime/validate-run.client.d.ts.map +1 -0
- package/types/runtime/validate.client.d.ts +4 -0
- package/types/runtime/validate.client.d.ts.map +1 -0
- package/types/runtime/validate.d.ts +1 -21
- package/types/runtime/validate.d.ts.map +1 -1
- package/types/server/actions.d.ts.map +1 -1
- package/types/server/answer.d.ts +6 -0
- package/types/server/answer.d.ts.map +1 -0
- package/types/server/api-input.d.ts +19 -0
- package/types/server/api-input.d.ts.map +1 -0
- package/types/server/api.d.ts.map +1 -1
- package/types/server/app-stages.d.ts +4 -1
- package/types/server/app-stages.d.ts.map +1 -1
- package/types/server/app.d.ts +2 -0
- package/types/server/app.d.ts.map +1 -1
- package/types/server/client.d.ts +1 -0
- package/types/server/client.d.ts.map +1 -1
- package/types/server/dev.d.ts +1 -1
- package/types/server/dev.d.ts.map +1 -1
- package/types/server/file-limit.d.ts.map +1 -1
- package/types/server/host-allowlist.d.ts +3 -3
- package/types/server/host-allowlist.d.ts.map +1 -1
- package/types/server/index.d.ts +2 -0
- package/types/server/index.d.ts.map +1 -1
- package/types/server/kay-routes.d.ts +47 -0
- package/types/server/kay-routes.d.ts.map +1 -0
- package/types/server/kay-server.d.ts +25 -0
- package/types/server/kay-server.d.ts.map +1 -0
- package/types/server/kept-exports.d.ts.map +1 -1
- package/types/server/library.d.ts +0 -1
- package/types/server/library.d.ts.map +1 -1
- package/types/server/openapi.d.ts.map +1 -1
- package/types/server/phases.d.ts +36 -0
- package/types/server/phases.d.ts.map +1 -0
- package/types/server/protection.d.ts +3 -2
- package/types/server/protection.d.ts.map +1 -1
- package/types/server/proxy-key.d.ts +3 -3
- package/types/server/proxy-key.d.ts.map +1 -1
- package/types/server/query.d.ts.map +1 -1
- package/types/server/receive.d.ts +9 -0
- package/types/server/receive.d.ts.map +1 -0
- package/types/server/render-document.d.ts.map +1 -1
- package/types/server/request-context.d.ts +29 -0
- package/types/server/request-context.d.ts.map +1 -0
- package/types/server/schema-check.d.ts +1 -0
- package/types/server/schema-check.d.ts.map +1 -1
- package/types/server/socket.d.ts +3 -5
- package/types/server/socket.d.ts.map +1 -1
- package/types/server/validate.d.ts +26 -0
- package/types/server/validate.d.ts.map +1 -0
- package/types/test/mount.d.ts.map +1 -1
- package/src/check/schema-type.ts +0 -9
- package/src/compiler/deprecated-script-fence.ts +0 -26
- package/src/server/field-errors.ts +0 -136
- package/types/check/schema-type.d.ts +0 -3
- package/types/check/schema-type.d.ts.map +0 -1
- package/types/compiler/deprecated-script-fence.d.ts +0 -3
- package/types/compiler/deprecated-script-fence.d.ts.map +0 -1
- package/types/server/field-errors.d.ts +0 -6
- package/types/server/field-errors.d.ts.map +0 -1
|
@@ -9,13 +9,13 @@ import type { ApiModule } from '../server/api-modules'
|
|
|
9
9
|
import type { PublicFile } from '../server/public'
|
|
10
10
|
import type { Endpoint, Route, RouteMount } from '../server/routes'
|
|
11
11
|
import type { ShadowFile, ShadowOptions, ShadowSettings } from './shadow'
|
|
12
|
-
import { existsSync
|
|
12
|
+
import { existsSync } from 'node:fs'
|
|
13
13
|
import { lstat, mkdir, readdir, readlink, rm, symlink, unlink } from 'node:fs/promises'
|
|
14
|
-
import {
|
|
14
|
+
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
15
15
|
import { readCacheEntry, writeCacheEntry } from '../build/cache'
|
|
16
16
|
import { findKayFiles, inWalkScope, treeEntries, writeIfChanged } from '../build/files'
|
|
17
17
|
import { iconTypes } from '../build/icons'
|
|
18
|
-
import { findKayLibraries, libraryOf,
|
|
18
|
+
import { extensionPackages, findKayLibraries, libraryOf, linkedOutside, reachableLibraryFiles, throughNodeModules } from '../build/libraries'
|
|
19
19
|
import { packageContextModule } from '../build/manifests'
|
|
20
20
|
import { isPageFile, mountedPageDirs } from '../build/page-dirs'
|
|
21
21
|
import { importedSignals } from '../build/signals'
|
|
@@ -33,6 +33,7 @@ import { redirectProblems } from '../server/redirects'
|
|
|
33
33
|
import { extensionEditor, patternShapes, routeMounts, scanEndpoints, scanRoutes, servedPaths } from '../server/routes'
|
|
34
34
|
import { readRuntimeRedirects } from '../server/runtime-redirects'
|
|
35
35
|
|
|
36
|
+
import { actionOptions } from './action-options'
|
|
36
37
|
import { actionReaders } from './action-readers'
|
|
37
38
|
import { actionType } from './action-type'
|
|
38
39
|
import { aiLanguage } from './ai-language'
|
|
@@ -44,31 +45,31 @@ import { cmsOptions } from './cms-options'
|
|
|
44
45
|
import { configGroups } from './config-groups'
|
|
45
46
|
import { configSwitches } from './config-switches'
|
|
46
47
|
import { contextImport } from './context-import'
|
|
47
|
-
import { ownFile } from './diagnose'
|
|
48
48
|
|
|
49
|
+
import { ownFile } from './diagnose'
|
|
49
50
|
import { endpointExports } from './endpoint-exports'
|
|
50
|
-
import { envFiles } from './env-files'
|
|
51
51
|
|
|
52
|
+
import { envFiles } from './env-files'
|
|
52
53
|
import { ASSET_TYPES, environmentTypes, kayPaths, packageTypes } from './env-types'
|
|
53
|
-
import { formatDurationNumbers } from './format-duration'
|
|
54
54
|
|
|
55
|
+
import { formatDurationNumbers } from './format-duration'
|
|
55
56
|
import { CONTENT_CHECK, EXPORTS_CHECK, exportsCheck, SETTINGS_CHECK, settingsCheck } from './generated'
|
|
56
|
-
import { guardOptions } from './guard-options'
|
|
57
57
|
|
|
58
|
+
import { guardOptions } from './guard-options'
|
|
58
59
|
import { unguardedRoutes, unguardedTools } from './guards'
|
|
59
60
|
import { hookContext } from './hook-context'
|
|
60
61
|
import { hookNames } from './hook-names'
|
|
61
62
|
import { i18nKeys } from './i18n-keys'
|
|
62
|
-
import { imagesKeys } from './images-keys'
|
|
63
63
|
|
|
64
|
+
import { imagesKeys } from './images-keys'
|
|
64
65
|
import { islandOnlyComponents } from './island-only'
|
|
66
|
+
|
|
65
67
|
import { diskFilesCalls, jobHandlers, jobOptions, scheduleCalls } from './job-shapes'
|
|
66
68
|
|
|
67
69
|
import { largePublicImages } from './large-images'
|
|
68
|
-
|
|
69
70
|
import { liveApi } from './live-api'
|
|
70
|
-
import { mailApi } from './mail-api'
|
|
71
71
|
|
|
72
|
+
import { mailApi } from './mail-api'
|
|
72
73
|
import { mcpRoutes } from './mcp-routes'
|
|
73
74
|
import { islandEvents, listenTarget, movedImports, navigateQuery, navigationHooks, persistedCall, persistedQuery } from './one-state-api'
|
|
74
75
|
import { unreadOpenSettings } from './open-settings'
|
|
@@ -81,7 +82,7 @@ import { retiredLintLevels } from './retired-lints'
|
|
|
81
82
|
import { routeKeys } from './route-keys'
|
|
82
83
|
import { routeShadow, routeShadowPath } from './route-shadow'
|
|
83
84
|
import { schemaBuilders } from './schema-builders'
|
|
84
|
-
import {
|
|
85
|
+
import { schemaJson } from './schema-json'
|
|
85
86
|
import { secretKeys } from './secret-keys'
|
|
86
87
|
import { compileShadow, guardTypes, layoutQueries, matcherSource, outerSlots, pageRoute, serializeShadowSettings, SHADOW_SETTINGS, shadowOptionsFor, shadowPath } from './shadow'
|
|
87
88
|
import { socketFrames } from './socket-frames'
|
|
@@ -208,8 +209,9 @@ const PROJECT_CHECKS: ((input: ProjectCheckInput) => CheckDiagnostic[] | Promise
|
|
|
208
209
|
async ({ root, options }) => listenTarget(root, options),
|
|
209
210
|
async ({ root, options }) => movedImports(root, options),
|
|
210
211
|
|
|
211
|
-
async ({ root, options }) => schemaType(root, options),
|
|
212
212
|
async ({ root, options }) => schemaBuilders(root, options),
|
|
213
|
+
async ({ root, options }) => schemaJson(root, options),
|
|
214
|
+
async ({ root, options }) => actionOptions(root, options),
|
|
213
215
|
async ({ root, options }) => aiLanguage(root, options),
|
|
214
216
|
async ({ root, options }) => hookNames(root, options),
|
|
215
217
|
async ({ root, options }) => mailApi(root, options),
|
|
@@ -387,7 +389,7 @@ async function libraryShadows(root: string, options: CheckOptions, own: string[]
|
|
|
387
389
|
const { routes: routesDir, cache: cacheDir } = projectPaths(root, options)
|
|
388
390
|
const libraries = await findKayLibraries(root)
|
|
389
391
|
// The app's own directories are checked already; a linked library has its real path outside any `node_modules`, an installed one inside.
|
|
390
|
-
const linked = (path: string) =>
|
|
392
|
+
const linked = (path: string) => linkedOutside(root, path)
|
|
391
393
|
const local = mounts.filter(mount => linked(mount.dir))
|
|
392
394
|
const diagnostics: CheckDiagnostic[] = []
|
|
393
395
|
const editor = editorOf(root, options.extensions, diagnostics)
|
|
@@ -543,20 +545,6 @@ async function linkDependencies(root: string, { dir, realDir }: KayLibrary, own:
|
|
|
543
545
|
}
|
|
544
546
|
}
|
|
545
547
|
|
|
546
|
-
// The package holding each of `extensionDirs`, an extension's routes or its editor's directory, that no kay library holds, the nearest directory above them with a package.json, as a library: its components are shadowed and reached as one's are.
|
|
547
|
-
async function extensionPackages(root: string, libraries: KayLibrary[], extensionDirs: string[]): Promise<KayLibrary[]> {
|
|
548
|
-
const dirs = new Set(extensionDirs.filter(dir => libraryOf(libraries, join(dir, 'page.kay')) === undefined).map(packageRoot))
|
|
549
|
-
|
|
550
|
-
const realRoot = realpathSync(root)
|
|
551
|
-
|
|
552
|
-
return Promise.all([...dirs].map(async (dir) => {
|
|
553
|
-
// Left out: the app itself, when the package holds it as a fixture; the other projects inside it, to their own checks; a kay library's files, to the library. A package linked into `node_modules` goes by that path, as the app imports it.
|
|
554
|
-
const files = (await findKayFiles(dir, { project: true, ownOnly: true, ownKayOnly: true })).filter(file => !realpathSync(file).startsWith(realRoot + sep) && libraryOf(libraries, file) === undefined)
|
|
555
|
-
|
|
556
|
-
return { name: basename(dir), dir, realDir: realpathSync(dir), files, specifiers: new Map<string, string>(), exports: undefined, extension: true as const }
|
|
557
|
-
}))
|
|
558
|
-
}
|
|
559
|
-
|
|
560
548
|
// The pages, public files, API modules and endpoints, with the locale settings, each with the reason the server would refuse it reported.
|
|
561
549
|
async function servedProject(root: string, options: CheckOptions, problems: CheckDiagnostic[], mounts: RouteMount[]): Promise<ServedProject> {
|
|
562
550
|
const paths = projectPaths(root, options)
|
package/src/compiler/codegen.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ClassTable } from '../runtime/class-table'
|
|
|
2
2
|
import type { UiEntry } from '../runtime/ui'
|
|
3
3
|
import type { ConstNode, ElementNode, ErrorMessages, KayFile, Node, SlotNode, Span, TemplateFacts, TemplateHelper } from './ast'
|
|
4
4
|
import type { IslandCause } from './island-cause'
|
|
5
|
+
import type { LazyImport } from './lazy-imports'
|
|
5
6
|
import type { LoadPlan } from './load-plan'
|
|
6
7
|
import type { Rewrite } from './mapping'
|
|
7
8
|
import type { AwaitAlert, WRITE_HELPERS } from './names'
|
|
@@ -15,10 +16,12 @@ import { domHelperImport, DomTemplate } from './dom'
|
|
|
15
16
|
import { addIslandShorthandTitle, addShorthandChecks, addShorthandGroup, hasShorthandTitle } from './head-shorthand'
|
|
16
17
|
import { emitHeadTag, emitHeadText } from './head-tags'
|
|
17
18
|
import { awaitAlertTail, htmlHelperImport, HtmlTemplate } from './html'
|
|
19
|
+
import { withoutComma } from './import-edits'
|
|
18
20
|
import { sourceLocator } from './inspect'
|
|
19
21
|
import { asksOf, exportsIslandOptions, islandMessages, withAlertKeys } from './island-arguments'
|
|
20
22
|
import { ambientHelpers, constDeclaration } from './items'
|
|
21
23
|
import { JsxTemplate } from './jsx'
|
|
24
|
+
import { lazyDomImport, lazyEdits, lazyNoteImport } from './lazy-imports'
|
|
22
25
|
import { planLoads } from './load-plan'
|
|
23
26
|
import { CodeBuilder, DYNAMIC_TAG } from './mapping'
|
|
24
27
|
import { helperName } from './markup'
|
|
@@ -104,6 +107,7 @@ export interface GenerateOptions {
|
|
|
104
107
|
ui?: UiEntry | undefined
|
|
105
108
|
// Type checking's counterpart of `ui`: the variants and values `src/ui.ts` adds to the component's props.
|
|
106
109
|
uiAdded?: UiEntry | undefined
|
|
110
|
+
lazy?: ReadonlyMap<string, LazyImport> | undefined
|
|
107
111
|
// Browser variant builds: the props the project's call sites write, so the rest list omits only those (the others cannot arrive); absent, every declared prop is omitted.
|
|
108
112
|
writtenProps?: ReadonlySet<string> | undefined
|
|
109
113
|
// Final pass: rewrites from the analysis pass are applied and the props destructuring disappears.
|
|
@@ -119,8 +123,6 @@ export interface Generated {
|
|
|
119
123
|
|
|
120
124
|
const CTX_REFERENCE = /\bctx\b/
|
|
121
125
|
const IDENTIFIER = /[\p{ID_Start}$_][\p{ID_Continue}$]*/gu
|
|
122
|
-
const IMPORT_COMMA_AFTER = /^\s*,\s*/
|
|
123
|
-
const IMPORT_COMMA_BEFORE = /,\s*$/
|
|
124
126
|
// The specifier of an import that did not parse, quoted and closed or not.
|
|
125
127
|
const BROKEN_SPECIFIER = /^((?:\s*(?:\/\/.*\n|\/\*(?:[^*]|\*(?!\/))*\*\/))*\s*import\b(?:[^'"]*[^\w$'"]from)?\s*)((['"])[^'";\s]*\3?)/
|
|
126
128
|
// `kay build` renders the page once when it is `true`.
|
|
@@ -382,13 +384,13 @@ class ModuleShell {
|
|
|
382
384
|
b.add(this.slotTypes().imports)
|
|
383
385
|
|
|
384
386
|
if (mode === 'html')
|
|
385
|
-
b.add(htmlHelperImport(this.options.awaitAlert, facts.await))
|
|
387
|
+
b.add(htmlHelperImport(this.options.awaitAlert, facts.await) + lazyNoteImport(this.options.lazy, mode))
|
|
386
388
|
|
|
387
389
|
if (this.loadPlan)
|
|
388
390
|
b.add(`import { loadScope as ${helperName('loadScope')} } from 'kay/html'\n`)
|
|
389
391
|
|
|
390
392
|
if (mode === 'dom')
|
|
391
|
-
b.add(domHelperImport(this.options.awaitAlert, facts.await))
|
|
393
|
+
b.add(domHelperImport(this.options.awaitAlert, facts.await) + lazyDomImport(this.options.lazy))
|
|
392
394
|
|
|
393
395
|
// Apart from the DOM helpers, which the entry shares with every page, so only a site using it ships its code.
|
|
394
396
|
if (mode === 'dom' && this.kind === 'island' && titled)
|
|
@@ -695,7 +697,7 @@ class ModuleShell {
|
|
|
695
697
|
if (left.length > 0 && left.length === imports.filter(inside).length)
|
|
696
698
|
return
|
|
697
699
|
|
|
698
|
-
const edits: { start: number, end: number, text?: string }[] = left.map(binding => this.
|
|
700
|
+
const edits: { start: number, end: number, text?: string }[] = [...left.map(binding => withoutComma(this.src, binding.span, binding.declaration)), ...lazyEdits(imports, span, this.options.lazy, this.mode, this.options.moduleId)]
|
|
699
701
|
|
|
700
702
|
for (const specifier of specifiers) {
|
|
701
703
|
const quoted = this.src.slice(specifier.start, specifier.end)
|
|
@@ -730,18 +732,6 @@ class ModuleShell {
|
|
|
730
732
|
return start === 0 || this.src[start - 1] === '\n' ? start : offset
|
|
731
733
|
}
|
|
732
734
|
|
|
733
|
-
// An import specifier with the comma that separates it from its neighbour.
|
|
734
|
-
private withoutComma(specifier: Span, declaration: Span): Span {
|
|
735
|
-
const after = IMPORT_COMMA_AFTER.exec(this.src.slice(specifier.end, declaration.end))
|
|
736
|
-
|
|
737
|
-
if (after)
|
|
738
|
-
return { start: specifier.start, end: specifier.end + after[0].length }
|
|
739
|
-
|
|
740
|
-
const before = IMPORT_COMMA_BEFORE.exec(this.src.slice(declaration.start, specifier.start))
|
|
741
|
-
|
|
742
|
-
return { start: specifier.start - (before?.[0].length ?? 0), end: specifier.end }
|
|
743
|
-
}
|
|
744
|
-
|
|
745
735
|
// Server exports stay at module level; the rest of the fence becomes `load(ctx)`, returning every name it declares.
|
|
746
736
|
private emitLoad(server: ServerAnalysis) {
|
|
747
737
|
const { b } = this
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IfBranch, IfNode, Span } from './ast'
|
|
2
|
+
|
|
3
|
+
const UNSET_NAME = /^(?:aria|data)-/
|
|
4
|
+
|
|
5
|
+
function text(src: string, span: Span): string {
|
|
6
|
+
return src.slice(span.start, span.end).trim()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// A branch whose test is the literal `false`, which a build writes for a feature no call site uses: it is never taken, so the code leaves it out.
|
|
10
|
+
export function neverTaken(src: string, branch: IfBranch): boolean {
|
|
11
|
+
return branch.alias === undefined && text(src, branch.test) === 'false'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// An `if` with no `else` that draws nothing: the markup keeps its markers and the code has no block to run for them.
|
|
15
|
+
export function neverShown(src: string, node: IfNode): boolean {
|
|
16
|
+
return node.fallback === undefined && node.branches.every(branch => neverTaken(src, branch))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// An `aria-` or `data-` attribute written `{undefined}`, as a build leaves one of a feature no call site uses: it is never set.
|
|
20
|
+
export function neverSet(src: string, attribute: { name: string, expression: Span, action: boolean }): boolean {
|
|
21
|
+
return !attribute.action && UNSET_NAME.test(attribute.name) && text(src, attribute.expression) === 'undefined'
|
|
22
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { Lint } from './lints'
|
|
2
|
+
|
|
3
|
+
// The lints of the `deprecated` group for how an island read its sources and actions before 1.105, with the others in `DEPRECATED_LINTS`.
|
|
4
|
+
export const SOURCE_READERS = {
|
|
5
|
+
'deprecated-source-readers': {
|
|
6
|
+
level: 'warn',
|
|
7
|
+
group: 'deprecated',
|
|
8
|
+
since: '1.105',
|
|
9
|
+
site: true,
|
|
10
|
+
summary: 'The readers and hooks of an island\'s sources before 1.105, which every source reads alike since: `data()` in place of `value()` (a `resource`), `last()` (a `stream` or `socket`) and `rows()` (a `local` collection), `onData` in place of `onSuccess` (a `track()` handle) and `onSync` (a collection), whose event hands `value` where they handed `data` and `rows`, an action\'s `data()` and `status()` in place of `succeeded()`, and a collection\'s `sync.queued()` and `sync.status()` in place of `unsynced()` and `syncStatus()`. The old names work until 1.108. Found in the TypeScript files and `.kay` files of the project, templates included, on a name bound once to a call of `resource`, `stream`, `socket` or `local` from `kay` or to a `.track()` call, as `kay check` reads no types: a source reached through a property, a prop or another file is not found; `succeeded()` is found on any receiver. The fix renames the member, and the `data` or `rows` of a hook\'s inline handler to `value`; `succeeded()?.data` becomes `data()` and `succeeded() !== undefined` becomes `status() === \'ready\'`. A `succeeded()` read in any other way, a handler that is no inline function and a shorthand hook are reported with no fix.',
|
|
11
|
+
wrong: '---\nimport { local, resource } from \'kay\'\nimport notesApi from \'../api/notes\'\nimport { save } from \'./notes\'\n\nconst list = resource(notesApi, \'/\')\nconst notes = local({ key: \'id\', read: () => [], put: save })\n---\np {list.value()?.length} on the server, {notes.rows().length} here, {notes.unsynced()} waiting',
|
|
12
|
+
right: '---\nimport { local, resource } from \'kay\'\nimport notesApi from \'../api/notes\'\nimport { save } from \'./notes\'\n\nconst list = resource(notesApi, \'/\')\nconst notes = local({ key: \'id\', read: () => [], put: save })\n---\np {list.data()?.length} on the server, {notes.data().length} here, {notes.sync.queued()} waiting',
|
|
13
|
+
},
|
|
14
|
+
'deprecated-live-api': {
|
|
15
|
+
level: 'warn',
|
|
16
|
+
group: 'deprecated',
|
|
17
|
+
since: '1.105',
|
|
18
|
+
site: true,
|
|
19
|
+
summary: 'The forms of `set` and `presence` before 1.105, which write every live value and every room alike since: `set(next, { key })` of a value per key and `set(next, { user })` of a value per user in place of `set(key, next)` and `set(user, next)`, and `presence({ room, member })` in place of `presence(room, member)`. The old forms work until 1.108. Found in the TypeScript files and `.kay` files of the project, on a name bound once to a `live()` call from `kay`, or imported under the name of a declaration every file of the project agrees on (a value per key is one declared with a function of the key or `key: true`, per user with `user: true`), as `kay check` reads no types: a value reached through a namespace import or a property is not found. `presence` is the one imported from `kay`. The fix reorders the arguments of `set`, and writes the arguments of `presence` as one object, its options object spread into it; a `presence` given options that are no object written there is reported with no fix.',
|
|
20
|
+
wrong: '// src/live.ts\nimport { live } from \'kay\'\n\nexport const room = live((id: string) => ({ id, users: 0 }))\n\nroom.set(\'lobby\', { id: \'lobby\', users: 3 })',
|
|
21
|
+
right: '// src/live.ts\nimport { live } from \'kay\'\n\nexport const room = live((id: string) => ({ id, users: 0 }))\n\nroom.set({ id: \'lobby\', users: 3 }, { key: \'lobby\' })',
|
|
22
|
+
},
|
|
23
|
+
'deprecated-action-type': {
|
|
24
|
+
level: 'warn',
|
|
25
|
+
group: 'deprecated',
|
|
26
|
+
since: '1.105',
|
|
27
|
+
site: true,
|
|
28
|
+
summary: '`Action<never, unknown>` before 1.105, the type a prop takes to accept any action: `Action` since, whose two parameters default to it. `Action<{ name: string }, string>` keeps its input and output types, and a `.with()` action crosses into an island as any other does. The old form works until 1.108. Found on the `Action` a file imports from `kay`, under any local name, in the TypeScript files and the fences of `.kay` files. The fix drops the type arguments.',
|
|
29
|
+
wrong: '---\nimport type { Action } from \'kay\'\n\nconst { run } = props<{ run: Action<never, unknown> }>()\n---\nform(action={run})\n button Go',
|
|
30
|
+
right: '---\nimport type { Action } from \'kay\'\n\nconst { run } = props<{ run: Action }>()\n---\nform(action={run})\n button Go',
|
|
31
|
+
},
|
|
32
|
+
'deprecated-action-readers': {
|
|
33
|
+
level: 'warn',
|
|
34
|
+
group: 'deprecated',
|
|
35
|
+
since: '1.105',
|
|
36
|
+
site: true,
|
|
37
|
+
summary: 'An action\'s `failed()`, `error(field)` and `validate(form, field)` before 1.105, which a form shows and now reads from `form`: `form.failed()`, `form.error(field)` and `form.validate(form, field)`, the call state (`pending()`, `status()`, `data()`) staying on the action. The old names work until 1.108. Found in the TypeScript files and `.kay` files of the project, templates included, on a name bound once to a call of `action` from `kay`, to the `.with()` of one, or imported in lowercase from a `.kay` file, as `kay check` reads no types: an action reached through a property or a prop is not found. The fix writes `form.` before the name.',
|
|
38
|
+
wrong: '---\nimport { add } from \'./notes.kay\'\n---\nform(action={add})\n input(name="title" aria-invalid={add.error(\'title\') ? \'true\' : undefined})\n if add.failed()\n p Not saved',
|
|
39
|
+
right: '---\nimport { add } from \'./notes.kay\'\n---\nform(action={add})\n input(name="title" aria-invalid={add.form.error(\'title\') ? \'true\' : undefined})\n if add.form.failed()\n p Not saved',
|
|
40
|
+
},
|
|
41
|
+
} as const satisfies Record<string, Lint>
|
|
@@ -7,7 +7,7 @@ export const SCHEMA_BUILDERS = {
|
|
|
7
7
|
group: 'deprecated',
|
|
8
8
|
since: '1.106',
|
|
9
9
|
site: true,
|
|
10
|
-
summary: 'The PascalCase builders of `s` before 1.106, which kay\'s own lowercase builders replace, each taking the same field options (`optional`, `default`, `error`, `label`, `description`, `example`) and short names for the rest: `s.String` is `s.string` (`min`, `max`), `s.Integer` `s.int`, `s.Number` and `s.Numeric` `s.number`, `s.Boolean` and `s.BooleanString` `s.boolean`, `s.Array` `s.list`, `s.UnionEnum` and `s.UnionKeys` `s.enum`, and `s.Date`, `s.Literal`, `s.Union`, `s.Object`, `s.File`, `s.Files`, `s.Secret` and `s.Public` their lowercase names; `s.Optional(field)` is `optional: true` in the options of the field; an `s.Object({ ... })` that is the schema of an `action` or a `defineEnv` is the record of fields alone; and a file size written `\'2m\'` is `\'2mb\'`. The old names work until 2.0. Found on the `s` a file imports from `kay`, in the TypeScript files and the fences of `.kay` files. The fix renames the builder and the options that changed; an `s.Optional` around anything but one of these builders, such as a helper of `kay/content`, is left as it is. A lowercase `s.object` refuses a key its shape lacks where kay reads the schema itself (
|
|
10
|
+
summary: 'The PascalCase builders of `s` before 1.106, which kay\'s own lowercase builders replace, each taking the same field options (`optional`, `default`, `error`, `label`, `description`, `example`) and short names for the rest: `s.String` is `s.string` (`min`, `max`), `s.Integer` `s.int`, `s.Number` and `s.Numeric` `s.number`, `s.Boolean` and `s.BooleanString` `s.boolean`, `s.Array` `s.list`, `s.UnionEnum` and `s.UnionKeys` `s.enum`, and `s.Date`, `s.Literal`, `s.Union`, `s.Object`, `s.File`, `s.Files`, `s.Secret` and `s.Public` their lowercase names; `s.Optional(field)` is `optional: true` in the options of the field; an `s.Object({ ... })` that is the schema of an `action` or a `defineEnv` is the record of fields alone; and a file size written `\'2m\'` is `\'2mb\'`. The old names work until 2.0. Found on the `s` a file imports from `kay`, in the TypeScript files and the fences of `.kay` files. The fix renames the builder and the options that changed; an `s.Optional` around anything but one of these builders, such as a helper of `kay/content`, is left as it is. A lowercase `s.object` refuses a key its shape lacks where kay reads the schema itself (an action\'s input, an API route\'s body, `defineEnv`, collection frontmatter), where `s.Object` let it by: write `{ extra: \'strip\' }` where the old way is wanted. A query, the headers and the cookies of a request carry keys no schema names, so their unknown keys are dropped whatever the schema says.',
|
|
11
11
|
wrong: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action(s.Object({ title: s.String({ maxLength: 200 }), note: s.Optional(s.String()) }), ({ title }) => title)\n---\np x',
|
|
12
12
|
right: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action({ title: s.string({ max: 200 }), note: s.string({ optional: true }) }, ({ title }) => title)\n---\np x',
|
|
13
13
|
},
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Lint } from './lints'
|
|
2
|
+
|
|
3
|
+
// The lints of the `deprecated` group that came in 1.107, with the others in `DEPRECATED_LINTS`.
|
|
4
|
+
export const ACTION_OPTIONS = {
|
|
5
|
+
'deprecated-action-options': {
|
|
6
|
+
level: 'warn',
|
|
7
|
+
group: 'deprecated',
|
|
8
|
+
since: '1.107',
|
|
9
|
+
site: true,
|
|
10
|
+
summary: 'The arguments of `action` before 1.107, `action(schema, handler, options)` and `action(handler, options)`: the options come first, with the input in them, as an API route\'s do, `action({ input: schema, ...options }, handler)` and `action(options, handler)`. `input` is a plain record of fields or any schema. The old forms work until 2.0. Found on the `action` a file imports from `kay`, in the TypeScript files and the fences of `.kay` files; the fix moves the arguments and keeps their text.',
|
|
11
|
+
wrong: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action({ title: s.string() }, ({ title }) => title, { maxSize: \'1mb\' })\n---\np x',
|
|
12
|
+
right: '--- server\nimport { action, s } from \'kay\'\n\nexport const add = action({ input: { title: s.string() }, maxSize: \'1mb\' }, ({ title }) => title)\n---\np x',
|
|
13
|
+
},
|
|
14
|
+
} as const satisfies Record<string, Lint>
|
|
@@ -1,47 +1,15 @@
|
|
|
1
1
|
import type { Lint } from './lints'
|
|
2
2
|
import { AUTH_LINTS } from './deprecated-auth-lints'
|
|
3
|
+
import { SOURCE_READERS } from './deprecated-lints-1-105'
|
|
3
4
|
import { SCHEMA_BUILDERS } from './deprecated-lints-1-106'
|
|
5
|
+
import { ACTION_OPTIONS } from './deprecated-lints-1-107'
|
|
4
6
|
import { TYPED_DEPRECATIONS } from './deprecated-typed-lints'
|
|
5
7
|
|
|
6
8
|
// The lints of the `deprecated` group, with the other lints in `LINTS`; each stays three minors from its `since`.
|
|
7
9
|
export const DEPRECATED_LINTS = {
|
|
8
10
|
...SCHEMA_BUILDERS,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
group: 'deprecated',
|
|
12
|
-
since: '1.105',
|
|
13
|
-
site: true,
|
|
14
|
-
summary: 'The readers and hooks of an island\'s sources before 1.105, which every source reads alike since: `data()` in place of `value()` (a `resource`), `last()` (a `stream` or `socket`) and `rows()` (a `local` collection), `onData` in place of `onSuccess` (a `track()` handle) and `onSync` (a collection), whose event hands `value` where they handed `data` and `rows`, an action\'s `data()` and `status()` in place of `succeeded()`, and a collection\'s `sync.queued()` and `sync.status()` in place of `unsynced()` and `syncStatus()`. The old names work until 1.108. Found in the TypeScript files and `.kay` files of the project, templates included, on a name bound once to a call of `resource`, `stream`, `socket` or `local` from `kay` or to a `.track()` call, as `kay check` reads no types: a source reached through a property, a prop or another file is not found; `succeeded()` is found on any receiver. The fix renames the member, and the `data` or `rows` of a hook\'s inline handler to `value`; `succeeded()?.data` becomes `data()` and `succeeded() !== undefined` becomes `status() === \'ready\'`. A `succeeded()` read in any other way, a handler that is no inline function and a shorthand hook are reported with no fix.',
|
|
15
|
-
wrong: '---\nimport { local, resource } from \'kay\'\nimport notesApi from \'../api/notes\'\nimport { save } from \'./notes\'\n\nconst list = resource(notesApi, \'/\')\nconst notes = local({ key: \'id\', read: () => [], put: save })\n---\np {list.value()?.length} on the server, {notes.rows().length} here, {notes.unsynced()} waiting',
|
|
16
|
-
right: '---\nimport { local, resource } from \'kay\'\nimport notesApi from \'../api/notes\'\nimport { save } from \'./notes\'\n\nconst list = resource(notesApi, \'/\')\nconst notes = local({ key: \'id\', read: () => [], put: save })\n---\np {list.data()?.length} on the server, {notes.data().length} here, {notes.sync.queued()} waiting',
|
|
17
|
-
},
|
|
18
|
-
'deprecated-live-api': {
|
|
19
|
-
level: 'warn',
|
|
20
|
-
group: 'deprecated',
|
|
21
|
-
since: '1.105',
|
|
22
|
-
site: true,
|
|
23
|
-
summary: 'The forms of `set` and `presence` before 1.105, which write every live value and every room alike since: `set(next, { key })` of a value per key and `set(next, { user })` of a value per user in place of `set(key, next)` and `set(user, next)`, and `presence({ room, member })` in place of `presence(room, member)`. The old forms work until 1.108. Found in the TypeScript files and `.kay` files of the project, on a name bound once to a `live()` call from `kay`, or imported under the name of a declaration every file of the project agrees on (a value per key is one declared with a function of the key or `key: true`, per user with `user: true`), as `kay check` reads no types: a value reached through a namespace import or a property is not found. `presence` is the one imported from `kay`. The fix reorders the arguments of `set`, and writes the arguments of `presence` as one object, its options object spread into it; a `presence` given options that are no object written there is reported with no fix.',
|
|
24
|
-
wrong: '// src/live.ts\nimport { live } from \'kay\'\n\nexport const room = live((id: string) => ({ id, users: 0 }))\n\nroom.set(\'lobby\', { id: \'lobby\', users: 3 })',
|
|
25
|
-
right: '// src/live.ts\nimport { live } from \'kay\'\n\nexport const room = live((id: string) => ({ id, users: 0 }))\n\nroom.set({ id: \'lobby\', users: 3 }, { key: \'lobby\' })',
|
|
26
|
-
},
|
|
27
|
-
'deprecated-action-type': {
|
|
28
|
-
level: 'warn',
|
|
29
|
-
group: 'deprecated',
|
|
30
|
-
since: '1.105',
|
|
31
|
-
site: true,
|
|
32
|
-
summary: '`Action<never, unknown>` before 1.105, the type a prop takes to accept any action: `Action` since, whose two parameters default to it. `Action<{ name: string }, string>` keeps its input and output types, and a `.with()` action crosses into an island as any other does. The old form works until 1.108. Found on the `Action` a file imports from `kay`, under any local name, in the TypeScript files and the fences of `.kay` files. The fix drops the type arguments.',
|
|
33
|
-
wrong: '---\nimport type { Action } from \'kay\'\n\nconst { run } = props<{ run: Action<never, unknown> }>()\n---\nform(action={run})\n button Go',
|
|
34
|
-
right: '---\nimport type { Action } from \'kay\'\n\nconst { run } = props<{ run: Action }>()\n---\nform(action={run})\n button Go',
|
|
35
|
-
},
|
|
36
|
-
'deprecated-action-readers': {
|
|
37
|
-
level: 'warn',
|
|
38
|
-
group: 'deprecated',
|
|
39
|
-
since: '1.105',
|
|
40
|
-
site: true,
|
|
41
|
-
summary: 'An action\'s `failed()`, `error(field)` and `validate(form, field)` before 1.105, which a form shows and now reads from `form`: `form.failed()`, `form.error(field)` and `form.validate(form, field)`, the call state (`pending()`, `status()`, `data()`) staying on the action. The old names work until 1.108. Found in the TypeScript files and `.kay` files of the project, templates included, on a name bound once to a call of `action` from `kay`, to the `.with()` of one, or imported in lowercase from a `.kay` file, as `kay check` reads no types: an action reached through a property or a prop is not found. The fix writes `form.` before the name.',
|
|
42
|
-
wrong: '---\nimport { add } from \'./notes.kay\'\n---\nform(action={add})\n input(name="title" aria-invalid={add.error(\'title\') ? \'true\' : undefined})\n if add.failed()\n p Not saved',
|
|
43
|
-
right: '---\nimport { add } from \'./notes.kay\'\n---\nform(action={add})\n input(name="title" aria-invalid={add.form.error(\'title\') ? \'true\' : undefined})\n if add.form.failed()\n p Not saved',
|
|
44
|
-
},
|
|
11
|
+
...ACTION_OPTIONS,
|
|
12
|
+
...SOURCE_READERS,
|
|
45
13
|
'deprecated-ui-props': {
|
|
46
14
|
level: 'warn',
|
|
47
15
|
group: 'deprecated',
|
|
@@ -66,32 +34,6 @@ export const DEPRECATED_LINTS = {
|
|
|
66
34
|
wrong: '---\nimport Card from \'./card.kay\'\n---\nCard(class={{ head: \'p-6\' }})',
|
|
67
35
|
right: '---\nimport Card from \'./card.kay\'\n---\nCard(parts={{ head: \'p-6\' }})',
|
|
68
36
|
},
|
|
69
|
-
'deprecated-script-fence': {
|
|
70
|
-
level: 'warn',
|
|
71
|
-
group: 'deprecated',
|
|
72
|
-
since: '1.102',
|
|
73
|
-
summary: '`--- script` as the first fence of a file, `---` since 1.102: the bare line opens the component script wherever no named fence comes before it, so one fence had two spellings. `--- script` stays for a script that follows a `--- server`, `--- module` or `--- style` fence, where a bare `---` would close that fence instead, and `--- client` still replaces `---` rather than modifying it. The old form still works. The fix drops the word, keeping the type parameters of `--- script <T>` as `--- <T>`.',
|
|
74
|
-
wrong: '--- script\nconst { title } = props<{ title: string }>()\n---\nh1 {title}',
|
|
75
|
-
right: '---\nconst { title } = props<{ title: string }>()\n---\nh1 {title}',
|
|
76
|
-
},
|
|
77
|
-
'deprecated-schema-type': {
|
|
78
|
-
level: 'warn',
|
|
79
|
-
group: 'deprecated',
|
|
80
|
-
since: '1.103',
|
|
81
|
-
site: true,
|
|
82
|
-
summary: '`TSchema` imported from `kay/library`, `Schema` since 1.103: kay\'s own name for what `s` builds and every schema option takes, so a signature of the app does not name TypeBox, whose type follows the Elysia kay is built on. The old name works until 1.106. Found on an import from `kay/library` in the TypeScript files and `.kay` files of the project. The fix renames the import and each use of it; a file that already has a `Schema` of its own is reported with no fix, and one that imports it aliased with only the import renamed.',
|
|
83
|
-
wrong: '---\nimport type { TSchema } from \'kay/library\'\n\nexport function check<Fields extends TSchema>(fields: Fields) {\n return fields\n}\n---\np x',
|
|
84
|
-
right: '---\nimport type { Schema } from \'kay/library\'\n\nexport function check<Fields extends Schema>(fields: Fields) {\n return fields\n}\n---\np x',
|
|
85
|
-
},
|
|
86
|
-
'deprecated-package-names': {
|
|
87
|
-
level: 'warn',
|
|
88
|
-
group: 'deprecated',
|
|
89
|
-
since: '1.104',
|
|
90
|
-
site: true,
|
|
91
|
-
summary: 'A package of kay under the `@kaynooo` scope, `@kayjs` since 1.104: `@kaynooo/kayjs` is `@kayjs/kay`, and `@kaynooo/kayjs-ui`, `-auth`, `-mail`, `-cms` and `-ai` are `@kayjs/ui`, `@kayjs/auth`, `@kayjs/mail`, `@kayjs/cms` and `@kayjs/ai`. The old names stop at 1.103, which stays installable, so an app on them installs and checks as before until it moves; this lint goes in 1.107. Found where a name is an `import` or `export ... from` specifier, a `require()`, `import()` or `mock.module()` argument or a config key (a quoted name keyed to anything but a package name or a version, as `librarySettings`) of the project\'s TypeScript and `.kay` files, in the `@import` and `@plugin` paths of its CSS, and in its package.json and tsconfig files; a name in a comment or any other string, as data a tool reads or a table of renames, is left alone. The fix writes the new name; a package.json that lists the new name already is reported with a fix that is not safe, and `kay upgrade` does the whole move, package.json and install included.',
|
|
92
|
-
wrong: '---\nimport Button from \'@kaynooo/kayjs-ui/button.kay\'\n---\nButton Save',
|
|
93
|
-
right: '---\nimport Button from \'@kayjs/ui/button.kay\'\n---\nButton Save',
|
|
94
|
-
},
|
|
95
37
|
'deprecated-test-helpers': {
|
|
96
38
|
level: 'warn',
|
|
97
39
|
group: 'deprecated',
|
|
@@ -595,9 +537,10 @@ export const DEPRECATION_MINORS: readonly { since: string, removedIn?: string }[
|
|
|
595
537
|
{ since: '1.99', removedIn: '1.103' },
|
|
596
538
|
{ since: '1.100', removedIn: '1.104' },
|
|
597
539
|
{ since: '1.101', removedIn: '1.105' },
|
|
598
|
-
{ since: '1.102' },
|
|
599
|
-
{ since: '1.103' },
|
|
600
|
-
{ since: '1.104' },
|
|
540
|
+
{ since: '1.102', removedIn: '1.107' },
|
|
541
|
+
{ since: '1.103', removedIn: '1.107' },
|
|
542
|
+
{ since: '1.104', removedIn: '1.108' },
|
|
601
543
|
{ since: '1.105' },
|
|
602
544
|
{ since: '1.106' },
|
|
545
|
+
{ since: '1.107' },
|
|
603
546
|
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Span } from './ast'
|
|
2
|
+
import type { CodeBuilder } from './mapping'
|
|
3
|
+
import type { LinkPlan } from './plan'
|
|
4
|
+
import { neverSet } from './dead-code'
|
|
5
|
+
|
|
6
|
+
// The effect setting the property an attribute written `name={value}` stands for, as the server writes it: none for one a build leaves `{undefined}`.
|
|
7
|
+
export function propertyBindings<Node>(b: CodeBuilder, src: string, attribute: { name: string, expression: Span, action: boolean }, link: LinkPlan, node: Node): ((variable: (node: Node) => string) => void)[] {
|
|
8
|
+
if (neverSet(src, attribute))
|
|
9
|
+
return []
|
|
10
|
+
|
|
11
|
+
return [(variable) => {
|
|
12
|
+
b.add(`KayEffect(() => KayProperty(${variable(node)}, ${JSON.stringify(attribute.name)}, `)
|
|
13
|
+
|
|
14
|
+
if (attribute.action)
|
|
15
|
+
b.add('KayFormAction((').addSource(attribute.expression).add('))')
|
|
16
|
+
else if (attribute.name === 'href' && link.leaving)
|
|
17
|
+
b.add(`KayOutside(${variable(node)}, (`).addSource(attribute.expression).add(`)${link.rel ? ', true' : ''})`)
|
|
18
|
+
else
|
|
19
|
+
b.add('(').addSource(attribute.expression).add(')')
|
|
20
|
+
|
|
21
|
+
b.add(`${link.written && attribute.name === 'href' ? ', true' : ''}));`)
|
|
22
|
+
}]
|
|
23
|
+
}
|
package/src/compiler/dom.ts
CHANGED
|
@@ -5,8 +5,10 @@ import type { CodeBuilder } from './mapping'
|
|
|
5
5
|
import type { BindingPlan, LinkPlan } from './plan'
|
|
6
6
|
import { mayLeaveSite } from '../runtime/outside'
|
|
7
7
|
import { marksServerIsland, modifiersOf } from './ast'
|
|
8
|
+
import { neverShown, neverTaken } from './dead-code'
|
|
8
9
|
import { fieldBindings } from './dom-fields'
|
|
9
10
|
import { FormHere } from './dom-here'
|
|
11
|
+
import { propertyBindings } from './dom-property'
|
|
10
12
|
import { addHandler, listenerOptions } from './event-modifiers'
|
|
11
13
|
import { decodeEntities, isFunctionAt } from './expression'
|
|
12
14
|
import { addKeyParameters, addRowItem, childItems, constDeclaration, contentOf, errorParagraphArguments, isDeclaration, rowKeying, slotValue, soleDynamic } from './items'
|
|
@@ -105,6 +107,9 @@ export class DomTemplate extends TemplateWriter {
|
|
|
105
107
|
this.element(item.node)
|
|
106
108
|
b.add('); ')
|
|
107
109
|
}
|
|
110
|
+
else if (item.kind === 'if' && neverShown(this.src, item.node)) {
|
|
111
|
+
b.add(`KayMarkers(${parent}); `)
|
|
112
|
+
}
|
|
108
113
|
else {
|
|
109
114
|
b.add(`{ const [KayS, KayE] = KayMarkers(${parent}); `)
|
|
110
115
|
this.dynamic(item, 'null', 'KayS', 'KayE')
|
|
@@ -115,6 +120,12 @@ export class DomTemplate extends TemplateWriter {
|
|
|
115
120
|
b.add(`${'} '.repeat(blocks)}})`)
|
|
116
121
|
}
|
|
117
122
|
|
|
123
|
+
// A dynamic part, but for an `if` that draws nothing: its markers are in the markup and there is no block to run.
|
|
124
|
+
private slot(item: DynamicItem, element: string, start: string, end: string): void {
|
|
125
|
+
if (item.kind !== 'if' || !neverShown(this.src, item.node))
|
|
126
|
+
this.dynamic(item, element, start, end)
|
|
127
|
+
}
|
|
128
|
+
|
|
118
129
|
// A dynamic part rendered into an element's content, or between two markers.
|
|
119
130
|
private dynamic(item: DynamicItem, element: string, start: string, end: string): void {
|
|
120
131
|
const { b } = this
|
|
@@ -218,7 +229,7 @@ export class DomTemplate extends TemplateWriter {
|
|
|
218
229
|
// A chain naming no value needs no memo of it.
|
|
219
230
|
b.add(`${node.branches.some(branch => branch.alias) ? 'KayBranches' : 'KayChoose'}(${at}, [`)
|
|
220
231
|
|
|
221
|
-
for (const branch of node.branches) {
|
|
232
|
+
for (const branch of node.branches.filter(each => !neverTaken(this.src, each))) {
|
|
222
233
|
b.wrap(branch, () => {
|
|
223
234
|
b.add('[() => (').addSource(branch.test).add('), (')
|
|
224
235
|
|
|
@@ -540,18 +551,7 @@ export class DomTemplate extends TemplateWriter {
|
|
|
540
551
|
break
|
|
541
552
|
case 'value':
|
|
542
553
|
this.notesLink(link, attribute.name)
|
|
543
|
-
own.push((
|
|
544
|
-
b.add(`KayEffect(() => KayProperty(${variable(node)}, ${JSON.stringify(attribute.name)}, `)
|
|
545
|
-
|
|
546
|
-
if (attribute.action)
|
|
547
|
-
b.add('KayFormAction((').addSource(attribute.expression).add('))')
|
|
548
|
-
else if (attribute.name === 'href' && link.leaving)
|
|
549
|
-
b.add(`KayOutside(${variable(node)}, (`).addSource(attribute.expression).add(`)${link.rel ? ', true' : ''})`)
|
|
550
|
-
else
|
|
551
|
-
b.add('(').addSource(attribute.expression).add(')')
|
|
552
|
-
|
|
553
|
-
b.add(`${link.written && attribute.name === 'href' ? ', true' : ''}));`)
|
|
554
|
-
})
|
|
554
|
+
own.push(...propertyBindings(b, this.src, attribute, link, node))
|
|
555
555
|
|
|
556
556
|
break
|
|
557
557
|
}
|
|
@@ -620,14 +620,14 @@ export class DomTemplate extends TemplateWriter {
|
|
|
620
620
|
html += this.templateOf(item.node, this.child(node, 'element'), bindings)
|
|
621
621
|
}
|
|
622
622
|
else if (sole) {
|
|
623
|
-
bindings.push(variable => this.
|
|
623
|
+
bindings.push(variable => this.slot(item, variable(node), 'null', 'null'))
|
|
624
624
|
}
|
|
625
625
|
else {
|
|
626
626
|
const start = this.child(node, 'start')
|
|
627
627
|
const end = this.child(node, 'end')
|
|
628
628
|
|
|
629
629
|
html += START_MARKER + END_MARKER
|
|
630
|
-
bindings.push(variable => this.
|
|
630
|
+
bindings.push(variable => this.slot(item, 'null', variable(start), variable(end)))
|
|
631
631
|
}
|
|
632
632
|
}
|
|
633
633
|
|
|
@@ -45,3 +45,18 @@ export function importEdits(file: KayFile, fence: Span | undefined, imports: rea
|
|
|
45
45
|
|
|
46
46
|
return edits
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
const COMMA_AFTER = /^\s*,\s*/
|
|
50
|
+
const COMMA_BEFORE = /,\s*$/
|
|
51
|
+
|
|
52
|
+
// An import specifier with the comma that separates it from its neighbour.
|
|
53
|
+
export function withoutComma(src: string, specifier: Span, declaration: Span): Span {
|
|
54
|
+
const after = COMMA_AFTER.exec(src.slice(specifier.end, declaration.end))
|
|
55
|
+
|
|
56
|
+
if (after)
|
|
57
|
+
return { start: specifier.start, end: specifier.end + after[0].length }
|
|
58
|
+
|
|
59
|
+
const before = COMMA_BEFORE.exec(src.slice(declaration.start, specifier.start))
|
|
60
|
+
|
|
61
|
+
return { start: specifier.start - (before?.[0].length ?? 0), end: specifier.end }
|
|
62
|
+
}
|
package/src/compiler/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { UiEntry } from '../runtime/ui'
|
|
|
3
3
|
import type { Attribute, Diagnostic, KayFile, Node, Span } from './ast'
|
|
4
4
|
import type { ErrorName } from './errors'
|
|
5
5
|
import type { IslandCause } from './island-cause'
|
|
6
|
+
import type { ImportedComponents } from './lazy-imports'
|
|
6
7
|
import type { LintLevels } from './lints'
|
|
7
8
|
import type { Expansion } from './markdown-block'
|
|
8
9
|
import type { ImportedSignals, SignalKind } from './module-signals'
|
|
@@ -19,13 +20,13 @@ import { deprecatedChildrenProp } from './deprecated-children'
|
|
|
19
20
|
import { deprecatedIslandAttributes, deprecatedIslandForms, islandProblems } from './deprecated-island'
|
|
20
21
|
import { deprecatedPageSettings } from './deprecated-page'
|
|
21
22
|
import { deprecatedPartsClass } from './deprecated-parts'
|
|
22
|
-
import { spelledOutScriptFence } from './deprecated-script-fence'
|
|
23
23
|
import { asyncReplies, cssImportsWithoutText, missingCaptchas, onceReadProps, separatePageSettings, serverOnlyImports, unboundedFields, unreturnedFails } from './fence-checks'
|
|
24
24
|
import { openRedirects } from './fence-redirects'
|
|
25
25
|
import { cwd, scopeStorage } from './host'
|
|
26
26
|
import { ignoredIslandExport, interactiveProps, islandMessages, malformedInteractive, withAlertKeys } from './island-arguments'
|
|
27
27
|
import { describeCause } from './island-cause'
|
|
28
28
|
import { markerMismatch } from './island-marker'
|
|
29
|
+
import { lazyImportsOf } from './lazy-imports'
|
|
29
30
|
import { linkFlags } from './link-flags'
|
|
30
31
|
import { applyLints, templateLints } from './lints'
|
|
31
32
|
import { SourceMap } from './mapping'
|
|
@@ -96,6 +97,8 @@ export interface CompileOptions {
|
|
|
96
97
|
insideIsland?: boolean | undefined
|
|
97
98
|
// The signals and memos of the modules the component imports, which it writes by assigning and the check reports read uncalled: `importedSignals` from kay's build finds them.
|
|
98
99
|
importedSignals?: ImportedSignals | undefined
|
|
100
|
+
// The `.kay` modules the component imports that a template draws only where a branch may not render, which then load on their own the first time they draw: found by kay's build, which names the chunk of each.
|
|
101
|
+
components?: ImportedComponents | undefined
|
|
99
102
|
// The browser's build only: the classes a later Tailwind class overrides, with which literal classes written together resolve while compiling.
|
|
100
103
|
classTable?: ClassTable | undefined
|
|
101
104
|
// The server's build of an app with Tailwind: a shorthand beside a static `class` merges while rendering.
|
|
@@ -325,9 +328,11 @@ export function compileKay(original: string, filename: string, options: CompileO
|
|
|
325
328
|
const hydratableServer = options.output === 'html' && options.hydratable === true
|
|
326
329
|
const twin = hydratableServer && !options.twinBuild && island === undefined && !routeFile ? `./${basename(filename)}${ISLAND_TWIN}` : undefined
|
|
327
330
|
const pin = file.pin
|
|
331
|
+
const hydrated = hydratableServer && (island !== undefined || options.twinBuild === true)
|
|
332
|
+
const lazy = lazyImportsOf(file, script.imports, options, hydrated, routeFile, client)
|
|
328
333
|
const rawCause = island === undefined ? undefined : islandCause(file, script) ?? browserCause(file, script, live)
|
|
329
334
|
const cause = withInteractive(realCause(rawCause, expansion, original), script)
|
|
330
|
-
const generateOptions = { cause: options.inspect === true && cause !== undefined ? describeCause(cause) : undefined, classTable: options.classTable, classMerge: options.classMerge, awaitAlert: options.awaitAlert, island, client, lives: island === undefined ? undefined : liveBindings(script, options.importedSignals).map(binding => binding.local), twin, writtenProps: options.writtenProps, output: options.output, failedCode, hydratable:
|
|
335
|
+
const generateOptions = { cause: options.inspect === true && cause !== undefined ? describeCause(cause) : undefined, classTable: options.classTable, classMerge: options.classMerge, awaitAlert: options.awaitAlert, island, client, lives: island === undefined ? undefined : liveBindings(script, options.importedSignals).map(binding => binding.local), twin, writtenProps: options.writtenProps, output: options.output, failedCode, hydratable: hydrated, moduleId: islandId(filename, options.root), includeServer: options.includeServer, params: options.params, paramTypes: options.paramTypes, outerQueries: options.outerQueries, outerGuards: options.outerGuards, outerSlots: options.outerSlots, layoutFile: basename(filename) === LAYOUT, component: options.page === false && !routeFile, check: options.check, route: options.check === true && pageFile, pageFile, namedRefresh: options.namedRefresh, insideIsland: options.insideIsland, inspect: options.inspect, inspectSource: expansion ? { text: original, real: (offset: number) => expansion.real(offset) } : undefined, relocateImport: options.relocateImport, lazy, contextModule: options.check === true ? options.contextModule : undefined, ui: options.output === undefined ? undefined : options.ui, uiAdded: options.output === undefined ? options.ui : undefined, errorPage: isErrorPage(basename(filename)), cardPage: basename(filename) === CARD_PAGE, special: basename(filename).startsWith('_') && basename(filename) !== LAYOUT }
|
|
331
336
|
// The analysis pass names the component so no read resolves to it, then the name is chosen free of what the code reads.
|
|
332
337
|
const analysis = generate(file, script, server, { ...generateOptions, name: SELF })
|
|
333
338
|
const imported = new Map<string, SignalKind>([...script.imports, ...server?.imports ?? []].flatMap((binding) => {
|
|
@@ -379,7 +384,7 @@ export function compileKay(original: string, filename: string, options: CompileO
|
|
|
379
384
|
const browserScript = (island !== undefined || options.insideIsland === true) && !routeFile ? scriptFences(script) : []
|
|
380
385
|
const unusedLints = broken ? [] : [...unreadNames(source, file.template, script, server, found.findings), ...constantSignals(source, [file.script, file.module], found.findings)]
|
|
381
386
|
|
|
382
|
-
diagnostics.push(...unboundedFields(server), ...fenceLints, ...serialAwaits(server), ...browserScript.flatMap(fence => serverOnlyImports(fence)), ...browserScript.includes(script.fence!) ? onceReadProps(script.fence!, script.props, templateWords(file)) : [], ...unusedLints, ...templateLints(file), ...
|
|
387
|
+
diagnostics.push(...unboundedFields(server), ...fenceLints, ...serialAwaits(server), ...browserScript.flatMap(fence => serverOnlyImports(fence)), ...browserScript.includes(script.fence!) ? onceReadProps(script.fence!, script.props, templateWords(file)) : [], ...unusedLints, ...templateLints(file), ...retiredAllowComments(source), ...deprecatedIslandForms(file, script), ...deprecatedIslandAttributes(file), ...deprecatedChildrenProp(file, script), ...linkFlags(file), ...deprecatedPartsClass(file), ...deprecatedPageSettings(source, server), ...ignoredIslandExport(script, island !== undefined), ...malformedInteractive(script))
|
|
383
388
|
}
|
|
384
389
|
|
|
385
390
|
if (checked && pin !== undefined)
|
|
@@ -179,3 +179,18 @@ export function rolesOf(source: string, script: Span | undefined, fence: Span &
|
|
|
179
179
|
|
|
180
180
|
return island.render === 'client' ? { island, client: island.span, pin: undefined } : { island, client: undefined, pin: { kind: island.render, ...island.span } }
|
|
181
181
|
}
|
|
182
|
+
|
|
183
|
+
// `--- script` opening a file: the bare `---` is the same fence, and only a script that follows a named fence needs the word, as there a bare line would close that one.
|
|
184
|
+
export function spelledOutFirstFence(source: string, line: Span | undefined, word: { start: number, end: number, word: string } | undefined): Diagnostic[] {
|
|
185
|
+
if (!line || word?.word !== 'script' || source.slice(0, line.start).trim() !== '')
|
|
186
|
+
return []
|
|
187
|
+
|
|
188
|
+
return [{
|
|
189
|
+
start: line.start,
|
|
190
|
+
end: word.end,
|
|
191
|
+
code: 'fence-invalid',
|
|
192
|
+
message: '`--- script` cannot open a file: the script is written `---`',
|
|
193
|
+
help: '`--- script` is only for a script that follows a `--- server`, `--- module` or `--- style` fence',
|
|
194
|
+
fixes: [{ title: 'Write `---`', safe: true, edits: [{ start: line.start + 3, end: word.end, text: '' }] }],
|
|
195
|
+
}]
|
|
196
|
+
}
|