wxa-runner 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +25 -2
- package/bin/wxa-runner.js +100 -0
- package/package.json +43 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 open-wxa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
#
|
|
1
|
+
# wxa-runner
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
在普通浏览器里,用**微信官方基础库**运行小程序。为本地调试和 E2E 自动化测试而生。
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx wxa-runner dev ./dist/dev/mp-weixin # 原生小程序目录,或 uni-app / Taro 编译产物
|
|
7
|
+
# → http://localhost:3000
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
- 需要 Node.js ≥ 18。经常用或要在 CI 里跑,装成开发依赖:`pnpm add -D wxa-runner`
|
|
11
|
+
- 基础库和编译器不用另外准备:本机有微信开发者工具就用它的,没有就用随依赖安装的内置版本。
|
|
12
|
+
内置基础库从 GitHub 安装,需要本机有 git、能访问 github.com
|
|
13
|
+
- 目前只支持基础库 3.7.0 及以下
|
|
14
|
+
|
|
15
|
+
| 命令 | 作用 |
|
|
16
|
+
| --- | --- |
|
|
17
|
+
| `wxa-runner dev <项目目录>` | 启动开发服务器,改动后热更新 |
|
|
18
|
+
| `wxa-runner baselib list` | 列出可用的基础库及兼容性 |
|
|
19
|
+
| `wxa-runner baselib extract [版本]` | 解包基础库(`dev` 会自动执行) |
|
|
20
|
+
|
|
21
|
+
命令选项和环境变量见 [docs/cli.md](https://github.com/open-wxa/wxa-runner/blob/main/docs/cli.md);
|
|
22
|
+
跳过登录、热更新、在 Playwright 中测试见 [项目主页](https://github.com/open-wxa/wxa-runner#readme)。
|
|
23
|
+
|
|
24
|
+
## 许可证
|
|
25
|
+
|
|
26
|
+
MIT。内置基础库 [wxa-baselib](https://github.com/open-wxa/wxa-baselib) 是微信官方代码,版权归腾讯所有,不适用本项目的 MIT 协议。
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { Command } = require('commander');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { spawn } = require('child_process');
|
|
7
|
+
|
|
8
|
+
const program = new Command();
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.name('wxa-runner')
|
|
12
|
+
.description('在浏览器中用官方基础库运行微信小程序')
|
|
13
|
+
.version(require('../package.json').version);
|
|
14
|
+
|
|
15
|
+
program
|
|
16
|
+
.command('dev <project-path>')
|
|
17
|
+
.description('启动开发服务器')
|
|
18
|
+
.option('-p, --port <port>', '端口号', '3000')
|
|
19
|
+
.option('--host <host>', '监听地址', 'localhost')
|
|
20
|
+
.option('-b, --baselib <version>', '基础库版本(默认使用本机已安装的最新兼容版本)')
|
|
21
|
+
.option('--setup <file>', '小程序启动前执行的 setup 文件(默认使用项目目录下的 wxa.setup.ts / .js / .mjs)')
|
|
22
|
+
.option('--no-setup', '不执行 setup 文件')
|
|
23
|
+
.option('--no-watch', '不监听文件变化')
|
|
24
|
+
.option('-o, --open', '启动后打开浏览器')
|
|
25
|
+
.option('--real-login', '使用本机微信开发者工具登录态获取真实 code 和手机号')
|
|
26
|
+
.action(async (projectPath, options) => {
|
|
27
|
+
const { DevServer } = require('@open-wxa/wxa-runner-core');
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const server = new DevServer({
|
|
31
|
+
projectPath: path.resolve(process.cwd(), projectPath),
|
|
32
|
+
port: parseInt(options.port, 10),
|
|
33
|
+
host: options.host,
|
|
34
|
+
baseLibVersion: options.baselib,
|
|
35
|
+
setup: options.setup,
|
|
36
|
+
watch: options.watch,
|
|
37
|
+
realLogin: options.realLogin
|
|
38
|
+
});
|
|
39
|
+
const url = await server.start();
|
|
40
|
+
|
|
41
|
+
console.log('');
|
|
42
|
+
console.log(chalk.green(' wxa-runner 已启动'));
|
|
43
|
+
console.log(` 地址 ${chalk.cyan(url)}`);
|
|
44
|
+
console.log(` 项目 ${server.project.root}`);
|
|
45
|
+
console.log(` 基础库 ${server.baseLib.version}${server.baseLib.source === 'bundled' ? '(内置)' : ''}`);
|
|
46
|
+
if (server.setupFile) console.log(` setup ${server.setupFile}`);
|
|
47
|
+
console.log('');
|
|
48
|
+
|
|
49
|
+
if (options.open) openBrowser(url);
|
|
50
|
+
|
|
51
|
+
const shutdown = () => server.close().then(() => process.exit(0));
|
|
52
|
+
process.on('SIGINT', shutdown);
|
|
53
|
+
process.on('SIGTERM', shutdown);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error(chalk.red('\n启动失败:'), error.message);
|
|
56
|
+
process.exit(1);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const baselib = program.command('baselib').description('管理官方基础库');
|
|
61
|
+
|
|
62
|
+
baselib
|
|
63
|
+
.command('list')
|
|
64
|
+
.description('列出可用的基础库:本机微信开发者工具已下载的和内置的')
|
|
65
|
+
.action(() => {
|
|
66
|
+
const { listBaseLibs, MAX_COMPATIBLE_VERSION } = require('@open-wxa/wxa-runner-extractor');
|
|
67
|
+
const libs = listBaseLibs();
|
|
68
|
+
if (libs.length === 0) {
|
|
69
|
+
console.log(chalk.yellow('没有找到基础库,请先安装并打开一次微信开发者工具,或重新安装依赖以安装内置基础库'));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const defaultLib = libs.find(lib => lib.compatible);
|
|
73
|
+
for (const lib of libs) {
|
|
74
|
+
const source = lib.source === 'bundled' ? chalk.cyan(' (内置)') : '';
|
|
75
|
+
const mark = lib === defaultLib ? chalk.green(' (默认)') : lib.compatible ? '' : chalk.gray(` (> ${MAX_COMPATIBLE_VERSION},暂不支持)`);
|
|
76
|
+
console.log(` ${lib.version}${source}${mark}`);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
baselib
|
|
81
|
+
.command('extract [version]')
|
|
82
|
+
.description('解包基础库到缓存目录(dev 命令会自动执行;内置基础库无需解包,直接输出所在目录)')
|
|
83
|
+
.action(version => {
|
|
84
|
+
const { resolveBaseLib } = require('@open-wxa/wxa-runner-extractor');
|
|
85
|
+
try {
|
|
86
|
+
const lib = resolveBaseLib({ version });
|
|
87
|
+
console.log(`${chalk.green('✓')} 基础库 ${lib.version} → ${lib.dir}`);
|
|
88
|
+
} catch (error) {
|
|
89
|
+
console.error(chalk.red(error.message));
|
|
90
|
+
process.exit(1);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
function openBrowser(url) {
|
|
95
|
+
const command = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open';
|
|
96
|
+
const args = process.platform === 'win32' ? ['/c', 'start', '', url] : [url];
|
|
97
|
+
spawn(command, args, { stdio: 'ignore', detached: true }).unref();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
program.parse();
|
package/package.json
CHANGED
|
@@ -1,6 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wxa-runner",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Run WeChat Mini Programs in the browser on the official base library, for debugging and E2E testing",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"wechat",
|
|
7
|
+
"miniprogram",
|
|
8
|
+
"weapp",
|
|
9
|
+
"runtime",
|
|
10
|
+
"e2e",
|
|
11
|
+
"testing"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "open-wxa",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/open-wxa/wxa-runner.git",
|
|
18
|
+
"directory": "packages/cli"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/open-wxa/wxa-runner#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/open-wxa/wxa-runner/issues"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"wxa-runner": "./bin/wxa-runner.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"bin"
|
|
29
|
+
],
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"chalk": "^4.1.2",
|
|
32
|
+
"commander": "^11.1.0",
|
|
33
|
+
"@open-wxa/wxa-runner-core": "0.1.0",
|
|
34
|
+
"@open-wxa/wxa-runner-extractor": "0.1.0"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"registry": "https://registry.npmjs.org/"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"dev": "node bin/wxa-runner.js"
|
|
45
|
+
}
|
|
6
46
|
}
|