@unocss/vite 0.64.1 → 0.65.0-beta.1

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.d.mts CHANGED
@@ -60,7 +60,7 @@ declare function ChunkModeBuildPlugin({ uno, filter }: UnocssPluginContext): Plu
60
60
 
61
61
  declare function GlobalModeBuildPlugin(ctx: UnocssPluginContext<VitePluginConfig>): Plugin[];
62
62
 
63
- declare function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules, onInvalidate, extract, filter, getConfig }: UnocssPluginContext): Plugin[];
63
+ declare function GlobalModeDevPlugin(ctx: UnocssPluginContext): Plugin[];
64
64
 
65
65
  declare function GlobalModePlugin(ctx: UnocssPluginContext): vite.Plugin<any>[];
66
66
 
package/dist/index.d.ts CHANGED
@@ -60,7 +60,7 @@ declare function ChunkModeBuildPlugin({ uno, filter }: UnocssPluginContext): Plu
60
60
 
61
61
  declare function GlobalModeBuildPlugin(ctx: UnocssPluginContext<VitePluginConfig>): Plugin[];
62
62
 
63
- declare function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules, onInvalidate, extract, filter, getConfig }: UnocssPluginContext): Plugin[];
63
+ declare function GlobalModeDevPlugin(ctx: UnocssPluginContext): Plugin[];
64
64
 
65
65
  declare function GlobalModePlugin(ctx: UnocssPluginContext): vite.Plugin<any>[];
66
66
 
package/dist/index.mjs CHANGED
@@ -14,15 +14,15 @@ import { createFilter } from '@rollup/pluginutils';
14
14
  import { createRecoveryConfigLoader } from '@unocss/config';
15
15
 
16
16
  function ConfigHMRPlugin(ctx) {
17
- const { ready, uno } = ctx;
17
+ const { ready } = ctx;
18
18
  return {
19
19
  name: "unocss:config",
20
20
  async configResolved(config) {
21
21
  await ctx.updateRoot(config.root);
22
22
  },
23
23
  async configureServer(server) {
24
- uno.config.envMode = "dev";
25
24
  const { sources } = await ready;
25
+ ctx.uno.config.envMode = "dev";
26
26
  if (!sources.length)
27
27
  return;
28
28
  server.watcher.add(sources);
@@ -254,7 +254,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
254
254
  let root = process$1.cwd();
255
255
  let rawConfig = {};
256
256
  let configFileList = [];
257
- const uno = createGenerator(rawConfig, defaults);
257
+ let uno;
258
+ const _uno = createGenerator(rawConfig, defaults).then((r) => {
259
+ uno = r;
260
+ return r;
261
+ });
258
262
  let rollupFilter = createFilter(
259
263
  defaultPipelineInclude,
260
264
  defaultPipelineExclude,
@@ -269,12 +273,13 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
269
273
  const loadConfig = createRecoveryConfigLoader();
270
274
  let ready = reloadConfig();
271
275
  async function reloadConfig() {
276
+ await _uno;
272
277
  const result = await loadConfig(root, configOrPath, extraConfigSources, defaults);
273
278
  resolveConfigResult(result);
274
279
  deprecationCheck(result.config);
275
280
  rawConfig = result.config;
276
281
  configFileList = result.sources;
277
- uno.setConfig(rawConfig);
282
+ await uno.setConfig(rawConfig);
278
283
  uno.config.envMode = "dev";
279
284
  rollupFilter = rawConfig.content?.pipeline === false ? () => false : createFilter(
280
285
  rawConfig.content?.pipeline?.include || rawConfig.include || defaultPipelineInclude,
@@ -301,10 +306,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
301
306
  reloadListeners.forEach((cb) => cb());
302
307
  }
303
308
  async function extract(code, id) {
309
+ const uno2 = await _uno;
304
310
  if (id)
305
311
  modules.set(id, code);
306
312
  const len = tokens.size;
307
- await uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
313
+ await uno2.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
308
314
  if (tokens.size > len)
309
315
  invalidate();
310
316
  }
@@ -341,7 +347,11 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
341
347
  onReload(fn) {
342
348
  reloadListeners.push(fn);
343
349
  },
344
- uno,
350
+ get uno() {
351
+ if (!uno)
352
+ throw new Error("Run `await context.ready` before accessing `context.uno`");
353
+ return uno;
354
+ },
345
355
  extract,
346
356
  getConfig,
347
357
  get root() {
@@ -516,7 +526,7 @@ function isLegacyChunk(chunk, options) {
516
526
  return options.format === "system" && chunk.fileName.includes("-legacy");
517
527
  }
518
528
  function GlobalModeBuildPlugin(ctx) {
519
- const { uno, ready, extract, tokens, filter, getConfig, tasks, flushTasks } = ctx;
529
+ const { ready, extract, tokens, filter, getConfig, tasks, flushTasks } = ctx;
520
530
  const vfsLayers = /* @__PURE__ */ new Set();
521
531
  const layerImporterMap = /* @__PURE__ */ new Map();
522
532
  let viteConfig;
@@ -544,7 +554,7 @@ function GlobalModeBuildPlugin(ctx) {
544
554
  await flushTasks();
545
555
  if (lastResult && lastTokenSize === tokens.size)
546
556
  return lastResult;
547
- lastResult = await uno.generate(tokens, { minify: true });
557
+ lastResult = await ctx.uno.generate(tokens, { minify: true });
548
558
  lastTokenSize = tokens.size;
549
559
  return lastResult;
550
560
  }
@@ -772,7 +782,8 @@ function GlobalModeBuildPlugin(ctx) {
772
782
  const WARN_TIMEOUT = 2e4;
773
783
  const WS_EVENT_PREFIX = "unocss:hmr";
774
784
  const HASH_LENGTH = 6;
775
- function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules, onInvalidate, extract, filter, getConfig }) {
785
+ function GlobalModeDevPlugin(ctx) {
786
+ const { tokens, tasks, flushTasks, affectedModules, onInvalidate, extract, filter, getConfig } = ctx;
776
787
  const servers = [];
777
788
  const entries = /* @__PURE__ */ new Set();
778
789
  let invalidateTimer;
@@ -785,7 +796,7 @@ function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules,
785
796
  let result;
786
797
  let tokensSize = tokens.size;
787
798
  do {
788
- result = await uno.generate(tokens);
799
+ result = await ctx.uno.generate(tokens);
789
800
  if (tokensSize === tokens.size)
790
801
  break;
791
802
  tokensSize = tokens.size;
@@ -869,7 +880,7 @@ function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules,
869
880
  });
870
881
  },
871
882
  buildStart() {
872
- uno.generate([], { preflights: true });
883
+ ctx.uno.generate([], { preflights: true });
873
884
  },
874
885
  transform(code, id) {
875
886
  if (filter(code, id))
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
3
  "type": "module",
4
- "version": "0.64.1",
4
+ "version": "0.65.0-beta.1",
5
5
  "description": "The Vite plugin for UnoCSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -46,7 +46,7 @@
46
46
  "dist"
47
47
  ],
48
48
  "peerDependencies": {
49
- "vite": "^2.9.0 || ^3.0.0-0 || ^4.0.0 || ^5.0.0-0"
49
+ "vite": "^2.9.0 || ^3.0.0-0 || ^4.0.0 || ^5.0.0-0 || ^6.0.0-0"
50
50
  },
51
51
  "dependencies": {
52
52
  "@ampproject/remapping": "^2.3.0",
@@ -54,13 +54,13 @@
54
54
  "chokidar": "^3.6.0",
55
55
  "magic-string": "^0.30.12",
56
56
  "tinyglobby": "^0.2.10",
57
- "@unocss/core": "0.64.1",
58
- "@unocss/config": "0.64.1",
59
- "@unocss/inspector": "0.64.1"
57
+ "@unocss/config": "0.65.0-beta.1",
58
+ "@unocss/core": "0.65.0-beta.1",
59
+ "@unocss/inspector": "0.65.0-beta.1"
60
60
  },
61
61
  "devDependencies": {
62
- "vite": "^5.4.10",
63
- "@unocss/shared-integration": "0.64.1"
62
+ "vite": "^6.0.0",
63
+ "@unocss/shared-integration": "0.65.0-beta.1"
64
64
  },
65
65
  "scripts": {
66
66
  "build": "unbuild",