@bamboocss/node 1.58.0 → 1.58.2
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.cjs +215 -100
- package/dist/index.d.cts +35 -22
- package/dist/index.d.mts +35 -22
- package/dist/index.mjs +216 -101
- package/dist/native/win32-x64-msvc.node +0 -0
- package/package.json +12 -12
package/dist/index.cjs
CHANGED
|
@@ -615,6 +615,112 @@ async function analyze(ctx, options = {}) {
|
|
|
615
615
|
ctx.runtime.fs.ensureDirSync(ctx.runtime.path.dirname(filePath));
|
|
616
616
|
return ctx.runtime.fs.writeFile(filePath, JSON.stringify(value, replacer, 2));
|
|
617
617
|
};
|
|
618
|
+
/**
|
|
619
|
+
* The tokens and keyframes the build's own prune removes, worked out once and shared by every
|
|
620
|
+
* report that speaks of use, so none of them can call a name unused that `getUnused` does not,
|
|
621
|
+
* or the other way round.
|
|
622
|
+
*
|
|
623
|
+
* Run with every prune on, whatever the config says, so a name here is one the stylesheet ships
|
|
624
|
+
* without. Anything the prune keeps for a reader it cannot follow — a `token()` path built at
|
|
625
|
+
* runtime, a theme, a `keepTokens` pattern — is kept here too: being told a token is unused when
|
|
626
|
+
* something still asks for it is worse than not being told at all.
|
|
627
|
+
*
|
|
628
|
+
* Read off a sheet of its own. The prune's settings are laid over the context's while it is
|
|
629
|
+
* built, and `unresolvedPath` is off for it: that one only decides how loudly the prune says what
|
|
630
|
+
* it could not read, and a project that does not prune tokens never hears it.
|
|
631
|
+
*/
|
|
632
|
+
let pruned;
|
|
633
|
+
const prunedNames = () => {
|
|
634
|
+
if (pruned) return pruned;
|
|
635
|
+
const prune = {
|
|
636
|
+
...ctx.config.prune,
|
|
637
|
+
keyframes: true,
|
|
638
|
+
unresolvedPath: "off"
|
|
639
|
+
};
|
|
640
|
+
if (prune.tokens === false) delete prune.tokens;
|
|
641
|
+
const configured = ctx.config.prune;
|
|
642
|
+
ctx.config.prune = prune;
|
|
643
|
+
let sheet;
|
|
644
|
+
try {
|
|
645
|
+
sheet = assembleExtractedSheet(ctx, {
|
|
646
|
+
parserResults,
|
|
647
|
+
prunePreflight: false
|
|
648
|
+
});
|
|
649
|
+
} finally {
|
|
650
|
+
ctx.config.prune = configured;
|
|
651
|
+
}
|
|
652
|
+
const declared = /* @__PURE__ */ new Set();
|
|
653
|
+
const keyframes = /* @__PURE__ */ new Set();
|
|
654
|
+
sheet.layers.tokens.walkDecls((decl) => {
|
|
655
|
+
if (decl.prop.startsWith("--")) declared.add(decl.prop);
|
|
656
|
+
});
|
|
657
|
+
sheet.layers.tokens.walkAtRules(/keyframes$/, (rule) => {
|
|
658
|
+
keyframes.add(rule.params.trim().replace(/^(["'])(.*)\1$/, "$2").replace(/\\(.)/g, "$1"));
|
|
659
|
+
});
|
|
660
|
+
const declarable = /* @__PURE__ */ new Set();
|
|
661
|
+
for (const vars of ctx.tokens.view.vars.values()) for (const name of vars.keys()) declarable.add(name);
|
|
662
|
+
const judged = /* @__PURE__ */ new Map();
|
|
663
|
+
const unused = /* @__PURE__ */ new Map();
|
|
664
|
+
const tokens = [];
|
|
665
|
+
const add = (into, category, name) => {
|
|
666
|
+
const names = into.get(category) ?? /* @__PURE__ */ new Set();
|
|
667
|
+
names.add(name);
|
|
668
|
+
into.set(category, names);
|
|
669
|
+
};
|
|
670
|
+
for (const token of ctx.tokens.allTokens) {
|
|
671
|
+
const { isVirtual, isNegative, category } = token.extensions;
|
|
672
|
+
if (isVirtual || isNegative || category === "breakpoints" || token.name.startsWith("sizes.breakpoint-")) continue;
|
|
673
|
+
const name = token.extensions.var;
|
|
674
|
+
if (!declarable.has(name)) continue;
|
|
675
|
+
if (category) add(judged, category, token.extensions.prop);
|
|
676
|
+
if (declared.has(name)) continue;
|
|
677
|
+
tokens.push(token.name);
|
|
678
|
+
if (category) add(unused, category, token.extensions.prop);
|
|
679
|
+
}
|
|
680
|
+
pruned = {
|
|
681
|
+
tokens: [...new Set(tokens)].sort(),
|
|
682
|
+
keyframes: Object.keys(ctx.config.theme?.keyframes ?? {}).filter((name) => !keyframes.has(name)).sort(),
|
|
683
|
+
judged,
|
|
684
|
+
unused
|
|
685
|
+
};
|
|
686
|
+
return pruned;
|
|
687
|
+
};
|
|
688
|
+
const { staticCss } = ctx.config;
|
|
689
|
+
const emitted = (rules) => (name) => rules === "*" || rules != null && typeof rules === "object" && name in rules;
|
|
690
|
+
const unusedPatterns = () => {
|
|
691
|
+
const kept = emitted(staticCss?.patterns);
|
|
692
|
+
return reporter.getPatternReport().filter((entry) => !entry.usedCount && !kept(entry.patternName)).map((entry) => entry.patternName).sort();
|
|
693
|
+
};
|
|
694
|
+
/**
|
|
695
|
+
* The configured names no source uses, of the kinds asked for.
|
|
696
|
+
*
|
|
697
|
+
* Tokens and keyframes are what the build's own prune removes; see `prunedNames`. A recipe or a
|
|
698
|
+
* pattern is one no source calls and `staticCss` does not emit regardless.
|
|
699
|
+
*/
|
|
700
|
+
const getUnused = (kinds = [
|
|
701
|
+
"tokens",
|
|
702
|
+
"recipes",
|
|
703
|
+
"patterns",
|
|
704
|
+
"keyframes"
|
|
705
|
+
]) => {
|
|
706
|
+
const unused = {
|
|
707
|
+
tokens: [],
|
|
708
|
+
recipes: [],
|
|
709
|
+
patterns: [],
|
|
710
|
+
keyframes: []
|
|
711
|
+
};
|
|
712
|
+
if (kinds.includes("tokens")) unused.tokens = prunedNames().tokens;
|
|
713
|
+
if (kinds.includes("keyframes")) unused.keyframes = prunedNames().keyframes;
|
|
714
|
+
if (kinds.includes("recipes")) {
|
|
715
|
+
const called = new Set(reporter.getRecipeReport().map((entry) => entry.recipeName));
|
|
716
|
+
const inConfig = emitted(staticCss?.recipes);
|
|
717
|
+
const { recipes = {}, slotRecipes = {} } = ctx.config.theme ?? {};
|
|
718
|
+
const ofItself = (name) => Boolean((recipes[name] ?? slotRecipes[name])?.staticCss?.length);
|
|
719
|
+
unused.recipes = [...ctx.recipes.keys].filter((name) => !called.has(name) && !inConfig(name) && !ofItself(name)).sort();
|
|
720
|
+
}
|
|
721
|
+
if (kinds.includes("patterns")) unused.patterns = unusedPatterns();
|
|
722
|
+
return unused;
|
|
723
|
+
};
|
|
618
724
|
return {
|
|
619
725
|
getRecipeReport(format = "table") {
|
|
620
726
|
const report = reporter.getRecipeReport();
|
|
@@ -623,104 +729,47 @@ async function analyze(ctx, options = {}) {
|
|
|
623
729
|
formatted: formatRecipeReport(report, format)
|
|
624
730
|
};
|
|
625
731
|
},
|
|
732
|
+
/** Each category's tokens, counted as used exactly when the build keeps them. */
|
|
626
733
|
getTokenReport(format = "table") {
|
|
627
|
-
const
|
|
734
|
+
const { judged, unused } = prunedNames();
|
|
735
|
+
const report = reporter.getTokenReport({
|
|
736
|
+
judged,
|
|
737
|
+
unused
|
|
738
|
+
});
|
|
628
739
|
return {
|
|
629
740
|
report,
|
|
630
741
|
formatted: formatTokenReport(report.getSummary(), format)
|
|
631
742
|
};
|
|
632
743
|
},
|
|
633
|
-
/** Every pattern the config defines,
|
|
634
|
-
getPatternReport: () =>
|
|
744
|
+
/** Every pattern the config defines, how often each is called, and whether anything uses it. */
|
|
745
|
+
getPatternReport: () => {
|
|
746
|
+
const unused = new Set(unusedPatterns());
|
|
747
|
+
return reporter.getPatternReport().map((entry) => ({
|
|
748
|
+
...entry,
|
|
749
|
+
unused: unused.has(entry.patternName)
|
|
750
|
+
}));
|
|
751
|
+
},
|
|
635
752
|
/** Every style property written, and how often. */
|
|
636
753
|
getUtilityReport: () => reporter.getUtilityReport(),
|
|
637
|
-
/** Every keyframe the theme defines,
|
|
638
|
-
getKeyframeReport: () =>
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
* Anything the prune keeps for a reader it cannot follow — a `token()` path built at runtime,
|
|
645
|
-
* a theme, a `keepTokens` pattern — is kept here too, and not listed: being told a token is
|
|
646
|
-
* unused when something still asks for it is worse than not being told at all. A recipe or a
|
|
647
|
-
* pattern is one no source calls and `staticCss` does not emit regardless.
|
|
648
|
-
*
|
|
649
|
-
* Read off a sheet of its own. The prune's settings are laid over the context's while it is
|
|
650
|
-
* built, and `unresolvedPath` is off for it: that one only decides how loudly the prune says
|
|
651
|
-
* what it could not read, and a project that does not prune tokens never hears it.
|
|
652
|
-
*/
|
|
653
|
-
getUnused(kinds = [
|
|
654
|
-
"tokens",
|
|
655
|
-
"recipes",
|
|
656
|
-
"patterns",
|
|
657
|
-
"keyframes"
|
|
658
|
-
]) {
|
|
659
|
-
const unused = {
|
|
660
|
-
tokens: [],
|
|
661
|
-
recipes: [],
|
|
662
|
-
patterns: [],
|
|
663
|
-
keyframes: []
|
|
664
|
-
};
|
|
665
|
-
if (kinds.includes("tokens") || kinds.includes("keyframes")) {
|
|
666
|
-
const prune = {
|
|
667
|
-
...ctx.config.prune,
|
|
668
|
-
keyframes: true,
|
|
669
|
-
unresolvedPath: "off"
|
|
670
|
-
};
|
|
671
|
-
if (prune.tokens === false) delete prune.tokens;
|
|
672
|
-
const configured = ctx.config.prune;
|
|
673
|
-
ctx.config.prune = prune;
|
|
674
|
-
let sheet;
|
|
675
|
-
try {
|
|
676
|
-
sheet = assembleExtractedSheet(ctx, {
|
|
677
|
-
parserResults,
|
|
678
|
-
prunePreflight: false
|
|
679
|
-
});
|
|
680
|
-
} finally {
|
|
681
|
-
ctx.config.prune = configured;
|
|
682
|
-
}
|
|
683
|
-
const declared = /* @__PURE__ */ new Set();
|
|
684
|
-
const keyframes = /* @__PURE__ */ new Set();
|
|
685
|
-
sheet.layers.tokens.walkDecls((decl) => {
|
|
686
|
-
if (decl.prop.startsWith("--")) declared.add(decl.prop);
|
|
687
|
-
});
|
|
688
|
-
sheet.layers.tokens.walkAtRules(/keyframes$/, (rule) => {
|
|
689
|
-
keyframes.add(rule.params.trim().replace(/^(["'])(.*)\1$/, "$2").replace(/\\(.)/g, "$1"));
|
|
690
|
-
});
|
|
691
|
-
const declarable = /* @__PURE__ */ new Set();
|
|
692
|
-
for (const vars of ctx.tokens.view.vars.values()) for (const name of vars.keys()) declarable.add(name);
|
|
693
|
-
const tokens = /* @__PURE__ */ new Set();
|
|
694
|
-
for (const token of ctx.tokens.allTokens) {
|
|
695
|
-
const { isVirtual, isNegative, category } = token.extensions;
|
|
696
|
-
if (isVirtual || isNegative || category === "breakpoints" || token.name.startsWith("sizes.breakpoint-")) continue;
|
|
697
|
-
const name = token.extensions.var;
|
|
698
|
-
if (declarable.has(name) && !declared.has(name)) tokens.add(token.name);
|
|
699
|
-
}
|
|
700
|
-
if (kinds.includes("tokens")) unused.tokens = [...tokens].sort();
|
|
701
|
-
if (kinds.includes("keyframes")) unused.keyframes = Object.keys(ctx.config.theme?.keyframes ?? {}).filter((name) => !keyframes.has(name)).sort();
|
|
702
|
-
}
|
|
703
|
-
const { staticCss } = ctx.config;
|
|
704
|
-
const emitted = (rules) => (name) => rules === "*" || rules != null && typeof rules === "object" && name in rules;
|
|
705
|
-
if (kinds.includes("recipes")) {
|
|
706
|
-
const called = new Set(reporter.getRecipeReport().map((entry) => entry.recipeName));
|
|
707
|
-
const inConfig = emitted(staticCss?.recipes);
|
|
708
|
-
const { recipes = {}, slotRecipes = {} } = ctx.config.theme ?? {};
|
|
709
|
-
const ofItself = (name) => Boolean((recipes[name] ?? slotRecipes[name])?.staticCss?.length);
|
|
710
|
-
unused.recipes = [...ctx.recipes.keys].filter((name) => !called.has(name) && !inConfig(name) && !ofItself(name)).sort();
|
|
711
|
-
}
|
|
712
|
-
if (kinds.includes("patterns")) {
|
|
713
|
-
const kept = emitted(staticCss?.patterns);
|
|
714
|
-
unused.patterns = reporter.getPatternReport().filter((entry) => !entry.usedCount && !kept(entry.patternName)).map((entry) => entry.patternName).sort();
|
|
715
|
-
}
|
|
716
|
-
return unused;
|
|
754
|
+
/** Every keyframe the theme defines, how often an animation names it, and whether the build keeps it. */
|
|
755
|
+
getKeyframeReport: () => {
|
|
756
|
+
const unused = new Set(prunedNames().keyframes);
|
|
757
|
+
return reporter.getKeyframeReport().map((entry) => ({
|
|
758
|
+
...entry,
|
|
759
|
+
unused: unused.has(entry.keyframe)
|
|
760
|
+
}));
|
|
717
761
|
},
|
|
762
|
+
getUnused,
|
|
718
763
|
/** The names as JSON, of the kinds `getUnused` was asked for. */
|
|
719
764
|
writeUnused(filePath, unused) {
|
|
720
765
|
return writeJson(filePath, unused);
|
|
721
766
|
},
|
|
767
|
+
/** The extraction report, with what `getUnused` makes of it, so the file cannot be read as calling a kept name unused. */
|
|
722
768
|
writeReport(filePath) {
|
|
723
|
-
return writeJson(filePath,
|
|
769
|
+
return writeJson(filePath, {
|
|
770
|
+
...reporter.report,
|
|
771
|
+
unused: getUnused()
|
|
772
|
+
});
|
|
724
773
|
}
|
|
725
774
|
};
|
|
726
775
|
}
|
|
@@ -2907,6 +2956,7 @@ var DiffEngine = class {
|
|
|
2907
2956
|
if (!affected.hasConfigChanged) {
|
|
2908
2957
|
applyTsConfig(this.ctx.conf, conf);
|
|
2909
2958
|
rememberTsConfigResolutionFiles(this.ctx.conf, getTsConfigResolutionFiles(conf));
|
|
2959
|
+
this.ctx.conf.dependencies = conf.dependencies;
|
|
2910
2960
|
}
|
|
2911
2961
|
return affected;
|
|
2912
2962
|
}
|
|
@@ -3518,9 +3568,15 @@ const nodeRuntime = {
|
|
|
3518
3568
|
} : false
|
|
3519
3569
|
});
|
|
3520
3570
|
_bamboocss_logger.logger.debug("watch:file", `Watching [ ${dirnames.join(", ")} ]`);
|
|
3521
|
-
|
|
3571
|
+
const onInterrupt = async () => {
|
|
3522
3572
|
await watcher.close();
|
|
3523
|
-
}
|
|
3573
|
+
};
|
|
3574
|
+
process.once("SIGINT", onInterrupt);
|
|
3575
|
+
const close = watcher.close.bind(watcher);
|
|
3576
|
+
watcher.close = () => {
|
|
3577
|
+
process.off("SIGINT", onInterrupt);
|
|
3578
|
+
return close();
|
|
3579
|
+
};
|
|
3524
3580
|
return watcher;
|
|
3525
3581
|
}
|
|
3526
3582
|
}
|
|
@@ -4536,23 +4592,80 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
4536
4592
|
if (fs.existsSync(recipesIndex)) fs.rmFileSync(recipesIndex);
|
|
4537
4593
|
if (fs.existsSync(recipesDir)) fs.rmFileSync(recipesDir);
|
|
4538
4594
|
};
|
|
4595
|
+
/**
|
|
4596
|
+
* Call `cb` when a file the config is built from changes.
|
|
4597
|
+
*
|
|
4598
|
+
* `cb` reloads the config, and hands the context it built to `reloaded` as soon as it has one, so
|
|
4599
|
+
* the watch can follow what that config is built from. Armed once with this context's files, an
|
|
4600
|
+
* edit that swapped in a preset, or imported one more module, left the new file unwatched:
|
|
4601
|
+
* editing it did nothing until the process restarted. Handed over before `cb` builds, because a
|
|
4602
|
+
* build can fail where the reload did not — a recipe in the new preset naming no token — and the
|
|
4603
|
+
* file to fix is that preset.
|
|
4604
|
+
*/
|
|
4539
4605
|
watchConfig = (cb, opts) => {
|
|
4540
4606
|
const { cwd, poll, exclude } = opts ?? {};
|
|
4541
4607
|
_bamboocss_logger.logger.info("ctx:watch", this.messages.configWatch());
|
|
4542
|
-
const
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4608
|
+
const arm = (include) => {
|
|
4609
|
+
const watcher = this.runtime.fs.watch({
|
|
4610
|
+
include,
|
|
4611
|
+
exclude,
|
|
4612
|
+
cwd,
|
|
4613
|
+
poll
|
|
4614
|
+
});
|
|
4615
|
+
watcher.on("all", (event, file) => {
|
|
4616
|
+
if (event === "add" || event === "change") rebuild(file);
|
|
4617
|
+
});
|
|
4618
|
+
return watcher;
|
|
4619
|
+
};
|
|
4620
|
+
let files = this.configFiles();
|
|
4621
|
+
let watcher = arm(files);
|
|
4622
|
+
const rearm = async (nextFiles) => {
|
|
4623
|
+
if (nextFiles.join("\n") === files.join("\n")) return;
|
|
4624
|
+
const previous = watcher;
|
|
4625
|
+
files = nextFiles;
|
|
4626
|
+
watcher = arm(files);
|
|
4627
|
+
await previous.close();
|
|
4628
|
+
};
|
|
4548
4629
|
const rebuild = (0, perfect_debounce.debounce)(async (file) => {
|
|
4549
4630
|
_bamboocss_logger.logger.info("ctx:change", "config changed, rebuilding...");
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4631
|
+
const reload = {};
|
|
4632
|
+
try {
|
|
4633
|
+
const next = await cb(file, (ctx) => {
|
|
4634
|
+
reload.ctx = ctx;
|
|
4635
|
+
});
|
|
4636
|
+
if (next) reload.ctx = next;
|
|
4637
|
+
} catch (error) {
|
|
4638
|
+
_bamboocss_logger.logger.error("ctx:rebuild", error instanceof Error ? error.message : String(error));
|
|
4639
|
+
const reloaded = reload.ctx;
|
|
4640
|
+
const nextFiles = reloaded ? reloaded.configFiles() : (0, _bamboocss_shared.uniq)([
|
|
4641
|
+
...files,
|
|
4642
|
+
...this.importedFiles(),
|
|
4643
|
+
...(0, _bamboocss_config.filesReadBy)(error)
|
|
4644
|
+
]).sort();
|
|
4645
|
+
await reportRebuildFailure(() => rearm(nextFiles));
|
|
4646
|
+
return;
|
|
4647
|
+
}
|
|
4648
|
+
const reloaded = reload.ctx;
|
|
4649
|
+
if (reloaded) await reportRebuildFailure(() => rearm(reloaded.configFiles()));
|
|
4554
4650
|
});
|
|
4555
4651
|
};
|
|
4652
|
+
/**
|
|
4653
|
+
* The files the config is built from: the config, what it imports, the presets it names by path,
|
|
4654
|
+
* and its `dependencies` — as patterns too, so a file that starts to match one is seen.
|
|
4655
|
+
*/
|
|
4656
|
+
configFiles = () => (0, _bamboocss_shared.uniq)([
|
|
4657
|
+
...this.explicitDeps,
|
|
4658
|
+
...this.conf.dependencies,
|
|
4659
|
+
...this.config.dependencies ?? []
|
|
4660
|
+
]).sort();
|
|
4661
|
+
/** What the config file imports, read off its source without running it, for a config that failed to load. */
|
|
4662
|
+
importedFiles = () => {
|
|
4663
|
+
try {
|
|
4664
|
+
return [...(0, _bamboocss_config.getConfigDependencies)(this.conf.path, this.conf.tsOptions, this.conf.tsconfig?.compilerOptions).deps];
|
|
4665
|
+
} catch {
|
|
4666
|
+
return [];
|
|
4667
|
+
}
|
|
4668
|
+
};
|
|
4556
4669
|
watchFiles = (cb, opts) => {
|
|
4557
4670
|
const { include, exclude, poll, cwd } = this.config;
|
|
4558
4671
|
_bamboocss_logger.logger.info("ctx:watch", this.messages.watch());
|
|
@@ -6371,10 +6484,11 @@ async function generate(config, configPath, options = {}) {
|
|
|
6371
6484
|
if (options.requireFiles && !ctx.config.emitTokensOnly) assertFilesMatched(ctx);
|
|
6372
6485
|
await build(ctx, watch ? sourceScanCache : void 0);
|
|
6373
6486
|
if (watch) {
|
|
6374
|
-
ctx.watchConfig(async () => {
|
|
6487
|
+
ctx.watchConfig(async (_file, reloaded) => {
|
|
6375
6488
|
const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
|
|
6376
6489
|
ctx = new BambooContext(conf);
|
|
6377
6490
|
});
|
|
6491
|
+
reloaded(ctx);
|
|
6378
6492
|
sourceScanCache.entries.clear();
|
|
6379
6493
|
sourceScanCache.resolvedTokenReferences.clear();
|
|
6380
6494
|
_bamboocss_logger.logger.info("ctx:updated", "config rebuilt ✅");
|
|
@@ -6382,7 +6496,8 @@ async function generate(config, configPath, options = {}) {
|
|
|
6382
6496
|
config: ctx.config,
|
|
6383
6497
|
changes: affecteds
|
|
6384
6498
|
});
|
|
6385
|
-
|
|
6499
|
+
await build(ctx, sourceScanCache, artifactsToRebuild(affecteds));
|
|
6500
|
+
return ctx;
|
|
6386
6501
|
}, {
|
|
6387
6502
|
cwd,
|
|
6388
6503
|
poll
|
|
@@ -6492,11 +6607,11 @@ async function setupConfig(cwd, opts = {}) {
|
|
|
6492
6607
|
}
|
|
6493
6608
|
const { detect } = await import("package-manager-detector");
|
|
6494
6609
|
const pm = ((await detect({ cwd }))?.agent ?? "npm").split("@")[0];
|
|
6495
|
-
const cmd = pm === "npm" ? "
|
|
6610
|
+
const cmd = pm === "npm" ? "npx" : pm;
|
|
6496
6611
|
const file = (0, look_it_up.lookItUpSync)("tsconfig.json", cwd) ? "bamboo.config.ts" : "bamboo.config.mjs";
|
|
6497
|
-
_bamboocss_logger.logger.info("init:config", `creating bamboo config file: ${(0, _bamboocss_logger.quote)(file)}`);
|
|
6498
6612
|
if (!force && configFile) _bamboocss_logger.logger.warn("init:config", _bamboocss_core.messages.configExists(cmd));
|
|
6499
6613
|
else {
|
|
6614
|
+
_bamboocss_logger.logger.info("init:config", `creating bamboo config file: ${(0, _bamboocss_logger.quote)(file)}`);
|
|
6500
6615
|
const content = outdent.outdent`
|
|
6501
6616
|
import { defineConfig } from "@bamboocss/dev"
|
|
6502
6617
|
|
package/dist/index.d.cts
CHANGED
|
@@ -692,7 +692,24 @@ declare class BambooContext extends Generator {
|
|
|
692
692
|
};
|
|
693
693
|
writeCss: (sheet?: Stylesheet) => Promise<PromiseSettledResult<void>[]> | undefined;
|
|
694
694
|
writeSplitCss: (sheet: Stylesheet) => Promise<void>;
|
|
695
|
-
|
|
695
|
+
/**
|
|
696
|
+
* Call `cb` when a file the config is built from changes.
|
|
697
|
+
*
|
|
698
|
+
* `cb` reloads the config, and hands the context it built to `reloaded` as soon as it has one, so
|
|
699
|
+
* the watch can follow what that config is built from. Armed once with this context's files, an
|
|
700
|
+
* edit that swapped in a preset, or imported one more module, left the new file unwatched:
|
|
701
|
+
* editing it did nothing until the process restarted. Handed over before `cb` builds, because a
|
|
702
|
+
* build can fail where the reload did not — a recipe in the new preset naming no token — and the
|
|
703
|
+
* file to fix is that preset.
|
|
704
|
+
*/
|
|
705
|
+
watchConfig: (cb: (file: string, reloaded: (ctx: BambooContext) => void) => BambooContext | void | Promise<BambooContext | void>, opts?: Omit<WatchOptions, "include">) => void;
|
|
706
|
+
/**
|
|
707
|
+
* The files the config is built from: the config, what it imports, the presets it names by path,
|
|
708
|
+
* and its `dependencies` — as patterns too, so a file that starts to match one is seen.
|
|
709
|
+
*/
|
|
710
|
+
private configFiles;
|
|
711
|
+
/** What the config file imports, read off its source without running it, for a config that failed to load. */
|
|
712
|
+
private importedFiles;
|
|
696
713
|
watchFiles: (cb: (event: WatcherEventType, file: string) => void | Promise<void>, opts?: Omit<WatchOptions, "include" | "exclude" | "poll" | "cwd" | "logger">) => void;
|
|
697
714
|
}
|
|
698
715
|
//#endregion
|
|
@@ -714,30 +731,26 @@ declare function analyze(ctx: BambooContext, options?: AnalysisOptions): Promise
|
|
|
714
731
|
getRecipeReport(format?: ReportFormat): {
|
|
715
732
|
report: import("@bamboocss/reporter").RecipeReportEntry[];
|
|
716
733
|
formatted: string;
|
|
717
|
-
};
|
|
734
|
+
}; /** Each category's tokens, counted as used exactly when the build keeps them. */
|
|
718
735
|
getTokenReport(format?: ReportFormat): {
|
|
719
736
|
report: import("@bamboocss/reporter").TokenAnalysisReport;
|
|
720
737
|
formatted: string;
|
|
721
|
-
}; /** Every pattern the config defines,
|
|
722
|
-
getPatternReport: () =>
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
* what it could not read, and a project that does not prune tokens never hears it.
|
|
738
|
-
*/
|
|
739
|
-
getUnused(kinds?: ReadonlyArray<keyof UnusedNames>): UnusedNames; /** The names as JSON, of the kinds `getUnused` was asked for. */
|
|
740
|
-
writeUnused(filePath: string, unused: Partial<UnusedNames>): Promise<void>;
|
|
738
|
+
}; /** Every pattern the config defines, how often each is called, and whether anything uses it. */
|
|
739
|
+
getPatternReport: () => {
|
|
740
|
+
unused: boolean;
|
|
741
|
+
patternName: string;
|
|
742
|
+
usedCount: number;
|
|
743
|
+
usedInXFiles: number;
|
|
744
|
+
}[]; /** Every style property written, and how often. */
|
|
745
|
+
getUtilityReport: () => import("@bamboocss/reporter").UtilityReportEntry[]; /** Every keyframe the theme defines, how often an animation names it, and whether the build keeps it. */
|
|
746
|
+
getKeyframeReport: () => {
|
|
747
|
+
unused: boolean;
|
|
748
|
+
keyframe: string;
|
|
749
|
+
usedCount: number;
|
|
750
|
+
usedInXFiles: number;
|
|
751
|
+
}[];
|
|
752
|
+
getUnused: (kinds?: ReadonlyArray<keyof UnusedNames>) => UnusedNames; /** The names as JSON, of the kinds `getUnused` was asked for. */
|
|
753
|
+
writeUnused(filePath: string, unused: Partial<UnusedNames>): Promise<void>; /** The extraction report, with what `getUnused` makes of it, so the file cannot be read as calling a kept name unused. */
|
|
741
754
|
writeReport(filePath: string): Promise<void>;
|
|
742
755
|
}>;
|
|
743
756
|
//#endregion
|
package/dist/index.d.mts
CHANGED
|
@@ -692,7 +692,24 @@ declare class BambooContext extends Generator {
|
|
|
692
692
|
};
|
|
693
693
|
writeCss: (sheet?: Stylesheet) => Promise<PromiseSettledResult<void>[]> | undefined;
|
|
694
694
|
writeSplitCss: (sheet: Stylesheet) => Promise<void>;
|
|
695
|
-
|
|
695
|
+
/**
|
|
696
|
+
* Call `cb` when a file the config is built from changes.
|
|
697
|
+
*
|
|
698
|
+
* `cb` reloads the config, and hands the context it built to `reloaded` as soon as it has one, so
|
|
699
|
+
* the watch can follow what that config is built from. Armed once with this context's files, an
|
|
700
|
+
* edit that swapped in a preset, or imported one more module, left the new file unwatched:
|
|
701
|
+
* editing it did nothing until the process restarted. Handed over before `cb` builds, because a
|
|
702
|
+
* build can fail where the reload did not — a recipe in the new preset naming no token — and the
|
|
703
|
+
* file to fix is that preset.
|
|
704
|
+
*/
|
|
705
|
+
watchConfig: (cb: (file: string, reloaded: (ctx: BambooContext) => void) => BambooContext | void | Promise<BambooContext | void>, opts?: Omit<WatchOptions, "include">) => void;
|
|
706
|
+
/**
|
|
707
|
+
* The files the config is built from: the config, what it imports, the presets it names by path,
|
|
708
|
+
* and its `dependencies` — as patterns too, so a file that starts to match one is seen.
|
|
709
|
+
*/
|
|
710
|
+
private configFiles;
|
|
711
|
+
/** What the config file imports, read off its source without running it, for a config that failed to load. */
|
|
712
|
+
private importedFiles;
|
|
696
713
|
watchFiles: (cb: (event: WatcherEventType, file: string) => void | Promise<void>, opts?: Omit<WatchOptions, "include" | "exclude" | "poll" | "cwd" | "logger">) => void;
|
|
697
714
|
}
|
|
698
715
|
//#endregion
|
|
@@ -714,30 +731,26 @@ declare function analyze(ctx: BambooContext, options?: AnalysisOptions): Promise
|
|
|
714
731
|
getRecipeReport(format?: ReportFormat): {
|
|
715
732
|
report: import("@bamboocss/reporter").RecipeReportEntry[];
|
|
716
733
|
formatted: string;
|
|
717
|
-
};
|
|
734
|
+
}; /** Each category's tokens, counted as used exactly when the build keeps them. */
|
|
718
735
|
getTokenReport(format?: ReportFormat): {
|
|
719
736
|
report: import("@bamboocss/reporter").TokenAnalysisReport;
|
|
720
737
|
formatted: string;
|
|
721
|
-
}; /** Every pattern the config defines,
|
|
722
|
-
getPatternReport: () =>
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
* what it could not read, and a project that does not prune tokens never hears it.
|
|
738
|
-
*/
|
|
739
|
-
getUnused(kinds?: ReadonlyArray<keyof UnusedNames>): UnusedNames; /** The names as JSON, of the kinds `getUnused` was asked for. */
|
|
740
|
-
writeUnused(filePath: string, unused: Partial<UnusedNames>): Promise<void>;
|
|
738
|
+
}; /** Every pattern the config defines, how often each is called, and whether anything uses it. */
|
|
739
|
+
getPatternReport: () => {
|
|
740
|
+
unused: boolean;
|
|
741
|
+
patternName: string;
|
|
742
|
+
usedCount: number;
|
|
743
|
+
usedInXFiles: number;
|
|
744
|
+
}[]; /** Every style property written, and how often. */
|
|
745
|
+
getUtilityReport: () => import("@bamboocss/reporter").UtilityReportEntry[]; /** Every keyframe the theme defines, how often an animation names it, and whether the build keeps it. */
|
|
746
|
+
getKeyframeReport: () => {
|
|
747
|
+
unused: boolean;
|
|
748
|
+
keyframe: string;
|
|
749
|
+
usedCount: number;
|
|
750
|
+
usedInXFiles: number;
|
|
751
|
+
}[];
|
|
752
|
+
getUnused: (kinds?: ReadonlyArray<keyof UnusedNames>) => UnusedNames; /** The names as JSON, of the kinds `getUnused` was asked for. */
|
|
753
|
+
writeUnused(filePath: string, unused: Partial<UnusedNames>): Promise<void>; /** The extraction report, with what `getUnused` makes of it, so the file cannot be read as calling a kept name unused. */
|
|
741
754
|
writeReport(filePath: string): Promise<void>;
|
|
742
755
|
}>;
|
|
743
756
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { checkNamingAgreement, formatNamingDisagreement, messages, prunesPreflig
|
|
|
5
5
|
import { BambooError, cssVarRefs, getOrCreateSet, groupBy, truncateList, uniq } from "@bamboocss/shared";
|
|
6
6
|
import { isMatch } from "matcher";
|
|
7
7
|
import fs, { appendFileSync, existsSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
8
|
-
import { changesEveryArtifact, convertTsPathsToRegexes, diffConfigs, findConfig, loadConfig, mergeHooks } from "@bamboocss/config";
|
|
8
|
+
import { changesEveryArtifact, convertTsPathsToRegexes, diffConfigs, filesReadBy, findConfig, getConfigDependencies, loadConfig, mergeHooks } from "@bamboocss/config";
|
|
9
9
|
import path, { basename, dirname, extname, isAbsolute, join, normalize, parse, posix, relative, resolve, sep } from "node:path";
|
|
10
10
|
import { pluginSvelte } from "@bamboocss/plugin-svelte";
|
|
11
11
|
import { pluginVue } from "@bamboocss/plugin-vue";
|
|
@@ -603,6 +603,112 @@ async function analyze(ctx, options = {}) {
|
|
|
603
603
|
ctx.runtime.fs.ensureDirSync(ctx.runtime.path.dirname(filePath));
|
|
604
604
|
return ctx.runtime.fs.writeFile(filePath, JSON.stringify(value, replacer, 2));
|
|
605
605
|
};
|
|
606
|
+
/**
|
|
607
|
+
* The tokens and keyframes the build's own prune removes, worked out once and shared by every
|
|
608
|
+
* report that speaks of use, so none of them can call a name unused that `getUnused` does not,
|
|
609
|
+
* or the other way round.
|
|
610
|
+
*
|
|
611
|
+
* Run with every prune on, whatever the config says, so a name here is one the stylesheet ships
|
|
612
|
+
* without. Anything the prune keeps for a reader it cannot follow — a `token()` path built at
|
|
613
|
+
* runtime, a theme, a `keepTokens` pattern — is kept here too: being told a token is unused when
|
|
614
|
+
* something still asks for it is worse than not being told at all.
|
|
615
|
+
*
|
|
616
|
+
* Read off a sheet of its own. The prune's settings are laid over the context's while it is
|
|
617
|
+
* built, and `unresolvedPath` is off for it: that one only decides how loudly the prune says what
|
|
618
|
+
* it could not read, and a project that does not prune tokens never hears it.
|
|
619
|
+
*/
|
|
620
|
+
let pruned;
|
|
621
|
+
const prunedNames = () => {
|
|
622
|
+
if (pruned) return pruned;
|
|
623
|
+
const prune = {
|
|
624
|
+
...ctx.config.prune,
|
|
625
|
+
keyframes: true,
|
|
626
|
+
unresolvedPath: "off"
|
|
627
|
+
};
|
|
628
|
+
if (prune.tokens === false) delete prune.tokens;
|
|
629
|
+
const configured = ctx.config.prune;
|
|
630
|
+
ctx.config.prune = prune;
|
|
631
|
+
let sheet;
|
|
632
|
+
try {
|
|
633
|
+
sheet = assembleExtractedSheet(ctx, {
|
|
634
|
+
parserResults,
|
|
635
|
+
prunePreflight: false
|
|
636
|
+
});
|
|
637
|
+
} finally {
|
|
638
|
+
ctx.config.prune = configured;
|
|
639
|
+
}
|
|
640
|
+
const declared = /* @__PURE__ */ new Set();
|
|
641
|
+
const keyframes = /* @__PURE__ */ new Set();
|
|
642
|
+
sheet.layers.tokens.walkDecls((decl) => {
|
|
643
|
+
if (decl.prop.startsWith("--")) declared.add(decl.prop);
|
|
644
|
+
});
|
|
645
|
+
sheet.layers.tokens.walkAtRules(/keyframes$/, (rule) => {
|
|
646
|
+
keyframes.add(rule.params.trim().replace(/^(["'])(.*)\1$/, "$2").replace(/\\(.)/g, "$1"));
|
|
647
|
+
});
|
|
648
|
+
const declarable = /* @__PURE__ */ new Set();
|
|
649
|
+
for (const vars of ctx.tokens.view.vars.values()) for (const name of vars.keys()) declarable.add(name);
|
|
650
|
+
const judged = /* @__PURE__ */ new Map();
|
|
651
|
+
const unused = /* @__PURE__ */ new Map();
|
|
652
|
+
const tokens = [];
|
|
653
|
+
const add = (into, category, name) => {
|
|
654
|
+
const names = into.get(category) ?? /* @__PURE__ */ new Set();
|
|
655
|
+
names.add(name);
|
|
656
|
+
into.set(category, names);
|
|
657
|
+
};
|
|
658
|
+
for (const token of ctx.tokens.allTokens) {
|
|
659
|
+
const { isVirtual, isNegative, category } = token.extensions;
|
|
660
|
+
if (isVirtual || isNegative || category === "breakpoints" || token.name.startsWith("sizes.breakpoint-")) continue;
|
|
661
|
+
const name = token.extensions.var;
|
|
662
|
+
if (!declarable.has(name)) continue;
|
|
663
|
+
if (category) add(judged, category, token.extensions.prop);
|
|
664
|
+
if (declared.has(name)) continue;
|
|
665
|
+
tokens.push(token.name);
|
|
666
|
+
if (category) add(unused, category, token.extensions.prop);
|
|
667
|
+
}
|
|
668
|
+
pruned = {
|
|
669
|
+
tokens: [...new Set(tokens)].sort(),
|
|
670
|
+
keyframes: Object.keys(ctx.config.theme?.keyframes ?? {}).filter((name) => !keyframes.has(name)).sort(),
|
|
671
|
+
judged,
|
|
672
|
+
unused
|
|
673
|
+
};
|
|
674
|
+
return pruned;
|
|
675
|
+
};
|
|
676
|
+
const { staticCss } = ctx.config;
|
|
677
|
+
const emitted = (rules) => (name) => rules === "*" || rules != null && typeof rules === "object" && name in rules;
|
|
678
|
+
const unusedPatterns = () => {
|
|
679
|
+
const kept = emitted(staticCss?.patterns);
|
|
680
|
+
return reporter.getPatternReport().filter((entry) => !entry.usedCount && !kept(entry.patternName)).map((entry) => entry.patternName).sort();
|
|
681
|
+
};
|
|
682
|
+
/**
|
|
683
|
+
* The configured names no source uses, of the kinds asked for.
|
|
684
|
+
*
|
|
685
|
+
* Tokens and keyframes are what the build's own prune removes; see `prunedNames`. A recipe or a
|
|
686
|
+
* pattern is one no source calls and `staticCss` does not emit regardless.
|
|
687
|
+
*/
|
|
688
|
+
const getUnused = (kinds = [
|
|
689
|
+
"tokens",
|
|
690
|
+
"recipes",
|
|
691
|
+
"patterns",
|
|
692
|
+
"keyframes"
|
|
693
|
+
]) => {
|
|
694
|
+
const unused = {
|
|
695
|
+
tokens: [],
|
|
696
|
+
recipes: [],
|
|
697
|
+
patterns: [],
|
|
698
|
+
keyframes: []
|
|
699
|
+
};
|
|
700
|
+
if (kinds.includes("tokens")) unused.tokens = prunedNames().tokens;
|
|
701
|
+
if (kinds.includes("keyframes")) unused.keyframes = prunedNames().keyframes;
|
|
702
|
+
if (kinds.includes("recipes")) {
|
|
703
|
+
const called = new Set(reporter.getRecipeReport().map((entry) => entry.recipeName));
|
|
704
|
+
const inConfig = emitted(staticCss?.recipes);
|
|
705
|
+
const { recipes = {}, slotRecipes = {} } = ctx.config.theme ?? {};
|
|
706
|
+
const ofItself = (name) => Boolean((recipes[name] ?? slotRecipes[name])?.staticCss?.length);
|
|
707
|
+
unused.recipes = [...ctx.recipes.keys].filter((name) => !called.has(name) && !inConfig(name) && !ofItself(name)).sort();
|
|
708
|
+
}
|
|
709
|
+
if (kinds.includes("patterns")) unused.patterns = unusedPatterns();
|
|
710
|
+
return unused;
|
|
711
|
+
};
|
|
606
712
|
return {
|
|
607
713
|
getRecipeReport(format = "table") {
|
|
608
714
|
const report = reporter.getRecipeReport();
|
|
@@ -611,104 +717,47 @@ async function analyze(ctx, options = {}) {
|
|
|
611
717
|
formatted: formatRecipeReport(report, format)
|
|
612
718
|
};
|
|
613
719
|
},
|
|
720
|
+
/** Each category's tokens, counted as used exactly when the build keeps them. */
|
|
614
721
|
getTokenReport(format = "table") {
|
|
615
|
-
const
|
|
722
|
+
const { judged, unused } = prunedNames();
|
|
723
|
+
const report = reporter.getTokenReport({
|
|
724
|
+
judged,
|
|
725
|
+
unused
|
|
726
|
+
});
|
|
616
727
|
return {
|
|
617
728
|
report,
|
|
618
729
|
formatted: formatTokenReport(report.getSummary(), format)
|
|
619
730
|
};
|
|
620
731
|
},
|
|
621
|
-
/** Every pattern the config defines,
|
|
622
|
-
getPatternReport: () =>
|
|
732
|
+
/** Every pattern the config defines, how often each is called, and whether anything uses it. */
|
|
733
|
+
getPatternReport: () => {
|
|
734
|
+
const unused = new Set(unusedPatterns());
|
|
735
|
+
return reporter.getPatternReport().map((entry) => ({
|
|
736
|
+
...entry,
|
|
737
|
+
unused: unused.has(entry.patternName)
|
|
738
|
+
}));
|
|
739
|
+
},
|
|
623
740
|
/** Every style property written, and how often. */
|
|
624
741
|
getUtilityReport: () => reporter.getUtilityReport(),
|
|
625
|
-
/** Every keyframe the theme defines,
|
|
626
|
-
getKeyframeReport: () =>
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
* Anything the prune keeps for a reader it cannot follow — a `token()` path built at runtime,
|
|
633
|
-
* a theme, a `keepTokens` pattern — is kept here too, and not listed: being told a token is
|
|
634
|
-
* unused when something still asks for it is worse than not being told at all. A recipe or a
|
|
635
|
-
* pattern is one no source calls and `staticCss` does not emit regardless.
|
|
636
|
-
*
|
|
637
|
-
* Read off a sheet of its own. The prune's settings are laid over the context's while it is
|
|
638
|
-
* built, and `unresolvedPath` is off for it: that one only decides how loudly the prune says
|
|
639
|
-
* what it could not read, and a project that does not prune tokens never hears it.
|
|
640
|
-
*/
|
|
641
|
-
getUnused(kinds = [
|
|
642
|
-
"tokens",
|
|
643
|
-
"recipes",
|
|
644
|
-
"patterns",
|
|
645
|
-
"keyframes"
|
|
646
|
-
]) {
|
|
647
|
-
const unused = {
|
|
648
|
-
tokens: [],
|
|
649
|
-
recipes: [],
|
|
650
|
-
patterns: [],
|
|
651
|
-
keyframes: []
|
|
652
|
-
};
|
|
653
|
-
if (kinds.includes("tokens") || kinds.includes("keyframes")) {
|
|
654
|
-
const prune = {
|
|
655
|
-
...ctx.config.prune,
|
|
656
|
-
keyframes: true,
|
|
657
|
-
unresolvedPath: "off"
|
|
658
|
-
};
|
|
659
|
-
if (prune.tokens === false) delete prune.tokens;
|
|
660
|
-
const configured = ctx.config.prune;
|
|
661
|
-
ctx.config.prune = prune;
|
|
662
|
-
let sheet;
|
|
663
|
-
try {
|
|
664
|
-
sheet = assembleExtractedSheet(ctx, {
|
|
665
|
-
parserResults,
|
|
666
|
-
prunePreflight: false
|
|
667
|
-
});
|
|
668
|
-
} finally {
|
|
669
|
-
ctx.config.prune = configured;
|
|
670
|
-
}
|
|
671
|
-
const declared = /* @__PURE__ */ new Set();
|
|
672
|
-
const keyframes = /* @__PURE__ */ new Set();
|
|
673
|
-
sheet.layers.tokens.walkDecls((decl) => {
|
|
674
|
-
if (decl.prop.startsWith("--")) declared.add(decl.prop);
|
|
675
|
-
});
|
|
676
|
-
sheet.layers.tokens.walkAtRules(/keyframes$/, (rule) => {
|
|
677
|
-
keyframes.add(rule.params.trim().replace(/^(["'])(.*)\1$/, "$2").replace(/\\(.)/g, "$1"));
|
|
678
|
-
});
|
|
679
|
-
const declarable = /* @__PURE__ */ new Set();
|
|
680
|
-
for (const vars of ctx.tokens.view.vars.values()) for (const name of vars.keys()) declarable.add(name);
|
|
681
|
-
const tokens = /* @__PURE__ */ new Set();
|
|
682
|
-
for (const token of ctx.tokens.allTokens) {
|
|
683
|
-
const { isVirtual, isNegative, category } = token.extensions;
|
|
684
|
-
if (isVirtual || isNegative || category === "breakpoints" || token.name.startsWith("sizes.breakpoint-")) continue;
|
|
685
|
-
const name = token.extensions.var;
|
|
686
|
-
if (declarable.has(name) && !declared.has(name)) tokens.add(token.name);
|
|
687
|
-
}
|
|
688
|
-
if (kinds.includes("tokens")) unused.tokens = [...tokens].sort();
|
|
689
|
-
if (kinds.includes("keyframes")) unused.keyframes = Object.keys(ctx.config.theme?.keyframes ?? {}).filter((name) => !keyframes.has(name)).sort();
|
|
690
|
-
}
|
|
691
|
-
const { staticCss } = ctx.config;
|
|
692
|
-
const emitted = (rules) => (name) => rules === "*" || rules != null && typeof rules === "object" && name in rules;
|
|
693
|
-
if (kinds.includes("recipes")) {
|
|
694
|
-
const called = new Set(reporter.getRecipeReport().map((entry) => entry.recipeName));
|
|
695
|
-
const inConfig = emitted(staticCss?.recipes);
|
|
696
|
-
const { recipes = {}, slotRecipes = {} } = ctx.config.theme ?? {};
|
|
697
|
-
const ofItself = (name) => Boolean((recipes[name] ?? slotRecipes[name])?.staticCss?.length);
|
|
698
|
-
unused.recipes = [...ctx.recipes.keys].filter((name) => !called.has(name) && !inConfig(name) && !ofItself(name)).sort();
|
|
699
|
-
}
|
|
700
|
-
if (kinds.includes("patterns")) {
|
|
701
|
-
const kept = emitted(staticCss?.patterns);
|
|
702
|
-
unused.patterns = reporter.getPatternReport().filter((entry) => !entry.usedCount && !kept(entry.patternName)).map((entry) => entry.patternName).sort();
|
|
703
|
-
}
|
|
704
|
-
return unused;
|
|
742
|
+
/** Every keyframe the theme defines, how often an animation names it, and whether the build keeps it. */
|
|
743
|
+
getKeyframeReport: () => {
|
|
744
|
+
const unused = new Set(prunedNames().keyframes);
|
|
745
|
+
return reporter.getKeyframeReport().map((entry) => ({
|
|
746
|
+
...entry,
|
|
747
|
+
unused: unused.has(entry.keyframe)
|
|
748
|
+
}));
|
|
705
749
|
},
|
|
750
|
+
getUnused,
|
|
706
751
|
/** The names as JSON, of the kinds `getUnused` was asked for. */
|
|
707
752
|
writeUnused(filePath, unused) {
|
|
708
753
|
return writeJson(filePath, unused);
|
|
709
754
|
},
|
|
755
|
+
/** The extraction report, with what `getUnused` makes of it, so the file cannot be read as calling a kept name unused. */
|
|
710
756
|
writeReport(filePath) {
|
|
711
|
-
return writeJson(filePath,
|
|
757
|
+
return writeJson(filePath, {
|
|
758
|
+
...reporter.report,
|
|
759
|
+
unused: getUnused()
|
|
760
|
+
});
|
|
712
761
|
}
|
|
713
762
|
};
|
|
714
763
|
}
|
|
@@ -2895,6 +2944,7 @@ var DiffEngine = class {
|
|
|
2895
2944
|
if (!affected.hasConfigChanged) {
|
|
2896
2945
|
applyTsConfig(this.ctx.conf, conf);
|
|
2897
2946
|
rememberTsConfigResolutionFiles(this.ctx.conf, getTsConfigResolutionFiles(conf));
|
|
2947
|
+
this.ctx.conf.dependencies = conf.dependencies;
|
|
2898
2948
|
}
|
|
2899
2949
|
return affected;
|
|
2900
2950
|
}
|
|
@@ -3506,9 +3556,15 @@ const nodeRuntime = {
|
|
|
3506
3556
|
} : false
|
|
3507
3557
|
});
|
|
3508
3558
|
logger.debug("watch:file", `Watching [ ${dirnames.join(", ")} ]`);
|
|
3509
|
-
|
|
3559
|
+
const onInterrupt = async () => {
|
|
3510
3560
|
await watcher.close();
|
|
3511
|
-
}
|
|
3561
|
+
};
|
|
3562
|
+
process.once("SIGINT", onInterrupt);
|
|
3563
|
+
const close = watcher.close.bind(watcher);
|
|
3564
|
+
watcher.close = () => {
|
|
3565
|
+
process.off("SIGINT", onInterrupt);
|
|
3566
|
+
return close();
|
|
3567
|
+
};
|
|
3512
3568
|
return watcher;
|
|
3513
3569
|
}
|
|
3514
3570
|
}
|
|
@@ -4524,23 +4580,80 @@ var BambooContext = class extends Generator {
|
|
|
4524
4580
|
if (fs.existsSync(recipesIndex)) fs.rmFileSync(recipesIndex);
|
|
4525
4581
|
if (fs.existsSync(recipesDir)) fs.rmFileSync(recipesDir);
|
|
4526
4582
|
};
|
|
4583
|
+
/**
|
|
4584
|
+
* Call `cb` when a file the config is built from changes.
|
|
4585
|
+
*
|
|
4586
|
+
* `cb` reloads the config, and hands the context it built to `reloaded` as soon as it has one, so
|
|
4587
|
+
* the watch can follow what that config is built from. Armed once with this context's files, an
|
|
4588
|
+
* edit that swapped in a preset, or imported one more module, left the new file unwatched:
|
|
4589
|
+
* editing it did nothing until the process restarted. Handed over before `cb` builds, because a
|
|
4590
|
+
* build can fail where the reload did not — a recipe in the new preset naming no token — and the
|
|
4591
|
+
* file to fix is that preset.
|
|
4592
|
+
*/
|
|
4527
4593
|
watchConfig = (cb, opts) => {
|
|
4528
4594
|
const { cwd, poll, exclude } = opts ?? {};
|
|
4529
4595
|
logger.info("ctx:watch", this.messages.configWatch());
|
|
4530
|
-
const
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4596
|
+
const arm = (include) => {
|
|
4597
|
+
const watcher = this.runtime.fs.watch({
|
|
4598
|
+
include,
|
|
4599
|
+
exclude,
|
|
4600
|
+
cwd,
|
|
4601
|
+
poll
|
|
4602
|
+
});
|
|
4603
|
+
watcher.on("all", (event, file) => {
|
|
4604
|
+
if (event === "add" || event === "change") rebuild(file);
|
|
4605
|
+
});
|
|
4606
|
+
return watcher;
|
|
4607
|
+
};
|
|
4608
|
+
let files = this.configFiles();
|
|
4609
|
+
let watcher = arm(files);
|
|
4610
|
+
const rearm = async (nextFiles) => {
|
|
4611
|
+
if (nextFiles.join("\n") === files.join("\n")) return;
|
|
4612
|
+
const previous = watcher;
|
|
4613
|
+
files = nextFiles;
|
|
4614
|
+
watcher = arm(files);
|
|
4615
|
+
await previous.close();
|
|
4616
|
+
};
|
|
4536
4617
|
const rebuild = debounce(async (file) => {
|
|
4537
4618
|
logger.info("ctx:change", "config changed, rebuilding...");
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4619
|
+
const reload = {};
|
|
4620
|
+
try {
|
|
4621
|
+
const next = await cb(file, (ctx) => {
|
|
4622
|
+
reload.ctx = ctx;
|
|
4623
|
+
});
|
|
4624
|
+
if (next) reload.ctx = next;
|
|
4625
|
+
} catch (error) {
|
|
4626
|
+
logger.error("ctx:rebuild", error instanceof Error ? error.message : String(error));
|
|
4627
|
+
const reloaded = reload.ctx;
|
|
4628
|
+
const nextFiles = reloaded ? reloaded.configFiles() : uniq([
|
|
4629
|
+
...files,
|
|
4630
|
+
...this.importedFiles(),
|
|
4631
|
+
...filesReadBy(error)
|
|
4632
|
+
]).sort();
|
|
4633
|
+
await reportRebuildFailure(() => rearm(nextFiles));
|
|
4634
|
+
return;
|
|
4635
|
+
}
|
|
4636
|
+
const reloaded = reload.ctx;
|
|
4637
|
+
if (reloaded) await reportRebuildFailure(() => rearm(reloaded.configFiles()));
|
|
4542
4638
|
});
|
|
4543
4639
|
};
|
|
4640
|
+
/**
|
|
4641
|
+
* The files the config is built from: the config, what it imports, the presets it names by path,
|
|
4642
|
+
* and its `dependencies` — as patterns too, so a file that starts to match one is seen.
|
|
4643
|
+
*/
|
|
4644
|
+
configFiles = () => uniq([
|
|
4645
|
+
...this.explicitDeps,
|
|
4646
|
+
...this.conf.dependencies,
|
|
4647
|
+
...this.config.dependencies ?? []
|
|
4648
|
+
]).sort();
|
|
4649
|
+
/** What the config file imports, read off its source without running it, for a config that failed to load. */
|
|
4650
|
+
importedFiles = () => {
|
|
4651
|
+
try {
|
|
4652
|
+
return [...getConfigDependencies(this.conf.path, this.conf.tsOptions, this.conf.tsconfig?.compilerOptions).deps];
|
|
4653
|
+
} catch {
|
|
4654
|
+
return [];
|
|
4655
|
+
}
|
|
4656
|
+
};
|
|
4544
4657
|
watchFiles = (cb, opts) => {
|
|
4545
4658
|
const { include, exclude, poll, cwd } = this.config;
|
|
4546
4659
|
logger.info("ctx:watch", this.messages.watch());
|
|
@@ -6359,10 +6472,11 @@ async function generate(config, configPath, options = {}) {
|
|
|
6359
6472
|
if (options.requireFiles && !ctx.config.emitTokensOnly) assertFilesMatched(ctx);
|
|
6360
6473
|
await build(ctx, watch ? sourceScanCache : void 0);
|
|
6361
6474
|
if (watch) {
|
|
6362
|
-
ctx.watchConfig(async () => {
|
|
6475
|
+
ctx.watchConfig(async (_file, reloaded) => {
|
|
6363
6476
|
const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
|
|
6364
6477
|
ctx = new BambooContext(conf);
|
|
6365
6478
|
});
|
|
6479
|
+
reloaded(ctx);
|
|
6366
6480
|
sourceScanCache.entries.clear();
|
|
6367
6481
|
sourceScanCache.resolvedTokenReferences.clear();
|
|
6368
6482
|
logger.info("ctx:updated", "config rebuilt ✅");
|
|
@@ -6370,7 +6484,8 @@ async function generate(config, configPath, options = {}) {
|
|
|
6370
6484
|
config: ctx.config,
|
|
6371
6485
|
changes: affecteds
|
|
6372
6486
|
});
|
|
6373
|
-
|
|
6487
|
+
await build(ctx, sourceScanCache, artifactsToRebuild(affecteds));
|
|
6488
|
+
return ctx;
|
|
6374
6489
|
}, {
|
|
6375
6490
|
cwd,
|
|
6376
6491
|
poll
|
|
@@ -6480,11 +6595,11 @@ async function setupConfig(cwd, opts = {}) {
|
|
|
6480
6595
|
}
|
|
6481
6596
|
const { detect } = await import("package-manager-detector");
|
|
6482
6597
|
const pm = ((await detect({ cwd }))?.agent ?? "npm").split("@")[0];
|
|
6483
|
-
const cmd = pm === "npm" ? "
|
|
6598
|
+
const cmd = pm === "npm" ? "npx" : pm;
|
|
6484
6599
|
const file = lookItUpSync("tsconfig.json", cwd) ? "bamboo.config.ts" : "bamboo.config.mjs";
|
|
6485
|
-
logger.info("init:config", `creating bamboo config file: ${quote(file)}`);
|
|
6486
6600
|
if (!force && configFile) logger.warn("init:config", messages.configExists(cmd));
|
|
6487
6601
|
else {
|
|
6602
|
+
logger.info("init:config", `creating bamboo config file: ${quote(file)}`);
|
|
6488
6603
|
const content = outdent`
|
|
6489
6604
|
import { defineConfig } from "@bamboocss/dev"
|
|
6490
6605
|
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/node",
|
|
3
|
-
"version": "1.58.
|
|
3
|
+
"version": "1.58.2",
|
|
4
4
|
"description": "The core css bamboo library",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,16 +60,16 @@
|
|
|
60
60
|
"pkg-types": "2.3.0",
|
|
61
61
|
"pluralize": "8.0.0",
|
|
62
62
|
"ts-pattern": "5.9.0",
|
|
63
|
-
"@bamboocss/config": "1.58.
|
|
64
|
-
"@bamboocss/core": "1.58.
|
|
65
|
-
"@bamboocss/generator": "1.58.
|
|
66
|
-
"@bamboocss/logger": "1.58.
|
|
67
|
-
"@bamboocss/plugin-svelte": "1.58.
|
|
68
|
-
"@bamboocss/plugin-vue": "1.58.
|
|
69
|
-
"@bamboocss/reporter": "1.58.
|
|
70
|
-
"@bamboocss/shared": "1.58.
|
|
71
|
-
"@bamboocss/token-dictionary": "1.58.
|
|
72
|
-
"@bamboocss/types": "1.58.
|
|
63
|
+
"@bamboocss/config": "1.58.2",
|
|
64
|
+
"@bamboocss/core": "1.58.2",
|
|
65
|
+
"@bamboocss/generator": "1.58.2",
|
|
66
|
+
"@bamboocss/logger": "1.58.2",
|
|
67
|
+
"@bamboocss/plugin-svelte": "1.58.2",
|
|
68
|
+
"@bamboocss/plugin-vue": "1.58.2",
|
|
69
|
+
"@bamboocss/reporter": "1.58.2",
|
|
70
|
+
"@bamboocss/shared": "1.58.2",
|
|
71
|
+
"@bamboocss/token-dictionary": "1.58.2",
|
|
72
|
+
"@bamboocss/types": "1.58.2"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@astrojs/compiler": "3.0.1",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"@types/fs-extra": "11.0.4",
|
|
78
78
|
"@types/picomatch": "4.0.2",
|
|
79
79
|
"boxen": "8.0.1",
|
|
80
|
-
"@bamboocss/native-extractor": "1.58.
|
|
80
|
+
"@bamboocss/native-extractor": "1.58.2"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"@astrojs/compiler": ">=2",
|