@animus-ui/vite-plugin 0.1.0-next.62 → 0.1.0-next.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +68 -23
- package/package.json +11 -5
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,16 @@ export interface AnimusExtractOptions {
|
|
|
11
11
|
include?: string[];
|
|
12
12
|
/** Glob patterns to exclude. */
|
|
13
13
|
exclude?: string[];
|
|
14
|
+
/**
|
|
15
|
+
* File extensions to scan for component definitions and JSX usages.
|
|
16
|
+
* Replaces the default list entirely (not additive). Include `.mdx` to
|
|
17
|
+
* extract components rendered from MDX files — `@mdx-js/mdx` must be
|
|
18
|
+
* installed as a peer for MDX files to be preprocessed; otherwise the
|
|
19
|
+
* plugin warns once at buildStart and skips them.
|
|
20
|
+
*
|
|
21
|
+
* @default ['.ts', '.tsx', '.js', '.jsx', '.mdx']
|
|
22
|
+
*/
|
|
23
|
+
extensions?: string[];
|
|
14
24
|
/** When true, extraction failures throw instead of warning. Use in CI to enforce full extraction. */
|
|
15
25
|
strict?: boolean;
|
|
16
26
|
/**
|
|
@@ -45,6 +55,7 @@ export interface AnimusExtractOptions {
|
|
|
45
55
|
*/
|
|
46
56
|
layers?: string[];
|
|
47
57
|
}
|
|
58
|
+
export declare function discoverFiles(dir: string, rootDir: string, excludePatterns: string[], extensionsSet: ReadonlySet<string>): string[];
|
|
48
59
|
export declare function animusExtract(options: AnimusExtractOptions): Plugin;
|
|
49
60
|
export default animusExtract;
|
|
50
61
|
//# 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":"AAmBA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,MAAM,CAAC;AAE3C,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,gCAAgC;IAChC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,qGAAqG;IACrG,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,2EAA2E;IAC3E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAgBD,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,MAAM,EAAE,EACzB,aAAa,EAAE,WAAW,CAAC,MAAM,CAAC,GACjC,MAAM,EAAE,CAqCV;AAqFD,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAsrCnE;eAEc,aAAa"}
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { createHash } from "crypto";
|
|
3
3
|
import { existsSync, readFileSync, readdirSync, statSync } from "fs";
|
|
4
4
|
import { dirname, extname, join, relative, resolve } from "path";
|
|
5
|
-
import { applyUnitFallback, assembleStylesheet, extractSystemFilePackages, stripLeadingLayerDeclaration, validateLayerOrder } from "@animus-ui/extract/pipeline";
|
|
5
|
+
import { DEFAULT_EXTENSIONS, applyUnitFallback, assembleStylesheet, extractSystemFilePackages, preprocessMdx, stripLeadingLayerDeclaration, validateLayerOrder } from "@animus-ui/extract/pipeline";
|
|
6
6
|
import browserslist from "browserslist";
|
|
7
7
|
import { browserslistToTargets, transform } from "lightningcss";
|
|
8
8
|
//#region \0rolldown/runtime.js
|
|
@@ -17,19 +17,13 @@ const VIRTUAL_BRIDGE_ID = "virtual:animus/hmr-bridge.js";
|
|
|
17
17
|
const RESOLVED_BRIDGE_ID = "\0virtual:animus/hmr-bridge.js";
|
|
18
18
|
const VIRTUAL_SYSTEM_PROPS_ID = "virtual:animus/system-props";
|
|
19
19
|
const RESOLVED_SYSTEM_PROPS_ID = "\0virtual:animus/system-props";
|
|
20
|
-
const DEFAULT_EXTENSIONS = new Set([
|
|
21
|
-
".ts",
|
|
22
|
-
".tsx",
|
|
23
|
-
".js",
|
|
24
|
-
".jsx"
|
|
25
|
-
]);
|
|
26
20
|
const DEFAULT_EXCLUDE = [
|
|
27
21
|
"node_modules",
|
|
28
22
|
"dist",
|
|
29
23
|
".test.",
|
|
30
24
|
".spec."
|
|
31
25
|
];
|
|
32
|
-
function discoverFiles(dir, rootDir, excludePatterns) {
|
|
26
|
+
function discoverFiles(dir, rootDir, excludePatterns, extensionsSet) {
|
|
33
27
|
const results = [];
|
|
34
28
|
let entries;
|
|
35
29
|
try {
|
|
@@ -47,8 +41,8 @@ function discoverFiles(dir, rootDir, excludePatterns) {
|
|
|
47
41
|
} catch {
|
|
48
42
|
continue;
|
|
49
43
|
}
|
|
50
|
-
if (stat.isDirectory()) results.push(...discoverFiles(fullPath, rootDir, excludePatterns));
|
|
51
|
-
else if (
|
|
44
|
+
if (stat.isDirectory()) results.push(...discoverFiles(fullPath, rootDir, excludePatterns, extensionsSet));
|
|
45
|
+
else if (extensionsSet.has(extname(entry))) results.push(fullPath);
|
|
52
46
|
}
|
|
53
47
|
return results;
|
|
54
48
|
}
|
|
@@ -148,6 +142,7 @@ function animusExtract(options) {
|
|
|
148
142
|
let globalStyleBlocksJson = null;
|
|
149
143
|
let keyframesBlocksJson = null;
|
|
150
144
|
let pathAliasesJson = null;
|
|
145
|
+
let extensionsSet = new Set(options.extensions ?? DEFAULT_EXTENSIONS);
|
|
151
146
|
let storedManifest = null;
|
|
152
147
|
let storedManifestJson = "";
|
|
153
148
|
let resolvedComponentCss = "";
|
|
@@ -327,11 +322,30 @@ function animusExtract(options) {
|
|
|
327
322
|
}
|
|
328
323
|
t0 = performance.now();
|
|
329
324
|
const excludePatterns = options.exclude ?? DEFAULT_EXCLUDE;
|
|
330
|
-
|
|
325
|
+
extensionsSet = new Set(options.extensions ?? DEFAULT_EXTENSIONS);
|
|
326
|
+
const shouldHandleMdx = extensionsSet.has(".mdx");
|
|
327
|
+
let mdxMissingDepWarned = false;
|
|
328
|
+
const filePaths = discoverFiles(rootDir, rootDir, excludePatterns, extensionsSet);
|
|
331
329
|
const fileEntries = [];
|
|
332
330
|
for (const filePath of filePaths) try {
|
|
333
|
-
|
|
334
|
-
|
|
331
|
+
let source = readFileSync(filePath, "utf-8");
|
|
332
|
+
let relPath = relative(rootDir, filePath);
|
|
333
|
+
if (shouldHandleMdx && extname(filePath) === ".mdx") {
|
|
334
|
+
const result = await preprocessMdx(source, relPath);
|
|
335
|
+
if (result.kind === "missing-dep") {
|
|
336
|
+
if (!mdxMissingDepWarned) {
|
|
337
|
+
warn("⚠ .mdx in extensions but @mdx-js/mdx not installed; MDX files skipped");
|
|
338
|
+
mdxMissingDepWarned = true;
|
|
339
|
+
}
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if (result.kind === "error") {
|
|
343
|
+
warn(`⚠ MDX preprocessing failed for ${relPath}: ${result.error}`);
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
source = result.source;
|
|
347
|
+
relPath = relPath + ".tsx";
|
|
348
|
+
}
|
|
335
349
|
const hash = !isProd ? contentHash(source) : void 0;
|
|
336
350
|
fileEntries.push({
|
|
337
351
|
path: relPath,
|
|
@@ -357,11 +371,27 @@ function animusExtract(options) {
|
|
|
357
371
|
const srcDir = join(pkgRoot, "src");
|
|
358
372
|
if (existsSync(srcDir)) {
|
|
359
373
|
collectedPkgDirs.push(srcDir);
|
|
360
|
-
const pkgFiles = discoverFiles(srcDir, rootDir, excludePatterns);
|
|
374
|
+
const pkgFiles = discoverFiles(srcDir, rootDir, excludePatterns, extensionsSet);
|
|
361
375
|
for (const pkgFile of pkgFiles) {
|
|
362
|
-
|
|
376
|
+
let pkgRelPath = relative(rootDir, pkgFile);
|
|
363
377
|
if (!fileEntries.some((e) => e.path === pkgRelPath)) {
|
|
364
|
-
|
|
378
|
+
let pkgSource = readFileSync(pkgFile, "utf-8");
|
|
379
|
+
if (shouldHandleMdx && extname(pkgFile) === ".mdx") {
|
|
380
|
+
const result = await preprocessMdx(pkgSource, pkgRelPath);
|
|
381
|
+
if (result.kind === "missing-dep") {
|
|
382
|
+
if (!mdxMissingDepWarned) {
|
|
383
|
+
warn("⚠ .mdx in extensions but @mdx-js/mdx not installed; MDX files skipped");
|
|
384
|
+
mdxMissingDepWarned = true;
|
|
385
|
+
}
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
if (result.kind === "error") {
|
|
389
|
+
warn(`⚠ MDX preprocessing failed for ${pkgRelPath}: ${result.error}`);
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
pkgSource = result.source;
|
|
393
|
+
pkgRelPath = pkgRelPath + ".tsx";
|
|
394
|
+
}
|
|
365
395
|
const pkgHash = !isProd ? contentHash(pkgSource) : void 0;
|
|
366
396
|
fileEntries.push({
|
|
367
397
|
path: pkgRelPath,
|
|
@@ -412,6 +442,7 @@ function animusExtract(options) {
|
|
|
412
442
|
log(`Reconciliation: ${report.components_extracted} kept, ${report.variants_eliminated} variants pruned, ${report.states_eliminated} states pruned`);
|
|
413
443
|
const details = report.eliminated_details || [];
|
|
414
444
|
for (const d of details) if (d.kind === "component") warn(`⚠ ${d.component} eliminated: ${d.reason}`);
|
|
445
|
+
else if (d.kind === "prospective_component") warn(`⚠ ${d.component} would be eliminated in production: ${d.reason}`);
|
|
415
446
|
else if (d.kind === "variant") warn(`⚠ ${d.component} variant '${d.name}' pruned: ${d.reason}`);
|
|
416
447
|
else if (d.kind === "state") warn(`⚠ ${d.component} state '${d.name}' pruned: ${d.reason}`);
|
|
417
448
|
}
|
|
@@ -594,10 +625,10 @@ if (import.meta.hot) {
|
|
|
594
625
|
}];
|
|
595
626
|
}
|
|
596
627
|
},
|
|
597
|
-
handleHotUpdate({ file, server: hmrServer, modules }) {
|
|
628
|
+
async handleHotUpdate({ file, server: hmrServer, modules }) {
|
|
598
629
|
if (isProd) return;
|
|
599
630
|
const ext = extname(file);
|
|
600
|
-
if (!
|
|
631
|
+
if (!extensionsSet.has(ext)) return;
|
|
601
632
|
const excludePatterns = options.exclude ?? DEFAULT_EXCLUDE;
|
|
602
633
|
if (!externalPackageDirs.some((dir) => file.startsWith(dir)) && excludePatterns.some((pattern) => file.includes(pattern) || relative(rootDir, file).includes(pattern))) return;
|
|
603
634
|
const absFile = resolve(file);
|
|
@@ -642,20 +673,34 @@ if (import.meta.hot) {
|
|
|
642
673
|
} catch {
|
|
643
674
|
return;
|
|
644
675
|
}
|
|
676
|
+
let scannerRelPath = relPath;
|
|
677
|
+
if (ext === ".mdx") {
|
|
678
|
+
const result = await preprocessMdx(source, relPath);
|
|
679
|
+
if (result.kind === "missing-dep") {
|
|
680
|
+
warn("⚠ .mdx HMR skipped: @mdx-js/mdx not installed; restart dev server after installing");
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (result.kind === "error") {
|
|
684
|
+
warn(`⚠ MDX preprocessing failed for ${relPath}: ${result.error}`);
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
source = result.source;
|
|
688
|
+
scannerRelPath = relPath + ".tsx";
|
|
689
|
+
}
|
|
645
690
|
const hash = contentHash(source);
|
|
646
|
-
const cached = fileCache.get(
|
|
691
|
+
const cached = fileCache.get(scannerRelPath);
|
|
647
692
|
if (cached && cached.hash === hash) {
|
|
648
|
-
log(`HMR skip: ${
|
|
693
|
+
log(`HMR skip: ${scannerRelPath} (unchanged)`);
|
|
649
694
|
return [];
|
|
650
695
|
}
|
|
651
|
-
fileCache.set(
|
|
696
|
+
fileCache.set(scannerRelPath, {
|
|
652
697
|
hash,
|
|
653
698
|
source
|
|
654
699
|
});
|
|
655
700
|
const hmrStart = performance.now();
|
|
656
701
|
const prevReplacements = /* @__PURE__ */ new Map();
|
|
657
702
|
if (storedManifest?.components) for (const [id, desc] of Object.entries(storedManifest.components)) prevReplacements.set(id, desc.replacement ?? "");
|
|
658
|
-
const directComponentIds = storedManifest?.files?.[
|
|
703
|
+
const directComponentIds = storedManifest?.files?.[scannerRelPath] ?? [];
|
|
659
704
|
const invalidatedIds = new Set(directComponentIds);
|
|
660
705
|
const queue = [...directComponentIds];
|
|
661
706
|
while (queue.length > 0) {
|
|
@@ -705,4 +750,4 @@ if (import.meta.hot) {
|
|
|
705
750
|
};
|
|
706
751
|
}
|
|
707
752
|
//#endregion
|
|
708
|
-
export { animusExtract, animusExtract as default };
|
|
753
|
+
export { animusExtract, animusExtract as default, discoverFiles };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@animus-ui/vite-plugin",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.65",
|
|
4
4
|
"description": "Animus static CSS extraction Vite plugin",
|
|
5
5
|
"author": "codecaaron <airrobb@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,15 +30,21 @@
|
|
|
30
30
|
],
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "bun run build:ts",
|
|
33
|
-
"build:ts": "tsdown &&
|
|
34
|
-
"compile": "
|
|
33
|
+
"build:ts": "tsdown && tsgo -p tsconfig.build.json",
|
|
34
|
+
"compile": "tsgo --noEmit",
|
|
35
|
+
"compile:tsc-fallback": "tsc --noEmit"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
38
|
+
"@mdx-js/mdx": "^3.0.0",
|
|
37
39
|
"vite": ">=5.0.0"
|
|
38
40
|
},
|
|
41
|
+
"peerDependenciesMeta": {
|
|
42
|
+
"@mdx-js/mdx": {
|
|
43
|
+
"optional": true
|
|
44
|
+
}
|
|
45
|
+
},
|
|
39
46
|
"dependencies": {
|
|
40
|
-
"@animus-ui/extract": "0.1.0-next.
|
|
41
|
-
"@animus-ui/system": "0.1.0-next.62",
|
|
47
|
+
"@animus-ui/extract": "0.1.0-next.65",
|
|
42
48
|
"browserslist": "^4.24.0",
|
|
43
49
|
"lightningcss": "^1.29.0"
|
|
44
50
|
}
|