@modular-css/vite 30.0.1 → 30.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Change Log
2
2
 
3
+ ## 30.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`63af4ac3`](https://github.com/tivac/modular-css/commit/63af4ac3ee6380ede5396463fb0305bc14274d84)]:
8
+ - @modular-css/css-to-js@29.0.3
9
+ - @modular-css/processor@29.0.3
10
+
11
+ ## 30.0.2
12
+
13
+ ### Patch Changes
14
+
15
+ - [#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.
16
+ Improved invalidation in the processor, preventing stale `@value` or `composes` references from being output.
17
+ - Updated dependencies [[`673df5d3`](https://github.com/tivac/modular-css/commit/673df5d345dead81f68eb6199757cfaf400f09a6)]:
18
+ - @modular-css/processor@29.0.2
19
+ - @modular-css/css-to-js@29.0.2
20
+
3
21
  ## 30.0.1
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -33,7 +33,7 @@ A minimatch pattern, or an array of minimatch patterns, relative to `process.cwd
33
33
 
34
34
  ### `processor`
35
35
 
36
- Pass an already-instantiated `Processor` instance to the rollup plugin. It will then add any files found when traversing the modules to it and both the rollup-discovered and any already-existing files will be output in the final CSS.
36
+ Pass an already-instantiated `Processor` instance to the vite plugin. It will then add any files found when traversing the modules to it and both the vite-discovered and any already-existing files will be output in the final CSS.
37
37
 
38
38
  #### `styleExport`
39
39
 
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.3",
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.3",
30
+ "@modular-css/processor": "^29.0.3",
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