ms-vite-plugin 0.2.9 → 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 +63 -0
- package/package.json +1 -1
package/dist/build.js
CHANGED
|
@@ -130,6 +130,54 @@ function detectPython314() {
|
|
|
130
130
|
}
|
|
131
131
|
return { ok: false };
|
|
132
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
|
+
}
|
|
133
181
|
const buildAll = async (isDev = true, workspacePath) => {
|
|
134
182
|
const isJs = await fsExtra.pathExists(path.join(workspacePath, "scripts", "main.js"));
|
|
135
183
|
const isPy = await fsExtra.pathExists(path.join(workspacePath, "scripts", "main.py"));
|
|
@@ -188,6 +236,21 @@ const buildAll = async (isDev = true, workspacePath) => {
|
|
|
188
236
|
const py = detectPython314();
|
|
189
237
|
if (py.ok) {
|
|
190
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
|
+
}
|
|
191
254
|
}
|
|
192
255
|
else {
|
|
193
256
|
console.warn("⚠️ 未检测到 Python 3.14,请确保在目标运行环境安装 Python 3.14");
|