@modular-css/vite 30.0.1 → 30.0.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.
Files changed (3) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/package.json +3 -3
  3. package/vite.js +38 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Change Log
2
2
 
3
+ ## 30.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#972](https://github.com/tivac/modular-css/pull/972) [`673df5d3`](https://github.com/tivac/modular-css/commit/673df5d345dead81f68eb6199757cfaf400f09a6) Thanks [@tivac](https://github.com/tivac)! - Improved vite integration, now correctly invalidating files when a file is changed or deleted.
8
+ Improved invalidation in the processor, preventing stale `@value` or `composes` references from being output.
9
+ - Updated dependencies [[`673df5d3`](https://github.com/tivac/modular-css/commit/673df5d345dead81f68eb6199757cfaf400f09a6)]:
10
+ - @modular-css/processor@29.0.2
11
+ - @modular-css/css-to-js@29.0.2
12
+
3
13
  ## 30.0.1
4
14
 
5
15
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modular-css/vite",
3
- "version": "30.0.1",
3
+ "version": "30.0.2",
4
4
  "description": "vite support for modular-css",
5
5
  "main": "./vite.js",
6
6
  "repository": {
@@ -26,8 +26,8 @@
26
26
  "postcss"
27
27
  ],
28
28
  "dependencies": {
29
- "@modular-css/css-to-js": "^29.0.1",
30
- "@modular-css/processor": "^29.0.1",
29
+ "@modular-css/css-to-js": "^29.0.2",
30
+ "@modular-css/processor": "^29.0.2",
31
31
  "@rollup/pluginutils": "^5.0.2"
32
32
  },
33
33
  "peerDependencies": {
package/vite.js CHANGED
@@ -59,11 +59,26 @@ module.exports = (
59
59
  }
60
60
 
61
61
  let viteServer;
62
+ let viteConfig;
63
+
64
+ const watchFile = (file) => {
65
+ const slashed = slash(file);
66
+
67
+ if(viteServer) {
68
+ viteServer.watcher.add(slashed);
69
+ } else if(viteConfig.build.watch) {
70
+ this.addWatchFile(slashed);
71
+ }
72
+ };
62
73
 
63
74
  return {
64
75
  name : "@modular-css/vite",
65
76
  enforce : "pre",
66
77
 
78
+ configResolved(config) {
79
+ viteConfig = config;
80
+ },
81
+
67
82
  configureServer(instance) {
68
83
  viteServer = instance;
69
84
 
@@ -75,6 +90,27 @@ module.exports = (
75
90
  }
76
91
 
77
92
  processor.invalidate(file);
93
+
94
+ // Make sure vite knows that files that depend on us might've changed too
95
+ processor.fileDependents(file).forEach((dep) => {
96
+ viteServer.watcher.emit("change", dep);
97
+ });
98
+ });
99
+
100
+ viteServer.watcher.on("unlink", (file) => {
101
+ if(!processor.has(file)) {
102
+ return;
103
+ }
104
+
105
+ // Have to grab deps _before_ removal
106
+ const deps = processor.fileDependents(file);
107
+
108
+ processor.remove(file);
109
+
110
+ // Invalidate dependencies of the file that was removed
111
+ deps.forEach((dep) => {
112
+ viteServer.watcher.emit("change", dep);
113
+ });
78
114
  });
79
115
  },
80
116
 
@@ -82,7 +118,7 @@ module.exports = (
82
118
  log("build start");
83
119
 
84
120
  // Watch any files already in the procesor
85
- Object.keys(processor.files).forEach((file) => this.addWatchFile(file));
121
+ Object.keys(processor.files).forEach((file) => watchFile(file));
86
122
  },
87
123
 
88
124
  async resolveId(source) {
@@ -191,7 +227,7 @@ module.exports = (
191
227
 
192
228
  const deps = processor.fileDependencies(file);
193
229
 
194
- deps.forEach((dep) => this.addWatchFile(slash(dep)));
230
+ deps.forEach((dep) => watchFile(dep));
195
231
 
196
232
  // TODO: Gets CSS order right by forcing them to load their dependent CSS first.
197
233
  // Feels very brittle and overkill, but this is what we've got for now