@kayjs/kay 1.107.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/dist/eslint.js +50 -29
- package/editors/zed/extension.toml +2 -2
- package/llms/actions-from-islands.md +1 -1
- package/llms/component-libraries.md +1 -1
- package/llms/deprecated-lints.md +0 -1
- package/llms/islands.md +1 -1
- package/llms/upgrading.md +6 -0
- package/llms/whats-new-archive.md +36 -1
- package/llms/whats-new.md +9 -39
- package/llms.txt +1 -1
- package/package.json +6 -6
- package/src/build/client.ts +7 -6
- package/src/build/icon-slots.ts +140 -0
- package/src/build/libraries.ts +24 -2
- package/src/build/plugin.ts +10 -0
- package/src/build/runtime-chunk.ts +2 -2
- package/src/build/source-files.ts +8 -3
- package/src/build/variants.ts +90 -1
- package/src/check/project.ts +4 -4
- package/src/check/renamed-packages.ts +3 -63
- package/src/check/shadow-types.ts +4 -18
- package/src/compiler/dead-code.ts +22 -0
- package/src/compiler/deprecated-lints.ts +1 -10
- package/src/compiler/dom-property.ts +23 -0
- package/src/compiler/dom.ts +15 -15
- package/src/package-names.ts +1 -1
- package/src/runtime/action-call.ts +39 -327
- package/src/runtime/action-run.ts +357 -0
- package/types/build/client.d.ts +1 -1
- package/types/build/client.d.ts.map +1 -1
- package/types/build/icon-slots.d.ts +7 -0
- package/types/build/icon-slots.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 +1 -0
- package/types/build/plugin.d.ts.map +1 -1
- package/types/build/source-files.d.ts.map +1 -1
- package/types/build/variants.d.ts.map +1 -1
- package/types/check/renamed-packages.d.ts +0 -3
- package/types/check/renamed-packages.d.ts.map +1 -1
- package/types/check/shadow-types.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.d.ts +0 -9
- 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/lints.d.ts +0 -9
- package/types/compiler/lints.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/src/build/libraries.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Manifest } from './manifests'
|
|
2
2
|
import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs'
|
|
3
3
|
import { isBuiltin } from 'node:module'
|
|
4
|
-
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
4
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path'
|
|
5
5
|
import { KayError } from '../compiler/errors'
|
|
6
6
|
import { parseKay } from '../compiler/parser'
|
|
7
7
|
import { findKayFiles, KAY_FILE, readSource, scoped, SCRIPT_FILE, scriptLoader, transpilerFor } from './files'
|
|
@@ -222,7 +222,28 @@ export function packageRoot(dir: string): string {
|
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
//
|
|
225
|
+
// Whether `path` exists outside the project's own files and is no install: a linked library or a folder above the root, whose real path is outside any `node_modules`.
|
|
226
|
+
export function linkedOutside(root: string, path: string): boolean {
|
|
227
|
+
const own = relative(resolve(root), path)
|
|
228
|
+
|
|
229
|
+
return (own.startsWith('..') || own.split(sep).includes('node_modules')) && existsSync(path) && !realpathSync(path).split(sep).includes('node_modules')
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// 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.
|
|
233
|
+
export async function extensionPackages(root: string, libraries: KayLibrary[], extensionDirs: string[]): Promise<KayLibrary[]> {
|
|
234
|
+
const dirs = new Set(extensionDirs.filter(dir => libraryOf(libraries, join(dir, 'page.kay')) === undefined).map(packageRoot))
|
|
235
|
+
|
|
236
|
+
const realRoot = realpathSync(root)
|
|
237
|
+
|
|
238
|
+
return Promise.all([...dirs].map(async (dir) => {
|
|
239
|
+
// 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.
|
|
240
|
+
const files = (await findKayFiles(dir, { project: true, ownOnly: true, ownKayOnly: true })).filter(file => !realpathSync(file).startsWith(realRoot + sep) && libraryOf(libraries, file) === undefined)
|
|
241
|
+
|
|
242
|
+
return { name: basename(dir), dir, realDir: realpathSync(dir), files, specifiers: new Map<string, string>(), exports: undefined, extension: true as const }
|
|
243
|
+
}))
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Whether the package.json at `manifest` names a package.
|
|
226
247
|
function namesPackage(manifest: string): boolean {
|
|
227
248
|
try {
|
|
228
249
|
return typeof (JSON.parse(readFileSync(manifest, 'utf8')) as { name?: unknown }).name === 'string'
|
|
@@ -232,6 +253,7 @@ function namesPackage(manifest: string): boolean {
|
|
|
232
253
|
}
|
|
233
254
|
}
|
|
234
255
|
|
|
256
|
+
// The library holding `file`, by its path under `node_modules` or its real one: the deepest, for a library installed inside another's `node_modules`.
|
|
235
257
|
export function libraryOf(libraries: KayLibrary[], file: string): KayLibrary | undefined {
|
|
236
258
|
const holding = (dir: string) => file.startsWith(dir + sep) ? dir.length : 0
|
|
237
259
|
|
package/src/build/plugin.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { cacheIds } from './cache-ids'
|
|
|
16
16
|
import { directImports } from './direct-imports'
|
|
17
17
|
import { KAY_MODULE, SCRIPT_FILE, scriptLoader } from './files'
|
|
18
18
|
import { expandGlobs } from './glob'
|
|
19
|
+
import { isUiRegistry, REGISTRY_FILE, registryWith } from './icon-slots'
|
|
19
20
|
import { iconModule, iconNames, installedIconSets } from './icons'
|
|
20
21
|
import { linkedKayCopies, settingsReplacements } from './libraries'
|
|
21
22
|
import { liveIds } from './live-ids'
|
|
@@ -67,6 +68,8 @@ export interface KayPluginOptions {
|
|
|
67
68
|
rewrite?: ((file: string, source: string) => string) | undefined
|
|
68
69
|
// What the build knows of the call sites of its components with features, shared by every bundle of it; one of its own, over the project's files, when unset.
|
|
69
70
|
variants?: VariantIndex | undefined
|
|
71
|
+
// The icon slots of kayjs-ui the islands can draw: its registry loads with these alone. Unset, it loads whole.
|
|
72
|
+
iconSlots?: ReadonlySet<string> | undefined
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
// A static component imports its `?island` twin, the build of it that renders inside islands, as a module of its own.
|
|
@@ -302,6 +305,13 @@ export function kayPlugin(options: KayPluginOptions, workers: string[]): BunPlug
|
|
|
302
305
|
build.onLoad({ filter: new RegExp(`^${RegExp.escape(path)}$`) }, () => ({ contents: `export * from ${JSON.stringify(replacement)}\nexport { default } from ${JSON.stringify(replacement)}\n`, loader: 'ts' }))
|
|
303
306
|
}
|
|
304
307
|
|
|
308
|
+
// After the app's own settings, which stay whole: only kayjs-ui's default registry is cut.
|
|
309
|
+
if (target === 'dom' && options.iconSlots !== undefined) {
|
|
310
|
+
const slots = options.iconSlots
|
|
311
|
+
|
|
312
|
+
build.onLoad({ filter: REGISTRY_FILE }, async ({ path }) => isUiRegistry(path) ? { contents: registryWith(await Bun.file(path).text(), slots), loader: 'ts' } : undefined)
|
|
313
|
+
}
|
|
314
|
+
|
|
305
315
|
// A linked library's own copy of kay loads as the app's: each of its modules re-exports the app's module at the same place, so the library and the app share one kay. A module the app's copy lacks, as another version may, stays the library's.
|
|
306
316
|
for (const { from, to } of linkedKayCopies(root)) {
|
|
307
317
|
build.onLoad({ filter: new RegExp(`^${RegExp.escape(from + sep)}(?!(?:.*[\\\\/])?node_modules[\\\\/]).*\\.[cm]?[jt]sx?$`) }, async ({ path }) => {
|
|
@@ -25,8 +25,8 @@ const DEFAULT_IMPORT = /^[\w$]+\s*(?:,|$)/
|
|
|
25
25
|
const NAMED = /\{([^}]*)\}/
|
|
26
26
|
const ALIAS = /\s+as\s+/
|
|
27
27
|
const KAY_SPECIFIER = /^kay(?:\/|$)/
|
|
28
|
-
// Lazy modules whose imports of the runtime stay with them rather than join the chunk a page loads: the code reviving an action, which only a page passing an island one loads, carries the action runtime along, the code
|
|
29
|
-
const STANDALONE = new Set([resolve(RUNTIME_DIR, 'action-reviver.ts'), resolve(RUNTIME_DIR, 'action-stream.ts'), resolve(RUNTIME_DIR, 'action-
|
|
28
|
+
// Lazy modules whose imports of the runtime stay with them rather than join the chunk a page loads: the code reviving an action, which only a page passing an island one loads, carries the action runtime along, the code running an action call, which the first call loads, and the reader of a streaming action's answer, whose `ended()`, `onData()` and `retry()` a page with no such action does not carry.
|
|
29
|
+
const STANDALONE = new Set([resolve(RUNTIME_DIR, 'action-reviver.ts'), resolve(RUNTIME_DIR, 'action-stream.ts'), resolve(RUNTIME_DIR, 'action-run.ts')])
|
|
30
30
|
// Entries of the runtime that bundle a package, or that few pages use, which stay in the chunks of the islands importing them rather than weigh on every page: the `for`, `await` and `try` blocks, the spread and the localizing of the links an island writes, which most islands do without.
|
|
31
31
|
const OWN_CHUNK = new Set(['kay/markdown', 'kay/internal/title', 'kay/dom-loop', 'kay/dom-await', 'kay/dom-try', 'kay/dom-spread', 'kay/dom-lazy', 'kay/i18n-links'])
|
|
32
32
|
const RELATIVE = /^\.\.?\//
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { KayExtension } from '../config'
|
|
2
2
|
import type { ImportGraph, KayLibrary } from './libraries'
|
|
3
3
|
import { existsSync } from 'node:fs'
|
|
4
|
+
import { dirname } from 'node:path'
|
|
4
5
|
import { extensionEditor, routeMounts } from '../server/routes'
|
|
5
6
|
import { findKayFiles } from './files'
|
|
6
|
-
import { findKayLibraries, reachableLibraryFiles } from './libraries'
|
|
7
|
+
import { extensionPackages, findKayLibraries, linkedOutside, reachableLibraryFiles } from './libraries'
|
|
7
8
|
|
|
8
9
|
export interface BuildFiles {
|
|
9
10
|
// The project's own components, the pages of the libraries it mounts and the components of the libraries it reaches, in that order.
|
|
@@ -22,9 +23,13 @@ export async function buildFiles(root: string, extensions: KayExtension[] | unde
|
|
|
22
23
|
const ownFiles = new Set(own)
|
|
23
24
|
const editor = extensionEditor(root, extensions)
|
|
24
25
|
// The pages of the libraries the app mounts, which it reaches through its config rather than an import.
|
|
25
|
-
const
|
|
26
|
+
const mounts = routeMounts(root, extensions)
|
|
27
|
+
const mountedFiles = (await Promise.all(mounts.map(async mount => existsSync(mount.dir) ? findKayFiles(mount.dir) : []))).flat()
|
|
26
28
|
const mounted = [...new Set([...mountedFiles, ...editor === undefined ? [] : [editor]])].filter(file => !ownFiles.has(file))
|
|
27
|
-
const
|
|
29
|
+
const installed = await findKayLibraries(root)
|
|
30
|
+
// An extension reached with no dependency on it, as a workspace link or a folder above the root, is a library whose islands the pages it wraps still render.
|
|
31
|
+
const mountDirs = mounts.filter(mount => mount.reaching !== 'context' && linkedOutside(root, mount.dir)).map(mount => mount.dir)
|
|
32
|
+
const libraries = [...installed, ...await extensionPackages(root, installed, [...mountDirs, ...editor === undefined || !linkedOutside(root, editor) ? [] : [dirname(editor)]])]
|
|
28
33
|
const fromLibraries = await reachableLibraryFiles(root, libraries, [...own, ...mounted], graph)
|
|
29
34
|
|
|
30
35
|
return { files: [...own, ...mounted, ...fromLibraries.components], own, mounted, editor, libraries, fromLibraries }
|
package/src/build/variants.ts
CHANGED
|
@@ -299,6 +299,95 @@ function splitTop(text: string, operator: '&&' | '||'): string[] | undefined {
|
|
|
299
299
|
return parts
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
+
// The depth-0 positions of `char` in `text`, outside brackets and strings; a `?.` and a `??` are no ternary.
|
|
303
|
+
function topLevel(text: string, char: '?' | ':'): number[] {
|
|
304
|
+
const found: number[] = []
|
|
305
|
+
let depth = 0
|
|
306
|
+
let quote = ''
|
|
307
|
+
|
|
308
|
+
for (let at = 0; at < text.length; at++) {
|
|
309
|
+
const here = text[at]!
|
|
310
|
+
|
|
311
|
+
if (quote !== '') {
|
|
312
|
+
if (here === '\\')
|
|
313
|
+
at++
|
|
314
|
+
else if (here === quote)
|
|
315
|
+
quote = ''
|
|
316
|
+
}
|
|
317
|
+
else if (here === '\'' || here === '"' || here === '`') {
|
|
318
|
+
quote = here
|
|
319
|
+
}
|
|
320
|
+
else if (here === '(' || here === '[' || here === '{') {
|
|
321
|
+
depth++
|
|
322
|
+
}
|
|
323
|
+
else if (here === ')' || here === ']' || here === '}') {
|
|
324
|
+
depth--
|
|
325
|
+
}
|
|
326
|
+
else if (here === char && depth === 0 && (char === ':' || (text[at + 1] !== '.' && text[at + 1] !== '?'))) {
|
|
327
|
+
found.push(at)
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
return found
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// Where the brace opened just before `from` closes, past the strings in between; -1 when it never does, or a template literal holds a `${`, whose nesting is not tracked.
|
|
335
|
+
function closingBrace(text: string, from: number): number {
|
|
336
|
+
let depth = 1
|
|
337
|
+
let quote = ''
|
|
338
|
+
|
|
339
|
+
for (let at = from; at < text.length; at++) {
|
|
340
|
+
const char = text[at]!
|
|
341
|
+
|
|
342
|
+
if (quote !== '') {
|
|
343
|
+
if (char === '\\')
|
|
344
|
+
at++
|
|
345
|
+
else if (quote === '`' && char === '$' && text[at + 1] === '{')
|
|
346
|
+
return -1
|
|
347
|
+
else if (char === quote)
|
|
348
|
+
quote = ''
|
|
349
|
+
}
|
|
350
|
+
else if (char === '\'' || char === '"' || char === '`') {
|
|
351
|
+
quote = char
|
|
352
|
+
}
|
|
353
|
+
else if (char === '{') {
|
|
354
|
+
depth++
|
|
355
|
+
}
|
|
356
|
+
else if (char === '}' && --depth === 0) {
|
|
357
|
+
return at
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
return -1
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// An arrow, an assignment or a comma in a condition binds looser than the ternary, so what comes before the `?` is not the whole test.
|
|
365
|
+
const LOWER_THAN_TERNARY = /=>|,|(?<![=!<>])=(?!=)/
|
|
366
|
+
|
|
367
|
+
// An attribute `name={cond ? value : undefined}` whose condition is false is `{undefined}`, which the compiler leaves unbound. Only a ternary with no other at its top level is read.
|
|
368
|
+
function foldAbsentAttributes(line: string): string {
|
|
369
|
+
let result = line
|
|
370
|
+
let from = 0
|
|
371
|
+
|
|
372
|
+
for (;;) {
|
|
373
|
+
const open = result.indexOf('={', from)
|
|
374
|
+
|
|
375
|
+
if (open === -1)
|
|
376
|
+
return result
|
|
377
|
+
|
|
378
|
+
const start = open + 2
|
|
379
|
+
const end = closingBrace(result, start)
|
|
380
|
+
const inner = result.slice(start, end)
|
|
381
|
+
const question = topLevel(inner, '?')[0]
|
|
382
|
+
const colons = topLevel(inner, ':')
|
|
383
|
+
|
|
384
|
+
from = start
|
|
385
|
+
|
|
386
|
+
if (end !== -1 && question !== undefined && colons.length === 1 && inner.slice(colons[0]! + 1).trim() === 'undefined' && !LOWER_THAN_TERNARY.test(inner.slice(0, question)) && alwaysFalse(inner.slice(0, question)))
|
|
387
|
+
result = `${result.slice(0, start)}undefined${result.slice(end)}`
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
302
391
|
// 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.
|
|
303
392
|
const ABSENT_DEFAULT = / = false(?: \|\| false)* \? wording\([^()]*\) : ''/g
|
|
304
393
|
const DEAD_SPREAD = /^(\s*)\.\.\.\(false(?: \|\| false)*\)\s*$/
|
|
@@ -343,7 +432,7 @@ export function specializedSource(source: string, present: ReadonlySet<string>,
|
|
|
343
432
|
if (hit === null) {
|
|
344
433
|
// A call in an attribute or a text expression is folded as one in the script.
|
|
345
434
|
if (lines[at]!.includes('uses('))
|
|
346
|
-
lines[at] = replaced(lines[at]!)
|
|
435
|
+
lines[at] = foldAbsentAttributes(replaced(lines[at]!))
|
|
347
436
|
|
|
348
437
|
continue
|
|
349
438
|
}
|
package/src/check/project.ts
CHANGED
|
@@ -34,7 +34,7 @@ import { browserModules, islandEdges } from './island-modules'
|
|
|
34
34
|
import { componentImporters, islandOnlyComponents, renderedInIslands } from './island-only'
|
|
35
35
|
import { linkFlagTests } from './link-flag-tests'
|
|
36
36
|
import { FILES_MARKER, stampOf } from './loaded'
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
import { configSeoLints } from './seo'
|
|
39
39
|
import { serverOnlyInIsland } from './server-only-reads'
|
|
40
40
|
import { fromCompile } from './shadow-types'
|
|
@@ -106,13 +106,13 @@ export function configProblems(root: string, options: CheckOptions, types: Shado
|
|
|
106
106
|
// The collections may still be read, which only the feeds and their own problems wait for.
|
|
107
107
|
export async function projectProblems(root: string, options: CheckOptions, collections: ContentChecks | Promise<ContentChecks>, memory?: ProbeMemory, scanned?: ServedProject): Promise<CheckDiagnostic[]> {
|
|
108
108
|
return inWalkScope(async () => {
|
|
109
|
-
const [content, messages, boot, modules,
|
|
109
|
+
const [content, messages, boot, modules, linkTests] = await Promise.all([collections, checkMessages(root, options, memory), (async () => {
|
|
110
110
|
const read = await collections
|
|
111
111
|
|
|
112
112
|
return bootProblems(resolve(root), options, read.feeds, scanned, read.routes)
|
|
113
|
-
})(), moduleLints(root, options),
|
|
113
|
+
})(), moduleLints(root, options), linkFlagTests(root, options.lints)])
|
|
114
114
|
|
|
115
|
-
return [...content.problems, ...messages, ...boot, ...modules, ...
|
|
115
|
+
return [...content.problems, ...messages, ...boot, ...modules, ...linkTests, ...uiProblems(root), ...contextModuleProblems(root)]
|
|
116
116
|
})
|
|
117
117
|
}
|
|
118
118
|
|
|
@@ -1,34 +1,12 @@
|
|
|
1
|
-
import type { CheckDiagnostic } from '.'
|
|
2
|
-
import type { LintLevels } from '../compiler/lints'
|
|
3
1
|
import { writeFile } from 'node:fs/promises'
|
|
4
2
|
import { basename } from 'node:path'
|
|
5
3
|
import { findProjectFiles } from '../build/files'
|
|
6
|
-
|
|
7
|
-
import { OLD_PACKAGE_NAME,
|
|
4
|
+
|
|
5
|
+
import { OLD_PACKAGE_NAME, RENAMED_PACKAGES } from '../package-names'
|
|
8
6
|
|
|
9
7
|
// The files that name a package: the scripts, components and stylesheets of the project, and its manifest and tsconfigs.
|
|
10
8
|
const NAMING_FILE = /^(?:package\.json|tsconfig[\w.-]*\.json)$|\.(?:[cm]?[jt]sx?|kay|css)$/
|
|
11
9
|
|
|
12
|
-
// The version a manifest entry asks of the package: after a key, `"@kaynooo/kayjs-ui": "~1.103.0"`, or after an alias, `npm:@kaynooo/kayjs@~1.103.0`.
|
|
13
|
-
const RANGE_AFTER_KEY = /"\s*:\s*"[~^]?(\d+\.\d+\.\d+)(?=")/y
|
|
14
|
-
const RANGE_AFTER_ALIAS = /@[~^]?(\d+\.\d+\.\d+)(?=")/y
|
|
15
|
-
|
|
16
|
-
// The range's version, when it is below the first one published under the new names, which no version of the new package satisfies: written as that first version, keeping its `~` or `^`.
|
|
17
|
-
function raisedRange(source: string, from: number): { start: number, end: number, text: string } | undefined {
|
|
18
|
-
const pattern = source[from] === '"' ? RANGE_AFTER_KEY : RANGE_AFTER_ALIAS
|
|
19
|
-
|
|
20
|
-
pattern.lastIndex = from
|
|
21
|
-
|
|
22
|
-
const found = pattern.exec(source)
|
|
23
|
-
|
|
24
|
-
if (found === null || Bun.semver.order(found[1]!, RENAMED_IN) !== -1)
|
|
25
|
-
return undefined
|
|
26
|
-
|
|
27
|
-
const start = from + found[0].length - found[1]!.length
|
|
28
|
-
|
|
29
|
-
return { start, end: start + found[1]!.length, text: RENAMED_IN }
|
|
30
|
-
}
|
|
31
|
-
|
|
32
10
|
const BLOCK_COMMENT = /\/\*[\s\S]*?(?:\*\/|$)/g
|
|
33
11
|
|
|
34
12
|
// What a name may follow inside its string: nothing, an alias, or a path through node_modules, as a stylesheet's `@source`.
|
|
@@ -86,7 +64,7 @@ function kindOf(file: string): Kind {
|
|
|
86
64
|
return file.endsWith('.css') ? 'stylesheet' : 'script'
|
|
87
65
|
}
|
|
88
66
|
|
|
89
|
-
// The position of each old package name a file depends on, as
|
|
67
|
+
// The position of each old package name a file depends on, as `kay upgrade` rewrites them.
|
|
90
68
|
export function oldNamesIn(file: string, source: string): RegExpExecArray[] {
|
|
91
69
|
const kind = kindOf(file)
|
|
92
70
|
const comments = kind === 'manifest' || kind === 'tsconfig' ? [] : [...source.matchAll(BLOCK_COMMENT)].map((c): [number, number] => [c.index, c.index + c[0].length])
|
|
@@ -117,41 +95,3 @@ export async function renameProjectFiles(root: string): Promise<void> {
|
|
|
117
95
|
await writeFile(file, renamed + source.slice(from))
|
|
118
96
|
}
|
|
119
97
|
}
|
|
120
|
-
|
|
121
|
-
// kay and its libraries under the `@kaynooo` scope, named as an import, `require` or `import()` specifier, a config key, a stylesheet's `@import` or `@plugin` path or a package.json entry, which are `@kayjs/*` since 1.104: each name found gets a safe fix writing the new one.
|
|
122
|
-
// A package.json that lists the new name already would get the entry twice, so its names are reported with a fix that is not safe; one that does not has the range raised to the first version under the new name.
|
|
123
|
-
export async function renamedPackages(root: string, levels: LintLevels | undefined): Promise<CheckDiagnostic[]> {
|
|
124
|
-
const level = lintLevel('deprecated-package-names', levels)
|
|
125
|
-
|
|
126
|
-
if (level === 'allow')
|
|
127
|
-
return []
|
|
128
|
-
|
|
129
|
-
const found: CheckDiagnostic[] = []
|
|
130
|
-
|
|
131
|
-
for (const file of (await findProjectFiles(root, NAMING_FILE, { project: true, ownKayOnly: true })).sort()) {
|
|
132
|
-
const source = await Bun.file(file).text()
|
|
133
|
-
const manifest = basename(file) === 'package.json'
|
|
134
|
-
|
|
135
|
-
for (const match of oldNamesIn(file, source)) {
|
|
136
|
-
const name = match[0]
|
|
137
|
-
|
|
138
|
-
const next = RENAMED_PACKAGES[name]!
|
|
139
|
-
const before = source.slice(0, match.index).split('\n')
|
|
140
|
-
const raised = manifest ? raisedRange(source, match.index + name.length) : undefined
|
|
141
|
-
|
|
142
|
-
found.push({
|
|
143
|
-
file,
|
|
144
|
-
line: before.length,
|
|
145
|
-
column: before.at(-1)!.length + 1,
|
|
146
|
-
end: match.index + name.length,
|
|
147
|
-
severity: level === 'warn' ? 'warning' : 'error',
|
|
148
|
-
code: 'deprecated-package-names',
|
|
149
|
-
message: `\`${name}\` is \`${next}\` since 1.104: kay and its libraries are published under the \`@kayjs\` scope`,
|
|
150
|
-
help: manifest ? `write \`${next}\` and run \`bun install\`, or run \`kay upgrade\`` : `import from \`${next}\``,
|
|
151
|
-
fixes: [{ title: `write ${next}`, safe: !manifest || !source.includes(`"${next}"`), edits: [{ start: match.index, end: match.index + name.length, text: next }, ...raised === undefined ? [] : [raised]] }],
|
|
152
|
-
})
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return found
|
|
157
|
-
}
|
|
@@ -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'
|
|
@@ -389,7 +389,7 @@ async function libraryShadows(root: string, options: CheckOptions, own: string[]
|
|
|
389
389
|
const { routes: routesDir, cache: cacheDir } = projectPaths(root, options)
|
|
390
390
|
const libraries = await findKayLibraries(root)
|
|
391
391
|
// The app's own directories are checked already; a linked library has its real path outside any `node_modules`, an installed one inside.
|
|
392
|
-
const linked = (path: string) =>
|
|
392
|
+
const linked = (path: string) => linkedOutside(root, path)
|
|
393
393
|
const local = mounts.filter(mount => linked(mount.dir))
|
|
394
394
|
const diagnostics: CheckDiagnostic[] = []
|
|
395
395
|
const editor = editorOf(root, options.extensions, diagnostics)
|
|
@@ -545,20 +545,6 @@ async function linkDependencies(root: string, { dir, realDir }: KayLibrary, own:
|
|
|
545
545
|
}
|
|
546
546
|
}
|
|
547
547
|
|
|
548
|
-
// 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.
|
|
549
|
-
async function extensionPackages(root: string, libraries: KayLibrary[], extensionDirs: string[]): Promise<KayLibrary[]> {
|
|
550
|
-
const dirs = new Set(extensionDirs.filter(dir => libraryOf(libraries, join(dir, 'page.kay')) === undefined).map(packageRoot))
|
|
551
|
-
|
|
552
|
-
const realRoot = realpathSync(root)
|
|
553
|
-
|
|
554
|
-
return Promise.all([...dirs].map(async (dir) => {
|
|
555
|
-
// 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.
|
|
556
|
-
const files = (await findKayFiles(dir, { project: true, ownOnly: true, ownKayOnly: true })).filter(file => !realpathSync(file).startsWith(realRoot + sep) && libraryOf(libraries, file) === undefined)
|
|
557
|
-
|
|
558
|
-
return { name: basename(dir), dir, realDir: realpathSync(dir), files, specifiers: new Map<string, string>(), exports: undefined, extension: true as const }
|
|
559
|
-
}))
|
|
560
|
-
}
|
|
561
|
-
|
|
562
548
|
// The pages, public files, API modules and endpoints, with the locale settings, each with the reason the server would refuse it reported.
|
|
563
549
|
async function servedProject(root: string, options: CheckOptions, problems: CheckDiagnostic[], mounts: RouteMount[]): Promise<ServedProject> {
|
|
564
550
|
const paths = projectPaths(root, options)
|
|
@@ -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
|
+
}
|
|
@@ -34,15 +34,6 @@ export const DEPRECATED_LINTS = {
|
|
|
34
34
|
wrong: '---\nimport Card from \'./card.kay\'\n---\nCard(class={{ head: \'p-6\' }})',
|
|
35
35
|
right: '---\nimport Card from \'./card.kay\'\n---\nCard(parts={{ head: \'p-6\' }})',
|
|
36
36
|
},
|
|
37
|
-
'deprecated-package-names': {
|
|
38
|
-
level: 'warn',
|
|
39
|
-
group: 'deprecated',
|
|
40
|
-
since: '1.104',
|
|
41
|
-
site: true,
|
|
42
|
-
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.',
|
|
43
|
-
wrong: '---\nimport Button from \'@kaynooo/kayjs-ui/button.kay\'\n---\nButton Save',
|
|
44
|
-
right: '---\nimport Button from \'@kayjs/ui/button.kay\'\n---\nButton Save',
|
|
45
|
-
},
|
|
46
37
|
'deprecated-test-helpers': {
|
|
47
38
|
level: 'warn',
|
|
48
39
|
group: 'deprecated',
|
|
@@ -548,7 +539,7 @@ export const DEPRECATION_MINORS: readonly { since: string, removedIn?: string }[
|
|
|
548
539
|
{ since: '1.101', removedIn: '1.105' },
|
|
549
540
|
{ since: '1.102', removedIn: '1.107' },
|
|
550
541
|
{ since: '1.103', removedIn: '1.107' },
|
|
551
|
-
{ since: '1.104' },
|
|
542
|
+
{ since: '1.104', removedIn: '1.108' },
|
|
552
543
|
{ since: '1.105' },
|
|
553
544
|
{ since: '1.106' },
|
|
554
545
|
{ since: '1.107' },
|
|
@@ -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
|
|
package/src/package-names.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// kay and its libraries were published under the `@kaynooo` scope up to 1.103 and are under `@kayjs` since 1.104: the new name of each, which `kay upgrade`
|
|
1
|
+
// kay and its libraries were published under the `@kaynooo` scope up to 1.103 and are under `@kayjs` since 1.104: the new name of each, which `kay upgrade` moves an app to.
|
|
2
2
|
export const RENAMED_PACKAGES: Readonly<Record<string, string>> = {
|
|
3
3
|
'@kaynooo/kayjs': '@kayjs/kay',
|
|
4
4
|
'@kaynooo/kayjs-ai': '@kayjs/ai',
|