@marko/vite 2.3.11 → 2.3.12

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.js CHANGED
@@ -82,10 +82,8 @@ function markoPlugin(opts = {}) {
82
82
  const id = normalizePath(from) + query;
83
83
  if (devServer) {
84
84
  const prev = virtualFiles.get(id);
85
- if (prev && prev.code !== dep.code) {
86
- devServer.moduleGraph.invalidateModule(
87
- devServer.moduleGraph.getModuleById(id)
88
- );
85
+ if (isDeferredPromise(prev)) {
86
+ prev.resolve(dep);
89
87
  }
90
88
  }
91
89
  virtualFiles.set(id, dep);
@@ -188,6 +186,8 @@ function markoPlugin(opts = {}) {
188
186
  devServer.watcher.on("all", (type, filename) => {
189
187
  if (type === "unlink") {
190
188
  entrySources.delete(filename);
189
+ transformWatchFiles.delete(filename);
190
+ transformOptionalFiles.delete(filename);
191
191
  }
192
192
  for (const [id, files] of transformWatchFiles) {
193
193
  if ((0, import_anymatch.default)(files, filename)) {
@@ -195,19 +195,23 @@ function markoPlugin(opts = {}) {
195
195
  }
196
196
  }
197
197
  if (type === "add" || type === "unlink") {
198
- let clearedCache = false;
199
198
  for (const [id, files] of transformOptionalFiles) {
200
199
  if ((0, import_anymatch.default)(files, filename)) {
201
- if (!clearedCache) {
202
- baseConfig.cache.clear();
203
- clearedCache = true;
204
- }
205
200
  devServer.watcher.emit("change", id);
206
201
  }
207
202
  }
208
203
  }
209
204
  });
210
205
  },
206
+ handleHotUpdate(ctx) {
207
+ compiler.taglib.clearCaches();
208
+ baseConfig.cache.clear();
209
+ for (const mod of ctx.modules) {
210
+ if (mod.id && virtualFiles.has(mod.id)) {
211
+ virtualFiles.set(mod.id, createDeferredPromise());
212
+ }
213
+ }
214
+ },
211
215
  async buildStart(inputOptions) {
212
216
  if (isBuild && linked && !isSSRBuild) {
213
217
  try {
@@ -343,7 +347,7 @@ function markoPlugin(opts = {}) {
343
347
  let { code } = compiled;
344
348
  if (query !== browserEntryQuery && devServer) {
345
349
  code += `
346
- if (import.meta.hot) import.meta.hot.accept();`;
350
+ if (import.meta.hot) import.meta.hot.accept(() => {});`;
347
351
  }
348
352
  if (devServer) {
349
353
  const templateName = getBasenameWithoutExt(id);
@@ -477,6 +481,20 @@ function getBasenameWithoutExt(file) {
477
481
  const extStart = file.indexOf(".", baseStart + 1);
478
482
  return file.slice(baseStart, extStart);
479
483
  }
484
+ function createDeferredPromise() {
485
+ let resolve;
486
+ let reject;
487
+ const promise = new Promise((res, rej) => {
488
+ resolve = res;
489
+ reject = rej;
490
+ });
491
+ promise.resolve = resolve;
492
+ promise.reject = reject;
493
+ return promise;
494
+ }
495
+ function isDeferredPromise(obj) {
496
+ return typeof (obj == null ? void 0 : obj.then) === "function";
497
+ }
480
498
  function isEmpty(obj) {
481
499
  for (const _ in obj) {
482
500
  return false;
package/dist/index.mjs CHANGED
@@ -62,10 +62,8 @@ function markoPlugin(opts = {}) {
62
62
  const id = normalizePath(from) + query;
63
63
  if (devServer) {
64
64
  const prev = virtualFiles.get(id);
65
- if (prev && prev.code !== dep.code) {
66
- devServer.moduleGraph.invalidateModule(
67
- devServer.moduleGraph.getModuleById(id)
68
- );
65
+ if (isDeferredPromise(prev)) {
66
+ prev.resolve(dep);
69
67
  }
70
68
  }
71
69
  virtualFiles.set(id, dep);
@@ -168,6 +166,8 @@ function markoPlugin(opts = {}) {
168
166
  devServer.watcher.on("all", (type, filename) => {
169
167
  if (type === "unlink") {
170
168
  entrySources.delete(filename);
169
+ transformWatchFiles.delete(filename);
170
+ transformOptionalFiles.delete(filename);
171
171
  }
172
172
  for (const [id, files] of transformWatchFiles) {
173
173
  if (anyMatch(files, filename)) {
@@ -175,19 +175,23 @@ function markoPlugin(opts = {}) {
175
175
  }
176
176
  }
177
177
  if (type === "add" || type === "unlink") {
178
- let clearedCache = false;
179
178
  for (const [id, files] of transformOptionalFiles) {
180
179
  if (anyMatch(files, filename)) {
181
- if (!clearedCache) {
182
- baseConfig.cache.clear();
183
- clearedCache = true;
184
- }
185
180
  devServer.watcher.emit("change", id);
186
181
  }
187
182
  }
188
183
  }
189
184
  });
190
185
  },
186
+ handleHotUpdate(ctx) {
187
+ compiler.taglib.clearCaches();
188
+ baseConfig.cache.clear();
189
+ for (const mod of ctx.modules) {
190
+ if (mod.id && virtualFiles.has(mod.id)) {
191
+ virtualFiles.set(mod.id, createDeferredPromise());
192
+ }
193
+ }
194
+ },
191
195
  async buildStart(inputOptions) {
192
196
  if (isBuild && linked && !isSSRBuild) {
193
197
  try {
@@ -323,7 +327,7 @@ function markoPlugin(opts = {}) {
323
327
  let { code } = compiled;
324
328
  if (query !== browserEntryQuery && devServer) {
325
329
  code += `
326
- if (import.meta.hot) import.meta.hot.accept();`;
330
+ if (import.meta.hot) import.meta.hot.accept(() => {});`;
327
331
  }
328
332
  if (devServer) {
329
333
  const templateName = getBasenameWithoutExt(id);
@@ -457,6 +461,20 @@ function getBasenameWithoutExt(file) {
457
461
  const extStart = file.indexOf(".", baseStart + 1);
458
462
  return file.slice(baseStart, extStart);
459
463
  }
464
+ function createDeferredPromise() {
465
+ let resolve;
466
+ let reject;
467
+ const promise = new Promise((res, rej) => {
468
+ resolve = res;
469
+ reject = rej;
470
+ });
471
+ promise.resolve = resolve;
472
+ promise.reject = reject;
473
+ return promise;
474
+ }
475
+ function isDeferredPromise(obj) {
476
+ return typeof (obj == null ? void 0 : obj.then) === "function";
477
+ }
460
478
  function isEmpty(obj) {
461
479
  for (const _ in obj) {
462
480
  return false;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@marko/vite",
3
3
  "description": "A Marko plugin for Vite",
4
- "version": "2.3.11",
4
+ "version": "2.3.12",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {