@bamboocss/node 1.46.3 → 1.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -8
- package/dist/index.cjs +137 -285
- package/dist/index.d.cts +24 -33
- package/dist/index.d.mts +24 -33
- package/dist/index.mjs +140 -284
- package/package.json +12 -17
package/dist/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
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,
|
|
5
|
-
import { checkNamingAgreement, formatNamingDisagreement, messages, prunesPreflight } from "@bamboocss/core";
|
|
4
|
+
import { convertTsPathsToRegexes, diffConfigs, findConfig, loadConfig, mergeHooks } from "@bamboocss/config";
|
|
6
5
|
import { BambooError, cssVarRefs, groupBy, truncateList, uniq } from "@bamboocss/shared";
|
|
7
6
|
import { createHash } from "node:crypto";
|
|
8
7
|
import { appendFileSync, existsSync, readFileSync, statSync, writeFileSync } from "fs";
|
|
9
|
-
import {
|
|
8
|
+
import { dirname, extname, isAbsolute, join, normalize, parse, relative, resolve, sep } from "path";
|
|
10
9
|
import { pluginSvelte } from "@bamboocss/plugin-svelte";
|
|
11
10
|
import { pluginVue } from "@bamboocss/plugin-vue";
|
|
11
|
+
import { checkNamingAgreement, formatNamingDisagreement, messages, prunesPreflight } from "@bamboocss/core";
|
|
12
12
|
import { Generator, generatePackageExports } from "@bamboocss/generator";
|
|
13
13
|
import { Project } from "@bamboocss/parser";
|
|
14
14
|
import { debounce } from "perfect-debounce";
|
|
@@ -22,8 +22,6 @@ import chokidar from "chokidar";
|
|
|
22
22
|
import glob from "fast-glob";
|
|
23
23
|
import fsExtra from "fs-extra";
|
|
24
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";
|
|
@@ -2284,7 +2282,7 @@ var BambooContext = class extends Generator {
|
|
|
2284
2282
|
const rootDir = this.paths.root;
|
|
2285
2283
|
const stylesDir = [...rootDir, "styles"];
|
|
2286
2284
|
const artifacts = this.getSplitCssArtifacts(sheet);
|
|
2287
|
-
const subDirs = new Set(
|
|
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,6 +2314,10 @@ var BambooContext = class extends Generator {
|
|
|
2330
2314
|
code: artifacts.index
|
|
2331
2315
|
}]
|
|
2332
2316
|
});
|
|
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);
|
|
2333
2321
|
};
|
|
2334
2322
|
watchConfig = (cb, opts) => {
|
|
2335
2323
|
const { cwd, poll, exclude } = opts ?? {};
|
|
@@ -2433,44 +2421,6 @@ async function loadConfigAndCreateContext(options = {}) {
|
|
|
2433
2421
|
return new BambooContext(conf);
|
|
2434
2422
|
}
|
|
2435
2423
|
//#endregion
|
|
2436
|
-
//#region src/parse-glob.ts
|
|
2437
|
-
function parseGlob(pattern) {
|
|
2438
|
-
let glob = pattern;
|
|
2439
|
-
const base = globParent(pattern);
|
|
2440
|
-
if (base !== ".") {
|
|
2441
|
-
glob = pattern.substring(base.length);
|
|
2442
|
-
if (glob.charAt(0) === "/") glob = glob.substring(1);
|
|
2443
|
-
}
|
|
2444
|
-
if (glob.substring(0, 2) === "./") glob = glob.substring(2);
|
|
2445
|
-
if (glob.charAt(0) === "/") glob = glob.substring(1);
|
|
2446
|
-
return {
|
|
2447
|
-
base,
|
|
2448
|
-
glob
|
|
2449
|
-
};
|
|
2450
|
-
}
|
|
2451
|
-
//#endregion
|
|
2452
|
-
//#region src/parse-dependency.ts
|
|
2453
|
-
function parseDependency(fileOrGlob) {
|
|
2454
|
-
if (fileOrGlob.startsWith("!")) return null;
|
|
2455
|
-
let message = null;
|
|
2456
|
-
if (isGlob(fileOrGlob)) {
|
|
2457
|
-
const { base, glob } = parseGlob(fileOrGlob);
|
|
2458
|
-
message = {
|
|
2459
|
-
type: "dir-dependency",
|
|
2460
|
-
dir: normalize(resolve(base)),
|
|
2461
|
-
glob
|
|
2462
|
-
};
|
|
2463
|
-
} else message = {
|
|
2464
|
-
type: "dependency",
|
|
2465
|
-
file: normalize(resolve(fileOrGlob))
|
|
2466
|
-
};
|
|
2467
|
-
if (message.type === "dir-dependency" && process.env.ROLLUP_WATCH === "true") message = {
|
|
2468
|
-
type: "dependency",
|
|
2469
|
-
file: normalize(resolve(message.dir))
|
|
2470
|
-
};
|
|
2471
|
-
return message;
|
|
2472
|
-
}
|
|
2473
|
-
//#endregion
|
|
2474
2424
|
//#region src/source-snapshots.ts
|
|
2475
2425
|
/**
|
|
2476
2426
|
* Every file `include` covers, read once.
|
|
@@ -3276,26 +3226,36 @@ function collectRenderedElements(ctx) {
|
|
|
3276
3226
|
return found;
|
|
3277
3227
|
}
|
|
3278
3228
|
//#endregion
|
|
3279
|
-
//#region src/
|
|
3280
|
-
const fileModifiedMap = /* @__PURE__ */ new Map();
|
|
3229
|
+
//#region src/assemble-sheet.ts
|
|
3281
3230
|
/**
|
|
3282
|
-
*
|
|
3231
|
+
* One stylesheet from an already-extracted encoder.
|
|
3283
3232
|
*
|
|
3284
|
-
* `
|
|
3285
|
-
*
|
|
3286
|
-
* by `write` on an earlier pass, or inlined from `styles.css` by `postcss-import`.
|
|
3287
|
-
*
|
|
3288
|
-
* A declaration rather than a comment because it has to survive the css being minified
|
|
3289
|
-
* between the copy landing and this check running, which a comment does not.
|
|
3233
|
+
* Vite, `bamboo cssgen`, and the CLI `bamboo` command all finish here so a recipe lowered to
|
|
3234
|
+
* atoms cannot have a different sheet depending on which integration asked for it.
|
|
3290
3235
|
*/
|
|
3291
|
-
const
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
}
|
|
3236
|
+
const assembleExtractedSheet = (ctx, { layerParams = false, sourceScanCache, mtimeOf, sourceInventory } = {}) => {
|
|
3237
|
+
ctx.encoder.atomizeObservedRecipes();
|
|
3238
|
+
const sheet = ctx.createSheet();
|
|
3239
|
+
if (layerParams) {
|
|
3240
|
+
const recipeLayer = ctx.config.layers?.recipes ?? "recipes";
|
|
3241
|
+
sheet.layers.root.prepend(`@layer ${sheet.layers.layerNames.filter((name) => name !== recipeLayer).join(", ")};`);
|
|
3242
|
+
}
|
|
3243
|
+
ctx.appendBaselineCss(sheet, { atomizeRecipes: true });
|
|
3244
|
+
const collectElements = prunesPreflight(ctx.config.preflight);
|
|
3245
|
+
const pruneKeyframes = Boolean(ctx.config.prune?.keyframes);
|
|
3246
|
+
const declaredKeyframes = pruneKeyframes ? keyframeNames(ctx) : [];
|
|
3247
|
+
const scans = ctx.config.prune?.tokens !== false || collectElements || pruneKeyframes ? collectSourceScans(ctx, {
|
|
3248
|
+
keyframeNames: declaredKeyframes,
|
|
3249
|
+
elements: collectElements
|
|
3250
|
+
}, sourceScanCache, mtimeOf, sourceInventory) : void 0;
|
|
3251
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, [], scans);
|
|
3252
|
+
if (collectElements && scans) ctx.prunePreflight(sheet, scans.elements);
|
|
3253
|
+
if (pruneKeyframes && scans) ctx.pruneKeyframes(sheet, scans.keyframeHits, reachableVars);
|
|
3254
|
+
return sheet;
|
|
3255
|
+
};
|
|
3256
|
+
//#endregion
|
|
3257
|
+
//#region src/builder.ts
|
|
3258
|
+
const fileModifiedMap = /* @__PURE__ */ new Map();
|
|
3299
3259
|
var Builder = class {
|
|
3300
3260
|
/**
|
|
3301
3261
|
* The current bamboo context
|
|
@@ -3306,7 +3266,6 @@ var Builder = class {
|
|
|
3306
3266
|
explicitDepsMeta;
|
|
3307
3267
|
affecteds;
|
|
3308
3268
|
configDependencies = /* @__PURE__ */ new Set();
|
|
3309
|
-
pendingConfigCrawl;
|
|
3310
3269
|
/** Last complete included inventory, including members which have since been deleted. */
|
|
3311
3270
|
sourceInventory;
|
|
3312
3271
|
/** Existing included owners selected by the last resolution-ledger invalidation pass. */
|
|
@@ -3341,6 +3300,35 @@ var Builder = class {
|
|
|
3341
3300
|
resolutionAffectedThisPass = false;
|
|
3342
3301
|
/** Per-pass digests of re-read values, so N dependents of one edit digest each value once. */
|
|
3343
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
|
+
};
|
|
3344
3332
|
/** @internal Current and missing resolver paths which can change the stylesheet. */
|
|
3345
3333
|
getResolutionReadFiles = () => {
|
|
3346
3334
|
const files = /* @__PURE__ */ new Set();
|
|
@@ -3371,41 +3359,13 @@ var Builder = class {
|
|
|
3371
3359
|
for (const file of current) this.resolutionConfigurationBytes.set(file, this.readResolutionConfiguration(file));
|
|
3372
3360
|
for (const file of this.resolutionConfigurationBytes.keys()) if (!current.has(file)) this.resolutionConfigurationBytes.delete(file);
|
|
3373
3361
|
};
|
|
3374
|
-
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
* whole TypeScript compiler. Only `registerDependency` reads the result, and only the PostCSS
|
|
3379
|
-
* plugin calls that — the CLI and the Vite plugin (which crawls separately, when it watches)
|
|
3380
|
-
* paid ~155ms of compiler load per build for a set neither of them ever read.
|
|
3381
|
-
*/
|
|
3382
|
-
setConfigDependencies(options) {
|
|
3383
|
-
this.pendingConfigCrawl = options;
|
|
3384
|
-
const cwd = options?.cwd ?? this.context?.config.cwd ?? process.cwd();
|
|
3385
|
-
for (const file of this.context?.conf.dependencies ?? []) this.configDependencies.add(resolve(cwd, file));
|
|
3386
|
-
}
|
|
3387
|
-
/** Crawl on first read, once per `setConfigDependencies`. */
|
|
3388
|
-
crawlConfigDependencies() {
|
|
3389
|
-
const options = this.pendingConfigCrawl;
|
|
3390
|
-
if (!options) return;
|
|
3391
|
-
this.pendingConfigCrawl = void 0;
|
|
3392
|
-
const tsOptions = this.context?.conf.tsOptions ?? {
|
|
3393
|
-
baseUrl: void 0,
|
|
3394
|
-
pathMappings: []
|
|
3395
|
-
};
|
|
3396
|
-
const compilerOptions = this.context?.conf.tsconfig?.compilerOptions ?? {};
|
|
3397
|
-
const { deps } = getConfigDependencies(options.configPath, tsOptions, compilerOptions);
|
|
3398
|
-
deps.forEach((file) => this.configDependencies.add(file));
|
|
3399
|
-
logger.debug("builder", "Config dependencies");
|
|
3400
|
-
logger.debug("builder", deps);
|
|
3401
|
-
}
|
|
3362
|
+
recordConfigDependencies = (ctx, cwd) => {
|
|
3363
|
+
const root = cwd ?? ctx.config.cwd;
|
|
3364
|
+
for (const file of uniq([...ctx.conf.dependencies, ...ctx.explicitDeps])) this.configDependencies.add(resolve(root, file));
|
|
3365
|
+
};
|
|
3402
3366
|
setup = async (options = {}) => {
|
|
3403
3367
|
logger.debug("builder", "🚧 Setup");
|
|
3404
3368
|
const configPath = options.configPath ?? findConfig({ cwd: options.cwd });
|
|
3405
|
-
this.setConfigDependencies({
|
|
3406
|
-
configPath,
|
|
3407
|
-
cwd: options.cwd
|
|
3408
|
-
});
|
|
3409
3369
|
if (!this.context) return this.setupContext({
|
|
3410
3370
|
configPath,
|
|
3411
3371
|
cwd: options.cwd,
|
|
@@ -3443,7 +3403,9 @@ var Builder = class {
|
|
|
3443
3403
|
this.affecteds = await ctx.diff.reloadConfigAndRefreshContext((conf) => {
|
|
3444
3404
|
this.context = new BambooContext(conf);
|
|
3445
3405
|
});
|
|
3446
|
-
|
|
3406
|
+
const nextContext = this.getContextOrThrow();
|
|
3407
|
+
this.recordConfigDependencies(nextContext, options.cwd);
|
|
3408
|
+
this.tsconfigResolutionFiles = nextContext.diff.getResolutionConfigFiles();
|
|
3447
3409
|
logger.debug("builder", this.affecteds);
|
|
3448
3410
|
this.explicitDepsMeta = this.checkFilesChanged(this.context.explicitDeps);
|
|
3449
3411
|
if (this.explicitDepsMeta.hasFilesChanged) {
|
|
@@ -3467,6 +3429,7 @@ var Builder = class {
|
|
|
3467
3429
|
this.sourceScanCache.entries.clear();
|
|
3468
3430
|
this.extractionReadsByOwner.clear();
|
|
3469
3431
|
this.recipeSurfaceByOwner.clear();
|
|
3432
|
+
this.capturedLedger = void 0;
|
|
3470
3433
|
await ctx.hooks["config:change"]?.({
|
|
3471
3434
|
config: ctx.config,
|
|
3472
3435
|
changes: this.affecteds
|
|
@@ -3503,7 +3466,8 @@ var Builder = class {
|
|
|
3503
3466
|
const changedResolutionConfigurations = this.changedResolutionConfigurations();
|
|
3504
3467
|
const changedResolutionSet = new Set(changedResolutionConfigurations);
|
|
3505
3468
|
const resolutionAffected = /* @__PURE__ */ new Set();
|
|
3506
|
-
const resolutionLedger = changedResolutionConfigurations.length ? ctx.project.getResolutionLedger() : void 0;
|
|
3469
|
+
const resolutionLedger = this.capturedLedger ?? (changedResolutionConfigurations.length ? ctx.project.getResolutionLedger() : void 0);
|
|
3470
|
+
this.capturedLedger = void 0;
|
|
3507
3471
|
for (const [owner, configurations] of this.resolutionConfigurationSets) if (configurations.some((file) => changedResolutionSet.has(file))) resolutionAffected.add(owner);
|
|
3508
3472
|
this.resolutionAffectedThisPass = resolutionAffected.size > 0;
|
|
3509
3473
|
if (changedResolutionConfigurations.length) {
|
|
@@ -3641,9 +3605,7 @@ var Builder = class {
|
|
|
3641
3605
|
cwd,
|
|
3642
3606
|
dev
|
|
3643
3607
|
});
|
|
3644
|
-
|
|
3645
|
-
this.configDependencies.add(resolve(cwd || ctx.conf.config.cwd, file));
|
|
3646
|
-
});
|
|
3608
|
+
this.recordConfigDependencies(ctx, cwd);
|
|
3647
3609
|
this.context = ctx;
|
|
3648
3610
|
this.tsconfigResolutionFiles = ctx.diff.getResolutionConfigFiles();
|
|
3649
3611
|
return ctx;
|
|
@@ -3802,73 +3764,23 @@ var Builder = class {
|
|
|
3802
3764
|
ctx.assertExtracted(files);
|
|
3803
3765
|
ctx.assertNoDeadCalls(files);
|
|
3804
3766
|
};
|
|
3805
|
-
isValidRoot = (root) => {
|
|
3806
|
-
const ctx = this.getContextOrThrow();
|
|
3807
|
-
let valid = false;
|
|
3808
|
-
root.walkAtRules("layer", (rule) => {
|
|
3809
|
-
if (ctx.isValidLayerParams(rule.params)) valid = true;
|
|
3810
|
-
});
|
|
3811
|
-
return valid;
|
|
3812
|
-
};
|
|
3813
|
-
write = (root) => {
|
|
3814
|
-
if (hasGeneratedCss(root)) {
|
|
3815
|
-
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.");
|
|
3816
|
-
return;
|
|
3817
|
-
}
|
|
3818
|
-
root.append(this.toCss());
|
|
3819
|
-
};
|
|
3820
3767
|
/**
|
|
3821
3768
|
* The finished stylesheet, as a string.
|
|
3822
3769
|
*
|
|
3823
|
-
*
|
|
3824
|
-
*
|
|
3825
|
-
* through here so a build cannot depend on which integration asked for it.
|
|
3826
|
-
*
|
|
3827
|
-
* `layerParams` is the one thing that differs between them, and it is not cosmetic: the
|
|
3828
|
-
* `@layer a, b, c;` statement is what fixes layer *order*, and css layers are ordered by
|
|
3829
|
-
* first appearance otherwise. `write` leaves it out because the root it appends to is a
|
|
3830
|
-
* file that already declares it -- that declaration is what `isValidRoot` matches on. A
|
|
3831
|
-
* virtual module is the whole stylesheet and has nothing to inherit it from.
|
|
3770
|
+
* `layerParams` controls the `@layer a, b, c;` statement that fixes layer order. CSS layers
|
|
3771
|
+
* are ordered by first appearance otherwise.
|
|
3832
3772
|
*
|
|
3833
3773
|
* `extract` has to have run first: this reads the encoder rather than filling it.
|
|
3834
3774
|
*/
|
|
3835
|
-
toCss = ({ layerParams = false
|
|
3836
|
-
const ctx = this.getContextOrThrow();
|
|
3837
|
-
const sheet = ctx.createSheet();
|
|
3838
|
-
if (layerParams) if (includeRecipes) ctx.appendLayerParams(sheet);
|
|
3839
|
-
else {
|
|
3840
|
-
const recipeLayer = ctx.config.layers?.recipes ?? "recipes";
|
|
3841
|
-
sheet.layers.root.prepend(`@layer ${sheet.layers.layerNames.filter((name) => name !== recipeLayer).join(", ")};`);
|
|
3842
|
-
}
|
|
3843
|
-
ctx.appendBaselineCss(sheet);
|
|
3844
|
-
if (!includeRecipes) {
|
|
3845
|
-
sheet.layers.recipes.removeAll();
|
|
3846
|
-
sheet.layers.recipes_base.removeAll();
|
|
3847
|
-
sheet.layers.recipes_slots.removeAll();
|
|
3848
|
-
sheet.layers.recipes_slots_base.removeAll();
|
|
3849
|
-
}
|
|
3850
|
-
const collectElements = prunesPreflight(ctx.config.preflight);
|
|
3851
|
-
const declaredKeyframes = ctx.config.prune?.keyframes ? keyframeNames(ctx) : [];
|
|
3852
|
-
const scans = ctx.config.prune?.tokens !== false || collectElements || declaredKeyframes.length > 0 ? collectSourceScans(ctx, {
|
|
3853
|
-
keyframeNames: declaredKeyframes,
|
|
3854
|
-
elements: collectElements
|
|
3855
|
-
}, this.sourceScanCache, (filePath) => this.filesMeta?.changes.get(filePath)?.mtime, this.sourceInventory) : void 0;
|
|
3856
|
-
const reachableVars = pruneTokensForBuild(ctx, sheet, [], scans);
|
|
3857
|
-
if (collectElements && scans) ctx.prunePreflight(sheet, scans.elements);
|
|
3858
|
-
if (ctx.config.prune?.keyframes && scans) ctx.pruneKeyframes(sheet, scans.keyframeHits, reachableVars);
|
|
3859
|
-
return ctx.getCss(sheet);
|
|
3860
|
-
};
|
|
3861
|
-
registerDependency = (fn) => {
|
|
3775
|
+
toCss = ({ layerParams = false } = {}) => {
|
|
3862
3776
|
const ctx = this.getContextOrThrow();
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
for (const file of this.configDependencies) fn({
|
|
3869
|
-
type: "dependency",
|
|
3870
|
-
file: normalize(resolve(file))
|
|
3777
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
3778
|
+
layerParams,
|
|
3779
|
+
sourceScanCache: this.sourceScanCache,
|
|
3780
|
+
mtimeOf: (filePath) => this.filesMeta?.changes.get(filePath)?.mtime,
|
|
3781
|
+
sourceInventory: this.sourceInventory
|
|
3871
3782
|
});
|
|
3783
|
+
return ctx.getCss(sheet);
|
|
3872
3784
|
};
|
|
3873
3785
|
};
|
|
3874
3786
|
//#endregion
|
|
@@ -3940,8 +3852,8 @@ const startProfiling = async (cwd, prefix, isWatching) => {
|
|
|
3940
3852
|
//#region src/cssgen.ts
|
|
3941
3853
|
const cssgen = async (ctx, options) => {
|
|
3942
3854
|
const { outfile, type, splitting } = options;
|
|
3943
|
-
const sheet = ctx.createSheet();
|
|
3944
3855
|
if (type) {
|
|
3856
|
+
const sheet = ctx.createSheet();
|
|
3945
3857
|
const done = logger.time.info(ctx.messages.cssArtifactComplete(type));
|
|
3946
3858
|
ctx.appendCssOfType(type, sheet);
|
|
3947
3859
|
if (type === "preflight" && prunesPreflight(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
@@ -3952,19 +3864,9 @@ const cssgen = async (ctx, options) => {
|
|
|
3952
3864
|
} else await ctx.writeCss(sheet);
|
|
3953
3865
|
done();
|
|
3954
3866
|
} else {
|
|
3955
|
-
const { files
|
|
3867
|
+
const { files } = ctx.parseFiles();
|
|
3956
3868
|
const done = logger.time.info(ctx.messages.buildComplete(files.length));
|
|
3957
|
-
ctx
|
|
3958
|
-
ctx.appendBaselineCss(sheet);
|
|
3959
|
-
ctx.appendParserCss(sheet);
|
|
3960
|
-
const collectElements = prunesPreflight(ctx.config.preflight);
|
|
3961
|
-
const scans = collectSourceScans(ctx, {
|
|
3962
|
-
keyframeNames: ctx.config.prune?.keyframes ? keyframeNames(ctx) : [],
|
|
3963
|
-
elements: collectElements
|
|
3964
|
-
});
|
|
3965
|
-
const reachableVars = pruneTokensForBuild(ctx, sheet, results, scans);
|
|
3966
|
-
if (collectElements) ctx.prunePreflight(sheet, scans.elements);
|
|
3967
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, scans.keyframeHits, reachableVars);
|
|
3869
|
+
const sheet = assembleExtractedSheet(ctx, { layerParams: true });
|
|
3968
3870
|
if (splitting) await ctx.writeSplitCss(sheet);
|
|
3969
3871
|
else if (outfile) {
|
|
3970
3872
|
const css = ctx.getCss(sheet);
|
|
@@ -4029,19 +3931,8 @@ async function build(ctx, artifactIds) {
|
|
|
4029
3931
|
await codegen(ctx, artifactIds);
|
|
4030
3932
|
if (ctx.config.emitTokensOnly) return logger.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens ✨");
|
|
4031
3933
|
const done = logger.time.info("");
|
|
4032
|
-
const sheet = ctx.createSheet();
|
|
4033
|
-
ctx.appendLayerParams(sheet);
|
|
4034
|
-
ctx.appendBaselineCss(sheet);
|
|
4035
3934
|
const parsed = ctx.parseFiles();
|
|
4036
|
-
ctx
|
|
4037
|
-
const collectElements = prunesPreflight(ctx.config.preflight);
|
|
4038
|
-
const scans = collectSourceScans(ctx, {
|
|
4039
|
-
keyframeNames: ctx.config.prune?.keyframes ? keyframeNames(ctx) : [],
|
|
4040
|
-
elements: collectElements
|
|
4041
|
-
});
|
|
4042
|
-
const reachableVars = pruneTokensForBuild(ctx, sheet, parsed.results, scans);
|
|
4043
|
-
if (collectElements) ctx.prunePreflight(sheet, scans.elements);
|
|
4044
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, scans.keyframeHits, reachableVars);
|
|
3935
|
+
const sheet = assembleExtractedSheet(ctx, { layerParams: true });
|
|
4045
3936
|
await ctx.writeCss(sheet);
|
|
4046
3937
|
done(ctx.messages.buildComplete(parsed.files.length));
|
|
4047
3938
|
}
|
|
@@ -4082,18 +3973,7 @@ async function generate(config, configPath) {
|
|
|
4082
3973
|
if (parsed === 0) return;
|
|
4083
3974
|
const outfile = ctx.runtime.path.join(...ctx.paths.root, "styles.css");
|
|
4084
3975
|
const done = logger.time.info(ctx.messages.buildComplete(parsed));
|
|
4085
|
-
const sheet = ctx
|
|
4086
|
-
ctx.appendLayerParams(sheet);
|
|
4087
|
-
ctx.appendBaselineCss(sheet);
|
|
4088
|
-
ctx.appendParserCss(sheet);
|
|
4089
|
-
const collectWatchElements = prunesPreflight(ctx.config.preflight);
|
|
4090
|
-
const watchScans = collectSourceScans(ctx, {
|
|
4091
|
-
keyframeNames: ctx.config.prune?.keyframes ? keyframeNames(ctx) : [],
|
|
4092
|
-
elements: collectWatchElements
|
|
4093
|
-
});
|
|
4094
|
-
const reachableVars = pruneTokensForBuild(ctx, sheet, [], watchScans);
|
|
4095
|
-
if (collectWatchElements) ctx.prunePreflight(sheet, watchScans.elements);
|
|
4096
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, watchScans.keyframeHits, reachableVars);
|
|
3976
|
+
const sheet = assembleExtractedSheet(ctx, { layerParams: true });
|
|
4097
3977
|
const css = ctx.getCss(sheet);
|
|
4098
3978
|
await ctx.runtime.fs.writeFile(outfile, css);
|
|
4099
3979
|
done();
|
|
@@ -4141,6 +4021,7 @@ const setLogStream = (options) => {
|
|
|
4141
4021
|
if (options.logfile) {
|
|
4142
4022
|
const outPath = path.resolve(cwd, options.logfile);
|
|
4143
4023
|
ensure(outPath);
|
|
4024
|
+
fs.closeSync(fs.openSync(outPath, "a"));
|
|
4144
4025
|
logger.info("logfile", outPath);
|
|
4145
4026
|
stream = fs.createWriteStream(outPath, { flags: "a" });
|
|
4146
4027
|
logger.onLog = (entry) => {
|
|
@@ -4165,67 +4046,6 @@ const ensure = (outPath) => {
|
|
|
4165
4046
|
return outPath;
|
|
4166
4047
|
};
|
|
4167
4048
|
//#endregion
|
|
4168
|
-
//#region src/vite-integration.ts
|
|
4169
|
-
/**
|
|
4170
|
-
* Every extension Vite accepts for its config, so "is this a Vite project" is answered by the
|
|
4171
|
-
* same file Vite itself would load.
|
|
4172
|
-
*
|
|
4173
|
-
* A file rather than a resolvable `vite` package: Vite is a transitive dependency of plenty of
|
|
4174
|
-
* things — Vitest above all — and a project that has one for its tests and builds with webpack
|
|
4175
|
-
* is exactly the case this must not mistake for a Vite app.
|
|
4176
|
-
*/
|
|
4177
|
-
const VITE_CONFIG_FILES = [
|
|
4178
|
-
"vite.config.ts",
|
|
4179
|
-
"vite.config.js",
|
|
4180
|
-
"vite.config.mjs",
|
|
4181
|
-
"vite.config.mts",
|
|
4182
|
-
"vite.config.cjs",
|
|
4183
|
-
"vite.config.cts"
|
|
4184
|
-
];
|
|
4185
|
-
/** The project's Vite config, if it has one. Not resolved further than existence. */
|
|
4186
|
-
const findViteConfig = (cwd) => VITE_CONFIG_FILES.map((file) => join(cwd, file)).find((file) => existsSync(file));
|
|
4187
|
-
/**
|
|
4188
|
-
* Frameworks that author styles in a file the Vite compiler does not transform.
|
|
4189
|
-
*
|
|
4190
|
-
* It compiles JavaScript and TypeScript. A `.svelte`, `.vue` or `.astro` file is a template
|
|
4191
|
-
* with a script in it, and the compiler leaves those alone — which for a Svelte or Vue project
|
|
4192
|
-
* makes the PostCSS integration the right one, not a downgrade. Worse than that: switching one
|
|
4193
|
-
* to `@bamboocss/vite` would prune every rule only its components reach, since reachability is
|
|
4194
|
-
* computed from modules the compiler saw, so the pages would render unstyled.
|
|
4195
|
-
*
|
|
4196
|
-
* So this is the exception to the advice, and it has to be checked before giving it.
|
|
4197
|
-
*/
|
|
4198
|
-
const TEMPLATE_EXTENSIONS = /\b(?:svelte|vue|astro|html|hbs|mdx?)\b/;
|
|
4199
|
-
const TEMPLATE_PACKAGES = [
|
|
4200
|
-
"svelte",
|
|
4201
|
-
"@sveltejs/kit",
|
|
4202
|
-
"vue",
|
|
4203
|
-
"nuxt",
|
|
4204
|
-
"astro"
|
|
4205
|
-
];
|
|
4206
|
-
/**
|
|
4207
|
-
* Does this project author styles somewhere the Vite compiler cannot reach?
|
|
4208
|
-
*
|
|
4209
|
-
* Two signals because the two callers know different things. A resolved config names the file
|
|
4210
|
-
* types directly, and is authoritative when it does; `bamboo init` runs before there is one,
|
|
4211
|
-
* so the dependency list stands in. Either one is enough — both directions of a wrong answer
|
|
4212
|
-
* here only decide whether advice is offered, and the advice is worth less than a Svelte
|
|
4213
|
-
* project being told to break itself.
|
|
4214
|
-
*/
|
|
4215
|
-
const hasUncompilableSources = (options) => {
|
|
4216
|
-
if (options.include?.some((glob) => TEMPLATE_EXTENSIONS.test(glob))) return true;
|
|
4217
|
-
try {
|
|
4218
|
-
const manifest = JSON.parse(readFileSync(join(options.cwd, "package.json"), "utf8"));
|
|
4219
|
-
const dependencies = {
|
|
4220
|
-
...manifest.dependencies,
|
|
4221
|
-
...manifest.devDependencies
|
|
4222
|
-
};
|
|
4223
|
-
return TEMPLATE_PACKAGES.some((name) => name in dependencies);
|
|
4224
|
-
} catch {
|
|
4225
|
-
return false;
|
|
4226
|
-
}
|
|
4227
|
-
};
|
|
4228
|
-
//#endregion
|
|
4229
4049
|
//#region src/setup-config.ts
|
|
4230
4050
|
async function setupConfig(cwd, opts = {}) {
|
|
4231
4051
|
const { force, outExtension, outdir = "styled-system", strictValues } = opts;
|
|
@@ -4282,19 +4102,6 @@ strictValues: ${JSON.stringify(strictValues)},\n` : ""}
|
|
|
4282
4102
|
logger.log(messages.thankYou());
|
|
4283
4103
|
}
|
|
4284
4104
|
}
|
|
4285
|
-
async function setupPostcss(cwd) {
|
|
4286
|
-
const viteConfig = findViteConfig(cwd);
|
|
4287
|
-
if (viteConfig && !hasUncompilableSources({ cwd })) logger.warn("init:postcss", `This project has ${quote(basename(viteConfig))}, so ${quote("@bamboocss/vite")} is the integration to use. The PostCSS one emits CSS only: it does not compile source, so ${quote("css()")} and ${quote("cva()")} stay runtime calls and the generated style engine ships in your client bundle. Both render identically, which is what makes the difference easy to miss. See https://bamboocss.com/docs/installation/vite`);
|
|
4288
|
-
logger.info("init:postcss", `creating postcss config file: ${quote("postcss.config.cjs")}`);
|
|
4289
|
-
const content = outdent`
|
|
4290
|
-
module.exports = {
|
|
4291
|
-
plugins: {
|
|
4292
|
-
'@bamboocss/dev/postcss': {},
|
|
4293
|
-
},
|
|
4294
|
-
}
|
|
4295
|
-
`;
|
|
4296
|
-
await fsExtra.writeFile(join(cwd, "postcss.config.cjs"), content);
|
|
4297
|
-
}
|
|
4298
4105
|
//#endregion
|
|
4299
4106
|
//#region src/spec.ts
|
|
4300
4107
|
async function spec(ctx, options) {
|
|
@@ -4318,4 +4125,53 @@ async function spec(ctx, options) {
|
|
|
4318
4125
|
return specs;
|
|
4319
4126
|
}
|
|
4320
4127
|
//#endregion
|
|
4321
|
-
|
|
4128
|
+
//#region src/vite-integration.ts
|
|
4129
|
+
/**
|
|
4130
|
+
* Every extension Vite accepts for its config, so "is this a Vite project" is answered by the
|
|
4131
|
+
* same file Vite itself would load.
|
|
4132
|
+
*
|
|
4133
|
+
* A file rather than a resolvable `vite` package: Vite is a transitive dependency of plenty of
|
|
4134
|
+
* things — Vitest above all — and a project that has one for its tests and builds with webpack
|
|
4135
|
+
* is exactly the case this must not mistake for a Vite app.
|
|
4136
|
+
*/
|
|
4137
|
+
const VITE_CONFIG_FILES = [
|
|
4138
|
+
"vite.config.ts",
|
|
4139
|
+
"vite.config.js",
|
|
4140
|
+
"vite.config.mjs",
|
|
4141
|
+
"vite.config.mts",
|
|
4142
|
+
"vite.config.cjs",
|
|
4143
|
+
"vite.config.cts"
|
|
4144
|
+
];
|
|
4145
|
+
/** The project's Vite config, if it has one. Not resolved further than existence. */
|
|
4146
|
+
const findViteConfig = (cwd) => VITE_CONFIG_FILES.map((file) => join(cwd, file)).find((file) => existsSync(file));
|
|
4147
|
+
/**
|
|
4148
|
+
* Frameworks that author styles in a file the Vite compiler does not transform as JavaScript
|
|
4149
|
+
* until a dedicated preprocessor exists. Vue, Svelte and Astro compile through
|
|
4150
|
+
* `bamboocss:compiler-sfc`. HTML / Handlebars templates still do not.
|
|
4151
|
+
*/
|
|
4152
|
+
const TEMPLATE_EXTENSIONS = /\b(?:html|hbs)\b/;
|
|
4153
|
+
const TEMPLATE_PACKAGES = [];
|
|
4154
|
+
/**
|
|
4155
|
+
* Does this project author styles somewhere the Vite compiler cannot reach?
|
|
4156
|
+
*
|
|
4157
|
+
* Two signals because the two callers know different things. A resolved config names the file
|
|
4158
|
+
* types directly, and is authoritative when it does; `bamboo init` runs before there is one,
|
|
4159
|
+
* so the dependency list stands in. Either one is enough — both directions of a wrong answer
|
|
4160
|
+
* here only decide whether advice is offered, and the advice is worth less than a Svelte
|
|
4161
|
+
* project being told to break itself.
|
|
4162
|
+
*/
|
|
4163
|
+
const hasUncompilableSources = (options) => {
|
|
4164
|
+
if (options.include?.some((glob) => TEMPLATE_EXTENSIONS.test(glob))) return true;
|
|
4165
|
+
try {
|
|
4166
|
+
const manifest = JSON.parse(readFileSync(join(options.cwd, "package.json"), "utf8"));
|
|
4167
|
+
const dependencies = {
|
|
4168
|
+
...manifest.dependencies,
|
|
4169
|
+
...manifest.devDependencies
|
|
4170
|
+
};
|
|
4171
|
+
return TEMPLATE_PACKAGES.some((name) => name in dependencies);
|
|
4172
|
+
} catch {
|
|
4173
|
+
return false;
|
|
4174
|
+
}
|
|
4175
|
+
};
|
|
4176
|
+
//#endregion
|
|
4177
|
+
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.0",
|
|
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.0",
|
|
66
|
+
"@bamboocss/core": "1.48.0",
|
|
67
|
+
"@bamboocss/generator": "1.48.0",
|
|
68
|
+
"@bamboocss/logger": "1.48.0",
|
|
69
|
+
"@bamboocss/parser": "1.48.0",
|
|
70
|
+
"@bamboocss/plugin-svelte": "1.48.0",
|
|
71
|
+
"@bamboocss/plugin-vue": "1.48.0",
|
|
72
|
+
"@bamboocss/reporter": "1.48.0",
|
|
73
|
+
"@bamboocss/shared": "1.48.0",
|
|
74
|
+
"@bamboocss/token-dictionary": "1.48.0",
|
|
75
|
+
"@bamboocss/types": "1.48.0"
|
|
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
|
},
|