@bamboocss/node 1.48.4 → 1.49.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/dist/index.cjs +105 -25
- package/dist/index.d.cts +8 -2
- package/dist/index.d.mts +9 -3
- package/dist/index.mjs +102 -22
- package/package.json +12 -12
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
}) : target, mod));
|
|
24
24
|
//#endregion
|
|
25
25
|
const require_static_compiler = require("./static-compiler.cjs");
|
|
26
|
-
let _bamboocss_reporter = require("@bamboocss/reporter");
|
|
27
26
|
let _bamboocss_logger = require("@bamboocss/logger");
|
|
28
27
|
let _bamboocss_config = require("@bamboocss/config");
|
|
29
28
|
let _bamboocss_shared = require("@bamboocss/shared");
|
|
@@ -64,8 +63,15 @@ let outdent = require("outdent");
|
|
|
64
63
|
outdent = __toESM(outdent);
|
|
65
64
|
let child_process = require("child_process");
|
|
66
65
|
//#region src/analyze.ts
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
/**
|
|
67
|
+
* `analyze` is one CLI command, but this module is reachable from `@bamboocss/node`'s index,
|
|
68
|
+
* so a static import made every consumer of that index — the CLI on any command, and the Vite
|
|
69
|
+
* plugin on every build — load the reporter and its table formatters to run neither. Loading
|
|
70
|
+
* it here keeps that off the path of everything that is not the `analyze` command.
|
|
71
|
+
*/
|
|
72
|
+
async function analyze(ctx, options = {}) {
|
|
73
|
+
const { Reporter, formatRecipeReport, formatTokenReport } = await import("@bamboocss/reporter");
|
|
74
|
+
const reporter = new Reporter(ctx, {
|
|
69
75
|
project: ctx.project,
|
|
70
76
|
getRelativePath: ctx.runtime.path.relative,
|
|
71
77
|
getFiles: ctx.getFiles,
|
|
@@ -77,14 +83,14 @@ function analyze(ctx, options = {}) {
|
|
|
77
83
|
const report = reporter.getRecipeReport();
|
|
78
84
|
return {
|
|
79
85
|
report,
|
|
80
|
-
formatted:
|
|
86
|
+
formatted: formatRecipeReport(report, format)
|
|
81
87
|
};
|
|
82
88
|
},
|
|
83
89
|
getTokenReport(format = "table") {
|
|
84
90
|
const report = reporter.getTokenReport();
|
|
85
91
|
return {
|
|
86
92
|
report,
|
|
87
|
-
formatted:
|
|
93
|
+
formatted: formatTokenReport(report.getSummary(), format)
|
|
88
94
|
};
|
|
89
95
|
},
|
|
90
96
|
writeReport(filePath) {
|
|
@@ -2266,9 +2272,10 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2266
2272
|
const results = [];
|
|
2267
2273
|
files.forEach((file) => {
|
|
2268
2274
|
const result = this.parseFile(file, encoder);
|
|
2269
|
-
if (!result || result.isEmpty()
|
|
2270
|
-
filesWithCss.push(file);
|
|
2275
|
+
if (!result || result.isEmpty()) return;
|
|
2271
2276
|
results.push(result);
|
|
2277
|
+
if (encoder.isEmpty()) return;
|
|
2278
|
+
filesWithCss.push(file);
|
|
2272
2279
|
});
|
|
2273
2280
|
this.assertExtracted(files);
|
|
2274
2281
|
this.assertNoDeadCalls(files);
|
|
@@ -2588,7 +2595,9 @@ function accountFile(ctx, sourceFile, filePath, paths, prefixes, declined) {
|
|
|
2588
2595
|
const decline = (node, reason) => declined.push({
|
|
2589
2596
|
filePath,
|
|
2590
2597
|
line: lineOf(node),
|
|
2591
|
-
reason
|
|
2598
|
+
reason,
|
|
2599
|
+
start: node.getStart(),
|
|
2600
|
+
end: node.getEnd()
|
|
2592
2601
|
});
|
|
2593
2602
|
/** Local names bound to the artifact: the `token` export, and any namespace of it. */
|
|
2594
2603
|
const bindings = /* @__PURE__ */ new Set();
|
|
@@ -2989,10 +2998,49 @@ function* sourceTexts(ctx) {
|
|
|
2989
2998
|
}
|
|
2990
2999
|
const createSourceScanCache = () => ({
|
|
2991
3000
|
signature: "",
|
|
2992
|
-
entries: /* @__PURE__ */ new Map()
|
|
3001
|
+
entries: /* @__PURE__ */ new Map(),
|
|
3002
|
+
resolvedTokenReferences: /* @__PURE__ */ new Map()
|
|
2993
3003
|
});
|
|
3004
|
+
const resolvedTokenReferences = (result) => {
|
|
3005
|
+
if (!result) return [];
|
|
3006
|
+
const facts = [];
|
|
3007
|
+
for (const item of result.token) {
|
|
3008
|
+
if (!item.tokenCalleeRange || !item.data?.length) continue;
|
|
3009
|
+
const paths = [];
|
|
3010
|
+
for (const value of item.data) {
|
|
3011
|
+
if (typeof value !== "string") break;
|
|
3012
|
+
paths.push(value);
|
|
3013
|
+
}
|
|
3014
|
+
if (paths.length !== item.data.length) continue;
|
|
3015
|
+
facts.push({
|
|
3016
|
+
...item.tokenCalleeRange,
|
|
3017
|
+
paths: [...new Set(paths)].sort()
|
|
3018
|
+
});
|
|
3019
|
+
}
|
|
3020
|
+
return facts.sort((left, right) => left.start - right.start || left.end - right.end);
|
|
3021
|
+
};
|
|
3022
|
+
const sameResolvedTokenReferences = (left, right) => (left?.length ?? 0) === right.length && right.every((fact, index) => fact.start === left[index].start && fact.end === left[index].end && fact.paths.length === left[index].paths.length && fact.paths.every((path, pathIndex) => path === left[index].paths[pathIndex]));
|
|
3023
|
+
/**
|
|
3024
|
+
* Reconcile one file's lightweight token facts after extraction.
|
|
3025
|
+
*
|
|
3026
|
+
* Deleting the source scan only when the semantic facts moved is important for dependents:
|
|
3027
|
+
* changing an imported constant can change `token(KEY)` without changing the consumer's mtime.
|
|
3028
|
+
*/
|
|
3029
|
+
const recordResolvedTokenReferences = (cache, filePath, result) => {
|
|
3030
|
+
const next = resolvedTokenReferences(result);
|
|
3031
|
+
if (sameResolvedTokenReferences(cache.resolvedTokenReferences.get(filePath), next)) return;
|
|
3032
|
+
if (next.length) cache.resolvedTokenReferences.set(filePath, next);
|
|
3033
|
+
else cache.resolvedTokenReferences.delete(filePath);
|
|
3034
|
+
cache.entries.delete(filePath);
|
|
3035
|
+
};
|
|
3036
|
+
const reconcileAccounting = (accounting, references, filePath) => {
|
|
3037
|
+
if (!references?.length) return;
|
|
3038
|
+
const ranges = new Set(references.map(({ start, end }) => `${start}:${end}`));
|
|
3039
|
+
for (const reference of references) for (const path of reference.paths) accounting.paths.add(path);
|
|
3040
|
+
accounting.declined = accounting.declined.filter((entry) => entry.reason !== "unresolved-reference" || filePath !== void 0 && entry.filePath !== filePath || entry.start == null || entry.end == null || !ranges.has(`${entry.start}:${entry.end}`));
|
|
3041
|
+
};
|
|
2994
3042
|
const OPEN_TAG = /<\s*([a-z][\w-]*)(?=[\s/>]|$)/g;
|
|
2995
|
-
const scanSnapshot = (ctx, snapshot, options, patterns) => {
|
|
3043
|
+
const scanSnapshot = (ctx, snapshot, options, patterns, resolvedReferences) => {
|
|
2996
3044
|
const tokenPaths = /* @__PURE__ */ new Set();
|
|
2997
3045
|
const cssVars = /* @__PURE__ */ new Set();
|
|
2998
3046
|
const elements = /* @__PURE__ */ new Set();
|
|
@@ -3011,6 +3059,7 @@ const scanSnapshot = (ctx, snapshot, options, patterns) => {
|
|
|
3011
3059
|
declined: []
|
|
3012
3060
|
};
|
|
3013
3061
|
accountSnapshot(ctx, snapshot, accounting);
|
|
3062
|
+
reconcileAccounting(accounting, resolvedReferences);
|
|
3014
3063
|
return {
|
|
3015
3064
|
tokenPaths: [...tokenPaths],
|
|
3016
3065
|
cssVars: [...cssVars],
|
|
@@ -3080,7 +3129,7 @@ function collectSourceScans(ctx, options, cache, mtimeOf, files) {
|
|
|
3080
3129
|
merge(entry.scan);
|
|
3081
3130
|
continue;
|
|
3082
3131
|
}
|
|
3083
|
-
const scan = scanSnapshot(ctx, readSnapshot(ctx, filePath), options, allPatterns);
|
|
3132
|
+
const scan = scanSnapshot(ctx, readSnapshot(ctx, filePath), options, allPatterns, cache.resolvedTokenReferences.get(filePath));
|
|
3084
3133
|
cache.entries.set(filePath, {
|
|
3085
3134
|
mtime,
|
|
3086
3135
|
scan
|
|
@@ -3093,6 +3142,7 @@ function collectSourceScans(ctx, options, cache, mtimeOf, files) {
|
|
|
3093
3142
|
}
|
|
3094
3143
|
if (cache && seen) {
|
|
3095
3144
|
for (const filePath of cache.entries.keys()) if (!seen.has(filePath)) cache.entries.delete(filePath);
|
|
3145
|
+
for (const filePath of cache.resolvedTokenReferences.keys()) if (!seen.has(filePath)) cache.resolvedTokenReferences.delete(filePath);
|
|
3096
3146
|
}
|
|
3097
3147
|
return result;
|
|
3098
3148
|
}
|
|
@@ -3113,7 +3163,10 @@ function pruneTokensForBuild(ctx, sheet, results, sourceScans) {
|
|
|
3113
3163
|
const vars = new Set(scans.cssVars);
|
|
3114
3164
|
const accounting = scans.accounting;
|
|
3115
3165
|
const reachable = scans.reachableFromJs;
|
|
3116
|
-
for (const result of results)
|
|
3166
|
+
for (const result of results) {
|
|
3167
|
+
if (result.filePath) reconcileAccounting(accounting, resolvedTokenReferences(result), ctx.runtime.path.abs(ctx.config.cwd, result.filePath));
|
|
3168
|
+
for (const item of result.token) for (const value of item.data ?? []) if (typeof value === "string") paths.add(value);
|
|
3169
|
+
}
|
|
3117
3170
|
for (const name of tokenVarsFor(ctx, paths)) vars.add(name);
|
|
3118
3171
|
const declared = declaredKeeps(ctx);
|
|
3119
3172
|
for (const name of tokenVarsFor(ctx, declared)) vars.add(name);
|
|
@@ -3245,7 +3298,7 @@ function collectRenderedElements(ctx) {
|
|
|
3245
3298
|
* Vite, `bamboo cssgen`, and the CLI `bamboo` command all finish here so a recipe lowered to
|
|
3246
3299
|
* atoms cannot have a different sheet depending on which integration asked for it.
|
|
3247
3300
|
*/
|
|
3248
|
-
const assembleExtractedSheet = (ctx, { layerParams = false, sourceScanCache, mtimeOf, sourceInventory } = {}) => {
|
|
3301
|
+
const assembleExtractedSheet = (ctx, { layerParams = false, sourceScanCache, mtimeOf, sourceInventory, parserResults = [] } = {}) => {
|
|
3249
3302
|
ctx.encoder.atomizeObservedRecipes();
|
|
3250
3303
|
const sheet = ctx.createSheet();
|
|
3251
3304
|
if (layerParams) {
|
|
@@ -3260,7 +3313,7 @@ const assembleExtractedSheet = (ctx, { layerParams = false, sourceScanCache, mti
|
|
|
3260
3313
|
keyframeNames: declaredKeyframes,
|
|
3261
3314
|
elements: collectElements
|
|
3262
3315
|
}, sourceScanCache, mtimeOf, sourceInventory) : void 0;
|
|
3263
|
-
const reachableVars = pruneTokensForBuild(ctx, sheet,
|
|
3316
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, parserResults, scans);
|
|
3264
3317
|
if (collectElements && scans) ctx.prunePreflight(sheet, scans.elements);
|
|
3265
3318
|
if (pruneKeyframes && scans) ctx.pruneKeyframes(sheet, scans.keyframeHits, reachableVars);
|
|
3266
3319
|
return sheet;
|
|
@@ -3511,6 +3564,7 @@ var Builder = class {
|
|
|
3511
3564
|
this.resolutionConfigurationSets.clear();
|
|
3512
3565
|
this.resolutionConfigurationBytes.clear();
|
|
3513
3566
|
this.sourceScanCache.entries.clear();
|
|
3567
|
+
this.sourceScanCache.resolvedTokenReferences.clear();
|
|
3514
3568
|
this.extractionReadsByOwner.clear();
|
|
3515
3569
|
this.recipeSurfaceByOwner.clear();
|
|
3516
3570
|
this.capturedLedger = void 0;
|
|
@@ -3791,6 +3845,7 @@ var Builder = class {
|
|
|
3791
3845
|
const previousCandidates = this.resolutionCandidateSets.get(owner) ?? [];
|
|
3792
3846
|
const previousConfigurations = this.resolutionConfigurationSets.get(owner) ?? [];
|
|
3793
3847
|
const parserResult = ctx.parseFile(file);
|
|
3848
|
+
recordResolvedTokenReferences(this.sourceScanCache, this.absOwner(ctx, file), parserResult);
|
|
3794
3849
|
fileModifiedMap.set(file, meta.mtime);
|
|
3795
3850
|
{
|
|
3796
3851
|
const owner = this.absOwner(ctx, file);
|
|
@@ -3963,9 +4018,12 @@ const cssgen = async (ctx, options) => {
|
|
|
3963
4018
|
} else await ctx.writeCss(sheet);
|
|
3964
4019
|
done();
|
|
3965
4020
|
} else {
|
|
3966
|
-
const { files } = ctx.parseFiles();
|
|
4021
|
+
const { files, results } = ctx.parseFiles();
|
|
3967
4022
|
const done = _bamboocss_logger.logger.time.info(ctx.messages.buildComplete(files.length));
|
|
3968
|
-
const sheet = assembleExtractedSheet(ctx, {
|
|
4023
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
4024
|
+
layerParams: true,
|
|
4025
|
+
parserResults: results
|
|
4026
|
+
});
|
|
3969
4027
|
if (splitting) await ctx.writeSplitCss(sheet);
|
|
3970
4028
|
else if (outfile) {
|
|
3971
4029
|
const css = ctx.getCss(sheet);
|
|
@@ -4026,12 +4084,22 @@ async function debug(ctx, options) {
|
|
|
4026
4084
|
}
|
|
4027
4085
|
//#endregion
|
|
4028
4086
|
//#region src/generate.ts
|
|
4029
|
-
async function build(ctx, artifactIds) {
|
|
4087
|
+
async function build(ctx, sourceScanCache, artifactIds) {
|
|
4030
4088
|
await codegen(ctx, artifactIds);
|
|
4031
4089
|
if (ctx.config.emitTokensOnly) return _bamboocss_logger.logger.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens ✨");
|
|
4032
4090
|
const done = _bamboocss_logger.logger.time.info("");
|
|
4033
4091
|
const parsed = ctx.parseFiles();
|
|
4034
|
-
|
|
4092
|
+
if (sourceScanCache) {
|
|
4093
|
+
for (const result of parsed.results) if (result.filePath) recordResolvedTokenReferences(sourceScanCache, ctx.runtime.path.abs(ctx.config.cwd, result.filePath), result);
|
|
4094
|
+
}
|
|
4095
|
+
const sheet = assembleExtractedSheet(ctx, sourceScanCache ? {
|
|
4096
|
+
layerParams: true,
|
|
4097
|
+
sourceScanCache,
|
|
4098
|
+
sourceInventory: parsed.files
|
|
4099
|
+
} : {
|
|
4100
|
+
layerParams: true,
|
|
4101
|
+
parserResults: parsed.results
|
|
4102
|
+
});
|
|
4035
4103
|
await ctx.writeCss(sheet);
|
|
4036
4104
|
done(ctx.messages.buildComplete(parsed.files.length));
|
|
4037
4105
|
}
|
|
@@ -4040,19 +4108,22 @@ async function generate(config, configPath) {
|
|
|
4040
4108
|
config,
|
|
4041
4109
|
configPath
|
|
4042
4110
|
});
|
|
4043
|
-
|
|
4111
|
+
const sourceScanCache = createSourceScanCache();
|
|
4044
4112
|
const { cwd, watch, poll } = ctx.config;
|
|
4113
|
+
await build(ctx, watch ? sourceScanCache : void 0);
|
|
4045
4114
|
if (watch) {
|
|
4046
4115
|
ctx.watchConfig(async () => {
|
|
4047
4116
|
const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
|
|
4048
4117
|
ctx = new BambooContext(conf);
|
|
4049
4118
|
});
|
|
4119
|
+
sourceScanCache.entries.clear();
|
|
4120
|
+
sourceScanCache.resolvedTokenReferences.clear();
|
|
4050
4121
|
_bamboocss_logger.logger.info("ctx:updated", "config rebuilt ✅");
|
|
4051
4122
|
await ctx.hooks["config:change"]?.({
|
|
4052
4123
|
config: ctx.config,
|
|
4053
4124
|
changes: affecteds
|
|
4054
4125
|
});
|
|
4055
|
-
return build(ctx, Array.from(affecteds.artifacts));
|
|
4126
|
+
return build(ctx, sourceScanCache, Array.from(affecteds.artifacts));
|
|
4056
4127
|
}, {
|
|
4057
4128
|
cwd,
|
|
4058
4129
|
poll
|
|
@@ -4065,14 +4136,21 @@ async function generate(config, configPath) {
|
|
|
4065
4136
|
* per file. Writing per file would run the optimize pipeline and hit the disk
|
|
4066
4137
|
* once per importer for a single keystroke.
|
|
4067
4138
|
*/
|
|
4068
|
-
const bundleStyles = async (ctx, changedFilePaths) => {
|
|
4139
|
+
const bundleStyles = async (ctx, changedFilePaths, inventoryChanged = false) => {
|
|
4069
4140
|
let parsed = 0;
|
|
4070
4141
|
const encoder = ctx.parserOptions.encoder;
|
|
4071
|
-
for (const filePath of changedFilePaths)
|
|
4072
|
-
|
|
4142
|
+
for (const filePath of changedFilePaths) {
|
|
4143
|
+
const result = encoder.withOwner("extract", filePath, () => ctx.project.parseSourceFile(filePath, encoder));
|
|
4144
|
+
recordResolvedTokenReferences(sourceScanCache, filePath, result);
|
|
4145
|
+
if (result) parsed++;
|
|
4146
|
+
}
|
|
4147
|
+
if (parsed === 0 && !inventoryChanged) return;
|
|
4073
4148
|
const outfile = ctx.runtime.path.join(...ctx.paths.root, "styles.css");
|
|
4074
4149
|
const done = _bamboocss_logger.logger.time.info(ctx.messages.buildComplete(parsed));
|
|
4075
|
-
const sheet = assembleExtractedSheet(ctx, {
|
|
4150
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
4151
|
+
layerParams: true,
|
|
4152
|
+
sourceScanCache
|
|
4153
|
+
});
|
|
4076
4154
|
const css = ctx.getCss(sheet);
|
|
4077
4155
|
await ctx.runtime.fs.writeFile(outfile, css);
|
|
4078
4156
|
done();
|
|
@@ -4082,7 +4160,9 @@ async function generate(config, configPath) {
|
|
|
4082
4160
|
if (event === "unlink") {
|
|
4083
4161
|
const dependents = ctx.project.getDependents(filePath);
|
|
4084
4162
|
ctx.project.removeSourceFile(filePath);
|
|
4085
|
-
|
|
4163
|
+
sourceScanCache.entries.delete(filePath);
|
|
4164
|
+
sourceScanCache.resolvedTokenReferences.delete(filePath);
|
|
4165
|
+
await bundleStyles(ctx, dependents, true);
|
|
4086
4166
|
} else if (event === "change") {
|
|
4087
4167
|
ctx.project.reloadSourceFile(filePath);
|
|
4088
4168
|
await bundleStyles(ctx, [filePath, ...ctx.project.getDependents(filePath)]);
|
package/dist/index.d.cts
CHANGED
|
@@ -200,7 +200,13 @@ declare class BambooContext extends Generator {
|
|
|
200
200
|
}
|
|
201
201
|
//#endregion
|
|
202
202
|
//#region src/analyze.d.ts
|
|
203
|
-
|
|
203
|
+
/**
|
|
204
|
+
* `analyze` is one CLI command, but this module is reachable from `@bamboocss/node`'s index,
|
|
205
|
+
* so a static import made every consumer of that index — the CLI on any command, and the Vite
|
|
206
|
+
* plugin on every build — load the reporter and its table formatters to run neither. Loading
|
|
207
|
+
* it here keeps that off the path of everything that is not the `analyze` command.
|
|
208
|
+
*/
|
|
209
|
+
declare function analyze(ctx: BambooContext, options?: AnalysisOptions): Promise<{
|
|
204
210
|
getRecipeReport(format?: ReportFormat): {
|
|
205
211
|
report: import("@bamboocss/reporter").RecipeReportEntry[];
|
|
206
212
|
formatted: string;
|
|
@@ -210,7 +216,7 @@ declare function analyze(ctx: BambooContext, options?: AnalysisOptions): {
|
|
|
210
216
|
formatted: string;
|
|
211
217
|
};
|
|
212
218
|
writeReport(filePath: string): Promise<void>;
|
|
213
|
-
}
|
|
219
|
+
}>;
|
|
214
220
|
//#endregion
|
|
215
221
|
//#region src/build-info.d.ts
|
|
216
222
|
declare function buildInfo(ctx: BambooContext, outfile: string): Promise<void>;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { n as markStaticCompilerActive, t as isStaticCompilerActive } from "./static-compiler-CvT9iHM_.mjs";
|
|
2
|
-
import { ReportFormat } from "@bamboocss/reporter";
|
|
3
2
|
import { DeadImport, StyleEncoder, Stylesheet } from "@bamboocss/core";
|
|
4
3
|
import { Generator, generatePackageExports } from "@bamboocss/generator";
|
|
5
4
|
import { ParserResult, Project } from "@bamboocss/parser";
|
|
5
|
+
import { ReportFormat } from "@bamboocss/reporter";
|
|
6
6
|
import { AnalysisOptions, Artifact, ArtifactId, BambooHooks, Config, CssArtifactType, LoadConfigResult, Runtime, SpecFile, WatchOptions, WatcherEventType } from "@bamboocss/types";
|
|
7
7
|
|
|
8
8
|
//#region src/diff-engine.d.ts
|
|
@@ -200,7 +200,13 @@ declare class BambooContext extends Generator {
|
|
|
200
200
|
}
|
|
201
201
|
//#endregion
|
|
202
202
|
//#region src/analyze.d.ts
|
|
203
|
-
|
|
203
|
+
/**
|
|
204
|
+
* `analyze` is one CLI command, but this module is reachable from `@bamboocss/node`'s index,
|
|
205
|
+
* so a static import made every consumer of that index — the CLI on any command, and the Vite
|
|
206
|
+
* plugin on every build — load the reporter and its table formatters to run neither. Loading
|
|
207
|
+
* it here keeps that off the path of everything that is not the `analyze` command.
|
|
208
|
+
*/
|
|
209
|
+
declare function analyze(ctx: BambooContext, options?: AnalysisOptions): Promise<{
|
|
204
210
|
getRecipeReport(format?: ReportFormat): {
|
|
205
211
|
report: import("@bamboocss/reporter").RecipeReportEntry[];
|
|
206
212
|
formatted: string;
|
|
@@ -210,7 +216,7 @@ declare function analyze(ctx: BambooContext, options?: AnalysisOptions): {
|
|
|
210
216
|
formatted: string;
|
|
211
217
|
};
|
|
212
218
|
writeReport(filePath: string): Promise<void>;
|
|
213
|
-
}
|
|
219
|
+
}>;
|
|
214
220
|
//#endregion
|
|
215
221
|
//#region src/build-info.d.ts
|
|
216
222
|
declare function buildInfo(ctx: BambooContext, outfile: string): Promise<void>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { isStaticCompilerActive, markStaticCompilerActive } from "./static-compiler.mjs";
|
|
2
|
-
import { Reporter, formatRecipeReport, formatTokenReport } from "@bamboocss/reporter";
|
|
3
2
|
import { colors, logger, quote } from "@bamboocss/logger";
|
|
4
3
|
import { convertTsPathsToRegexes, diffConfigs, findConfig, loadConfig, mergeHooks } from "@bamboocss/config";
|
|
5
4
|
import { BambooError, cssVarRefs, groupBy, truncateList, uniq } from "@bamboocss/shared";
|
|
@@ -52,7 +51,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
52
51
|
}) : target, mod));
|
|
53
52
|
//#endregion
|
|
54
53
|
//#region src/analyze.ts
|
|
55
|
-
|
|
54
|
+
/**
|
|
55
|
+
* `analyze` is one CLI command, but this module is reachable from `@bamboocss/node`'s index,
|
|
56
|
+
* so a static import made every consumer of that index — the CLI on any command, and the Vite
|
|
57
|
+
* plugin on every build — load the reporter and its table formatters to run neither. Loading
|
|
58
|
+
* it here keeps that off the path of everything that is not the `analyze` command.
|
|
59
|
+
*/
|
|
60
|
+
async function analyze(ctx, options = {}) {
|
|
61
|
+
const { Reporter, formatRecipeReport, formatTokenReport } = await import("@bamboocss/reporter");
|
|
56
62
|
const reporter = new Reporter(ctx, {
|
|
57
63
|
project: ctx.project,
|
|
58
64
|
getRelativePath: ctx.runtime.path.relative,
|
|
@@ -2254,9 +2260,10 @@ var BambooContext = class extends Generator {
|
|
|
2254
2260
|
const results = [];
|
|
2255
2261
|
files.forEach((file) => {
|
|
2256
2262
|
const result = this.parseFile(file, encoder);
|
|
2257
|
-
if (!result || result.isEmpty()
|
|
2258
|
-
filesWithCss.push(file);
|
|
2263
|
+
if (!result || result.isEmpty()) return;
|
|
2259
2264
|
results.push(result);
|
|
2265
|
+
if (encoder.isEmpty()) return;
|
|
2266
|
+
filesWithCss.push(file);
|
|
2260
2267
|
});
|
|
2261
2268
|
this.assertExtracted(files);
|
|
2262
2269
|
this.assertNoDeadCalls(files);
|
|
@@ -2576,7 +2583,9 @@ function accountFile(ctx, sourceFile, filePath, paths, prefixes, declined) {
|
|
|
2576
2583
|
const decline = (node, reason) => declined.push({
|
|
2577
2584
|
filePath,
|
|
2578
2585
|
line: lineOf(node),
|
|
2579
|
-
reason
|
|
2586
|
+
reason,
|
|
2587
|
+
start: node.getStart(),
|
|
2588
|
+
end: node.getEnd()
|
|
2580
2589
|
});
|
|
2581
2590
|
/** Local names bound to the artifact: the `token` export, and any namespace of it. */
|
|
2582
2591
|
const bindings = /* @__PURE__ */ new Set();
|
|
@@ -2977,10 +2986,49 @@ function* sourceTexts(ctx) {
|
|
|
2977
2986
|
}
|
|
2978
2987
|
const createSourceScanCache = () => ({
|
|
2979
2988
|
signature: "",
|
|
2980
|
-
entries: /* @__PURE__ */ new Map()
|
|
2989
|
+
entries: /* @__PURE__ */ new Map(),
|
|
2990
|
+
resolvedTokenReferences: /* @__PURE__ */ new Map()
|
|
2981
2991
|
});
|
|
2992
|
+
const resolvedTokenReferences = (result) => {
|
|
2993
|
+
if (!result) return [];
|
|
2994
|
+
const facts = [];
|
|
2995
|
+
for (const item of result.token) {
|
|
2996
|
+
if (!item.tokenCalleeRange || !item.data?.length) continue;
|
|
2997
|
+
const paths = [];
|
|
2998
|
+
for (const value of item.data) {
|
|
2999
|
+
if (typeof value !== "string") break;
|
|
3000
|
+
paths.push(value);
|
|
3001
|
+
}
|
|
3002
|
+
if (paths.length !== item.data.length) continue;
|
|
3003
|
+
facts.push({
|
|
3004
|
+
...item.tokenCalleeRange,
|
|
3005
|
+
paths: [...new Set(paths)].sort()
|
|
3006
|
+
});
|
|
3007
|
+
}
|
|
3008
|
+
return facts.sort((left, right) => left.start - right.start || left.end - right.end);
|
|
3009
|
+
};
|
|
3010
|
+
const sameResolvedTokenReferences = (left, right) => (left?.length ?? 0) === right.length && right.every((fact, index) => fact.start === left[index].start && fact.end === left[index].end && fact.paths.length === left[index].paths.length && fact.paths.every((path, pathIndex) => path === left[index].paths[pathIndex]));
|
|
3011
|
+
/**
|
|
3012
|
+
* Reconcile one file's lightweight token facts after extraction.
|
|
3013
|
+
*
|
|
3014
|
+
* Deleting the source scan only when the semantic facts moved is important for dependents:
|
|
3015
|
+
* changing an imported constant can change `token(KEY)` without changing the consumer's mtime.
|
|
3016
|
+
*/
|
|
3017
|
+
const recordResolvedTokenReferences = (cache, filePath, result) => {
|
|
3018
|
+
const next = resolvedTokenReferences(result);
|
|
3019
|
+
if (sameResolvedTokenReferences(cache.resolvedTokenReferences.get(filePath), next)) return;
|
|
3020
|
+
if (next.length) cache.resolvedTokenReferences.set(filePath, next);
|
|
3021
|
+
else cache.resolvedTokenReferences.delete(filePath);
|
|
3022
|
+
cache.entries.delete(filePath);
|
|
3023
|
+
};
|
|
3024
|
+
const reconcileAccounting = (accounting, references, filePath) => {
|
|
3025
|
+
if (!references?.length) return;
|
|
3026
|
+
const ranges = new Set(references.map(({ start, end }) => `${start}:${end}`));
|
|
3027
|
+
for (const reference of references) for (const path of reference.paths) accounting.paths.add(path);
|
|
3028
|
+
accounting.declined = accounting.declined.filter((entry) => entry.reason !== "unresolved-reference" || filePath !== void 0 && entry.filePath !== filePath || entry.start == null || entry.end == null || !ranges.has(`${entry.start}:${entry.end}`));
|
|
3029
|
+
};
|
|
2982
3030
|
const OPEN_TAG = /<\s*([a-z][\w-]*)(?=[\s/>]|$)/g;
|
|
2983
|
-
const scanSnapshot = (ctx, snapshot, options, patterns) => {
|
|
3031
|
+
const scanSnapshot = (ctx, snapshot, options, patterns, resolvedReferences) => {
|
|
2984
3032
|
const tokenPaths = /* @__PURE__ */ new Set();
|
|
2985
3033
|
const cssVars = /* @__PURE__ */ new Set();
|
|
2986
3034
|
const elements = /* @__PURE__ */ new Set();
|
|
@@ -2999,6 +3047,7 @@ const scanSnapshot = (ctx, snapshot, options, patterns) => {
|
|
|
2999
3047
|
declined: []
|
|
3000
3048
|
};
|
|
3001
3049
|
accountSnapshot(ctx, snapshot, accounting);
|
|
3050
|
+
reconcileAccounting(accounting, resolvedReferences);
|
|
3002
3051
|
return {
|
|
3003
3052
|
tokenPaths: [...tokenPaths],
|
|
3004
3053
|
cssVars: [...cssVars],
|
|
@@ -3068,7 +3117,7 @@ function collectSourceScans(ctx, options, cache, mtimeOf, files) {
|
|
|
3068
3117
|
merge(entry.scan);
|
|
3069
3118
|
continue;
|
|
3070
3119
|
}
|
|
3071
|
-
const scan = scanSnapshot(ctx, readSnapshot(ctx, filePath), options, allPatterns);
|
|
3120
|
+
const scan = scanSnapshot(ctx, readSnapshot(ctx, filePath), options, allPatterns, cache.resolvedTokenReferences.get(filePath));
|
|
3072
3121
|
cache.entries.set(filePath, {
|
|
3073
3122
|
mtime,
|
|
3074
3123
|
scan
|
|
@@ -3081,6 +3130,7 @@ function collectSourceScans(ctx, options, cache, mtimeOf, files) {
|
|
|
3081
3130
|
}
|
|
3082
3131
|
if (cache && seen) {
|
|
3083
3132
|
for (const filePath of cache.entries.keys()) if (!seen.has(filePath)) cache.entries.delete(filePath);
|
|
3133
|
+
for (const filePath of cache.resolvedTokenReferences.keys()) if (!seen.has(filePath)) cache.resolvedTokenReferences.delete(filePath);
|
|
3084
3134
|
}
|
|
3085
3135
|
return result;
|
|
3086
3136
|
}
|
|
@@ -3101,7 +3151,10 @@ function pruneTokensForBuild(ctx, sheet, results, sourceScans) {
|
|
|
3101
3151
|
const vars = new Set(scans.cssVars);
|
|
3102
3152
|
const accounting = scans.accounting;
|
|
3103
3153
|
const reachable = scans.reachableFromJs;
|
|
3104
|
-
for (const result of results)
|
|
3154
|
+
for (const result of results) {
|
|
3155
|
+
if (result.filePath) reconcileAccounting(accounting, resolvedTokenReferences(result), ctx.runtime.path.abs(ctx.config.cwd, result.filePath));
|
|
3156
|
+
for (const item of result.token) for (const value of item.data ?? []) if (typeof value === "string") paths.add(value);
|
|
3157
|
+
}
|
|
3105
3158
|
for (const name of tokenVarsFor(ctx, paths)) vars.add(name);
|
|
3106
3159
|
const declared = declaredKeeps(ctx);
|
|
3107
3160
|
for (const name of tokenVarsFor(ctx, declared)) vars.add(name);
|
|
@@ -3233,7 +3286,7 @@ function collectRenderedElements(ctx) {
|
|
|
3233
3286
|
* Vite, `bamboo cssgen`, and the CLI `bamboo` command all finish here so a recipe lowered to
|
|
3234
3287
|
* atoms cannot have a different sheet depending on which integration asked for it.
|
|
3235
3288
|
*/
|
|
3236
|
-
const assembleExtractedSheet = (ctx, { layerParams = false, sourceScanCache, mtimeOf, sourceInventory } = {}) => {
|
|
3289
|
+
const assembleExtractedSheet = (ctx, { layerParams = false, sourceScanCache, mtimeOf, sourceInventory, parserResults = [] } = {}) => {
|
|
3237
3290
|
ctx.encoder.atomizeObservedRecipes();
|
|
3238
3291
|
const sheet = ctx.createSheet();
|
|
3239
3292
|
if (layerParams) {
|
|
@@ -3248,7 +3301,7 @@ const assembleExtractedSheet = (ctx, { layerParams = false, sourceScanCache, mti
|
|
|
3248
3301
|
keyframeNames: declaredKeyframes,
|
|
3249
3302
|
elements: collectElements
|
|
3250
3303
|
}, sourceScanCache, mtimeOf, sourceInventory) : void 0;
|
|
3251
|
-
const reachableVars = pruneTokensForBuild(ctx, sheet,
|
|
3304
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, parserResults, scans);
|
|
3252
3305
|
if (collectElements && scans) ctx.prunePreflight(sheet, scans.elements);
|
|
3253
3306
|
if (pruneKeyframes && scans) ctx.pruneKeyframes(sheet, scans.keyframeHits, reachableVars);
|
|
3254
3307
|
return sheet;
|
|
@@ -3499,6 +3552,7 @@ var Builder = class {
|
|
|
3499
3552
|
this.resolutionConfigurationSets.clear();
|
|
3500
3553
|
this.resolutionConfigurationBytes.clear();
|
|
3501
3554
|
this.sourceScanCache.entries.clear();
|
|
3555
|
+
this.sourceScanCache.resolvedTokenReferences.clear();
|
|
3502
3556
|
this.extractionReadsByOwner.clear();
|
|
3503
3557
|
this.recipeSurfaceByOwner.clear();
|
|
3504
3558
|
this.capturedLedger = void 0;
|
|
@@ -3779,6 +3833,7 @@ var Builder = class {
|
|
|
3779
3833
|
const previousCandidates = this.resolutionCandidateSets.get(owner) ?? [];
|
|
3780
3834
|
const previousConfigurations = this.resolutionConfigurationSets.get(owner) ?? [];
|
|
3781
3835
|
const parserResult = ctx.parseFile(file);
|
|
3836
|
+
recordResolvedTokenReferences(this.sourceScanCache, this.absOwner(ctx, file), parserResult);
|
|
3782
3837
|
fileModifiedMap.set(file, meta.mtime);
|
|
3783
3838
|
{
|
|
3784
3839
|
const owner = this.absOwner(ctx, file);
|
|
@@ -3951,9 +4006,12 @@ const cssgen = async (ctx, options) => {
|
|
|
3951
4006
|
} else await ctx.writeCss(sheet);
|
|
3952
4007
|
done();
|
|
3953
4008
|
} else {
|
|
3954
|
-
const { files } = ctx.parseFiles();
|
|
4009
|
+
const { files, results } = ctx.parseFiles();
|
|
3955
4010
|
const done = logger.time.info(ctx.messages.buildComplete(files.length));
|
|
3956
|
-
const sheet = assembleExtractedSheet(ctx, {
|
|
4011
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
4012
|
+
layerParams: true,
|
|
4013
|
+
parserResults: results
|
|
4014
|
+
});
|
|
3957
4015
|
if (splitting) await ctx.writeSplitCss(sheet);
|
|
3958
4016
|
else if (outfile) {
|
|
3959
4017
|
const css = ctx.getCss(sheet);
|
|
@@ -4014,12 +4072,22 @@ async function debug(ctx, options) {
|
|
|
4014
4072
|
}
|
|
4015
4073
|
//#endregion
|
|
4016
4074
|
//#region src/generate.ts
|
|
4017
|
-
async function build(ctx, artifactIds) {
|
|
4075
|
+
async function build(ctx, sourceScanCache, artifactIds) {
|
|
4018
4076
|
await codegen(ctx, artifactIds);
|
|
4019
4077
|
if (ctx.config.emitTokensOnly) return logger.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens ✨");
|
|
4020
4078
|
const done = logger.time.info("");
|
|
4021
4079
|
const parsed = ctx.parseFiles();
|
|
4022
|
-
|
|
4080
|
+
if (sourceScanCache) {
|
|
4081
|
+
for (const result of parsed.results) if (result.filePath) recordResolvedTokenReferences(sourceScanCache, ctx.runtime.path.abs(ctx.config.cwd, result.filePath), result);
|
|
4082
|
+
}
|
|
4083
|
+
const sheet = assembleExtractedSheet(ctx, sourceScanCache ? {
|
|
4084
|
+
layerParams: true,
|
|
4085
|
+
sourceScanCache,
|
|
4086
|
+
sourceInventory: parsed.files
|
|
4087
|
+
} : {
|
|
4088
|
+
layerParams: true,
|
|
4089
|
+
parserResults: parsed.results
|
|
4090
|
+
});
|
|
4023
4091
|
await ctx.writeCss(sheet);
|
|
4024
4092
|
done(ctx.messages.buildComplete(parsed.files.length));
|
|
4025
4093
|
}
|
|
@@ -4028,19 +4096,22 @@ async function generate(config, configPath) {
|
|
|
4028
4096
|
config,
|
|
4029
4097
|
configPath
|
|
4030
4098
|
});
|
|
4031
|
-
|
|
4099
|
+
const sourceScanCache = createSourceScanCache();
|
|
4032
4100
|
const { cwd, watch, poll } = ctx.config;
|
|
4101
|
+
await build(ctx, watch ? sourceScanCache : void 0);
|
|
4033
4102
|
if (watch) {
|
|
4034
4103
|
ctx.watchConfig(async () => {
|
|
4035
4104
|
const affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
|
|
4036
4105
|
ctx = new BambooContext(conf);
|
|
4037
4106
|
});
|
|
4107
|
+
sourceScanCache.entries.clear();
|
|
4108
|
+
sourceScanCache.resolvedTokenReferences.clear();
|
|
4038
4109
|
logger.info("ctx:updated", "config rebuilt ✅");
|
|
4039
4110
|
await ctx.hooks["config:change"]?.({
|
|
4040
4111
|
config: ctx.config,
|
|
4041
4112
|
changes: affecteds
|
|
4042
4113
|
});
|
|
4043
|
-
return build(ctx, Array.from(affecteds.artifacts));
|
|
4114
|
+
return build(ctx, sourceScanCache, Array.from(affecteds.artifacts));
|
|
4044
4115
|
}, {
|
|
4045
4116
|
cwd,
|
|
4046
4117
|
poll
|
|
@@ -4053,14 +4124,21 @@ async function generate(config, configPath) {
|
|
|
4053
4124
|
* per file. Writing per file would run the optimize pipeline and hit the disk
|
|
4054
4125
|
* once per importer for a single keystroke.
|
|
4055
4126
|
*/
|
|
4056
|
-
const bundleStyles = async (ctx, changedFilePaths) => {
|
|
4127
|
+
const bundleStyles = async (ctx, changedFilePaths, inventoryChanged = false) => {
|
|
4057
4128
|
let parsed = 0;
|
|
4058
4129
|
const encoder = ctx.parserOptions.encoder;
|
|
4059
|
-
for (const filePath of changedFilePaths)
|
|
4060
|
-
|
|
4130
|
+
for (const filePath of changedFilePaths) {
|
|
4131
|
+
const result = encoder.withOwner("extract", filePath, () => ctx.project.parseSourceFile(filePath, encoder));
|
|
4132
|
+
recordResolvedTokenReferences(sourceScanCache, filePath, result);
|
|
4133
|
+
if (result) parsed++;
|
|
4134
|
+
}
|
|
4135
|
+
if (parsed === 0 && !inventoryChanged) return;
|
|
4061
4136
|
const outfile = ctx.runtime.path.join(...ctx.paths.root, "styles.css");
|
|
4062
4137
|
const done = logger.time.info(ctx.messages.buildComplete(parsed));
|
|
4063
|
-
const sheet = assembleExtractedSheet(ctx, {
|
|
4138
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
4139
|
+
layerParams: true,
|
|
4140
|
+
sourceScanCache
|
|
4141
|
+
});
|
|
4064
4142
|
const css = ctx.getCss(sheet);
|
|
4065
4143
|
await ctx.runtime.fs.writeFile(outfile, css);
|
|
4066
4144
|
done();
|
|
@@ -4070,7 +4148,9 @@ async function generate(config, configPath) {
|
|
|
4070
4148
|
if (event === "unlink") {
|
|
4071
4149
|
const dependents = ctx.project.getDependents(filePath);
|
|
4072
4150
|
ctx.project.removeSourceFile(filePath);
|
|
4073
|
-
|
|
4151
|
+
sourceScanCache.entries.delete(filePath);
|
|
4152
|
+
sourceScanCache.resolvedTokenReferences.delete(filePath);
|
|
4153
|
+
await bundleStyles(ctx, dependents, true);
|
|
4074
4154
|
} else if (event === "change") {
|
|
4075
4155
|
ctx.project.reloadSourceFile(filePath);
|
|
4076
4156
|
await bundleStyles(ctx, [filePath, ...ctx.project.getDependents(filePath)]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.49.0",
|
|
4
4
|
"description": "The core css bamboo library",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -62,17 +62,17 @@
|
|
|
62
62
|
"pluralize": "8.0.0",
|
|
63
63
|
"ts-morph": "28.0.0",
|
|
64
64
|
"ts-pattern": "5.9.0",
|
|
65
|
-
"@bamboocss/
|
|
66
|
-
"@bamboocss/
|
|
67
|
-
"@bamboocss/generator": "1.
|
|
68
|
-
"@bamboocss/logger": "1.
|
|
69
|
-
"@bamboocss/parser": "1.
|
|
70
|
-
"@bamboocss/plugin-
|
|
71
|
-
"@bamboocss/
|
|
72
|
-
"@bamboocss/
|
|
73
|
-
"@bamboocss/shared": "1.
|
|
74
|
-
"@bamboocss/token-dictionary": "1.
|
|
75
|
-
"@bamboocss/types": "1.
|
|
65
|
+
"@bamboocss/core": "1.49.0",
|
|
66
|
+
"@bamboocss/config": "1.49.0",
|
|
67
|
+
"@bamboocss/generator": "1.49.0",
|
|
68
|
+
"@bamboocss/logger": "1.49.0",
|
|
69
|
+
"@bamboocss/parser": "1.49.0",
|
|
70
|
+
"@bamboocss/plugin-vue": "1.49.0",
|
|
71
|
+
"@bamboocss/reporter": "1.49.0",
|
|
72
|
+
"@bamboocss/plugin-svelte": "1.49.0",
|
|
73
|
+
"@bamboocss/shared": "1.49.0",
|
|
74
|
+
"@bamboocss/token-dictionary": "1.49.0",
|
|
75
|
+
"@bamboocss/types": "1.49.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@types/fs-extra": "11.0.4",
|