@bamboocss/node 1.32.0 → 1.34.0
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/index.cjs +177 -33
- package/dist/index.d.cts +72 -1
- package/dist/index.d.mts +72 -1
- package/dist/index.mjs +174 -30
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Everything below is exported from `@bamboocss/node`.
|
|
|
14
14
|
### Context
|
|
15
15
|
|
|
16
16
|
- `loadConfigAndCreateContext({ cwd?, config?, configPath? })` – resolve the config file, merge presets and inline
|
|
17
|
-
overrides, auto-inject the built-in plugins (`vue`, `svelte
|
|
17
|
+
overrides, auto-inject the built-in plugins (`vue`, `svelte`), and return a `BambooContext`.
|
|
18
18
|
- `BambooContext` – the resolved config plus everything derived from it: tokens, utilities, conditions, recipes,
|
|
19
19
|
patterns, the `ts-morph` project, the output engine and the diff engine.
|
|
20
20
|
- `Builder` – the incremental driver the bundler plugins use. It owns context setup, tracks which files and config
|
package/dist/index.cjs
CHANGED
|
@@ -25,12 +25,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
25
|
let _bamboocss_reporter = require("@bamboocss/reporter");
|
|
26
26
|
let _bamboocss_logger = require("@bamboocss/logger");
|
|
27
27
|
let _bamboocss_config = require("@bamboocss/config");
|
|
28
|
+
let _bamboocss_core = require("@bamboocss/core");
|
|
28
29
|
let _bamboocss_shared = require("@bamboocss/shared");
|
|
29
30
|
let fs = require("fs");
|
|
30
31
|
let path = require("path");
|
|
31
32
|
let _bamboocss_plugin_svelte = require("@bamboocss/plugin-svelte");
|
|
32
33
|
let _bamboocss_plugin_vue = require("@bamboocss/plugin-vue");
|
|
33
|
-
let _bamboocss_core = require("@bamboocss/core");
|
|
34
34
|
let _bamboocss_generator = require("@bamboocss/generator");
|
|
35
35
|
let _bamboocss_parser = require("@bamboocss/parser");
|
|
36
36
|
let perfect_debounce = require("perfect-debounce");
|
|
@@ -125,15 +125,20 @@ async function codegen(ctx, ids) {
|
|
|
125
125
|
const limit = pLimit(20);
|
|
126
126
|
if (ctx.config.clean) ctx.output.empty();
|
|
127
127
|
let artifacts = ctx.getArtifacts(ids);
|
|
128
|
+
let complete = !ids;
|
|
128
129
|
if (ctx.hooks["codegen:prepare"]) {
|
|
129
130
|
const results = await ctx.hooks["codegen:prepare"]?.({
|
|
130
131
|
changed: ids,
|
|
131
132
|
artifacts
|
|
132
133
|
});
|
|
133
|
-
if (results)
|
|
134
|
+
if (results) {
|
|
135
|
+
artifacts = results;
|
|
136
|
+
complete = false;
|
|
137
|
+
}
|
|
134
138
|
}
|
|
135
139
|
const promises = artifacts.map((artifact) => limit(() => ctx.output.write(artifact)));
|
|
136
140
|
await Promise.allSettled(promises);
|
|
141
|
+
if (complete) ctx.output.prune(artifacts);
|
|
137
142
|
await ctx.hooks["codegen:done"]?.({ changed: ids });
|
|
138
143
|
return {
|
|
139
144
|
box: ctx.initMessage(),
|
|
@@ -1509,10 +1514,13 @@ const nodeRuntime = {
|
|
|
1509
1514
|
writeFile: fs_extra.default.writeFile,
|
|
1510
1515
|
writeFileSync: fs_extra.default.writeFileSync,
|
|
1511
1516
|
readDirSync: fs_extra.default.readdirSync,
|
|
1517
|
+
isDirSync(path$6) {
|
|
1518
|
+
return fs_extra.default.statSync(path$6, { throwIfNoEntry: false })?.isDirectory() ?? false;
|
|
1519
|
+
},
|
|
1512
1520
|
rmDirSync: fs_extra.default.emptyDirSync,
|
|
1513
1521
|
rmFileSync: fs_extra.default.removeSync,
|
|
1514
|
-
ensureDirSync(path$
|
|
1515
|
-
return fs_extra.default.ensureDirSync(path$
|
|
1522
|
+
ensureDirSync(path$7) {
|
|
1523
|
+
return fs_extra.default.ensureDirSync(path$7);
|
|
1516
1524
|
},
|
|
1517
1525
|
watch(options) {
|
|
1518
1526
|
const { include, exclude, cwd, poll } = options;
|
|
@@ -1526,8 +1534,8 @@ const nodeRuntime = {
|
|
|
1526
1534
|
const watcher = chokidar.default.watch(dirnames, {
|
|
1527
1535
|
usePolling: poll,
|
|
1528
1536
|
cwd,
|
|
1529
|
-
ignored(path$
|
|
1530
|
-
const relativePath = (0, path.relative)(workingDir, path$
|
|
1537
|
+
ignored(path$8, stats) {
|
|
1538
|
+
const relativePath = (0, path.relative)(workingDir, path$8);
|
|
1531
1539
|
return !!stats?.isFile() && !isValidPath(relativePath);
|
|
1532
1540
|
},
|
|
1533
1541
|
ignoreInitial: true,
|
|
@@ -1573,6 +1581,69 @@ var OutputEngine = class {
|
|
|
1573
1581
|
this.fs.ensureDirSync(dirname);
|
|
1574
1582
|
return outPath;
|
|
1575
1583
|
};
|
|
1584
|
+
/**
|
|
1585
|
+
* Delete files in the generated directories that this codegen no longer produces.
|
|
1586
|
+
*
|
|
1587
|
+
* Codegen was write-only, so an artifact that stopped being generated stayed on disk
|
|
1588
|
+
* forever. Dropping a pattern from the config rewrote `patterns/index.js` without it and
|
|
1589
|
+
* left `patterns/stack.js` sitting beside it — importing through the barrel then failed
|
|
1590
|
+
* loudly, which is fine, but a deep import resolved, ran, returned a class name and
|
|
1591
|
+
* emitted no css. A stale artifact is worse than a missing one: it answers.
|
|
1592
|
+
*
|
|
1593
|
+
* Scoped to the directories this call actually wrote to, so a directory bamboo does not
|
|
1594
|
+
* generate into is never read, let alone emptied. It is bounded twice over, because the
|
|
1595
|
+
* cost of being wrong here is a deleted file rather than a stale one:
|
|
1596
|
+
*
|
|
1597
|
+
* - only a *complete* codegen may be swept, since a filtered artifact list cannot say what
|
|
1598
|
+
* a directory should contain. That is the caller's to enforce;
|
|
1599
|
+
* - within a directory, only files carrying an extension this codegen actually wrote
|
|
1600
|
+
* *there* are eligible. `patterns/` got `.mjs` and `.d.ts` files, so a leftover
|
|
1601
|
+
* `stack.mjs` is stale; a `.gitignore`, a `README.md` or a `styles.css` is not the kind
|
|
1602
|
+
* of thing we put there and is none of our business.
|
|
1603
|
+
*
|
|
1604
|
+
* The second bound replaces a list of known exceptions, which was the wrong shape: a
|
|
1605
|
+
* denylist has to name every file anyone might legitimately keep in an output directory,
|
|
1606
|
+
* and the failure mode when it misses one is silent deletion. It missed the `.gitignore`
|
|
1607
|
+
* that ships inside a generated directory, which is committed in this repo's own fixtures.
|
|
1608
|
+
* Reasoning from what we wrote needs no such list.
|
|
1609
|
+
*
|
|
1610
|
+
* Subdirectories are left alone; they are swept as themselves when their own artifacts
|
|
1611
|
+
* are written.
|
|
1612
|
+
*/
|
|
1613
|
+
prune = (artifacts) => {
|
|
1614
|
+
const produced = /* @__PURE__ */ new Map();
|
|
1615
|
+
/** Per directory, the file extensions this codegen wrote into it. */
|
|
1616
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
1617
|
+
for (const artifact of artifacts) {
|
|
1618
|
+
if (!artifact) continue;
|
|
1619
|
+
const dir = this.path.join(...artifact.dir ?? this.paths.root);
|
|
1620
|
+
let files = produced.get(dir);
|
|
1621
|
+
if (!files) produced.set(dir, files = /* @__PURE__ */ new Set());
|
|
1622
|
+
let extensions = kinds.get(dir);
|
|
1623
|
+
if (!extensions) kinds.set(dir, extensions = /* @__PURE__ */ new Set());
|
|
1624
|
+
for (const { file, code } of artifact.files) {
|
|
1625
|
+
if (!code) continue;
|
|
1626
|
+
files.add(file);
|
|
1627
|
+
extensions.add(this.path.extname(file));
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
let removed = 0;
|
|
1631
|
+
for (const [dir, files] of produced) {
|
|
1632
|
+
if (!this.fs.existsSync(dir)) continue;
|
|
1633
|
+
const extensions = kinds.get(dir);
|
|
1634
|
+
for (const entry of this.fs.readDirSync(dir)) {
|
|
1635
|
+
if (files.has(entry)) continue;
|
|
1636
|
+
if (!extensions.has(this.path.extname(entry))) continue;
|
|
1637
|
+
const absPath = this.path.join(dir, entry);
|
|
1638
|
+
if (this.fs.isDirSync(absPath)) continue;
|
|
1639
|
+
_bamboocss_logger.logger.debug("write:stale", `removing ${entry}`);
|
|
1640
|
+
this.fs.rmFileSync(absPath);
|
|
1641
|
+
removed++;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
if (removed) _bamboocss_logger.logger.debug("write:stale", `Removed ${removed} artifact(s) no longer generated`);
|
|
1645
|
+
return { removed };
|
|
1646
|
+
};
|
|
1576
1647
|
write = (output) => {
|
|
1577
1648
|
if (!output) return;
|
|
1578
1649
|
const { dir = this.paths.root, files } = output;
|
|
@@ -1653,6 +1724,16 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
1653
1724
|
* syntax error.
|
|
1654
1725
|
*/
|
|
1655
1726
|
parseFailures = /* @__PURE__ */ new Map();
|
|
1727
|
+
/**
|
|
1728
|
+
* Files that call a binding their entrypoint no longer exports, keyed by path.
|
|
1729
|
+
*
|
|
1730
|
+
* Keyed and scoped exactly like `parseFailures`, and for the same reasons: an incremental
|
|
1731
|
+
* pass that skips an unchanged file does not re-parse it, so the finding has to outlive the
|
|
1732
|
+
* pass that recorded it or a no-op rebuild launders a broken build into a green one — and it
|
|
1733
|
+
* has to be dropped once the file is fixed, deleted, or leaves `include`, or the fix can
|
|
1734
|
+
* never take.
|
|
1735
|
+
*/
|
|
1736
|
+
deadCalls = /* @__PURE__ */ new Map();
|
|
1656
1737
|
constructor(conf) {
|
|
1657
1738
|
super(conf);
|
|
1658
1739
|
const config = conf.config;
|
|
@@ -1686,6 +1767,7 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
1686
1767
|
const unresolved = result.unresolved;
|
|
1687
1768
|
if (!unresolved?.length) return;
|
|
1688
1769
|
for (const entry of unresolved) {
|
|
1770
|
+
if (this.isGenerated(entry.filePath)) continue;
|
|
1689
1771
|
const where = `${entry.filePath}:${entry.line}:${entry.column}`;
|
|
1690
1772
|
const prop = entry.prop ? `\`${entry.prop}\`` : "a property";
|
|
1691
1773
|
const [what] = unresolvedReasons[entry.reason](prop);
|
|
@@ -1746,11 +1828,66 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
1746
1828
|
const inScope = new Set(Array.from(files ?? this.getFiles(), (file) => this.runtime.path.abs(this.config.cwd, file)));
|
|
1747
1829
|
for (const file of this.parseFailures.keys()) if (!inScope.has(file)) this.parseFailures.delete(file);
|
|
1748
1830
|
if (!this.parseFailures.size) return;
|
|
1749
|
-
const detail = Array.from(this.parseFailures.entries()
|
|
1831
|
+
const detail = (0, _bamboocss_shared.truncateList)(Array.from(this.parseFailures.entries(), ([file, error]) => `${this.relative(file)}\n${messageOf(error).replace(/^(?=.)/gm, " ")}`), { unit: "file" });
|
|
1750
1832
|
throw new _bamboocss_shared.BambooError("EXTRACT_FAILED", `${this.parseFailures.size} file(s) could not be extracted:\n\n${detail}\n\nNothing emits a rule for a file the build could not read, so every style in these is absent from the stylesheet and the classes their components ask for have nothing behind them.`, { cause: new AggregateError(Array.from(this.parseFailures.values()), `${this.parseFailures.size} file(s) could not be extracted`) });
|
|
1751
1833
|
};
|
|
1834
|
+
/**
|
|
1835
|
+
* Fail on a call to a binding the pattern or recipe entrypoint no longer exports.
|
|
1836
|
+
*
|
|
1837
|
+
* The same test `assertExtracted` applies, against the other way of arriving at the same
|
|
1838
|
+
* output. There the build could not read the file; here it read it and the call named
|
|
1839
|
+
* nothing, so the extractor recorded no styles and the class the component asks for has no
|
|
1840
|
+
* rule behind it. Both leave a green build and a stylesheet missing rules, which is the one
|
|
1841
|
+
* failure a diff of the output is the only way to notice.
|
|
1842
|
+
*
|
|
1843
|
+
* Not graded by a severity option, unlike an unresolved token path: that one is inferred
|
|
1844
|
+
* from a value's shape and can be wrong about a literal, while this is read off the
|
|
1845
|
+
* entrypoint's own export list. There is no configuration under which calling a binding
|
|
1846
|
+
* that does not exist is what someone meant.
|
|
1847
|
+
*
|
|
1848
|
+
* Scoped like `assertExtracted`, for the reasons given there — a file taken out of
|
|
1849
|
+
* `include` or deleted is a fix, and an entry naming a path that no longer exists would
|
|
1850
|
+
* fail every later build and wedge a dev server.
|
|
1851
|
+
*/
|
|
1852
|
+
assertNoDeadCalls = (files) => {
|
|
1853
|
+
if (!this.deadCalls.size) return;
|
|
1854
|
+
const inScope = new Set(Array.from(files ?? this.getFiles(), (file) => this.runtime.path.abs(this.config.cwd, file)));
|
|
1855
|
+
for (const file of this.deadCalls.keys()) if (!inScope.has(file)) this.deadCalls.delete(file);
|
|
1856
|
+
if (!this.deadCalls.size) return;
|
|
1857
|
+
const entrypoint = {
|
|
1858
|
+
pattern: "pattern",
|
|
1859
|
+
recipe: "recipe"
|
|
1860
|
+
};
|
|
1861
|
+
const occurrences = Array.from(this.deadCalls.entries()).flatMap(([file, calls]) => calls.map((call) => ({
|
|
1862
|
+
file,
|
|
1863
|
+
call
|
|
1864
|
+
})));
|
|
1865
|
+
const detail = (0, _bamboocss_shared.truncateList)(Array.from((0, _bamboocss_shared.groupBy)(occurrences, ({ call }) => `${call.entrypoint}${call.mod}${call.name}${call.alias}`), ([, group]) => {
|
|
1866
|
+
const { call } = group[0];
|
|
1867
|
+
const named = call.alias === call.name ? `\`${call.name}\`` : `\`${call.name}\` (called as \`${call.alias}\`)`;
|
|
1868
|
+
const files = (0, _bamboocss_shared.uniq)(group.map(({ file }) => this.relative(file)));
|
|
1869
|
+
const shown = files.slice(0, 5).join(", ");
|
|
1870
|
+
const rest = files.length > 5 ? `, … and ${files.length - 5} more` : "";
|
|
1871
|
+
return `${named} is not a ${entrypoint[call.entrypoint]} — \`${call.mod}\` does not export it.\n ${files.length} file(s): ${shown}${rest}`;
|
|
1872
|
+
}), { unit: "binding" });
|
|
1873
|
+
const count = occurrences.length;
|
|
1874
|
+
throw new _bamboocss_shared.BambooError("DEAD_IMPORT", `${count} call(s) name a binding that does not exist:\n\n${detail}\n\nBoth entrypoints are generated from your config, so what they export moves when it does — a pattern dropped from a preset, a recipe renamed. The call survives that as a binding to nothing: nothing extracts it, so every rule it would have contributed is absent from the stylesheet and the classes their components ask for have nothing behind them.`);
|
|
1875
|
+
};
|
|
1752
1876
|
/** A path as the user typed it, when it is under `cwd`. */
|
|
1753
1877
|
relative = (file) => file.startsWith(this.config.cwd) ? file.slice(this.config.cwd.length + 1) : file;
|
|
1878
|
+
/**
|
|
1879
|
+
* Whether a file is one bamboo wrote.
|
|
1880
|
+
*
|
|
1881
|
+
* `include` conventionally covers a source tree that `outdir` sits inside — `./src/**` and
|
|
1882
|
+
* `src/styled-system` — so the build routinely parses its own output. That is load-bearing
|
|
1883
|
+
* rather than accidental, which is why the answer here is "do not report it" rather than
|
|
1884
|
+
* "do not read it": the token and keyframe scans read whatever `include` covers, and a
|
|
1885
|
+
* project that excludes its `outdir` should not lose them.
|
|
1886
|
+
*/
|
|
1887
|
+
isGenerated = (file) => {
|
|
1888
|
+
const outdir = this.runtime.path.join(...this.paths.root);
|
|
1889
|
+
return file === outdir || file.startsWith(outdir + this.runtime.path.sep);
|
|
1890
|
+
};
|
|
1754
1891
|
parseFile = (filePath, styleEncoder) => {
|
|
1755
1892
|
const file = this.runtime.path.abs(this.config.cwd, filePath);
|
|
1756
1893
|
_bamboocss_logger.logger.debug("file:extract", file);
|
|
@@ -1764,7 +1901,11 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
1764
1901
|
_bamboocss_logger.logger.caughtError("file:extract", `Failed to parse ${file}`, error);
|
|
1765
1902
|
this.parseFailures.set(file, error);
|
|
1766
1903
|
}
|
|
1767
|
-
if (result)
|
|
1904
|
+
if (result) {
|
|
1905
|
+
this.reportUnresolvedStyles(result);
|
|
1906
|
+
if (result.deadCalls.length) this.deadCalls.set(file, result.deadCalls);
|
|
1907
|
+
else this.deadCalls.delete(file);
|
|
1908
|
+
}
|
|
1768
1909
|
measure();
|
|
1769
1910
|
return result;
|
|
1770
1911
|
};
|
|
@@ -1787,6 +1928,7 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
1787
1928
|
results.push(result);
|
|
1788
1929
|
});
|
|
1789
1930
|
this.assertExtracted(files);
|
|
1931
|
+
this.assertNoDeadCalls(files);
|
|
1790
1932
|
return {
|
|
1791
1933
|
filesWithCss,
|
|
1792
1934
|
files,
|
|
@@ -2597,12 +2739,15 @@ function* sourceTexts(ctx) {
|
|
|
2597
2739
|
* exists for does not apply to them, and opting out of token pruning should not mean shipping
|
|
2598
2740
|
* a preset's whole filter and gradient set for nothing.
|
|
2599
2741
|
*/
|
|
2742
|
+
/**
|
|
2743
|
+
* Returns the custom properties left standing, for `pruneKeyframes` to root its own walk
|
|
2744
|
+
* at — see `Generator.pruneKeyframes`. `'all'` when this pass had nothing to remove and so
|
|
2745
|
+
* never computed the closure, which is not a missing answer but the correct one: a sheet
|
|
2746
|
+
* nothing was removed from still declares everything it declared.
|
|
2747
|
+
*/
|
|
2600
2748
|
function pruneTokensForBuild(ctx, sheet, results) {
|
|
2601
2749
|
const strategy = ctx.config.prune?.tokens ?? "reachable";
|
|
2602
|
-
if (strategy === "off")
|
|
2603
|
-
ctx.pruneTokens(sheet);
|
|
2604
|
-
return;
|
|
2605
|
-
}
|
|
2750
|
+
if (strategy === "off") return ctx.pruneTokens(sheet)?.reachable ?? "all";
|
|
2606
2751
|
const accounts = strategy === "accounted";
|
|
2607
2752
|
const unresolved = accounts ? ctx.config.prune?.unresolvedPath ?? "warn" : "off";
|
|
2608
2753
|
const paths = /* @__PURE__ */ new Set();
|
|
@@ -2625,10 +2770,7 @@ function pruneTokensForBuild(ctx, sheet, results) {
|
|
|
2625
2770
|
for (const name of tokenVarsFor(ctx, paths)) vars.add(name);
|
|
2626
2771
|
const declared = declaredKeeps(ctx);
|
|
2627
2772
|
for (const name of tokenVarsFor(ctx, declared)) vars.add(name);
|
|
2628
|
-
if (!accounts)
|
|
2629
|
-
ctx.pruneTokens(sheet, vars, reachable);
|
|
2630
|
-
return;
|
|
2631
|
-
}
|
|
2773
|
+
if (!accounts) return ctx.pruneTokens(sheet, vars, reachable)?.reachable ?? "all";
|
|
2632
2774
|
for (const name of tokenVarsFor(ctx, accounting.paths)) vars.add(name);
|
|
2633
2775
|
const bounded = (ctx.config.prune?.keepTokens?.length ?? 0) > 0;
|
|
2634
2776
|
if (accounting.prefixes.size && (bounded || !accounting.declined.length)) {
|
|
@@ -2646,7 +2788,7 @@ function pruneTokensForBuild(ctx, sheet, results) {
|
|
|
2646
2788
|
_bamboocss_logger.logger.warn("tokens:unresolved", bounded ? where + "`prune.keepTokens` covers them: they keep what it names rather than every declaration in the theme. Nothing checks that they stay inside it, which is why it is yours to declare — a read landing outside the patterns loses its declaration and resolves to a `var()` with nothing behind it. Respell what you can, and widen the patterns for what you cannot." : where + "`prune.tokens: 'accounted'` asserts that every token path resolves at build time. Spell the path as a string literal at the call, give a template a static prefix so it can be bounded, name the category they land in with `prune: { keepTokens: ['colors.*'] }`, or set `prune: { tokens: 'reachable' }` to stop asserting.");
|
|
2647
2789
|
}
|
|
2648
2790
|
if (reported.length && unresolved !== "off") _bamboocss_logger.logger.warn("tokens:unresolved", `${reported.length} reference(s) could not be accounted for, so ` + (bounded ? `\`prune.keepTokens\` decides what they keep` : `every token declaration is kept`) + `.\n\n${formatDeclined(ctx, reported)}\n\nThese are shapes the build cannot follow rather than paths you can respell — a component stored post-transform, a file it could not parse, a barrel it cannot classify, a dynamic \`import()\`. ` + (bounded ? "Nothing checks that they stay inside `keepTokens`, which is why it is yours to declare: a read landing outside it loses its declaration. Narrow `include`, or widen the patterns." : "Narrow `include`, name the categories they reach with `prune: { keepTokens: [...] }`, or accept the keeps."));
|
|
2649
|
-
ctx.pruneTokens(sheet, vars, !bounded && accounting.declined.length > 0 && reachable);
|
|
2791
|
+
return ctx.pruneTokens(sheet, vars, !bounded && accounting.declined.length > 0 && reachable)?.reachable ?? "all";
|
|
2650
2792
|
}
|
|
2651
2793
|
/**
|
|
2652
2794
|
* The dash-cased spelling of a token path, as it appears in the emitted css variable.
|
|
@@ -2754,7 +2896,7 @@ const keyframeNames = (ctx) => Object.keys(ctx.config.theme?.keyframes ?? {});
|
|
|
2754
2896
|
*
|
|
2755
2897
|
* Lowercase-initial only, so a JSX component (`<Button />`) is not mistaken for an element.
|
|
2756
2898
|
* That cuts the other way too — a component rendering `<button>` inside a dependency is
|
|
2757
|
-
* invisible here, which is why `prune
|
|
2899
|
+
* invisible here, which is why `preflight.prune` is opt-in.
|
|
2758
2900
|
*
|
|
2759
2901
|
* The commoner blind spot is nearer than a dependency: this reads `include`, and `include`
|
|
2760
2902
|
* conventionally covers components rather than markup. An entry template — `index.html`,
|
|
@@ -2914,13 +3056,15 @@ var Builder = class {
|
|
|
2914
3056
|
const hasConfigChanged = this.affecteds ? this.affecteds.hasConfigChanged : true;
|
|
2915
3057
|
if (!this.filesMeta && !hasConfigChanged) {
|
|
2916
3058
|
_bamboocss_logger.logger.debug("builder", "No files or config changed, skipping extract");
|
|
2917
|
-
|
|
3059
|
+
ctx.assertExtracted();
|
|
3060
|
+
return ctx.assertNoDeadCalls();
|
|
2918
3061
|
}
|
|
2919
3062
|
const files = ctx.getFiles();
|
|
2920
3063
|
const done = _bamboocss_logger.logger.time.info("Extracted in");
|
|
2921
|
-
|
|
3064
|
+
for (const file of files) this.extractFile(ctx, file);
|
|
2922
3065
|
done();
|
|
2923
3066
|
ctx.assertExtracted(files);
|
|
3067
|
+
ctx.assertNoDeadCalls(files);
|
|
2924
3068
|
};
|
|
2925
3069
|
isValidRoot = (root) => {
|
|
2926
3070
|
const ctx = this.getContextOrThrow();
|
|
@@ -2957,9 +3101,9 @@ var Builder = class {
|
|
|
2957
3101
|
const sheet = ctx.createSheet();
|
|
2958
3102
|
if (layerParams) ctx.appendLayerParams(sheet);
|
|
2959
3103
|
ctx.appendBaselineCss(sheet);
|
|
2960
|
-
pruneTokensForBuild(ctx, sheet, []);
|
|
2961
|
-
if (ctx.config.
|
|
2962
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
|
|
3104
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, []);
|
|
3105
|
+
if ((0, _bamboocss_core.prunesPreflight)(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
3106
|
+
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)), reachableVars);
|
|
2963
3107
|
return ctx.getCss(sheet);
|
|
2964
3108
|
};
|
|
2965
3109
|
registerDependency = (fn) => {
|
|
@@ -3047,7 +3191,7 @@ const cssgen = async (ctx, options) => {
|
|
|
3047
3191
|
if (type) {
|
|
3048
3192
|
const done = _bamboocss_logger.logger.time.info(ctx.messages.cssArtifactComplete(type));
|
|
3049
3193
|
ctx.appendCssOfType(type, sheet);
|
|
3050
|
-
if (type === "preflight" && ctx.config.
|
|
3194
|
+
if (type === "preflight" && (0, _bamboocss_core.prunesPreflight)(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
3051
3195
|
if (outfile) {
|
|
3052
3196
|
const css = ctx.getCss(sheet);
|
|
3053
3197
|
_bamboocss_logger.logger.info("css", ctx.runtime.path.resolve(outfile));
|
|
@@ -3060,9 +3204,9 @@ const cssgen = async (ctx, options) => {
|
|
|
3060
3204
|
ctx.appendLayerParams(sheet);
|
|
3061
3205
|
ctx.appendBaselineCss(sheet);
|
|
3062
3206
|
ctx.appendParserCss(sheet);
|
|
3063
|
-
pruneTokensForBuild(ctx, sheet, results);
|
|
3064
|
-
if (ctx.config.
|
|
3065
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
|
|
3207
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, results);
|
|
3208
|
+
if ((0, _bamboocss_core.prunesPreflight)(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
3209
|
+
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)), reachableVars);
|
|
3066
3210
|
if (splitting) await ctx.writeSplitCss(sheet);
|
|
3067
3211
|
else if (outfile) {
|
|
3068
3212
|
const css = ctx.getCss(sheet);
|
|
@@ -3132,9 +3276,9 @@ async function build(ctx, artifactIds) {
|
|
|
3132
3276
|
ctx.appendBaselineCss(sheet);
|
|
3133
3277
|
const parsed = ctx.parseFiles();
|
|
3134
3278
|
ctx.appendParserCss(sheet);
|
|
3135
|
-
pruneTokensForBuild(ctx, sheet, parsed.results);
|
|
3136
|
-
if (ctx.config.
|
|
3137
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
|
|
3279
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, parsed.results);
|
|
3280
|
+
if ((0, _bamboocss_core.prunesPreflight)(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
3281
|
+
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)), reachableVars);
|
|
3138
3282
|
await ctx.writeCss(sheet);
|
|
3139
3283
|
done(ctx.messages.buildComplete(parsed.files.length));
|
|
3140
3284
|
}
|
|
@@ -3178,9 +3322,9 @@ async function generate(config, configPath) {
|
|
|
3178
3322
|
ctx.appendLayerParams(sheet);
|
|
3179
3323
|
ctx.appendBaselineCss(sheet);
|
|
3180
3324
|
ctx.appendParserCss(sheet);
|
|
3181
|
-
pruneTokensForBuild(ctx, sheet, []);
|
|
3182
|
-
if (ctx.config.
|
|
3183
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
|
|
3325
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, []);
|
|
3326
|
+
if ((0, _bamboocss_core.prunesPreflight)(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
3327
|
+
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)), reachableVars);
|
|
3184
3328
|
const css = ctx.getCss(sheet);
|
|
3185
3329
|
await ctx.runtime.fs.writeFile(outfile, css);
|
|
3186
3330
|
done();
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ReportFormat } from "@bamboocss/reporter";
|
|
2
2
|
import { AnalysisOptions, Artifact, ArtifactId, BambooHooks, Config, CssArtifactType, LoadConfigResult, Runtime, SpecFile, WatchOptions, WatcherEventType } from "@bamboocss/types";
|
|
3
|
-
import { StyleEncoder, Stylesheet } from "@bamboocss/core";
|
|
3
|
+
import { DeadImport, StyleEncoder, Stylesheet } from "@bamboocss/core";
|
|
4
4
|
import { Generator, generatePackageExports } from "@bamboocss/generator";
|
|
5
5
|
import { ParserResult, Project } from "@bamboocss/parser";
|
|
6
6
|
import { Message, Root } from "postcss";
|
|
@@ -34,6 +34,38 @@ declare class OutputEngine {
|
|
|
34
34
|
constructor(options: OutputEngineOptions);
|
|
35
35
|
empty: () => void;
|
|
36
36
|
ensure: (file: string, cwd: string) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Delete files in the generated directories that this codegen no longer produces.
|
|
39
|
+
*
|
|
40
|
+
* Codegen was write-only, so an artifact that stopped being generated stayed on disk
|
|
41
|
+
* forever. Dropping a pattern from the config rewrote `patterns/index.js` without it and
|
|
42
|
+
* left `patterns/stack.js` sitting beside it — importing through the barrel then failed
|
|
43
|
+
* loudly, which is fine, but a deep import resolved, ran, returned a class name and
|
|
44
|
+
* emitted no css. A stale artifact is worse than a missing one: it answers.
|
|
45
|
+
*
|
|
46
|
+
* Scoped to the directories this call actually wrote to, so a directory bamboo does not
|
|
47
|
+
* generate into is never read, let alone emptied. It is bounded twice over, because the
|
|
48
|
+
* cost of being wrong here is a deleted file rather than a stale one:
|
|
49
|
+
*
|
|
50
|
+
* - only a *complete* codegen may be swept, since a filtered artifact list cannot say what
|
|
51
|
+
* a directory should contain. That is the caller's to enforce;
|
|
52
|
+
* - within a directory, only files carrying an extension this codegen actually wrote
|
|
53
|
+
* *there* are eligible. `patterns/` got `.mjs` and `.d.ts` files, so a leftover
|
|
54
|
+
* `stack.mjs` is stale; a `.gitignore`, a `README.md` or a `styles.css` is not the kind
|
|
55
|
+
* of thing we put there and is none of our business.
|
|
56
|
+
*
|
|
57
|
+
* The second bound replaces a list of known exceptions, which was the wrong shape: a
|
|
58
|
+
* denylist has to name every file anyone might legitimately keep in an output directory,
|
|
59
|
+
* and the failure mode when it misses one is silent deletion. It missed the `.gitignore`
|
|
60
|
+
* that ships inside a generated directory, which is committed in this repo's own fixtures.
|
|
61
|
+
* Reasoning from what we wrote needs no such list.
|
|
62
|
+
*
|
|
63
|
+
* Subdirectories are left alone; they are swept as themselves when their own artifacts
|
|
64
|
+
* are written.
|
|
65
|
+
*/
|
|
66
|
+
prune: (artifacts: Array<Artifact | undefined>) => {
|
|
67
|
+
removed: number;
|
|
68
|
+
};
|
|
37
69
|
write: (output: Artifact | undefined) => Promise<PromiseSettledResult<void>[]> | undefined;
|
|
38
70
|
/**
|
|
39
71
|
* Unlike the rest of the output, `package.json` is not exclusively ours: `emit-pkg`
|
|
@@ -71,6 +103,16 @@ declare class BambooContext extends Generator {
|
|
|
71
103
|
* syntax error.
|
|
72
104
|
*/
|
|
73
105
|
parseFailures: Map<string, unknown>;
|
|
106
|
+
/**
|
|
107
|
+
* Files that call a binding their entrypoint no longer exports, keyed by path.
|
|
108
|
+
*
|
|
109
|
+
* Keyed and scoped exactly like `parseFailures`, and for the same reasons: an incremental
|
|
110
|
+
* pass that skips an unchanged file does not re-parse it, so the finding has to outlive the
|
|
111
|
+
* pass that recorded it or a no-op rebuild launders a broken build into a green one — and it
|
|
112
|
+
* has to be dropped once the file is fixed, deleted, or leaves `include`, or the fix can
|
|
113
|
+
* never take.
|
|
114
|
+
*/
|
|
115
|
+
deadCalls: Map<string, DeadImport[]>;
|
|
74
116
|
constructor(conf: LoadConfigResult);
|
|
75
117
|
/**
|
|
76
118
|
* Report `css()` calls whose styles the build could not fully see.
|
|
@@ -105,8 +147,37 @@ declare class BambooContext extends Generator {
|
|
|
105
147
|
* process was restarted.
|
|
106
148
|
*/
|
|
107
149
|
assertExtracted: (files?: Iterable<string>) => void;
|
|
150
|
+
/**
|
|
151
|
+
* Fail on a call to a binding the pattern or recipe entrypoint no longer exports.
|
|
152
|
+
*
|
|
153
|
+
* The same test `assertExtracted` applies, against the other way of arriving at the same
|
|
154
|
+
* output. There the build could not read the file; here it read it and the call named
|
|
155
|
+
* nothing, so the extractor recorded no styles and the class the component asks for has no
|
|
156
|
+
* rule behind it. Both leave a green build and a stylesheet missing rules, which is the one
|
|
157
|
+
* failure a diff of the output is the only way to notice.
|
|
158
|
+
*
|
|
159
|
+
* Not graded by a severity option, unlike an unresolved token path: that one is inferred
|
|
160
|
+
* from a value's shape and can be wrong about a literal, while this is read off the
|
|
161
|
+
* entrypoint's own export list. There is no configuration under which calling a binding
|
|
162
|
+
* that does not exist is what someone meant.
|
|
163
|
+
*
|
|
164
|
+
* Scoped like `assertExtracted`, for the reasons given there — a file taken out of
|
|
165
|
+
* `include` or deleted is a fix, and an entry naming a path that no longer exists would
|
|
166
|
+
* fail every later build and wedge a dev server.
|
|
167
|
+
*/
|
|
168
|
+
assertNoDeadCalls: (files?: Iterable<string>) => void;
|
|
108
169
|
/** A path as the user typed it, when it is under `cwd`. */
|
|
109
170
|
private relative;
|
|
171
|
+
/**
|
|
172
|
+
* Whether a file is one bamboo wrote.
|
|
173
|
+
*
|
|
174
|
+
* `include` conventionally covers a source tree that `outdir` sits inside — `./src/**` and
|
|
175
|
+
* `src/styled-system` — so the build routinely parses its own output. That is load-bearing
|
|
176
|
+
* rather than accidental, which is why the answer here is "do not report it" rather than
|
|
177
|
+
* "do not read it": the token and keyframe scans read whatever `include` covers, and a
|
|
178
|
+
* project that excludes its `outdir` should not lose them.
|
|
179
|
+
*/
|
|
180
|
+
private isGenerated;
|
|
110
181
|
parseFile: (filePath: string, styleEncoder?: StyleEncoder) => ParserResult | undefined;
|
|
111
182
|
/**
|
|
112
183
|
* Extract every file in one pass, and fail on the ones that could not be read.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReportFormat } from "@bamboocss/reporter";
|
|
2
|
-
import { StyleEncoder, Stylesheet } from "@bamboocss/core";
|
|
2
|
+
import { DeadImport, StyleEncoder, Stylesheet } from "@bamboocss/core";
|
|
3
3
|
import { Generator, generatePackageExports } from "@bamboocss/generator";
|
|
4
4
|
import { ParserResult, Project } from "@bamboocss/parser";
|
|
5
5
|
import { AnalysisOptions, Artifact, ArtifactId, BambooHooks, Config, CssArtifactType, LoadConfigResult, Runtime, SpecFile, WatchOptions, WatcherEventType } from "@bamboocss/types";
|
|
@@ -34,6 +34,38 @@ declare class OutputEngine {
|
|
|
34
34
|
constructor(options: OutputEngineOptions);
|
|
35
35
|
empty: () => void;
|
|
36
36
|
ensure: (file: string, cwd: string) => string;
|
|
37
|
+
/**
|
|
38
|
+
* Delete files in the generated directories that this codegen no longer produces.
|
|
39
|
+
*
|
|
40
|
+
* Codegen was write-only, so an artifact that stopped being generated stayed on disk
|
|
41
|
+
* forever. Dropping a pattern from the config rewrote `patterns/index.js` without it and
|
|
42
|
+
* left `patterns/stack.js` sitting beside it — importing through the barrel then failed
|
|
43
|
+
* loudly, which is fine, but a deep import resolved, ran, returned a class name and
|
|
44
|
+
* emitted no css. A stale artifact is worse than a missing one: it answers.
|
|
45
|
+
*
|
|
46
|
+
* Scoped to the directories this call actually wrote to, so a directory bamboo does not
|
|
47
|
+
* generate into is never read, let alone emptied. It is bounded twice over, because the
|
|
48
|
+
* cost of being wrong here is a deleted file rather than a stale one:
|
|
49
|
+
*
|
|
50
|
+
* - only a *complete* codegen may be swept, since a filtered artifact list cannot say what
|
|
51
|
+
* a directory should contain. That is the caller's to enforce;
|
|
52
|
+
* - within a directory, only files carrying an extension this codegen actually wrote
|
|
53
|
+
* *there* are eligible. `patterns/` got `.mjs` and `.d.ts` files, so a leftover
|
|
54
|
+
* `stack.mjs` is stale; a `.gitignore`, a `README.md` or a `styles.css` is not the kind
|
|
55
|
+
* of thing we put there and is none of our business.
|
|
56
|
+
*
|
|
57
|
+
* The second bound replaces a list of known exceptions, which was the wrong shape: a
|
|
58
|
+
* denylist has to name every file anyone might legitimately keep in an output directory,
|
|
59
|
+
* and the failure mode when it misses one is silent deletion. It missed the `.gitignore`
|
|
60
|
+
* that ships inside a generated directory, which is committed in this repo's own fixtures.
|
|
61
|
+
* Reasoning from what we wrote needs no such list.
|
|
62
|
+
*
|
|
63
|
+
* Subdirectories are left alone; they are swept as themselves when their own artifacts
|
|
64
|
+
* are written.
|
|
65
|
+
*/
|
|
66
|
+
prune: (artifacts: Array<Artifact | undefined>) => {
|
|
67
|
+
removed: number;
|
|
68
|
+
};
|
|
37
69
|
write: (output: Artifact | undefined) => Promise<PromiseSettledResult<void>[]> | undefined;
|
|
38
70
|
/**
|
|
39
71
|
* Unlike the rest of the output, `package.json` is not exclusively ours: `emit-pkg`
|
|
@@ -71,6 +103,16 @@ declare class BambooContext extends Generator {
|
|
|
71
103
|
* syntax error.
|
|
72
104
|
*/
|
|
73
105
|
parseFailures: Map<string, unknown>;
|
|
106
|
+
/**
|
|
107
|
+
* Files that call a binding their entrypoint no longer exports, keyed by path.
|
|
108
|
+
*
|
|
109
|
+
* Keyed and scoped exactly like `parseFailures`, and for the same reasons: an incremental
|
|
110
|
+
* pass that skips an unchanged file does not re-parse it, so the finding has to outlive the
|
|
111
|
+
* pass that recorded it or a no-op rebuild launders a broken build into a green one — and it
|
|
112
|
+
* has to be dropped once the file is fixed, deleted, or leaves `include`, or the fix can
|
|
113
|
+
* never take.
|
|
114
|
+
*/
|
|
115
|
+
deadCalls: Map<string, DeadImport[]>;
|
|
74
116
|
constructor(conf: LoadConfigResult);
|
|
75
117
|
/**
|
|
76
118
|
* Report `css()` calls whose styles the build could not fully see.
|
|
@@ -105,8 +147,37 @@ declare class BambooContext extends Generator {
|
|
|
105
147
|
* process was restarted.
|
|
106
148
|
*/
|
|
107
149
|
assertExtracted: (files?: Iterable<string>) => void;
|
|
150
|
+
/**
|
|
151
|
+
* Fail on a call to a binding the pattern or recipe entrypoint no longer exports.
|
|
152
|
+
*
|
|
153
|
+
* The same test `assertExtracted` applies, against the other way of arriving at the same
|
|
154
|
+
* output. There the build could not read the file; here it read it and the call named
|
|
155
|
+
* nothing, so the extractor recorded no styles and the class the component asks for has no
|
|
156
|
+
* rule behind it. Both leave a green build and a stylesheet missing rules, which is the one
|
|
157
|
+
* failure a diff of the output is the only way to notice.
|
|
158
|
+
*
|
|
159
|
+
* Not graded by a severity option, unlike an unresolved token path: that one is inferred
|
|
160
|
+
* from a value's shape and can be wrong about a literal, while this is read off the
|
|
161
|
+
* entrypoint's own export list. There is no configuration under which calling a binding
|
|
162
|
+
* that does not exist is what someone meant.
|
|
163
|
+
*
|
|
164
|
+
* Scoped like `assertExtracted`, for the reasons given there — a file taken out of
|
|
165
|
+
* `include` or deleted is a fix, and an entry naming a path that no longer exists would
|
|
166
|
+
* fail every later build and wedge a dev server.
|
|
167
|
+
*/
|
|
168
|
+
assertNoDeadCalls: (files?: Iterable<string>) => void;
|
|
108
169
|
/** A path as the user typed it, when it is under `cwd`. */
|
|
109
170
|
private relative;
|
|
171
|
+
/**
|
|
172
|
+
* Whether a file is one bamboo wrote.
|
|
173
|
+
*
|
|
174
|
+
* `include` conventionally covers a source tree that `outdir` sits inside — `./src/**` and
|
|
175
|
+
* `src/styled-system` — so the build routinely parses its own output. That is load-bearing
|
|
176
|
+
* rather than accidental, which is why the answer here is "do not report it" rather than
|
|
177
|
+
* "do not read it": the token and keyframe scans read whatever `include` covers, and a
|
|
178
|
+
* project that excludes its `outdir` should not lose them.
|
|
179
|
+
*/
|
|
180
|
+
private isGenerated;
|
|
110
181
|
parseFile: (filePath: string, styleEncoder?: StyleEncoder) => ParserResult | undefined;
|
|
111
182
|
/**
|
|
112
183
|
* Extract every file in one pass, and fail on the ones that could not be read.
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Reporter, formatRecipeReport, formatTokenReport } from "@bamboocss/reporter";
|
|
2
2
|
import { colors, logger, quote } from "@bamboocss/logger";
|
|
3
3
|
import { convertTsPathsToRegexes, diffConfigs, findConfig, getConfigDependencies, loadConfig, mergeHooks } from "@bamboocss/config";
|
|
4
|
-
import {
|
|
4
|
+
import { checkNamingAgreement, formatNamingDisagreement, messages, prunesPreflight } from "@bamboocss/core";
|
|
5
|
+
import { BambooError, cssVarRefs, groupBy, truncateList, uniq } from "@bamboocss/shared";
|
|
5
6
|
import { appendFileSync, existsSync, readFileSync, statSync, writeFileSync } from "fs";
|
|
6
7
|
import { dirname, extname, isAbsolute, join, normalize, parse, relative, resolve, sep } from "path";
|
|
7
8
|
import { pluginSvelte } from "@bamboocss/plugin-svelte";
|
|
8
9
|
import { pluginVue } from "@bamboocss/plugin-vue";
|
|
9
|
-
import { checkNamingAgreement, formatNamingDisagreement, messages } from "@bamboocss/core";
|
|
10
10
|
import { Generator, generatePackageExports } from "@bamboocss/generator";
|
|
11
11
|
import { Project } from "@bamboocss/parser";
|
|
12
12
|
import { debounce } from "perfect-debounce";
|
|
@@ -111,15 +111,20 @@ async function codegen(ctx, ids) {
|
|
|
111
111
|
const limit = pLimit(20);
|
|
112
112
|
if (ctx.config.clean) ctx.output.empty();
|
|
113
113
|
let artifacts = ctx.getArtifacts(ids);
|
|
114
|
+
let complete = !ids;
|
|
114
115
|
if (ctx.hooks["codegen:prepare"]) {
|
|
115
116
|
const results = await ctx.hooks["codegen:prepare"]?.({
|
|
116
117
|
changed: ids,
|
|
117
118
|
artifacts
|
|
118
119
|
});
|
|
119
|
-
if (results)
|
|
120
|
+
if (results) {
|
|
121
|
+
artifacts = results;
|
|
122
|
+
complete = false;
|
|
123
|
+
}
|
|
120
124
|
}
|
|
121
125
|
const promises = artifacts.map((artifact) => limit(() => ctx.output.write(artifact)));
|
|
122
126
|
await Promise.allSettled(promises);
|
|
127
|
+
if (complete) ctx.output.prune(artifacts);
|
|
123
128
|
await ctx.hooks["codegen:done"]?.({ changed: ids });
|
|
124
129
|
return {
|
|
125
130
|
box: ctx.initMessage(),
|
|
@@ -1495,6 +1500,9 @@ const nodeRuntime = {
|
|
|
1495
1500
|
writeFile: fsExtra.writeFile,
|
|
1496
1501
|
writeFileSync: fsExtra.writeFileSync,
|
|
1497
1502
|
readDirSync: fsExtra.readdirSync,
|
|
1503
|
+
isDirSync(path) {
|
|
1504
|
+
return fsExtra.statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false;
|
|
1505
|
+
},
|
|
1498
1506
|
rmDirSync: fsExtra.emptyDirSync,
|
|
1499
1507
|
rmFileSync: fsExtra.removeSync,
|
|
1500
1508
|
ensureDirSync(path) {
|
|
@@ -1559,6 +1567,69 @@ var OutputEngine = class {
|
|
|
1559
1567
|
this.fs.ensureDirSync(dirname);
|
|
1560
1568
|
return outPath;
|
|
1561
1569
|
};
|
|
1570
|
+
/**
|
|
1571
|
+
* Delete files in the generated directories that this codegen no longer produces.
|
|
1572
|
+
*
|
|
1573
|
+
* Codegen was write-only, so an artifact that stopped being generated stayed on disk
|
|
1574
|
+
* forever. Dropping a pattern from the config rewrote `patterns/index.js` without it and
|
|
1575
|
+
* left `patterns/stack.js` sitting beside it — importing through the barrel then failed
|
|
1576
|
+
* loudly, which is fine, but a deep import resolved, ran, returned a class name and
|
|
1577
|
+
* emitted no css. A stale artifact is worse than a missing one: it answers.
|
|
1578
|
+
*
|
|
1579
|
+
* Scoped to the directories this call actually wrote to, so a directory bamboo does not
|
|
1580
|
+
* generate into is never read, let alone emptied. It is bounded twice over, because the
|
|
1581
|
+
* cost of being wrong here is a deleted file rather than a stale one:
|
|
1582
|
+
*
|
|
1583
|
+
* - only a *complete* codegen may be swept, since a filtered artifact list cannot say what
|
|
1584
|
+
* a directory should contain. That is the caller's to enforce;
|
|
1585
|
+
* - within a directory, only files carrying an extension this codegen actually wrote
|
|
1586
|
+
* *there* are eligible. `patterns/` got `.mjs` and `.d.ts` files, so a leftover
|
|
1587
|
+
* `stack.mjs` is stale; a `.gitignore`, a `README.md` or a `styles.css` is not the kind
|
|
1588
|
+
* of thing we put there and is none of our business.
|
|
1589
|
+
*
|
|
1590
|
+
* The second bound replaces a list of known exceptions, which was the wrong shape: a
|
|
1591
|
+
* denylist has to name every file anyone might legitimately keep in an output directory,
|
|
1592
|
+
* and the failure mode when it misses one is silent deletion. It missed the `.gitignore`
|
|
1593
|
+
* that ships inside a generated directory, which is committed in this repo's own fixtures.
|
|
1594
|
+
* Reasoning from what we wrote needs no such list.
|
|
1595
|
+
*
|
|
1596
|
+
* Subdirectories are left alone; they are swept as themselves when their own artifacts
|
|
1597
|
+
* are written.
|
|
1598
|
+
*/
|
|
1599
|
+
prune = (artifacts) => {
|
|
1600
|
+
const produced = /* @__PURE__ */ new Map();
|
|
1601
|
+
/** Per directory, the file extensions this codegen wrote into it. */
|
|
1602
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
1603
|
+
for (const artifact of artifacts) {
|
|
1604
|
+
if (!artifact) continue;
|
|
1605
|
+
const dir = this.path.join(...artifact.dir ?? this.paths.root);
|
|
1606
|
+
let files = produced.get(dir);
|
|
1607
|
+
if (!files) produced.set(dir, files = /* @__PURE__ */ new Set());
|
|
1608
|
+
let extensions = kinds.get(dir);
|
|
1609
|
+
if (!extensions) kinds.set(dir, extensions = /* @__PURE__ */ new Set());
|
|
1610
|
+
for (const { file, code } of artifact.files) {
|
|
1611
|
+
if (!code) continue;
|
|
1612
|
+
files.add(file);
|
|
1613
|
+
extensions.add(this.path.extname(file));
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
let removed = 0;
|
|
1617
|
+
for (const [dir, files] of produced) {
|
|
1618
|
+
if (!this.fs.existsSync(dir)) continue;
|
|
1619
|
+
const extensions = kinds.get(dir);
|
|
1620
|
+
for (const entry of this.fs.readDirSync(dir)) {
|
|
1621
|
+
if (files.has(entry)) continue;
|
|
1622
|
+
if (!extensions.has(this.path.extname(entry))) continue;
|
|
1623
|
+
const absPath = this.path.join(dir, entry);
|
|
1624
|
+
if (this.fs.isDirSync(absPath)) continue;
|
|
1625
|
+
logger.debug("write:stale", `removing ${entry}`);
|
|
1626
|
+
this.fs.rmFileSync(absPath);
|
|
1627
|
+
removed++;
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
if (removed) logger.debug("write:stale", `Removed ${removed} artifact(s) no longer generated`);
|
|
1631
|
+
return { removed };
|
|
1632
|
+
};
|
|
1562
1633
|
write = (output) => {
|
|
1563
1634
|
if (!output) return;
|
|
1564
1635
|
const { dir = this.paths.root, files } = output;
|
|
@@ -1639,6 +1710,16 @@ var BambooContext = class extends Generator {
|
|
|
1639
1710
|
* syntax error.
|
|
1640
1711
|
*/
|
|
1641
1712
|
parseFailures = /* @__PURE__ */ new Map();
|
|
1713
|
+
/**
|
|
1714
|
+
* Files that call a binding their entrypoint no longer exports, keyed by path.
|
|
1715
|
+
*
|
|
1716
|
+
* Keyed and scoped exactly like `parseFailures`, and for the same reasons: an incremental
|
|
1717
|
+
* pass that skips an unchanged file does not re-parse it, so the finding has to outlive the
|
|
1718
|
+
* pass that recorded it or a no-op rebuild launders a broken build into a green one — and it
|
|
1719
|
+
* has to be dropped once the file is fixed, deleted, or leaves `include`, or the fix can
|
|
1720
|
+
* never take.
|
|
1721
|
+
*/
|
|
1722
|
+
deadCalls = /* @__PURE__ */ new Map();
|
|
1642
1723
|
constructor(conf) {
|
|
1643
1724
|
super(conf);
|
|
1644
1725
|
const config = conf.config;
|
|
@@ -1672,6 +1753,7 @@ var BambooContext = class extends Generator {
|
|
|
1672
1753
|
const unresolved = result.unresolved;
|
|
1673
1754
|
if (!unresolved?.length) return;
|
|
1674
1755
|
for (const entry of unresolved) {
|
|
1756
|
+
if (this.isGenerated(entry.filePath)) continue;
|
|
1675
1757
|
const where = `${entry.filePath}:${entry.line}:${entry.column}`;
|
|
1676
1758
|
const prop = entry.prop ? `\`${entry.prop}\`` : "a property";
|
|
1677
1759
|
const [what] = unresolvedReasons[entry.reason](prop);
|
|
@@ -1732,11 +1814,66 @@ var BambooContext = class extends Generator {
|
|
|
1732
1814
|
const inScope = new Set(Array.from(files ?? this.getFiles(), (file) => this.runtime.path.abs(this.config.cwd, file)));
|
|
1733
1815
|
for (const file of this.parseFailures.keys()) if (!inScope.has(file)) this.parseFailures.delete(file);
|
|
1734
1816
|
if (!this.parseFailures.size) return;
|
|
1735
|
-
const detail = Array.from(this.parseFailures.entries()
|
|
1817
|
+
const detail = truncateList(Array.from(this.parseFailures.entries(), ([file, error]) => `${this.relative(file)}\n${messageOf(error).replace(/^(?=.)/gm, " ")}`), { unit: "file" });
|
|
1736
1818
|
throw new BambooError("EXTRACT_FAILED", `${this.parseFailures.size} file(s) could not be extracted:\n\n${detail}\n\nNothing emits a rule for a file the build could not read, so every style in these is absent from the stylesheet and the classes their components ask for have nothing behind them.`, { cause: new AggregateError(Array.from(this.parseFailures.values()), `${this.parseFailures.size} file(s) could not be extracted`) });
|
|
1737
1819
|
};
|
|
1820
|
+
/**
|
|
1821
|
+
* Fail on a call to a binding the pattern or recipe entrypoint no longer exports.
|
|
1822
|
+
*
|
|
1823
|
+
* The same test `assertExtracted` applies, against the other way of arriving at the same
|
|
1824
|
+
* output. There the build could not read the file; here it read it and the call named
|
|
1825
|
+
* nothing, so the extractor recorded no styles and the class the component asks for has no
|
|
1826
|
+
* rule behind it. Both leave a green build and a stylesheet missing rules, which is the one
|
|
1827
|
+
* failure a diff of the output is the only way to notice.
|
|
1828
|
+
*
|
|
1829
|
+
* Not graded by a severity option, unlike an unresolved token path: that one is inferred
|
|
1830
|
+
* from a value's shape and can be wrong about a literal, while this is read off the
|
|
1831
|
+
* entrypoint's own export list. There is no configuration under which calling a binding
|
|
1832
|
+
* that does not exist is what someone meant.
|
|
1833
|
+
*
|
|
1834
|
+
* Scoped like `assertExtracted`, for the reasons given there — a file taken out of
|
|
1835
|
+
* `include` or deleted is a fix, and an entry naming a path that no longer exists would
|
|
1836
|
+
* fail every later build and wedge a dev server.
|
|
1837
|
+
*/
|
|
1838
|
+
assertNoDeadCalls = (files) => {
|
|
1839
|
+
if (!this.deadCalls.size) return;
|
|
1840
|
+
const inScope = new Set(Array.from(files ?? this.getFiles(), (file) => this.runtime.path.abs(this.config.cwd, file)));
|
|
1841
|
+
for (const file of this.deadCalls.keys()) if (!inScope.has(file)) this.deadCalls.delete(file);
|
|
1842
|
+
if (!this.deadCalls.size) return;
|
|
1843
|
+
const entrypoint = {
|
|
1844
|
+
pattern: "pattern",
|
|
1845
|
+
recipe: "recipe"
|
|
1846
|
+
};
|
|
1847
|
+
const occurrences = Array.from(this.deadCalls.entries()).flatMap(([file, calls]) => calls.map((call) => ({
|
|
1848
|
+
file,
|
|
1849
|
+
call
|
|
1850
|
+
})));
|
|
1851
|
+
const detail = truncateList(Array.from(groupBy(occurrences, ({ call }) => `${call.entrypoint}${call.mod}${call.name}${call.alias}`), ([, group]) => {
|
|
1852
|
+
const { call } = group[0];
|
|
1853
|
+
const named = call.alias === call.name ? `\`${call.name}\`` : `\`${call.name}\` (called as \`${call.alias}\`)`;
|
|
1854
|
+
const files = uniq(group.map(({ file }) => this.relative(file)));
|
|
1855
|
+
const shown = files.slice(0, 5).join(", ");
|
|
1856
|
+
const rest = files.length > 5 ? `, … and ${files.length - 5} more` : "";
|
|
1857
|
+
return `${named} is not a ${entrypoint[call.entrypoint]} — \`${call.mod}\` does not export it.\n ${files.length} file(s): ${shown}${rest}`;
|
|
1858
|
+
}), { unit: "binding" });
|
|
1859
|
+
const count = occurrences.length;
|
|
1860
|
+
throw new BambooError("DEAD_IMPORT", `${count} call(s) name a binding that does not exist:\n\n${detail}\n\nBoth entrypoints are generated from your config, so what they export moves when it does — a pattern dropped from a preset, a recipe renamed. The call survives that as a binding to nothing: nothing extracts it, so every rule it would have contributed is absent from the stylesheet and the classes their components ask for have nothing behind them.`);
|
|
1861
|
+
};
|
|
1738
1862
|
/** A path as the user typed it, when it is under `cwd`. */
|
|
1739
1863
|
relative = (file) => file.startsWith(this.config.cwd) ? file.slice(this.config.cwd.length + 1) : file;
|
|
1864
|
+
/**
|
|
1865
|
+
* Whether a file is one bamboo wrote.
|
|
1866
|
+
*
|
|
1867
|
+
* `include` conventionally covers a source tree that `outdir` sits inside — `./src/**` and
|
|
1868
|
+
* `src/styled-system` — so the build routinely parses its own output. That is load-bearing
|
|
1869
|
+
* rather than accidental, which is why the answer here is "do not report it" rather than
|
|
1870
|
+
* "do not read it": the token and keyframe scans read whatever `include` covers, and a
|
|
1871
|
+
* project that excludes its `outdir` should not lose them.
|
|
1872
|
+
*/
|
|
1873
|
+
isGenerated = (file) => {
|
|
1874
|
+
const outdir = this.runtime.path.join(...this.paths.root);
|
|
1875
|
+
return file === outdir || file.startsWith(outdir + this.runtime.path.sep);
|
|
1876
|
+
};
|
|
1740
1877
|
parseFile = (filePath, styleEncoder) => {
|
|
1741
1878
|
const file = this.runtime.path.abs(this.config.cwd, filePath);
|
|
1742
1879
|
logger.debug("file:extract", file);
|
|
@@ -1750,7 +1887,11 @@ var BambooContext = class extends Generator {
|
|
|
1750
1887
|
logger.caughtError("file:extract", `Failed to parse ${file}`, error);
|
|
1751
1888
|
this.parseFailures.set(file, error);
|
|
1752
1889
|
}
|
|
1753
|
-
if (result)
|
|
1890
|
+
if (result) {
|
|
1891
|
+
this.reportUnresolvedStyles(result);
|
|
1892
|
+
if (result.deadCalls.length) this.deadCalls.set(file, result.deadCalls);
|
|
1893
|
+
else this.deadCalls.delete(file);
|
|
1894
|
+
}
|
|
1754
1895
|
measure();
|
|
1755
1896
|
return result;
|
|
1756
1897
|
};
|
|
@@ -1773,6 +1914,7 @@ var BambooContext = class extends Generator {
|
|
|
1773
1914
|
results.push(result);
|
|
1774
1915
|
});
|
|
1775
1916
|
this.assertExtracted(files);
|
|
1917
|
+
this.assertNoDeadCalls(files);
|
|
1776
1918
|
return {
|
|
1777
1919
|
filesWithCss,
|
|
1778
1920
|
files,
|
|
@@ -2583,12 +2725,15 @@ function* sourceTexts(ctx) {
|
|
|
2583
2725
|
* exists for does not apply to them, and opting out of token pruning should not mean shipping
|
|
2584
2726
|
* a preset's whole filter and gradient set for nothing.
|
|
2585
2727
|
*/
|
|
2728
|
+
/**
|
|
2729
|
+
* Returns the custom properties left standing, for `pruneKeyframes` to root its own walk
|
|
2730
|
+
* at — see `Generator.pruneKeyframes`. `'all'` when this pass had nothing to remove and so
|
|
2731
|
+
* never computed the closure, which is not a missing answer but the correct one: a sheet
|
|
2732
|
+
* nothing was removed from still declares everything it declared.
|
|
2733
|
+
*/
|
|
2586
2734
|
function pruneTokensForBuild(ctx, sheet, results) {
|
|
2587
2735
|
const strategy = ctx.config.prune?.tokens ?? "reachable";
|
|
2588
|
-
if (strategy === "off")
|
|
2589
|
-
ctx.pruneTokens(sheet);
|
|
2590
|
-
return;
|
|
2591
|
-
}
|
|
2736
|
+
if (strategy === "off") return ctx.pruneTokens(sheet)?.reachable ?? "all";
|
|
2592
2737
|
const accounts = strategy === "accounted";
|
|
2593
2738
|
const unresolved = accounts ? ctx.config.prune?.unresolvedPath ?? "warn" : "off";
|
|
2594
2739
|
const paths = /* @__PURE__ */ new Set();
|
|
@@ -2611,10 +2756,7 @@ function pruneTokensForBuild(ctx, sheet, results) {
|
|
|
2611
2756
|
for (const name of tokenVarsFor(ctx, paths)) vars.add(name);
|
|
2612
2757
|
const declared = declaredKeeps(ctx);
|
|
2613
2758
|
for (const name of tokenVarsFor(ctx, declared)) vars.add(name);
|
|
2614
|
-
if (!accounts)
|
|
2615
|
-
ctx.pruneTokens(sheet, vars, reachable);
|
|
2616
|
-
return;
|
|
2617
|
-
}
|
|
2759
|
+
if (!accounts) return ctx.pruneTokens(sheet, vars, reachable)?.reachable ?? "all";
|
|
2618
2760
|
for (const name of tokenVarsFor(ctx, accounting.paths)) vars.add(name);
|
|
2619
2761
|
const bounded = (ctx.config.prune?.keepTokens?.length ?? 0) > 0;
|
|
2620
2762
|
if (accounting.prefixes.size && (bounded || !accounting.declined.length)) {
|
|
@@ -2632,7 +2774,7 @@ function pruneTokensForBuild(ctx, sheet, results) {
|
|
|
2632
2774
|
logger.warn("tokens:unresolved", bounded ? where + "`prune.keepTokens` covers them: they keep what it names rather than every declaration in the theme. Nothing checks that they stay inside it, which is why it is yours to declare — a read landing outside the patterns loses its declaration and resolves to a `var()` with nothing behind it. Respell what you can, and widen the patterns for what you cannot." : where + "`prune.tokens: 'accounted'` asserts that every token path resolves at build time. Spell the path as a string literal at the call, give a template a static prefix so it can be bounded, name the category they land in with `prune: { keepTokens: ['colors.*'] }`, or set `prune: { tokens: 'reachable' }` to stop asserting.");
|
|
2633
2775
|
}
|
|
2634
2776
|
if (reported.length && unresolved !== "off") logger.warn("tokens:unresolved", `${reported.length} reference(s) could not be accounted for, so ` + (bounded ? `\`prune.keepTokens\` decides what they keep` : `every token declaration is kept`) + `.\n\n${formatDeclined(ctx, reported)}\n\nThese are shapes the build cannot follow rather than paths you can respell — a component stored post-transform, a file it could not parse, a barrel it cannot classify, a dynamic \`import()\`. ` + (bounded ? "Nothing checks that they stay inside `keepTokens`, which is why it is yours to declare: a read landing outside it loses its declaration. Narrow `include`, or widen the patterns." : "Narrow `include`, name the categories they reach with `prune: { keepTokens: [...] }`, or accept the keeps."));
|
|
2635
|
-
ctx.pruneTokens(sheet, vars, !bounded && accounting.declined.length > 0 && reachable);
|
|
2777
|
+
return ctx.pruneTokens(sheet, vars, !bounded && accounting.declined.length > 0 && reachable)?.reachable ?? "all";
|
|
2636
2778
|
}
|
|
2637
2779
|
/**
|
|
2638
2780
|
* The dash-cased spelling of a token path, as it appears in the emitted css variable.
|
|
@@ -2740,7 +2882,7 @@ const keyframeNames = (ctx) => Object.keys(ctx.config.theme?.keyframes ?? {});
|
|
|
2740
2882
|
*
|
|
2741
2883
|
* Lowercase-initial only, so a JSX component (`<Button />`) is not mistaken for an element.
|
|
2742
2884
|
* That cuts the other way too — a component rendering `<button>` inside a dependency is
|
|
2743
|
-
* invisible here, which is why `prune
|
|
2885
|
+
* invisible here, which is why `preflight.prune` is opt-in.
|
|
2744
2886
|
*
|
|
2745
2887
|
* The commoner blind spot is nearer than a dependency: this reads `include`, and `include`
|
|
2746
2888
|
* conventionally covers components rather than markup. An entry template — `index.html`,
|
|
@@ -2900,13 +3042,15 @@ var Builder = class {
|
|
|
2900
3042
|
const hasConfigChanged = this.affecteds ? this.affecteds.hasConfigChanged : true;
|
|
2901
3043
|
if (!this.filesMeta && !hasConfigChanged) {
|
|
2902
3044
|
logger.debug("builder", "No files or config changed, skipping extract");
|
|
2903
|
-
|
|
3045
|
+
ctx.assertExtracted();
|
|
3046
|
+
return ctx.assertNoDeadCalls();
|
|
2904
3047
|
}
|
|
2905
3048
|
const files = ctx.getFiles();
|
|
2906
3049
|
const done = logger.time.info("Extracted in");
|
|
2907
|
-
|
|
3050
|
+
for (const file of files) this.extractFile(ctx, file);
|
|
2908
3051
|
done();
|
|
2909
3052
|
ctx.assertExtracted(files);
|
|
3053
|
+
ctx.assertNoDeadCalls(files);
|
|
2910
3054
|
};
|
|
2911
3055
|
isValidRoot = (root) => {
|
|
2912
3056
|
const ctx = this.getContextOrThrow();
|
|
@@ -2943,9 +3087,9 @@ var Builder = class {
|
|
|
2943
3087
|
const sheet = ctx.createSheet();
|
|
2944
3088
|
if (layerParams) ctx.appendLayerParams(sheet);
|
|
2945
3089
|
ctx.appendBaselineCss(sheet);
|
|
2946
|
-
pruneTokensForBuild(ctx, sheet, []);
|
|
2947
|
-
if (ctx.config.
|
|
2948
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
|
|
3090
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, []);
|
|
3091
|
+
if (prunesPreflight(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
3092
|
+
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)), reachableVars);
|
|
2949
3093
|
return ctx.getCss(sheet);
|
|
2950
3094
|
};
|
|
2951
3095
|
registerDependency = (fn) => {
|
|
@@ -3033,7 +3177,7 @@ const cssgen = async (ctx, options) => {
|
|
|
3033
3177
|
if (type) {
|
|
3034
3178
|
const done = logger.time.info(ctx.messages.cssArtifactComplete(type));
|
|
3035
3179
|
ctx.appendCssOfType(type, sheet);
|
|
3036
|
-
if (type === "preflight" && ctx.config.
|
|
3180
|
+
if (type === "preflight" && prunesPreflight(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
3037
3181
|
if (outfile) {
|
|
3038
3182
|
const css = ctx.getCss(sheet);
|
|
3039
3183
|
logger.info("css", ctx.runtime.path.resolve(outfile));
|
|
@@ -3046,9 +3190,9 @@ const cssgen = async (ctx, options) => {
|
|
|
3046
3190
|
ctx.appendLayerParams(sheet);
|
|
3047
3191
|
ctx.appendBaselineCss(sheet);
|
|
3048
3192
|
ctx.appendParserCss(sheet);
|
|
3049
|
-
pruneTokensForBuild(ctx, sheet, results);
|
|
3050
|
-
if (ctx.config.
|
|
3051
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
|
|
3193
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, results);
|
|
3194
|
+
if (prunesPreflight(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
3195
|
+
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)), reachableVars);
|
|
3052
3196
|
if (splitting) await ctx.writeSplitCss(sheet);
|
|
3053
3197
|
else if (outfile) {
|
|
3054
3198
|
const css = ctx.getCss(sheet);
|
|
@@ -3118,9 +3262,9 @@ async function build(ctx, artifactIds) {
|
|
|
3118
3262
|
ctx.appendBaselineCss(sheet);
|
|
3119
3263
|
const parsed = ctx.parseFiles();
|
|
3120
3264
|
ctx.appendParserCss(sheet);
|
|
3121
|
-
pruneTokensForBuild(ctx, sheet, parsed.results);
|
|
3122
|
-
if (ctx.config.
|
|
3123
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
|
|
3265
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, parsed.results);
|
|
3266
|
+
if (prunesPreflight(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
3267
|
+
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)), reachableVars);
|
|
3124
3268
|
await ctx.writeCss(sheet);
|
|
3125
3269
|
done(ctx.messages.buildComplete(parsed.files.length));
|
|
3126
3270
|
}
|
|
@@ -3164,9 +3308,9 @@ async function generate(config, configPath) {
|
|
|
3164
3308
|
ctx.appendLayerParams(sheet);
|
|
3165
3309
|
ctx.appendBaselineCss(sheet);
|
|
3166
3310
|
ctx.appendParserCss(sheet);
|
|
3167
|
-
pruneTokensForBuild(ctx, sheet, []);
|
|
3168
|
-
if (ctx.config.
|
|
3169
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
|
|
3311
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, []);
|
|
3312
|
+
if (prunesPreflight(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
3313
|
+
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)), reachableVars);
|
|
3170
3314
|
const css = ctx.getCss(sheet);
|
|
3171
3315
|
await ctx.runtime.fs.writeFile(outfile, css);
|
|
3172
3316
|
done();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.34.0",
|
|
4
4
|
"description": "The core css bamboo library",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,17 +52,17 @@
|
|
|
52
52
|
"postcss": "8.5.26",
|
|
53
53
|
"ts-morph": "28.0.0",
|
|
54
54
|
"ts-pattern": "5.9.0",
|
|
55
|
-
"@bamboocss/config": "1.
|
|
56
|
-
"@bamboocss/core": "1.
|
|
57
|
-
"@bamboocss/generator": "1.
|
|
58
|
-
"@bamboocss/logger": "1.
|
|
59
|
-
"@bamboocss/parser": "1.
|
|
60
|
-
"@bamboocss/plugin-svelte": "1.
|
|
61
|
-
"@bamboocss/plugin-vue": "1.
|
|
62
|
-
"@bamboocss/reporter": "1.
|
|
63
|
-
"@bamboocss/shared": "1.
|
|
64
|
-
"@bamboocss/token-dictionary": "1.
|
|
65
|
-
"@bamboocss/types": "1.
|
|
55
|
+
"@bamboocss/config": "1.34.0",
|
|
56
|
+
"@bamboocss/core": "1.34.0",
|
|
57
|
+
"@bamboocss/generator": "1.34.0",
|
|
58
|
+
"@bamboocss/logger": "1.34.0",
|
|
59
|
+
"@bamboocss/parser": "1.34.0",
|
|
60
|
+
"@bamboocss/plugin-svelte": "1.34.0",
|
|
61
|
+
"@bamboocss/plugin-vue": "1.34.0",
|
|
62
|
+
"@bamboocss/reporter": "1.34.0",
|
|
63
|
+
"@bamboocss/shared": "1.34.0",
|
|
64
|
+
"@bamboocss/token-dictionary": "1.34.0",
|
|
65
|
+
"@bamboocss/types": "1.34.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"@types/fs-extra": "11.0.4",
|