@unocss/extractor-pug 66.5.10 → 66.5.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.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- import { Extractor } from '@unocss/core';
2
- import { Options } from 'pug';
1
+ import { Options } from "pug";
2
+ import { Extractor } from "@unocss/core";
3
3
 
4
+ //#region src/index.d.ts
4
5
  declare function extractorPug(options?: Options): Extractor;
5
-
6
- export { extractorPug as default };
6
+ //#endregion
7
+ export { extractorPug as default };
package/dist/index.mjs CHANGED
@@ -1,39 +1,33 @@
1
+ //#region src/index.ts
1
2
  const regexVueTemplate = /<template.*?lang=['"]pug['"][^>]*>([\s\S]*?)<\/template>/g;
2
3
  function extractorPug(options = {}) {
3
- async function compile(code, id) {
4
- const Pug = await import('pug');
5
- try {
6
- return Pug.compile(code, { filename: id, doctype: "html", ...options })();
7
- } catch {
8
- }
9
- }
10
- return {
11
- name: "pug",
12
- order: -1,
13
- async extract(ctx) {
14
- if (!ctx.id)
15
- return;
16
- if (ctx.id.endsWith(".pug") || ctx.id.includes("?vue&type=template")) {
17
- try {
18
- ctx.code = await compile(ctx.code, ctx.id) || ctx.code;
19
- } catch {
20
- }
21
- } else if (ctx.id.endsWith(".vue") || ctx.id.endsWith(".svelte")) {
22
- const matches = Array.from(ctx.code.matchAll(regexVueTemplate));
23
- let tail = "";
24
- for (const match of matches) {
25
- if (match && match[1])
26
- tail += `
27
- ${await compile(match[1].trim(), ctx.id)}`;
28
- }
29
- if (tail)
30
- ctx.code = `${ctx.code}
31
-
32
- ${tail}`;
33
- }
34
- return void 0;
35
- }
36
- };
4
+ async function compile(code, id) {
5
+ const Pug = await import("pug");
6
+ try {
7
+ return Pug.compile(code, {
8
+ filename: id,
9
+ doctype: "html",
10
+ ...options
11
+ })();
12
+ } catch {}
13
+ }
14
+ return {
15
+ name: "pug",
16
+ order: -1,
17
+ async extract(ctx) {
18
+ if (!ctx.id) return;
19
+ if (ctx.id.endsWith(".pug") || ctx.id.includes("?vue&type=template")) try {
20
+ ctx.code = await compile(ctx.code, ctx.id) || ctx.code;
21
+ } catch {}
22
+ else if (ctx.id.endsWith(".vue") || ctx.id.endsWith(".svelte")) {
23
+ const matches = Array.from(ctx.code.matchAll(regexVueTemplate));
24
+ let tail = "";
25
+ for (const match of matches) if (match && match[1]) tail += `\n${await compile(match[1].trim(), ctx.id)}`;
26
+ if (tail) ctx.code = `${ctx.code}\n\n${tail}`;
27
+ }
28
+ }
29
+ };
37
30
  }
38
31
 
39
- export { extractorPug as default };
32
+ //#endregion
33
+ export { extractorPug as default };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/extractor-pug",
3
3
  "type": "module",
4
- "version": "66.5.10",
4
+ "version": "66.5.12",
5
5
  "description": "UnoCSS extractor for Pug",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "main": "./dist/index.mjs",
31
31
  "module": "./dist/index.mjs",
32
- "types": "./dist/index.d.ts",
32
+ "types": "./dist/index.d.mts",
33
33
  "files": [
34
34
  "dist"
35
35
  ],
@@ -44,11 +44,10 @@
44
44
  "devDependencies": {
45
45
  "@types/pug": "^2.0.10",
46
46
  "pug": "^3.0.3",
47
- "@unocss/core": "66.5.10"
47
+ "@unocss/core": "66.5.12"
48
48
  },
49
49
  "scripts": {
50
- "build": "unbuild",
51
- "stub": "unbuild --stub",
52
- "test:attw": "attw --pack --config-path ../../.attw-esm-only.json"
50
+ "build": "tsdown --config-loader unrun",
51
+ "dev": "tsdown --config-loader unrun --watch"
53
52
  }
54
53
  }
package/dist/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { Extractor } from '@unocss/core';
2
- import { Options } from 'pug';
3
-
4
- declare function extractorPug(options?: Options): Extractor;
5
-
6
- export { extractorPug as default };