@jk2908/cxx 0.2.3 → 0.2.6
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 +1 -1
- package/dist/build.d.ts +37 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +188 -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 +2 -184
- package/dist/index.js.map +4 -7
- package/dist/logger.d.ts +9 -9
- package/dist/lru.d.ts +2 -2
- package/dist/next/cxx-loader.cjs +37 -22
- package/dist/next/cxx-loader.cjs.map +7 -7
- package/dist/next/index.js +7 -13
- package/dist/next/index.js.map +6 -6
- package/dist/vite/index.d.ts +3 -3
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +9 -15
- package/dist/vite/index.js.map +7 -7
- package/package.json +13 -9
- package/src/build.ts +208 -0
- package/src/index.ts +3 -206
- package/src/logger.ts +9 -9
- package/src/lru.ts +2 -2
- package/src/next/index.ts +1 -1
- package/src/vite/index.ts +1 -1
package/dist/vite/index.js.map
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/
|
|
3
|
+
"sources": ["../src/build.ts", "../src/config.ts", "../src/lru.ts", "../src/utils.ts", "../src/vite/index.ts", "../src/logger.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,
|
|
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",
|
|
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
|
-
"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
|
|
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
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 function debounce<T extends unknown[]>(fn: (...args: T) => void, wait: number) {\n\tlet timeoutId: ReturnType<typeof setTimeout> | null = null\n\n\treturn (...args: T) => {\n\t\tif (timeoutId) {\n\t\t\tclearTimeout(timeoutId)\n\t\t}\n\n\t\ttimeoutId = setTimeout(() => {\n\t\t\tfn.apply(null, args)\n\t\t}, wait)\n\t}\n}\n",
|
|
9
|
-
"import { realpathSync } from 'node:fs'\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport { type Plugin, type ViteDevServer } from 'vite'\n\nimport type { BuildContext, PluginConfig } from '../types.js'\nimport {
|
|
10
|
-
"const LEVELS = {\n\tdebug: 0,\n\tinfo: 1,\n\twarn: 2,\n\terror: 3,\n\tfatal: 4,\n} as const\n\nexport type LogLevel = keyof typeof LEVELS\n\ntype LogEntry = {\n\tts: number\n\tlevel: LogLevel\n\tmessage: string\n\terror?:\n\t\t| Error\n\t\t| {\n\t\t\t\tmessage: string\n\t\t\t\tstack?: string\n\t\t\t\tcause?: unknown\n\t\t }\n}\n\n/**\n * Log messages with different severity levels
|
|
9
|
+
"import { realpathSync } from 'node:fs'\nimport fs from 'node:fs/promises'\nimport path from 'node:path'\n\nimport { type Plugin, type ViteDevServer } from 'vite'\n\nimport type { BuildContext, PluginConfig } from '../types.js'\nimport { collect, flattenTags, isENOENT, writeTypes } from '../build.js'\nimport { GENERATED_DIR } from '../config.js'\nimport { Logger } from '../logger.js'\nimport { debounce } from '../utils.js'\n\nconst ACCEPTED_EXTENSIONS = new Set(['.js', '.jsx', '.ts', '.tsx'])\n\nfunction normaliseWatchPath(p: string) {\n\treturn p.replace(/\\\\/g, '/')\n}\n\nexport default function cxx(pluginConfig: PluginConfig = {}) {\n\tconst buildContext = {\n\t\ttagsByFile: new Map(),\n\t} satisfies BuildContext\n\n\tconst logger = new Logger(\n\t\t(pluginConfig?.logger?.level ?? process.env.NODE_ENV === 'production')\n\t\t\t? 'error'\n\t\t\t: 'debug',\n\t)\n\n\t// write generated files into a hidden folder at the project root\n\t// keep the generated surface out of src\n\tconst watchRoot = normaliseWatchPath(realpathSync.native(process.cwd()))\n\tconst watchedRoots = [`${watchRoot}/`]\n\n\tlet rebuildRunning = false\n\tlet rebuildQueued = false\n\n\t// watcher events can arrive through symlinked paths like /var while cwd has\n\t// already resolved to /private/var, so canonicalise the parent dir once and\n\t// reattach the file name for stable prefix checks\n\tfunction resolveWatchFile(filePath: string) {\n\t\tconst absolutePath = path.resolve(watchRoot, filePath)\n\t\tconst parentPath = path.dirname(absolutePath)\n\n\t\ttry {\n\t\t\tconst resolvedParentPath = normaliseWatchPath(realpathSync.native(parentPath))\n\n\t\t\treturn normaliseWatchPath(\n\t\t\t\tpath.join(resolvedParentPath, path.basename(absolutePath)),\n\t\t\t)\n\t\t} catch {\n\t\t\treturn normaliseWatchPath(absolutePath)\n\t\t}\n\t}\n\n\tfunction watchedFile(filePath: string) {\n\t\tconst resolvedPath = resolveWatchFile(filePath)\n\n\t\treturn (\n\t\t\twatchedRoots.some(root => resolvedPath.startsWith(root)) &&\n\t\t\t!resolvedPath.includes(`/${GENERATED_DIR}/`) &&\n\t\t\tACCEPTED_EXTENSIONS.has(path.extname(resolvedPath))\n\t\t)\n\t}\n\n\tconst rebuild = debounce((event: 'add' | 'change' | 'unlink', filePath: string) => {\n\t\tfunction queue() {\n\t\t\tvoid (async () => {\n\t\t\t\t// collapse bursts of file events into one active rebuild plus a single\n\t\t\t\t// queued rerun when changes land mid-build\n\t\t\t\tif (rebuildRunning) {\n\t\t\t\t\trebuildQueued = true\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\trebuildRunning = true\n\n\t\t\t\tdo {\n\t\t\t\t\trebuildQueued = false\n\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst hadTags = buildContext.tagsByFile.has(file)\n\t\t\t\t\t\tlet hasTags = false\n\n\t\t\t\t\t\tif (event === 'unlink') {\n\t\t\t\t\t\t\tbuildContext.tagsByFile.delete(file)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst source = await fs.readFile(file, 'utf-8')\n\t\t\t\t\t\t\tconst { tags } = collect(source, file, pluginConfig)\n\n\t\t\t\t\t\t\thasTags = tags.size > 0\n\n\t\t\t\t\t\t\tif (hasTags) {\n\t\t\t\t\t\t\t\tbuildContext.tagsByFile.set(file, tags)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tbuildContext.tagsByFile.delete(file)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (!hadTags && !hasTags) continue\n\n\t\t\t\t\t\tawait writeTypes(flattenTags(buildContext.tagsByFile))\n\t\t\t\t\t\tlogger.info(`updated types from ${file}`)\n\t\t\t\t\t} catch (err) {\n\t\t\t\t\t\tif (isENOENT(err)) {\n\t\t\t\t\t\t\tif (!buildContext.tagsByFile.has(file)) continue\n\n\t\t\t\t\t\t\tbuildContext.tagsByFile.delete(file)\n\t\t\t\t\t\t\tawait writeTypes(flattenTags(buildContext.tagsByFile))\n\n\t\t\t\t\t\t\tlogger.info(`updated types from ${file}`)\n\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlogger.error(`failed to update types from ${file}`, err)\n\t\t\t\t\t}\n\t\t\t\t} while (rebuildQueued)\n\n\t\t\t\trebuildRunning = false\n\t\t\t})()\n\t\t}\n\n\t\t// ignore anything outside the watched content dirs\n\t\tif (!watchedFile(filePath)) return\n\n\t\tconst file = resolveWatchFile(filePath)\n\t\tqueue()\n\t}, 75)\n\n\treturn {\n\t\tname: 'cxx',\n\t\tenforce: 'pre',\n\t\ttransform(code, id) {\n\t\t\tconst { template, tags } = collect(code, id, pluginConfig)\n\n\t\t\tif (tags.size) buildContext.tagsByFile.set(id, tags)\n\n\t\t\treturn {\n\t\t\t\tcode: template,\n\t\t\t\tmap: null,\n\t\t\t}\n\t\t},\n\t\tconfigureServer(server: ViteDevServer) {\n\t\t\tlogger.info('Watching for changes...')\n\n\t\t\tserver.watcher\n\t\t\t\t.on('add', (p: string) => rebuild('add', p))\n\t\t\t\t.on('change', (p: string) => rebuild('change', p))\n\t\t\t\t.on('unlink', (p: string) => rebuild('unlink', p))\n\t\t},\n\t\tasync writeBundle() {\n\t\t\tawait writeTypes(flattenTags(buildContext.tagsByFile))\n\t\t},\n\t} satisfies Plugin\n}\n",
|
|
10
|
+
"const LEVELS = {\n\tdebug: 0,\n\tinfo: 1,\n\twarn: 2,\n\terror: 3,\n\tfatal: 4,\n} as const\n\nexport type LogLevel = keyof typeof LEVELS\n\ntype LogEntry = {\n\tts: number\n\tlevel: LogLevel\n\tmessage: string\n\terror?:\n\t\t| Error\n\t\t| {\n\t\t\t\tmessage: string\n\t\t\t\tstack?: string\n\t\t\t\tcause?: unknown\n\t\t }\n}\n\n/**\n * Log messages with different severity levels.\n */\nexport class Logger {\n\tstatic #defaultLevel: LogLevel = 'info'\n\n\t#level?: LogLevel\n\n\tconstructor(\n\t\tlevel?: LogLevel,\n\t\tpublic name?: string,\n\t) {\n\t\tthis.#level = level\n\t}\n\n\tstatic set defaultLevel(level: LogLevel) {\n\t\tLogger.#defaultLevel = level\n\t}\n\n\tstatic get defaultLevel() {\n\t\treturn Logger.#defaultLevel\n\t}\n\n\t/**\n\t * Convert a value to an Error instance.\n\t */\n\tstatic toError(err: unknown) {\n\t\treturn err instanceof Error ? err : new Error(String(err), { cause: err })\n\t}\n\n\t/**\n\t * Stringify the error for logging.\n\t */\n\tstatic print(err: unknown) {\n\t\tif (err instanceof Error) {\n\t\t\treturn err.message + (err.stack ? `\\n${err.stack}` : '')\n\t\t}\n\n\t\t// for plain objects, attempt to stringify with indentation\n\t\t// for readability\n\t\tif (typeof err === 'object' && err !== null) {\n\t\t\ttry {\n\t\t\t\treturn JSON.stringify(err, null, 2)\n\t\t\t} catch {\n\t\t\t\t// if stringify fails (e.g. circular reference), fall back\n\t\t\t\t// to basic string conversion\n\t\t\t\treturn String(err)\n\t\t\t}\n\t\t}\n\n\t\treturn String(err)\n\t}\n\n\tset level(level: LogLevel) {\n\t\tthis.#level = level\n\t}\n\n\tget level() {\n\t\treturn this.#level ?? Logger.#defaultLevel\n\t}\n\n\t/**\n\t * Log a message with a specific level.\n\t */\n\tlog(level: LogLevel, message: string, error?: Error) {\n\t\tif (LEVELS[level] < LEVELS[this.level]) return\n\n\t\tconst entry: LogEntry = {\n\t\t\tts: Date.now(),\n\t\t\tlevel,\n\t\t\tmessage,\n\t\t}\n\n\t\tif (level === 'error' || level === 'fatal') {\n\t\t\tentry.error = error ? Logger.toError(error) : new Error(message)\n\t\t}\n\n\t\tconst line = `${this.name ? `[${this.name}]` : ''} [${entry.ts}] [${level.toUpperCase()}] ${message}`\n\t\tconst extra = entry.error ? `\\n${Logger.print(entry.error)}` : ''\n\n\t\tif (level === 'warn') {\n\t\t\tconsole.warn(line, extra)\n\t\t\treturn\n\t\t}\n\n\t\tif (level === 'error' || level === 'fatal') {\n\t\t\tconsole.error(line, extra)\n\t\t\treturn\n\t\t}\n\n\t\tconsole.log(line, extra)\n\t}\n\n\t/**\n\t * Log a debug message.\n\t */\n\tdebug(...messages: string[]) {\n\t\tthis.log('debug', messages.join(' '))\n\t}\n\n\t/**\n\t * Log an info message.\n\t */\n\tinfo(...messages: string[]) {\n\t\tthis.log('info', messages.join(' '))\n\t}\n\n\t/**\n\t * Log a warning message.\n\t */\n\twarn(...messages: string[]) {\n\t\tthis.log('warn', messages.join(' '))\n\t}\n\n\t/**\n\t * Log an error message.\n\t */\n\terror(message: string, error?: unknown) {\n\t\tthis.log('error', message, error === undefined ? undefined : Logger.toError(error))\n\t}\n\n\t/**\n\t * Log a fatal error message.\n\t */\n\tfatal(message: string, error?: unknown) {\n\t\tthis.log('fatal', message, error === undefined ? undefined : Logger.toError(error))\n\t}\n}\n"
|
|
11
11
|
],
|
|
12
|
-
"mappings": ";AAAA;AACA;AACA;AAEA;;;ACJO,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,EAC7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k2908/cxx",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Jerome Kenway",
|
|
6
6
|
"repository": {
|
|
@@ -9,9 +9,13 @@
|
|
|
9
9
|
},
|
|
10
10
|
"main": "./dist/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
12
15
|
"scripts": {
|
|
13
16
|
"build": "bun run ./build.ts && bun x tsc --project tsconfig.json --emitDeclarationOnly",
|
|
14
|
-
"prepack": "npm run build"
|
|
17
|
+
"prepack": "npm run build",
|
|
18
|
+
"test": "bunx vitest"
|
|
15
19
|
},
|
|
16
20
|
"dependencies": {
|
|
17
21
|
"@parcel/watcher": "^2.5.6",
|
|
@@ -20,20 +24,20 @@
|
|
|
20
24
|
"devDependencies": {
|
|
21
25
|
"@types/bun": "^1.3.13",
|
|
22
26
|
"@types/node": "^24.0.1",
|
|
23
|
-
"@types/react": "
|
|
24
|
-
"@types/react-dom": "
|
|
27
|
+
"@types/react": "^19.2.17",
|
|
28
|
+
"@types/react-dom": "^19.2.3",
|
|
25
29
|
"@typescript/native-preview": "^7.0.0-dev.20260421.2",
|
|
26
30
|
"next": "^16.2.10",
|
|
27
|
-
"react": "^19.
|
|
28
|
-
"react-dom": "^19.
|
|
31
|
+
"react": "^19.2.7",
|
|
32
|
+
"react-dom": "^19.2.7",
|
|
29
33
|
"typescript": "^5.5.4",
|
|
30
|
-
"vite": "^
|
|
34
|
+
"vite": "^8.1.5",
|
|
35
|
+
"vitest": "^4.1.10"
|
|
31
36
|
},
|
|
32
37
|
"peerDependencies": {
|
|
33
38
|
"next": "^15.3.0 || ^16.0.0",
|
|
34
39
|
"react": "^19.0.0-rc || ^19.0.0-beta || ^19.0.0",
|
|
35
|
-
"react-dom": "^19.0.0-rc || ^19.0.0-beta || ^19.0.0"
|
|
36
|
-
"vite": "^4.0.0"
|
|
40
|
+
"react-dom": "^19.0.0-rc || ^19.0.0-beta || ^19.0.0"
|
|
37
41
|
},
|
|
38
42
|
"exports": {
|
|
39
43
|
".": {
|
package/src/build.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import fs from 'node:fs/promises'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { transform } from 'lightningcss'
|
|
6
|
+
|
|
7
|
+
import type { BuildContext, PluginConfig, Tags } from './types.js'
|
|
8
|
+
import { AUTOGEN_MSG, GENERATED_DIR, PKG_NAME } from './config.js'
|
|
9
|
+
import { LruCache } from './lru.js'
|
|
10
|
+
import { pascalise } from './utils.js'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* LRU cache of `collect` results by file id and last seen source so watcher and transform can
|
|
14
|
+
* reuse the same parsed template/tags.
|
|
15
|
+
*/
|
|
16
|
+
const collectCache = new LruCache<{ source: string; template: string; tags: Tags }>()
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* LRU cache for file content. Stores the last written content per file path so `maybeWrite`
|
|
20
|
+
* can skip disk i/o when nothing has changed.
|
|
21
|
+
*/
|
|
22
|
+
const fileCache = new LruCache<string>()
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Returns whether the error was caused by a missing file or directory.
|
|
26
|
+
*/
|
|
27
|
+
export function isENOENT(err: unknown) {
|
|
28
|
+
return err instanceof Error && 'code' in err && err.code === 'ENOENT'
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Write a file only if the content has changed since the last build.
|
|
33
|
+
*/
|
|
34
|
+
export async function maybeWrite(filePath: string, content: string) {
|
|
35
|
+
const cached = fileCache.get(filePath)
|
|
36
|
+
|
|
37
|
+
if (cached !== content) {
|
|
38
|
+
// cache says content changed, write without reading
|
|
39
|
+
await fs.writeFile(filePath, content)
|
|
40
|
+
fileCache.set(filePath, content)
|
|
41
|
+
|
|
42
|
+
return true
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// cache miss or cache hit with same content — verify on disk
|
|
46
|
+
try {
|
|
47
|
+
if ((await fs.readFile(filePath, 'utf-8')) === content) {
|
|
48
|
+
fileCache.set(filePath, content)
|
|
49
|
+
return false
|
|
50
|
+
}
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (!isENOENT(err)) throw err
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await fs.writeFile(filePath, content)
|
|
56
|
+
fileCache.set(filePath, content)
|
|
57
|
+
|
|
58
|
+
return true
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// matches `[css, classes, href] = cxx\`...\`` and `cxx.tag<T>('name')\`...\``
|
|
62
|
+
// capture groups: 1-3 assigned variable names, 4 plain css body, 5 quote
|
|
63
|
+
// kind, 6 tag name, 7 tagged css body
|
|
64
|
+
const regex =
|
|
65
|
+
/(?: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
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Hash transformed CSS into a stable href for style deduplication.
|
|
69
|
+
*/
|
|
70
|
+
function hashCss(code: Uint8Array) {
|
|
71
|
+
return `cxx-${createHash('sha256').update(code).digest('base64url').slice(0, 12)}`
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export class DuplicateTagError extends Error {
|
|
75
|
+
name = 'DuplicateTagError'
|
|
76
|
+
|
|
77
|
+
constructor(tag: string) {
|
|
78
|
+
super(`Tag ${tag} has already been seen. Tags must be unique across your application`)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Transform `cxx` templates in one source file and collect any exported tag types.
|
|
84
|
+
*/
|
|
85
|
+
export function collect(source: string, id: string, config: PluginConfig) {
|
|
86
|
+
const tags: Tags = new Map()
|
|
87
|
+
|
|
88
|
+
const cached = collectCache.get(id)
|
|
89
|
+
if (cached?.source === source) return cached
|
|
90
|
+
|
|
91
|
+
const template = source.replace(
|
|
92
|
+
regex,
|
|
93
|
+
(_match, varOne, varTwo, varThree, plainCss, _quote, tag, taggedCss) => {
|
|
94
|
+
const css = plainCss ?? taggedCss
|
|
95
|
+
|
|
96
|
+
const { code, exports = {} } = transform({
|
|
97
|
+
minify: true,
|
|
98
|
+
cssModules: true,
|
|
99
|
+
filename: id,
|
|
100
|
+
code: new TextEncoder().encode(css),
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const href = hashCss(code)
|
|
104
|
+
const styles = Object.fromEntries(
|
|
105
|
+
Object.entries(exports).map(([k, v]) => [k, v.name]),
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
if (tag) {
|
|
109
|
+
const suffix =
|
|
110
|
+
typeof config.typeSuffix === 'string'
|
|
111
|
+
? config.typeSuffix
|
|
112
|
+
: config.typeSuffix === false
|
|
113
|
+
? ''
|
|
114
|
+
: 'Classes'
|
|
115
|
+
const tagWithSuffix = pascalise(`${tag}${suffix}`)
|
|
116
|
+
|
|
117
|
+
if (tags.has(tagWithSuffix)) throw new DuplicateTagError(tagWithSuffix)
|
|
118
|
+
|
|
119
|
+
// side effect but neccessary
|
|
120
|
+
tags.set(tagWithSuffix, Object.keys(styles))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return [
|
|
124
|
+
varOne && `const ${varOne} = \`${code}\``,
|
|
125
|
+
varTwo && `const ${varTwo} = ${JSON.stringify(styles)}`,
|
|
126
|
+
varThree && `const ${varThree} = \`${href}\``,
|
|
127
|
+
]
|
|
128
|
+
.filter(Boolean)
|
|
129
|
+
.join('\n')
|
|
130
|
+
},
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
// cache
|
|
134
|
+
collectCache.set(id, { source, template, tags })
|
|
135
|
+
|
|
136
|
+
return {
|
|
137
|
+
template,
|
|
138
|
+
tags,
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Write the generated declaration file for the current set of collected tags.
|
|
144
|
+
*/
|
|
145
|
+
export async function writeTypes(tags: Tags) {
|
|
146
|
+
const filePath = path.join(GENERATED_DIR, 'index.d.ts')
|
|
147
|
+
|
|
148
|
+
if (!tags.size) {
|
|
149
|
+
try {
|
|
150
|
+
await fs.rm(filePath, { force: true })
|
|
151
|
+
fileCache.delete(filePath)
|
|
152
|
+
} catch (err) {
|
|
153
|
+
if (!isENOENT(err)) throw err
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
await fs.mkdir(GENERATED_DIR, { recursive: true })
|
|
160
|
+
|
|
161
|
+
await maybeWrite(
|
|
162
|
+
filePath,
|
|
163
|
+
`${AUTOGEN_MSG}
|
|
164
|
+
|
|
165
|
+
import '${PKG_NAME}'
|
|
166
|
+
|
|
167
|
+
declare module '${PKG_NAME}' {
|
|
168
|
+
${tagsToType(tags)}
|
|
169
|
+
}
|
|
170
|
+
`,
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Render collected tags as a module augmentation for the package entrypoint.
|
|
176
|
+
*/
|
|
177
|
+
export function tagsToType(tags: Tags) {
|
|
178
|
+
return [...tags]
|
|
179
|
+
.map(
|
|
180
|
+
([tag, classes]) => `
|
|
181
|
+
export type ${tag} = ${
|
|
182
|
+
classes.length > 0
|
|
183
|
+
? classes
|
|
184
|
+
.toSorted((a, b) => a.length - b.length)
|
|
185
|
+
.map(c => `'${c}'`)
|
|
186
|
+
.join(' | ')
|
|
187
|
+
: 'never'
|
|
188
|
+
}
|
|
189
|
+
`,
|
|
190
|
+
)
|
|
191
|
+
.join('\n')
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Merge per-file tag maps into one application-wide tag map.
|
|
196
|
+
*/
|
|
197
|
+
export function flattenTags(tagsByFile: BuildContext['tagsByFile']) {
|
|
198
|
+
const tags = new Map<string, string[]>()
|
|
199
|
+
|
|
200
|
+
for (const fileTags of tagsByFile.values()) {
|
|
201
|
+
for (const [name, classes] of fileTags) {
|
|
202
|
+
if (tags.has(name)) throw new DuplicateTagError(name)
|
|
203
|
+
tags.set(name, classes)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return tags
|
|
208
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,212 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import fs from 'node:fs/promises'
|
|
3
|
-
import path from 'node:path'
|
|
1
|
+
import type { Cxx, Result } from './types.js'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import type { BuildContext, Cxx, PluginConfig, Result, Tags } from './types.js'
|
|
8
|
-
import { AUTOGEN_MSG, GENERATED_DIR, PKG_NAME } from './config.js'
|
|
9
|
-
import { LruCache } from './lru.js'
|
|
10
|
-
import { pascalise } from './utils.js'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* LRU cache of `collect` results by file id and last seen source so watcher and transform can
|
|
14
|
-
* reuse the same parsed template/tags
|
|
15
|
-
*/
|
|
16
|
-
const collectCache = new LruCache<{ source: string; template: string; tags: Tags }>()
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* LRU cache for file content. Stores the last written content per file path so `maybeWrite`
|
|
20
|
-
* can skip disk i/o when nothing has changed
|
|
21
|
-
*/
|
|
22
|
-
const fileCache = new LruCache<string>()
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Returns whether the error was caused by a missing file or directory
|
|
26
|
-
*/
|
|
27
|
-
export function isENOENT(err: unknown) {
|
|
28
|
-
return err instanceof Error && 'code' in err && err.code === 'ENOENT'
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Write a file only if the content has changed since the last build
|
|
33
|
-
*/
|
|
34
|
-
export async function maybeWrite(filePath: string, content: string) {
|
|
35
|
-
const cached = fileCache.get(filePath)
|
|
36
|
-
|
|
37
|
-
if (cached !== content) {
|
|
38
|
-
// cache says content changed, write without reading
|
|
39
|
-
await fs.writeFile(filePath, content)
|
|
40
|
-
fileCache.set(filePath, content)
|
|
41
|
-
|
|
42
|
-
return true
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// cache miss or cache hit with same content — verify on disk
|
|
46
|
-
try {
|
|
47
|
-
if ((await fs.readFile(filePath, 'utf-8')) === content) {
|
|
48
|
-
fileCache.set(filePath, content)
|
|
49
|
-
return false
|
|
50
|
-
}
|
|
51
|
-
} catch (err) {
|
|
52
|
-
if (!isENOENT(err)) throw err
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
await fs.writeFile(filePath, content)
|
|
56
|
-
fileCache.set(filePath, content)
|
|
57
|
-
|
|
58
|
-
return true
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// matches `[css, classes, href] = cxx\`...\`` and `cxx.tag<T>('name')\`...\``
|
|
62
|
-
// capture groups: 1-3 assigned variable names, 4 plain css body, 5 quote
|
|
63
|
-
// kind, 6 tag name, 7 tagged css body
|
|
64
|
-
const regex =
|
|
65
|
-
/(?: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
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Hash transformed CSS into a stable href for style deduplication
|
|
69
|
-
*/
|
|
70
|
-
function hashCss(code: Uint8Array) {
|
|
71
|
-
return `cxx-${createHash('sha256').update(code).digest('base64url').slice(0, 12)}`
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export class TagDuplicateError extends Error {
|
|
75
|
-
constructor(tag: string) {
|
|
76
|
-
super(`Tag ${tag} has already been seen. Tags must be unique across your application`)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Transform `cxx` templates in one source file and collect any exported tag types
|
|
82
|
-
*/
|
|
83
|
-
export function collect(source: string, id: string, config: PluginConfig) {
|
|
84
|
-
const tags: Tags = new Map()
|
|
85
|
-
|
|
86
|
-
const cached = collectCache.get(id)
|
|
87
|
-
if (cached?.source === source) return cached
|
|
88
|
-
|
|
89
|
-
const template = source.replace(
|
|
90
|
-
regex,
|
|
91
|
-
(_match, varOne, varTwo, varThree, plainCss, _quote, tag, taggedCss) => {
|
|
92
|
-
const css = plainCss ?? taggedCss
|
|
93
|
-
|
|
94
|
-
const { code, exports = {} } = transform({
|
|
95
|
-
minify: true,
|
|
96
|
-
cssModules: true,
|
|
97
|
-
filename: id,
|
|
98
|
-
code: new TextEncoder().encode(css),
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
const href = hashCss(code)
|
|
102
|
-
const styles = Object.fromEntries(
|
|
103
|
-
Object.entries(exports).map(([k, v]) => [k, v.name]),
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
if (tag) {
|
|
107
|
-
const suffix =
|
|
108
|
-
typeof config.typeSuffix === 'string'
|
|
109
|
-
? config.typeSuffix
|
|
110
|
-
: config.typeSuffix === false
|
|
111
|
-
? ''
|
|
112
|
-
: 'Classes'
|
|
113
|
-
const tagWithSuffix = pascalise(`${tag}${suffix}`)
|
|
114
|
-
|
|
115
|
-
if (tags.has(tagWithSuffix)) throw new TagDuplicateError(tagWithSuffix)
|
|
116
|
-
|
|
117
|
-
// side effect but neccessary
|
|
118
|
-
tags.set(tagWithSuffix, Object.keys(styles))
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return [
|
|
122
|
-
varOne && `const ${varOne} = \`${code}\``,
|
|
123
|
-
varTwo && `const ${varTwo} = ${JSON.stringify(styles)}`,
|
|
124
|
-
varThree && `const ${varThree} = \`${href}\``,
|
|
125
|
-
]
|
|
126
|
-
.filter(Boolean)
|
|
127
|
-
.join('\n')
|
|
128
|
-
},
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
// cache
|
|
132
|
-
collectCache.set(id, { source, template, tags })
|
|
133
|
-
|
|
134
|
-
return {
|
|
135
|
-
template,
|
|
136
|
-
tags,
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Write the generated declaration file for the current set of collected tags
|
|
142
|
-
*/
|
|
143
|
-
export async function writeTypes(tags: Tags) {
|
|
144
|
-
const filePath = path.join(GENERATED_DIR, 'index.d.ts')
|
|
145
|
-
|
|
146
|
-
if (!tags.size) {
|
|
147
|
-
try {
|
|
148
|
-
await fs.rm(filePath, { force: true })
|
|
149
|
-
fileCache.delete(filePath)
|
|
150
|
-
} catch (err) {
|
|
151
|
-
if (!isENOENT(err)) throw err
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
await fs.mkdir(GENERATED_DIR, { recursive: true })
|
|
158
|
-
|
|
159
|
-
await maybeWrite(
|
|
160
|
-
filePath,
|
|
161
|
-
`${AUTOGEN_MSG}
|
|
162
|
-
|
|
163
|
-
import '${PKG_NAME}'
|
|
164
|
-
|
|
165
|
-
declare module '${PKG_NAME}' {
|
|
166
|
-
${tagsToType(tags)}
|
|
167
|
-
}
|
|
168
|
-
`,
|
|
169
|
-
)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Render collected tags as a module augmentation for the package entrypoint
|
|
174
|
-
*/
|
|
175
|
-
export function tagsToType(tags: Tags) {
|
|
176
|
-
return [...tags]
|
|
177
|
-
.map(
|
|
178
|
-
([tag, classes]) => `
|
|
179
|
-
export type ${tag} = ${
|
|
180
|
-
classes.length > 0
|
|
181
|
-
? classes
|
|
182
|
-
.toSorted((a, b) => a.length - b.length)
|
|
183
|
-
.map(c => `'${c}'`)
|
|
184
|
-
.join(' | ')
|
|
185
|
-
: 'never'
|
|
186
|
-
}
|
|
187
|
-
`,
|
|
188
|
-
)
|
|
189
|
-
.join('\n')
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Merge per-file tag maps into one application-wide tag map
|
|
194
|
-
*/
|
|
195
|
-
export function flattenTags(tagsByFile: BuildContext['tagsByFile']) {
|
|
196
|
-
const tags = new Map<string, string[]>()
|
|
197
|
-
|
|
198
|
-
for (const fileTags of tagsByFile.values()) {
|
|
199
|
-
for (const [name, classes] of fileTags) {
|
|
200
|
-
if (tags.has(name)) throw new TagDuplicateError(name)
|
|
201
|
-
tags.set(name, classes)
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
return tags
|
|
206
|
-
}
|
|
3
|
+
export type { Cxx, Result, Tag } from './types.js'
|
|
207
4
|
|
|
208
5
|
/**
|
|
209
|
-
* Build-time template tag placeholder used by the transform to emit CSS, classes and href values
|
|
6
|
+
* Build-time template tag placeholder used by the transform to emit CSS, classes and href values.
|
|
210
7
|
*/
|
|
211
8
|
export const cxx: Cxx = Object.assign((_: TemplateStringsArray): Result => ['', {}, ''], {
|
|
212
9
|
tag:
|