@unocss/astro 0.55.0 → 0.55.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.cjs CHANGED
@@ -8,24 +8,28 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
8
8
 
9
9
  const VitePlugin__default = /*#__PURE__*/_interopDefaultLegacy(VitePlugin);
10
10
 
11
+ const RESOLVED_ID_RE = /[\/\\]__uno(?:(_.*?))?\.css$/;
12
+
11
13
  const UNO_INJECT_ID = "uno-astro";
12
- const UNO_QUERY_KEY = "uno-with-astro-key";
13
14
  const astroCSSKeyRE = /(\?|\&)lang\.css/;
14
15
  function AstroVitePlugin(options) {
15
16
  const { injects, injectReset } = options;
16
17
  const resetInjectPath = injectReset ? injects[0] : void 0;
17
18
  let command;
18
- let nodeModulesPath;
19
+ let root;
19
20
  let resetCSSInjected = false;
20
21
  const resolveCSSQueue = /* @__PURE__ */ new Set();
21
22
  return {
22
23
  name: "unocss:astro",
23
24
  enforce: "pre",
24
25
  configResolved(config) {
26
+ root = config.root;
25
27
  command = config.command;
26
- nodeModulesPath = `${config.root}/node_modules`;
27
28
  },
28
29
  async resolveId(id, importer) {
30
+ if (RESOLVED_ID_RE.test(id)) {
31
+ return node_path.join(root, id);
32
+ }
29
33
  if (id === UNO_INJECT_ID) {
30
34
  if (injectReset) {
31
35
  resetCSSInjected = false;
@@ -38,7 +42,6 @@ function AstroVitePlugin(options) {
38
42
  const resolved = await this.resolve(id, importer, { skipSelf: true });
39
43
  if (resolved) {
40
44
  const fsPath = resolved.id;
41
- const realId = `${fsPath}${fsPath.includes("?") ? "&" : "?"}${UNO_QUERY_KEY}`;
42
45
  if (injectReset) {
43
46
  if (resetInjectPath.includes(id)) {
44
47
  setTimeout(() => {
@@ -50,19 +53,19 @@ function AstroVitePlugin(options) {
50
53
  resetCSSInjected = true;
51
54
  } else if (id.includes(".css") && !resetCSSInjected) {
52
55
  return new Promise((resolve2) => {
53
- resolveCSSQueue.add(() => resolve2(realId));
56
+ resolveCSSQueue.add(() => {
57
+ resolve2(fsPath);
58
+ });
54
59
  });
55
60
  }
56
61
  }
57
- return realId;
62
+ return fsPath;
58
63
  }
59
64
  }
60
65
  },
61
- load(id, options2) {
66
+ load(id) {
62
67
  if (id.endsWith(UNO_INJECT_ID))
63
68
  return injects.join("\n");
64
- if (!options2?.ssr && id.includes(UNO_QUERY_KEY) && id.includes(".css") && !id.startsWith(nodeModulesPath))
65
- return "";
66
69
  }
67
70
  };
68
71
  }
package/dist/index.mjs CHANGED
@@ -1,25 +1,29 @@
1
- import { resolve } from 'node:path';
1
+ import { resolve, join } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import VitePlugin from '@unocss/vite';
4
4
 
5
+ const RESOLVED_ID_RE = /[\/\\]__uno(?:(_.*?))?\.css$/;
6
+
5
7
  const UNO_INJECT_ID = "uno-astro";
6
- const UNO_QUERY_KEY = "uno-with-astro-key";
7
8
  const astroCSSKeyRE = /(\?|\&)lang\.css/;
8
9
  function AstroVitePlugin(options) {
9
10
  const { injects, injectReset } = options;
10
11
  const resetInjectPath = injectReset ? injects[0] : void 0;
11
12
  let command;
12
- let nodeModulesPath;
13
+ let root;
13
14
  let resetCSSInjected = false;
14
15
  const resolveCSSQueue = /* @__PURE__ */ new Set();
15
16
  return {
16
17
  name: "unocss:astro",
17
18
  enforce: "pre",
18
19
  configResolved(config) {
20
+ root = config.root;
19
21
  command = config.command;
20
- nodeModulesPath = `${config.root}/node_modules`;
21
22
  },
22
23
  async resolveId(id, importer) {
24
+ if (RESOLVED_ID_RE.test(id)) {
25
+ return join(root, id);
26
+ }
23
27
  if (id === UNO_INJECT_ID) {
24
28
  if (injectReset) {
25
29
  resetCSSInjected = false;
@@ -32,7 +36,6 @@ function AstroVitePlugin(options) {
32
36
  const resolved = await this.resolve(id, importer, { skipSelf: true });
33
37
  if (resolved) {
34
38
  const fsPath = resolved.id;
35
- const realId = `${fsPath}${fsPath.includes("?") ? "&" : "?"}${UNO_QUERY_KEY}`;
36
39
  if (injectReset) {
37
40
  if (resetInjectPath.includes(id)) {
38
41
  setTimeout(() => {
@@ -44,19 +47,19 @@ function AstroVitePlugin(options) {
44
47
  resetCSSInjected = true;
45
48
  } else if (id.includes(".css") && !resetCSSInjected) {
46
49
  return new Promise((resolve2) => {
47
- resolveCSSQueue.add(() => resolve2(realId));
50
+ resolveCSSQueue.add(() => {
51
+ resolve2(fsPath);
52
+ });
48
53
  });
49
54
  }
50
55
  }
51
- return realId;
56
+ return fsPath;
52
57
  }
53
58
  }
54
59
  },
55
- load(id, options2) {
60
+ load(id) {
56
61
  if (id.endsWith(UNO_INJECT_ID))
57
62
  return injects.join("\n");
58
- if (!options2?.ssr && id.includes(UNO_QUERY_KEY) && id.includes(".css") && !id.startsWith(nodeModulesPath))
59
- return "";
60
63
  }
61
64
  };
62
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/astro",
3
- "version": "0.55.0",
3
+ "version": "0.55.1",
4
4
  "description": "UnoCSS integration for Astro",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -45,12 +45,12 @@
45
45
  }
46
46
  },
47
47
  "dependencies": {
48
- "@unocss/core": "0.55.0",
49
- "@unocss/reset": "0.55.0",
50
- "@unocss/vite": "0.55.0"
48
+ "@unocss/core": "0.55.1",
49
+ "@unocss/reset": "0.55.1",
50
+ "@unocss/vite": "0.55.1"
51
51
  },
52
52
  "devDependencies": {
53
- "astro": "^2.10.1"
53
+ "astro": "^2.10.9"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "unbuild",