zyzz 0.0.6 → 0.0.8
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 +26 -1
- package/dist/Style.d.ts +3 -3
- package/dist/Style.d.ts.map +1 -1
- package/dist/Style.js +12 -1
- package/dist/Style.js.map +1 -1
- package/dist/babel/index.d.ts +4 -1
- package/dist/babel/index.d.ts.map +1 -1
- package/dist/babel/index.js +6 -3
- package/dist/babel/index.js.map +1 -1
- package/dist/babel/internal/Compilation.d.ts +12 -0
- package/dist/babel/internal/Compilation.d.ts.map +1 -0
- package/dist/babel/internal/Compilation.js +3 -0
- package/dist/babel/internal/Compilation.js.map +1 -0
- package/dist/compiler/Graph.d.ts +6 -1
- package/dist/compiler/Graph.d.ts.map +1 -1
- package/dist/compiler/Graph.js +160 -36
- package/dist/compiler/Graph.js.map +1 -1
- package/dist/compiler/Transform.d.ts.map +1 -1
- package/dist/compiler/Transform.js +2 -1
- package/dist/compiler/Transform.js.map +1 -1
- package/dist/compiler/internal/Stylesheets.d.ts +8 -0
- package/dist/compiler/internal/Stylesheets.d.ts.map +1 -1
- package/dist/compiler/internal/Stylesheets.js +4 -0
- package/dist/compiler/internal/Stylesheets.js.map +1 -1
- package/dist/internal/Authoring.d.ts.map +1 -1
- package/dist/internal/Authoring.js +14 -0
- package/dist/internal/Authoring.js.map +1 -1
- package/dist/internal/Binding.d.ts +7 -0
- package/dist/internal/Binding.d.ts.map +1 -1
- package/dist/internal/Binding.js.map +1 -1
- package/dist/internal/Configuration.d.ts +1 -1
- package/dist/internal/Configuration.d.ts.map +1 -1
- package/dist/internal/Configuration.js +7 -6
- package/dist/internal/Configuration.js.map +1 -1
- package/dist/internal/Theme.d.ts +1 -1
- package/dist/internal/Theme.d.ts.map +1 -1
- package/dist/internal/Theme.js.map +1 -1
- package/dist/internal/Token.d.ts +3 -1
- package/dist/internal/Token.d.ts.map +1 -1
- package/dist/internal/Token.js +28 -3
- package/dist/internal/Token.js.map +1 -1
- package/dist/internal/Value.d.ts +22 -0
- package/dist/internal/Value.d.ts.map +1 -1
- package/dist/internal/Value.js +76 -9
- package/dist/internal/Value.js.map +1 -1
- package/dist/metro/Graph.d.ts +9 -1
- package/dist/metro/Graph.d.ts.map +1 -1
- package/dist/metro/Graph.js +5 -4
- package/dist/metro/Graph.js.map +1 -1
- package/dist/metro/transformer.d.ts +0 -1
- package/dist/metro/transformer.d.ts.map +1 -1
- package/dist/metro/transformer.js +19 -1
- package/dist/metro/transformer.js.map +1 -1
- package/dist/next/index.d.ts +3 -3
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +25 -30
- package/dist/next/index.js.map +1 -1
- package/dist/next/internal/Project.d.ts +28 -0
- package/dist/next/internal/Project.d.ts.map +1 -0
- package/dist/next/internal/Project.js +295 -0
- package/dist/next/internal/Project.js.map +1 -0
- package/dist/next/loader.d.ts +5 -6
- package/dist/next/loader.d.ts.map +1 -1
- package/dist/next/loader.js +161 -247
- package/dist/next/loader.js.map +1 -1
- package/dist/node/Host.d.ts.map +1 -1
- package/dist/node/Host.js +11 -3
- package/dist/node/Host.js.map +1 -1
- package/dist/node/internal/Snapshot.d.ts +12 -0
- package/dist/node/internal/Snapshot.d.ts.map +1 -0
- package/dist/node/internal/Snapshot.js +74 -0
- package/dist/node/internal/Snapshot.js.map +1 -0
- package/dist/unplugin/index.d.ts.map +1 -1
- package/dist/unplugin/index.js +10 -5
- package/dist/unplugin/index.js.map +1 -1
- package/dist/variants.d.ts +1 -1
- package/dist/variants.d.ts.map +1 -1
- package/dist/variants.js.map +1 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +19 -4
- package/dist/vite/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Style.ts +42 -8
- package/src/babel/index.ts +10 -4
- package/src/babel/internal/Compilation.ts +13 -0
- package/src/compiler/Graph.ts +213 -47
- package/src/compiler/Transform.ts +2 -1
- package/src/compiler/internal/Stylesheets.ts +9 -0
- package/src/internal/Authoring.ts +21 -0
- package/src/internal/Binding.ts +30 -0
- package/src/internal/Configuration.ts +19 -13
- package/src/internal/Theme.ts +5 -1
- package/src/internal/Token.ts +34 -3
- package/src/internal/Value.ts +180 -10
- package/src/metro/Graph.ts +5 -3
- package/src/metro/transformer.ts +26 -1
- package/src/next/index.ts +26 -31
- package/src/next/internal/Project.ts +378 -0
- package/src/next/loader.ts +195 -315
- package/src/node/Host.ts +15 -3
- package/src/node/internal/Snapshot.ts +79 -0
- package/src/unplugin/index.ts +10 -5
- package/src/variants.ts +1 -0
- package/src/vite/index.ts +24 -4
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Retains unchanged source text and syntax within an adapter instance. @module */
|
|
2
|
+
import * as Fs from 'node:fs'
|
|
3
|
+
import * as Syntax from '../../compiler/internal/Syntax.js'
|
|
4
|
+
|
|
5
|
+
/** Creates a source cache; resolution and directory discovery remain owned by the host. */
|
|
6
|
+
export function create() {
|
|
7
|
+
const files = new Map<string, { source: string; version: string }>()
|
|
8
|
+
const syntax = new Map<
|
|
9
|
+
string,
|
|
10
|
+
{ parsed: ReturnType<typeof Syntax.parse>; source: string }
|
|
11
|
+
>()
|
|
12
|
+
|
|
13
|
+
function parse(options: Syntax.parse.Options) {
|
|
14
|
+
let entry = syntax.get(options.moduleId)
|
|
15
|
+
if (entry?.source !== options.source) {
|
|
16
|
+
entry = { parsed: Syntax.parse(options), source: options.source }
|
|
17
|
+
syntax.set(options.moduleId, entry)
|
|
18
|
+
}
|
|
19
|
+
return entry.parsed
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
clear() {
|
|
24
|
+
files.clear()
|
|
25
|
+
syntax.clear()
|
|
26
|
+
},
|
|
27
|
+
delete(file: string, moduleId: string) {
|
|
28
|
+
files.delete(file)
|
|
29
|
+
syntax.delete(moduleId)
|
|
30
|
+
},
|
|
31
|
+
parse,
|
|
32
|
+
programs(modules: Readonly<Record<string, string>>) {
|
|
33
|
+
return new Map(
|
|
34
|
+
Object.entries(modules).map(([moduleId, source]) => [
|
|
35
|
+
moduleId,
|
|
36
|
+
parse({ moduleId, source }),
|
|
37
|
+
]),
|
|
38
|
+
)
|
|
39
|
+
},
|
|
40
|
+
async read(file: string) {
|
|
41
|
+
try {
|
|
42
|
+
const stat = await Fs.promises.stat(file, { bigint: true })
|
|
43
|
+
const version = `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`
|
|
44
|
+
let entry = files.get(file)
|
|
45
|
+
if (entry?.version !== version) {
|
|
46
|
+
entry = { source: await Fs.promises.readFile(file, 'utf8'), version }
|
|
47
|
+
files.set(file, entry)
|
|
48
|
+
}
|
|
49
|
+
return entry.source
|
|
50
|
+
} catch (error) {
|
|
51
|
+
files.delete(file)
|
|
52
|
+
throw error
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
readSync(file: string) {
|
|
56
|
+
try {
|
|
57
|
+
const stat = Fs.statSync(file, { bigint: true })
|
|
58
|
+
const version = `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}`
|
|
59
|
+
let entry = files.get(file)
|
|
60
|
+
if (entry?.version !== version) {
|
|
61
|
+
entry = { source: Fs.readFileSync(file, 'utf8'), version }
|
|
62
|
+
files.set(file, entry)
|
|
63
|
+
}
|
|
64
|
+
return entry.source
|
|
65
|
+
} catch (error) {
|
|
66
|
+
files.delete(file)
|
|
67
|
+
throw error
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
retain(
|
|
71
|
+
paths: ReadonlySet<string>,
|
|
72
|
+
modules: Readonly<Record<string, string>>,
|
|
73
|
+
) {
|
|
74
|
+
for (const file of files.keys()) if (!paths.has(file)) files.delete(file)
|
|
75
|
+
for (const id of syntax.keys())
|
|
76
|
+
if (!Object.hasOwn(modules, id)) syntax.delete(id)
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
}
|
package/src/unplugin/index.ts
CHANGED
|
@@ -4,7 +4,8 @@ import * as Crypto from 'node:crypto'
|
|
|
4
4
|
import * as Fs from 'node:fs/promises'
|
|
5
5
|
import * as Path from 'node:path'
|
|
6
6
|
import * as Reset from '../node/Reset.js'
|
|
7
|
-
import * as
|
|
7
|
+
import * as Snapshot from '../node/internal/Snapshot.js'
|
|
8
|
+
import * as Syntax from '../compiler/internal/Syntax.js'
|
|
8
9
|
import { createUnplugin } from 'unplugin'
|
|
9
10
|
import type { UnpluginBuildContext } from 'unplugin'
|
|
10
11
|
import * as Graph from '../compiler/Graph.js'
|
|
@@ -30,6 +31,7 @@ const portable = createUnplugin<Options | undefined, false>(
|
|
|
30
31
|
(options = {}, meta) => {
|
|
31
32
|
const root = Path.resolve(options.root ?? process.cwd())
|
|
32
33
|
const compiler = Graph.create()
|
|
34
|
+
const snapshot = Snapshot.create()
|
|
33
35
|
let graph: Graph.compile.ReturnType | undefined
|
|
34
36
|
let pending: Promise<void> | undefined
|
|
35
37
|
let files = new Set<string>()
|
|
@@ -138,7 +140,7 @@ const portable = createUnplugin<Options | undefined, false>(
|
|
|
138
140
|
sourcePattern.test(file) &&
|
|
139
141
|
!excludedPattern.test(file)
|
|
140
142
|
) {
|
|
141
|
-
const source = await
|
|
143
|
+
const source = await snapshot.read(file)
|
|
142
144
|
|
|
143
145
|
files.add(file)
|
|
144
146
|
sources.set(file, source)
|
|
@@ -205,7 +207,7 @@ const portable = createUnplugin<Options | undefined, false>(
|
|
|
205
207
|
|
|
206
208
|
files.add(sidecar)
|
|
207
209
|
try {
|
|
208
|
-
contracts[file] = await
|
|
210
|
+
contracts[file] = await snapshot.read(sidecar)
|
|
209
211
|
} catch (error) {
|
|
210
212
|
if (
|
|
211
213
|
!required &&
|
|
@@ -235,8 +237,9 @@ const portable = createUnplugin<Options | undefined, false>(
|
|
|
235
237
|
await scan(root)
|
|
236
238
|
for (const [file, source] of sources) {
|
|
237
239
|
const links = (imports[identity(file)] = Object.create(null))
|
|
238
|
-
for (const node of
|
|
239
|
-
|
|
240
|
+
for (const node of snapshot.parse({
|
|
241
|
+
moduleId: identity(file),
|
|
242
|
+
source,
|
|
240
243
|
}).program.body) {
|
|
241
244
|
if (
|
|
242
245
|
(node.type !== 'ImportDeclaration' &&
|
|
@@ -282,6 +285,7 @@ const portable = createUnplugin<Options | undefined, false>(
|
|
|
282
285
|
}
|
|
283
286
|
|
|
284
287
|
const result = compiler.compile({
|
|
288
|
+
[Syntax.cache]: snapshot.programs(modules),
|
|
285
289
|
compiler: options.compiler,
|
|
286
290
|
reset: options.reset ? Reset.read() : undefined,
|
|
287
291
|
contracts,
|
|
@@ -500,6 +504,7 @@ const portable = createUnplugin<Options | undefined, false>(
|
|
|
500
504
|
Catalogs.read,
|
|
501
505
|
),
|
|
502
506
|
).join('\n')
|
|
507
|
+
snapshot.retain(files, modules)
|
|
503
508
|
graph = result
|
|
504
509
|
if (meta.framework === 'webpack') emit(this)
|
|
505
510
|
if (meta.framework === 'rollup')
|
package/src/variants.ts
CHANGED
|
@@ -51,6 +51,7 @@ type CheckedChoice<
|
|
|
51
51
|
values: values,
|
|
52
52
|
) => CheckedStyles<body, tokens, layers, mappings> &
|
|
53
53
|
Binding.Checked<body> &
|
|
54
|
+
Binding.TokenSlots<body, values, tokens, mappings> &
|
|
54
55
|
(string extends keyof values
|
|
55
56
|
? never
|
|
56
57
|
: values extends Record<string, string | number> &
|
package/src/vite/index.ts
CHANGED
|
@@ -14,6 +14,8 @@ import * as Reset from '../node/Reset.js'
|
|
|
14
14
|
import { isBuiltin } from 'node:module'
|
|
15
15
|
import * as Parser from 'oxc-parser'
|
|
16
16
|
import * as Walker from 'oxc-walker'
|
|
17
|
+
import * as Snapshot from '../node/internal/Snapshot.js'
|
|
18
|
+
import * as Syntax from '../compiler/internal/Syntax.js'
|
|
17
19
|
import * as Scope from '../compiler/internal/Scope.js'
|
|
18
20
|
import type { Environment, Plugin, Rollup, ViteDevServer } from 'vite'
|
|
19
21
|
import * as Graph from '../compiler/Graph.js'
|
|
@@ -40,6 +42,10 @@ export function zyzz(options: zyzz.Options = {}): Plugin {
|
|
|
40
42
|
if (native && options.compiler === false)
|
|
41
43
|
throw new Error('Native builds require source compilation.')
|
|
42
44
|
|
|
45
|
+
const snapshots = new WeakMap<
|
|
46
|
+
Environment,
|
|
47
|
+
ReturnType<typeof Snapshot.create>
|
|
48
|
+
>()
|
|
43
49
|
const states = new WeakMap<Environment, Map<string, Entry>>()
|
|
44
50
|
const discoveries = new WeakMap<Environment, Promise<Map<string, string>>>()
|
|
45
51
|
const contributionFiles = new WeakMap<Environment, Set<string>>()
|
|
@@ -51,6 +57,15 @@ export function zyzz(options: zyzz.Options = {}): Plugin {
|
|
|
51
57
|
const sourceEntrypoints = new Set<string>()
|
|
52
58
|
let root: string
|
|
53
59
|
|
|
60
|
+
function snapshot(environment: Environment) {
|
|
61
|
+
let value = snapshots.get(environment)
|
|
62
|
+
if (!value) {
|
|
63
|
+
value = Snapshot.create()
|
|
64
|
+
snapshots.set(environment, value)
|
|
65
|
+
}
|
|
66
|
+
return value
|
|
67
|
+
}
|
|
68
|
+
|
|
54
69
|
function entries(environment: Environment) {
|
|
55
70
|
let state = states.get(environment)
|
|
56
71
|
|
|
@@ -273,7 +288,10 @@ export function zyzz(options: zyzz.Options = {}): Plugin {
|
|
|
273
288
|
file: string,
|
|
274
289
|
event: string,
|
|
275
290
|
) {
|
|
276
|
-
if (event === 'delete')
|
|
291
|
+
if (event === 'delete') {
|
|
292
|
+
entries(environment).delete(file)
|
|
293
|
+
snapshot(environment).delete(file, sourceId(file))
|
|
294
|
+
}
|
|
277
295
|
|
|
278
296
|
const pending = discoveries.get(environment)
|
|
279
297
|
if (!pending || !eager(file)) return
|
|
@@ -330,7 +348,7 @@ export function zyzz(options: zyzz.Options = {}): Plugin {
|
|
|
330
348
|
host.watch(file)
|
|
331
349
|
|
|
332
350
|
const id = sourceId(file)
|
|
333
|
-
const text = source ?? (await
|
|
351
|
+
const text = source ?? (await snapshot(entry.environment).read(file))
|
|
334
352
|
|
|
335
353
|
modules[id] = text
|
|
336
354
|
|
|
@@ -338,8 +356,9 @@ export function zyzz(options: zyzz.Options = {}): Plugin {
|
|
|
338
356
|
|
|
339
357
|
imports[id] = resolutions
|
|
340
358
|
|
|
341
|
-
const parsed =
|
|
342
|
-
|
|
359
|
+
const parsed = snapshot(entry.environment).parse({
|
|
360
|
+
moduleId: id,
|
|
361
|
+
source: text,
|
|
343
362
|
})
|
|
344
363
|
|
|
345
364
|
for (const node of parsed.program.body) {
|
|
@@ -642,6 +661,7 @@ export function zyzz(options: zyzz.Options = {}): Plugin {
|
|
|
642
661
|
)
|
|
643
662
|
|
|
644
663
|
const result = entry.compiler.compile({
|
|
664
|
+
[Syntax.cache]: snapshot(entry.environment).programs(modules),
|
|
645
665
|
compiler: options.compiler,
|
|
646
666
|
reset: options.reset ? Reset.read() : undefined,
|
|
647
667
|
native,
|