@bamboocss/node 1.20.1 → 1.20.3

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,8 +28,6 @@ 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);
33
31
  let _bamboocss_plugin_lightningcss = require("@bamboocss/plugin-lightningcss");
34
32
  let _bamboocss_plugin_svelte = require("@bamboocss/plugin-svelte");
35
33
  let _bamboocss_plugin_vue = require("@bamboocss/plugin-vue");
@@ -2241,28 +2239,22 @@ const keyframeNames = (ctx) => Object.keys(ctx.config.theme?.keyframes ?? {});
2241
2239
  //#region src/builder.ts
2242
2240
  const fileModifiedMap = /* @__PURE__ */ new Map();
2243
2241
  /**
2244
- * Bracket the css `write` injects, so a second pass replaces it instead of adding to it.
2242
+ * The declaration that says generated css is already present in a root.
2245
2243
  *
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.
2244
+ * `generateGlobalCss` emits it unconditionally and `appendBaselineCss` always reaches that
2245
+ * artifact, so anything carrying it holds a copy of the sheet however it got there — written
2246
+ * by `write` on an earlier pass, or inlined from `styles.css` by `postcss-import`.
2253
2247
  *
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.
2248
+ * A declaration rather than a comment because it has to survive the css being minified
2249
+ * between the copy landing and this check running, which a comment does not.
2258
2250
  */
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();
2251
+ const GENERATED_SENTINEL = "--made-with-bamboo";
2252
+ function hasGeneratedCss(root) {
2253
+ let found = false;
2254
+ root.walkDecls(GENERATED_SENTINEL, () => {
2255
+ found = true;
2256
+ });
2257
+ return found;
2266
2258
  }
2267
2259
  var Builder = class {
2268
2260
  /**
@@ -2400,6 +2392,10 @@ var Builder = class {
2400
2392
  return valid;
2401
2393
  };
2402
2394
  write = (root) => {
2395
+ if (hasGeneratedCss(root)) {
2396
+ _bamboocss_logger.logger.warn("postcss", "Generated css is already present in this file, so nothing was injected. It is imported and generated here at once — keep the `@import` of `styles.css` or the `@layer` statement that the postcss plugin injects at, not both.");
2397
+ return;
2398
+ }
2403
2399
  const ctx = this.getContextOrThrow();
2404
2400
  const sheet = ctx.createSheet();
2405
2401
  ctx.appendBaselineCss(sheet);
@@ -2407,10 +2403,7 @@ var Builder = class {
2407
2403
  else ctx.pruneTokens(sheet);
2408
2404
  if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2409
2405
  const css = ctx.getCss(sheet);
2410
- dropPreviousInjection(root);
2411
- root.append(postcss.default.comment({ text: INJECTED_START }));
2412
2406
  root.append(css);
2413
- root.append(postcss.default.comment({ text: INJECTED_END }));
2414
2407
  };
2415
2408
  registerDependency = (fn) => {
2416
2409
  const ctx = this.getContextOrThrow();
package/dist/index.d.mts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { ReportFormat } from "@bamboocss/reporter";
2
- import { Message, Root } from "postcss";
3
2
  import { StyleEncoder, Stylesheet } from "@bamboocss/core";
4
3
  import { Generator } from "@bamboocss/generator";
5
4
  import { ParserResult, Project } from "@bamboocss/parser";
6
5
  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,7 +4,6 @@ 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";
8
7
  import { pluginLightningcss } from "@bamboocss/plugin-lightningcss";
9
8
  import { pluginSvelte } from "@bamboocss/plugin-svelte";
10
9
  import { pluginVue } from "@bamboocss/plugin-vue";
@@ -2225,28 +2224,22 @@ const keyframeNames = (ctx) => Object.keys(ctx.config.theme?.keyframes ?? {});
2225
2224
  //#region src/builder.ts
2226
2225
  const fileModifiedMap = /* @__PURE__ */ new Map();
2227
2226
  /**
2228
- * Bracket the css `write` injects, so a second pass replaces it instead of adding to it.
2227
+ * The declaration that says generated css is already present in a root.
2229
2228
  *
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.
2229
+ * `generateGlobalCss` emits it unconditionally and `appendBaselineCss` always reaches that
2230
+ * artifact, so anything carrying it holds a copy of the sheet however it got there — written
2231
+ * by `write` on an earlier pass, or inlined from `styles.css` by `postcss-import`.
2237
2232
  *
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.
2233
+ * A declaration rather than a comment because it has to survive the css being minified
2234
+ * between the copy landing and this check running, which a comment does not.
2242
2235
  */
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();
2236
+ const GENERATED_SENTINEL = "--made-with-bamboo";
2237
+ function hasGeneratedCss(root) {
2238
+ let found = false;
2239
+ root.walkDecls(GENERATED_SENTINEL, () => {
2240
+ found = true;
2241
+ });
2242
+ return found;
2250
2243
  }
2251
2244
  var Builder = class {
2252
2245
  /**
@@ -2384,6 +2377,10 @@ var Builder = class {
2384
2377
  return valid;
2385
2378
  };
2386
2379
  write = (root) => {
2380
+ if (hasGeneratedCss(root)) {
2381
+ 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.");
2382
+ return;
2383
+ }
2387
2384
  const ctx = this.getContextOrThrow();
2388
2385
  const sheet = ctx.createSheet();
2389
2386
  ctx.appendBaselineCss(sheet);
@@ -2391,10 +2388,7 @@ var Builder = class {
2391
2388
  else ctx.pruneTokens(sheet);
2392
2389
  if (ctx.config.pruneUnusedKeyframes) ctx.pruneKeyframes(sheet, collectKeyframeReferences(ctx, keyframeNames(ctx)));
2393
2390
  const css = ctx.getCss(sheet);
2394
- dropPreviousInjection(root);
2395
- root.append(postcss.comment({ text: INJECTED_START }));
2396
2391
  root.append(css);
2397
- root.append(postcss.comment({ text: INJECTED_END }));
2398
2392
  };
2399
2393
  registerDependency = (fn) => {
2400
2394
  const ctx = this.getContextOrThrow();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/node",
3
- "version": "1.20.1",
3
+ "version": "1.20.3",
4
4
  "description": "The core css bamboo library",
5
5
  "homepage": "https://bamboocss.com",
6
6
  "license": "MIT",
@@ -52,18 +52,18 @@
52
52
  "postcss": "8.5.26",
53
53
  "ts-morph": "28.0.0",
54
54
  "ts-pattern": "5.9.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"
55
+ "@bamboocss/logger": "1.20.3",
56
+ "@bamboocss/core": "1.20.3",
57
+ "@bamboocss/parser": "1.20.3",
58
+ "@bamboocss/plugin-lightningcss": "1.20.3",
59
+ "@bamboocss/plugin-svelte": "1.20.3",
60
+ "@bamboocss/plugin-vue": "1.20.3",
61
+ "@bamboocss/reporter": "1.20.3",
62
+ "@bamboocss/shared": "1.20.3",
63
+ "@bamboocss/token-dictionary": "1.20.3",
64
+ "@bamboocss/types": "1.20.3",
65
+ "@bamboocss/generator": "1.20.3",
66
+ "@bamboocss/config": "1.20.3"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@types/fs-extra": "11.0.4",