@bamboocss/node 1.19.0 → 1.20.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/dist/index.cjs CHANGED
@@ -28,6 +28,8 @@ let _bamboocss_config = require("@bamboocss/config");
28
28
  let _bamboocss_shared = require("@bamboocss/shared");
29
29
  let fs = require("fs");
30
30
  let path = require("path");
31
+ let postcss = require("postcss");
32
+ postcss = __toESM(postcss);
31
33
  let _bamboocss_plugin_lightningcss = require("@bamboocss/plugin-lightningcss");
32
34
  let _bamboocss_plugin_svelte = require("@bamboocss/plugin-svelte");
33
35
  let _bamboocss_plugin_vue = require("@bamboocss/plugin-vue");
@@ -2238,6 +2240,30 @@ const keyframeNames = (ctx) => Object.keys(ctx.config.theme?.keyframes ?? {});
2238
2240
  //#endregion
2239
2241
  //#region src/builder.ts
2240
2242
  const fileModifiedMap = /* @__PURE__ */ new Map();
2243
+ /**
2244
+ * Bracket the css `write` injects, so a second pass replaces it instead of adding to it.
2245
+ *
2246
+ * Comments rather than a node flag: the root can be stringified and re-parsed between two
2247
+ * plugins in the same chain, and nothing on the node itself survives that round trip.
2248
+ */
2249
+ const INJECTED_START = "bamboocss:start";
2250
+ const INJECTED_END = "bamboocss:end";
2251
+ /**
2252
+ * Remove a previously injected block, markers included.
2253
+ *
2254
+ * Bounded by the end marker rather than running to the end of the root, so anything a later
2255
+ * plugin appended after the injection is left where it is. A start marker with no end -- the
2256
+ * shape a minifier that strips comments unevenly could leave behind -- removes nothing,
2257
+ * which is the safe direction: a duplicate is a size problem, dropping a user's css is not.
2258
+ */
2259
+ function dropPreviousInjection(root) {
2260
+ const nodes = root.nodes ?? [];
2261
+ const start = nodes.findIndex((n) => n.type === "comment" && n.text === INJECTED_START);
2262
+ if (start < 0) return;
2263
+ const end = nodes.findIndex((n, i) => i > start && n.type === "comment" && n.text === INJECTED_END);
2264
+ if (end < 0) return;
2265
+ for (const node of nodes.slice(start, end + 1)) node.remove();
2266
+ }
2241
2267
  var Builder = class {
2242
2268
  /**
2243
2269
  * The current bamboo context
@@ -2378,9 +2404,13 @@ var Builder = class {
2378
2404
  const sheet = ctx.createSheet();
2379
2405
  ctx.appendBaselineCss(sheet);
2380
2406
  if (ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, []));
2407
+ else ctx.pruneTokens(sheet);
2381
2408
  if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2382
2409
  const css = ctx.getCss(sheet);
2410
+ dropPreviousInjection(root);
2411
+ root.append(postcss.default.comment({ text: INJECTED_START }));
2383
2412
  root.append(css);
2413
+ root.append(postcss.default.comment({ text: INJECTED_END }));
2384
2414
  };
2385
2415
  registerDependency = (fn) => {
2386
2416
  const ctx = this.getContextOrThrow();
@@ -2482,6 +2512,7 @@ const cssgen = async (ctx, options) => {
2482
2512
  }
2483
2513
  ctx.appendParserCss(sheet);
2484
2514
  if (!minimal && ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, results));
2515
+ else if (!minimal) ctx.pruneTokens(sheet);
2485
2516
  if (!minimal && ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2486
2517
  if (splitting) await ctx.writeSplitCss(sheet);
2487
2518
  else if (outfile) {
@@ -2553,6 +2584,7 @@ async function build(ctx, artifactIds) {
2553
2584
  const parsed = ctx.parseFiles();
2554
2585
  ctx.appendParserCss(sheet);
2555
2586
  if (ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, parsed.results));
2587
+ else ctx.pruneTokens(sheet);
2556
2588
  if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2557
2589
  await ctx.writeCss(sheet);
2558
2590
  done(ctx.messages.buildComplete(parsed.files.length));
@@ -2699,12 +2731,11 @@ export default defineConfig({
2699
2731
  // Files to exclude
2700
2732
  exclude: [],
2701
2733
 
2702
- // Drop tokens, keyframes and @property rules nothing in the emitted css reaches. Worth 50-60% of a new
2703
- // project's stylesheet. Turn off if you read tokens from somewhere the build cannot
2704
- // see them — \`token.var()\` with a computed path, or a hand-written stylesheet outside
2705
- // \`include\` — or list those under \`staticCss\` to keep them.
2706
- pruneUnusedTokens: true,
2707
- pruneUnusedKeyframes: true,
2734
+ // Tokens, keyframes and @property rules nothing in the emitted css reaches are dropped
2735
+ // by default — worth 50-60% of a new project's stylesheet. Set \`pruneUnusedTokens: false\`
2736
+ // if you read tokens from somewhere the build cannot see them — \`token.var()\` with a
2737
+ // computed path, or a hand-written stylesheet outside \`include\` — or list those under
2738
+ // \`staticCss\` to keep them.
2708
2739
 
2709
2740
  // Useful for theme customization
2710
2741
  theme: {
package/dist/index.d.mts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { ReportFormat } from "@bamboocss/reporter";
2
+ import { Message, Root } from "postcss";
2
3
  import { StyleEncoder, Stylesheet } from "@bamboocss/core";
3
4
  import { Generator } from "@bamboocss/generator";
4
5
  import { ParserResult, Project } from "@bamboocss/parser";
5
6
  import { AnalysisOptions, Artifact, ArtifactId, BambooHooks, Config, CssArtifactType, LoadConfigResult, Runtime, SpecFile, WatchOptions, WatcherEventType } from "@bamboocss/types";
6
- import { Message, Root } from "postcss";
7
7
 
8
8
  //#region src/diff-engine.d.ts
9
9
  declare class DiffEngine {
package/dist/index.mjs CHANGED
@@ -4,6 +4,7 @@ import { convertTsPathsToRegexes, diffConfigs, findConfig, getConfigDependencies
4
4
  import { BambooError, cssVarRefs, uniq } from "@bamboocss/shared";
5
5
  import { appendFileSync, existsSync, readFileSync, statSync, writeFileSync } from "fs";
6
6
  import { dirname, extname, isAbsolute, join, normalize, parse, relative, resolve, sep } from "path";
7
+ import postcss from "postcss";
7
8
  import { pluginLightningcss } from "@bamboocss/plugin-lightningcss";
8
9
  import { pluginSvelte } from "@bamboocss/plugin-svelte";
9
10
  import { pluginVue } from "@bamboocss/plugin-vue";
@@ -2223,6 +2224,30 @@ const keyframeNames = (ctx) => Object.keys(ctx.config.theme?.keyframes ?? {});
2223
2224
  //#endregion
2224
2225
  //#region src/builder.ts
2225
2226
  const fileModifiedMap = /* @__PURE__ */ new Map();
2227
+ /**
2228
+ * Bracket the css `write` injects, so a second pass replaces it instead of adding to it.
2229
+ *
2230
+ * Comments rather than a node flag: the root can be stringified and re-parsed between two
2231
+ * plugins in the same chain, and nothing on the node itself survives that round trip.
2232
+ */
2233
+ const INJECTED_START = "bamboocss:start";
2234
+ const INJECTED_END = "bamboocss:end";
2235
+ /**
2236
+ * Remove a previously injected block, markers included.
2237
+ *
2238
+ * Bounded by the end marker rather than running to the end of the root, so anything a later
2239
+ * plugin appended after the injection is left where it is. A start marker with no end -- the
2240
+ * shape a minifier that strips comments unevenly could leave behind -- removes nothing,
2241
+ * which is the safe direction: a duplicate is a size problem, dropping a user's css is not.
2242
+ */
2243
+ function dropPreviousInjection(root) {
2244
+ const nodes = root.nodes ?? [];
2245
+ const start = nodes.findIndex((n) => n.type === "comment" && n.text === INJECTED_START);
2246
+ if (start < 0) return;
2247
+ const end = nodes.findIndex((n, i) => i > start && n.type === "comment" && n.text === INJECTED_END);
2248
+ if (end < 0) return;
2249
+ for (const node of nodes.slice(start, end + 1)) node.remove();
2250
+ }
2226
2251
  var Builder = class {
2227
2252
  /**
2228
2253
  * The current bamboo context
@@ -2363,9 +2388,13 @@ var Builder = class {
2363
2388
  const sheet = ctx.createSheet();
2364
2389
  ctx.appendBaselineCss(sheet);
2365
2390
  if (ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, []));
2391
+ else ctx.pruneTokens(sheet);
2366
2392
  if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2367
2393
  const css = ctx.getCss(sheet);
2394
+ dropPreviousInjection(root);
2395
+ root.append(postcss.comment({ text: INJECTED_START }));
2368
2396
  root.append(css);
2397
+ root.append(postcss.comment({ text: INJECTED_END }));
2369
2398
  };
2370
2399
  registerDependency = (fn) => {
2371
2400
  const ctx = this.getContextOrThrow();
@@ -2467,6 +2496,7 @@ const cssgen = async (ctx, options) => {
2467
2496
  }
2468
2497
  ctx.appendParserCss(sheet);
2469
2498
  if (!minimal && ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, results));
2499
+ else if (!minimal) ctx.pruneTokens(sheet);
2470
2500
  if (!minimal && ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2471
2501
  if (splitting) await ctx.writeSplitCss(sheet);
2472
2502
  else if (outfile) {
@@ -2538,6 +2568,7 @@ async function build(ctx, artifactIds) {
2538
2568
  const parsed = ctx.parseFiles();
2539
2569
  ctx.appendParserCss(sheet);
2540
2570
  if (ctx.config.pruneUnusedTokens) ctx.pruneTokens(sheet, collectTokenReferences(ctx, parsed.results));
2571
+ else ctx.pruneTokens(sheet);
2541
2572
  if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2542
2573
  await ctx.writeCss(sheet);
2543
2574
  done(ctx.messages.buildComplete(parsed.files.length));
@@ -2684,12 +2715,11 @@ export default defineConfig({
2684
2715
  // Files to exclude
2685
2716
  exclude: [],
2686
2717
 
2687
- // Drop tokens, keyframes and @property rules nothing in the emitted css reaches. Worth 50-60% of a new
2688
- // project's stylesheet. Turn off if you read tokens from somewhere the build cannot
2689
- // see them — \`token.var()\` with a computed path, or a hand-written stylesheet outside
2690
- // \`include\` — or list those under \`staticCss\` to keep them.
2691
- pruneUnusedTokens: true,
2692
- pruneUnusedKeyframes: true,
2718
+ // Tokens, keyframes and @property rules nothing in the emitted css reaches are dropped
2719
+ // by default — worth 50-60% of a new project's stylesheet. Set \`pruneUnusedTokens: false\`
2720
+ // if you read tokens from somewhere the build cannot see them — \`token.var()\` with a
2721
+ // computed path, or a hand-written stylesheet outside \`include\` — or list those under
2722
+ // \`staticCss\` to keep them.
2693
2723
 
2694
2724
  // Useful for theme customization
2695
2725
  theme: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/node",
3
- "version": "1.19.0",
3
+ "version": "1.20.1",
4
4
  "description": "The core css bamboo library",
5
5
  "homepage": "https://bamboocss.com",
6
6
  "license": "MIT",
@@ -33,8 +33,8 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "browserslist": "4.28.1",
37
- "chokidar": "4.0.3",
36
+ "browserslist": "4.28.7",
37
+ "chokidar": "5.0.0",
38
38
  "fast-glob": "3.3.3",
39
39
  "fs-extra": "11.3.2",
40
40
  "get-tsconfig": "^4.13.0",
@@ -46,24 +46,24 @@
46
46
  "p-limit": "5.0.0",
47
47
  "package-manager-detector": "1.6.0",
48
48
  "perfect-debounce": "1.0.0",
49
- "picomatch": "4.0.4",
49
+ "picomatch": "4.0.5",
50
50
  "pkg-types": "2.3.0",
51
51
  "pluralize": "8.0.0",
52
- "postcss": "8.5.25",
52
+ "postcss": "8.5.26",
53
53
  "ts-morph": "28.0.0",
54
54
  "ts-pattern": "5.9.0",
55
- "@bamboocss/config": "1.19.0",
56
- "@bamboocss/core": "1.19.0",
57
- "@bamboocss/generator": "1.19.0",
58
- "@bamboocss/logger": "1.19.0",
59
- "@bamboocss/parser": "1.19.0",
60
- "@bamboocss/plugin-lightningcss": "1.19.0",
61
- "@bamboocss/plugin-svelte": "1.19.0",
62
- "@bamboocss/plugin-vue": "1.19.0",
63
- "@bamboocss/reporter": "1.19.0",
64
- "@bamboocss/shared": "1.19.0",
65
- "@bamboocss/token-dictionary": "1.19.0",
66
- "@bamboocss/types": "1.19.0"
55
+ "@bamboocss/config": "1.20.1",
56
+ "@bamboocss/core": "1.20.1",
57
+ "@bamboocss/generator": "1.20.1",
58
+ "@bamboocss/logger": "1.20.1",
59
+ "@bamboocss/parser": "1.20.1",
60
+ "@bamboocss/plugin-lightningcss": "1.20.1",
61
+ "@bamboocss/plugin-svelte": "1.20.1",
62
+ "@bamboocss/plugin-vue": "1.20.1",
63
+ "@bamboocss/reporter": "1.20.1",
64
+ "@bamboocss/shared": "1.20.1",
65
+ "@bamboocss/token-dictionary": "1.20.1",
66
+ "@bamboocss/types": "1.20.1"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/fs-extra": "11.0.4",