feat: 优化跨平台路径解析并修复引号拼接 Bug

This commit is contained in:
yczpf2019
2026-01-24 16:02:28 +08:00
parent 0bdd6b4dc6
commit d5aa1c6c8c
4 changed files with 28 additions and 32 deletions

1
.gitignore vendored
View File

@@ -8,5 +8,6 @@ yarn.lock
dist
/temp
/arduino-cli
/arduino-libs
/bundle.cjs
/nw_cache

35
package-lock.json generated
View File

@@ -811,6 +811,7 @@
"resolved": "https://registry.npmmirror.com/acorn/-/acorn-8.14.0.tgz",
"integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==",
"dev": true,
"peer": true,
"bin": {
"acorn": "bin/acorn"
},
@@ -832,6 +833,7 @@
"resolved": "https://registry.npmmirror.com/ajv/-/ajv-6.12.6.tgz",
"integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
"dev": true,
"peer": true,
"dependencies": {
"fast-deep-equal": "^3.1.1",
"fast-json-stable-stringify": "^2.0.0",
@@ -1155,6 +1157,7 @@
"url": "https://github.com/sponsors/ai"
}
],
"peer": true,
"dependencies": {
"caniuse-lite": "^1.0.30001669",
"electron-to-chromium": "^1.5.41",
@@ -1229,20 +1232,6 @@
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
"dev": true
},
"node_modules/bufferutil": {
"version": "4.0.8",
"resolved": "https://registry.npmmirror.com/bufferutil/-/bufferutil-4.0.8.tgz",
"integrity": "sha512-4T53u4PdgsXqKaIctwF8ifXlRTTmEPJ8iEPWFdGZvcf7sbwYo6FKFEX9eNNAnzFZ7EzJAQ3CJeOtCRA4rDp7Pw==",
"hasInstallScript": true,
"optional": true,
"peer": true,
"dependencies": {
"node-gyp-build": "^4.3.0"
},
"engines": {
"node": ">=6.14.2"
}
},
"node_modules/bytes": {
"version": "3.1.2",
"resolved": "https://registry.npmmirror.com/bytes/-/bytes-3.1.2.tgz",
@@ -2020,6 +2009,7 @@
"deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.6.1",
@@ -4960,6 +4950,7 @@
"resolved": "https://registry.npmmirror.com/ajv/-/ajv-8.17.1.tgz",
"integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
"dev": true,
"peer": true,
"dependencies": {
"fast-deep-equal": "^3.1.3",
"fast-uri": "^3.0.1",
@@ -5996,20 +5987,6 @@
"node": "^18 || ^20 || >= 21"
}
},
"node_modules/utf-8-validate": {
"version": "6.0.5",
"resolved": "https://registry.npmmirror.com/utf-8-validate/-/utf-8-validate-6.0.5.tgz",
"integrity": "sha512-EYZR+OpIXp9Y1eG1iueg8KRsY8TuT8VNgnanZ0uA3STqhHQTLwbl+WX76/9X5OY12yQubymBpaBSmMPkSTQcKA==",
"hasInstallScript": true,
"optional": true,
"peer": true,
"dependencies": {
"node-gyp-build": "^4.3.0"
},
"engines": {
"node": ">=6.14.2"
}
},
"node_modules/util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/util-deprecate/-/util-deprecate-1.0.2.tgz",
@@ -6069,6 +6046,7 @@
"resolved": "https://registry.npmmirror.com/webpack/-/webpack-5.96.1.tgz",
"integrity": "sha512-l2LlBSvVZGhL4ZrPwyr8+37AunkcYj5qh8o6u2/2rzoPc8gxFJkLj1WxNgooi9pnoc06jh0BjuXnamM4qlujZA==",
"dev": true,
"peer": true,
"dependencies": {
"@types/eslint-scope": "^3.7.7",
"@types/estree": "^1.0.6",
@@ -6115,6 +6093,7 @@
"resolved": "https://registry.npmmirror.com/webpack-cli/-/webpack-cli-5.1.4.tgz",
"integrity": "sha512-pIDJHIEI9LR0yxHXQ+Qh95k2EvXpWzZ5l+d+jIo+RdSm9MiHfzazIxwwni/p7+x4eJZuvG1AJwgC4TNQ7NRgsg==",
"dev": true,
"peer": true,
"dependencies": {
"@discoveryjs/json-ext": "^0.5.0",
"@webpack-cli/configtest": "^2.1.1",

View File

@@ -4,18 +4,34 @@ import fsExtra from 'fs-extra';
function processConfig(data) {
const resolvePath = (p) => {
if (!p || typeof p !== 'string') {
return p;
}
// 如果是系统命令(不含路径斜杠),不作为路径处理,直接返回原名
if (!p.includes('/') && !p.includes('\\')) {
return p;
}
// 如果已经是绝对路径,则直接返回
if (path.isAbsolute(p)) {
return p;
}
// 否则解析为相对于当前工作目录的路径
return path.resolve(process.cwd(), p);
};
for (let i in data.path) {
if (!data.path[i]) {
continue;
}
if (typeof data.path[i] === 'string') {
data.path[i] = path.resolve(process.cwd(), data.path[i]);
data.path[i] = resolvePath(data.path[i]);
} else if (typeof data.path[i] === 'object') {
for (let j in data.path[i]) {
if (typeof data.path[i][j] !== 'string') {
continue;
}
data.path[i][j] = path.resolve(process.cwd(), data.path[i][j]);
data.path[i][j] = resolvePath(data.path[i][j]);
}
}
}

View File

@@ -12,7 +12,7 @@ export default class ShellMicroPython extends Shell {
async burn(config) {
const info = {
indexPath: path.resolve(CLIENT_PATH, config.boardDirPath),
esptool: `${PYTHON.path.cli}" "${MICROPYTHON.path.esptool}`,
esptool: `"${PYTHON.path.cli}" "${MICROPYTHON.path.esptool}`,
com: config.port
};
const command = MString.tpl(config.command, info);
@@ -22,7 +22,7 @@ export default class ShellMicroPython extends Shell {
async upload(config) {
const info = {
indexPath: path.resolve(CLIENT_PATH, config.boardDirPath),
ampy: `${PYTHON.path.cli}" "${MICROPYTHON.path.ampy}`,
ampy: `"${PYTHON.path.cli}" "${MICROPYTHON.path.ampy}`,
com: config.port
};
const command = MString.tpl(config.command, info);