@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/dist/index.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { isStaticCompilerActive, markStaticCompilerActive } from "./static-compiler.mjs";
|
|
2
2
|
import { Reporter, formatRecipeReport, formatTokenReport } from "@bamboocss/reporter";
|
|
3
3
|
import { colors, logger, quote } from "@bamboocss/logger";
|
|
4
|
-
import { convertTsPathsToRegexes, diffConfigs, findConfig,
|
|
4
|
+
import { convertTsPathsToRegexes, diffConfigs, findConfig, loadConfig, mergeHooks } from "@bamboocss/config";
|
|
5
5
|
import { BambooError, cssVarRefs, groupBy, truncateList, uniq } from "@bamboocss/shared";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import { appendFileSync, existsSync, readFileSync, statSync, writeFileSync } from "fs";
|
|
8
8
|
import { dirname, extname, isAbsolute, join, normalize, parse, relative, resolve, sep } from "path";
|
|
9
|
+
import picomatch from "picomatch";
|
|
9
10
|
import { pluginSvelte } from "@bamboocss/plugin-svelte";
|
|
10
11
|
import { pluginVue } from "@bamboocss/plugin-vue";
|
|
11
12
|
import { checkNamingAgreement, formatNamingDisagreement, messages, prunesPreflight } from "@bamboocss/core";
|
|
@@ -21,9 +22,6 @@ import { Node, SyntaxKind, ts } from "ts-morph";
|
|
|
21
22
|
import chokidar from "chokidar";
|
|
22
23
|
import glob from "fast-glob";
|
|
23
24
|
import fsExtra from "fs-extra";
|
|
24
|
-
import picomatch from "picomatch";
|
|
25
|
-
import isGlob from "is-glob";
|
|
26
|
-
import globParent from "glob-parent";
|
|
27
25
|
import { isMatch } from "matcher";
|
|
28
26
|
import { resolveTsPathPattern } from "@bamboocss/config/ts-path";
|
|
29
27
|
import readline from "node:readline";
|
|
@@ -2279,12 +2277,12 @@ var BambooContext = class extends Generator {
|
|
|
2279
2277
|
}]
|
|
2280
2278
|
});
|
|
2281
2279
|
};
|
|
2282
|
-
writeSplitCss = async (sheet
|
|
2280
|
+
writeSplitCss = async (sheet) => {
|
|
2283
2281
|
const { path: pathUtil, fs } = this.runtime;
|
|
2284
2282
|
const rootDir = this.paths.root;
|
|
2285
2283
|
const stylesDir = [...rootDir, "styles"];
|
|
2286
|
-
const artifacts = this.getSplitCssArtifacts(sheet
|
|
2287
|
-
const subDirs = new Set(
|
|
2284
|
+
const artifacts = this.getSplitCssArtifacts(sheet);
|
|
2285
|
+
const subDirs = new Set(artifacts.themes.map((a) => a.dir).filter(Boolean));
|
|
2288
2286
|
fs.ensureDirSync(pathUtil.join(...stylesDir));
|
|
2289
2287
|
subDirs.forEach((dir) => fs.ensureDirSync(pathUtil.join(...stylesDir, dir)));
|
|
2290
2288
|
const styleFiles = [];
|
|
@@ -2295,20 +2293,6 @@ var BambooContext = class extends Generator {
|
|
|
2295
2293
|
});
|
|
2296
2294
|
logger.info("css", pathUtil.join(...stylesDir, layer.file));
|
|
2297
2295
|
}
|
|
2298
|
-
for (const recipe of artifacts.recipes) {
|
|
2299
|
-
styleFiles.push({
|
|
2300
|
-
file: `${recipe.dir}/${recipe.file}`,
|
|
2301
|
-
code: recipe.code
|
|
2302
|
-
});
|
|
2303
|
-
logger.info("css", pathUtil.join(...stylesDir, recipe.dir, recipe.file));
|
|
2304
|
-
}
|
|
2305
|
-
if (artifacts.recipes.length) {
|
|
2306
|
-
styleFiles.push({
|
|
2307
|
-
file: "recipes.css",
|
|
2308
|
-
code: artifacts.recipesIndex
|
|
2309
|
-
});
|
|
2310
|
-
logger.info("css", pathUtil.join(...stylesDir, "recipes.css"));
|
|
2311
|
-
}
|
|
2312
2296
|
for (const theme of artifacts.themes) {
|
|
2313
2297
|
styleFiles.push({
|
|
2314
2298
|
file: `${theme.dir}/${theme.file}`,
|
|
@@ -2330,12 +2314,10 @@ var BambooContext = class extends Generator {
|
|
|
2330
2314
|
code: artifacts.index
|
|
2331
2315
|
}]
|
|
2332
2316
|
});
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
if (fs.existsSync(recipesDir)) fs.rmFileSync(recipesDir);
|
|
2338
|
-
}
|
|
2317
|
+
const recipesIndex = pathUtil.join(...stylesDir, "recipes.css");
|
|
2318
|
+
const recipesDir = pathUtil.join(...stylesDir, "recipes");
|
|
2319
|
+
if (fs.existsSync(recipesIndex)) fs.rmFileSync(recipesIndex);
|
|
2320
|
+
if (fs.existsSync(recipesDir)) fs.rmFileSync(recipesDir);
|
|
2339
2321
|
};
|
|
2340
2322
|
watchConfig = (cb, opts) => {
|
|
2341
2323
|
const { cwd, poll, exclude } = opts ?? {};
|
|
@@ -2439,44 +2421,6 @@ async function loadConfigAndCreateContext(options = {}) {
|
|
|
2439
2421
|
return new BambooContext(conf);
|
|
2440
2422
|
}
|
|
2441
2423
|
//#endregion
|
|
2442
|
-
//#region src/parse-glob.ts
|
|
2443
|
-
function parseGlob(pattern) {
|
|
2444
|
-
let glob = pattern;
|
|
2445
|
-
const base = globParent(pattern);
|
|
2446
|
-
if (base !== ".") {
|
|
2447
|
-
glob = pattern.substring(base.length);
|
|
2448
|
-
if (glob.charAt(0) === "/") glob = glob.substring(1);
|
|
2449
|
-
}
|
|
2450
|
-
if (glob.substring(0, 2) === "./") glob = glob.substring(2);
|
|
2451
|
-
if (glob.charAt(0) === "/") glob = glob.substring(1);
|
|
2452
|
-
return {
|
|
2453
|
-
base,
|
|
2454
|
-
glob
|
|
2455
|
-
};
|
|
2456
|
-
}
|
|
2457
|
-
//#endregion
|
|
2458
|
-
//#region src/parse-dependency.ts
|
|
2459
|
-
function parseDependency(fileOrGlob) {
|
|
2460
|
-
if (fileOrGlob.startsWith("!")) return null;
|
|
2461
|
-
let message = null;
|
|
2462
|
-
if (isGlob(fileOrGlob)) {
|
|
2463
|
-
const { base, glob } = parseGlob(fileOrGlob);
|
|
2464
|
-
message = {
|
|
2465
|
-
type: "dir-dependency",
|
|
2466
|
-
dir: normalize(resolve(base)),
|
|
2467
|
-
glob
|
|
2468
|
-
};
|
|
2469
|
-
} else message = {
|
|
2470
|
-
type: "dependency",
|
|
2471
|
-
file: normalize(resolve(fileOrGlob))
|
|
2472
|
-
};
|
|
2473
|
-
if (message.type === "dir-dependency" && process.env.ROLLUP_WATCH === "true") message = {
|
|
2474
|
-
type: "dependency",
|
|
2475
|
-
file: normalize(resolve(message.dir))
|
|
2476
|
-
};
|
|
2477
|
-
return message;
|
|
2478
|
-
}
|
|
2479
|
-
//#endregion
|
|
2480
2424
|
//#region src/source-snapshots.ts
|
|
2481
2425
|
/**
|
|
2482
2426
|
* Every file `include` covers, read once.
|
|
@@ -3289,22 +3233,14 @@ function collectRenderedElements(ctx) {
|
|
|
3289
3233
|
* Vite, `bamboo cssgen`, and the CLI `bamboo` command all finish here so a recipe lowered to
|
|
3290
3234
|
* atoms cannot have a different sheet depending on which integration asked for it.
|
|
3291
3235
|
*/
|
|
3292
|
-
const assembleExtractedSheet = (ctx, { layerParams = false,
|
|
3293
|
-
|
|
3294
|
-
if (!includeRecipes) ctx.encoder.atomizeObservedRecipes();
|
|
3236
|
+
const assembleExtractedSheet = (ctx, { layerParams = false, sourceScanCache, mtimeOf, sourceInventory } = {}) => {
|
|
3237
|
+
ctx.encoder.atomizeObservedRecipes();
|
|
3295
3238
|
const sheet = ctx.createSheet();
|
|
3296
|
-
if (layerParams)
|
|
3297
|
-
else {
|
|
3239
|
+
if (layerParams) {
|
|
3298
3240
|
const recipeLayer = ctx.config.layers?.recipes ?? "recipes";
|
|
3299
3241
|
sheet.layers.root.prepend(`@layer ${sheet.layers.layerNames.filter((name) => name !== recipeLayer).join(", ")};`);
|
|
3300
3242
|
}
|
|
3301
|
-
ctx.appendBaselineCss(sheet);
|
|
3302
|
-
if (!includeRecipes) {
|
|
3303
|
-
sheet.layers.recipes.removeAll();
|
|
3304
|
-
sheet.layers.recipes_base.removeAll();
|
|
3305
|
-
sheet.layers.recipes_slots.removeAll();
|
|
3306
|
-
sheet.layers.recipes_slots_base.removeAll();
|
|
3307
|
-
}
|
|
3243
|
+
ctx.appendBaselineCss(sheet, { atomizeRecipes: true });
|
|
3308
3244
|
const collectElements = prunesPreflight(ctx.config.preflight);
|
|
3309
3245
|
const pruneKeyframes = Boolean(ctx.config.prune?.keyframes);
|
|
3310
3246
|
const declaredKeyframes = pruneKeyframes ? keyframeNames(ctx) : [];
|
|
@@ -3320,24 +3256,6 @@ const assembleExtractedSheet = (ctx, { layerParams = false, includeRecipes = fal
|
|
|
3320
3256
|
//#endregion
|
|
3321
3257
|
//#region src/builder.ts
|
|
3322
3258
|
const fileModifiedMap = /* @__PURE__ */ new Map();
|
|
3323
|
-
/**
|
|
3324
|
-
* The declaration that says generated css is already present in a root.
|
|
3325
|
-
*
|
|
3326
|
-
* `generateGlobalCss` emits it unconditionally and `appendBaselineCss` always reaches that
|
|
3327
|
-
* artifact, so anything carrying it holds a copy of the sheet however it got there — written
|
|
3328
|
-
* by `write` on an earlier pass, or inlined from `styles.css` by `postcss-import`.
|
|
3329
|
-
*
|
|
3330
|
-
* A declaration rather than a comment because it has to survive the css being minified
|
|
3331
|
-
* between the copy landing and this check running, which a comment does not.
|
|
3332
|
-
*/
|
|
3333
|
-
const GENERATED_SENTINEL = "--made-with-bamboo";
|
|
3334
|
-
function hasGeneratedCss(root) {
|
|
3335
|
-
let found = false;
|
|
3336
|
-
root.walkDecls(GENERATED_SENTINEL, () => {
|
|
3337
|
-
found = true;
|
|
3338
|
-
});
|
|
3339
|
-
return found;
|
|
3340
|
-
}
|
|
3341
3259
|
var Builder = class {
|
|
3342
3260
|
/**
|
|
3343
3261
|
* The current bamboo context
|
|
@@ -3348,7 +3266,6 @@ var Builder = class {
|
|
|
3348
3266
|
explicitDepsMeta;
|
|
3349
3267
|
affecteds;
|
|
3350
3268
|
configDependencies = /* @__PURE__ */ new Set();
|
|
3351
|
-
pendingConfigCrawl;
|
|
3352
3269
|
/** Last complete included inventory, including members which have since been deleted. */
|
|
3353
3270
|
sourceInventory;
|
|
3354
3271
|
/** Existing included owners selected by the last resolution-ledger invalidation pass. */
|
|
@@ -3383,6 +3300,35 @@ var Builder = class {
|
|
|
3383
3300
|
resolutionAffectedThisPass = false;
|
|
3384
3301
|
/** Per-pass digests of re-read values, so N dependents of one edit digest each value once. */
|
|
3385
3302
|
readDigestMemo = /* @__PURE__ */ new Map();
|
|
3303
|
+
/** Resolution ledger as it stood before this pass's first physical source mutation. */
|
|
3304
|
+
capturedLedger;
|
|
3305
|
+
/**
|
|
3306
|
+
* Reload one edited source, keeping the closure the next extraction pass has to select.
|
|
3307
|
+
*
|
|
3308
|
+
* An integration which shares this context has to refresh an edited module before anything
|
|
3309
|
+
* folds against it — a consumer is transformed before the module it imports, so the fold
|
|
3310
|
+
* would otherwise bake in the previous contents. Doing that through the Project directly
|
|
3311
|
+
* loses the graph the rebuild needs: reloading retracts the file's own forward edges, and
|
|
3312
|
+
* `invalidateChangedSources` reads them afterwards to find its dependents. So the mutation
|
|
3313
|
+
* belongs here, behind a snapshot taken before the first of them.
|
|
3314
|
+
*
|
|
3315
|
+
* Once per pass, not once per file: the first mutation is the boundary, and every later one
|
|
3316
|
+
* in the same event is already described by that snapshot. `refreshSourceState` consumes it.
|
|
3317
|
+
*/
|
|
3318
|
+
reloadSource = (filePath) => {
|
|
3319
|
+
const ctx = this.getContextOrThrow();
|
|
3320
|
+
this.captureResolutionLedger(ctx);
|
|
3321
|
+
return ctx.project.reloadSourceFile(filePath);
|
|
3322
|
+
};
|
|
3323
|
+
/** The deletion half of `reloadSource`, with the same snapshot obligation. */
|
|
3324
|
+
removeSource = (filePath) => {
|
|
3325
|
+
const ctx = this.getContextOrThrow();
|
|
3326
|
+
this.captureResolutionLedger(ctx);
|
|
3327
|
+
return ctx.project.removeSourceFile(filePath);
|
|
3328
|
+
};
|
|
3329
|
+
captureResolutionLedger = (ctx) => {
|
|
3330
|
+
this.capturedLedger ??= ctx.project.getResolutionLedger();
|
|
3331
|
+
};
|
|
3386
3332
|
/** @internal Current and missing resolver paths which can change the stylesheet. */
|
|
3387
3333
|
getResolutionReadFiles = () => {
|
|
3388
3334
|
const files = /* @__PURE__ */ new Set();
|
|
@@ -3393,6 +3339,26 @@ var Builder = class {
|
|
|
3393
3339
|
]) for (const dependencies of readSets.values()) for (const dependency of dependencies) files.add(dependency);
|
|
3394
3340
|
return Object.freeze([...files].sort());
|
|
3395
3341
|
};
|
|
3342
|
+
/** @internal The inventory reconciled by the most recent extraction pass. */
|
|
3343
|
+
getSourceFiles = () => Object.freeze([...this.sourceInventory ?? []]);
|
|
3344
|
+
/** @internal Whether creating this path can change source or explicit-dependency membership. */
|
|
3345
|
+
isPotentialSourceFile = (filePath) => {
|
|
3346
|
+
const ctx = this.getContextOrThrow();
|
|
3347
|
+
const absolutePath = this.absOwner(ctx, filePath);
|
|
3348
|
+
const relativePath = this.sourcePath(ctx.runtime.path.relative(ctx.config.cwd, absolutePath));
|
|
3349
|
+
const sourcePatterns = ctx.config.include ?? [];
|
|
3350
|
+
const sourceMatcher = sourcePatterns.length ? picomatch(sourcePatterns, { ignore: globIgnore(ctx.config.exclude) }) : void 0;
|
|
3351
|
+
return sourceMatcher?.(relativePath) || sourceMatcher?.(absolutePath) || false;
|
|
3352
|
+
};
|
|
3353
|
+
/** @internal Whether creating or deleting this path can change a `dependencies` glob. */
|
|
3354
|
+
isPotentialConfigDependency = (filePath) => {
|
|
3355
|
+
const ctx = this.getContextOrThrow();
|
|
3356
|
+
const absolutePath = this.absOwner(ctx, filePath);
|
|
3357
|
+
const relativePath = this.sourcePath(ctx.runtime.path.relative(ctx.config.cwd, absolutePath));
|
|
3358
|
+
const patterns = ctx.config.dependencies ?? [];
|
|
3359
|
+
const matcher = patterns.length ? picomatch(patterns) : void 0;
|
|
3360
|
+
return matcher?.(relativePath) || matcher?.(absolutePath) || false;
|
|
3361
|
+
};
|
|
3396
3362
|
/** @internal Exact local package/tsconfig files which can change semantic resolution. */
|
|
3397
3363
|
getResolutionConfigurationFiles = () => {
|
|
3398
3364
|
const files = /* @__PURE__ */ new Set();
|
|
@@ -3407,53 +3373,26 @@ var Builder = class {
|
|
|
3407
3373
|
throw error;
|
|
3408
3374
|
}
|
|
3409
3375
|
};
|
|
3410
|
-
changedResolutionConfigurations = () => this.getResolutionConfigurationFiles().filter((file) => this.resolutionConfigurationBytes.get(file) !== this.readResolutionConfiguration(file));
|
|
3376
|
+
changedResolutionConfigurations = (knownChanges) => this.getResolutionConfigurationFiles().filter((file) => (!knownChanges || knownChanges.has(this.sourcePath(file))) && this.resolutionConfigurationBytes.get(file) !== this.readResolutionConfiguration(file));
|
|
3411
3377
|
snapshotResolutionConfigurations = () => {
|
|
3412
3378
|
const current = new Set(this.getResolutionConfigurationFiles());
|
|
3413
3379
|
for (const file of current) this.resolutionConfigurationBytes.set(file, this.readResolutionConfiguration(file));
|
|
3414
3380
|
for (const file of this.resolutionConfigurationBytes.keys()) if (!current.has(file)) this.resolutionConfigurationBytes.delete(file);
|
|
3415
3381
|
};
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
* whole TypeScript compiler. Only `registerDependency` reads the result, and only the PostCSS
|
|
3421
|
-
* plugin calls that — the CLI and the Vite plugin (which crawls separately, when it watches)
|
|
3422
|
-
* paid ~155ms of compiler load per build for a set neither of them ever read.
|
|
3423
|
-
*/
|
|
3424
|
-
setConfigDependencies(options) {
|
|
3425
|
-
this.pendingConfigCrawl = options;
|
|
3426
|
-
const cwd = options?.cwd ?? this.context?.config.cwd ?? process.cwd();
|
|
3427
|
-
for (const file of this.context?.conf.dependencies ?? []) this.configDependencies.add(resolve(cwd, file));
|
|
3428
|
-
}
|
|
3429
|
-
/** Crawl on first read, once per `setConfigDependencies`. */
|
|
3430
|
-
crawlConfigDependencies() {
|
|
3431
|
-
const options = this.pendingConfigCrawl;
|
|
3432
|
-
if (!options) return;
|
|
3433
|
-
this.pendingConfigCrawl = void 0;
|
|
3434
|
-
const tsOptions = this.context?.conf.tsOptions ?? {
|
|
3435
|
-
baseUrl: void 0,
|
|
3436
|
-
pathMappings: []
|
|
3437
|
-
};
|
|
3438
|
-
const compilerOptions = this.context?.conf.tsconfig?.compilerOptions ?? {};
|
|
3439
|
-
const { deps } = getConfigDependencies(options.configPath, tsOptions, compilerOptions);
|
|
3440
|
-
deps.forEach((file) => this.configDependencies.add(file));
|
|
3441
|
-
logger.debug("builder", "Config dependencies");
|
|
3442
|
-
logger.debug("builder", deps);
|
|
3443
|
-
}
|
|
3382
|
+
recordConfigDependencies = (ctx, cwd) => {
|
|
3383
|
+
const root = cwd ?? ctx.config.cwd;
|
|
3384
|
+
for (const file of uniq([...ctx.conf.dependencies, ...ctx.explicitDeps])) this.configDependencies.add(resolve(root, file));
|
|
3385
|
+
};
|
|
3444
3386
|
setup = async (options = {}) => {
|
|
3445
3387
|
logger.debug("builder", "🚧 Setup");
|
|
3446
3388
|
const configPath = options.configPath ?? findConfig({ cwd: options.cwd });
|
|
3447
|
-
this.setConfigDependencies({
|
|
3448
|
-
configPath,
|
|
3449
|
-
cwd: options.cwd
|
|
3450
|
-
});
|
|
3451
3389
|
if (!this.context) return this.setupContext({
|
|
3452
3390
|
configPath,
|
|
3453
3391
|
cwd: options.cwd,
|
|
3454
3392
|
dev: options.dev
|
|
3455
3393
|
});
|
|
3456
3394
|
const ctx = this.getContextOrThrow();
|
|
3395
|
+
const previousExplicitDeps = [...ctx.explicitDeps];
|
|
3457
3396
|
const previousTsconfigFiles = this.tsconfigResolutionFiles.length ? this.tsconfigResolutionFiles : ctx.diff.getResolutionConfigFiles();
|
|
3458
3397
|
/**
|
|
3459
3398
|
* Dev fast path: skip the config reload when nothing that can change the resolved config
|
|
@@ -3472,22 +3411,33 @@ var Builder = class {
|
|
|
3472
3411
|
* preset external to the config bundle — and a one-shot build keeps paying the reload
|
|
3473
3412
|
* rather than trading that recovery for a latency only watch mode feels.
|
|
3474
3413
|
*/
|
|
3475
|
-
if (options.dev && this.configGraphUnchanged(configPath)) {
|
|
3414
|
+
if (options.dev && this.configGraphUnchanged(configPath, options.sourceChanges)) {
|
|
3476
3415
|
this.affecteds = {
|
|
3477
3416
|
artifacts: /* @__PURE__ */ new Set(),
|
|
3478
3417
|
hasConfigChanged: false,
|
|
3479
3418
|
diffs: []
|
|
3480
3419
|
};
|
|
3481
3420
|
this.explicitDepsMeta = this.checkFilesChanged(this.context.explicitDeps);
|
|
3482
|
-
this.refreshSourceState(ctx, previousTsconfigFiles);
|
|
3421
|
+
this.refreshSourceState(ctx, previousTsconfigFiles, options.sourceChanges);
|
|
3483
3422
|
return;
|
|
3484
3423
|
}
|
|
3485
3424
|
this.affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
|
|
3486
3425
|
this.context = new BambooContext(conf);
|
|
3487
3426
|
});
|
|
3488
|
-
|
|
3427
|
+
const nextContext = this.getContextOrThrow();
|
|
3428
|
+
if (options.sourceChanges?.needsConfigReload) {
|
|
3429
|
+
const { cwd: configCwd, dependencies } = nextContext.config;
|
|
3430
|
+
nextContext.explicitDeps = dependencies ? nextContext.runtime.fs.glob({
|
|
3431
|
+
include: dependencies,
|
|
3432
|
+
cwd: configCwd
|
|
3433
|
+
}) : [];
|
|
3434
|
+
}
|
|
3435
|
+
this.recordConfigDependencies(nextContext, options.cwd);
|
|
3436
|
+
this.tsconfigResolutionFiles = nextContext.diff.getResolutionConfigFiles();
|
|
3489
3437
|
logger.debug("builder", this.affecteds);
|
|
3490
|
-
|
|
3438
|
+
const explicitDeps = options.sourceChanges?.needsConfigReload ? uniq([...previousExplicitDeps, ...this.context.explicitDeps]) : this.context.explicitDeps;
|
|
3439
|
+
const knownChanges = options.sourceChanges ? new Set(options.sourceChanges.files.map((file) => this.absOwner(this.context, file))) : void 0;
|
|
3440
|
+
this.explicitDepsMeta = this.checkFilesChanged(explicitDeps, knownChanges);
|
|
3491
3441
|
if (this.explicitDepsMeta.hasFilesChanged) {
|
|
3492
3442
|
this.explicitDepsMeta.changes.forEach((meta, file) => {
|
|
3493
3443
|
fileModifiedMap.set(file, meta.mtime);
|
|
@@ -3509,6 +3459,7 @@ var Builder = class {
|
|
|
3509
3459
|
this.sourceScanCache.entries.clear();
|
|
3510
3460
|
this.extractionReadsByOwner.clear();
|
|
3511
3461
|
this.recipeSurfaceByOwner.clear();
|
|
3462
|
+
this.capturedLedger = void 0;
|
|
3512
3463
|
await ctx.hooks["config:change"]?.({
|
|
3513
3464
|
config: ctx.config,
|
|
3514
3465
|
changes: this.affecteds
|
|
@@ -3516,7 +3467,7 @@ var Builder = class {
|
|
|
3516
3467
|
this.snapshotConfigGraphMtimes(configPath);
|
|
3517
3468
|
return;
|
|
3518
3469
|
}
|
|
3519
|
-
this.refreshSourceState(ctx, previousTsconfigFiles);
|
|
3470
|
+
this.refreshSourceState(ctx, previousTsconfigFiles, options.sourceChanges);
|
|
3520
3471
|
this.snapshotConfigGraphMtimes(configPath);
|
|
3521
3472
|
};
|
|
3522
3473
|
/** Every file whose content participates in the resolved config, for the dev fast path. */
|
|
@@ -3526,10 +3477,13 @@ var Builder = class {
|
|
|
3526
3477
|
...this.tsconfigResolutionFiles,
|
|
3527
3478
|
...this.context?.explicitDeps ?? []
|
|
3528
3479
|
].map(normalize));
|
|
3529
|
-
configGraphUnchanged = (configPath) => {
|
|
3480
|
+
configGraphUnchanged = (configPath, sourceChanges) => {
|
|
3530
3481
|
const snapshot = this.configGraphMtimes;
|
|
3531
3482
|
if (!snapshot) return false;
|
|
3483
|
+
if (sourceChanges?.needsConfigReload) return false;
|
|
3484
|
+
const changed = sourceChanges ? new Set(sourceChanges.files.map((file) => this.sourcePath(resolve(this.context?.config.cwd ?? "", file)))) : void 0;
|
|
3532
3485
|
for (const file of this.configGraphFiles(configPath)) {
|
|
3486
|
+
if (changed?.has(this.sourcePath(resolve(this.context?.config.cwd ?? "", file)))) return false;
|
|
3533
3487
|
const recorded = snapshot.get(file);
|
|
3534
3488
|
if (recorded === void 0 || recorded !== this.getFileMeta(file).mtime) return false;
|
|
3535
3489
|
}
|
|
@@ -3541,11 +3495,13 @@ var Builder = class {
|
|
|
3541
3495
|
this.configGraphMtimes = snapshot;
|
|
3542
3496
|
};
|
|
3543
3497
|
/** The per-pass source bookkeeping every setup ends with, config reload or not. */
|
|
3544
|
-
refreshSourceState = (ctx, previousTsconfigFiles) => {
|
|
3545
|
-
const
|
|
3498
|
+
refreshSourceState = (ctx, previousTsconfigFiles, sourceChanges) => {
|
|
3499
|
+
const knownChanges = sourceChanges ? new Set(sourceChanges.files.map((file) => this.absOwner(ctx, file))) : void 0;
|
|
3500
|
+
const changedResolutionConfigurations = this.changedResolutionConfigurations(knownChanges);
|
|
3546
3501
|
const changedResolutionSet = new Set(changedResolutionConfigurations);
|
|
3547
3502
|
const resolutionAffected = /* @__PURE__ */ new Set();
|
|
3548
|
-
const resolutionLedger = changedResolutionConfigurations.length ? ctx.project.getResolutionLedger() : void 0;
|
|
3503
|
+
const resolutionLedger = this.capturedLedger ?? (changedResolutionConfigurations.length ? ctx.project.getResolutionLedger() : void 0);
|
|
3504
|
+
this.capturedLedger = void 0;
|
|
3549
3505
|
for (const [owner, configurations] of this.resolutionConfigurationSets) if (configurations.some((file) => changedResolutionSet.has(file))) resolutionAffected.add(owner);
|
|
3550
3506
|
this.resolutionAffectedThisPass = resolutionAffected.size > 0;
|
|
3551
3507
|
if (changedResolutionConfigurations.length) {
|
|
@@ -3553,14 +3509,21 @@ var Builder = class {
|
|
|
3553
3509
|
const replaceCompilerOptions = changedResolutionConfigurations.some((file) => tsconfigCandidates.has(file));
|
|
3554
3510
|
ctx.project.refreshResolutionConfiguration(ctx.conf.tsconfig?.compilerOptions, this.tsconfigResolutionFiles, replaceCompilerOptions);
|
|
3555
3511
|
}
|
|
3556
|
-
const
|
|
3557
|
-
const
|
|
3512
|
+
const needsInventoryScan = !sourceChanges || sourceChanges.needsInventoryScan || this.sourceInventory === void 0;
|
|
3513
|
+
const inventory = needsInventoryScan ? ctx.getFiles() : [...this.sourceInventory];
|
|
3514
|
+
const allTracked = uniq([
|
|
3558
3515
|
...this.sourceInventory ?? inventory,
|
|
3559
3516
|
...inventory,
|
|
3560
3517
|
...this.getResolutionReadFiles()
|
|
3561
3518
|
]);
|
|
3562
|
-
|
|
3563
|
-
|
|
3519
|
+
const trackedPaths = new Set(allTracked.map((file) => this.absOwner(ctx, file)));
|
|
3520
|
+
const tracked = knownChanges && !needsInventoryScan ? [...knownChanges].filter((file) => trackedPaths.has(file)) : allTracked;
|
|
3521
|
+
this.filesMeta = tracked.length ? this.checkFilesChanged(tracked, knownChanges) : changedResolutionConfigurations.length ? {
|
|
3522
|
+
changes: /* @__PURE__ */ new Map(),
|
|
3523
|
+
hasFilesChanged: false
|
|
3524
|
+
} : void 0;
|
|
3525
|
+
for (const [file, meta] of this.filesMeta?.changes ?? []) if (!meta.isUnchanged) this.sourceScanCache.entries.delete(this.absOwner(ctx, file));
|
|
3526
|
+
if (this.filesMeta?.hasFilesChanged) {
|
|
3564
3527
|
logger.debug("builder", "Files changed, invalidating them");
|
|
3565
3528
|
this.invalidateChangedSources(ctx, inventory, resolutionAffected, resolutionLedger);
|
|
3566
3529
|
} else if (changedResolutionConfigurations.length) {
|
|
@@ -3683,9 +3646,7 @@ var Builder = class {
|
|
|
3683
3646
|
cwd,
|
|
3684
3647
|
dev
|
|
3685
3648
|
});
|
|
3686
|
-
|
|
3687
|
-
this.configDependencies.add(resolve(cwd || ctx.conf.config.cwd, file));
|
|
3688
|
-
});
|
|
3649
|
+
this.recordConfigDependencies(ctx, cwd);
|
|
3689
3650
|
this.context = ctx;
|
|
3690
3651
|
this.tsconfigResolutionFiles = ctx.diff.getResolutionConfigFiles();
|
|
3691
3652
|
return ctx;
|
|
@@ -3740,11 +3701,12 @@ var Builder = class {
|
|
|
3740
3701
|
isUnchanged: fileModifiedMap.has(file) && mtime === fileModifiedMap.get(file)
|
|
3741
3702
|
};
|
|
3742
3703
|
};
|
|
3743
|
-
checkFilesChanged(files) {
|
|
3704
|
+
checkFilesChanged(files, knownChanges) {
|
|
3744
3705
|
const changes = /* @__PURE__ */ new Map();
|
|
3745
3706
|
let hasFilesChanged = false;
|
|
3746
3707
|
for (const file of files) {
|
|
3747
3708
|
const meta = this.getFileMeta(file);
|
|
3709
|
+
if (knownChanges?.has(this.sourcePath(file))) meta.isUnchanged = false;
|
|
3748
3710
|
changes.set(file, meta);
|
|
3749
3711
|
if (!meta.isUnchanged) hasFilesChanged = true;
|
|
3750
3712
|
}
|
|
@@ -3837,66 +3799,34 @@ var Builder = class {
|
|
|
3837
3799
|
for (const file of filesToExtract) this.extractFile(ctx, file);
|
|
3838
3800
|
done();
|
|
3839
3801
|
this.sourceInventory = [...files];
|
|
3840
|
-
for (const file of uniq([...files, ...this.getResolutionReadFiles()]))
|
|
3802
|
+
for (const file of uniq([...files, ...this.getResolutionReadFiles()])) {
|
|
3803
|
+
const mtime = this.filesMeta?.changes.get(file)?.mtime ?? fileModifiedMap.get(file) ?? this.getFileMeta(file).mtime;
|
|
3804
|
+
fileModifiedMap.set(file, mtime);
|
|
3805
|
+
}
|
|
3841
3806
|
this.snapshotResolutionConfigurations();
|
|
3842
3807
|
this.affectedFiles = void 0;
|
|
3843
3808
|
this.extractionOrder = void 0;
|
|
3844
3809
|
ctx.assertExtracted(files);
|
|
3845
3810
|
ctx.assertNoDeadCalls(files);
|
|
3846
3811
|
};
|
|
3847
|
-
isValidRoot = (root) => {
|
|
3848
|
-
const ctx = this.getContextOrThrow();
|
|
3849
|
-
let valid = false;
|
|
3850
|
-
root.walkAtRules("layer", (rule) => {
|
|
3851
|
-
if (ctx.isValidLayerParams(rule.params)) valid = true;
|
|
3852
|
-
});
|
|
3853
|
-
return valid;
|
|
3854
|
-
};
|
|
3855
|
-
write = (root) => {
|
|
3856
|
-
if (hasGeneratedCss(root)) {
|
|
3857
|
-
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.");
|
|
3858
|
-
return;
|
|
3859
|
-
}
|
|
3860
|
-
root.append(this.toCss());
|
|
3861
|
-
};
|
|
3862
3812
|
/**
|
|
3863
3813
|
* The finished stylesheet, as a string.
|
|
3864
3814
|
*
|
|
3865
|
-
*
|
|
3866
|
-
*
|
|
3867
|
-
* through here so a build cannot depend on which integration asked for it.
|
|
3868
|
-
*
|
|
3869
|
-
* `layerParams` is the one thing that differs between them, and it is not cosmetic: the
|
|
3870
|
-
* `@layer a, b, c;` statement is what fixes layer *order*, and css layers are ordered by
|
|
3871
|
-
* first appearance otherwise. `write` leaves it out because the root it appends to is a
|
|
3872
|
-
* file that already declares it -- that declaration is what `isValidRoot` matches on. A
|
|
3873
|
-
* virtual module is the whole stylesheet and has nothing to inherit it from.
|
|
3815
|
+
* `layerParams` controls the `@layer a, b, c;` statement that fixes layer order. CSS layers
|
|
3816
|
+
* are ordered by first appearance otherwise.
|
|
3874
3817
|
*
|
|
3875
3818
|
* `extract` has to have run first: this reads the encoder rather than filling it.
|
|
3876
3819
|
*/
|
|
3877
|
-
toCss = ({ layerParams = false
|
|
3820
|
+
toCss = ({ layerParams = false } = {}) => {
|
|
3878
3821
|
const ctx = this.getContextOrThrow();
|
|
3879
3822
|
const sheet = assembleExtractedSheet(ctx, {
|
|
3880
3823
|
layerParams,
|
|
3881
|
-
includeRecipes,
|
|
3882
3824
|
sourceScanCache: this.sourceScanCache,
|
|
3883
|
-
mtimeOf: (filePath) => this.filesMeta?.changes.get(filePath)?.mtime,
|
|
3825
|
+
mtimeOf: (filePath) => this.filesMeta?.changes.get(filePath)?.mtime ?? fileModifiedMap.get(filePath),
|
|
3884
3826
|
sourceInventory: this.sourceInventory
|
|
3885
3827
|
});
|
|
3886
3828
|
return ctx.getCss(sheet);
|
|
3887
3829
|
};
|
|
3888
|
-
registerDependency = (fn) => {
|
|
3889
|
-
const ctx = this.getContextOrThrow();
|
|
3890
|
-
this.crawlConfigDependencies();
|
|
3891
|
-
for (const fileOrGlob of ctx.config.include) {
|
|
3892
|
-
const dependency = parseDependency(fileOrGlob);
|
|
3893
|
-
if (dependency) fn(dependency);
|
|
3894
|
-
}
|
|
3895
|
-
for (const file of this.configDependencies) fn({
|
|
3896
|
-
type: "dependency",
|
|
3897
|
-
file: normalize(resolve(file))
|
|
3898
|
-
});
|
|
3899
|
-
};
|
|
3900
3830
|
};
|
|
3901
3831
|
//#endregion
|
|
3902
3832
|
//#region src/cpu-profile.ts
|
|
@@ -3981,11 +3911,8 @@ const cssgen = async (ctx, options) => {
|
|
|
3981
3911
|
} else {
|
|
3982
3912
|
const { files } = ctx.parseFiles();
|
|
3983
3913
|
const done = logger.time.info(ctx.messages.buildComplete(files.length));
|
|
3984
|
-
const sheet = assembleExtractedSheet(ctx, {
|
|
3985
|
-
|
|
3986
|
-
includeRecipes: false
|
|
3987
|
-
});
|
|
3988
|
-
if (splitting) await ctx.writeSplitCss(sheet, { includeRecipes: false });
|
|
3914
|
+
const sheet = assembleExtractedSheet(ctx, { layerParams: true });
|
|
3915
|
+
if (splitting) await ctx.writeSplitCss(sheet);
|
|
3989
3916
|
else if (outfile) {
|
|
3990
3917
|
const css = ctx.getCss(sheet);
|
|
3991
3918
|
logger.info("css", ctx.runtime.path.resolve(outfile));
|
|
@@ -4050,10 +3977,7 @@ async function build(ctx, artifactIds) {
|
|
|
4050
3977
|
if (ctx.config.emitTokensOnly) return logger.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens ✨");
|
|
4051
3978
|
const done = logger.time.info("");
|
|
4052
3979
|
const parsed = ctx.parseFiles();
|
|
4053
|
-
const sheet = assembleExtractedSheet(ctx, {
|
|
4054
|
-
layerParams: true,
|
|
4055
|
-
includeRecipes: false
|
|
4056
|
-
});
|
|
3980
|
+
const sheet = assembleExtractedSheet(ctx, { layerParams: true });
|
|
4057
3981
|
await ctx.writeCss(sheet);
|
|
4058
3982
|
done(ctx.messages.buildComplete(parsed.files.length));
|
|
4059
3983
|
}
|
|
@@ -4094,10 +4018,7 @@ async function generate(config, configPath) {
|
|
|
4094
4018
|
if (parsed === 0) return;
|
|
4095
4019
|
const outfile = ctx.runtime.path.join(...ctx.paths.root, "styles.css");
|
|
4096
4020
|
const done = logger.time.info(ctx.messages.buildComplete(parsed));
|
|
4097
|
-
const sheet = assembleExtractedSheet(ctx, {
|
|
4098
|
-
layerParams: true,
|
|
4099
|
-
includeRecipes: false
|
|
4100
|
-
});
|
|
4021
|
+
const sheet = assembleExtractedSheet(ctx, { layerParams: true });
|
|
4101
4022
|
const css = ctx.getCss(sheet);
|
|
4102
4023
|
await ctx.runtime.fs.writeFile(outfile, css);
|
|
4103
4024
|
done();
|
|
@@ -4298,4 +4219,4 @@ const hasUncompilableSources = (options) => {
|
|
|
4298
4219
|
}
|
|
4299
4220
|
};
|
|
4300
4221
|
//#endregion
|
|
4301
|
-
export { BambooContext, Builder, analyze, buildInfo, codegen, cssgen, debug, findViteConfig, generate, generatePackageExports, hasUncompilableSources, isStaticCompilerActive, loadConfigAndCreateContext, markStaticCompilerActive,
|
|
4222
|
+
export { BambooContext, Builder, analyze, buildInfo, codegen, cssgen, debug, findViteConfig, generate, generatePackageExports, hasUncompilableSources, isStaticCompilerActive, loadConfigAndCreateContext, markStaticCompilerActive, setLogStream, setupConfig, setupGitIgnore, spec, startProfiling };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/node",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.48.1",
|
|
4
4
|
"description": "The core css bamboo library",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,8 +50,6 @@
|
|
|
50
50
|
"fast-glob": "3.3.3",
|
|
51
51
|
"fs-extra": "11.3.2",
|
|
52
52
|
"get-tsconfig": "^4.13.0",
|
|
53
|
-
"glob-parent": "6.0.2",
|
|
54
|
-
"is-glob": "4.0.3",
|
|
55
53
|
"lodash.merge": "4.6.2",
|
|
56
54
|
"look-it-up": "2.1.0",
|
|
57
55
|
"matcher": "6.0.0",
|
|
@@ -62,25 +60,22 @@
|
|
|
62
60
|
"picomatch": "4.0.5",
|
|
63
61
|
"pkg-types": "2.3.0",
|
|
64
62
|
"pluralize": "8.0.0",
|
|
65
|
-
"postcss": "8.5.26",
|
|
66
63
|
"ts-morph": "28.0.0",
|
|
67
64
|
"ts-pattern": "5.9.0",
|
|
68
|
-
"@bamboocss/config": "1.
|
|
69
|
-
"@bamboocss/core": "1.
|
|
70
|
-
"@bamboocss/generator": "1.
|
|
71
|
-
"@bamboocss/logger": "1.
|
|
72
|
-
"@bamboocss/parser": "1.
|
|
73
|
-
"@bamboocss/plugin-svelte": "1.
|
|
74
|
-
"@bamboocss/plugin-vue": "1.
|
|
75
|
-
"@bamboocss/reporter": "1.
|
|
76
|
-
"@bamboocss/shared": "1.
|
|
77
|
-
"@bamboocss/token-dictionary": "1.
|
|
78
|
-
"@bamboocss/types": "1.
|
|
65
|
+
"@bamboocss/config": "1.48.1",
|
|
66
|
+
"@bamboocss/core": "1.48.1",
|
|
67
|
+
"@bamboocss/generator": "1.48.1",
|
|
68
|
+
"@bamboocss/logger": "1.48.1",
|
|
69
|
+
"@bamboocss/parser": "1.48.1",
|
|
70
|
+
"@bamboocss/plugin-svelte": "1.48.1",
|
|
71
|
+
"@bamboocss/plugin-vue": "1.48.1",
|
|
72
|
+
"@bamboocss/reporter": "1.48.1",
|
|
73
|
+
"@bamboocss/shared": "1.48.1",
|
|
74
|
+
"@bamboocss/token-dictionary": "1.48.1",
|
|
75
|
+
"@bamboocss/types": "1.48.1"
|
|
79
76
|
},
|
|
80
77
|
"devDependencies": {
|
|
81
78
|
"@types/fs-extra": "11.0.4",
|
|
82
|
-
"@types/glob-parent": "5.1.3",
|
|
83
|
-
"@types/is-glob": "4.0.4",
|
|
84
79
|
"@types/picomatch": "4.0.2",
|
|
85
80
|
"boxen": "8.0.1"
|
|
86
81
|
},
|