@unocss/vite 0.40.0 → 0.41.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
@@ -62,6 +62,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
62
62
  const reloadListeners = [];
63
63
  const modules = new core.BetterMap();
64
64
  const tokens = /* @__PURE__ */ new Set();
65
+ const affectedModules = /* @__PURE__ */ new Set();
65
66
  let ready = reloadConfig();
66
67
  async function reloadConfig() {
67
68
  const result = await config.loadConfig(root, configOrPath, extraConfigSources);
@@ -121,6 +122,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
121
122
  },
122
123
  tokens,
123
124
  modules,
125
+ affectedModules,
124
126
  invalidate,
125
127
  onInvalidate(fn) {
126
128
  invalidations.push(fn);
@@ -354,7 +356,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
354
356
 
355
357
  const WARN_TIMEOUT = 2e4;
356
358
  const WS_EVENT_PREFIX = "unocss:hmr";
357
- function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
359
+ function GlobalModeDevPlugin({ uno, tokens, affectedModules, onInvalidate, extract, filter }) {
358
360
  const servers = [];
359
361
  let base = "";
360
362
  const tasks = [];
@@ -371,9 +373,9 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
371
373
  else if (base.endsWith("/"))
372
374
  base = base.slice(0, base.length - 1);
373
375
  }
374
- function invalidate(timer = 10) {
376
+ function invalidate(timer = 10, ids = entries) {
375
377
  for (const server of servers) {
376
- for (const id of entries) {
378
+ for (const id of ids) {
377
379
  const mod = server.moduleGraph.getModuleById(id);
378
380
  if (!mod)
379
381
  continue;
@@ -381,19 +383,24 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
381
383
  }
382
384
  }
383
385
  clearTimeout(invalidateTimer);
384
- invalidateTimer = setTimeout(sendUpdate, timer);
386
+ invalidateTimer = setTimeout(() => sendUpdate(ids), timer);
385
387
  }
386
- function sendUpdate() {
388
+ function sendUpdate(ids) {
387
389
  lastUpdate = Date.now();
388
390
  for (const server of servers) {
389
391
  server.ws.send({
390
392
  type: "update",
391
- updates: Array.from(entries).map((i) => ({
392
- acceptedPath: i,
393
- path: i,
394
- timestamp: lastUpdate,
395
- type: "js-update"
396
- }))
393
+ updates: Array.from(ids).map((id) => {
394
+ const mod = server.moduleGraph.getModuleById(id);
395
+ if (!mod)
396
+ return null;
397
+ return {
398
+ acceptedPath: mod.url,
399
+ path: mod.url,
400
+ timestamp: lastUpdate,
401
+ type: "js-update"
402
+ };
403
+ }).filter(core.notNull)
397
404
  });
398
405
  }
399
406
  }
@@ -413,7 +420,9 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
413
420
  }, WARN_TIMEOUT);
414
421
  }
415
422
  }
416
- onInvalidate(invalidate);
423
+ onInvalidate(() => {
424
+ invalidate(0, /* @__PURE__ */ new Set([...entries, ...affectedModules]));
425
+ });
417
426
  return [
418
427
  {
419
428
  name: "unocss:global",
@@ -754,6 +763,7 @@ function initTransformerPlugins(ctx) {
754
763
  await t.transform(s, id, ctx);
755
764
  }
756
765
  if (s.hasChanged()) {
766
+ ctx.affectedModules.add(id);
757
767
  return {
758
768
  code: s.toString(),
759
769
  map: s.generateMap({ hires: true, source: id })
package/dist/index.d.ts CHANGED
@@ -39,7 +39,7 @@ interface VitePluginConfig<Theme extends {} = {}> extends UserConfig<Theme> {
39
39
 
40
40
  declare function ChunkModeBuildPlugin({ uno, filter }: UnocssPluginContext): Plugin;
41
41
 
42
- declare function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }: UnocssPluginContext): Plugin[];
42
+ declare function GlobalModeDevPlugin({ uno, tokens, affectedModules, onInvalidate, extract, filter }: UnocssPluginContext): Plugin[];
43
43
 
44
44
  declare function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig }: UnocssPluginContext<VitePluginConfig>): Plugin[];
45
45
 
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import UnocssInspector from '@unocss/inspector';
2
2
  import { resolve, dirname } from 'path';
3
3
  import { createHash } from 'crypto';
4
- import { cssIdRE, createGenerator, BetterMap, toEscapedSelector } from '@unocss/core';
4
+ import { cssIdRE, createGenerator, BetterMap, notNull, toEscapedSelector } from '@unocss/core';
5
5
  import { createFilter } from '@rollup/pluginutils';
6
6
  import MagicString from 'magic-string';
7
7
  import fs from 'fs';
@@ -52,6 +52,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
52
52
  const reloadListeners = [];
53
53
  const modules = new BetterMap();
54
54
  const tokens = /* @__PURE__ */ new Set();
55
+ const affectedModules = /* @__PURE__ */ new Set();
55
56
  let ready = reloadConfig();
56
57
  async function reloadConfig() {
57
58
  const result = await loadConfig(root, configOrPath, extraConfigSources);
@@ -111,6 +112,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
111
112
  },
112
113
  tokens,
113
114
  modules,
115
+ affectedModules,
114
116
  invalidate,
115
117
  onInvalidate(fn) {
116
118
  invalidations.push(fn);
@@ -344,7 +346,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
344
346
 
345
347
  const WARN_TIMEOUT = 2e4;
346
348
  const WS_EVENT_PREFIX = "unocss:hmr";
347
- function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
349
+ function GlobalModeDevPlugin({ uno, tokens, affectedModules, onInvalidate, extract, filter }) {
348
350
  const servers = [];
349
351
  let base = "";
350
352
  const tasks = [];
@@ -361,9 +363,9 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
361
363
  else if (base.endsWith("/"))
362
364
  base = base.slice(0, base.length - 1);
363
365
  }
364
- function invalidate(timer = 10) {
366
+ function invalidate(timer = 10, ids = entries) {
365
367
  for (const server of servers) {
366
- for (const id of entries) {
368
+ for (const id of ids) {
367
369
  const mod = server.moduleGraph.getModuleById(id);
368
370
  if (!mod)
369
371
  continue;
@@ -371,19 +373,24 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
371
373
  }
372
374
  }
373
375
  clearTimeout(invalidateTimer);
374
- invalidateTimer = setTimeout(sendUpdate, timer);
376
+ invalidateTimer = setTimeout(() => sendUpdate(ids), timer);
375
377
  }
376
- function sendUpdate() {
378
+ function sendUpdate(ids) {
377
379
  lastUpdate = Date.now();
378
380
  for (const server of servers) {
379
381
  server.ws.send({
380
382
  type: "update",
381
- updates: Array.from(entries).map((i) => ({
382
- acceptedPath: i,
383
- path: i,
384
- timestamp: lastUpdate,
385
- type: "js-update"
386
- }))
383
+ updates: Array.from(ids).map((id) => {
384
+ const mod = server.moduleGraph.getModuleById(id);
385
+ if (!mod)
386
+ return null;
387
+ return {
388
+ acceptedPath: mod.url,
389
+ path: mod.url,
390
+ timestamp: lastUpdate,
391
+ type: "js-update"
392
+ };
393
+ }).filter(notNull)
387
394
  });
388
395
  }
389
396
  }
@@ -403,7 +410,9 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
403
410
  }, WARN_TIMEOUT);
404
411
  }
405
412
  }
406
- onInvalidate(invalidate);
413
+ onInvalidate(() => {
414
+ invalidate(0, /* @__PURE__ */ new Set([...entries, ...affectedModules]));
415
+ });
407
416
  return [
408
417
  {
409
418
  name: "unocss:global",
@@ -744,6 +753,7 @@ function initTransformerPlugins(ctx) {
744
753
  await t.transform(s, id, ctx);
745
754
  }
746
755
  if (s.hasChanged()) {
756
+ ctx.affectedModules.add(id);
747
757
  return {
748
758
  code: s.toString(),
749
759
  map: s.generateMap({ hires: true, source: id })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.40.0",
3
+ "version": "0.41.2",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -43,15 +43,15 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@rollup/pluginutils": "^4.2.1",
46
- "@unocss/config": "0.40.0",
47
- "@unocss/core": "0.40.0",
48
- "@unocss/inspector": "0.40.0",
49
- "@unocss/scope": "0.40.0",
50
- "@unocss/transformer-directives": "0.40.0",
46
+ "@unocss/config": "0.41.2",
47
+ "@unocss/core": "0.41.2",
48
+ "@unocss/inspector": "0.41.2",
49
+ "@unocss/scope": "0.41.2",
50
+ "@unocss/transformer-directives": "0.41.2",
51
51
  "magic-string": "^0.26.2"
52
52
  },
53
53
  "devDependencies": {
54
- "@unocss/shared-integration": "0.40.0",
54
+ "@unocss/shared-integration": "0.41.2",
55
55
  "vite": "^2.9.12"
56
56
  },
57
57
  "scripts": {