@meituan-nocode/vite-plugin-nocode-compiler 0.1.0-beta.21-z → 0.1.0-beta.22-z

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 ADDED
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ componentCompiler: () => componentCompiler,
24
+ default: () => index_default
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_nocode_compiler_core = require("@meituan-nocode/nocode-compiler-core");
28
+
29
+ // src/utils.ts
30
+ var JsFileExtList = [".js", ".ts", ".mjs", ".mts", ".jsx", ".tsx"];
31
+ function isJsTypeFile(file) {
32
+ return JsFileExtList.some((ext) => file.endsWith(ext));
33
+ }
34
+
35
+ // src/index.ts
36
+ function componentCompiler(options = {}) {
37
+ options = {
38
+ enableLogging: false,
39
+ ...options
40
+ };
41
+ const vueCompiler = new import_nocode_compiler_core.VueCompiler(options);
42
+ const jsxCompiler = new import_nocode_compiler_core.JSXCompiler(options);
43
+ return {
44
+ name: "vite-plugin-nocode-compiler",
45
+ enforce: "pre",
46
+ async transform(code, id) {
47
+ if (id.includes("node_modules")) {
48
+ return code;
49
+ }
50
+ const [_completePath, query] = id.split("?", 2);
51
+ let filePath = _completePath;
52
+ const params = new URLSearchParams(query);
53
+ const isJsTypeFileResult = isJsTypeFile(filePath);
54
+ const isVueFile = filePath.endsWith(".vue");
55
+ const isHtmlFile = filePath.endsWith(".html");
56
+ const type = params.get("type");
57
+ const lang = params.get("lang");
58
+ const isTemplateType = type === "template";
59
+ const isScriptType = type === "script";
60
+ const isJsxLang = lang === "tsx" || lang === "jsx";
61
+ const isRawType = params.get("raw") !== null;
62
+ if (isVueFile && isScriptType && isJsxLang) {
63
+ return jsxCompiler.compile(code, filePath) || code;
64
+ }
65
+ if (isVueFile && isTemplateType) {
66
+ return vueCompiler.compile(code, filePath) || code;
67
+ }
68
+ if (isHtmlFile && isTemplateType && params.has("vue")) {
69
+ return vueCompiler.compile(code, filePath) || code;
70
+ }
71
+ if (isJsTypeFileResult && !isVueFile) {
72
+ return jsxCompiler.compile(code, filePath) || code;
73
+ }
74
+ if (isVueFile && !type && !isRawType) {
75
+ return vueCompiler.compile(code, filePath) || code;
76
+ }
77
+ return code;
78
+ }
79
+ };
80
+ }
81
+ var index_default = componentCompiler;
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ componentCompiler
85
+ });
@@ -0,0 +1,15 @@
1
+ interface NocodeCompilerOptions {
2
+ enableLogging?: boolean;
3
+ rootPath?: string;
4
+ }
5
+ /**
6
+ * Vite插件
7
+ * 用于在构建过程中处理Vue和React组件,添加nocode相关的标记
8
+ */
9
+ declare function componentCompiler(options?: NocodeCompilerOptions): {
10
+ name: string;
11
+ enforce: "pre";
12
+ transform(code: string, id: string): Promise<string>;
13
+ };
14
+
15
+ export { type NocodeCompilerOptions, componentCompiler, componentCompiler as default };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export interface NocodeCompilerOptions {
1
+ interface NocodeCompilerOptions {
2
2
  enableLogging?: boolean;
3
3
  rootPath?: string;
4
4
  }
@@ -6,9 +6,10 @@ export interface NocodeCompilerOptions {
6
6
  * Vite插件
7
7
  * 用于在构建过程中处理Vue和React组件,添加nocode相关的标记
8
8
  */
9
- export declare function componentCompiler(options?: NocodeCompilerOptions): {
9
+ declare function componentCompiler(options?: NocodeCompilerOptions): {
10
10
  name: string;
11
11
  enforce: "pre";
12
12
  transform(code: string, id: string): Promise<string>;
13
13
  };
14
- export default componentCompiler;
14
+
15
+ export { type NocodeCompilerOptions, componentCompiler, componentCompiler as default };
package/dist/index.js CHANGED
@@ -1,60 +1,60 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.componentCompiler = componentCompiler;
4
- const nocode_compiler_core_1 = require("@meituan-nocode/nocode-compiler-core");
5
- const utils_1 = require("./utils");
6
- /**
7
- * Vite插件
8
- * 用于在构建过程中处理Vue和React组件,添加nocode相关的标记
9
- */
1
+ // src/index.ts
2
+ import { JSXCompiler, VueCompiler } from "@meituan-nocode/nocode-compiler-core";
3
+
4
+ // src/utils.ts
5
+ var JsFileExtList = [".js", ".ts", ".mjs", ".mts", ".jsx", ".tsx"];
6
+ function isJsTypeFile(file) {
7
+ return JsFileExtList.some((ext) => file.endsWith(ext));
8
+ }
9
+
10
+ // src/index.ts
10
11
  function componentCompiler(options = {}) {
11
- options = {
12
- enableLogging: false,
13
- ...options,
14
- };
15
- // 创建代码转换器实例
16
- // const codeTransformer = new CodeTransformer(options);
17
- const vueCompiler = new nocode_compiler_core_1.VueCompiler(options);
18
- const jsxCompiler = new nocode_compiler_core_1.JSXCompiler(options);
19
- return {
20
- name: 'vite-plugin-nocode-compiler',
21
- enforce: 'pre',
22
- async transform(code, id) {
23
- // 跳过node_modules
24
- if (id.includes('node_modules')) {
25
- return code;
26
- }
27
- const [_completePath, query] = id.split('?', 2); // 当前文件的绝对路径
28
- let filePath = _completePath;
29
- const params = new URLSearchParams(query);
30
- // let fileType = '';
31
- if ((0, utils_1.isJsTypeFile)(filePath) || (filePath.endsWith('.vue') && (utils_1.JsxParamList.some(param => params.get(param) !== null) || params.get('lang') === 'tsx' || params.get('lang') === 'jsx'))) {
32
- // jsx 代码
33
- return jsxCompiler.compile(code, filePath) || code;
34
- }
35
- else if (filePath.endsWith('.html') && params.get('type') === 'template' && params.has('vue')) {
36
- // <template src="xxx.html"></template>
37
- return vueCompiler.compile(code, filePath) || code;
38
- }
39
- else if (filePath.endsWith('.vue') && params.get('type') !== 'style' && params.get('raw') === null) {
40
- // vue 代码
41
- return vueCompiler.compile(code, filePath) || code;
42
- }
43
- // // 如果是Vue文件但@vue/compiler-dom不可用,跳过处理
44
- // if (fileType === 'vue' && !vueCompilerAvailable) {
45
- // console.warn(`[vite-plugin-nocode-compiler] Skipping Vue file processing for ${filePath} due to missing @vue/compiler-dom`);
46
- // return code;
47
- // }
48
- // if (fileType) {
49
- // return codeTransformer.transformCode({
50
- // content: code,
51
- // filePath,
52
- // fileType,
53
- // });
54
- // }
55
- return code;
56
- },
57
- };
12
+ options = {
13
+ enableLogging: false,
14
+ ...options
15
+ };
16
+ const vueCompiler = new VueCompiler(options);
17
+ const jsxCompiler = new JSXCompiler(options);
18
+ return {
19
+ name: "vite-plugin-nocode-compiler",
20
+ enforce: "pre",
21
+ async transform(code, id) {
22
+ if (id.includes("node_modules")) {
23
+ return code;
24
+ }
25
+ const [_completePath, query] = id.split("?", 2);
26
+ let filePath = _completePath;
27
+ const params = new URLSearchParams(query);
28
+ const isJsTypeFileResult = isJsTypeFile(filePath);
29
+ const isVueFile = filePath.endsWith(".vue");
30
+ const isHtmlFile = filePath.endsWith(".html");
31
+ const type = params.get("type");
32
+ const lang = params.get("lang");
33
+ const isTemplateType = type === "template";
34
+ const isScriptType = type === "script";
35
+ const isJsxLang = lang === "tsx" || lang === "jsx";
36
+ const isRawType = params.get("raw") !== null;
37
+ if (isVueFile && isScriptType && isJsxLang) {
38
+ return jsxCompiler.compile(code, filePath) || code;
39
+ }
40
+ if (isVueFile && isTemplateType) {
41
+ return vueCompiler.compile(code, filePath) || code;
42
+ }
43
+ if (isHtmlFile && isTemplateType && params.has("vue")) {
44
+ return vueCompiler.compile(code, filePath) || code;
45
+ }
46
+ if (isJsTypeFileResult && !isVueFile) {
47
+ return jsxCompiler.compile(code, filePath) || code;
48
+ }
49
+ if (isVueFile && !type && !isRawType) {
50
+ return vueCompiler.compile(code, filePath) || code;
51
+ }
52
+ return code;
53
+ }
54
+ };
58
55
  }
59
- // 添加默认导出,使 ESM 导入更方便
60
- exports.default = componentCompiler;
56
+ var index_default = componentCompiler;
57
+ export {
58
+ componentCompiler,
59
+ index_default as default
60
+ };
package/package.json CHANGED
@@ -1,32 +1,33 @@
1
1
  {
2
2
  "name": "@meituan-nocode/vite-plugin-nocode-compiler",
3
- "version": "0.1.0-beta.21-z",
4
- "description": "nocode compiler plugin",
3
+ "version": "0.1.0-beta.22-z",
4
+ "description": "Vite plugin for nocode compiler",
5
5
  "type": "module",
6
- "main": "dist/index.cjs.js",
7
- "module": "dist/index.es.js",
8
- "types": "dist/index.d.ts",
9
6
  "exports": {
10
7
  ".": {
11
- "require": "./dist/index.cjs.js",
12
- "import": "./dist/index.es.js",
13
- "types": "./dist/index.d.ts"
14
- }
8
+ "import": "./dist/index.js",
9
+ "require": "./dist/index.cjs"
10
+ },
11
+ "./package.json": "./package.json"
15
12
  },
13
+ "main": "./dist/index.cjs",
14
+ "types": "./dist/index.d.ts",
15
+ "module": "./dist/index.js",
16
16
  "files": [
17
17
  "dist"
18
18
  ],
19
19
  "scripts": {
20
- "dev": "tsc --watch",
21
- "build": "tsc",
20
+ "dev": "tsup --watch",
21
+ "build": "tsup",
22
22
  "prepublishOnly": "npm run build"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^20.0.0",
26
26
  "typescript": "^5.0.0",
27
- "vite": "^4.5.14"
27
+ "vite": "^4.5.14",
28
+ "tsup": "8.5.0"
28
29
  },
29
30
  "dependencies": {
30
- "@meituan-nocode/nocode-compiler-core": "0.1.0-beta.21-z"
31
+ "@meituan-nocode/nocode-compiler-core": "0.1.0-beta.22-z"
31
32
  }
32
33
  }
package/dist/utils.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export declare const JsFileExtList: string[];
2
- export declare const JsxParamList: string[];
3
- export declare function isJsTypeFile(file: string): boolean;
4
- /**
5
- * 规范化路径,将反斜杠转换为正斜杠
6
- * @param filePath 文件路径
7
- * @returns 规范化后的路径
8
- */
9
- export declare function normalizePath(filePath: string): string;
package/dist/utils.js DELETED
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JsxParamList = exports.JsFileExtList = void 0;
4
- exports.isJsTypeFile = isJsTypeFile;
5
- exports.normalizePath = normalizePath;
6
- exports.JsFileExtList = ['.js', '.ts', '.mjs', '.mts', '.jsx', '.tsx'];
7
- exports.JsxParamList = ['isJsx', 'isTsx', 'lang.jsx', 'lang.tsx'];
8
- // 是否为 JS 类型的文件
9
- function isJsTypeFile(file) {
10
- return exports.JsFileExtList.some(ext => file.endsWith(ext));
11
- }
12
- /**
13
- * 规范化路径,将反斜杠转换为正斜杠
14
- * @param filePath 文件路径
15
- * @returns 规范化后的路径
16
- */
17
- function normalizePath(filePath) {
18
- if (!filePath)
19
- return '';
20
- return filePath.replace(/\\/g, '/');
21
- }