@jk2908/cxx 0.2.6 → 0.3.3
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 +18 -2
- package/dist/build.d.ts +22 -11
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +242 -73
- package/dist/build.js.map +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/index.js.map +3 -3
- package/dist/logger.d.ts +0 -2
- package/dist/logger.d.ts.map +1 -1
- package/dist/next/cxx-loader.cjs +287 -146
- package/dist/next/cxx-loader.cjs.map +7 -7
- package/dist/next/index.d.ts +34 -9
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +338 -142
- package/dist/next/index.js.map +5 -5
- package/dist/types.d.ts +5 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +16 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/vite/index.d.ts +4 -3
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +336 -139
- package/dist/vite/index.js.map +6 -6
- package/package.json +85 -81
- package/src/build.ts +312 -108
- package/src/index.ts +26 -9
- package/src/logger.ts +5 -13
- package/src/next/cxx-loader.js +9 -6
- package/src/next/index.ts +152 -100
- package/src/types.ts +5 -8
- package/src/utils.ts +81 -8
- package/src/vite/index.ts +141 -89
package/README.md
CHANGED
|
@@ -92,7 +92,23 @@ const nextConfig = {}
|
|
|
92
92
|
export default withCxx(nextConfig, { typeSuffix: 'Classes' })
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
Use the Next integration when you want `cxx` transforms and generated class-key types inside a Next app.
|
|
95
|
+
Use the Next integration when you want `cxx` transforms and generated class-key types inside a Next app.
|
|
96
|
+
|
|
97
|
+
## Watch options
|
|
98
|
+
|
|
99
|
+
`watch.root` sets the tree used for type-regeneration watching. It defaults to the Vite root, and to the Turbopack root in Next (falling back to `process.cwd()`).
|
|
100
|
+
|
|
101
|
+
`watch.ignore` adds extra globs on top of the built-in ignores (`node_modules`, `.next`, `.cxx`, `.git`). In Next they are added to the cxx watcher. In Vite they only stop cxx from regenerating types for matching files; use Vite's own `server.watch.ignored` to reduce what Vite watches, since that also affects HMR.
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
export default withCxx(nextConfig, {
|
|
105
|
+
typeSuffix: 'Classes',
|
|
106
|
+
watch: {
|
|
107
|
+
root: '../../',
|
|
108
|
+
ignore: ['**/*.stories.tsx'],
|
|
109
|
+
},
|
|
110
|
+
})
|
|
111
|
+
```
|
|
96
112
|
|
|
97
113
|
See [CHANGELOG.md](./CHANGELOG.md) for release notes.
|
|
98
114
|
|
|
@@ -102,4 +118,4 @@ The [`vscode-cxx`](https://github.com/jk2908/cxx/tree/main/packages/vscode-cxx)
|
|
|
102
118
|
|
|
103
119
|
## License
|
|
104
120
|
|
|
105
|
-
MIT
|
|
121
|
+
MIT
|
package/dist/build.d.ts
CHANGED
|
@@ -1,37 +1,48 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type SourceMap } from 'magic-string';
|
|
2
|
+
import type { PluginConfig, Tags } from './types.js';
|
|
2
3
|
/**
|
|
3
4
|
* Returns whether the error was caused by a missing file or directory.
|
|
4
5
|
*/
|
|
5
6
|
export declare function isENOENT(err: unknown): boolean;
|
|
6
7
|
/**
|
|
7
|
-
* Write a file only if the content
|
|
8
|
+
* Write a file only if the content differs from what is already on disk, so watchers are not woken
|
|
9
|
+
* by a needless mtime change.
|
|
8
10
|
*/
|
|
9
11
|
export declare function maybeWrite(filePath: string, content: string): Promise<boolean>;
|
|
10
12
|
export declare class DuplicateTagError extends Error {
|
|
11
13
|
name: string;
|
|
12
14
|
constructor(tag: string);
|
|
13
15
|
}
|
|
16
|
+
export declare class InvalidTagError extends Error {
|
|
17
|
+
name: string;
|
|
18
|
+
constructor(tag: string);
|
|
19
|
+
}
|
|
14
20
|
/**
|
|
15
21
|
* Transform `cxx` templates in one source file and collect any exported tag types.
|
|
16
22
|
*/
|
|
17
23
|
export declare function collect(source: string, id: string, config: PluginConfig): {
|
|
18
24
|
source: string;
|
|
25
|
+
config: string;
|
|
19
26
|
template: string;
|
|
20
27
|
tags: Tags;
|
|
21
|
-
|
|
22
|
-
template: string;
|
|
23
|
-
tags: Tags;
|
|
28
|
+
map: SourceMap | null;
|
|
24
29
|
};
|
|
25
30
|
/**
|
|
26
|
-
*
|
|
31
|
+
* Persist one file's tags to its own partial, then rebuild the shared types soon. Rebuilding is
|
|
32
|
+
* debounced and serialised, so a large build does not re-read every partial per file.
|
|
27
33
|
*/
|
|
28
|
-
export declare function
|
|
34
|
+
export declare function writeTypesForFile(filePath: string, tags: Tags): Promise<void>;
|
|
29
35
|
/**
|
|
30
|
-
*
|
|
36
|
+
* Rebuild `index.d.ts` from every partial now. If another writer touches a partial mid-rebuild,
|
|
37
|
+
* rebuild once more so the final write reflects every partial. Bounded to avoid spinning.
|
|
31
38
|
*/
|
|
32
|
-
export declare function
|
|
39
|
+
export declare function flushTypes(): Promise<void>;
|
|
33
40
|
/**
|
|
34
|
-
*
|
|
41
|
+
* Return and clear any error from a background rebuild, so a caller can fail loudly.
|
|
35
42
|
*/
|
|
36
|
-
export declare function
|
|
43
|
+
export declare function takeRebuildError(): unknown;
|
|
44
|
+
/**
|
|
45
|
+
* Render collected tags as a module augmentation for the package entrypoint.
|
|
46
|
+
*/
|
|
47
|
+
export declare function tagsToType(tags: Tags): string;
|
|
37
48
|
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAKA,OAAoB,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAA;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AA4BpD;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,WAEpC;AAqCD;;;GAGG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,oBAUjE;AAiBD,qBAAa,iBAAkB,SAAQ,KAAK;IAC3C,IAAI,SAAsB;gBAEd,GAAG,EAAE,MAAM;CAGvB;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACzC,IAAI,SAAoB;gBAEZ,GAAG,EAAE,MAAM;CAMvB;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY;YA5G/D,MAAM;YACN,MAAM;cACJ,MAAM;UACV,IAAI;SACL,SAAS,GAAG,IAAI;EAkMrB;AA0GD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,iBAiB7D;AAaD;;;GAGG;AACH,wBAAgB,UAAU,kBAkBzB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,YAI/B;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,UAepC"}
|
package/dist/build.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
+
|
|
1
4
|
// src/build.ts
|
|
2
5
|
import { createHash } from "node:crypto";
|
|
3
6
|
import fs from "node:fs/promises";
|
|
4
7
|
import path from "node:path";
|
|
5
8
|
import { transform } from "lightningcss";
|
|
9
|
+
import MagicString from "magic-string";
|
|
6
10
|
|
|
7
11
|
// src/config.ts
|
|
8
12
|
var NAME = "cxx";
|
|
@@ -52,45 +56,93 @@ function capitalise(str) {
|
|
|
52
56
|
function pascalise(str) {
|
|
53
57
|
return str.split(/[ _-]+/).map(capitalise).join("");
|
|
54
58
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
function createBatcher(wait, flush) {
|
|
60
|
+
const pending = new Map;
|
|
61
|
+
let timer = null;
|
|
62
|
+
let current = null;
|
|
63
|
+
function drain() {
|
|
64
|
+
if (current)
|
|
65
|
+
return current;
|
|
66
|
+
const run = (async () => {
|
|
67
|
+
while (pending.size > 0) {
|
|
68
|
+
const batch = new Map(pending);
|
|
69
|
+
pending.clear();
|
|
70
|
+
await flush(batch);
|
|
71
|
+
}
|
|
72
|
+
})();
|
|
73
|
+
current = run;
|
|
74
|
+
run.then(() => {
|
|
75
|
+
if (current === run)
|
|
76
|
+
current = null;
|
|
77
|
+
}, () => {
|
|
78
|
+
if (current === run)
|
|
79
|
+
current = null;
|
|
80
|
+
});
|
|
81
|
+
return run;
|
|
82
|
+
}
|
|
83
|
+
function schedule() {
|
|
84
|
+
if (timer)
|
|
85
|
+
clearTimeout(timer);
|
|
86
|
+
timer = setTimeout(() => {
|
|
87
|
+
timer = null;
|
|
88
|
+
drain().catch(() => {});
|
|
63
89
|
}, wait);
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
add(key, value) {
|
|
93
|
+
pending.set(key, value);
|
|
94
|
+
schedule();
|
|
95
|
+
},
|
|
96
|
+
flush() {
|
|
97
|
+
if (timer) {
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
timer = null;
|
|
100
|
+
}
|
|
101
|
+
return drain();
|
|
102
|
+
}
|
|
64
103
|
};
|
|
65
104
|
}
|
|
66
105
|
|
|
67
106
|
// src/build.ts
|
|
107
|
+
var decoder = new TextDecoder;
|
|
108
|
+
var encoder = new TextEncoder;
|
|
68
109
|
var collectCache = new LruCache;
|
|
69
|
-
var
|
|
110
|
+
var writeChain = Promise.resolve();
|
|
70
111
|
function isENOENT(err) {
|
|
71
112
|
return err instanceof Error && "code" in err && err.code === "ENOENT";
|
|
72
113
|
}
|
|
73
|
-
async function
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
114
|
+
async function writeFileAtomic(filePath, content) {
|
|
115
|
+
const tmp = `${filePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
116
|
+
await fs.writeFile(tmp, content);
|
|
117
|
+
try {
|
|
118
|
+
await fs.rename(tmp, filePath);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
await fs.rm(tmp, { force: true });
|
|
121
|
+
throw err;
|
|
79
122
|
}
|
|
123
|
+
}
|
|
124
|
+
function enqueueWrite(task) {
|
|
125
|
+
const run = writeChain.then(task, task);
|
|
126
|
+
writeChain = run.then(() => {
|
|
127
|
+
return;
|
|
128
|
+
}, () => {
|
|
129
|
+
return;
|
|
130
|
+
});
|
|
131
|
+
return run;
|
|
132
|
+
}
|
|
133
|
+
async function maybeWrite(filePath, content) {
|
|
80
134
|
try {
|
|
81
|
-
if (await fs.readFile(filePath, "utf-8") === content)
|
|
82
|
-
fileCache.set(filePath, content);
|
|
135
|
+
if (await fs.readFile(filePath, "utf-8") === content)
|
|
83
136
|
return false;
|
|
84
|
-
}
|
|
85
137
|
} catch (err) {
|
|
86
138
|
if (!isENOENT(err))
|
|
87
139
|
throw err;
|
|
88
140
|
}
|
|
89
|
-
await
|
|
90
|
-
fileCache.set(filePath, content);
|
|
141
|
+
await writeFileAtomic(filePath, content);
|
|
91
142
|
return true;
|
|
92
143
|
}
|
|
93
|
-
var regex = /(?:const|var|let)\s*\[(\w
|
|
144
|
+
var regex = /((?:export\s+)?)(?:const|var|let)\s*\[(\w*)\s*,?\s*(\w*)\s*,?\s*(\w*)\s*\]\s*=\s*cxx(?:\s*`([\s\S]*?)`|\s*\.\s*tag(?:\s*<[^>]+>)?\s*\(\s*(['"])(.*?)\6\s*\)\s*`([\s\S]*?)`)/gm;
|
|
145
|
+
var IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
94
146
|
function hashCss(code) {
|
|
95
147
|
return `cxx-${createHash("sha256").update(code).digest("base64url").slice(0, 12)}`;
|
|
96
148
|
}
|
|
@@ -101,73 +153,137 @@ class DuplicateTagError extends Error {
|
|
|
101
153
|
super(`Tag ${tag} has already been seen. Tags must be unique across your application`);
|
|
102
154
|
}
|
|
103
155
|
}
|
|
156
|
+
|
|
157
|
+
class InvalidTagError extends Error {
|
|
158
|
+
name = "InvalidTagError";
|
|
159
|
+
constructor(tag) {
|
|
160
|
+
super(`Tag "${tag}" does not map to a valid TypeScript identifier. ` + `Use letters, numbers, spaces, "_" or "-"`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
104
163
|
function collect(source, id, config) {
|
|
105
|
-
const
|
|
164
|
+
const configKey = JSON.stringify(config);
|
|
106
165
|
const cached = collectCache.get(id);
|
|
107
|
-
if (cached?.source === source)
|
|
166
|
+
if (cached?.source === source && cached.config === configKey)
|
|
108
167
|
return cached;
|
|
109
|
-
const
|
|
168
|
+
const tags = new Map;
|
|
169
|
+
const magic = new MagicString(source);
|
|
170
|
+
let matched = false;
|
|
171
|
+
regex.lastIndex = 0;
|
|
172
|
+
let match;
|
|
173
|
+
while (match = regex.exec(source)) {
|
|
174
|
+
matched = true;
|
|
175
|
+
const [, exp, varOne, varTwo, varThree, plainCss, , tag, taggedCss] = match;
|
|
110
176
|
const css = plainCss ?? taggedCss;
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
177
|
+
const matchIndex = match.index;
|
|
178
|
+
const { code, exports: classExports = {} } = (() => {
|
|
179
|
+
try {
|
|
180
|
+
return transform({
|
|
181
|
+
minify: true,
|
|
182
|
+
cssModules: true,
|
|
183
|
+
filename: id,
|
|
184
|
+
code: encoder.encode(css)
|
|
185
|
+
});
|
|
186
|
+
} catch (err) {
|
|
187
|
+
const line = source.slice(0, matchIndex).split(`
|
|
188
|
+
`).length;
|
|
189
|
+
throw new Error(`Failed to compile cxx CSS at ${id}:${line}`, { cause: err });
|
|
190
|
+
}
|
|
191
|
+
})();
|
|
117
192
|
const href = hashCss(code);
|
|
118
|
-
const styles = Object.fromEntries(Object.entries(
|
|
193
|
+
const styles = Object.fromEntries(Object.entries(classExports).map(([k, v]) => [k, v.name]));
|
|
119
194
|
if (tag) {
|
|
120
195
|
const suffix = typeof config.typeSuffix === "string" ? config.typeSuffix : config.typeSuffix === false ? "" : "Classes";
|
|
121
196
|
const tagWithSuffix = pascalise(`${tag}${suffix}`);
|
|
197
|
+
if (!IDENTIFIER.test(tagWithSuffix))
|
|
198
|
+
throw new InvalidTagError(tag);
|
|
122
199
|
if (tags.has(tagWithSuffix))
|
|
123
200
|
throw new DuplicateTagError(tagWithSuffix);
|
|
124
201
|
tags.set(tagWithSuffix, Object.keys(styles));
|
|
125
202
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
203
|
+
const statements = [];
|
|
204
|
+
if (varOne) {
|
|
205
|
+
statements.push(`${exp}const ${varOne} = ${JSON.stringify(decoder.decode(code))}`);
|
|
206
|
+
}
|
|
207
|
+
if (varTwo) {
|
|
208
|
+
statements.push(`${exp}const ${varTwo} = ${JSON.stringify(styles)}`);
|
|
209
|
+
}
|
|
210
|
+
if (varThree) {
|
|
211
|
+
statements.push(`${exp}const ${varThree} = ${JSON.stringify(href)}`);
|
|
212
|
+
}
|
|
213
|
+
magic.overwrite(matchIndex, matchIndex + match[0].length, statements.join(`
|
|
214
|
+
`));
|
|
215
|
+
}
|
|
216
|
+
const template = magic.toString();
|
|
217
|
+
const map = matched ? magic.generateMap({ source: id, includeContent: true, hires: true }) : null;
|
|
218
|
+
const result = { source, config: configKey, template, tags, map };
|
|
219
|
+
collectCache.set(id, result);
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
function renderTypes(tags) {
|
|
223
|
+
return [
|
|
224
|
+
AUTOGEN_MSG,
|
|
225
|
+
"",
|
|
226
|
+
`import '${PKG_NAME}'`,
|
|
227
|
+
"",
|
|
228
|
+
`declare module '${PKG_NAME}' {`,
|
|
229
|
+
tagsToType(tags),
|
|
230
|
+
"}",
|
|
231
|
+
""
|
|
232
|
+
].join(`
|
|
131
233
|
`);
|
|
132
|
-
});
|
|
133
|
-
collectCache.set(id, { source, template, tags });
|
|
134
|
-
return {
|
|
135
|
-
template,
|
|
136
|
-
tags
|
|
137
|
-
};
|
|
138
234
|
}
|
|
139
|
-
async function
|
|
235
|
+
async function writeRenderedTypes(tags) {
|
|
140
236
|
const filePath = path.join(GENERATED_DIR, "index.d.ts");
|
|
141
237
|
if (!tags.size) {
|
|
142
|
-
|
|
143
|
-
await fs.rm(filePath, { force: true });
|
|
144
|
-
fileCache.delete(filePath);
|
|
145
|
-
} catch (err) {
|
|
146
|
-
if (!isENOENT(err))
|
|
147
|
-
throw err;
|
|
148
|
-
}
|
|
238
|
+
await fs.rm(filePath, { force: true });
|
|
149
239
|
return;
|
|
150
240
|
}
|
|
151
241
|
await fs.mkdir(GENERATED_DIR, { recursive: true });
|
|
152
|
-
await maybeWrite(filePath,
|
|
153
|
-
|
|
154
|
-
import '${PKG_NAME}'
|
|
155
|
-
|
|
156
|
-
declare module '${PKG_NAME}' {
|
|
157
|
-
${tagsToType(tags)}
|
|
158
|
-
}
|
|
159
|
-
`);
|
|
242
|
+
await maybeWrite(filePath, renderTypes(tags));
|
|
160
243
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
244
|
+
var PARTIAL_DIR = path.join(GENERATED_DIR, "tags");
|
|
245
|
+
var REBUILD_WAIT = 100;
|
|
246
|
+
var rebuildTimer = null;
|
|
247
|
+
var rebuildError = null;
|
|
248
|
+
function partialPath(filePath) {
|
|
249
|
+
return path.join(PARTIAL_DIR, `${createHash("sha1").update(filePath).digest("hex")}.json`);
|
|
166
250
|
}
|
|
167
|
-
function
|
|
251
|
+
async function partialDirMtime() {
|
|
252
|
+
try {
|
|
253
|
+
return (await fs.stat(PARTIAL_DIR)).mtimeMs;
|
|
254
|
+
} catch (err) {
|
|
255
|
+
if (isENOENT(err))
|
|
256
|
+
return 0;
|
|
257
|
+
throw err;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async function readPartials() {
|
|
261
|
+
let entries;
|
|
262
|
+
try {
|
|
263
|
+
entries = await fs.readdir(PARTIAL_DIR);
|
|
264
|
+
} catch (err) {
|
|
265
|
+
if (isENOENT(err))
|
|
266
|
+
return new Map;
|
|
267
|
+
throw err;
|
|
268
|
+
}
|
|
168
269
|
const tags = new Map;
|
|
169
|
-
for (const
|
|
170
|
-
|
|
270
|
+
for (const entry of entries) {
|
|
271
|
+
if (!entry.endsWith(".json"))
|
|
272
|
+
continue;
|
|
273
|
+
const partial = path.join(PARTIAL_DIR, entry);
|
|
274
|
+
let parsed;
|
|
275
|
+
try {
|
|
276
|
+
parsed = JSON.parse(await fs.readFile(partial, "utf-8"));
|
|
277
|
+
} catch {
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
try {
|
|
281
|
+
await fs.access(parsed.file);
|
|
282
|
+
} catch {
|
|
283
|
+
await fs.rm(partial, { force: true });
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
for (const [name, classes] of Object.entries(parsed.tags)) {
|
|
171
287
|
if (tags.has(name))
|
|
172
288
|
throw new DuplicateTagError(name);
|
|
173
289
|
tags.set(name, classes);
|
|
@@ -175,14 +291,67 @@ function flattenTags(tagsByFile) {
|
|
|
175
291
|
}
|
|
176
292
|
return tags;
|
|
177
293
|
}
|
|
294
|
+
function writeTypesForFile(filePath, tags) {
|
|
295
|
+
return enqueueWrite(async () => {
|
|
296
|
+
await fs.mkdir(PARTIAL_DIR, { recursive: true });
|
|
297
|
+
const partial = partialPath(filePath);
|
|
298
|
+
if (!tags.size) {
|
|
299
|
+
await fs.rm(partial, { force: true });
|
|
300
|
+
} else {
|
|
301
|
+
await writeFileAtomic(partial, JSON.stringify({ file: filePath, tags: Object.fromEntries(tags) }));
|
|
302
|
+
}
|
|
303
|
+
}).then(() => {
|
|
304
|
+
scheduleRebuild();
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
function scheduleRebuild() {
|
|
308
|
+
if (rebuildTimer)
|
|
309
|
+
clearTimeout(rebuildTimer);
|
|
310
|
+
rebuildTimer = setTimeout(() => {
|
|
311
|
+
rebuildTimer = null;
|
|
312
|
+
flushTypes().catch((err) => {
|
|
313
|
+
rebuildError = err;
|
|
314
|
+
});
|
|
315
|
+
}, REBUILD_WAIT);
|
|
316
|
+
}
|
|
317
|
+
function flushTypes() {
|
|
318
|
+
if (rebuildTimer) {
|
|
319
|
+
clearTimeout(rebuildTimer);
|
|
320
|
+
rebuildTimer = null;
|
|
321
|
+
}
|
|
322
|
+
return enqueueWrite(async () => {
|
|
323
|
+
let before = await partialDirMtime();
|
|
324
|
+
for (let attempt = 0;attempt < 3; attempt++) {
|
|
325
|
+
await writeRenderedTypes(await readPartials());
|
|
326
|
+
const after = await partialDirMtime();
|
|
327
|
+
if (after === before)
|
|
328
|
+
return;
|
|
329
|
+
before = after;
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
function takeRebuildError() {
|
|
334
|
+
const err = rebuildError;
|
|
335
|
+
rebuildError = null;
|
|
336
|
+
return err;
|
|
337
|
+
}
|
|
338
|
+
function tagsToType(tags) {
|
|
339
|
+
return [...tags].toSorted(([a], [b]) => a.localeCompare(b)).map(([tag, classes]) => {
|
|
340
|
+
const union = classes.length > 0 ? classes.toSorted((a, b) => a.length - b.length).map((c) => `'${c}'`).join(" | ") : "never";
|
|
341
|
+
return ` export type ${tag} = ${union}`;
|
|
342
|
+
}).join(`
|
|
343
|
+
`);
|
|
344
|
+
}
|
|
178
345
|
export {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
maybeWrite,
|
|
182
|
-
isENOENT,
|
|
183
|
-
flattenTags,
|
|
346
|
+
DuplicateTagError,
|
|
347
|
+
InvalidTagError,
|
|
184
348
|
collect,
|
|
185
|
-
|
|
349
|
+
flushTypes,
|
|
350
|
+
isENOENT,
|
|
351
|
+
maybeWrite,
|
|
352
|
+
tagsToType,
|
|
353
|
+
takeRebuildError,
|
|
354
|
+
writeTypesForFile
|
|
186
355
|
};
|
|
187
356
|
|
|
188
|
-
//# debugId=
|
|
357
|
+
//# debugId=54844DE5AC18C36D64756E2164756E21
|
package/dist/build.js.map
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/build.ts", "../src/config.ts", "../src/lru.ts", "../src/utils.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import { createHash } from 'node:crypto'\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport { transform } from 'lightningcss'\n\nimport type { BuildContext, PluginConfig, Tags } from './types.js'\nimport { AUTOGEN_MSG, GENERATED_DIR, PKG_NAME } from './config.js'\nimport { LruCache } from './lru.js'\nimport { pascalise } from './utils.js'\n\n/**\n * LRU cache of `collect` results by file id and last seen source so watcher and transform can\n * reuse the same parsed template/tags.\n */\nconst collectCache = new LruCache<{ source: string; template: string; tags: Tags }>()\n\n/**\n * LRU cache for file content. Stores the last written content per file path so `maybeWrite`\n * can skip disk i/o when nothing has changed.\n */\nconst fileCache = new LruCache<string>()\n\n/**\n * Returns whether the error was caused by a missing file or directory.\n */\nexport function isENOENT(err: unknown) {\n\treturn err instanceof Error && 'code' in err && err.code === 'ENOENT'\n}\n\n/**\n * Write a file only if the content has changed since the last build.\n */\nexport async function maybeWrite(filePath: string, content: string) {\n\tconst cached = fileCache.get(filePath)\n\n\tif (cached !== content) {\n\t\t// cache says content changed, write without reading\n\t\tawait fs.writeFile(filePath, content)\n\t\tfileCache.set(filePath, content)\n\n\t\treturn true\n\t}\n\n\t// cache miss or cache hit with same content — verify on disk\n\ttry {\n\t\tif ((await fs.readFile(filePath, 'utf-8')) === content) {\n\t\t\tfileCache.set(filePath, content)\n\t\t\treturn false\n\t\t}\n\t} catch (err) {\n\t\tif (!isENOENT(err)) throw err\n\t}\n\n\tawait fs.writeFile(filePath, content)\n\tfileCache.set(filePath, content)\n\n\treturn true\n}\n\n// matches `[css, classes, href] = cxx\\`...\\`` and `cxx.tag<T>('name')\\`...\\``\n// capture groups: 1-3 assigned variable names, 4 plain css body, 5 quote\n// kind, 6 tag name, 7 tagged css body\nconst regex =\n\t/(?:const|var|let)\\s*\\[(\\w+|)\\s*,?\\s*(\\w+|)\\s*,?\\s*(\\w+|)\\s*\\]\\s*=\\s*cxx(?:\\s*`([\\s\\S]*?)`|\\s*\\.\\s*tag(?:\\s*<[^>]+>)?\\s*\\(\\s*(['\"])(.*?)\\5\\s*\\)\\s*`([\\s\\S]*?)`)/gm\n\n/**\n * Hash transformed CSS into a stable href for style deduplication.\n */\nfunction hashCss(code: Uint8Array) {\n\treturn `cxx-${createHash('sha256').update(code).digest('base64url').slice(0, 12)}`\n}\n\nexport class DuplicateTagError extends Error {\n\tname = 'DuplicateTagError'\n\n\tconstructor(tag: string) {\n\t\tsuper(`Tag ${tag} has already been seen. Tags must be unique across your application`)\n\t}\n}\n\n/**\n * Transform `cxx` templates in one source file and collect any exported tag types.\n */\nexport function collect(source: string, id: string, config: PluginConfig) {\n\tconst tags: Tags = new Map()\n\n\tconst cached = collectCache.get(id)\n\tif (cached?.source === source) return cached\n\n\tconst template = source.replace(\n\t\tregex,\n\t\t(_match, varOne, varTwo, varThree, plainCss, _quote, tag, taggedCss) => {\n\t\t\tconst css = plainCss ?? taggedCss\n\n\t\t\tconst { code, exports = {} } = transform({\n\t\t\t\tminify: true,\n\t\t\t\tcssModules: true,\n\t\t\t\tfilename: id,\n\t\t\t\tcode: new TextEncoder().encode(css),\n\t\t\t})\n\n\t\t\tconst href = hashCss(code)\n\t\t\tconst styles = Object.fromEntries(\n\t\t\t\tObject.entries(exports).map(([k, v]) => [k, v.name]),\n\t\t\t)\n\n\t\t\tif (tag) {\n\t\t\t\tconst suffix =\n\t\t\t\t\ttypeof config.typeSuffix === 'string'\n\t\t\t\t\t\t? config.typeSuffix\n\t\t\t\t\t\t: config.typeSuffix === false\n\t\t\t\t\t\t\t? ''\n\t\t\t\t\t\t\t: 'Classes'\n\t\t\t\tconst tagWithSuffix = pascalise(`${tag}${suffix}`)\n\n\t\t\t\tif (tags.has(tagWithSuffix)) throw new DuplicateTagError(tagWithSuffix)\n\n\t\t\t\t// side effect but neccessary\n\t\t\t\ttags.set(tagWithSuffix, Object.keys(styles))\n\t\t\t}\n\n\t\t\treturn [\n\t\t\t\tvarOne && `const ${varOne} = \\`${code}\\``,\n\t\t\t\tvarTwo && `const ${varTwo} = ${JSON.stringify(styles)}`,\n\t\t\t\tvarThree && `const ${varThree} = \\`${href}\\``,\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join('\\n')\n\t\t},\n\t)\n\n\t// cache\n\tcollectCache.set(id, { source, template, tags })\n\n\treturn {\n\t\ttemplate,\n\t\ttags,\n\t}\n}\n\n/**\n * Write the generated declaration file for the current set of collected tags.\n */\nexport async function writeTypes(tags: Tags) {\n\tconst filePath = path.join(GENERATED_DIR, 'index.d.ts')\n\n\tif (!tags.size) {\n\t\ttry {\n\t\t\tawait fs.rm(filePath, { force: true })\n\t\t\tfileCache.delete(filePath)\n\t\t} catch (err) {\n\t\t\tif (!isENOENT(err)) throw err\n\t\t}\n\n\t\treturn\n\t}\n\n\tawait fs.mkdir(GENERATED_DIR, { recursive: true })\n\n\tawait maybeWrite(\n\t\tfilePath,\n\t\t`${AUTOGEN_MSG}\n\n\t\t\timport '${PKG_NAME}'\n\n\t\t\tdeclare module '${PKG_NAME}' {\n\t\t\t\t${tagsToType(tags)}\n\t\t\t}\n\t\t`,\n\t)\n}\n\n/**\n * Render collected tags as a module augmentation for the package entrypoint.\n */\nexport function tagsToType(tags: Tags) {\n\treturn [...tags]\n\t\t.map(\n\t\t\t([tag, classes]) => `\n\t\texport type ${tag} = ${\n\t\t\tclasses.length > 0\n\t\t\t\t? classes\n\t\t\t\t\t\t.toSorted((a, b) => a.length - b.length)\n\t\t\t\t\t\t.map(c => `'${c}'`)\n\t\t\t\t\t\t.join(' | ')\n\t\t\t\t: 'never'\n\t\t}\n\t`,\n\t\t)\n\t\t.join('\\n')\n}\n\n/**\n * Merge per-file tag maps into one application-wide tag map.\n */\nexport function flattenTags(tagsByFile: BuildContext['tagsByFile']) {\n\tconst tags = new Map<string, string[]>()\n\n\tfor (const fileTags of tagsByFile.values()) {\n\t\tfor (const [name, classes] of fileTags) {\n\t\t\tif (tags.has(name)) throw new DuplicateTagError(name)\n\t\t\ttags.set(name, classes)\n\t\t}\n\t}\n\n\treturn tags\n}\n",
|
|
5
|
+
"import { createHash } from 'node:crypto'\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport { transform } from 'lightningcss'\nimport MagicString, { type SourceMap } from 'magic-string'\n\nimport type { PluginConfig, Tags } from './types.js'\nimport { AUTOGEN_MSG, GENERATED_DIR, PKG_NAME } from './config.js'\nimport { LruCache } from './lru.js'\nimport { pascalise } from './utils.js'\n\n// decode bytes to a string, then stringify into a safe literal. `${bytes}` only\n// works by accident for Buffer; a plain Uint8Array stringifies as `97,123,125`\nconst decoder = new TextDecoder()\nconst encoder = new TextEncoder()\n\n/**\n * LRU cache of `collect` results by file id + last seen source + config so watcher and transform\n * can reuse the same parsed template/tags.\n */\nconst collectCache = new LruCache<{\n\tsource: string\n\tconfig: string\n\ttemplate: string\n\ttags: Tags\n\tmap: SourceMap | null\n}>()\n\n/**\n * Serialises type file writes inside a single process so overlapping writes can't interleave or\n * land out of order.\n */\nlet writeChain: Promise<void> = Promise.resolve()\n\n/**\n * Returns whether the error was caused by a missing file or directory.\n */\nexport function isENOENT(err: unknown) {\n\treturn err instanceof Error && 'code' in err && err.code === 'ENOENT'\n}\n\n/**\n * Write a file by writing to a unique temporary file and renaming it into place, so concurrent\n * writers never observe a partial file. The temp file is cleaned up if the rename fails.\n */\nasync function writeFileAtomic(filePath: string, content: string) {\n\tconst tmp = `${filePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`\n\n\tawait fs.writeFile(tmp, content)\n\n\ttry {\n\t\tawait fs.rename(tmp, filePath)\n\t} catch (err) {\n\t\tawait fs.rm(tmp, { force: true })\n\t\tthrow err\n\t}\n}\n\n/**\n * Run a write task after all previously queued writes have settled. A rejection doesn't break the\n * chain for later tasks.\n */\nfunction enqueueWrite<T>(task: () => Promise<T>) {\n\t// wait for the previous write to finish, then run this one, even if the previous one failed\n\tconst run = writeChain.then(task, task)\n\n\t// move the queue on to this write, but turn either outcome into success so it never rejects\n\twriteChain = run.then(\n\t\t() => undefined,\n\t\t() => undefined,\n\t)\n\n\t// return the real promise, so the caller still sees this write's value or error\n\treturn run\n}\n\n/**\n * Write a file only if the content differs from what is already on disk, so watchers are not woken\n * by a needless mtime change.\n */\nexport async function maybeWrite(filePath: string, content: string) {\n\ttry {\n\t\tif ((await fs.readFile(filePath, 'utf-8')) === content) return false\n\t} catch (err) {\n\t\tif (!isENOENT(err)) throw err\n\t}\n\n\tawait writeFileAtomic(filePath, content)\n\n\treturn true\n}\n\n// matches `[css, classes, href] = cxx\\`...\\`` and `cxx.tag<T>('name')\\`...\\``\n// capture groups: 1 optional `export `, 2-4 assigned variable names, 5 plain\n// css body, 6 quote kind, 7 tag name, 8 tagged css body\nconst regex =\n\t/((?:export\\s+)?)(?:const|var|let)\\s*\\[(\\w*)\\s*,?\\s*(\\w*)\\s*,?\\s*(\\w*)\\s*\\]\\s*=\\s*cxx(?:\\s*`([\\s\\S]*?)`|\\s*\\.\\s*tag(?:\\s*<[^>]+>)?\\s*\\(\\s*(['\"])(.*?)\\6\\s*\\)\\s*`([\\s\\S]*?)`)/gm\n\nconst IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/\n\n/**\n * Hash transformed CSS into a stable href for style deduplication.\n */\nfunction hashCss(code: Uint8Array) {\n\treturn `cxx-${createHash('sha256').update(code).digest('base64url').slice(0, 12)}`\n}\n\nexport class DuplicateTagError extends Error {\n\tname = 'DuplicateTagError'\n\n\tconstructor(tag: string) {\n\t\tsuper(`Tag ${tag} has already been seen. Tags must be unique across your application`)\n\t}\n}\n\nexport class InvalidTagError extends Error {\n\tname = 'InvalidTagError'\n\n\tconstructor(tag: string) {\n\t\tsuper(\n\t\t\t`Tag \"${tag}\" does not map to a valid TypeScript identifier. ` +\n\t\t\t\t`Use letters, numbers, spaces, \"_\" or \"-\"`,\n\t\t)\n\t}\n}\n\n/**\n * Transform `cxx` templates in one source file and collect any exported tag types.\n */\nexport function collect(source: string, id: string, config: PluginConfig) {\n\tconst configKey = JSON.stringify(config)\n\n\t// reuse the last result when the source and config are unchanged\n\tconst cached = collectCache.get(id)\n\tif (cached?.source === source && cached.config === configKey) return cached\n\n\tconst tags: Tags = new Map()\n\tconst magic = new MagicString(source)\n\tlet matched = false\n\n\t// the regex is global, so reset its cursor before scanning\n\tregex.lastIndex = 0\n\n\tlet match: RegExpExecArray | null\n\n\t// walk every cxx template and replace it in place\n\twhile ((match = regex.exec(source))) {\n\t\tmatched = true\n\n\t\t// capture groups: export, three bindings, plain css, (quote), tag, tagged css\n\t\tconst [, exp, varOne, varTwo, varThree, plainCss, , tag, taggedCss] = match\n\t\tconst css = plainCss ?? taggedCss\n\t\tconst matchIndex = match.index\n\n\t\t// compile the CSS to minified CSS Modules, reporting the source line on failure\n\t\tconst { code, exports: classExports = {} } = (() => {\n\t\t\ttry {\n\t\t\t\treturn transform({\n\t\t\t\t\tminify: true,\n\t\t\t\t\tcssModules: true,\n\t\t\t\t\tfilename: id,\n\t\t\t\t\tcode: encoder.encode(css),\n\t\t\t\t})\n\t\t\t} catch (err) {\n\t\t\t\tconst line = source.slice(0, matchIndex).split('\\n').length\n\t\t\t\tthrow new Error(`Failed to compile cxx CSS at ${id}:${line}`, { cause: err })\n\t\t\t}\n\t\t})()\n\n\t\tconst href = hashCss(code)\n\t\t// map each class name to its generated (scoped) name\n\t\tconst styles = Object.fromEntries(\n\t\t\tObject.entries(classExports).map(([k, v]) => [k, v.name]),\n\t\t)\n\n\t\tif (tag) {\n\t\t\tconst suffix =\n\t\t\t\ttypeof config.typeSuffix === 'string'\n\t\t\t\t\t? config.typeSuffix\n\t\t\t\t\t: config.typeSuffix === false\n\t\t\t\t\t\t? ''\n\t\t\t\t\t\t: 'Classes'\n\t\t\tconst tagWithSuffix = pascalise(`${tag}${suffix}`)\n\n\t\t\tif (!IDENTIFIER.test(tagWithSuffix)) throw new InvalidTagError(tag)\n\t\t\tif (tags.has(tagWithSuffix)) throw new DuplicateTagError(tagWithSuffix)\n\n\t\t\t// side effect but necessary\n\t\t\ttags.set(tagWithSuffix, Object.keys(styles))\n\t\t}\n\n\t\tconst statements: string[] = []\n\n\t\tif (varOne) {\n\t\t\tstatements.push(`${exp}const ${varOne} = ${JSON.stringify(decoder.decode(code))}`)\n\t\t}\n\n\t\tif (varTwo) {\n\t\t\tstatements.push(`${exp}const ${varTwo} = ${JSON.stringify(styles)}`)\n\t\t}\n\n\t\tif (varThree) {\n\t\t\tstatements.push(`${exp}const ${varThree} = ${JSON.stringify(href)}`)\n\t\t}\n\n\t\t// swap the template for the generated declarations, keeping the export keyword\n\t\tmagic.overwrite(matchIndex, matchIndex + match[0].length, statements.join('\\n'))\n\t}\n\n\tconst template = magic.toString()\n\t// only build a map when something was actually rewritten\n\tconst map = matched\n\t\t? magic.generateMap({ source: id, includeContent: true, hires: true })\n\t\t: null\n\tconst result = { source, config: configKey, template, tags, map }\n\n\tcollectCache.set(id, result)\n\n\treturn result\n}\n\n/**\n * Render the generated declaration file contents for a set of collected tags.\n */\nfunction renderTypes(tags: Tags) {\n\treturn [\n\t\tAUTOGEN_MSG,\n\t\t'',\n\t\t`import '${PKG_NAME}'`,\n\t\t'',\n\t\t`declare module '${PKG_NAME}' {`,\n\t\ttagsToType(tags),\n\t\t'}',\n\t\t'',\n\t].join('\\n')\n}\n\n/**\n * Write (or remove) the generated `index.d.ts` for a full tag surface.\n */\nasync function writeRenderedTypes(tags: Tags) {\n\tconst filePath = path.join(GENERATED_DIR, 'index.d.ts')\n\n\tif (!tags.size) {\n\t\tawait fs.rm(filePath, { force: true })\n\t\treturn\n\t}\n\n\tawait fs.mkdir(GENERATED_DIR, { recursive: true })\n\tawait maybeWrite(filePath, renderTypes(tags))\n}\n\nconst PARTIAL_DIR = path.join(GENERATED_DIR, 'tags')\n\n// wait this long after the last file before rebuilding, so a burst of files\n// only re-reads the partials once\nconst REBUILD_WAIT = 100\n\nlet rebuildTimer: ReturnType<typeof setTimeout> | null = null\nlet rebuildError: unknown = null\n\nfunction partialPath(filePath: string) {\n\treturn path.join(\n\t\tPARTIAL_DIR,\n\t\t`${createHash('sha1').update(filePath).digest('hex')}.json`,\n\t)\n}\n\n/**\n * The partial directory changes whenever any process adds, removes or overwrites a partial, so\n * its mtime tells us whether another writer moved while we were rebuilding.\n */\nasync function partialDirMtime() {\n\ttry {\n\t\treturn (await fs.stat(PARTIAL_DIR)).mtimeMs\n\t} catch (err) {\n\t\tif (isENOENT(err)) return 0\n\t\tthrow err\n\t}\n}\n\n/**\n * Read every per-file partial and merge them into one tag map. Partials whose source file no\n * longer exists are pruned so deleted files drop out of the types.\n */\nasync function readPartials() {\n\tlet entries: string[]\n\n\ttry {\n\t\tentries = await fs.readdir(PARTIAL_DIR)\n\t} catch (err) {\n\t\tif (isENOENT(err)) return new Map()\n\t\tthrow err\n\t}\n\n\tconst tags: Tags = new Map()\n\n\tfor (const entry of entries) {\n\t\tif (!entry.endsWith('.json')) continue\n\n\t\tconst partial = path.join(PARTIAL_DIR, entry)\n\t\tlet parsed: { file: string; tags: Record<string, string[]> }\n\n\t\ttry {\n\t\t\tparsed = JSON.parse(await fs.readFile(partial, 'utf-8'))\n\t\t} catch {\n\t\t\tcontinue\n\t\t}\n\n\t\ttry {\n\t\t\tawait fs.access(parsed.file)\n\t\t} catch {\n\t\t\tawait fs.rm(partial, { force: true })\n\t\t\tcontinue\n\t\t}\n\n\t\tfor (const [name, classes] of Object.entries(parsed.tags)) {\n\t\t\tif (tags.has(name)) throw new DuplicateTagError(name)\n\t\t\ttags.set(name, classes)\n\t\t}\n\t}\n\n\treturn tags\n}\n\n/**\n * Persist one file's tags to its own partial, then rebuild the shared types soon. Rebuilding is\n * debounced and serialised, so a large build does not re-read every partial per file.\n */\nexport function writeTypesForFile(filePath: string, tags: Tags) {\n\treturn enqueueWrite(async () => {\n\t\tawait fs.mkdir(PARTIAL_DIR, { recursive: true })\n\n\t\tconst partial = partialPath(filePath)\n\n\t\tif (!tags.size) {\n\t\t\tawait fs.rm(partial, { force: true })\n\t\t} else {\n\t\t\tawait writeFileAtomic(\n\t\t\t\tpartial,\n\t\t\t\tJSON.stringify({ file: filePath, tags: Object.fromEntries(tags) }),\n\t\t\t)\n\t\t}\n\t}).then(() => {\n\t\tscheduleRebuild()\n\t})\n}\n\nfunction scheduleRebuild() {\n\tif (rebuildTimer) clearTimeout(rebuildTimer)\n\n\trebuildTimer = setTimeout(() => {\n\t\trebuildTimer = null\n\t\tflushTypes().catch(err => {\n\t\t\trebuildError = err\n\t\t})\n\t}, REBUILD_WAIT)\n}\n\n/**\n * Rebuild `index.d.ts` from every partial now. If another writer touches a partial mid-rebuild,\n * rebuild once more so the final write reflects every partial. Bounded to avoid spinning.\n */\nexport function flushTypes() {\n\tif (rebuildTimer) {\n\t\tclearTimeout(rebuildTimer)\n\t\trebuildTimer = null\n\t}\n\n\treturn enqueueWrite(async () => {\n\t\tlet before = await partialDirMtime()\n\n\t\tfor (let attempt = 0; attempt < 3; attempt++) {\n\t\t\tawait writeRenderedTypes(await readPartials())\n\n\t\t\tconst after = await partialDirMtime()\n\t\t\tif (after === before) return\n\n\t\t\tbefore = after\n\t\t}\n\t})\n}\n\n/**\n * Return and clear any error from a background rebuild, so a caller can fail loudly.\n */\nexport function takeRebuildError() {\n\tconst err = rebuildError\n\trebuildError = null\n\treturn err\n}\n\n/**\n * Render collected tags as a module augmentation for the package entrypoint.\n */\nexport function tagsToType(tags: Tags) {\n\treturn [...tags]\n\t\t.toSorted(([a], [b]) => a.localeCompare(b))\n\t\t.map(([tag, classes]) => {\n\t\t\tconst union =\n\t\t\t\tclasses.length > 0\n\t\t\t\t\t? classes\n\t\t\t\t\t\t\t.toSorted((a, b) => a.length - b.length)\n\t\t\t\t\t\t\t.map(c => `'${c}'`)\n\t\t\t\t\t\t\t.join(' | ')\n\t\t\t\t\t: 'never'\n\n\t\t\treturn `\\texport type ${tag} = ${union}`\n\t\t})\n\t\t.join('\\n')\n}\n",
|
|
6
6
|
"export const NAME = 'cxx'\nexport const PKG_NAME = `@jk2908/${NAME}`\nexport const GENERATED_DIR = `.${NAME}`\nexport const AUTOGEN_MSG = `// auto-generated by ${NAME}`\n",
|
|
7
7
|
"export const CACHE_MAX_SIZE = 100\n\nexport class LruCache<T> {\n\t#cache: Map<string, T> = new Map()\n\t#maxSize: number\n\n\tconstructor(maxSize = CACHE_MAX_SIZE) {\n\t\tthis.#maxSize = maxSize\n\t}\n\n\tget size() {\n\t\treturn this.#cache.size\n\t}\n\n\t/**\n\t * Retrieve a cached value and promote it to most-recently-used so it won't\n\t * be evicted while still actively referenced.\n\t */\n\tget(key: string) {\n\t\tconst cached = this.#cache.get(key)\n\t\tif (this.#cache.has(key)) this.set(key, cached as T)\n\n\t\treturn cached\n\t}\n\n\t/**\n\t * Promote an existing cache entry to most-recently-used by deleting and\n\t * re-inserting it, which moves it to the end of the Map's iteration\n\t * order. If the cache is at capacity, evict the least recently used\n\t * entry (front) before inserting.\n\t */\n\tset(key: string, value: T) {\n\t\t// drop any existing entry\n\t\tthis.#cache.delete(key)\n\n\t\tif (this.#cache.size >= this.#maxSize) {\n\t\t\tconst lru = this.#cache.keys().next().value\n\t\t\tif (lru !== undefined) this.#cache.delete(lru)\n\t\t}\n\n\t\tthis.#cache.set(key, value)\n\t}\n\n\tdelete(key: string) {\n\t\treturn this.#cache.delete(key)\n\t}\n\n\tclear() {\n\t\treturn this.#cache.clear()\n\t}\n}\n",
|
|
8
|
-
"export function capitalise(str: string) {\n\treturn str.charAt(0).toUpperCase() + str.slice(1)\n}\n\nexport function pascalise(str: string) {\n\treturn str\n\t\t.split(/[ _-]+/)\n\t\t.map(capitalise)\n\t\t.join('')\n}\n\nexport
|
|
8
|
+
"export function capitalise(str: string) {\n\treturn str.charAt(0).toUpperCase() + str.slice(1)\n}\n\nexport function pascalise(str: string) {\n\treturn str\n\t\t.split(/[ _-]+/)\n\t\t.map(capitalise)\n\t\t.join('')\n}\n\nexport type Batcher<K, V> = {\n\t/**\n\t * Queue a value for a key. Queueing the same key again replaces the previous value.\n\t */\n\tadd: (key: K, value: V) => void\n\t/**\n\t * Run any waiting work now and resolve once it has finished.\n\t */\n\tflush: () => Promise<void>\n}\n\n/**\n * Group bursts of work and run them together. Every key queued within `wait` is\n * included once, and a key queued while a batch is running is handled in the next\n * batch instead of replacing the one in progress.\n */\nexport function createBatcher<K, V>(\n\twait: number,\n\tflush: (batch: Map<K, V>) => void | Promise<void>,\n): Batcher<K, V> {\n\t// work waiting to run, keyed so each key is only queued once\n\tconst pending = new Map<K, V>()\n\t// waits for a burst of changes to settle before running\n\tlet timer: ReturnType<typeof setTimeout> | null = null\n\t// the run in progress, so `flush` can wait for it and we never start a second\n\tlet current: Promise<void> | null = null\n\n\tfunction drain() {\n\t\t// a run is already going, so let it pick up the new work\n\t\tif (current) return current\n\n\t\tconst run = (async () => {\n\t\t\t// keep looping while there is work, including work added during a flush\n\t\t\twhile (pending.size > 0) {\n\t\t\t\t// snapshot the queued work\n\t\t\t\tconst batch = new Map(pending)\n\t\t\t\t// empty the queue right away, so anything added during flush waits for the next loop\n\t\t\t\tpending.clear()\n\n\t\t\t\tawait flush(batch)\n\t\t\t}\n\t\t})()\n\n\t\tcurrent = run\n\t\trun.then(\n\t\t\t() => {\n\t\t\t\tif (current === run) current = null\n\t\t\t},\n\t\t\t() => {\n\t\t\t\tif (current === run) current = null\n\t\t\t},\n\t\t)\n\n\t\treturn run\n\t}\n\n\tfunction schedule() {\n\t\t// cancel the previous wait, so the timer restarts from now\n\t\tif (timer) clearTimeout(timer)\n\n\t\t// run once the calls stop coming for `wait` ms\n\t\ttimer = setTimeout(() => {\n\t\t\t// the timer has fired, so drop the stale handle\n\t\t\ttimer = null\n\t\t\t// the flush callback handles its own errors, so just start the run\n\t\t\tvoid drain().catch(() => {})\n\t\t}, wait)\n\t}\n\n\treturn {\n\t\tadd(key, value) {\n\t\t\t// the newest value for this key wins\n\t\t\tpending.set(key, value)\n\t\t\tschedule()\n\t\t},\n\t\tflush() {\n\t\t\t// run now instead of waiting out the timer\n\t\t\tif (timer) {\n\t\t\t\tclearTimeout(timer)\n\t\t\t\ttimer = null\n\t\t\t}\n\n\t\t\treturn drain()\n\t\t},\n\t}\n}\n"
|
|
9
9
|
],
|
|
10
|
-
"mappings": "
|
|
11
|
-
"debugId": "
|
|
10
|
+
"mappings": ";;;;AAAA;AACA;AACA;AAEA;AACA;;;ACLO,IAAM,OAAO;AACb,IAAM,WAAW,WAAW;AAC5B,IAAM,gBAAgB,IAAI;AAC1B,IAAM,cAAc,wBAAwB;;;ACH5C,IAAM,iBAAiB;AAAA;AAEvB,MAAM,SAAY;AAAA,EACxB,SAAyB,IAAI;AAAA,EAC7B;AAAA,EAEA,WAAW,CAAC,UAAU,gBAAgB;AAAA,IACrC,KAAK,WAAW;AAAA;AAAA,MAGb,IAAI,GAAG;AAAA,IACV,OAAO,KAAK,OAAO;AAAA;AAAA,EAOpB,GAAG,CAAC,KAAa;AAAA,IAChB,MAAM,SAAS,KAAK,OAAO,IAAI,GAAG;AAAA,IAClC,IAAI,KAAK,OAAO,IAAI,GAAG;AAAA,MAAG,KAAK,IAAI,KAAK,MAAW;AAAA,IAEnD,OAAO;AAAA;AAAA,EASR,GAAG,CAAC,KAAa,OAAU;AAAA,IAE1B,KAAK,OAAO,OAAO,GAAG;AAAA,IAEtB,I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
"debugId": "54844DE5AC18C36D64756E2164756E21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAU,MAAM,YAAY,CAAA;AAE7C,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAU,MAAM,YAAY,CAAA;AAE7C,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAmBlD;;GAEG;AACH,eAAO,MAAM,GAAG,EAAE,GAQjB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
+
|
|
1
4
|
// src/index.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
]
|
|
5
|
+
function untransformed() {
|
|
6
|
+
throw new Error("cxx template was not transformed. Make sure the cxx Vite plugin or Next integration is configured and applies to this file.");
|
|
7
|
+
}
|
|
8
|
+
var cxx = Object.assign((_) => untransformed(), {
|
|
9
|
+
tag: (_) => (_strings) => untransformed()
|
|
8
10
|
});
|
|
9
11
|
export {
|
|
10
12
|
cxx
|
|
11
13
|
};
|
|
12
14
|
|
|
13
|
-
//# debugId=
|
|
15
|
+
//# debugId=3CD7511904F6E92464756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { Cxx, Result } from './types.js'\n\nexport type { Cxx, Result, Tag } from './types.js'\n\n/**\n * Build-time template tag placeholder used by the transform to emit CSS, classes and href values.\n */\nexport const cxx: Cxx = Object.assign((_: TemplateStringsArray): Result =>
|
|
5
|
+
"import type { Cxx, Result } from './types.js'\n\nexport type { Cxx, Result, Tag } from './types.js'\n\n/**\n * Hit when a `cxx` template reaches runtime, which means the build transform did\n * not run. Throws so the problem is obvious instead of rendering empty styles.\n *\n * @example\n * ```ts\n * // no cxx plugin configured\n * const [css, styles, href] = cxx`.a { color: red; }`\n * // Error: cxx template was not transformed ...\n * ```\n */\nfunction untransformed(): never {\n\tthrow new Error(\n\t\t'cxx template was not transformed. Make sure the cxx Vite plugin or Next integration is configured and applies to this file.',\n\t)\n}\n\n/**\n * Build-time template tag placeholder used by the transform to emit CSS, classes and href values.\n */\nexport const cxx: Cxx = Object.assign(\n\t(_: TemplateStringsArray): Result => untransformed(),\n\t{\n\t\ttag:\n\t\t\t<ClassName extends string = string>(_: string) =>\n\t\t\t(_strings: TemplateStringsArray): Result<ClassName> =>\n\t\t\t\tuntransformed(),\n\t},\n)\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;AAeA,SAAS,aAAa,GAAU;AAAA,EAC/B,MAAM,IAAI,MACT,6HACD;AAAA;AAMM,IAAM,MAAW,OAAO,OAC9B,CAAC,MAAoC,cAAc,GACnD;AAAA,EACC,KACC,CAAoC,MACpC,CAAC,aACA,cAAc;AACjB,CACD;",
|
|
8
|
+
"debugId": "3CD7511904F6E92464756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/logger.d.ts
CHANGED
|
@@ -13,8 +13,6 @@ export declare class Logger {
|
|
|
13
13
|
#private;
|
|
14
14
|
name?: string | undefined;
|
|
15
15
|
constructor(level?: LogLevel, name?: string | undefined);
|
|
16
|
-
static set defaultLevel(level: LogLevel);
|
|
17
|
-
static get defaultLevel(): LogLevel;
|
|
18
16
|
/**
|
|
19
17
|
* Convert a value to an Error instance.
|
|
20
18
|
*/
|