@weapp-vite/volar 0.0.1 → 0.0.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.
Files changed (3) hide show
  1. package/dist/index.js +108 -16
  2. package/dist/index.mjs +103 -15
  3. package/package.json +4 -2
package/dist/index.js CHANGED
@@ -1,42 +1,134 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// package.json
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// ../../node_modules/.pnpm/tsup@8.5.0_@swc+core@1.14.0_jiti@2.6.1_postcss@8.5.6_tsx@4.20.6_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
2
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
3
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
4
+
5
+ // src/index.ts
6
+ var _module = require('module');
7
+
8
+ // package.json
2
9
  var name = "@weapp-vite/volar";
3
10
 
4
11
  // src/index.ts
5
12
  var BLOCK_TYPE = "config";
13
+ var JSON_LANG = "json";
14
+ var TS_LANG = "ts";
15
+ var PLUGIN_VERSION = 2.2;
16
+ var FULL_CAPABILITIES = {
17
+ verification: true,
18
+ completion: true,
19
+ semantic: true,
20
+ navigation: true,
21
+ structure: true,
22
+ format: true
23
+ };
24
+ var VOID_CAPABILITIES = {
25
+ verification: false,
26
+ completion: false,
27
+ semantic: false,
28
+ navigation: false,
29
+ structure: false,
30
+ format: false
31
+ };
32
+ var require2 = _module.createRequire.call(void 0, importMetaUrl);
33
+ var hasSchematicsTypes = false;
34
+ try {
35
+ require2.resolve("@weapp-core/schematics");
36
+ hasSchematicsTypes = true;
37
+ } catch (e) {
38
+ hasSchematicsTypes = false;
39
+ }
40
+ function normalizeLang(lang) {
41
+ if (!lang) {
42
+ return JSON_LANG;
43
+ }
44
+ if (lang === "txt") {
45
+ return JSON_LANG;
46
+ }
47
+ return lang;
48
+ }
49
+ function normalizeFilename(filename) {
50
+ if (!filename) {
51
+ return "";
52
+ }
53
+ return filename.replace(/\\/g, "/");
54
+ }
55
+ function inferConfigType(filename) {
56
+ const normalized = normalizeFilename(filename);
57
+ if (normalized.endsWith("/app.vue")) {
58
+ return "App";
59
+ }
60
+ if (normalized.includes("/plugin/")) {
61
+ return "Plugin";
62
+ }
63
+ if (normalized.includes("/components/")) {
64
+ return "Component";
65
+ }
66
+ if (normalized.includes("/theme/")) {
67
+ return "Theme";
68
+ }
69
+ if (normalized.includes("/sitemap")) {
70
+ return "Sitemap";
71
+ }
72
+ return "Page";
73
+ }
6
74
  var plugin = () => {
7
75
  return {
8
76
  name,
9
- version: 2.1,
10
- getEmbeddedCodes(_fileName, sfc) {
77
+ version: PLUGIN_VERSION,
78
+ getEmbeddedCodes(_, sfc) {
11
79
  const names = [];
12
80
  for (let i = 0; i < sfc.customBlocks.length; i++) {
13
81
  const block = sfc.customBlocks[i];
14
82
  if (block.type === BLOCK_TYPE) {
15
- const lang = block.lang === "txt" ? "json" : block.lang;
83
+ const normalizedLang = normalizeLang(block.lang);
84
+ const lang = hasSchematicsTypes ? TS_LANG : normalizedLang;
16
85
  names.push({ id: `${BLOCK_TYPE}_${i}`, lang });
17
86
  }
18
87
  }
19
88
  return names;
20
89
  },
21
- resolveEmbeddedCode(_fileName, sfc, embeddedCode) {
90
+ resolveEmbeddedCode(fileName, sfc, embeddedCode) {
22
91
  const match = embeddedCode.id.match(new RegExp(`^${BLOCK_TYPE}_(\\d+)$`));
23
- if (match) {
24
- const index = Number.parseInt(match[1]);
25
- const block = sfc.customBlocks[index];
92
+ if (!match) {
93
+ return;
94
+ }
95
+ const index = Number.parseInt(match[1]);
96
+ const block = sfc.customBlocks[index];
97
+ if (!block) {
98
+ return;
99
+ }
100
+ if (!hasSchematicsTypes) {
26
101
  embeddedCode.content.push([
27
102
  block.content,
28
103
  block.name,
29
104
  0,
30
- {
31
- verification: true,
32
- completion: true,
33
- semantic: true,
34
- navigation: true,
35
- structure: true,
36
- format: true
37
- }
105
+ FULL_CAPABILITIES
38
106
  ]);
107
+ return;
39
108
  }
109
+ const configType = inferConfigType(fileName);
110
+ const prefix = `import type { ${configType} as __WeappConfig } from '@weapp-core/schematics'
111
+
112
+ export default `;
113
+ const suffix = " satisfies __WeappConfig\n";
114
+ embeddedCode.content.push([
115
+ prefix,
116
+ void 0,
117
+ 0,
118
+ VOID_CAPABILITIES
119
+ ]);
120
+ embeddedCode.content.push([
121
+ block.content,
122
+ block.name,
123
+ 0,
124
+ FULL_CAPABILITIES
125
+ ]);
126
+ embeddedCode.content.push([
127
+ suffix,
128
+ void 0,
129
+ block.content.length,
130
+ VOID_CAPABILITIES
131
+ ]);
40
132
  }
41
133
  };
42
134
  };
package/dist/index.mjs CHANGED
@@ -1,42 +1,130 @@
1
+ // src/index.ts
2
+ import { createRequire } from "module";
3
+
1
4
  // package.json
2
5
  var name = "@weapp-vite/volar";
3
6
 
4
7
  // src/index.ts
5
8
  var BLOCK_TYPE = "config";
9
+ var JSON_LANG = "json";
10
+ var TS_LANG = "ts";
11
+ var PLUGIN_VERSION = 2.2;
12
+ var FULL_CAPABILITIES = {
13
+ verification: true,
14
+ completion: true,
15
+ semantic: true,
16
+ navigation: true,
17
+ structure: true,
18
+ format: true
19
+ };
20
+ var VOID_CAPABILITIES = {
21
+ verification: false,
22
+ completion: false,
23
+ semantic: false,
24
+ navigation: false,
25
+ structure: false,
26
+ format: false
27
+ };
28
+ var require2 = createRequire(import.meta.url);
29
+ var hasSchematicsTypes = false;
30
+ try {
31
+ require2.resolve("@weapp-core/schematics");
32
+ hasSchematicsTypes = true;
33
+ } catch {
34
+ hasSchematicsTypes = false;
35
+ }
36
+ function normalizeLang(lang) {
37
+ if (!lang) {
38
+ return JSON_LANG;
39
+ }
40
+ if (lang === "txt") {
41
+ return JSON_LANG;
42
+ }
43
+ return lang;
44
+ }
45
+ function normalizeFilename(filename) {
46
+ if (!filename) {
47
+ return "";
48
+ }
49
+ return filename.replace(/\\/g, "/");
50
+ }
51
+ function inferConfigType(filename) {
52
+ const normalized = normalizeFilename(filename);
53
+ if (normalized.endsWith("/app.vue")) {
54
+ return "App";
55
+ }
56
+ if (normalized.includes("/plugin/")) {
57
+ return "Plugin";
58
+ }
59
+ if (normalized.includes("/components/")) {
60
+ return "Component";
61
+ }
62
+ if (normalized.includes("/theme/")) {
63
+ return "Theme";
64
+ }
65
+ if (normalized.includes("/sitemap")) {
66
+ return "Sitemap";
67
+ }
68
+ return "Page";
69
+ }
6
70
  var plugin = () => {
7
71
  return {
8
72
  name,
9
- version: 2.1,
10
- getEmbeddedCodes(_fileName, sfc) {
73
+ version: PLUGIN_VERSION,
74
+ getEmbeddedCodes(_, sfc) {
11
75
  const names = [];
12
76
  for (let i = 0; i < sfc.customBlocks.length; i++) {
13
77
  const block = sfc.customBlocks[i];
14
78
  if (block.type === BLOCK_TYPE) {
15
- const lang = block.lang === "txt" ? "json" : block.lang;
79
+ const normalizedLang = normalizeLang(block.lang);
80
+ const lang = hasSchematicsTypes ? TS_LANG : normalizedLang;
16
81
  names.push({ id: `${BLOCK_TYPE}_${i}`, lang });
17
82
  }
18
83
  }
19
84
  return names;
20
85
  },
21
- resolveEmbeddedCode(_fileName, sfc, embeddedCode) {
86
+ resolveEmbeddedCode(fileName, sfc, embeddedCode) {
22
87
  const match = embeddedCode.id.match(new RegExp(`^${BLOCK_TYPE}_(\\d+)$`));
23
- if (match) {
24
- const index = Number.parseInt(match[1]);
25
- const block = sfc.customBlocks[index];
88
+ if (!match) {
89
+ return;
90
+ }
91
+ const index = Number.parseInt(match[1]);
92
+ const block = sfc.customBlocks[index];
93
+ if (!block) {
94
+ return;
95
+ }
96
+ if (!hasSchematicsTypes) {
26
97
  embeddedCode.content.push([
27
98
  block.content,
28
99
  block.name,
29
100
  0,
30
- {
31
- verification: true,
32
- completion: true,
33
- semantic: true,
34
- navigation: true,
35
- structure: true,
36
- format: true
37
- }
101
+ FULL_CAPABILITIES
38
102
  ]);
103
+ return;
39
104
  }
105
+ const configType = inferConfigType(fileName);
106
+ const prefix = `import type { ${configType} as __WeappConfig } from '@weapp-core/schematics'
107
+
108
+ export default `;
109
+ const suffix = " satisfies __WeappConfig\n";
110
+ embeddedCode.content.push([
111
+ prefix,
112
+ void 0,
113
+ 0,
114
+ VOID_CAPABILITIES
115
+ ]);
116
+ embeddedCode.content.push([
117
+ block.content,
118
+ block.name,
119
+ 0,
120
+ FULL_CAPABILITIES
121
+ ]);
122
+ embeddedCode.content.push([
123
+ suffix,
124
+ void 0,
125
+ block.content.length,
126
+ VOID_CAPABILITIES
127
+ ]);
40
128
  }
41
129
  };
42
130
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@weapp-vite/volar",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "tsup(esbuild) build package template",
5
5
  "author": "ice breaker <1324318532@qq.com>",
6
6
  "license": "MIT",
@@ -30,7 +30,9 @@
30
30
  "files": [
31
31
  "dist"
32
32
  ],
33
- "dependencies": {},
33
+ "dependencies": {
34
+ "@weapp-core/schematics": "4.0.0"
35
+ },
34
36
  "scripts": {
35
37
  "dev": "tsup --watch --sourcemap",
36
38
  "build": "tsup",