Repository navigation
fix(mini-ci): 修复 Windows 下 devToolsInstallPath 配置校验及开发者工具路径未加引号的问题 #19579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Single-Dancer
merged 3 commits into
NervJS:main
from
b84330808:fix/mini-ci-open-quote-paths
Oct 30, 2026
+163
−8
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| module.exports = { | ||
| preset: 'ts-jest', | ||
| moduleFileExtensions: ['js', 'ts', 'json', 'node'], | ||
| testEnvironment: 'node', | ||
| testMatch: ['<rootDir>/tests/**/*.spec.ts'], | ||
| transform: { | ||
| '^.+\\.ts$': ['ts-jest', { | ||
| diagnostics: false | ||
| }], | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,8 @@ export default (ctx: IPluginContext, _pluginOpts: CIOptions | (() => CIOptions)) | |
| type: joi.string().valid('miniProgram', 'miniProgramPlugin', 'miniGame', 'miniGamePlugin'), | ||
| ignores: joi.array().items(joi.string().required()), | ||
| robot: joi.number(), | ||
| setting: joi.object() | ||
| setting: joi.object(), | ||
| devToolsInstallPath: joi.string() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 放开这个配置后,WeappCI.init() 会在第一次构建时把 devToolsInstallPath 从共享配置对象中删掉。watch 模式下第二次构建会复用这个对象,之后就会退回默认安装路径。建议不要删除原配置字段,并补一个连续两次构建的回归测试。 |
||
| }), | ||
| /** 抖音小程序上传配置 */ | ||
| tt: joi.object({ | ||
|
|
@@ -71,14 +72,16 @@ export default (ctx: IPluginContext, _pluginOpts: CIOptions | (() => CIOptions)) | |
| toolId: joi.string().required(), | ||
| privateKeyPath: joi.string().required(), | ||
| clientType: joi.string().valid('alipay', 'ampe', 'amap', 'genie', 'alios', 'uc', 'quark', 'health', 'koubei', 'alipayiot', 'cainiao', 'alihealth'), | ||
| deleteVersion: joi.string().regex(/^\d+\.\d+\.\d+$/) | ||
| deleteVersion: joi.string().regex(/^\d+\.\d+\.\d+$/), | ||
| devToolsInstallPath: joi.string() | ||
| }), | ||
| joi.object({ | ||
| appid: joi.string().required(), | ||
| toolId: joi.string().required(), | ||
| privateKey: joi.string().required(), | ||
| clientType: joi.string().valid('alipay', 'ampe', 'amap', 'genie', 'alios', 'uc', 'quark', 'health', 'koubei', 'alipayiot', 'cainiao', 'alihealth'), | ||
| deleteVersion: joi.string().regex(/^\d+\.\d+\.\d+$/) | ||
| deleteVersion: joi.string().regex(/^\d+\.\d+\.\d+$/), | ||
| devToolsInstallPath: joi.string() | ||
| }), | ||
|
|
||
| ), | ||
|
|
@@ -97,7 +100,8 @@ export default (ctx: IPluginContext, _pluginOpts: CIOptions | (() => CIOptions)) | |
| /** 百度小程序上传配置 */ | ||
| swan: joi.object({ | ||
| token: joi.string().required(), | ||
| minSwanVersion: joi.string() | ||
| minSwanVersion: joi.string(), | ||
| devToolsInstallPath: joi.string() | ||
| }), | ||
| jd: joi.object({ | ||
| privateKey: joi.string().required(), | ||
|
|
||
106 changes: 106 additions & 0 deletions
106
packages/taro-plugin-mini-ci/tests/open-devtools.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import * as crypto from 'node:crypto' | ||
| import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' | ||
| import { readFile } from 'node:fs/promises' | ||
| import { tmpdir } from 'node:os' | ||
| import * as path from 'node:path' | ||
|
|
||
| import SwanCI from '../src/SwanCI' | ||
| import WeappCI from '../src/WeappCI' | ||
|
|
||
| jest.mock('../src/utils/npm', () => ({ | ||
| getNpmPkgSync: () => ({ Project: class {} }), | ||
| resolveNpmSync: () => '' | ||
| })) | ||
|
|
||
| let root: string | null = null | ||
|
|
||
| afterEach(() => { | ||
| if (root) { | ||
| rmSync(root, { recursive: true, force: true }) | ||
| root = null | ||
| } | ||
| }) | ||
|
|
||
| function setup () { | ||
| // 目录名带空格,模拟 C:\Program Files (x86)\... 这类默认安装路径 | ||
| root = mkdtempSync(path.join(tmpdir(), 'taro mini ci ')) | ||
| const projectPath = path.join(root, 'my app', 'dist') | ||
| const argsFile = path.join(root, 'args.txt') | ||
| mkdirSync(projectPath, { recursive: true }) | ||
| writeFileSync(path.join(root, 'package.json'), '{}') | ||
| writeFileSync(path.join(root, 'private.key'), '') | ||
| const ctx = { | ||
| paths: { appPath: root }, | ||
| helper: { | ||
| fs: { | ||
| readFileSync, | ||
| readFile, | ||
| pathExists: async (p: string) => existsSync(p), | ||
| pathExistsSync: existsSync | ||
| }, | ||
| chalk: { red: (s: string) => s }, | ||
| printLog: () => {}, | ||
| processTypeEnum: {}, | ||
| getUserHomeDir: () => root | ||
| } | ||
| } | ||
| // 假的开发者工具命令行:把收到的参数写入 args.txt | ||
| const createCli = (installPath: string) => { | ||
| mkdirSync(installPath, { recursive: true }) | ||
| writeFileSync(path.join(installPath, 'cli.bat'), `@echo %*> "${argsFile}"\r\n`) | ||
| } | ||
| return { root, projectPath, argsFile, ctx, createCli } | ||
| } | ||
|
|
||
| describe('weapp devToolsInstallPath', () => { | ||
| it('keeps the configured path for the next build in watch mode', () => { | ||
| const { root, ctx } = setup() | ||
| const installPath = path.join(root, 'devtools') | ||
| // watch 模式下每次构建都会用同一份插件配置创建新的 WeappCI | ||
| const pluginOpts = { | ||
| weapp: { appid: 'wx0000000000000000', privateKeyPath: 'private.key', devToolsInstallPath: installPath } | ||
| } | ||
|
|
||
| for (let build = 0; build < 2; build++) { | ||
| const ci = new WeappCI(ctx as any, pluginOpts) | ||
| ci.init() | ||
| expect((ci as any).devToolsInstallPath).toBe(installPath) | ||
| } | ||
| expect(pluginOpts.weapp.devToolsInstallPath).toBe(installPath) | ||
| }) | ||
| }) | ||
|
|
||
| const describeOnWindows = process.platform === 'win32' ? describe : describe.skip | ||
|
|
||
| describeOnWindows('open devtools on Windows', () => { | ||
| it('weapp: works when the install path and project path contain spaces', async () => { | ||
| const { root, projectPath, argsFile, ctx, createCli } = setup() | ||
| const installPath = path.join(root, 'Program Files (x86)', 'Tencent', '微信web开发者工具') | ||
| createCli(installPath) | ||
| const md5 = crypto.createHash('md5').update(installPath).digest('hex') | ||
| const ideStatusDir = path.join(root, 'AppData', 'Local', '微信开发者工具', 'User Data', md5, 'Default') | ||
| mkdirSync(ideStatusDir, { recursive: true }) | ||
| writeFileSync(path.join(ideStatusDir, '.ide-status'), 'On') | ||
|
|
||
| const ci = new WeappCI(ctx as any, { | ||
| weapp: { appid: 'wx0000000000000000', privateKeyPath: 'private.key', devToolsInstallPath: installPath } | ||
| }) | ||
| ci.setProjectPath(projectPath) | ||
| ci.init() | ||
| await ci.open() | ||
|
|
||
| expect(readFileSync(argsFile, 'utf8').trim()).toBe(`open --project "${projectPath}"`) | ||
| }) | ||
|
|
||
| it('swan: works when the install path and project path contain spaces', async () => { | ||
| const { root, projectPath, argsFile, ctx, createCli } = setup() | ||
| const installPath = path.join(root, 'Program Files', 'swan-ide-gui') | ||
| createCli(installPath) | ||
|
|
||
| const ci = new SwanCI(ctx as any, { swan: { token: 'token', devToolsInstallPath: installPath } }) | ||
| ci.setProjectPath(projectPath) | ||
| await ci.open() | ||
|
|
||
| expect(readFileSync(argsFile, 'utf8').trim()).toBe(`--project-path "${projectPath}"`) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { createRequire } from 'node:module' | ||
|
|
||
| import miniCI from '../src/index' | ||
|
|
||
| // 使用与 @tarojs/service 校验插件参数时相同的 joi | ||
| const joi = createRequire(require.resolve('@tarojs/service/package.json'))('joi') | ||
|
|
||
| function validate (opts) { | ||
| let optsSchema | ||
| const ctx = { | ||
| addPluginOptsSchema: (schema) => { | ||
| optsSchema = schema | ||
| }, | ||
| registerCommand: () => {} | ||
| } | ||
| miniCI(ctx as any, opts) | ||
| return optsSchema(joi).validate(opts) | ||
| } | ||
|
|
||
| describe('plugin options schema', () => { | ||
| it.each([ | ||
| ['weapp', { appid: 'wx0000000000000000', privateKeyPath: 'private.key' }], | ||
| ['alipay', { appid: '2021000000000000', toolId: 'tool-id', privateKeyPath: 'private.txt' }], | ||
| ['alipay', { appid: '2021000000000000', toolId: 'tool-id', privateKey: 'private-key' }], | ||
| ['swan', { token: 'token' }], | ||
| ['dd', { appid: 'dd-appid', token: 'token' }] | ||
| ])('accepts devToolsInstallPath for %s', (platform, config) => { | ||
| const { error } = validate({ | ||
| [platform]: { ...config, devToolsInstallPath: 'D:\\Program Files\\devtools' } | ||
| }) | ||
| expect(error).toBeUndefined() | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
避免 shell 展开安装路径。
新允许的
devToolsInstallPath在 macOS 上可以包含$。例如,实际目录名包含$HOME时,双引号内仍会发生变量展开,CLI 将使用错误的路径。命令替换也会被执行。(gnu.org)请在 macOS 上使用不经过 shell 的参数数组调用。
SwanCI.open的 Line 37 有相同问题。OpenGrep (1.30.1)
[ERROR] 83-83: A nonliteral argument is passed to exec/execSync. Identify the receiver: Node child_process methods execute shell commands, while regular-expression and database methods have different contracts. For shell execution, prefer execFile or spawn with an argument array.
(coderabbit.command-injection.exec-js)
Source: Linters/SAST tools