vite-plugin-ai-shared 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Your Name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,63 @@
1
+ /**
2
+ * 共享类型定义
3
+ */
4
+ interface ErrorInfo {
5
+ type: string;
6
+ message: string;
7
+ stack?: string;
8
+ file?: string;
9
+ code?: string;
10
+ }
11
+ interface FileInfo {
12
+ path: string;
13
+ content: string;
14
+ size: number;
15
+ lines: number;
16
+ }
17
+ interface PluginConfig {
18
+ enabled?: boolean;
19
+ debug?: boolean;
20
+ }
21
+
22
+ /**
23
+ * 共享工具函数
24
+ */
25
+ /**
26
+ * 从错误对象中提取源文件路径
27
+ */
28
+ declare function extractSourceFile(error: Error, fallbackFile: string | null): string | null;
29
+ /**
30
+ * 读取源文件内容
31
+ */
32
+ declare function readSourceFile(filePath: string): string | null;
33
+ /**
34
+ * 获取文件信息
35
+ */
36
+ declare function getFileInfo(filePath: string): {
37
+ path: string;
38
+ size: number;
39
+ lines: number;
40
+ content: string;
41
+ } | null;
42
+
43
+ /**
44
+ * 共享常量定义
45
+ */
46
+ declare const PLUGIN_PREFIX = "vite-plugin";
47
+ declare const DEFAULT_CONFIG: {
48
+ enabled: boolean;
49
+ debug: boolean;
50
+ };
51
+ declare const FILE_EXTENSIONS: {
52
+ vue: string[];
53
+ typescript: string[];
54
+ javascript: string[];
55
+ all: string[];
56
+ };
57
+ declare const ERROR_TYPES: {
58
+ BUILD: string;
59
+ TRANSFORM: string;
60
+ RENDER: string;
61
+ };
62
+
63
+ export { DEFAULT_CONFIG, ERROR_TYPES, type ErrorInfo, FILE_EXTENSIONS, type FileInfo, PLUGIN_PREFIX, type PluginConfig, extractSourceFile, getFileInfo, readSourceFile };
@@ -0,0 +1,63 @@
1
+ /**
2
+ * 共享类型定义
3
+ */
4
+ interface ErrorInfo {
5
+ type: string;
6
+ message: string;
7
+ stack?: string;
8
+ file?: string;
9
+ code?: string;
10
+ }
11
+ interface FileInfo {
12
+ path: string;
13
+ content: string;
14
+ size: number;
15
+ lines: number;
16
+ }
17
+ interface PluginConfig {
18
+ enabled?: boolean;
19
+ debug?: boolean;
20
+ }
21
+
22
+ /**
23
+ * 共享工具函数
24
+ */
25
+ /**
26
+ * 从错误对象中提取源文件路径
27
+ */
28
+ declare function extractSourceFile(error: Error, fallbackFile: string | null): string | null;
29
+ /**
30
+ * 读取源文件内容
31
+ */
32
+ declare function readSourceFile(filePath: string): string | null;
33
+ /**
34
+ * 获取文件信息
35
+ */
36
+ declare function getFileInfo(filePath: string): {
37
+ path: string;
38
+ size: number;
39
+ lines: number;
40
+ content: string;
41
+ } | null;
42
+
43
+ /**
44
+ * 共享常量定义
45
+ */
46
+ declare const PLUGIN_PREFIX = "vite-plugin";
47
+ declare const DEFAULT_CONFIG: {
48
+ enabled: boolean;
49
+ debug: boolean;
50
+ };
51
+ declare const FILE_EXTENSIONS: {
52
+ vue: string[];
53
+ typescript: string[];
54
+ javascript: string[];
55
+ all: string[];
56
+ };
57
+ declare const ERROR_TYPES: {
58
+ BUILD: string;
59
+ TRANSFORM: string;
60
+ RENDER: string;
61
+ };
62
+
63
+ export { DEFAULT_CONFIG, ERROR_TYPES, type ErrorInfo, FILE_EXTENSIONS, type FileInfo, PLUGIN_PREFIX, type PluginConfig, extractSourceFile, getFileInfo, readSourceFile };
package/dist/index.js ADDED
@@ -0,0 +1,84 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var pc = require('picocolors');
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
10
+ var path__default = /*#__PURE__*/_interopDefault(path);
11
+ var pc__default = /*#__PURE__*/_interopDefault(pc);
12
+
13
+ // src/utils.ts
14
+ function extractSourceFile(error, fallbackFile) {
15
+ const errorStr = error.toString();
16
+ const stackStr = error.stack || "";
17
+ const filePathMatch = errorStr.match(/([A-Z]:[\\/][\w\\/.-]+\.(vue|ts|js|tsx|jsx))/i) || stackStr.match(/([A-Z]:[\\/][\w\\/.-]+\.(vue|ts|js|tsx|jsx))/i);
18
+ if (filePathMatch) {
19
+ const filePath = filePathMatch[1];
20
+ if (!filePath.includes("node_modules") && fs__default.default.existsSync(filePath)) {
21
+ return filePath;
22
+ }
23
+ }
24
+ const relativeMatch = errorStr.match(/(src[\\/][\w\\/.-]+\.(vue|ts|js|tsx|jsx))/i) || stackStr.match(/(src[\\/][\w\\/.-]+\.(vue|ts|js|tsx|jsx))/i);
25
+ if (relativeMatch) {
26
+ const relativePath = relativeMatch[1];
27
+ const absolutePath = path__default.default.resolve(process.cwd(), relativePath);
28
+ if (fs__default.default.existsSync(absolutePath)) {
29
+ return absolutePath;
30
+ }
31
+ }
32
+ if (fallbackFile && !fallbackFile.includes("node_modules")) {
33
+ return fallbackFile;
34
+ }
35
+ return null;
36
+ }
37
+ function readSourceFile(filePath) {
38
+ try {
39
+ if (fs__default.default.existsSync(filePath)) {
40
+ return fs__default.default.readFileSync(filePath, "utf-8");
41
+ }
42
+ } catch (error) {
43
+ console.warn(pc__default.default.yellow(`\u26A0\uFE0F \u65E0\u6CD5\u8BFB\u53D6\u6587\u4EF6: ${filePath}`));
44
+ }
45
+ return null;
46
+ }
47
+ function getFileInfo(filePath) {
48
+ const content = readSourceFile(filePath);
49
+ if (!content) return null;
50
+ return {
51
+ path: filePath,
52
+ size: content.length,
53
+ lines: content.split("\n").length,
54
+ content
55
+ };
56
+ }
57
+
58
+ // src/constants.ts
59
+ var PLUGIN_PREFIX = "vite-plugin";
60
+ var DEFAULT_CONFIG = {
61
+ enabled: true,
62
+ debug: false
63
+ };
64
+ var FILE_EXTENSIONS = {
65
+ vue: [".vue"],
66
+ typescript: [".ts", ".tsx"],
67
+ javascript: [".js", ".jsx"],
68
+ all: [".vue", ".ts", ".tsx", ".js", ".jsx"]
69
+ };
70
+ var ERROR_TYPES = {
71
+ BUILD: "build",
72
+ TRANSFORM: "transform",
73
+ RENDER: "render"
74
+ };
75
+
76
+ exports.DEFAULT_CONFIG = DEFAULT_CONFIG;
77
+ exports.ERROR_TYPES = ERROR_TYPES;
78
+ exports.FILE_EXTENSIONS = FILE_EXTENSIONS;
79
+ exports.PLUGIN_PREFIX = PLUGIN_PREFIX;
80
+ exports.extractSourceFile = extractSourceFile;
81
+ exports.getFileInfo = getFileInfo;
82
+ exports.readSourceFile = readSourceFile;
83
+ //# sourceMappingURL=index.js.map
84
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts","../src/constants.ts"],"names":["fs","path","pc"],"mappings":";;;;;;;;;;;;;AAWO,SAAS,iBAAA,CACd,OACA,YAAA,EACe;AACf,EAAA,MAAM,QAAA,GAAW,MAAM,QA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,CAAC,CAAA;AAAA,EACnD;AACA,EAAA,OAAO,IAAA;AACT;AAKO,SAAS,YAAY,QAAA,EAKnB;AACP,EAAA,MAAM,OAAA,GAAU,eAAe,QAAQ,CAAA;AACvC,EAAA,IAAI,CAAC,SAAS,OAAO,IAAA;AAErB,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,QAAA;AAAA,IACN,MAAM,OAAA,CAAQ,MAAA;AAAA,IACd,KAAA,EAAO,OAAA,CAAQ,KAAA,CAAM,IAAI,CAAA,CAAE,MAAA;AAAA,IAC3B;AAAA,GACF;AACF;;;AC/EO,IAAM,aAAA,GAAgB;AAEtB,IAAM,cAAA,GAAiB;AAAA,EAC5B,OAAA,EAAS,IAAA;AAAA,EACT,KAAA,EAAO;AACT;AAEO,IAAM,eAAA,GAAkB;AAAA,EAC7B,GAAA,EAAK,CAAC,MAAM,CAAA;AAAA,EACZ,UAAA,EAAY,CAAC,KAAA,EAAO,MAAM,CAAA;AAAA,EAC1B,UAAA,EAAY,CAAC,KAAA,EAAO,MAAM,CAAA;AAAA,EAC1B,KAAK,CAAC,MAAA,EAAQ,KAAA,EAAO,MAAA,EAAQ,OAAO,MAAM;AAC5C;AAEO,IAAM,WAAA,GAAc;AAAA,EACzB,KAAA,EAAO,OAAA;AAAA,EACP,SAAA,EAAW,WAAA;AAAA,EACX,MAAA,EAAQ;AACV","file":"index.js","sourcesContent":["/**\r\n * 共享工具函数\r\n */\r\n\r\nimport fs from \"fs\";\r\nimport path from \"path\";\r\nimport pc from \"picocolors\";\r\n\r\n/**\r\n * 从错误对象中提取源文件路径\r\n */\r\nexport function extractSourceFile(\r\n error: Error,\r\n fallbackFile: string | null,\r\n): string | null {\r\n const errorStr = error.toString();\r\n const stackStr = error.stack || \"\";\r\n\r\n // 方法 1: 从错误消息中提取绝对路径\r\n const filePathMatch =\r\n errorStr.match(/([A-Z]:[\\\\/][\\w\\\\/.-]+\\.(vue|ts|js|tsx|jsx))/i) ||\r\n stackStr.match(/([A-Z]:[\\\\/][\\w\\\\/.-]+\\.(vue|ts|js|tsx|jsx))/i);\r\n\r\n if (filePathMatch) {\r\n const filePath = filePathMatch[1];\r\n if (!filePath.includes(\"node_modules\") && fs.existsSync(filePath)) {\r\n return filePath;\r\n }\r\n }\r\n\r\n // 方法 2: 从错误消息中提取相对路径\r\n const relativeMatch =\r\n errorStr.match(/(src[\\\\/][\\w\\\\/.-]+\\.(vue|ts|js|tsx|jsx))/i) ||\r\n stackStr.match(/(src[\\\\/][\\w\\\\/.-]+\\.(vue|ts|js|tsx|jsx))/i);\r\n\r\n if (relativeMatch) {\r\n const relativePath = relativeMatch[1];\r\n const absolutePath = path.resolve(process.cwd(), relativePath);\r\n if (fs.existsSync(absolutePath)) {\r\n return absolutePath;\r\n }\r\n }\r\n\r\n // 方法 3: 使用 fallback\r\n if (fallbackFile && !fallbackFile.includes(\"node_modules\")) {\r\n return fallbackFile;\r\n }\r\n\r\n return null;\r\n}\r\n\r\n/**\r\n * 读取源文件内容\r\n */\r\nexport function readSourceFile(filePath: string): string | null {\r\n try {\r\n if (fs.existsSync(filePath)) {\r\n return fs.readFileSync(filePath, \"utf-8\");\r\n }\r\n } catch (error) {\r\n console.warn(pc.yellow(`⚠️ 无法读取文件: ${filePath}`));\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 获取文件信息\r\n */\r\nexport function getFileInfo(filePath: string): {\r\n path: string;\r\n size: number;\r\n lines: number;\r\n content: string;\r\n} | null {\r\n const content = readSourceFile(filePath);\r\n if (!content) return null;\r\n\r\n return {\r\n path: filePath,\r\n size: content.length,\r\n lines: content.split(\"\\n\").length,\r\n content,\r\n };\r\n}\r\n","/**\r\n * 共享常量定义\r\n */\r\n\r\nexport const PLUGIN_PREFIX = \"vite-plugin\";\r\n\r\nexport const DEFAULT_CONFIG = {\r\n enabled: true,\r\n debug: false,\r\n};\r\n\r\nexport const FILE_EXTENSIONS = {\r\n vue: [\".vue\"],\r\n typescript: [\".ts\", \".tsx\"],\r\n javascript: [\".js\", \".jsx\"],\r\n all: [\".vue\", \".ts\", \".tsx\", \".js\", \".jsx\"],\r\n};\r\n\r\nexport const ERROR_TYPES = {\r\n BUILD: \"build\",\r\n TRANSFORM: \"transform\",\r\n RENDER: \"render\",\r\n};\r\n"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,70 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import pc from 'picocolors';
4
+
5
+ // src/utils.ts
6
+ function extractSourceFile(error, fallbackFile) {
7
+ const errorStr = error.toString();
8
+ const stackStr = error.stack || "";
9
+ const filePathMatch = errorStr.match(/([A-Z]:[\\/][\w\\/.-]+\.(vue|ts|js|tsx|jsx))/i) || stackStr.match(/([A-Z]:[\\/][\w\\/.-]+\.(vue|ts|js|tsx|jsx))/i);
10
+ if (filePathMatch) {
11
+ const filePath = filePathMatch[1];
12
+ if (!filePath.includes("node_modules") && fs.existsSync(filePath)) {
13
+ return filePath;
14
+ }
15
+ }
16
+ const relativeMatch = errorStr.match(/(src[\\/][\w\\/.-]+\.(vue|ts|js|tsx|jsx))/i) || stackStr.match(/(src[\\/][\w\\/.-]+\.(vue|ts|js|tsx|jsx))/i);
17
+ if (relativeMatch) {
18
+ const relativePath = relativeMatch[1];
19
+ const absolutePath = path.resolve(process.cwd(), relativePath);
20
+ if (fs.existsSync(absolutePath)) {
21
+ return absolutePath;
22
+ }
23
+ }
24
+ if (fallbackFile && !fallbackFile.includes("node_modules")) {
25
+ return fallbackFile;
26
+ }
27
+ return null;
28
+ }
29
+ function readSourceFile(filePath) {
30
+ try {
31
+ if (fs.existsSync(filePath)) {
32
+ return fs.readFileSync(filePath, "utf-8");
33
+ }
34
+ } catch (error) {
35
+ console.warn(pc.yellow(`\u26A0\uFE0F \u65E0\u6CD5\u8BFB\u53D6\u6587\u4EF6: ${filePath}`));
36
+ }
37
+ return null;
38
+ }
39
+ function getFileInfo(filePath) {
40
+ const content = readSourceFile(filePath);
41
+ if (!content) return null;
42
+ return {
43
+ path: filePath,
44
+ size: content.length,
45
+ lines: content.split("\n").length,
46
+ content
47
+ };
48
+ }
49
+
50
+ // src/constants.ts
51
+ var PLUGIN_PREFIX = "vite-plugin";
52
+ var DEFAULT_CONFIG = {
53
+ enabled: true,
54
+ debug: false
55
+ };
56
+ var FILE_EXTENSIONS = {
57
+ vue: [".vue"],
58
+ typescript: [".ts", ".tsx"],
59
+ javascript: [".js", ".jsx"],
60
+ all: [".vue", ".ts", ".tsx", ".js", ".jsx"]
61
+ };
62
+ var ERROR_TYPES = {
63
+ BUILD: "build",
64
+ TRANSFORM: "transform",
65
+ RENDER: "render"
66
+ };
67
+
68
+ export { DEFAULT_CONFIG, ERROR_TYPES, FILE_EXTENSIONS, PLUGIN_PREFIX, extractSourceFile, getFileInfo, readSourceFile };
69
+ //# sourceMappingURL=index.mjs.map
70
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.ts","../src/constants.ts"],"names":[],"mappings":";;;;;AAWO,SAAS,iBAAA,CACd,OACA,YAAA,EACe;AACf,EAAA,MAAM,QAAA,GAAW,MAAM,QAAA,EAAS;AAChC,EAAA,MAAM,QAAA,GAAW,MAAM,KAAA,IAAS,EAAA;AAGhC,EAAA,MAAM,gBACJ,QAAA,CAAS,KAAA,CAAM,+CAA+C,CAAA,IAC9D,QAAA,CAAS,MAAM,+CAA+C,CAAA;AAEhE,EAAA,IAAI,aAAA,EAAe;AACjB,IAAA,MAAM,QAAA,GAAW,cAAc,CAAC,CAAA;AAChC,IAAA,IAAI,CAAC,SAAS,QAAA,CAAS,cAAc,KAAK,EAAA,CAAG,UAAA,CAAW,QAAQ,CAAA,EAAG;AACjE,MAAA,OAAO,QAAA;AAAA,IACT;AAAA,EACF;AAGA,EAAA,MAAM,gBACJ,QAAA,CAAS,KAAA,CAAM,4CAA4C,CAAA,IAC3D,QAAA,CAAS,MAAM,4CAA4C,CAAA;AAE7D,EAAA,IAAI,aAAA,EAAe;AACjB,IAAA,MAAM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AA,EAAY,CAAC,KAAA,EAAO,MAAM,CAAA;AAAA,EAC1B,UAAA,EAAY,CAAC,KAAA,EAAO,MAAM,CAAA;AAAA,EAC1B,KAAK,CAAC,MAAA,EAAQ,KAAA,EAAO,MAAA,EAAQ,OAAO,MAAM;AAC5C;AAEO,IAAM,WAAA,GAAc;AAAA,EACzB,KAAA,EAAO,OAAA;AAAA,EACP,SAAA,EAAW,WAAA;AAAA,EACX,MAAA,EAAQ;AACV","file":"index.mjs","sourcesContent":["/**\r\n * 共享工具函数\r\n */\r\n\r\nimport fs from \"fs\";\r\nimport path from \"path\";\r\nimport pc from \"picocolors\";\r\n\r\n/**\r\n * 从错误对象中提取源文件路径\r\n */\r\nexport function extractSourceFile(\r\n error: Error,\r\n fallbackFile: string | null,\r\n): string | null {\r\n const errorStr = error.toString();\r\n const stackStr = error.stack || \"\";\r\n\r\n // 方法 1: 从错误消息中提取绝对路径\r\n const filePathMatch =\r\n errorStr.match(/([A-Z]:[\\\\/][\\w\\\\/.-]+\\.(vue|ts|js|tsx|jsx))/i) ||\r\n stackStr.match(/([A-Z]:[\\\\/][\\w\\\\/.-]+\\.(vue|ts|js|tsx|jsx))/i);\r\n\r\n if (filePathMatch) {\r\n const filePath = filePathMatch[1];\r\n if (!filePath.includes(\"node_modules\") && fs.existsSync(filePath)) {\r\n return filePath;\r\n }\r\n }\r\n\r\n // 方法 2: 从错误消息中提取相对路径\r\n const relativeMatch =\r\n errorStr.match(/(src[\\\\/][\\w\\\\/.-]+\\.(vue|ts|js|tsx|jsx))/i) ||\r\n stackStr.match(/(src[\\\\/][\\w\\\\/.-]+\\.(vue|ts|js|tsx|jsx))/i);\r\n\r\n if (relativeMatch) {\r\n const relativePath = relativeMatch[1];\r\n const absolutePath = path.resolve(process.cwd(), relativePath);\r\n if (fs.existsSync(absolutePath)) {\r\n return absolutePath;\r\n }\r\n }\r\n\r\n // 方法 3: 使用 fallback\r\n if (fallbackFile && !fallbackFile.includes(\"node_modules\")) {\r\n return fallbackFile;\r\n }\r\n\r\n return null;\r\n}\r\n\r\n/**\r\n * 读取源文件内容\r\n */\r\nexport function readSourceFile(filePath: string): string | null {\r\n try {\r\n if (fs.existsSync(filePath)) {\r\n return fs.readFileSync(filePath, \"utf-8\");\r\n }\r\n } catch (error) {\r\n console.warn(pc.yellow(`⚠️ 无法读取文件: ${filePath}`));\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 获取文件信息\r\n */\r\nexport function getFileInfo(filePath: string): {\r\n path: string;\r\n size: number;\r\n lines: number;\r\n content: string;\r\n} | null {\r\n const content = readSourceFile(filePath);\r\n if (!content) return null;\r\n\r\n return {\r\n path: filePath,\r\n size: content.length,\r\n lines: content.split(\"\\n\").length,\r\n content,\r\n };\r\n}\r\n","/**\r\n * 共享常量定义\r\n */\r\n\r\nexport const PLUGIN_PREFIX = \"vite-plugin\";\r\n\r\nexport const DEFAULT_CONFIG = {\r\n enabled: true,\r\n debug: false,\r\n};\r\n\r\nexport const FILE_EXTENSIONS = {\r\n vue: [\".vue\"],\r\n typescript: [\".ts\", \".tsx\"],\r\n javascript: [\".js\", \".jsx\"],\r\n all: [\".vue\", \".ts\", \".tsx\", \".js\", \".jsx\"],\r\n};\r\n\r\nexport const ERROR_TYPES = {\r\n BUILD: \"build\",\r\n TRANSFORM: \"transform\",\r\n RENDER: \"render\",\r\n};\r\n"]}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "vite-plugin-ai-shared",
3
+ "version": "1.0.0",
4
+ "description": "Shared utilities for AI Vite plugins",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "keywords": [
19
+ "vite",
20
+ "plugin",
21
+ "shared",
22
+ "utilities"
23
+ ],
24
+ "author": "Haihui Mo <591348205@qq.com>",
25
+ "license": "MIT",
26
+ "dependencies": {
27
+ "picocolors": "^1.1.1"
28
+ },
29
+ "scripts": {
30
+ "build": "tsup",
31
+ "dev": "tsup --watch",
32
+ "test": "echo 'No tests yet'",
33
+ "clean": "rm -rf dist"
34
+ }
35
+ }