@bamboocss/vite 1.48.0 → 1.48.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
@@ -79,6 +79,31 @@ const createCompilationHost = (options = {}) => {
79
79
  let openSetup;
80
80
  let openSetupStale = false;
81
81
  let cssPass;
82
+ let changedSourceFiles = /* @__PURE__ */ new Set();
83
+ let needsInventoryScan = false;
84
+ let needsConfigReload = false;
85
+ const recordSourceChange = (filePath, event, options) => {
86
+ changedSourceFiles.add(filePath);
87
+ if (event !== "update") needsInventoryScan = true;
88
+ needsConfigReload ||= options?.needsConfigReload === true;
89
+ openSetupStale = true;
90
+ };
91
+ const takeSourceChanges = () => {
92
+ const changes = {
93
+ files: [...changedSourceFiles].sort(),
94
+ needsInventoryScan,
95
+ ...needsConfigReload ? { needsConfigReload: true } : {}
96
+ };
97
+ changedSourceFiles = /* @__PURE__ */ new Set();
98
+ needsInventoryScan = false;
99
+ needsConfigReload = false;
100
+ return changes;
101
+ };
102
+ const restoreSourceChanges = (changes) => {
103
+ for (const file of changes.files) changedSourceFiles.add(file);
104
+ needsInventoryScan ||= changes.needsInventoryScan === true;
105
+ needsConfigReload ||= changes.needsConfigReload === true;
106
+ };
82
107
  const settled = async (attempt) => {
83
108
  try {
84
109
  await attempt;
@@ -95,12 +120,19 @@ const createCompilationHost = (options = {}) => {
95
120
  };
96
121
  const runSetup = async () => {
97
122
  builder ??= await loadBuilder();
98
- await builder.setup({
99
- configPath,
100
- cwd,
101
- dev: command === "serve"
102
- });
103
- return publish();
123
+ const sourceChanges = takeSourceChanges();
124
+ try {
125
+ await builder.setup({
126
+ configPath,
127
+ cwd,
128
+ dev: command === "serve",
129
+ ...command === "serve" ? { sourceChanges } : {}
130
+ });
131
+ return publish();
132
+ } catch (error) {
133
+ if (command === "serve") restoreSourceChanges(sourceChanges);
134
+ throw error;
135
+ }
104
136
  };
105
137
  /**
106
138
  * The setup covering the pass currently open, started at most once.
@@ -153,12 +185,15 @@ const createCompilationHost = (options = {}) => {
153
185
  while (cssPass) await settled(cssPass);
154
186
  return run();
155
187
  },
188
+ noteSourceChange(filePath, event, options) {
189
+ if (command === "serve") recordSourceChange(filePath, event, options);
190
+ },
156
191
  reloadSource(filePath) {
157
- openSetupStale = true;
192
+ recordSourceChange(filePath, "update");
158
193
  builder?.reloadSource(filePath);
159
194
  },
160
195
  removeSource(filePath) {
161
- openSetupStale = true;
196
+ recordSourceChange(filePath, "update");
162
197
  builder?.removeSource(filePath);
163
198
  }
164
199
  };
@@ -290,12 +325,17 @@ const bamboocssCss = (options) => {
290
325
  let command = "build";
291
326
  /** The run's own `build` options, for a bundler with no per-environment config. */
292
327
  let ssrBuildOptions;
293
- /** Included owners plus local modules their extraction actually resolved and read. */
328
+ /** Every source, resolver input and expanded config dependency which can change the sheet. */
294
329
  const extractedSourceFiles = () => {
295
330
  const activeBuilder = builder;
296
331
  const context = activeBuilder?.context;
297
332
  if (!context) return [];
298
- return [...new Set([...context.getFiles(), ...activeBuilder.getResolutionReadFiles()].map((file) => context.runtime.path.abs(context.config.cwd, file)))];
333
+ return [...new Set([
334
+ ...activeBuilder.getSourceFiles(),
335
+ ...activeBuilder.getResolutionReadFiles(),
336
+ ...activeBuilder.getResolutionConfigurationFiles(),
337
+ ...context.explicitDeps
338
+ ].map((file) => context.runtime.path.abs(context.config.cwd, file)))];
299
339
  };
300
340
  /**
301
341
  * Serialised, because both `load` and the watcher can reach it and `Builder` keeps one
@@ -549,23 +589,27 @@ const bamboocssCss = (options) => {
549
589
  * about. Vite 5 has one graph and no `environments`, where the question is exact.
550
590
  */
551
591
  const clientGraph = devServer.environments?.client?.moduleGraph ?? devServer.moduleGraph;
552
- const invalidate = (file) => {
553
- const ctx = builder?.context;
592
+ const invalidate = (file, event) => {
593
+ const activeBuilder = builder;
594
+ const ctx = activeBuilder?.context;
554
595
  if (!ctx) return;
555
596
  const absoluteFile = ctx.runtime.path.abs(ctx.config.cwd, file);
556
- if (!session.extractedFiles.has(absoluteFile)) return;
597
+ const wasExtracted = session.extractedFiles.has(absoluteFile);
598
+ const changesConfigMembership = event !== "update" && activeBuilder.isPotentialConfigDependency(absoluteFile);
599
+ if (!wasExtracted && (event !== "create" || !activeBuilder.isPotentialSourceFile(absoluteFile) && !changesConfigMembership)) return;
600
+ host.noteSourceChange(absoluteFile, event, { needsConfigReload: changesConfigMembership });
557
601
  changeGeneration++;
558
602
  prebuilt = void 0;
559
603
  const mod = server?.moduleGraph.getModuleById(RESOLVED_ID);
560
604
  if (!mod) return;
561
- if (clientGraph.getModulesByFile(absoluteFile)?.size) return;
605
+ if (wasExtracted && clientGraph.getModulesByFile(absoluteFile)?.size) return;
562
606
  server?.moduleGraph.invalidateModule(mod);
563
607
  server?.reloadModule(mod);
564
608
  _bamboocss_logger.logger.debug("vite", `styles invalidated by ${absoluteFile}`);
565
609
  };
566
- devServer.watcher.on("change", invalidate);
567
- devServer.watcher.on("add", invalidate);
568
- devServer.watcher.on("unlink", invalidate);
610
+ devServer.watcher.on("change", (file) => invalidate(file, "update"));
611
+ devServer.watcher.on("add", (file) => invalidate(file, "create"));
612
+ devServer.watcher.on("unlink", (file) => invalidate(file, "delete"));
569
613
  },
570
614
  generateBundle: {
571
615
  order: "post",
@@ -1947,10 +1991,11 @@ const bamboocss = (options = {}) => {
1947
1991
  state.unchangedFolds.clear();
1948
1992
  state.changedRun = 0;
1949
1993
  }
1950
- if (!ctx) return;
1951
- if (!shouldTransform(id)) return;
1952
1994
  const [filePath] = id.split("?");
1953
1995
  if (!filePath) return;
1996
+ if (change.event === "update") host.noteSourceChange(filePath, change.event);
1997
+ if (!ctx) return;
1998
+ if (!shouldTransform(id)) return;
1954
1999
  for (const state of transformStateByEnvironment.values()) state.recipeConfigCache.clear();
1955
2000
  if (change.event === "delete") {
1956
2001
  host.removeSource(filePath);
package/dist/index.mjs CHANGED
@@ -74,6 +74,31 @@ const createCompilationHost = (options = {}) => {
74
74
  let openSetup;
75
75
  let openSetupStale = false;
76
76
  let cssPass;
77
+ let changedSourceFiles = /* @__PURE__ */ new Set();
78
+ let needsInventoryScan = false;
79
+ let needsConfigReload = false;
80
+ const recordSourceChange = (filePath, event, options) => {
81
+ changedSourceFiles.add(filePath);
82
+ if (event !== "update") needsInventoryScan = true;
83
+ needsConfigReload ||= options?.needsConfigReload === true;
84
+ openSetupStale = true;
85
+ };
86
+ const takeSourceChanges = () => {
87
+ const changes = {
88
+ files: [...changedSourceFiles].sort(),
89
+ needsInventoryScan,
90
+ ...needsConfigReload ? { needsConfigReload: true } : {}
91
+ };
92
+ changedSourceFiles = /* @__PURE__ */ new Set();
93
+ needsInventoryScan = false;
94
+ needsConfigReload = false;
95
+ return changes;
96
+ };
97
+ const restoreSourceChanges = (changes) => {
98
+ for (const file of changes.files) changedSourceFiles.add(file);
99
+ needsInventoryScan ||= changes.needsInventoryScan === true;
100
+ needsConfigReload ||= changes.needsConfigReload === true;
101
+ };
77
102
  const settled = async (attempt) => {
78
103
  try {
79
104
  await attempt;
@@ -90,12 +115,19 @@ const createCompilationHost = (options = {}) => {
90
115
  };
91
116
  const runSetup = async () => {
92
117
  builder ??= await loadBuilder();
93
- await builder.setup({
94
- configPath,
95
- cwd,
96
- dev: command === "serve"
97
- });
98
- return publish();
118
+ const sourceChanges = takeSourceChanges();
119
+ try {
120
+ await builder.setup({
121
+ configPath,
122
+ cwd,
123
+ dev: command === "serve",
124
+ ...command === "serve" ? { sourceChanges } : {}
125
+ });
126
+ return publish();
127
+ } catch (error) {
128
+ if (command === "serve") restoreSourceChanges(sourceChanges);
129
+ throw error;
130
+ }
99
131
  };
100
132
  /**
101
133
  * The setup covering the pass currently open, started at most once.
@@ -148,12 +180,15 @@ const createCompilationHost = (options = {}) => {
148
180
  while (cssPass) await settled(cssPass);
149
181
  return run();
150
182
  },
183
+ noteSourceChange(filePath, event, options) {
184
+ if (command === "serve") recordSourceChange(filePath, event, options);
185
+ },
151
186
  reloadSource(filePath) {
152
- openSetupStale = true;
187
+ recordSourceChange(filePath, "update");
153
188
  builder?.reloadSource(filePath);
154
189
  },
155
190
  removeSource(filePath) {
156
- openSetupStale = true;
191
+ recordSourceChange(filePath, "update");
157
192
  builder?.removeSource(filePath);
158
193
  }
159
194
  };
@@ -285,12 +320,17 @@ const bamboocssCss = (options) => {
285
320
  let command = "build";
286
321
  /** The run's own `build` options, for a bundler with no per-environment config. */
287
322
  let ssrBuildOptions;
288
- /** Included owners plus local modules their extraction actually resolved and read. */
323
+ /** Every source, resolver input and expanded config dependency which can change the sheet. */
289
324
  const extractedSourceFiles = () => {
290
325
  const activeBuilder = builder;
291
326
  const context = activeBuilder?.context;
292
327
  if (!context) return [];
293
- return [...new Set([...context.getFiles(), ...activeBuilder.getResolutionReadFiles()].map((file) => context.runtime.path.abs(context.config.cwd, file)))];
328
+ return [...new Set([
329
+ ...activeBuilder.getSourceFiles(),
330
+ ...activeBuilder.getResolutionReadFiles(),
331
+ ...activeBuilder.getResolutionConfigurationFiles(),
332
+ ...context.explicitDeps
333
+ ].map((file) => context.runtime.path.abs(context.config.cwd, file)))];
294
334
  };
295
335
  /**
296
336
  * Serialised, because both `load` and the watcher can reach it and `Builder` keeps one
@@ -544,23 +584,27 @@ const bamboocssCss = (options) => {
544
584
  * about. Vite 5 has one graph and no `environments`, where the question is exact.
545
585
  */
546
586
  const clientGraph = devServer.environments?.client?.moduleGraph ?? devServer.moduleGraph;
547
- const invalidate = (file) => {
548
- const ctx = builder?.context;
587
+ const invalidate = (file, event) => {
588
+ const activeBuilder = builder;
589
+ const ctx = activeBuilder?.context;
549
590
  if (!ctx) return;
550
591
  const absoluteFile = ctx.runtime.path.abs(ctx.config.cwd, file);
551
- if (!session.extractedFiles.has(absoluteFile)) return;
592
+ const wasExtracted = session.extractedFiles.has(absoluteFile);
593
+ const changesConfigMembership = event !== "update" && activeBuilder.isPotentialConfigDependency(absoluteFile);
594
+ if (!wasExtracted && (event !== "create" || !activeBuilder.isPotentialSourceFile(absoluteFile) && !changesConfigMembership)) return;
595
+ host.noteSourceChange(absoluteFile, event, { needsConfigReload: changesConfigMembership });
552
596
  changeGeneration++;
553
597
  prebuilt = void 0;
554
598
  const mod = server?.moduleGraph.getModuleById(RESOLVED_ID);
555
599
  if (!mod) return;
556
- if (clientGraph.getModulesByFile(absoluteFile)?.size) return;
600
+ if (wasExtracted && clientGraph.getModulesByFile(absoluteFile)?.size) return;
557
601
  server?.moduleGraph.invalidateModule(mod);
558
602
  server?.reloadModule(mod);
559
603
  logger.debug("vite", `styles invalidated by ${absoluteFile}`);
560
604
  };
561
- devServer.watcher.on("change", invalidate);
562
- devServer.watcher.on("add", invalidate);
563
- devServer.watcher.on("unlink", invalidate);
605
+ devServer.watcher.on("change", (file) => invalidate(file, "update"));
606
+ devServer.watcher.on("add", (file) => invalidate(file, "create"));
607
+ devServer.watcher.on("unlink", (file) => invalidate(file, "delete"));
564
608
  },
565
609
  generateBundle: {
566
610
  order: "post",
@@ -1942,10 +1986,11 @@ const bamboocss = (options = {}) => {
1942
1986
  state.unchangedFolds.clear();
1943
1987
  state.changedRun = 0;
1944
1988
  }
1945
- if (!ctx) return;
1946
- if (!shouldTransform(id)) return;
1947
1989
  const [filePath] = id.split("?");
1948
1990
  if (!filePath) return;
1991
+ if (change.event === "update") host.noteSourceChange(filePath, change.event);
1992
+ if (!ctx) return;
1993
+ if (!shouldTransform(id)) return;
1949
1994
  for (const state of transformStateByEnvironment.values()) state.recipeConfigCache.clear();
1950
1995
  if (change.event === "delete") {
1951
1996
  host.removeSource(filePath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bamboocss/vite",
3
- "version": "1.48.0",
3
+ "version": "1.48.2",
4
4
  "description": "Vite integration for Bamboo CSS",
5
5
  "homepage": "https://bamboocss.com",
6
6
  "license": "MIT",
@@ -42,18 +42,18 @@
42
42
  "postcss": "8.5.26",
43
43
  "postcss-selector-parser": "7.1.5",
44
44
  "ts-morph": "28.0.0",
45
- "@bamboocss/logger": "1.48.0",
46
- "@bamboocss/config": "1.48.0",
47
- "@bamboocss/core": "1.48.0",
48
- "@bamboocss/node": "1.48.0",
49
- "@bamboocss/extractor": "1.48.0",
50
- "@bamboocss/shared": "1.48.0",
51
- "@bamboocss/types": "1.48.0"
45
+ "@bamboocss/config": "1.48.2",
46
+ "@bamboocss/core": "1.48.2",
47
+ "@bamboocss/logger": "1.48.2",
48
+ "@bamboocss/extractor": "1.48.2",
49
+ "@bamboocss/node": "1.48.2",
50
+ "@bamboocss/types": "1.48.2",
51
+ "@bamboocss/shared": "1.48.2"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@jridgewell/trace-mapping": "^0.3.31",
55
55
  "vite": "7.2.6",
56
- "@bamboocss/fixture": "1.48.0"
56
+ "@bamboocss/fixture": "1.48.2"
57
57
  },
58
58
  "peerDependencies": {
59
59
  "vite": ">=5"