@bamboocss/vite 1.37.0 → 1.37.2

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
@@ -211,22 +211,23 @@ const carriesGeneratedCss = (output) => output.type === "asset" && output.fileNa
211
211
  */
212
212
  const optimizeStaticCssAssets = (bundle, session, options = {}) => {
213
213
  const { rename = true } = options;
214
- for (const [bundleName, output] of Object.entries(bundle)) {
214
+ for (const output of Object.values(bundle)) {
215
215
  if (!carriesGeneratedCss(output)) continue;
216
216
  const source = typeof output.source === "string" ? output.source : Buffer.from(output.source).toString();
217
217
  if (!source.includes("--made-with-bamboo")) continue;
218
218
  const optimized = pruneStaticCss(source, session);
219
219
  output.source = optimized;
220
220
  if (optimized === source) continue;
221
- if (!rename) continue;
221
+ if (!rename) {
222
+ output.source = source;
223
+ continue;
224
+ }
222
225
  const nextName = output.fileName.replace(/\.css$/, `.b-${(0, _bamboocss_shared.toHash)(optimized)}.css`);
223
226
  if (nextName === output.fileName) continue;
224
227
  if (bundle[nextName] && bundle[nextName] !== output) throw new Error(`bamboocss: final CSS asset name collision at ${JSON.stringify(nextName)}.`);
225
228
  const previous = output.fileName;
226
229
  output.fileName = nextName;
227
230
  replaceAssetReferences(bundle, previous, nextName, session.sourcemap);
228
- delete bundle[bundleName];
229
- bundle[nextName] = output;
230
231
  }
231
232
  };
232
233
  /**
@@ -244,6 +245,15 @@ const optimizeStaticCssAssets = (bundle, session, options = {}) => {
244
245
  */
245
246
  const bamboocssCss = (options) => {
246
247
  const { configPath, cwd, session, renameCssAsset = true } = options;
248
+ /**
249
+ * Environments whose `load` served the virtual stylesheet.
250
+ *
251
+ * The lost-sheet guard below is about an asset that existed and then went missing, so it
252
+ * can only be asked of an environment that asked for one. An SSR bundle never imports the
253
+ * stylesheet — the client build emits it — and firing there turned a correct two-environment
254
+ * build into a hard failure.
255
+ */
256
+ const servedEnvironments = /* @__PURE__ */ new Set();
247
257
  const builder = new _bamboocss_node.Builder();
248
258
  let server;
249
259
  let command = "build";
@@ -304,6 +314,7 @@ const bamboocssCss = (options) => {
304
314
  },
305
315
  async load(id) {
306
316
  if (id !== RESOLVED_ID) return null;
317
+ servedEnvironments.add(this.environment?.name ?? "default");
307
318
  let css;
308
319
  try {
309
320
  css = await generate();
@@ -332,8 +343,8 @@ const bamboocssCss = (options) => {
332
343
  generateBundle: {
333
344
  order: "post",
334
345
  handler(_, bundle) {
335
- const rolldown = Boolean(this.meta?.rolldownVersion);
336
- optimizeStaticCssAssets(bundle, session, { rename: renameCssAsset && !rolldown });
346
+ optimizeStaticCssAssets(bundle, session, { rename: renameCssAsset });
347
+ if (!servedEnvironments.has(this.environment?.name ?? "default")) return;
337
348
  if (!session.transformedFiles.size) return;
338
349
  if (!Object.values(bundle).some((output) => {
339
350
  if (!carriesGeneratedCss(output)) return false;
@@ -2763,6 +2774,8 @@ const formatSkipped = (id, skipped) => {
2763
2774
  const bamboocss = (options = {}) => {
2764
2775
  const { configPath, cwd, reportSkipped = false, reportSummary = true, maxRecipeStates, renameCssAsset = true } = options;
2765
2776
  if (maxRecipeStates !== void 0 && (!Number.isSafeInteger(maxRecipeStates) || maxRecipeStates < 1)) throw new Error("bamboocss: `maxRecipeStates` must be a positive safe integer.");
2777
+ /** Environments whose `buildStart` has run in the build currently in progress. */
2778
+ const seenEnvironments = /* @__PURE__ */ new Set();
2766
2779
  /** Totals across the build, for the summary. */
2767
2780
  const totals = {
2768
2781
  folded: 0,
@@ -2834,14 +2847,19 @@ const bamboocss = (options = {}) => {
2834
2847
  command = config.command;
2835
2848
  },
2836
2849
  async buildStart() {
2837
- totals.folded = 0;
2838
- totals.files = 0;
2839
- totals.filesWithFolds = 0;
2840
- totals.skipped.clear();
2841
- survivors.length = 0;
2842
- survivorKeys.clear();
2843
- recipeConfigCache.clear();
2844
- resetStaticCompilationSession(staticSession);
2850
+ const environment = this.environment?.name ?? "default";
2851
+ if (seenEnvironments.has(environment)) {
2852
+ seenEnvironments.clear();
2853
+ totals.folded = 0;
2854
+ totals.files = 0;
2855
+ totals.filesWithFolds = 0;
2856
+ totals.skipped.clear();
2857
+ survivors.length = 0;
2858
+ survivorKeys.clear();
2859
+ recipeConfigCache.clear();
2860
+ resetStaticCompilationSession(staticSession);
2861
+ }
2862
+ seenEnvironments.add(environment);
2845
2863
  try {
2846
2864
  await ensureContext();
2847
2865
  } catch (error) {
package/dist/index.d.cts CHANGED
@@ -39,17 +39,15 @@ interface BambooVitePluginOptions {
39
39
  /**
40
40
  * Give the pruned stylesheet a final name derived from its own bytes.
41
41
  *
42
- * Rollup expands `[hash]` before `generateBundle`, so pruning after it can leave two
43
- * different reachable subsets under one CDN key. Renaming closes that, at the cost of
44
- * replacing an entry in the output bundle — which not every consumer of the bundle
45
- * tolerates. Rolldown drops the asset outright (detected automatically, no flag needed),
46
- * and a framework that relocates assets itself, such as react-router's SSR build, can
47
- * lose track of the new name.
42
+ * Rollup and Rolldown both expand `[hash]` before `generateBundle`, so pruning after it can
43
+ * leave two different reachable subsets under one CDN key. Renaming the pruned stylesheet to
44
+ * a hash of its own bytes closes that.
48
45
  *
49
- * Turning it off keeps the pruned bytes and Vite's own content hash. That hash is computed
50
- * before pruning, so it stops describing the file exactly; in practice it still changes
51
- * whenever the extracted CSS does, and only a change that alters *reachability alone*
52
- * can now reuse a key. Prefer that over an asset your framework cannot find.
46
+ * Turning it off does not merely skip the rename it skips the pruning with it. The two are
47
+ * one operation: pruned bytes under a name describing the unpruned ones is how a stale
48
+ * stylesheet outlives a deploy, which is worse than shipping a larger sheet. Reach for this
49
+ * only when something downstream cannot follow a renamed asset, and expect the full
50
+ * extracted stylesheet when you do.
53
51
  *
54
52
  * @default true
55
53
  */
package/dist/index.d.mts CHANGED
@@ -39,17 +39,15 @@ interface BambooVitePluginOptions {
39
39
  /**
40
40
  * Give the pruned stylesheet a final name derived from its own bytes.
41
41
  *
42
- * Rollup expands `[hash]` before `generateBundle`, so pruning after it can leave two
43
- * different reachable subsets under one CDN key. Renaming closes that, at the cost of
44
- * replacing an entry in the output bundle — which not every consumer of the bundle
45
- * tolerates. Rolldown drops the asset outright (detected automatically, no flag needed),
46
- * and a framework that relocates assets itself, such as react-router's SSR build, can
47
- * lose track of the new name.
42
+ * Rollup and Rolldown both expand `[hash]` before `generateBundle`, so pruning after it can
43
+ * leave two different reachable subsets under one CDN key. Renaming the pruned stylesheet to
44
+ * a hash of its own bytes closes that.
48
45
  *
49
- * Turning it off keeps the pruned bytes and Vite's own content hash. That hash is computed
50
- * before pruning, so it stops describing the file exactly; in practice it still changes
51
- * whenever the extracted CSS does, and only a change that alters *reachability alone*
52
- * can now reuse a key. Prefer that over an asset your framework cannot find.
46
+ * Turning it off does not merely skip the rename it skips the pruning with it. The two are
47
+ * one operation: pruned bytes under a name describing the unpruned ones is how a stale
48
+ * stylesheet outlives a deploy, which is worse than shipping a larger sheet. Reach for this
49
+ * only when something downstream cannot follow a renamed asset, and expect the full
50
+ * extracted stylesheet when you do.
53
51
  *
54
52
  * @default true
55
53
  */
package/dist/index.mjs CHANGED
@@ -181,22 +181,23 @@ const carriesGeneratedCss = (output) => output.type === "asset" && output.fileNa
181
181
  */
182
182
  const optimizeStaticCssAssets = (bundle, session, options = {}) => {
183
183
  const { rename = true } = options;
184
- for (const [bundleName, output] of Object.entries(bundle)) {
184
+ for (const output of Object.values(bundle)) {
185
185
  if (!carriesGeneratedCss(output)) continue;
186
186
  const source = typeof output.source === "string" ? output.source : Buffer.from(output.source).toString();
187
187
  if (!source.includes("--made-with-bamboo")) continue;
188
188
  const optimized = pruneStaticCss(source, session);
189
189
  output.source = optimized;
190
190
  if (optimized === source) continue;
191
- if (!rename) continue;
191
+ if (!rename) {
192
+ output.source = source;
193
+ continue;
194
+ }
192
195
  const nextName = output.fileName.replace(/\.css$/, `.b-${toHash(optimized)}.css`);
193
196
  if (nextName === output.fileName) continue;
194
197
  if (bundle[nextName] && bundle[nextName] !== output) throw new Error(`bamboocss: final CSS asset name collision at ${JSON.stringify(nextName)}.`);
195
198
  const previous = output.fileName;
196
199
  output.fileName = nextName;
197
200
  replaceAssetReferences(bundle, previous, nextName, session.sourcemap);
198
- delete bundle[bundleName];
199
- bundle[nextName] = output;
200
201
  }
201
202
  };
202
203
  /**
@@ -214,6 +215,15 @@ const optimizeStaticCssAssets = (bundle, session, options = {}) => {
214
215
  */
215
216
  const bamboocssCss = (options) => {
216
217
  const { configPath, cwd, session, renameCssAsset = true } = options;
218
+ /**
219
+ * Environments whose `load` served the virtual stylesheet.
220
+ *
221
+ * The lost-sheet guard below is about an asset that existed and then went missing, so it
222
+ * can only be asked of an environment that asked for one. An SSR bundle never imports the
223
+ * stylesheet — the client build emits it — and firing there turned a correct two-environment
224
+ * build into a hard failure.
225
+ */
226
+ const servedEnvironments = /* @__PURE__ */ new Set();
217
227
  const builder = new Builder();
218
228
  let server;
219
229
  let command = "build";
@@ -274,6 +284,7 @@ const bamboocssCss = (options) => {
274
284
  },
275
285
  async load(id) {
276
286
  if (id !== RESOLVED_ID) return null;
287
+ servedEnvironments.add(this.environment?.name ?? "default");
277
288
  let css;
278
289
  try {
279
290
  css = await generate();
@@ -302,8 +313,8 @@ const bamboocssCss = (options) => {
302
313
  generateBundle: {
303
314
  order: "post",
304
315
  handler(_, bundle) {
305
- const rolldown = Boolean(this.meta?.rolldownVersion);
306
- optimizeStaticCssAssets(bundle, session, { rename: renameCssAsset && !rolldown });
316
+ optimizeStaticCssAssets(bundle, session, { rename: renameCssAsset });
317
+ if (!servedEnvironments.has(this.environment?.name ?? "default")) return;
307
318
  if (!session.transformedFiles.size) return;
308
319
  if (!Object.values(bundle).some((output) => {
309
320
  if (!carriesGeneratedCss(output)) return false;
@@ -2733,6 +2744,8 @@ const formatSkipped = (id, skipped) => {
2733
2744
  const bamboocss = (options = {}) => {
2734
2745
  const { configPath, cwd, reportSkipped = false, reportSummary = true, maxRecipeStates, renameCssAsset = true } = options;
2735
2746
  if (maxRecipeStates !== void 0 && (!Number.isSafeInteger(maxRecipeStates) || maxRecipeStates < 1)) throw new Error("bamboocss: `maxRecipeStates` must be a positive safe integer.");
2747
+ /** Environments whose `buildStart` has run in the build currently in progress. */
2748
+ const seenEnvironments = /* @__PURE__ */ new Set();
2736
2749
  /** Totals across the build, for the summary. */
2737
2750
  const totals = {
2738
2751
  folded: 0,
@@ -2804,14 +2817,19 @@ const bamboocss = (options = {}) => {
2804
2817
  command = config.command;
2805
2818
  },
2806
2819
  async buildStart() {
2807
- totals.folded = 0;
2808
- totals.files = 0;
2809
- totals.filesWithFolds = 0;
2810
- totals.skipped.clear();
2811
- survivors.length = 0;
2812
- survivorKeys.clear();
2813
- recipeConfigCache.clear();
2814
- resetStaticCompilationSession(staticSession);
2820
+ const environment = this.environment?.name ?? "default";
2821
+ if (seenEnvironments.has(environment)) {
2822
+ seenEnvironments.clear();
2823
+ totals.folded = 0;
2824
+ totals.files = 0;
2825
+ totals.filesWithFolds = 0;
2826
+ totals.skipped.clear();
2827
+ survivors.length = 0;
2828
+ survivorKeys.clear();
2829
+ recipeConfigCache.clear();
2830
+ resetStaticCompilationSession(staticSession);
2831
+ }
2832
+ seenEnvironments.add(environment);
2815
2833
  try {
2816
2834
  await ensureContext();
2817
2835
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/vite",
3
- "version": "1.37.0",
3
+ "version": "1.37.2",
4
4
  "description": "Vite integration for Bamboo CSS",
5
5
  "homepage": "https://bamboocss.com",
6
6
  "license": "MIT",
@@ -40,18 +40,18 @@
40
40
  "postcss": "8.5.26",
41
41
  "postcss-selector-parser": "7.1.5",
42
42
  "ts-morph": "28.0.0",
43
- "@bamboocss/config": "1.37.0",
44
- "@bamboocss/core": "1.37.0",
45
- "@bamboocss/extractor": "1.37.0",
46
- "@bamboocss/logger": "1.37.0",
47
- "@bamboocss/node": "1.37.0",
48
- "@bamboocss/shared": "1.37.0",
49
- "@bamboocss/types": "1.37.0"
43
+ "@bamboocss/config": "1.37.2",
44
+ "@bamboocss/core": "1.37.2",
45
+ "@bamboocss/extractor": "1.37.2",
46
+ "@bamboocss/logger": "1.37.2",
47
+ "@bamboocss/node": "1.37.2",
48
+ "@bamboocss/shared": "1.37.2",
49
+ "@bamboocss/types": "1.37.2"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@jridgewell/trace-mapping": "^0.3.31",
53
53
  "vite": "7.2.6",
54
- "@bamboocss/fixture": "1.37.0"
54
+ "@bamboocss/fixture": "1.37.2"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "vite": ">=5"