@bamboocss/node 1.46.2 → 1.47.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 +4 -4
- package/dist/index.cjs +115 -136
- package/dist/index.d.cts +6 -3
- package/dist/index.d.mts +6 -3
- package/dist/index.mjs +117 -137
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
The Node runtime behind Bamboo CSS: config loading, context creation, extraction and the write side of codegen and
|
|
4
4
|
`styles.css`.
|
|
5
5
|
|
|
6
|
-
This is an internal package. It is what `@bamboocss/dev` (the CLI)
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
This is an internal package. It is what `@bamboocss/dev` (the CLI) and `@bamboocss/vite` are built on, and it is
|
|
7
|
+
versioned with them — most projects should install one of those instead. User-facing documentation lives at
|
|
8
|
+
[bamboocss.com/docs](https://bamboocss.com/docs).
|
|
9
9
|
|
|
10
10
|
## Exports
|
|
11
11
|
|
|
@@ -35,7 +35,7 @@ Each takes a `BambooContext`, and each backs the CLI command of the same name.
|
|
|
35
35
|
|
|
36
36
|
### Setup and utilities
|
|
37
37
|
|
|
38
|
-
- `setupConfig(cwd, options?)`
|
|
38
|
+
- `setupConfig(cwd, options?)` – scaffold `bamboo.config.ts`.
|
|
39
39
|
- `setupGitIgnore(ctx)` – add the outdir to `.gitignore`, unless `config.gitignore` is off.
|
|
40
40
|
- `parseDependency(fileOrGlob)` – turn a `config.dependencies` entry into a PostCSS `dependency` or `dir-dependency`
|
|
41
41
|
message.
|
package/dist/index.cjs
CHANGED
|
@@ -26,13 +26,13 @@ const require_static_compiler = require("./static-compiler.cjs");
|
|
|
26
26
|
let _bamboocss_reporter = require("@bamboocss/reporter");
|
|
27
27
|
let _bamboocss_logger = require("@bamboocss/logger");
|
|
28
28
|
let _bamboocss_config = require("@bamboocss/config");
|
|
29
|
-
let _bamboocss_core = require("@bamboocss/core");
|
|
30
29
|
let _bamboocss_shared = require("@bamboocss/shared");
|
|
31
30
|
let node_crypto = require("node:crypto");
|
|
32
31
|
let fs = require("fs");
|
|
33
32
|
let path = require("path");
|
|
34
33
|
let _bamboocss_plugin_svelte = require("@bamboocss/plugin-svelte");
|
|
35
34
|
let _bamboocss_plugin_vue = require("@bamboocss/plugin-vue");
|
|
35
|
+
let _bamboocss_core = require("@bamboocss/core");
|
|
36
36
|
let _bamboocss_generator = require("@bamboocss/generator");
|
|
37
37
|
let _bamboocss_parser = require("@bamboocss/parser");
|
|
38
38
|
let perfect_debounce = require("perfect-debounce");
|
|
@@ -2293,11 +2293,11 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2293
2293
|
}]
|
|
2294
2294
|
});
|
|
2295
2295
|
};
|
|
2296
|
-
writeSplitCss = async (sheet) => {
|
|
2296
|
+
writeSplitCss = async (sheet, { includeRecipes = false } = {}) => {
|
|
2297
2297
|
const { path: pathUtil, fs } = this.runtime;
|
|
2298
2298
|
const rootDir = this.paths.root;
|
|
2299
2299
|
const stylesDir = [...rootDir, "styles"];
|
|
2300
|
-
const artifacts = this.getSplitCssArtifacts(sheet);
|
|
2300
|
+
const artifacts = this.getSplitCssArtifacts(sheet, { includeRecipes });
|
|
2301
2301
|
const subDirs = new Set([...artifacts.recipes, ...artifacts.themes].map((a) => a.dir).filter(Boolean));
|
|
2302
2302
|
fs.ensureDirSync(pathUtil.join(...stylesDir));
|
|
2303
2303
|
subDirs.forEach((dir) => fs.ensureDirSync(pathUtil.join(...stylesDir, dir)));
|
|
@@ -2344,6 +2344,12 @@ var BambooContext = class extends _bamboocss_generator.Generator {
|
|
|
2344
2344
|
code: artifacts.index
|
|
2345
2345
|
}]
|
|
2346
2346
|
});
|
|
2347
|
+
if (!includeRecipes) {
|
|
2348
|
+
const recipesIndex = pathUtil.join(...stylesDir, "recipes.css");
|
|
2349
|
+
const recipesDir = pathUtil.join(...stylesDir, "recipes");
|
|
2350
|
+
if (fs.existsSync(recipesIndex)) fs.rmFileSync(recipesIndex);
|
|
2351
|
+
if (fs.existsSync(recipesDir)) fs.rmFileSync(recipesDir);
|
|
2352
|
+
}
|
|
2347
2353
|
};
|
|
2348
2354
|
watchConfig = (cb, opts) => {
|
|
2349
2355
|
const { cwd, poll, exclude } = opts ?? {};
|
|
@@ -3290,6 +3296,42 @@ function collectRenderedElements(ctx) {
|
|
|
3290
3296
|
return found;
|
|
3291
3297
|
}
|
|
3292
3298
|
//#endregion
|
|
3299
|
+
//#region src/assemble-sheet.ts
|
|
3300
|
+
/**
|
|
3301
|
+
* One stylesheet from an already-extracted encoder.
|
|
3302
|
+
*
|
|
3303
|
+
* Vite, `bamboo cssgen`, and the CLI `bamboo` command all finish here so a recipe lowered to
|
|
3304
|
+
* atoms cannot have a different sheet depending on which integration asked for it.
|
|
3305
|
+
*/
|
|
3306
|
+
const assembleExtractedSheet = (ctx, { layerParams = false, includeRecipes = false, sourceScanCache, mtimeOf, sourceInventory } = {}) => {
|
|
3307
|
+
if (!includeRecipes && ctx.config.polyfill) throw new Error("bamboocss: the cascade-layer polyfill is incompatible with compiled atomic styles. The polyfill removes the utility-layer boundary required for safe atom reachability and renaming.");
|
|
3308
|
+
if (!includeRecipes) ctx.encoder.atomizeObservedRecipes();
|
|
3309
|
+
const sheet = ctx.createSheet();
|
|
3310
|
+
if (layerParams) if (includeRecipes) ctx.appendLayerParams(sheet);
|
|
3311
|
+
else {
|
|
3312
|
+
const recipeLayer = ctx.config.layers?.recipes ?? "recipes";
|
|
3313
|
+
sheet.layers.root.prepend(`@layer ${sheet.layers.layerNames.filter((name) => name !== recipeLayer).join(", ")};`);
|
|
3314
|
+
}
|
|
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
|
+
}
|
|
3322
|
+
const collectElements = (0, _bamboocss_core.prunesPreflight)(ctx.config.preflight);
|
|
3323
|
+
const pruneKeyframes = Boolean(ctx.config.prune?.keyframes);
|
|
3324
|
+
const declaredKeyframes = pruneKeyframes ? keyframeNames(ctx) : [];
|
|
3325
|
+
const scans = ctx.config.prune?.tokens !== false || collectElements || pruneKeyframes ? collectSourceScans(ctx, {
|
|
3326
|
+
keyframeNames: declaredKeyframes,
|
|
3327
|
+
elements: collectElements
|
|
3328
|
+
}, sourceScanCache, mtimeOf, sourceInventory) : void 0;
|
|
3329
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, [], scans);
|
|
3330
|
+
if (collectElements && scans) ctx.prunePreflight(sheet, scans.elements);
|
|
3331
|
+
if (pruneKeyframes && scans) ctx.pruneKeyframes(sheet, scans.keyframeHits, reachableVars);
|
|
3332
|
+
return sheet;
|
|
3333
|
+
};
|
|
3334
|
+
//#endregion
|
|
3293
3335
|
//#region src/builder.ts
|
|
3294
3336
|
const fileModifiedMap = /* @__PURE__ */ new Map();
|
|
3295
3337
|
/**
|
|
@@ -3846,30 +3888,15 @@ var Builder = class {
|
|
|
3846
3888
|
*
|
|
3847
3889
|
* `extract` has to have run first: this reads the encoder rather than filling it.
|
|
3848
3890
|
*/
|
|
3849
|
-
toCss = ({ layerParams = false, includeRecipes =
|
|
3891
|
+
toCss = ({ layerParams = false, includeRecipes = false } = {}) => {
|
|
3850
3892
|
const ctx = this.getContextOrThrow();
|
|
3851
|
-
const sheet = ctx
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
if (!includeRecipes) {
|
|
3859
|
-
sheet.layers.recipes.removeAll();
|
|
3860
|
-
sheet.layers.recipes_base.removeAll();
|
|
3861
|
-
sheet.layers.recipes_slots.removeAll();
|
|
3862
|
-
sheet.layers.recipes_slots_base.removeAll();
|
|
3863
|
-
}
|
|
3864
|
-
const collectElements = (0, _bamboocss_core.prunesPreflight)(ctx.config.preflight);
|
|
3865
|
-
const declaredKeyframes = ctx.config.prune?.keyframes ? keyframeNames(ctx) : [];
|
|
3866
|
-
const scans = ctx.config.prune?.tokens !== false || collectElements || declaredKeyframes.length > 0 ? collectSourceScans(ctx, {
|
|
3867
|
-
keyframeNames: declaredKeyframes,
|
|
3868
|
-
elements: collectElements
|
|
3869
|
-
}, this.sourceScanCache, (filePath) => this.filesMeta?.changes.get(filePath)?.mtime, this.sourceInventory) : void 0;
|
|
3870
|
-
const reachableVars = pruneTokensForBuild(ctx, sheet, [], scans);
|
|
3871
|
-
if (collectElements && scans) ctx.prunePreflight(sheet, scans.elements);
|
|
3872
|
-
if (ctx.config.prune?.keyframes && scans) ctx.pruneKeyframes(sheet, scans.keyframeHits, reachableVars);
|
|
3893
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
3894
|
+
layerParams,
|
|
3895
|
+
includeRecipes,
|
|
3896
|
+
sourceScanCache: this.sourceScanCache,
|
|
3897
|
+
mtimeOf: (filePath) => this.filesMeta?.changes.get(filePath)?.mtime,
|
|
3898
|
+
sourceInventory: this.sourceInventory
|
|
3899
|
+
});
|
|
3873
3900
|
return ctx.getCss(sheet);
|
|
3874
3901
|
};
|
|
3875
3902
|
registerDependency = (fn) => {
|
|
@@ -3954,8 +3981,8 @@ const startProfiling = async (cwd, prefix, isWatching) => {
|
|
|
3954
3981
|
//#region src/cssgen.ts
|
|
3955
3982
|
const cssgen = async (ctx, options) => {
|
|
3956
3983
|
const { outfile, type, splitting } = options;
|
|
3957
|
-
const sheet = ctx.createSheet();
|
|
3958
3984
|
if (type) {
|
|
3985
|
+
const sheet = ctx.createSheet();
|
|
3959
3986
|
const done = _bamboocss_logger.logger.time.info(ctx.messages.cssArtifactComplete(type));
|
|
3960
3987
|
ctx.appendCssOfType(type, sheet);
|
|
3961
3988
|
if (type === "preflight" && (0, _bamboocss_core.prunesPreflight)(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
@@ -3966,20 +3993,13 @@ const cssgen = async (ctx, options) => {
|
|
|
3966
3993
|
} else await ctx.writeCss(sheet);
|
|
3967
3994
|
done();
|
|
3968
3995
|
} else {
|
|
3969
|
-
const { files
|
|
3996
|
+
const { files } = ctx.parseFiles();
|
|
3970
3997
|
const done = _bamboocss_logger.logger.time.info(ctx.messages.buildComplete(files.length));
|
|
3971
|
-
ctx
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
const collectElements = (0, _bamboocss_core.prunesPreflight)(ctx.config.preflight);
|
|
3975
|
-
const scans = collectSourceScans(ctx, {
|
|
3976
|
-
keyframeNames: ctx.config.prune?.keyframes ? keyframeNames(ctx) : [],
|
|
3977
|
-
elements: collectElements
|
|
3998
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
3999
|
+
layerParams: true,
|
|
4000
|
+
includeRecipes: false
|
|
3978
4001
|
});
|
|
3979
|
-
|
|
3980
|
-
if (collectElements) ctx.prunePreflight(sheet, scans.elements);
|
|
3981
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, scans.keyframeHits, reachableVars);
|
|
3982
|
-
if (splitting) await ctx.writeSplitCss(sheet);
|
|
4002
|
+
if (splitting) await ctx.writeSplitCss(sheet, { includeRecipes: false });
|
|
3983
4003
|
else if (outfile) {
|
|
3984
4004
|
const css = ctx.getCss(sheet);
|
|
3985
4005
|
_bamboocss_logger.logger.info("css", ctx.runtime.path.resolve(outfile));
|
|
@@ -4043,19 +4063,11 @@ async function build(ctx, artifactIds) {
|
|
|
4043
4063
|
await codegen(ctx, artifactIds);
|
|
4044
4064
|
if (ctx.config.emitTokensOnly) return _bamboocss_logger.logger.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens ✨");
|
|
4045
4065
|
const done = _bamboocss_logger.logger.time.info("");
|
|
4046
|
-
const sheet = ctx.createSheet();
|
|
4047
|
-
ctx.appendLayerParams(sheet);
|
|
4048
|
-
ctx.appendBaselineCss(sheet);
|
|
4049
4066
|
const parsed = ctx.parseFiles();
|
|
4050
|
-
ctx
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
keyframeNames: ctx.config.prune?.keyframes ? keyframeNames(ctx) : [],
|
|
4054
|
-
elements: collectElements
|
|
4067
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
4068
|
+
layerParams: true,
|
|
4069
|
+
includeRecipes: false
|
|
4055
4070
|
});
|
|
4056
|
-
const reachableVars = pruneTokensForBuild(ctx, sheet, parsed.results, scans);
|
|
4057
|
-
if (collectElements) ctx.prunePreflight(sheet, scans.elements);
|
|
4058
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, scans.keyframeHits, reachableVars);
|
|
4059
4071
|
await ctx.writeCss(sheet);
|
|
4060
4072
|
done(ctx.messages.buildComplete(parsed.files.length));
|
|
4061
4073
|
}
|
|
@@ -4096,18 +4108,10 @@ async function generate(config, configPath) {
|
|
|
4096
4108
|
if (parsed === 0) return;
|
|
4097
4109
|
const outfile = ctx.runtime.path.join(...ctx.paths.root, "styles.css");
|
|
4098
4110
|
const done = _bamboocss_logger.logger.time.info(ctx.messages.buildComplete(parsed));
|
|
4099
|
-
const sheet = ctx
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
ctx.appendParserCss(sheet);
|
|
4103
|
-
const collectWatchElements = (0, _bamboocss_core.prunesPreflight)(ctx.config.preflight);
|
|
4104
|
-
const watchScans = collectSourceScans(ctx, {
|
|
4105
|
-
keyframeNames: ctx.config.prune?.keyframes ? keyframeNames(ctx) : [],
|
|
4106
|
-
elements: collectWatchElements
|
|
4111
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
4112
|
+
layerParams: true,
|
|
4113
|
+
includeRecipes: false
|
|
4107
4114
|
});
|
|
4108
|
-
const reachableVars = pruneTokensForBuild(ctx, sheet, [], watchScans);
|
|
4109
|
-
if (collectWatchElements) ctx.prunePreflight(sheet, watchScans.elements);
|
|
4110
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, watchScans.keyframeHits, reachableVars);
|
|
4111
4115
|
const css = ctx.getCss(sheet);
|
|
4112
4116
|
await ctx.runtime.fs.writeFile(outfile, css);
|
|
4113
4117
|
done();
|
|
@@ -4155,6 +4159,7 @@ const setLogStream = (options) => {
|
|
|
4155
4159
|
if (options.logfile) {
|
|
4156
4160
|
const outPath = node_path.default.resolve(cwd, options.logfile);
|
|
4157
4161
|
ensure(outPath);
|
|
4162
|
+
node_fs.default.closeSync(node_fs.default.openSync(outPath, "a"));
|
|
4158
4163
|
_bamboocss_logger.logger.info("logfile", outPath);
|
|
4159
4164
|
stream = node_fs.default.createWriteStream(outPath, { flags: "a" });
|
|
4160
4165
|
_bamboocss_logger.logger.onLog = (entry) => {
|
|
@@ -4179,67 +4184,6 @@ const ensure = (outPath) => {
|
|
|
4179
4184
|
return outPath;
|
|
4180
4185
|
};
|
|
4181
4186
|
//#endregion
|
|
4182
|
-
//#region src/vite-integration.ts
|
|
4183
|
-
/**
|
|
4184
|
-
* Every extension Vite accepts for its config, so "is this a Vite project" is answered by the
|
|
4185
|
-
* same file Vite itself would load.
|
|
4186
|
-
*
|
|
4187
|
-
* A file rather than a resolvable `vite` package: Vite is a transitive dependency of plenty of
|
|
4188
|
-
* things — Vitest above all — and a project that has one for its tests and builds with webpack
|
|
4189
|
-
* is exactly the case this must not mistake for a Vite app.
|
|
4190
|
-
*/
|
|
4191
|
-
const VITE_CONFIG_FILES = [
|
|
4192
|
-
"vite.config.ts",
|
|
4193
|
-
"vite.config.js",
|
|
4194
|
-
"vite.config.mjs",
|
|
4195
|
-
"vite.config.mts",
|
|
4196
|
-
"vite.config.cjs",
|
|
4197
|
-
"vite.config.cts"
|
|
4198
|
-
];
|
|
4199
|
-
/** The project's Vite config, if it has one. Not resolved further than existence. */
|
|
4200
|
-
const findViteConfig = (cwd) => VITE_CONFIG_FILES.map((file) => (0, path.join)(cwd, file)).find((file) => (0, fs.existsSync)(file));
|
|
4201
|
-
/**
|
|
4202
|
-
* Frameworks that author styles in a file the Vite compiler does not transform.
|
|
4203
|
-
*
|
|
4204
|
-
* It compiles JavaScript and TypeScript. A `.svelte`, `.vue` or `.astro` file is a template
|
|
4205
|
-
* with a script in it, and the compiler leaves those alone — which for a Svelte or Vue project
|
|
4206
|
-
* makes the PostCSS integration the right one, not a downgrade. Worse than that: switching one
|
|
4207
|
-
* to `@bamboocss/vite` would prune every rule only its components reach, since reachability is
|
|
4208
|
-
* computed from modules the compiler saw, so the pages would render unstyled.
|
|
4209
|
-
*
|
|
4210
|
-
* So this is the exception to the advice, and it has to be checked before giving it.
|
|
4211
|
-
*/
|
|
4212
|
-
const TEMPLATE_EXTENSIONS = /\b(?:svelte|vue|astro|html|hbs|mdx?)\b/;
|
|
4213
|
-
const TEMPLATE_PACKAGES = [
|
|
4214
|
-
"svelte",
|
|
4215
|
-
"@sveltejs/kit",
|
|
4216
|
-
"vue",
|
|
4217
|
-
"nuxt",
|
|
4218
|
-
"astro"
|
|
4219
|
-
];
|
|
4220
|
-
/**
|
|
4221
|
-
* Does this project author styles somewhere the Vite compiler cannot reach?
|
|
4222
|
-
*
|
|
4223
|
-
* Two signals because the two callers know different things. A resolved config names the file
|
|
4224
|
-
* types directly, and is authoritative when it does; `bamboo init` runs before there is one,
|
|
4225
|
-
* so the dependency list stands in. Either one is enough — both directions of a wrong answer
|
|
4226
|
-
* here only decide whether advice is offered, and the advice is worth less than a Svelte
|
|
4227
|
-
* project being told to break itself.
|
|
4228
|
-
*/
|
|
4229
|
-
const hasUncompilableSources = (options) => {
|
|
4230
|
-
if (options.include?.some((glob) => TEMPLATE_EXTENSIONS.test(glob))) return true;
|
|
4231
|
-
try {
|
|
4232
|
-
const manifest = JSON.parse((0, fs.readFileSync)((0, path.join)(options.cwd, "package.json"), "utf8"));
|
|
4233
|
-
const dependencies = {
|
|
4234
|
-
...manifest.dependencies,
|
|
4235
|
-
...manifest.devDependencies
|
|
4236
|
-
};
|
|
4237
|
-
return TEMPLATE_PACKAGES.some((name) => name in dependencies);
|
|
4238
|
-
} catch {
|
|
4239
|
-
return false;
|
|
4240
|
-
}
|
|
4241
|
-
};
|
|
4242
|
-
//#endregion
|
|
4243
4187
|
//#region src/setup-config.ts
|
|
4244
4188
|
async function setupConfig(cwd, opts = {}) {
|
|
4245
4189
|
const { force, outExtension, outdir = "styled-system", strictValues } = opts;
|
|
@@ -4296,19 +4240,6 @@ strictValues: ${JSON.stringify(strictValues)},\n` : ""}
|
|
|
4296
4240
|
_bamboocss_logger.logger.log(_bamboocss_core.messages.thankYou());
|
|
4297
4241
|
}
|
|
4298
4242
|
}
|
|
4299
|
-
async function setupPostcss(cwd) {
|
|
4300
|
-
const viteConfig = findViteConfig(cwd);
|
|
4301
|
-
if (viteConfig && !hasUncompilableSources({ cwd })) _bamboocss_logger.logger.warn("init:postcss", `This project has ${(0, _bamboocss_logger.quote)((0, path.basename)(viteConfig))}, so ${(0, _bamboocss_logger.quote)("@bamboocss/vite")} is the integration to use. The PostCSS one emits CSS only: it does not compile source, so ${(0, _bamboocss_logger.quote)("css()")} and ${(0, _bamboocss_logger.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`);
|
|
4302
|
-
_bamboocss_logger.logger.info("init:postcss", `creating postcss config file: ${(0, _bamboocss_logger.quote)("postcss.config.cjs")}`);
|
|
4303
|
-
const content = outdent.outdent`
|
|
4304
|
-
module.exports = {
|
|
4305
|
-
plugins: {
|
|
4306
|
-
'@bamboocss/dev/postcss': {},
|
|
4307
|
-
},
|
|
4308
|
-
}
|
|
4309
|
-
`;
|
|
4310
|
-
await fs_extra.default.writeFile((0, path.join)(cwd, "postcss.config.cjs"), content);
|
|
4311
|
-
}
|
|
4312
4243
|
//#endregion
|
|
4313
4244
|
//#region src/spec.ts
|
|
4314
4245
|
async function spec(ctx, options) {
|
|
@@ -4332,6 +4263,55 @@ async function spec(ctx, options) {
|
|
|
4332
4263
|
return specs;
|
|
4333
4264
|
}
|
|
4334
4265
|
//#endregion
|
|
4266
|
+
//#region src/vite-integration.ts
|
|
4267
|
+
/**
|
|
4268
|
+
* Every extension Vite accepts for its config, so "is this a Vite project" is answered by the
|
|
4269
|
+
* same file Vite itself would load.
|
|
4270
|
+
*
|
|
4271
|
+
* A file rather than a resolvable `vite` package: Vite is a transitive dependency of plenty of
|
|
4272
|
+
* things — Vitest above all — and a project that has one for its tests and builds with webpack
|
|
4273
|
+
* is exactly the case this must not mistake for a Vite app.
|
|
4274
|
+
*/
|
|
4275
|
+
const VITE_CONFIG_FILES = [
|
|
4276
|
+
"vite.config.ts",
|
|
4277
|
+
"vite.config.js",
|
|
4278
|
+
"vite.config.mjs",
|
|
4279
|
+
"vite.config.mts",
|
|
4280
|
+
"vite.config.cjs",
|
|
4281
|
+
"vite.config.cts"
|
|
4282
|
+
];
|
|
4283
|
+
/** The project's Vite config, if it has one. Not resolved further than existence. */
|
|
4284
|
+
const findViteConfig = (cwd) => VITE_CONFIG_FILES.map((file) => (0, path.join)(cwd, file)).find((file) => (0, fs.existsSync)(file));
|
|
4285
|
+
/**
|
|
4286
|
+
* Frameworks that author styles in a file the Vite compiler does not transform as JavaScript
|
|
4287
|
+
* until a dedicated preprocessor exists. Vue, Svelte and Astro compile through
|
|
4288
|
+
* `bamboocss:compiler-sfc`. HTML / Handlebars templates still do not.
|
|
4289
|
+
*/
|
|
4290
|
+
const TEMPLATE_EXTENSIONS = /\b(?:html|hbs)\b/;
|
|
4291
|
+
const TEMPLATE_PACKAGES = [];
|
|
4292
|
+
/**
|
|
4293
|
+
* Does this project author styles somewhere the Vite compiler cannot reach?
|
|
4294
|
+
*
|
|
4295
|
+
* Two signals because the two callers know different things. A resolved config names the file
|
|
4296
|
+
* types directly, and is authoritative when it does; `bamboo init` runs before there is one,
|
|
4297
|
+
* so the dependency list stands in. Either one is enough — both directions of a wrong answer
|
|
4298
|
+
* here only decide whether advice is offered, and the advice is worth less than a Svelte
|
|
4299
|
+
* project being told to break itself.
|
|
4300
|
+
*/
|
|
4301
|
+
const hasUncompilableSources = (options) => {
|
|
4302
|
+
if (options.include?.some((glob) => TEMPLATE_EXTENSIONS.test(glob))) return true;
|
|
4303
|
+
try {
|
|
4304
|
+
const manifest = JSON.parse((0, fs.readFileSync)((0, path.join)(options.cwd, "package.json"), "utf8"));
|
|
4305
|
+
const dependencies = {
|
|
4306
|
+
...manifest.dependencies,
|
|
4307
|
+
...manifest.devDependencies
|
|
4308
|
+
};
|
|
4309
|
+
return TEMPLATE_PACKAGES.some((name) => name in dependencies);
|
|
4310
|
+
} catch {
|
|
4311
|
+
return false;
|
|
4312
|
+
}
|
|
4313
|
+
};
|
|
4314
|
+
//#endregion
|
|
4335
4315
|
exports.BambooContext = BambooContext;
|
|
4336
4316
|
exports.Builder = Builder;
|
|
4337
4317
|
exports.analyze = analyze;
|
|
@@ -4355,6 +4335,5 @@ exports.parseDependency = parseDependency;
|
|
|
4355
4335
|
exports.setLogStream = setLogStream;
|
|
4356
4336
|
exports.setupConfig = setupConfig;
|
|
4357
4337
|
exports.setupGitIgnore = setupGitIgnore;
|
|
4358
|
-
exports.setupPostcss = setupPostcss;
|
|
4359
4338
|
exports.spec = spec;
|
|
4360
4339
|
exports.startProfiling = startProfiling;
|
package/dist/index.d.cts
CHANGED
|
@@ -195,7 +195,11 @@ declare class BambooContext extends Generator {
|
|
|
195
195
|
results: ParserResult[];
|
|
196
196
|
};
|
|
197
197
|
writeCss: (sheet?: Stylesheet) => Promise<PromiseSettledResult<void>[]> | undefined;
|
|
198
|
-
writeSplitCss: (sheet: Stylesheet
|
|
198
|
+
writeSplitCss: (sheet: Stylesheet, {
|
|
199
|
+
includeRecipes
|
|
200
|
+
}?: {
|
|
201
|
+
includeRecipes?: boolean;
|
|
202
|
+
}) => Promise<void>;
|
|
199
203
|
watchConfig: (cb: (file: string) => void | Promise<void>, opts?: Omit<WatchOptions, "include">) => void;
|
|
200
204
|
watchFiles: (cb: (event: WatcherEventType, file: string) => void | Promise<void>, opts?: Omit<WatchOptions, "include" | "exclude" | "poll" | "cwd" | "logger">) => void;
|
|
201
205
|
}
|
|
@@ -447,7 +451,6 @@ type SetupOptions = Partial<Config> & {
|
|
|
447
451
|
force?: boolean;
|
|
448
452
|
};
|
|
449
453
|
declare function setupConfig(cwd: string, opts?: SetupOptions): Promise<void>;
|
|
450
|
-
declare function setupPostcss(cwd: string): Promise<void>;
|
|
451
454
|
//#endregion
|
|
452
455
|
//#region src/spec.d.ts
|
|
453
456
|
interface SpecOptions {
|
|
@@ -472,4 +475,4 @@ declare const hasUncompilableSources: (options: {
|
|
|
472
475
|
include?: readonly string[];
|
|
473
476
|
}) => boolean;
|
|
474
477
|
//#endregion
|
|
475
|
-
export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, findViteConfig, generate, generatePackageExports, hasUncompilableSources, isStaticCompilerActive, loadConfigAndCreateContext, markStaticCompilerActive, parseDependency, setLogStream, setupConfig, setupGitIgnore,
|
|
478
|
+
export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, findViteConfig, generate, generatePackageExports, hasUncompilableSources, isStaticCompilerActive, loadConfigAndCreateContext, markStaticCompilerActive, parseDependency, setLogStream, setupConfig, setupGitIgnore, spec, startProfiling };
|
package/dist/index.d.mts
CHANGED
|
@@ -195,7 +195,11 @@ declare class BambooContext extends Generator {
|
|
|
195
195
|
results: ParserResult[];
|
|
196
196
|
};
|
|
197
197
|
writeCss: (sheet?: Stylesheet) => Promise<PromiseSettledResult<void>[]> | undefined;
|
|
198
|
-
writeSplitCss: (sheet: Stylesheet
|
|
198
|
+
writeSplitCss: (sheet: Stylesheet, {
|
|
199
|
+
includeRecipes
|
|
200
|
+
}?: {
|
|
201
|
+
includeRecipes?: boolean;
|
|
202
|
+
}) => Promise<void>;
|
|
199
203
|
watchConfig: (cb: (file: string) => void | Promise<void>, opts?: Omit<WatchOptions, "include">) => void;
|
|
200
204
|
watchFiles: (cb: (event: WatcherEventType, file: string) => void | Promise<void>, opts?: Omit<WatchOptions, "include" | "exclude" | "poll" | "cwd" | "logger">) => void;
|
|
201
205
|
}
|
|
@@ -447,7 +451,6 @@ type SetupOptions = Partial<Config> & {
|
|
|
447
451
|
force?: boolean;
|
|
448
452
|
};
|
|
449
453
|
declare function setupConfig(cwd: string, opts?: SetupOptions): Promise<void>;
|
|
450
|
-
declare function setupPostcss(cwd: string): Promise<void>;
|
|
451
454
|
//#endregion
|
|
452
455
|
//#region src/spec.d.ts
|
|
453
456
|
interface SpecOptions {
|
|
@@ -472,4 +475,4 @@ declare const hasUncompilableSources: (options: {
|
|
|
472
475
|
include?: readonly string[];
|
|
473
476
|
}) => boolean;
|
|
474
477
|
//#endregion
|
|
475
|
-
export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, findViteConfig, generate, generatePackageExports, hasUncompilableSources, isStaticCompilerActive, loadConfigAndCreateContext, markStaticCompilerActive, parseDependency, setLogStream, setupConfig, setupGitIgnore,
|
|
478
|
+
export { BambooContext, Builder, type CssGenOptions, analyze, buildInfo, codegen, cssgen, debug, findViteConfig, generate, generatePackageExports, hasUncompilableSources, isStaticCompilerActive, loadConfigAndCreateContext, markStaticCompilerActive, parseDependency, setLogStream, setupConfig, setupGitIgnore, spec, startProfiling };
|
package/dist/index.mjs
CHANGED
|
@@ -2,13 +2,13 @@ import { isStaticCompilerActive, markStaticCompilerActive } from "./static-compi
|
|
|
2
2
|
import { Reporter, formatRecipeReport, formatTokenReport } from "@bamboocss/reporter";
|
|
3
3
|
import { colors, logger, quote } from "@bamboocss/logger";
|
|
4
4
|
import { convertTsPathsToRegexes, diffConfigs, findConfig, getConfigDependencies, loadConfig, mergeHooks } from "@bamboocss/config";
|
|
5
|
-
import { checkNamingAgreement, formatNamingDisagreement, messages, prunesPreflight } from "@bamboocss/core";
|
|
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";
|
|
@@ -2279,11 +2279,11 @@ var BambooContext = class extends Generator {
|
|
|
2279
2279
|
}]
|
|
2280
2280
|
});
|
|
2281
2281
|
};
|
|
2282
|
-
writeSplitCss = async (sheet) => {
|
|
2282
|
+
writeSplitCss = async (sheet, { includeRecipes = false } = {}) => {
|
|
2283
2283
|
const { path: pathUtil, fs } = this.runtime;
|
|
2284
2284
|
const rootDir = this.paths.root;
|
|
2285
2285
|
const stylesDir = [...rootDir, "styles"];
|
|
2286
|
-
const artifacts = this.getSplitCssArtifacts(sheet);
|
|
2286
|
+
const artifacts = this.getSplitCssArtifacts(sheet, { includeRecipes });
|
|
2287
2287
|
const subDirs = new Set([...artifacts.recipes, ...artifacts.themes].map((a) => a.dir).filter(Boolean));
|
|
2288
2288
|
fs.ensureDirSync(pathUtil.join(...stylesDir));
|
|
2289
2289
|
subDirs.forEach((dir) => fs.ensureDirSync(pathUtil.join(...stylesDir, dir)));
|
|
@@ -2330,6 +2330,12 @@ var BambooContext = class extends Generator {
|
|
|
2330
2330
|
code: artifacts.index
|
|
2331
2331
|
}]
|
|
2332
2332
|
});
|
|
2333
|
+
if (!includeRecipes) {
|
|
2334
|
+
const recipesIndex = pathUtil.join(...stylesDir, "recipes.css");
|
|
2335
|
+
const recipesDir = pathUtil.join(...stylesDir, "recipes");
|
|
2336
|
+
if (fs.existsSync(recipesIndex)) fs.rmFileSync(recipesIndex);
|
|
2337
|
+
if (fs.existsSync(recipesDir)) fs.rmFileSync(recipesDir);
|
|
2338
|
+
}
|
|
2333
2339
|
};
|
|
2334
2340
|
watchConfig = (cb, opts) => {
|
|
2335
2341
|
const { cwd, poll, exclude } = opts ?? {};
|
|
@@ -3276,6 +3282,42 @@ function collectRenderedElements(ctx) {
|
|
|
3276
3282
|
return found;
|
|
3277
3283
|
}
|
|
3278
3284
|
//#endregion
|
|
3285
|
+
//#region src/assemble-sheet.ts
|
|
3286
|
+
/**
|
|
3287
|
+
* One stylesheet from an already-extracted encoder.
|
|
3288
|
+
*
|
|
3289
|
+
* Vite, `bamboo cssgen`, and the CLI `bamboo` command all finish here so a recipe lowered to
|
|
3290
|
+
* atoms cannot have a different sheet depending on which integration asked for it.
|
|
3291
|
+
*/
|
|
3292
|
+
const assembleExtractedSheet = (ctx, { layerParams = false, includeRecipes = false, sourceScanCache, mtimeOf, sourceInventory } = {}) => {
|
|
3293
|
+
if (!includeRecipes && ctx.config.polyfill) throw new Error("bamboocss: the cascade-layer polyfill is incompatible with compiled atomic styles. The polyfill removes the utility-layer boundary required for safe atom reachability and renaming.");
|
|
3294
|
+
if (!includeRecipes) ctx.encoder.atomizeObservedRecipes();
|
|
3295
|
+
const sheet = ctx.createSheet();
|
|
3296
|
+
if (layerParams) if (includeRecipes) ctx.appendLayerParams(sheet);
|
|
3297
|
+
else {
|
|
3298
|
+
const recipeLayer = ctx.config.layers?.recipes ?? "recipes";
|
|
3299
|
+
sheet.layers.root.prepend(`@layer ${sheet.layers.layerNames.filter((name) => name !== recipeLayer).join(", ")};`);
|
|
3300
|
+
}
|
|
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
|
+
}
|
|
3308
|
+
const collectElements = prunesPreflight(ctx.config.preflight);
|
|
3309
|
+
const pruneKeyframes = Boolean(ctx.config.prune?.keyframes);
|
|
3310
|
+
const declaredKeyframes = pruneKeyframes ? keyframeNames(ctx) : [];
|
|
3311
|
+
const scans = ctx.config.prune?.tokens !== false || collectElements || pruneKeyframes ? collectSourceScans(ctx, {
|
|
3312
|
+
keyframeNames: declaredKeyframes,
|
|
3313
|
+
elements: collectElements
|
|
3314
|
+
}, sourceScanCache, mtimeOf, sourceInventory) : void 0;
|
|
3315
|
+
const reachableVars = pruneTokensForBuild(ctx, sheet, [], scans);
|
|
3316
|
+
if (collectElements && scans) ctx.prunePreflight(sheet, scans.elements);
|
|
3317
|
+
if (pruneKeyframes && scans) ctx.pruneKeyframes(sheet, scans.keyframeHits, reachableVars);
|
|
3318
|
+
return sheet;
|
|
3319
|
+
};
|
|
3320
|
+
//#endregion
|
|
3279
3321
|
//#region src/builder.ts
|
|
3280
3322
|
const fileModifiedMap = /* @__PURE__ */ new Map();
|
|
3281
3323
|
/**
|
|
@@ -3832,30 +3874,15 @@ var Builder = class {
|
|
|
3832
3874
|
*
|
|
3833
3875
|
* `extract` has to have run first: this reads the encoder rather than filling it.
|
|
3834
3876
|
*/
|
|
3835
|
-
toCss = ({ layerParams = false, includeRecipes =
|
|
3877
|
+
toCss = ({ layerParams = false, includeRecipes = false } = {}) => {
|
|
3836
3878
|
const ctx = this.getContextOrThrow();
|
|
3837
|
-
const sheet = ctx
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
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);
|
|
3879
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
3880
|
+
layerParams,
|
|
3881
|
+
includeRecipes,
|
|
3882
|
+
sourceScanCache: this.sourceScanCache,
|
|
3883
|
+
mtimeOf: (filePath) => this.filesMeta?.changes.get(filePath)?.mtime,
|
|
3884
|
+
sourceInventory: this.sourceInventory
|
|
3885
|
+
});
|
|
3859
3886
|
return ctx.getCss(sheet);
|
|
3860
3887
|
};
|
|
3861
3888
|
registerDependency = (fn) => {
|
|
@@ -3940,8 +3967,8 @@ const startProfiling = async (cwd, prefix, isWatching) => {
|
|
|
3940
3967
|
//#region src/cssgen.ts
|
|
3941
3968
|
const cssgen = async (ctx, options) => {
|
|
3942
3969
|
const { outfile, type, splitting } = options;
|
|
3943
|
-
const sheet = ctx.createSheet();
|
|
3944
3970
|
if (type) {
|
|
3971
|
+
const sheet = ctx.createSheet();
|
|
3945
3972
|
const done = logger.time.info(ctx.messages.cssArtifactComplete(type));
|
|
3946
3973
|
ctx.appendCssOfType(type, sheet);
|
|
3947
3974
|
if (type === "preflight" && prunesPreflight(ctx.config.preflight)) ctx.prunePreflight(sheet, collectRenderedElements(ctx));
|
|
@@ -3952,20 +3979,13 @@ const cssgen = async (ctx, options) => {
|
|
|
3952
3979
|
} else await ctx.writeCss(sheet);
|
|
3953
3980
|
done();
|
|
3954
3981
|
} else {
|
|
3955
|
-
const { files
|
|
3982
|
+
const { files } = ctx.parseFiles();
|
|
3956
3983
|
const done = logger.time.info(ctx.messages.buildComplete(files.length));
|
|
3957
|
-
ctx
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
const collectElements = prunesPreflight(ctx.config.preflight);
|
|
3961
|
-
const scans = collectSourceScans(ctx, {
|
|
3962
|
-
keyframeNames: ctx.config.prune?.keyframes ? keyframeNames(ctx) : [],
|
|
3963
|
-
elements: collectElements
|
|
3984
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
3985
|
+
layerParams: true,
|
|
3986
|
+
includeRecipes: false
|
|
3964
3987
|
});
|
|
3965
|
-
|
|
3966
|
-
if (collectElements) ctx.prunePreflight(sheet, scans.elements);
|
|
3967
|
-
if (ctx.config.prune?.keyframes) ctx.pruneKeyframes(sheet, scans.keyframeHits, reachableVars);
|
|
3968
|
-
if (splitting) await ctx.writeSplitCss(sheet);
|
|
3988
|
+
if (splitting) await ctx.writeSplitCss(sheet, { includeRecipes: false });
|
|
3969
3989
|
else if (outfile) {
|
|
3970
3990
|
const css = ctx.getCss(sheet);
|
|
3971
3991
|
logger.info("css", ctx.runtime.path.resolve(outfile));
|
|
@@ -4029,19 +4049,11 @@ async function build(ctx, artifactIds) {
|
|
|
4029
4049
|
await codegen(ctx, artifactIds);
|
|
4030
4050
|
if (ctx.config.emitTokensOnly) return logger.info("css:emit", "Successfully rebuilt the css variables and js function to query your tokens ✨");
|
|
4031
4051
|
const done = logger.time.info("");
|
|
4032
|
-
const sheet = ctx.createSheet();
|
|
4033
|
-
ctx.appendLayerParams(sheet);
|
|
4034
|
-
ctx.appendBaselineCss(sheet);
|
|
4035
4052
|
const parsed = ctx.parseFiles();
|
|
4036
|
-
ctx
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
keyframeNames: ctx.config.prune?.keyframes ? keyframeNames(ctx) : [],
|
|
4040
|
-
elements: collectElements
|
|
4053
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
4054
|
+
layerParams: true,
|
|
4055
|
+
includeRecipes: false
|
|
4041
4056
|
});
|
|
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);
|
|
4045
4057
|
await ctx.writeCss(sheet);
|
|
4046
4058
|
done(ctx.messages.buildComplete(parsed.files.length));
|
|
4047
4059
|
}
|
|
@@ -4082,18 +4094,10 @@ async function generate(config, configPath) {
|
|
|
4082
4094
|
if (parsed === 0) return;
|
|
4083
4095
|
const outfile = ctx.runtime.path.join(...ctx.paths.root, "styles.css");
|
|
4084
4096
|
const done = logger.time.info(ctx.messages.buildComplete(parsed));
|
|
4085
|
-
const sheet = ctx
|
|
4086
|
-
|
|
4087
|
-
|
|
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
|
|
4097
|
+
const sheet = assembleExtractedSheet(ctx, {
|
|
4098
|
+
layerParams: true,
|
|
4099
|
+
includeRecipes: false
|
|
4093
4100
|
});
|
|
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);
|
|
4097
4101
|
const css = ctx.getCss(sheet);
|
|
4098
4102
|
await ctx.runtime.fs.writeFile(outfile, css);
|
|
4099
4103
|
done();
|
|
@@ -4141,6 +4145,7 @@ const setLogStream = (options) => {
|
|
|
4141
4145
|
if (options.logfile) {
|
|
4142
4146
|
const outPath = path.resolve(cwd, options.logfile);
|
|
4143
4147
|
ensure(outPath);
|
|
4148
|
+
fs.closeSync(fs.openSync(outPath, "a"));
|
|
4144
4149
|
logger.info("logfile", outPath);
|
|
4145
4150
|
stream = fs.createWriteStream(outPath, { flags: "a" });
|
|
4146
4151
|
logger.onLog = (entry) => {
|
|
@@ -4165,67 +4170,6 @@ const ensure = (outPath) => {
|
|
|
4165
4170
|
return outPath;
|
|
4166
4171
|
};
|
|
4167
4172
|
//#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
4173
|
//#region src/setup-config.ts
|
|
4230
4174
|
async function setupConfig(cwd, opts = {}) {
|
|
4231
4175
|
const { force, outExtension, outdir = "styled-system", strictValues } = opts;
|
|
@@ -4282,19 +4226,6 @@ strictValues: ${JSON.stringify(strictValues)},\n` : ""}
|
|
|
4282
4226
|
logger.log(messages.thankYou());
|
|
4283
4227
|
}
|
|
4284
4228
|
}
|
|
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
4229
|
//#endregion
|
|
4299
4230
|
//#region src/spec.ts
|
|
4300
4231
|
async function spec(ctx, options) {
|
|
@@ -4318,4 +4249,53 @@ async function spec(ctx, options) {
|
|
|
4318
4249
|
return specs;
|
|
4319
4250
|
}
|
|
4320
4251
|
//#endregion
|
|
4321
|
-
|
|
4252
|
+
//#region src/vite-integration.ts
|
|
4253
|
+
/**
|
|
4254
|
+
* Every extension Vite accepts for its config, so "is this a Vite project" is answered by the
|
|
4255
|
+
* same file Vite itself would load.
|
|
4256
|
+
*
|
|
4257
|
+
* A file rather than a resolvable `vite` package: Vite is a transitive dependency of plenty of
|
|
4258
|
+
* things — Vitest above all — and a project that has one for its tests and builds with webpack
|
|
4259
|
+
* is exactly the case this must not mistake for a Vite app.
|
|
4260
|
+
*/
|
|
4261
|
+
const VITE_CONFIG_FILES = [
|
|
4262
|
+
"vite.config.ts",
|
|
4263
|
+
"vite.config.js",
|
|
4264
|
+
"vite.config.mjs",
|
|
4265
|
+
"vite.config.mts",
|
|
4266
|
+
"vite.config.cjs",
|
|
4267
|
+
"vite.config.cts"
|
|
4268
|
+
];
|
|
4269
|
+
/** The project's Vite config, if it has one. Not resolved further than existence. */
|
|
4270
|
+
const findViteConfig = (cwd) => VITE_CONFIG_FILES.map((file) => join(cwd, file)).find((file) => existsSync(file));
|
|
4271
|
+
/**
|
|
4272
|
+
* Frameworks that author styles in a file the Vite compiler does not transform as JavaScript
|
|
4273
|
+
* until a dedicated preprocessor exists. Vue, Svelte and Astro compile through
|
|
4274
|
+
* `bamboocss:compiler-sfc`. HTML / Handlebars templates still do not.
|
|
4275
|
+
*/
|
|
4276
|
+
const TEMPLATE_EXTENSIONS = /\b(?:html|hbs)\b/;
|
|
4277
|
+
const TEMPLATE_PACKAGES = [];
|
|
4278
|
+
/**
|
|
4279
|
+
* Does this project author styles somewhere the Vite compiler cannot reach?
|
|
4280
|
+
*
|
|
4281
|
+
* Two signals because the two callers know different things. A resolved config names the file
|
|
4282
|
+
* types directly, and is authoritative when it does; `bamboo init` runs before there is one,
|
|
4283
|
+
* so the dependency list stands in. Either one is enough — both directions of a wrong answer
|
|
4284
|
+
* here only decide whether advice is offered, and the advice is worth less than a Svelte
|
|
4285
|
+
* project being told to break itself.
|
|
4286
|
+
*/
|
|
4287
|
+
const hasUncompilableSources = (options) => {
|
|
4288
|
+
if (options.include?.some((glob) => TEMPLATE_EXTENSIONS.test(glob))) return true;
|
|
4289
|
+
try {
|
|
4290
|
+
const manifest = JSON.parse(readFileSync(join(options.cwd, "package.json"), "utf8"));
|
|
4291
|
+
const dependencies = {
|
|
4292
|
+
...manifest.dependencies,
|
|
4293
|
+
...manifest.devDependencies
|
|
4294
|
+
};
|
|
4295
|
+
return TEMPLATE_PACKAGES.some((name) => name in dependencies);
|
|
4296
|
+
} catch {
|
|
4297
|
+
return false;
|
|
4298
|
+
}
|
|
4299
|
+
};
|
|
4300
|
+
//#endregion
|
|
4301
|
+
export { BambooContext, Builder, analyze, buildInfo, codegen, cssgen, debug, findViteConfig, generate, generatePackageExports, hasUncompilableSources, isStaticCompilerActive, loadConfigAndCreateContext, markStaticCompilerActive, parseDependency, 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.47.0",
|
|
4
4
|
"description": "The core css bamboo library",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -65,17 +65,17 @@
|
|
|
65
65
|
"postcss": "8.5.26",
|
|
66
66
|
"ts-morph": "28.0.0",
|
|
67
67
|
"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.
|
|
68
|
+
"@bamboocss/config": "1.47.0",
|
|
69
|
+
"@bamboocss/core": "1.47.0",
|
|
70
|
+
"@bamboocss/generator": "1.47.0",
|
|
71
|
+
"@bamboocss/logger": "1.47.0",
|
|
72
|
+
"@bamboocss/parser": "1.47.0",
|
|
73
|
+
"@bamboocss/plugin-svelte": "1.47.0",
|
|
74
|
+
"@bamboocss/plugin-vue": "1.47.0",
|
|
75
|
+
"@bamboocss/reporter": "1.47.0",
|
|
76
|
+
"@bamboocss/shared": "1.47.0",
|
|
77
|
+
"@bamboocss/token-dictionary": "1.47.0",
|
|
78
|
+
"@bamboocss/types": "1.47.0"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@types/fs-extra": "11.0.4",
|