@jk2908/cxx 0.2.4 → 0.3.1
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 +46 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +314 -0
- package/dist/build.js.map +13 -0
- package/dist/index.d.ts +3 -36
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -188
- package/dist/index.js.map +4 -7
- package/dist/logger.d.ts +9 -11
- package/dist/logger.d.ts.map +1 -1
- package/dist/lru.d.ts +2 -2
- package/dist/next/cxx-loader.cjs +249 -152
- package/dist/next/cxx-loader.cjs.map +9 -9
- package/dist/next/index.d.ts +32 -11
- package/dist/next/index.d.ts.map +1 -1
- package/dist/next/index.js +278 -135
- package/dist/next/index.js.map +7 -7
- package/dist/types.d.ts +3 -3
- 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 +14 -6
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +281 -129
- package/dist/vite/index.js.map +8 -8
- package/package.json +83 -75
- package/src/build.ts +373 -0
- package/src/index.ts +24 -210
- package/src/logger.ts +14 -22
- package/src/lru.ts +2 -2
- package/src/next/cxx-loader.js +1 -5
- package/src/next/index.ts +143 -100
- package/src/types.ts +5 -4
- package/src/utils.ts +72 -7
- package/src/vite/index.ts +110 -79
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 Vite the globs are added to `server.watch.ignored`.
|
|
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
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type SourceMap } from 'magic-string';
|
|
2
|
+
import type { BuildContext, PluginConfig, Tags } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Returns whether the error was caused by a missing file or directory.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isENOENT(err: unknown): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Write a file only if the content actually differs from what is already on disk.
|
|
9
|
+
*/
|
|
10
|
+
export declare function maybeWrite(filePath: string, content: string): Promise<boolean>;
|
|
11
|
+
export declare class DuplicateTagError extends Error {
|
|
12
|
+
name: string;
|
|
13
|
+
constructor(tag: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class InvalidTagError extends Error {
|
|
16
|
+
name: string;
|
|
17
|
+
constructor(tag: string);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Transform `cxx` templates in one source file and collect any exported tag types.
|
|
21
|
+
*/
|
|
22
|
+
export declare function collect(source: string, id: string, config: PluginConfig): {
|
|
23
|
+
source: string;
|
|
24
|
+
config: string;
|
|
25
|
+
template: string;
|
|
26
|
+
tags: Tags;
|
|
27
|
+
map: SourceMap | null;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Write the generated declaration file for the current set of collected tags.
|
|
31
|
+
*/
|
|
32
|
+
export declare function writeTypes(tags: Tags): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Next-specific write path. Turbopack spreads loaders across worker processes, so each worker
|
|
35
|
+
* persists its own per-file partial and rebuilds the shared declaration file from all of them.
|
|
36
|
+
*/
|
|
37
|
+
export declare function writeTypesForFile(filePath: string, tags: Tags): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Render collected tags as a module augmentation for the package entrypoint.
|
|
40
|
+
*/
|
|
41
|
+
export declare function tagsToType(tags: Tags): string;
|
|
42
|
+
/**
|
|
43
|
+
* Merge per-file tag maps into one application-wide tag map.
|
|
44
|
+
*/
|
|
45
|
+
export declare function flattenTags(tagsByFile: BuildContext['tagsByFile']): Map<string, string[]>;
|
|
46
|
+
//# sourceMappingURL=build.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAiClE;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,WAEpC;AA+BD;;GAEG;AACH,wBAAsB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,oBAoBjE;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;YArH/D,MAAM;YACN,MAAM;cACJ,MAAM;UACV,IAAI;SACL,SAAS,GAAG,IAAI;EAmMrB;AAoCD;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,iBAEpC;AAuDD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,iBAiB7D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,UAcpC;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,YAAY,CAAC,YAAY,CAAC,yBAWjE"}
|
package/dist/build.js
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
3
|
+
|
|
4
|
+
// src/build.ts
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import fs from "node:fs/promises";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { transform } from "lightningcss";
|
|
9
|
+
import MagicString from "magic-string";
|
|
10
|
+
|
|
11
|
+
// src/config.ts
|
|
12
|
+
var NAME = "cxx";
|
|
13
|
+
var PKG_NAME = `@jk2908/${NAME}`;
|
|
14
|
+
var GENERATED_DIR = `.${NAME}`;
|
|
15
|
+
var AUTOGEN_MSG = `// auto-generated by ${NAME}`;
|
|
16
|
+
|
|
17
|
+
// src/lru.ts
|
|
18
|
+
var CACHE_MAX_SIZE = 100;
|
|
19
|
+
|
|
20
|
+
class LruCache {
|
|
21
|
+
#cache = new Map;
|
|
22
|
+
#maxSize;
|
|
23
|
+
constructor(maxSize = CACHE_MAX_SIZE) {
|
|
24
|
+
this.#maxSize = maxSize;
|
|
25
|
+
}
|
|
26
|
+
get size() {
|
|
27
|
+
return this.#cache.size;
|
|
28
|
+
}
|
|
29
|
+
get(key) {
|
|
30
|
+
const cached = this.#cache.get(key);
|
|
31
|
+
if (this.#cache.has(key))
|
|
32
|
+
this.set(key, cached);
|
|
33
|
+
return cached;
|
|
34
|
+
}
|
|
35
|
+
set(key, value) {
|
|
36
|
+
this.#cache.delete(key);
|
|
37
|
+
if (this.#cache.size >= this.#maxSize) {
|
|
38
|
+
const lru = this.#cache.keys().next().value;
|
|
39
|
+
if (lru !== undefined)
|
|
40
|
+
this.#cache.delete(lru);
|
|
41
|
+
}
|
|
42
|
+
this.#cache.set(key, value);
|
|
43
|
+
}
|
|
44
|
+
delete(key) {
|
|
45
|
+
return this.#cache.delete(key);
|
|
46
|
+
}
|
|
47
|
+
clear() {
|
|
48
|
+
return this.#cache.clear();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/utils.ts
|
|
53
|
+
function capitalise(str) {
|
|
54
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
55
|
+
}
|
|
56
|
+
function pascalise(str) {
|
|
57
|
+
return str.split(/[ _-]+/).map(capitalise).join("");
|
|
58
|
+
}
|
|
59
|
+
function createBatcher(wait, flush) {
|
|
60
|
+
const pending = new Map;
|
|
61
|
+
let timer = null;
|
|
62
|
+
let running = false;
|
|
63
|
+
async function drain() {
|
|
64
|
+
if (running)
|
|
65
|
+
return;
|
|
66
|
+
running = true;
|
|
67
|
+
try {
|
|
68
|
+
while (pending.size > 0) {
|
|
69
|
+
const batch = new Map(pending);
|
|
70
|
+
pending.clear();
|
|
71
|
+
await flush(batch);
|
|
72
|
+
}
|
|
73
|
+
} finally {
|
|
74
|
+
running = false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function schedule() {
|
|
78
|
+
if (timer)
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
timer = setTimeout(() => {
|
|
81
|
+
timer = null;
|
|
82
|
+
drain();
|
|
83
|
+
}, wait);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
add(key, value) {
|
|
87
|
+
pending.set(key, value);
|
|
88
|
+
schedule();
|
|
89
|
+
},
|
|
90
|
+
flush() {
|
|
91
|
+
if (timer) {
|
|
92
|
+
clearTimeout(timer);
|
|
93
|
+
timer = null;
|
|
94
|
+
}
|
|
95
|
+
return drain();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/build.ts
|
|
101
|
+
var decoder = new TextDecoder;
|
|
102
|
+
var collectCache = new LruCache;
|
|
103
|
+
var fileCache = new LruCache;
|
|
104
|
+
var writeChain = Promise.resolve();
|
|
105
|
+
function isENOENT(err) {
|
|
106
|
+
return err instanceof Error && "code" in err && err.code === "ENOENT";
|
|
107
|
+
}
|
|
108
|
+
async function writeFileAtomic(filePath, content) {
|
|
109
|
+
const tmp = `${filePath}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
110
|
+
await fs.writeFile(tmp, content);
|
|
111
|
+
await fs.rename(tmp, filePath);
|
|
112
|
+
}
|
|
113
|
+
function enqueueWrite(task) {
|
|
114
|
+
const run = writeChain.then(task, task);
|
|
115
|
+
writeChain = run.then(() => {
|
|
116
|
+
return;
|
|
117
|
+
}, () => {
|
|
118
|
+
return;
|
|
119
|
+
});
|
|
120
|
+
return run;
|
|
121
|
+
}
|
|
122
|
+
async function maybeWrite(filePath, content) {
|
|
123
|
+
const cached = fileCache.get(filePath);
|
|
124
|
+
if (cached === content)
|
|
125
|
+
return false;
|
|
126
|
+
try {
|
|
127
|
+
if (await fs.readFile(filePath, "utf-8") === content) {
|
|
128
|
+
fileCache.set(filePath, content);
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
} catch (err) {
|
|
132
|
+
if (!isENOENT(err))
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
await writeFileAtomic(filePath, content);
|
|
136
|
+
fileCache.set(filePath, content);
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
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;
|
|
140
|
+
var IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
141
|
+
function hashCss(code) {
|
|
142
|
+
return `cxx-${createHash("sha256").update(code).digest("base64url").slice(0, 12)}`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
class DuplicateTagError extends Error {
|
|
146
|
+
name = "DuplicateTagError";
|
|
147
|
+
constructor(tag) {
|
|
148
|
+
super(`Tag ${tag} has already been seen. Tags must be unique across your application`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
class InvalidTagError extends Error {
|
|
153
|
+
name = "InvalidTagError";
|
|
154
|
+
constructor(tag) {
|
|
155
|
+
super(`Tag "${tag}" does not map to a valid TypeScript identifier. ` + `Use letters, numbers, spaces, "_" or "-"`);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function collect(source, id, config) {
|
|
159
|
+
const configKey = JSON.stringify(config);
|
|
160
|
+
const cached = collectCache.get(id);
|
|
161
|
+
if (cached?.source === source && cached.config === configKey)
|
|
162
|
+
return cached;
|
|
163
|
+
const tags = new Map;
|
|
164
|
+
const magic = new MagicString(source);
|
|
165
|
+
let matched = false;
|
|
166
|
+
regex.lastIndex = 0;
|
|
167
|
+
let match;
|
|
168
|
+
while (match = regex.exec(source)) {
|
|
169
|
+
matched = true;
|
|
170
|
+
const [, exp, varOne, varTwo, varThree, plainCss, , tag, taggedCss] = match;
|
|
171
|
+
const css = plainCss ?? taggedCss;
|
|
172
|
+
const { code, exports = {} } = transform({
|
|
173
|
+
minify: true,
|
|
174
|
+
cssModules: true,
|
|
175
|
+
filename: id,
|
|
176
|
+
code: new TextEncoder().encode(css)
|
|
177
|
+
});
|
|
178
|
+
const href = hashCss(code);
|
|
179
|
+
const styles = Object.fromEntries(Object.entries(exports).map(([k, v]) => [k, v.name]));
|
|
180
|
+
if (tag) {
|
|
181
|
+
const suffix = typeof config.typeSuffix === "string" ? config.typeSuffix : config.typeSuffix === false ? "" : "Classes";
|
|
182
|
+
const tagWithSuffix = pascalise(`${tag}${suffix}`);
|
|
183
|
+
if (!IDENTIFIER.test(tagWithSuffix))
|
|
184
|
+
throw new InvalidTagError(tag);
|
|
185
|
+
if (tags.has(tagWithSuffix))
|
|
186
|
+
throw new DuplicateTagError(tagWithSuffix);
|
|
187
|
+
tags.set(tagWithSuffix, Object.keys(styles));
|
|
188
|
+
}
|
|
189
|
+
const statements = [];
|
|
190
|
+
if (varOne) {
|
|
191
|
+
statements.push(`${exp}const ${varOne} = ${JSON.stringify(decoder.decode(code))}`);
|
|
192
|
+
}
|
|
193
|
+
if (varTwo) {
|
|
194
|
+
statements.push(`${exp}const ${varTwo} = ${JSON.stringify(styles)}`);
|
|
195
|
+
}
|
|
196
|
+
if (varThree) {
|
|
197
|
+
statements.push(`${exp}const ${varThree} = ${JSON.stringify(href)}`);
|
|
198
|
+
}
|
|
199
|
+
magic.overwrite(match.index, match.index + match[0].length, statements.join(`
|
|
200
|
+
`));
|
|
201
|
+
}
|
|
202
|
+
const template = magic.toString();
|
|
203
|
+
const map = matched ? magic.generateMap({ source: id, includeContent: true, hires: true }) : null;
|
|
204
|
+
const result = { source, config: configKey, template, tags, map };
|
|
205
|
+
collectCache.set(id, result);
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
function renderTypes(tags) {
|
|
209
|
+
return [
|
|
210
|
+
AUTOGEN_MSG,
|
|
211
|
+
"",
|
|
212
|
+
`import '${PKG_NAME}'`,
|
|
213
|
+
"",
|
|
214
|
+
`declare module '${PKG_NAME}' {`,
|
|
215
|
+
tagsToType(tags),
|
|
216
|
+
"}",
|
|
217
|
+
""
|
|
218
|
+
].join(`
|
|
219
|
+
`);
|
|
220
|
+
}
|
|
221
|
+
async function writeRenderedTypes(tags) {
|
|
222
|
+
const filePath = path.join(GENERATED_DIR, "index.d.ts");
|
|
223
|
+
if (!tags.size) {
|
|
224
|
+
await fs.rm(filePath, { force: true });
|
|
225
|
+
fileCache.delete(filePath);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
await fs.mkdir(GENERATED_DIR, { recursive: true });
|
|
229
|
+
await maybeWrite(filePath, renderTypes(tags));
|
|
230
|
+
}
|
|
231
|
+
function writeTypes(tags) {
|
|
232
|
+
return enqueueWrite(() => writeRenderedTypes(tags));
|
|
233
|
+
}
|
|
234
|
+
var PARTIAL_DIR = path.join(GENERATED_DIR, "tags");
|
|
235
|
+
function partialPath(filePath) {
|
|
236
|
+
return path.join(PARTIAL_DIR, `${createHash("sha1").update(filePath).digest("hex")}.json`);
|
|
237
|
+
}
|
|
238
|
+
async function readPartials() {
|
|
239
|
+
let entries;
|
|
240
|
+
try {
|
|
241
|
+
entries = await fs.readdir(PARTIAL_DIR);
|
|
242
|
+
} catch (err) {
|
|
243
|
+
if (isENOENT(err))
|
|
244
|
+
return new Map;
|
|
245
|
+
throw err;
|
|
246
|
+
}
|
|
247
|
+
const tags = new Map;
|
|
248
|
+
for (const entry of entries) {
|
|
249
|
+
if (!entry.endsWith(".json"))
|
|
250
|
+
continue;
|
|
251
|
+
const partial = path.join(PARTIAL_DIR, entry);
|
|
252
|
+
let parsed;
|
|
253
|
+
try {
|
|
254
|
+
parsed = JSON.parse(await fs.readFile(partial, "utf-8"));
|
|
255
|
+
} catch {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
await fs.access(parsed.file);
|
|
260
|
+
} catch {
|
|
261
|
+
await fs.rm(partial, { force: true });
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
for (const [name, classes] of Object.entries(parsed.tags)) {
|
|
265
|
+
if (tags.has(name))
|
|
266
|
+
throw new DuplicateTagError(name);
|
|
267
|
+
tags.set(name, classes);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return tags;
|
|
271
|
+
}
|
|
272
|
+
function writeTypesForFile(filePath, tags) {
|
|
273
|
+
return enqueueWrite(async () => {
|
|
274
|
+
await fs.mkdir(PARTIAL_DIR, { recursive: true });
|
|
275
|
+
const partial = partialPath(filePath);
|
|
276
|
+
if (!tags.size) {
|
|
277
|
+
await fs.rm(partial, { force: true });
|
|
278
|
+
} else {
|
|
279
|
+
await writeFileAtomic(partial, JSON.stringify({ file: filePath, tags: Object.fromEntries(tags) }));
|
|
280
|
+
}
|
|
281
|
+
await writeRenderedTypes(await readPartials());
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
function tagsToType(tags) {
|
|
285
|
+
return [...tags].map(([tag, classes]) => {
|
|
286
|
+
const union = classes.length > 0 ? classes.toSorted((a, b) => a.length - b.length).map((c) => `'${c}'`).join(" | ") : "never";
|
|
287
|
+
return ` export type ${tag} = ${union}`;
|
|
288
|
+
}).join(`
|
|
289
|
+
`);
|
|
290
|
+
}
|
|
291
|
+
function flattenTags(tagsByFile) {
|
|
292
|
+
const tags = new Map;
|
|
293
|
+
for (const fileTags of tagsByFile.values()) {
|
|
294
|
+
for (const [name, classes] of fileTags) {
|
|
295
|
+
if (tags.has(name))
|
|
296
|
+
throw new DuplicateTagError(name);
|
|
297
|
+
tags.set(name, classes);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return tags;
|
|
301
|
+
}
|
|
302
|
+
export {
|
|
303
|
+
DuplicateTagError,
|
|
304
|
+
InvalidTagError,
|
|
305
|
+
collect,
|
|
306
|
+
flattenTags,
|
|
307
|
+
isENOENT,
|
|
308
|
+
maybeWrite,
|
|
309
|
+
tagsToType,
|
|
310
|
+
writeTypes,
|
|
311
|
+
writeTypesForFile
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
//# debugId=9492B787092F945A64756E2164756E21
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/build.ts", "../src/config.ts", "../src/lru.ts", "../src/utils.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
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 { 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// 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()\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 * 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 * Serialises type file writes inside a single process so overlapping `writeTypes` calls can't\n * interleave or 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 first writing to a unique temporary file and then renaming it into place, so\n * concurrent writers (e.g. Turbopack loader workers) never observe a partial file.\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\tawait fs.rename(tmp, filePath)\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 actually differs from what is already on disk.\n */\nexport async function maybeWrite(filePath: string, content: string) {\n\tconst cached = fileCache.get(filePath)\n\t// fast path: already wrote this exact content in this process\n\tif (cached === content) return false\n\n\t// verify against disk on a cold start (or when the cache is stale) so we\n\t// don't needlessly bump the mtime and invalidate downstream watchers\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 writeFileAtomic(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 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\n\t\t// compile the CSS to minified CSS Modules\n\t\tconst { code, exports = {} } = transform({\n\t\t\tminify: true,\n\t\t\tcssModules: true,\n\t\t\tfilename: id,\n\t\t\tcode: new TextEncoder().encode(css),\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(exports).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(match.index, match.index + 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\t// `force` makes this a no-op when the file is already absent\n\t\tawait fs.rm(filePath, { force: true })\n\t\tfileCache.delete(filePath)\n\n\t\treturn\n\t}\n\n\tawait fs.mkdir(GENERATED_DIR, { recursive: true })\n\tawait maybeWrite(filePath, renderTypes(tags))\n}\n\n/**\n * Write the generated declaration file for the current set of collected tags.\n */\nexport function writeTypes(tags: Tags) {\n\treturn enqueueWrite(() => writeRenderedTypes(tags))\n}\n\nconst PARTIAL_DIR = path.join(GENERATED_DIR, 'tags')\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 * Read every per-file partial written by the Next loader workers and merge them into one tag map.\n * Partials whose source file no 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 * Next-specific write path. Turbopack spreads loaders across worker processes, so each worker\n * persists its own per-file partial and rebuilds the shared declaration file from all of them.\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\n\t\tawait writeRenderedTypes(await readPartials())\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(([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\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",
|
|
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
|
+
"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 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// true while a batch is running, so we never start a second one\n\tlet running = false\n\n\tasync function drain() {\n\t\t// a run is already going, so let it pick up the new work\n\t\tif (running) return\n\t\trunning = true\n\n\t\ttry {\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} finally {\n\t\t\t// always allow the next run, even if flush threw\n\t\t\trunning = false\n\t\t}\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// start the run without waiting for it (this is a timer callback)\n\t\t\tvoid drain()\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
|
+
],
|
|
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,IAAI,KAAK,OAAO,QAAQ,KAAK,UAAU;AAAA,MAC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AY,WAAW,OAAO,GAAG;AAAA,IAC3C,YAAY,MAAM,YAAY,UAAU;AAAA,MACvC,IAAI,KAAK,IAAI,IAAI;AAAA,QAAG,MAAM,IAAI,kBAAkB,IAAI;AAAA,MACpD,KAAK,IAAI,MAAM,OAAO;AAAA,IACvB;AAAA,EACD;AAAA,EAEA,OAAO;AAAA;",
|
|
11
|
+
"debugId": "9492B787092F945A64756E2164756E21",
|
|
12
|
+
"names": []
|
|
13
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Cxx } from './types.js';
|
|
2
|
+
export type { Cxx, Result, Tag } from './types.js';
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
export declare function isENOENT(err: unknown): boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Write a file only if the content has changed since the last build
|
|
8
|
-
*/
|
|
9
|
-
export declare function maybeWrite(filePath: string, content: string): Promise<boolean>;
|
|
10
|
-
export declare class TagDuplicateError extends Error {
|
|
11
|
-
constructor(tag: string);
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Transform `cxx` templates in one source file and collect any exported tag types
|
|
15
|
-
*/
|
|
16
|
-
export declare function collect(source: string, id: string, config: PluginConfig): {
|
|
17
|
-
source: string;
|
|
18
|
-
template: string;
|
|
19
|
-
tags: Tags;
|
|
20
|
-
} | {
|
|
21
|
-
template: string;
|
|
22
|
-
tags: Tags;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Write the generated declaration file for the current set of collected tags
|
|
26
|
-
*/
|
|
27
|
-
export declare function writeTypes(tags: Tags): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* Render collected tags as a module augmentation for the package entrypoint
|
|
30
|
-
*/
|
|
31
|
-
export declare function tagsToType(tags: Tags): string;
|
|
32
|
-
/**
|
|
33
|
-
* Merge per-file tag maps into one application-wide tag map
|
|
34
|
-
*/
|
|
35
|
-
export declare function flattenTags(tagsByFile: BuildContext['tagsByFile']): Map<string, string[]>;
|
|
36
|
-
/**
|
|
37
|
-
* Build-time template tag placeholder used by the transform to emit CSS, classes and href values
|
|
4
|
+
* Build-time template tag placeholder used by the transform to emit CSS, classes and href values.
|
|
38
5
|
*/
|
|
39
6
|
export declare const cxx: Cxx;
|
|
40
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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"}
|