@meituan-nocode/vite-plugin-nocode-compiler 0.1.0-beta.18-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 +1 -0
- package/dist/index.js +11 -2
- package/dist/utils.d.ts +14 -0
- package/dist/utils.js +37 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -34,8 +34,6 @@ 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");
|
|
@@ -54,6 +52,11 @@ catch (error) {
|
|
|
54
52
|
* 兼容 Vite 4.x 和 5.x 版本
|
|
55
53
|
*/
|
|
56
54
|
function NocodeCompiler(options = {}) {
|
|
55
|
+
options = {
|
|
56
|
+
enableLogging: false,
|
|
57
|
+
entryFileMarker: false,
|
|
58
|
+
...options,
|
|
59
|
+
};
|
|
57
60
|
// 创建代码转换器实例
|
|
58
61
|
const codeTransformer = new CodeTransformer(options);
|
|
59
62
|
return {
|
|
@@ -67,6 +70,11 @@ function NocodeCompiler(options = {}) {
|
|
|
67
70
|
const [_completePath, query] = id.split('?', 2); // 当前文件的绝对路径
|
|
68
71
|
let filePath = _completePath;
|
|
69
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
|
+
}
|
|
70
78
|
let fileType = '';
|
|
71
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'))) {
|
|
72
80
|
// jsx 代码
|
|
@@ -90,6 +98,7 @@ function NocodeCompiler(options = {}) {
|
|
|
90
98
|
content: code,
|
|
91
99
|
filePath,
|
|
92
100
|
fileType,
|
|
101
|
+
isEntry,
|
|
93
102
|
});
|
|
94
103
|
}
|
|
95
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.
|
|
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.
|
|
30
|
+
"@meituan-nocode/nocode-compiler-core": "0.1.0-beta.19-z"
|
|
31
31
|
}
|
|
32
32
|
}
|