@bamboocss/node 1.47.0 → 1.48.1
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 -4
- package/dist/index.cjs +120 -202
- package/dist/index.d.cts +49 -43
- package/dist/index.d.mts +49 -43
- package/dist/index.mjs +121 -200
- package/package.json +12 -17
package/README.md
CHANGED
|
@@ -18,8 +18,7 @@ Everything below is exported from `@bamboocss/node`.
|
|
|
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
|
|
21
|
-
dependencies changed, re-extracts only those, and hands back the stylesheet (`toCss`)
|
|
22
|
-
(`write`).
|
|
21
|
+
dependencies changed, re-extracts only those, and hands back the stylesheet (`toCss`).
|
|
23
22
|
|
|
24
23
|
### Commands
|
|
25
24
|
|
|
@@ -37,8 +36,6 @@ Each takes a `BambooContext`, and each backs the CLI command of the same name.
|
|
|
37
36
|
|
|
38
37
|
- `setupConfig(cwd, options?)` – scaffold `bamboo.config.ts`.
|
|
39
38
|
- `setupGitIgnore(ctx)` – add the outdir to `.gitignore`, unless `config.gitignore` is off.
|
|
40
|
-
- `parseDependency(fileOrGlob)` – turn a `config.dependencies` entry into a PostCSS `dependency` or `dir-dependency`
|
|
41
|
-
message.
|
|
42
39
|
- `setLogStream({ cwd, logfile })` – tee logs to a file.
|
|
43
40
|
- `startProfiling(cwd, prefix, isWatching?)` – start a V8 CPU profile; the returned function stops it and writes
|
|
44
41
|
`bamboo-{prefix}-{timestamp}.cpuprofile` into `cwd`.
|
package/dist/index.cjs
CHANGED
|
@@ -30,6 +30,8 @@ let _bamboocss_shared = require("@bamboocss/shared");
|
|
|
30
30
|
let node_crypto = require("node:crypto");
|
|
31
31
|
let fs = require("fs");
|
|
32
32
|
let path = require("path");
|
|
33
|
+
let picomatch = require("picomatch");
|
|
34
|
+
picomatch = __toESM(picomatch);
|
|
33
35
|
let _bamboocss_plugin_svelte = require("@bamboocss/plugin-svelte");
|
|
34
36
|
let _bamboocss_plugin_vue = require("@bamboocss/plugin-vue");
|
|
35
37
|
let _bamboocss_core = require("@bamboocss/core");
|
|
@@ -53,12 +55,6 @@ let fast_glob = require("fast-glob");
|
|
|
53
55
|
fast_glob = __toESM(fast_glob);
|
|
54
56
|
let fs_extra = require("fs-extra");
|
|
55
57
|
fs_extra = __toESM(fs_extra);
|
|
56
|
-
let picomatch = require("picomatch");
|
|
57
|
-
picomatch = __toESM(picomatch);
|
|
58
|
-
let is_glob = require("is-glob");
|
|
59
|
-
is_glob = __toESM(is_glob);
|
|
60
|
-
let glob_parent = require("glob-parent");
|
|
61
|
-
glob_parent = __toESM(glob_parent);
|
|
62
58
|
let matcher = require("matcher");
|
|
63
59
|
let _bamboocss_config_ts_path = require("@bamboocss/config/ts-path");
|
|
64
60
|
let node_readline = require("node:readline");
|
|
@@ -2293,12 +2289,12 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2293
2289
|
}]
|
|
2294
2290
|
});
|
|
2295
2291
|
};
|
|
2296
|
-
writeSplitCss = async (sheet
|
|
2292
|
+
writeSplitCss = async (sheet) => {
|
|
2297
2293
|
const { path: pathUtil, fs } = this.runtime;
|
|
2298
2294
|
const rootDir = this.paths.root;
|
|
2299
2295
|
const stylesDir = [...rootDir, "styles"];
|
|
2300
|
-
const artifacts = this.getSplitCssArtifacts(sheet
|
|
2301
|
-
const subDirs = new Set(
|
|
2296
|
+
const artifacts = this.getSplitCssArtifacts(sheet);
|
|
2297
|
+
const subDirs = new Set(artifacts.themes.map((a) => a.dir).filter(Boolean));
|
|
2302
2298
|
fs.ensureDirSync(pathUtil.join(...stylesDir));
|
|
2303
2299
|
subDirs.forEach((dir) => fs.ensureDirSync(pathUtil.join(...stylesDir, dir)));
|
|
2304
2300
|
const styleFiles = [];
|
|
@@ -2309,20 +2305,6 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2309
2305
|
});
|
|
2310
2306
|
_bamboocss_logger.logger.info("css", pathUtil.join(...stylesDir, layer.file));
|
|
2311
2307
|
}
|
|
2312
|
-
for (const recipe of artifacts.recipes) {
|
|
2313
|
-
styleFiles.push({
|
|
2314
|
-
file: `${recipe.dir}/${recipe.file}`,
|
|
2315
|
-
code: recipe.code
|
|
2316
|
-
});
|
|
2317
|
-
_bamboocss_logger.logger.info("css", pathUtil.join(...stylesDir, recipe.dir, recipe.file));
|
|
2318
|
-
}
|
|
2319
|
-
if (artifacts.recipes.length) {
|
|
2320
|
-
styleFiles.push({
|
|
2321
|
-
file: "recipes.css",
|
|
2322
|
-
code: artifacts.recipesIndex
|
|
2323
|
-
});
|
|
2324
|
-
_bamboocss_logger.logger.info("css", pathUtil.join(...stylesDir, "recipes.css"));
|
|
2325
|
-
}
|
|
2326
2308
|
for (const theme of artifacts.themes) {
|
|
2327
2309
|
styleFiles.push({
|
|
2328
2310
|
file: `${theme.dir}/${theme.file}`,
|
|
@@ -2344,12 +2326,10 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2344
2326
|
code: artifacts.index
|
|
2345
2327
|
}]
|
|
2346
2328
|
});
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
if (fs.existsSync(recipesDir)) fs.rmFileSync(recipesDir);
|
|
2352
|
-
}
|
|
2329
|
+
const recipesIndex = pathUtil.join(...stylesDir, "recipes.css");
|
|
2330
|
+
const recipesDir = pathUtil.join(...stylesDir, "recipes");
|
|
2331
|
+
if (fs.existsSync(recipesIndex)) fs.rmFileSync(recipesIndex);
|
|
2332
|
+
if (fs.existsSync(recipesDir)) fs.rmFileSync(recipesDir);
|
|
2353
2333
|
};
|
|
2354
2334
|
watchConfig = (cb, opts) => {
|
|
2355
2335
|
const { cwd, poll, exclude } = opts ?? {};
|
|
@@ -2453,44 +2433,6 @@ async function loadConfigAndCreateContext(options = {}) {
|
|
|
2453
2433
|
return new BambooContext(conf);
|
|
2454
2434
|
}
|
|
2455
2435
|
//#endregion
|
|
2456
|
-
//#region src/parse-glob.ts
|
|
2457
|
-
function parseGlob(pattern) {
|
|
2458
|
-
let glob = pattern;
|
|
2459
|
-
const base = (0, glob_parent.default)(pattern);
|
|
2460
|
-
if (base !== ".") {
|
|
2461
|
-
glob = pattern.substring(base.length);
|
|
2462
|
-
if (glob.charAt(0) === "/") glob = glob.substring(1);
|
|
2463
|
-
}
|
|
2464
|
-
if (glob.substring(0, 2) === "./") glob = glob.substring(2);
|
|
2465
|
-
if (glob.charAt(0) === "/") glob = glob.substring(1);
|
|
2466
|
-
return {
|
|
2467
|
-
base,
|
|
2468
|
-
glob
|
|
2469
|
-
};
|
|
2470
|
-
}
|
|
2471
|
-
//#endregion
|
|
2472
|
-
//#region src/parse-dependency.ts
|
|
2473
|
-
function parseDependency(fileOrGlob) {
|
|
2474
|
-
if (fileOrGlob.startsWith("!")) return null;
|
|
2475
|
-
let message = null;
|
|
2476
|
-
if ((0, is_glob.default)(fileOrGlob)) {
|
|
2477
|
-
const { base, glob } = parseGlob(fileOrGlob);
|
|
2478
|
-
message = {
|
|
2479
|
-
type: "dir-dependency",
|
|
2480
|
-
dir: (0, path.normalize)((0, path.resolve)(base)),
|
|
2481
|
-
glob
|
|
2482
|
-
};
|
|
2483
|
-
} else message = {
|
|
2484
|
-
type: "dependency",
|
|
2485
|
-
file: (0, path.normalize)((0, path.resolve)(fileOrGlob))
|
|
2486
|
-
};
|
|
2487
|
-
if (message.type === "dir-dependency" && process.env.ROLLUP_WATCH === "true") message = {
|
|
2488
|
-
type: "dependency",
|
|
2489
|
-
file: (0, path.normalize)((0, path.resolve)(message.dir))
|
|
2490
|
-
};
|
|
2491
|
-
return message;
|
|
2492
|
-
}
|
|
2493
|
-
//#endregion
|
|
2494
2436
|
//#region src/source-snapshots.ts
|
|
2495
2437
|
/**
|
|
2496
2438
|
* Every file `include` covers, read once.
|
|
@@ -3303,22 +3245,14 @@ function collectRenderedElements(ctx) {
|
|
|
3303
3245
|
* Vite, `bamboo cssgen`, and the CLI `bamboo` command all finish here so a recipe lowered to
|
|
3304
3246
|
* atoms cannot have a different sheet depending on which integration asked for it.
|
|
3305
3247
|
*/
|
|
3306
|
-
const assembleExtractedSheet = (ctx, { layerParams = false,
|
|
3307
|
-
|
|
3308
|
-
if (!includeRecipes) ctx.encoder.atomizeObservedRecipes();
|
|
3248
|
+
const assembleExtractedSheet = (ctx, { layerParams = false, sourceScanCache, mtimeOf, sourceInventory } = {}) => {
|
|
3249
|
+
ctx.encoder.atomizeObservedRecipes();
|
|
3309
3250
|
const sheet = ctx.createSheet();
|
|
3310
|
-
if (layerParams)
|
|
3311
|
-
else {
|
|
3251
|
+
if (layerParams) {
|
|
3312
3252
|
const recipeLayer = ctx.config.layers?.recipes ?? "recipes";
|
|
3313
3253
|
sheet.layers.root.prepend(`@layer ${sheet.layers.layerNames.filter((name) => name !== recipeLayer).join(", ")};`);
|
|
3314
3254
|
}
|
|
3315
|
-
ctx.appendBaselineCss(sheet);
|
|
3316
|
-
if (!includeRecipes) {
|
|
3317
|
-
sheet.layers.recipes.removeAll();
|
|
3318
|
-
sheet.layers.recipes_base.removeAll();
|
|
3319
|
-
sheet.layers.recipes_slots.removeAll();
|
|
3320
|
-
sheet.layers.recipes_slots_base.removeAll();
|
|
3321
|
-
}
|
|
3255
|
+
ctx.appendBaselineCss(sheet, { atomizeRecipes: true });
|
|
3322
3256
|
const collectElements = (0, _bamboocss_core.prunesPreflight)(ctx.config.preflight);
|
|
3323
3257
|
const pruneKeyframes = Boolean(ctx.config.prune?.keyframes);
|
|
3324
3258
|
const declaredKeyframes = pruneKeyframes ? keyframeNames(ctx) : [];
|
|
@@ -3334,24 +3268,6 @@ const assembleExtractedSheet = (ctx, { layerParams = false, includeRecipes = fal
|
|
|
3334
3268
|
//#endregion
|
|
3335
3269
|
//#region src/builder.ts
|
|
3336
3270
|
const fileModifiedMap = /* @__PURE__ */ new Map();
|
|
3337
|
-
/**
|
|
3338
|
-
* The declaration that says generated css is already present in a root.
|
|
3339
|
-
*
|
|
3340
|
-
* `generateGlobalCss` emits it unconditionally and `appendBaselineCss` always reaches that
|
|
3341
|
-
* artifact, so anything carrying it holds a copy of the sheet however it got there — written
|
|
3342
|
-
* by `write` on an earlier pass, or inlined from `styles.css` by `postcss-import`.
|
|
3343
|
-
*
|
|
3344
|
-
* A declaration rather than a comment because it has to survive the css being minified
|
|
3345
|
-
* between the copy landing and this check running, which a comment does not.
|
|
3346
|
-
*/
|
|
3347
|
-
const GENERATED_SENTINEL = "--made-with-bamboo";
|
|
3348
|
-
function hasGeneratedCss(root) {
|
|
3349
|
-
let found = false;
|
|
3350
|
-
root.walkDecls(GENERATED_SENTINEL, () => {
|
|
3351
|
-
found = true;
|
|
3352
|
-
});
|
|
3353
|
-
return found;
|
|
3354
|
-
}
|
|
3355
3271
|
var Builder = class {
|
|
3356
3272
|
/**
|
|
3357
3273
|
* The current bamboo context
|
|
@@ -3362,7 +3278,6 @@ var Builder = class {
|
|
|
3362
3278
|
explicitDepsMeta;
|
|
3363
3279
|
affecteds;
|
|
3364
3280
|
configDependencies = /* @__PURE__ */ new Set();
|
|
3365
|
-
pendingConfigCrawl;
|
|
3366
3281
|
/** Last complete included inventory, including members which have since been deleted. */
|
|
3367
3282
|
sourceInventory;
|
|
3368
3283
|
/** Existing included owners selected by the last resolution-ledger invalidation pass. */
|
|
@@ -3397,6 +3312,35 @@ var Builder = class {
|
|
|
3397
3312
|
resolutionAffectedThisPass = false;
|
|
3398
3313
|
/** Per-pass digests of re-read values, so N dependents of one edit digest each value once. */
|
|
3399
3314
|
readDigestMemo = /* @__PURE__ */ new Map();
|
|
3315
|
+
/** Resolution ledger as it stood before this pass's first physical source mutation. */
|
|
3316
|
+
capturedLedger;
|
|
3317
|
+
/**
|
|
3318
|
+
* Reload one edited source, keeping the closure the next extraction pass has to select.
|
|
3319
|
+
*
|
|
3320
|
+
* An integration which shares this context has to refresh an edited module before anything
|
|
3321
|
+
* folds against it — a consumer is transformed before the module it imports, so the fold
|
|
3322
|
+
* would otherwise bake in the previous contents. Doing that through the Project directly
|
|
3323
|
+
* loses the graph the rebuild needs: reloading retracts the file's own forward edges, and
|
|
3324
|
+
* `invalidateChangedSources` reads them afterwards to find its dependents. So the mutation
|
|
3325
|
+
* belongs here, behind a snapshot taken before the first of them.
|
|
3326
|
+
*
|
|
3327
|
+
* Once per pass, not once per file: the first mutation is the boundary, and every later one
|
|
3328
|
+
* in the same event is already described by that snapshot. `refreshSourceState` consumes it.
|
|
3329
|
+
*/
|
|
3330
|
+
reloadSource = (filePath) => {
|
|
3331
|
+
const ctx = this.getContextOrThrow();
|
|
3332
|
+
this.captureResolutionLedger(ctx);
|
|
3333
|
+
return ctx.project.reloadSourceFile(filePath);
|
|
3334
|
+
};
|
|
3335
|
+
/** The deletion half of `reloadSource`, with the same snapshot obligation. */
|
|
3336
|
+
removeSource = (filePath) => {
|
|
3337
|
+
const ctx = this.getContextOrThrow();
|
|
3338
|
+
this.captureResolutionLedger(ctx);
|
|
3339
|
+
return ctx.project.removeSourceFile(filePath);
|
|
3340
|
+
};
|
|
3341
|
+
captureResolutionLedger = (ctx) => {
|
|
3342
|
+
this.capturedLedger ??= ctx.project.getResolutionLedger();
|
|
3343
|
+
};
|
|
3400
3344
|
/** @internal Current and missing resolver paths which can change the stylesheet. */
|
|
3401
3345
|
getResolutionReadFiles = () => {
|
|
3402
3346
|
const files = /* @__PURE__ */ new Set();
|
|
@@ -3407,6 +3351,26 @@ var Builder = class {
|
|
|
3407
3351
|
]) for (const dependencies of readSets.values()) for (const dependency of dependencies) files.add(dependency);
|
|
3408
3352
|
return Object.freeze([...files].sort());
|
|
3409
3353
|
};
|
|
3354
|
+
/** @internal The inventory reconciled by the most recent extraction pass. */
|
|
3355
|
+
getSourceFiles = () => Object.freeze([...this.sourceInventory ?? []]);
|
|
3356
|
+
/** @internal Whether creating this path can change source or explicit-dependency membership. */
|
|
3357
|
+
isPotentialSourceFile = (filePath) => {
|
|
3358
|
+
const ctx = this.getContextOrThrow();
|
|
3359
|
+
const absolutePath = this.absOwner(ctx, filePath);
|
|
3360
|
+
const relativePath = this.sourcePath(ctx.runtime.path.relative(ctx.config.cwd, absolutePath));
|
|
3361
|
+
const sourcePatterns = ctx.config.include ?? [];
|
|
3362
|
+
const sourceMatcher = sourcePatterns.length ? (0, picomatch.default)(sourcePatterns, { ignore: globIgnore(ctx.config.exclude) }) : void 0;
|
|
3363
|
+
return sourceMatcher?.(relativePath) || sourceMatcher?.(absolutePath) || false;
|
|
3364
|
+
};
|
|
3365
|
+
/** @internal Whether creating or deleting this path can change a `dependencies` glob. */
|
|
3366
|
+
isPotentialConfigDependency = (filePath) => {
|
|
3367
|
+
const ctx = this.getContextOrThrow();
|
|
3368
|
+
const absolutePath = this.absOwner(ctx, filePath);
|
|
3369
|
+
const relativePath = this.sourcePath(ctx.runtime.path.relative(ctx.config.cwd, absolutePath));
|
|
3370
|
+
const patterns = ctx.config.dependencies ?? [];
|
|
3371
|
+
const matcher = patterns.length ? (0, picomatch.default)(patterns) : void 0;
|
|
3372
|
+
return matcher?.(relativePath) || matcher?.(absolutePath) || false;
|
|
3373
|
+
};
|
|
3410
3374
|
/** @internal Exact local package/tsconfig files which can change semantic resolution. */
|
|
3411
3375
|
getResolutionConfigurationFiles = () => {
|
|
3412
3376
|
const files = /* @__PURE__ */ new Set();
|
|
@@ -3421,53 +3385,26 @@ var Builder = class {
|
|
|
3421
3385
|
throw error;
|
|
3422
3386
|
}
|
|
3423
3387
|
};
|
|
3424
|
-
changedResolutionConfigurations = () => this.getResolutionConfigurationFiles().filter((file) => this.resolutionConfigurationBytes.get(file) !== this.readResolutionConfiguration(file));
|
|
3388
|
+
changedResolutionConfigurations = (knownChanges) => this.getResolutionConfigurationFiles().filter((file) => (!knownChanges || knownChanges.has(this.sourcePath(file))) && this.resolutionConfigurationBytes.get(file) !== this.readResolutionConfiguration(file));
|
|
3425
3389
|
snapshotResolutionConfigurations = () => {
|
|
3426
3390
|
const current = new Set(this.getResolutionConfigurationFiles());
|
|
3427
3391
|
for (const file of current) this.resolutionConfigurationBytes.set(file, this.readResolutionConfiguration(file));
|
|
3428
3392
|
for (const file of this.resolutionConfigurationBytes.keys()) if (!current.has(file)) this.resolutionConfigurationBytes.delete(file);
|
|
3429
3393
|
};
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
* whole TypeScript compiler. Only `registerDependency` reads the result, and only the PostCSS
|
|
3435
|
-
* plugin calls that — the CLI and the Vite plugin (which crawls separately, when it watches)
|
|
3436
|
-
* paid ~155ms of compiler load per build for a set neither of them ever read.
|
|
3437
|
-
*/
|
|
3438
|
-
setConfigDependencies(options) {
|
|
3439
|
-
this.pendingConfigCrawl = options;
|
|
3440
|
-
const cwd = options?.cwd ?? this.context?.config.cwd ?? process.cwd();
|
|
3441
|
-
for (const file of this.context?.conf.dependencies ?? []) this.configDependencies.add((0, path.resolve)(cwd, file));
|
|
3442
|
-
}
|
|
3443
|
-
/** Crawl on first read, once per `setConfigDependencies`. */
|
|
3444
|
-
crawlConfigDependencies() {
|
|
3445
|
-
const options = this.pendingConfigCrawl;
|
|
3446
|
-
if (!options) return;
|
|
3447
|
-
this.pendingConfigCrawl = void 0;
|
|
3448
|
-
const tsOptions = this.context?.conf.tsOptions ?? {
|
|
3449
|
-
baseUrl: void 0,
|
|
3450
|
-
pathMappings: []
|
|
3451
|
-
};
|
|
3452
|
-
const compilerOptions = this.context?.conf.tsconfig?.compilerOptions ?? {};
|
|
3453
|
-
const { deps } = (0, _bamboocss_config.getConfigDependencies)(options.configPath, tsOptions, compilerOptions);
|
|
3454
|
-
deps.forEach((file) => this.configDependencies.add(file));
|
|
3455
|
-
_bamboocss_logger.logger.debug("builder", "Config dependencies");
|
|
3456
|
-
_bamboocss_logger.logger.debug("builder", deps);
|
|
3457
|
-
}
|
|
3394
|
+
recordConfigDependencies = (ctx, cwd) => {
|
|
3395
|
+
const root = cwd ?? ctx.config.cwd;
|
|
3396
|
+
for (const file of (0, _bamboocss_shared.uniq)([...ctx.conf.dependencies, ...ctx.explicitDeps])) this.configDependencies.add((0, path.resolve)(root, file));
|
|
3397
|
+
};
|
|
3458
3398
|
setup = async (options = {}) => {
|
|
3459
3399
|
_bamboocss_logger.logger.debug("builder", "🚧 Setup");
|
|
3460
3400
|
const configPath = options.configPath ?? (0, _bamboocss_config.findConfig)({ cwd: options.cwd });
|
|
3461
|
-
this.setConfigDependencies({
|
|
3462
|
-
configPath,
|
|
3463
|
-
cwd: options.cwd
|
|
3464
|
-
});
|
|
3465
3401
|
if (!this.context) return this.setupContext({
|
|
3466
3402
|
configPath,
|
|
3467
3403
|
cwd: options.cwd,
|
|
3468
3404
|
dev: options.dev
|
|
3469
3405
|
});
|
|
3470
3406
|
const ctx = this.getContextOrThrow();
|
|
3407
|
+
const previousExplicitDeps = [...ctx.explicitDeps];
|
|
3471
3408
|
const previousTsconfigFiles = this.tsconfigResolutionFiles.length ? this.tsconfigResolutionFiles : ctx.diff.getResolutionConfigFiles();
|
|
3472
3409
|
/**
|
|
3473
3410
|
* Dev fast path: skip the config reload when nothing that can change the resolved config
|
|
@@ -3486,22 +3423,33 @@ var Builder = class {
|
|
|
3486
3423
|
* preset external to the config bundle — and a one-shot build keeps paying the reload
|
|
3487
3424
|
* rather than trading that recovery for a latency only watch mode feels.
|
|
3488
3425
|
*/
|
|
3489
|
-
if (options.dev && this.configGraphUnchanged(configPath)) {
|
|
3426
|
+
if (options.dev && this.configGraphUnchanged(configPath, options.sourceChanges)) {
|
|
3490
3427
|
this.affecteds = {
|
|
3491
3428
|
artifacts: /* @__PURE__ */ new Set(),
|
|
3492
3429
|
hasConfigChanged: false,
|
|
3493
3430
|
diffs: []
|
|
3494
3431
|
};
|
|
3495
3432
|
this.explicitDepsMeta = this.checkFilesChanged(this.context.explicitDeps);
|
|
3496
|
-
this.refreshSourceState(ctx, previousTsconfigFiles);
|
|
3433
|
+
this.refreshSourceState(ctx, previousTsconfigFiles, options.sourceChanges);
|
|
3497
3434
|
return;
|
|
3498
3435
|
}
|
|
3499
3436
|
this.affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
|
|
3500
3437
|
this.context = new BambooContext(conf);
|
|
3501
3438
|
});
|
|
3502
|
-
|
|
3439
|
+
const nextContext = this.getContextOrThrow();
|
|
3440
|
+
if (options.sourceChanges?.needsConfigReload) {
|
|
3441
|
+
const { cwd: configCwd, dependencies } = nextContext.config;
|
|
3442
|
+
nextContext.explicitDeps = dependencies ? nextContext.runtime.fs.glob({
|
|
3443
|
+
include: dependencies,
|
|
3444
|
+
cwd: configCwd
|
|
3445
|
+
}) : [];
|
|
3446
|
+
}
|
|
3447
|
+
this.recordConfigDependencies(nextContext, options.cwd);
|
|
3448
|
+
this.tsconfigResolutionFiles = nextContext.diff.getResolutionConfigFiles();
|
|
3503
3449
|
_bamboocss_logger.logger.debug("builder", this.affecteds);
|
|
3504
|
-
|
|
3450
|
+
const explicitDeps = options.sourceChanges?.needsConfigReload ? (0, _bamboocss_shared.uniq)([...previousExplicitDeps, ...this.context.explicitDeps]) : this.context.explicitDeps;
|
|
3451
|
+
const knownChanges = options.sourceChanges ? new Set(options.sourceChanges.files.map((file) => this.absOwner(this.context, file))) : void 0;
|
|
3452
|
+
this.explicitDepsMeta = this.checkFilesChanged(explicitDeps, knownChanges);
|
|
3505
3453
|
if (this.explicitDepsMeta.hasFilesChanged) {
|
|
3506
3454
|
this.explicitDepsMeta.changes.forEach((meta, file) => {
|
|
3507
3455
|
fileModifiedMap.set(file, meta.mtime);
|
|
@@ -3523,6 +3471,7 @@ var Builder = class {
|
|
|
3523
3471
|
this.sourceScanCache.entries.clear();
|
|
3524
3472
|
this.extractionReadsByOwner.clear();
|
|
3525
3473
|
this.recipeSurfaceByOwner.clear();
|
|
3474
|
+
this.capturedLedger = void 0;
|
|
3526
3475
|
await ctx.hooks["config:change"]?.({
|
|
3527
3476
|
config: ctx.config,
|
|
3528
3477
|
changes: this.affecteds
|
|
@@ -3530,7 +3479,7 @@ var Builder = class {
|
|
|
3530
3479
|
this.snapshotConfigGraphMtimes(configPath);
|
|
3531
3480
|
return;
|
|
3532
3481
|
}
|
|
3533
|
-
this.refreshSourceState(ctx, previousTsconfigFiles);
|
|
3482
|
+
this.refreshSourceState(ctx, previousTsconfigFiles, options.sourceChanges);
|
|
3534
3483
|
this.snapshotConfigGraphMtimes(configPath);
|
|
3535
3484
|
};
|
|
3536
3485
|
/** Every file whose content participates in the resolved config, for the dev fast path. */
|
|
@@ -3540,10 +3489,13 @@ var Builder = class {
|
|
|
3540
3489
|
...this.tsconfigResolutionFiles,
|
|
3541
3490
|
...this.context?.explicitDeps ?? []
|
|
3542
3491
|
].map(path.normalize));
|
|
3543
|
-
configGraphUnchanged = (configPath) => {
|
|
3492
|
+
configGraphUnchanged = (configPath, sourceChanges) => {
|
|
3544
3493
|
const snapshot = this.configGraphMtimes;
|
|
3545
3494
|
if (!snapshot) return false;
|
|
3495
|
+
if (sourceChanges?.needsConfigReload) return false;
|
|
3496
|
+
const changed = sourceChanges ? new Set(sourceChanges.files.map((file) => this.sourcePath((0, path.resolve)(this.context?.config.cwd ?? "", file)))) : void 0;
|
|
3546
3497
|
for (const file of this.configGraphFiles(configPath)) {
|
|
3498
|
+
if (changed?.has(this.sourcePath((0, path.resolve)(this.context?.config.cwd ?? "", file)))) return false;
|
|
3547
3499
|
const recorded = snapshot.get(file);
|
|
3548
3500
|
if (recorded === void 0 || recorded !== this.getFileMeta(file).mtime) return false;
|
|
3549
3501
|
}
|
|
@@ -3555,11 +3507,13 @@ var Builder = class {
|
|
|
3555
3507
|
this.configGraphMtimes = snapshot;
|
|
3556
3508
|
};
|
|
3557
3509
|
/** The per-pass source bookkeeping every setup ends with, config reload or not. */
|
|
3558
|
-
refreshSourceState = (ctx, previousTsconfigFiles) => {
|
|
3559
|
-
const
|
|
3510
|
+
refreshSourceState = (ctx, previousTsconfigFiles, sourceChanges) => {
|
|
3511
|
+
const knownChanges = sourceChanges ? new Set(sourceChanges.files.map((file) => this.absOwner(ctx, file))) : void 0;
|
|
3512
|
+
const changedResolutionConfigurations = this.changedResolutionConfigurations(knownChanges);
|
|
3560
3513
|
const changedResolutionSet = new Set(changedResolutionConfigurations);
|
|
3561
3514
|
const resolutionAffected = /* @__PURE__ */ new Set();
|
|
3562
|
-
const resolutionLedger = changedResolutionConfigurations.length ? ctx.project.getResolutionLedger() : void 0;
|
|
3515
|
+
const resolutionLedger = this.capturedLedger ?? (changedResolutionConfigurations.length ? ctx.project.getResolutionLedger() : void 0);
|
|
3516
|
+
this.capturedLedger = void 0;
|
|
3563
3517
|
for (const [owner, configurations] of this.resolutionConfigurationSets) if (configurations.some((file) => changedResolutionSet.has(file))) resolutionAffected.add(owner);
|
|
3564
3518
|
this.resolutionAffectedThisPass = resolutionAffected.size > 0;
|
|
3565
3519
|
if (changedResolutionConfigurations.length) {
|
|
@@ -3567,14 +3521,21 @@ var Builder = class {
|
|
|
3567
3521
|
const replaceCompilerOptions = changedResolutionConfigurations.some((file) => tsconfigCandidates.has(file));
|
|
3568
3522
|
ctx.project.refreshResolutionConfiguration(ctx.conf.tsconfig?.compilerOptions, this.tsconfigResolutionFiles, replaceCompilerOptions);
|
|
3569
3523
|
}
|
|
3570
|
-
const
|
|
3571
|
-
const
|
|
3524
|
+
const needsInventoryScan = !sourceChanges || sourceChanges.needsInventoryScan || this.sourceInventory === void 0;
|
|
3525
|
+
const inventory = needsInventoryScan ? ctx.getFiles() : [...this.sourceInventory];
|
|
3526
|
+
const allTracked = (0, _bamboocss_shared.uniq)([
|
|
3572
3527
|
...this.sourceInventory ?? inventory,
|
|
3573
3528
|
...inventory,
|
|
3574
3529
|
...this.getResolutionReadFiles()
|
|
3575
3530
|
]);
|
|
3576
|
-
|
|
3577
|
-
|
|
3531
|
+
const trackedPaths = new Set(allTracked.map((file) => this.absOwner(ctx, file)));
|
|
3532
|
+
const tracked = knownChanges && !needsInventoryScan ? [...knownChanges].filter((file) => trackedPaths.has(file)) : allTracked;
|
|
3533
|
+
this.filesMeta = tracked.length ? this.checkFilesChanged(tracked, knownChanges) : changedResolutionConfigurations.length ? {
|
|
3534
|
+
changes: /* @__PURE__ */ new Map(),
|
|
3535
|
+
hasFilesChanged: false
|
|
3536
|
+
} : void 0;
|
|
3537
|
+
for (const [file, meta] of this.filesMeta?.changes ?? []) if (!meta.isUnchanged) this.sourceScanCache.entries.delete(this.absOwner(ctx, file));
|
|
3538
|
+
if (this.filesMeta?.hasFilesChanged) {
|
|
3578
3539
|
_bamboocss_logger.logger.debug("builder", "Files changed, invalidating them");
|
|
3579
3540
|
this.invalidateChangedSources(ctx, inventory, resolutionAffected, resolutionLedger);
|
|
3580
3541
|
} else if (changedResolutionConfigurations.length) {
|
|
@@ -3697,9 +3658,7 @@ var Builder = class {
|
|
|
3697
3658
|
cwd,
|
|
3698
3659
|
dev
|
|
3699
3660
|
});
|
|
3700
|
-
|
|
3701
|
-
this.configDependencies.add((0, path.resolve)(cwd || ctx.conf.config.cwd, file));
|
|
3702
|
-
});
|
|
3661
|
+
this.recordConfigDependencies(ctx, cwd);
|
|
3703
3662
|
this.context = ctx;
|
|
3704
3663
|
this.tsconfigResolutionFiles = ctx.diff.getResolutionConfigFiles();
|
|
3705
3664
|
return ctx;
|
|
@@ -3754,11 +3713,12 @@ var Builder = class {
|
|
|
3754
3713
|
isUnchanged: fileModifiedMap.has(file) && mtime === fileModifiedMap.get(file)
|
|
3755
3714
|
};
|
|
3756
3715
|
};
|
|
3757
|
-
checkFilesChanged(files) {
|
|
3716
|
+
checkFilesChanged(files, knownChanges) {
|
|
3758
3717
|
const changes = /* @__PURE__ */ new Map();
|
|
3759
3718
|
let hasFilesChanged = false;
|
|
3760
3719
|
for (const file of files) {
|
|
3761
3720
|
const meta = this.getFileMeta(file);
|
|
3721
|
+
if (knownChanges?.has(this.sourcePath(file))) meta.isUnchanged = false;
|
|
3762
3722
|
changes.set(file, meta);
|
|
3763
3723
|
if (!meta.isUnchanged) hasFilesChanged = true;
|
|
3764
3724
|
}
|
|
@@ -3851,66 +3811,34 @@ var Builder = class {
|
|
|
3851
3811
|
for (const file of filesToExtract) this.extractFile(ctx, file);
|
|
3852
3812
|
done();
|
|
3853
3813
|
this.sourceInventory = [...files];
|
|
3854
|
-
for (const file of (0, _bamboocss_shared.uniq)([...files, ...this.getResolutionReadFiles()]))
|
|
3814
|
+
for (const file of (0, _bamboocss_shared.uniq)([...files, ...this.getResolutionReadFiles()])) {
|
|
3815
|
+
const mtime = this.filesMeta?.changes.get(file)?.mtime ?? fileModifiedMap.get(file) ?? this.getFileMeta(file).mtime;
|
|
3816
|
+
fileModifiedMap.set(file, mtime);
|
|
3817
|
+
}
|
|
3855
3818
|
this.snapshotResolutionConfigurations();
|
|
3856
3819
|
this.affectedFiles = void 0;
|
|
3857
3820
|
this.extractionOrder = void 0;
|
|
3858
3821
|
ctx.assertExtracted(files);
|
|
3859
3822
|
ctx.assertNoDeadCalls(files);
|
|
3860
3823
|
};
|
|
3861
|
-
isValidRoot = (root) => {
|
|
3862
|
-
const ctx = this.getContextOrThrow();
|
|
3863
|
-
let valid = false;
|
|
3864
|
-
root.walkAtRules("layer", (rule) => {
|
|
3865
|
-
if (ctx.isValidLayerParams(rule.params)) valid = true;
|
|
3866
|
-
});
|
|
3867
|
-
return valid;
|
|
3868
|
-
};
|
|
3869
|
-
write = (root) => {
|
|
3870
|
-
if (hasGeneratedCss(root)) {
|
|
3871
|
-
_bamboocss_logger.logger.warn("postcss", "Generated css is already present in this file, so nothing was injected. It is imported and generated here at once — keep the `@import` of `styles.css` or the `@layer` statement that the postcss plugin injects at, not both.");
|
|
3872
|
-
return;
|
|
3873
|
-
}
|
|
3874
|
-
root.append(this.toCss());
|
|
3875
|
-
};
|
|
3876
3824
|
/**
|
|
3877
3825
|
* The finished stylesheet, as a string.
|
|
3878
3826
|
*
|
|
3879
|
-
*
|
|
3880
|
-
*
|
|
3881
|
-
* through here so a build cannot depend on which integration asked for it.
|
|
3882
|
-
*
|
|
3883
|
-
* `layerParams` is the one thing that differs between them, and it is not cosmetic: the
|
|
3884
|
-
* `@layer a, b, c;` statement is what fixes layer *order*, and css layers are ordered by
|
|
3885
|
-
* first appearance otherwise. `write` leaves it out because the root it appends to is a
|
|
3886
|
-
* file that already declares it -- that declaration is what `isValidRoot` matches on. A
|
|
3887
|
-
* virtual module is the whole stylesheet and has nothing to inherit it from.
|
|
3827
|
+
* `layerParams` controls the `@layer a, b, c;` statement that fixes layer order. CSS layers
|
|
3828
|
+
* are ordered by first appearance otherwise.
|
|
3888
3829
|
*
|
|
3889
3830
|
* `extract` has to have run first: this reads the encoder rather than filling it.
|
|
3890
3831
|
*/
|
|
3891
|
-
toCss = ({ layerParams = false
|
|
3832
|
+
toCss = ({ layerParams = false } = {}) => {
|
|
3892
3833
|
const ctx = this.getContextOrThrow();
|
|
3893
3834
|
const sheet = assembleExtractedSheet(ctx, {
|
|
3894
3835
|
layerParams,
|
|
3895
|
-
includeRecipes,
|
|
3896
3836
|
sourceScanCache: this.sourceScanCache,
|
|
3897
|
-
mtimeOf: (filePath) => this.filesMeta?.changes.get(filePath)?.mtime,
|
|
3837
|
+
mtimeOf: (filePath) => this.filesMeta?.changes.get(filePath)?.mtime ?? fileModifiedMap.get(filePath),
|
|
3898
3838
|
sourceInventory: this.sourceInventory
|
|
3899
3839
|
});
|
|
3900
3840
|
return ctx.getCss(sheet);
|
|
3901
3841
|
};
|
|
3902
|
-
registerDependency = (fn) => {
|
|
3903
|
-
const ctx = this.getContextOrThrow();
|
|
3904
|
-
this.crawlConfigDependencies();
|
|
3905
|
-
for (const fileOrGlob of ctx.config.include) {
|
|
3906
|
-
const dependency = parseDependency(fileOrGlob);
|
|
3907
|
-
if (dependency) fn(dependency);
|
|
3908
|
-
}
|
|
3909
|
-
for (const file of this.configDependencies) fn({
|
|
3910
|
-
type: "dependency",
|
|
3911
|
-
file: (0, path.normalize)((0, path.resolve)(file))
|
|
3912
|
-
});
|
|
3913
|
-
};
|
|
3914
3842
|
};
|
|
3915
3843
|
//#endregion
|
|
3916
3844
|
//#region src/cpu-profile.ts
|
|
@@ -3995,11 +3923,8 @@ const cssgen = async (ctx, options) => {
|
|
|
3995
3923
|
} else {
|
|
3996
3924
|
const { files } = ctx.parseFiles();
|
|
3997
3925
|
const done = _bamboocss_logger.logger.time.info(ctx.messages.buildComplete(files.length));
|
|
3998
|
-
const sheet = assembleExtractedSheet(ctx, {
|
|
3999
|
-
|
|
4000
|
-
includeRecipes: false
|
|
4001
|
-
});
|
|
4002
|
-
if (splitting) await ctx.writeSplitCss(sheet, { includeRecipes: false });
|
|
3926
|
+
const sheet = assembleExtractedSheet(ctx, { layerParams: true });
|
|
3927
|
+
if (splitting) await ctx.writeSplitCss(sheet);
|
|
4003
3928
|
else if (outfile) {
|
|
4004
3929
|
const css = ctx.getCss(sheet);
|
|
4005
3930
|
_bamboocss_logger.logger.info("css", ctx.runtime.path.resolve(outfile));
|
|
@@ -4064,10 +3989,7 @@ async function build(ctx, artifactIds) {
|
|
|
4064
3989
|
if (ctx.config.emitTokensOnly) return _bamboocss_logger.logger.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens ✨");
|
|
4065
3990
|
const done = _bamboocss_logger.logger.time.info("");
|
|
4066
3991
|
const parsed = ctx.parseFiles();
|
|
4067
|
-
const sheet = assembleExtractedSheet(ctx, {
|
|
4068
|
-
layerParams: true,
|
|
4069
|
-
includeRecipes: false
|
|
4070
|
-
});
|
|
3992
|
+
const sheet = assembleExtractedSheet(ctx, { layerParams: true });
|
|
4071
3993
|
await ctx.writeCss(sheet);
|
|
4072
3994
|
done(ctx.messages.buildComplete(parsed.files.length));
|
|
4073
3995
|
}
|
|
@@ -4108,10 +4030,7 @@ async function generate(config, configPath) {
|
|
|
4108
4030
|
if (parsed === 0) return;
|
|
4109
4031
|
const outfile = ctx.runtime.path.join(...ctx.paths.root, "styles.css");
|
|
4110
4032
|
const done = _bamboocss_logger.logger.time.info(ctx.messages.buildComplete(parsed));
|
|
4111
|
-
const sheet = assembleExtractedSheet(ctx, {
|
|
4112
|
-
layerParams: true,
|
|
4113
|
-
includeRecipes: false
|
|
4114
|
-
});
|
|
4033
|
+
const sheet = assembleExtractedSheet(ctx, { layerParams: true });
|
|
4115
4034
|
const css = ctx.getCss(sheet);
|
|
4116
4035
|
await ctx.runtime.fs.writeFile(outfile, css);
|
|
4117
4036
|
done();
|
|
@@ -4331,7 +4250,6 @@ exports.hasUncompilableSources = hasUncompilableSources;
|
|
|
4331
4250
|
exports.isStaticCompilerActive = require_static_compiler.isStaticCompilerActive;
|
|
4332
4251
|
exports.loadConfigAndCreateContext = loadConfigAndCreateContext;
|
|
4333
4252
|
exports.markStaticCompilerActive = require_static_compiler.markStaticCompilerActive;
|
|
4334
|
-
exports.parseDependency = parseDependency;
|
|
4335
4253
|
exports.setLogStream = setLogStream;
|
|
4336
4254
|
exports.setupConfig = setupConfig;
|
|
4337
4255
|
exports.setupGitIgnore = setupGitIgnore;
|