ms-vite-plugin 0.2.8 → 0.3.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/dist/build.js +94 -0
- package/package.json +4 -4
package/dist/build.js
CHANGED
|
@@ -41,6 +41,7 @@ const zip_a_folder_1 = require("zip-a-folder");
|
|
|
41
41
|
const fsExtra = __importStar(require("fs-extra"));
|
|
42
42
|
const path = __importStar(require("path"));
|
|
43
43
|
const vite_1 = require("vite");
|
|
44
|
+
const child_process_1 = require("child_process");
|
|
44
45
|
const vite_plugin_bundle_obfuscator_1 = __importDefault(require("vite-plugin-bundle-obfuscator"));
|
|
45
46
|
/**
|
|
46
47
|
* 查找入口文件:main.js/main.ts 和所有以 _thread 结尾的 JS/TS 文件
|
|
@@ -107,6 +108,76 @@ function prodReturnMain() {
|
|
|
107
108
|
},
|
|
108
109
|
};
|
|
109
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* 检测系统是否存在 Python 3.14
|
|
113
|
+
* - 依次尝试 python3.14、python3、py -3.14(Windows)
|
|
114
|
+
* - 返回检测结果与版本字符串
|
|
115
|
+
*/
|
|
116
|
+
function detectPython314() {
|
|
117
|
+
const candidates = [
|
|
118
|
+
{ cmd: "python3.14", args: ["--version"] },
|
|
119
|
+
{ cmd: "python3", args: ["--version"] },
|
|
120
|
+
];
|
|
121
|
+
for (const c of candidates) {
|
|
122
|
+
try {
|
|
123
|
+
const r = (0, child_process_1.spawnSync)(c.cmd, c.args, { encoding: "utf8" });
|
|
124
|
+
const out = (r.stdout || r.stderr || "").trim();
|
|
125
|
+
if (out && /Python\s+3\.14(\.\d+)?/i.test(out)) {
|
|
126
|
+
return { ok: true, path: c.cmd, version: out };
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch { }
|
|
130
|
+
}
|
|
131
|
+
return { ok: false };
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 处理 Python 构建产物:
|
|
135
|
+
* - 将所有 ".cpython-314.pyc" 重命名为 ".pyc"
|
|
136
|
+
* - 将 __pycache__/name.cpython-314.pyc 移动到上级目录为 name.pyc
|
|
137
|
+
* - 删除所有 ".py" 源文件
|
|
138
|
+
*/
|
|
139
|
+
async function normalizePythonArtifacts(rootDir) {
|
|
140
|
+
async function walk(dir) {
|
|
141
|
+
const entries = await fsExtra.readdir(dir, { withFileTypes: true });
|
|
142
|
+
for (const entry of entries) {
|
|
143
|
+
const full = path.join(dir, entry.name);
|
|
144
|
+
if (entry.isDirectory()) {
|
|
145
|
+
if (entry.name === "__pycache__") {
|
|
146
|
+
const cacheEntries = await fsExtra.readdir(full, {
|
|
147
|
+
withFileTypes: true,
|
|
148
|
+
});
|
|
149
|
+
for (const ce of cacheEntries) {
|
|
150
|
+
const cacheFull = path.join(full, ce.name);
|
|
151
|
+
if (ce.isFile() && ce.name.endsWith(".cpython-314.pyc")) {
|
|
152
|
+
const parent = path.dirname(full);
|
|
153
|
+
const base = ce.name.replace(/\.cpython-314\.pyc$/, ".pyc");
|
|
154
|
+
const target = path.join(parent, base);
|
|
155
|
+
await fsExtra.move(cacheFull, target, { overwrite: true });
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// 清理 __pycache__ 目录
|
|
159
|
+
try {
|
|
160
|
+
await fsExtra.remove(full);
|
|
161
|
+
}
|
|
162
|
+
catch { }
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
await walk(full);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else if (entry.isFile()) {
|
|
169
|
+
if (entry.name.endsWith(".cpython-314.pyc")) {
|
|
170
|
+
const target = full.replace(".cpython-314.pyc", ".pyc");
|
|
171
|
+
await fsExtra.move(full, target, { overwrite: true });
|
|
172
|
+
}
|
|
173
|
+
else if (entry.name.endsWith(".py")) {
|
|
174
|
+
await fsExtra.remove(full);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
await walk(rootDir);
|
|
180
|
+
}
|
|
110
181
|
const buildAll = async (isDev = true, workspacePath) => {
|
|
111
182
|
const isJs = await fsExtra.pathExists(path.join(workspacePath, "scripts", "main.js"));
|
|
112
183
|
const isPy = await fsExtra.pathExists(path.join(workspacePath, "scripts", "main.py"));
|
|
@@ -161,6 +232,29 @@ const buildAll = async (isDev = true, workspacePath) => {
|
|
|
161
232
|
await fsExtra.ensureDir(outPath);
|
|
162
233
|
if (isPy) {
|
|
163
234
|
await fsExtra.copy(path.join(workspacePath, "scripts"), path.join(outPath, "scripts"));
|
|
235
|
+
// 获取系统有没有 3.14 版本的 python
|
|
236
|
+
const py = detectPython314();
|
|
237
|
+
if (py.ok) {
|
|
238
|
+
console.log(`✅ 检测到 ${py.version} (${py.path})`);
|
|
239
|
+
// python -m compileall scripts
|
|
240
|
+
const r = (0, child_process_1.spawnSync)(py.path, ["-m", "compileall", "scripts"], {
|
|
241
|
+
encoding: "utf8",
|
|
242
|
+
cwd: outPath,
|
|
243
|
+
});
|
|
244
|
+
if (r.status === 0) {
|
|
245
|
+
console.log("✅ 成功编译所有 Python 文件");
|
|
246
|
+
// 修改所有 .cpython-314.pyc 为 .pyc,并删除所有 .py 文件
|
|
247
|
+
await normalizePythonArtifacts(path.join(outPath, "scripts"));
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
console.error("❌ 编译 Python 文件失败");
|
|
251
|
+
console.error(r.stderr);
|
|
252
|
+
process.exit(1);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
console.warn("⚠️ 未检测到 Python 3.14,请确保在目标运行环境安装 Python 3.14");
|
|
257
|
+
}
|
|
164
258
|
}
|
|
165
259
|
// 打包完成后执行
|
|
166
260
|
await fsExtra.copy(path.join(workspacePath, "res"), path.join(outPath, "res"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ms-vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"commander": "^14.0.2",
|
|
23
23
|
"fs-extra": "^11.3.2",
|
|
24
|
-
"vite": "^7.2.
|
|
24
|
+
"vite": "^7.2.4",
|
|
25
25
|
"vite-plugin-bundle-obfuscator": "^1.8.0",
|
|
26
|
-
"zip-a-folder": "^
|
|
26
|
+
"zip-a-folder": "^4.0.4"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/fs-extra": "^11.0.4",
|
|
30
|
-
"@types/node": "^24.10.
|
|
30
|
+
"@types/node": "^24.10.1",
|
|
31
31
|
"typescript": "~5.9.3"
|
|
32
32
|
}
|
|
33
33
|
}
|