@meituan-nocode/vite-plugin-nocode-compiler 0.1.0-beta.17-z → 0.1.0-beta.19-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.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export interface NocodeCompilerOptions {
2
2
  enableLogging?: boolean;
3
+ entryFileMarker?: boolean;
3
4
  }
4
5
  /**
5
6
  * Vite插件
package/dist/index.js CHANGED
@@ -34,17 +34,29 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.NocodeCompiler = NocodeCompiler;
37
- // import { Plugin } from 'vite';
38
- // 使用动态导入方式解决 ESM 和 CommonJS 的兼容性问题
39
37
  const compilerCore = __importStar(require("@meituan-nocode/nocode-compiler-core"));
40
38
  const { CodeTransformer } = compilerCore;
41
39
  const utils_1 = require("./utils");
40
+ // 检查是否安装了@vue/compiler-dom
41
+ let vueCompilerAvailable = false;
42
+ try {
43
+ require('@vue/compiler-dom');
44
+ vueCompilerAvailable = true;
45
+ }
46
+ catch (error) {
47
+ console.warn('[vite-plugin-nocode-compiler] @vue/compiler-dom not found. Vue compilation will be skipped.');
48
+ }
42
49
  /**
43
50
  * Vite插件
44
51
  * 用于在构建过程中处理Vue和React组件,添加nocode相关的标记
45
52
  * 兼容 Vite 4.x 和 5.x 版本
46
53
  */
47
54
  function NocodeCompiler(options = {}) {
55
+ options = {
56
+ enableLogging: false,
57
+ entryFileMarker: false,
58
+ ...options,
59
+ };
48
60
  // 创建代码转换器实例
49
61
  const codeTransformer = new CodeTransformer(options);
50
62
  return {
@@ -58,6 +70,11 @@ function NocodeCompiler(options = {}) {
58
70
  const [_completePath, query] = id.split('?', 2); // 当前文件的绝对路径
59
71
  let filePath = _completePath;
60
72
  const params = new URLSearchParams(query);
73
+ // 检查是否需要标记入口文件
74
+ const isEntry = options.entryFileMarker && (0, utils_1.isEntryFile)(filePath);
75
+ if (isEntry && options.enableLogging) {
76
+ console.log(`[vite-plugin-nocode-compiler] Processing entry file: ${filePath}`);
77
+ }
61
78
  let fileType = '';
62
79
  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'))) {
63
80
  // jsx 代码
@@ -71,11 +88,17 @@ function NocodeCompiler(options = {}) {
71
88
  // vue 代码
72
89
  fileType = 'vue';
73
90
  }
91
+ // 如果是Vue文件但@vue/compiler-dom不可用,跳过处理
92
+ if (fileType === 'vue' && !vueCompilerAvailable) {
93
+ console.warn(`[vite-plugin-nocode-compiler] Skipping Vue file processing for ${filePath} due to missing @vue/compiler-dom`);
94
+ return code;
95
+ }
74
96
  if (fileType) {
75
97
  return codeTransformer.transformCode({
76
98
  content: code,
77
99
  filePath,
78
100
  fileType,
101
+ isEntry,
79
102
  });
80
103
  }
81
104
  return code;
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,17 @@
1
1
  export declare const JsFileExtList: string[];
2
2
  export declare const jsxParamList: string[];
3
3
  export declare function isJsTypeFile(file: string): boolean;
4
+ /**
5
+ * 判断文件是否为入口文件
6
+ * 在 Vite 中,入口文件通常是 index.html 或者在 build.rollupOptions.input 中指定的文件
7
+ * 由于插件无法直接访问 Vite 配置,我们使用一些启发式方法来判断
8
+ * @param filePath 文件路径
9
+ * @returns 是否为入口文件
10
+ */
11
+ export declare function isEntryFile(filePath: string): boolean;
12
+ /**
13
+ * 规范化路径,将反斜杠转换为正斜杠
14
+ * @param filePath 文件路径
15
+ * @returns 规范化后的路径
16
+ */
17
+ export declare function normalizePath(filePath: string): string;
package/dist/utils.js CHANGED
@@ -1,10 +1,47 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.jsxParamList = exports.JsFileExtList = void 0;
4
7
  exports.isJsTypeFile = isJsTypeFile;
8
+ exports.isEntryFile = isEntryFile;
9
+ exports.normalizePath = normalizePath;
10
+ const path_1 = __importDefault(require("path"));
5
11
  exports.JsFileExtList = ['.js', '.ts', '.mjs', '.mts', '.jsx', '.tsx'];
6
12
  exports.jsxParamList = ['isJsx', 'isTsx', 'lang.jsx', 'lang.tsx'];
7
13
  // 是否为 JS 类型的文件
8
14
  function isJsTypeFile(file) {
9
15
  return exports.JsFileExtList.some(ext => file.endsWith(ext));
10
16
  }
17
+ /**
18
+ * 判断文件是否为入口文件
19
+ * 在 Vite 中,入口文件通常是 index.html 或者在 build.rollupOptions.input 中指定的文件
20
+ * 由于插件无法直接访问 Vite 配置,我们使用一些启发式方法来判断
21
+ * @param filePath 文件路径
22
+ * @returns 是否为入口文件
23
+ */
24
+ function isEntryFile(filePath) {
25
+ // 规范化路径
26
+ const normalizedPath = normalizePath(filePath);
27
+ // 检查是否为 index.html
28
+ if (normalizedPath.endsWith('/index.html') || normalizedPath.endsWith('\\index.html')) {
29
+ return true;
30
+ }
31
+ // 检查是否为 src/main.js, src/main.ts, src/index.js, src/index.ts 等常见入口文件
32
+ const fileName = path_1.default.basename(normalizedPath);
33
+ const dirName = path_1.default.dirname(normalizedPath);
34
+ if ((fileName === 'main.js' || fileName === 'main.ts' || fileName === 'main.jsx' || fileName === 'main.tsx' || fileName === 'index.js' || fileName === 'index.ts' || fileName === 'index.jsx' || fileName === 'index.tsx') && (dirName.endsWith('/src') || dirName.endsWith('\\src'))) {
35
+ return true;
36
+ }
37
+ // 如果有更多的入口文件模式,可以在这里添加
38
+ return false;
39
+ }
40
+ /**
41
+ * 规范化路径,将反斜杠转换为正斜杠
42
+ * @param filePath 文件路径
43
+ * @returns 规范化后的路径
44
+ */
45
+ function normalizePath(filePath) {
46
+ return filePath.replace(/\\/g, '/');
47
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meituan-nocode/vite-plugin-nocode-compiler",
3
- "version": "0.1.0-beta.17-z",
3
+ "version": "0.1.0-beta.19-z",
4
4
  "description": "nocode compiler plugin",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
@@ -27,6 +27,6 @@
27
27
  "vite": "^4.5.14"
28
28
  },
29
29
  "dependencies": {
30
- "@meituan-nocode/nocode-compiler-core": "0.1.0-beta.17-z"
30
+ "@meituan-nocode/nocode-compiler-core": "0.1.0-beta.19-z"
31
31
  }
32
32
  }