@open-wxa/wxa-runner-compiler 0.0.0-stage → 0.2.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 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,10 @@
1
- # Temporary Holding Version
1
+ # @open-wxa/wxa-runner-compiler
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [wxa-runner](https://github.com/open-wxa/wxa-runner) 的内部包:调用微信官方的 WXML / WXSS 编译器(wcc / wcsc)。
4
+ 一般不需要直接安装,用 [`wxa-runner`](https://www.npmjs.com/package/wxa-runner) 即可。
5
+
6
+ 编译器依次从这些位置查找:
7
+
8
+ 1. 环境变量 `WXA_WCC` + `WXA_WCSC`
9
+ 2. 本机微信开发者工具(不在默认位置时用 `WXA_DEVTOOLS_PATH` 指定)
10
+ 3. 随依赖安装的 [miniprogram-compiler](https://www.npmjs.com/package/miniprogram-compiler),Linux 只支持 x86-64
@@ -0,0 +1,67 @@
1
+ /**
2
+ * WXML 编译(wcc)
3
+ *
4
+ * 所有 wxml/wxs 一次性编译成一个 $gwx 函数,模板 import/include 和 wxs 引用由 wcc 自己解析。
5
+ */
6
+ interface ComponentTags {
7
+ /** 页面或组件路径,不带扩展名,如 "pages/index/index" */
8
+ path: string;
9
+ /** 该 wxml 中属于自定义组件(含抽象节点)的标签名 */
10
+ tags: string[];
11
+ }
12
+ interface WxmlCompileOptions {
13
+ /** 小程序根目录 */
14
+ cwd: string;
15
+ /** 相对 cwd 的 ./ 开头路径,包含 .wxml 和 .wxs */
16
+ files: string[];
17
+ components: ComponentTags[];
18
+ /**
19
+ * true:逻辑层使用的裁剪版(-xc),只保留组件结构信息;
20
+ * false:渲染层使用的完整版(-cc)
21
+ */
22
+ cut: boolean;
23
+ genfuncName?: string;
24
+ }
25
+ declare function compileWxml(options: WxmlCompileOptions): Promise<string>;
26
+
27
+ /**
28
+ * WXSS 编译(wcsc)
29
+ *
30
+ * 输出是 "key=value=key=value" 交替的字符串,value 是转义过的 JS 源码:
31
+ * comm 公共运行时(setCssToHead、rpx 换算)以及非页面样式(app.wxss 等)的立即执行代码
32
+ * ./pages/a.wxss 每个页面/组件一个 setCssToHead(...),返回的函数在页面创建时调用
33
+ */
34
+ interface WxssCompileOptions {
35
+ cwd: string;
36
+ /** 页面和组件的 wxss,./ 开头 */
37
+ pageFiles: string[];
38
+ /** 其余样式(app.wxss),以公共样式形式写入 comm */
39
+ commonFiles: string[];
40
+ }
41
+ interface WxssCompileResult {
42
+ comm: string;
43
+ /** 键为不带 ./ 的路径,如 "pages/index/index.wxss" */
44
+ pages: Record<string, string>;
45
+ }
46
+ declare function compileWxss(options: WxssCompileOptions): Promise<WxssCompileResult>;
47
+ declare function parseWcscOutput(output: string): Record<string, string>;
48
+ declare function unescapeJsString(value: string): string;
49
+
50
+ /**
51
+ * 定位 wcc / wcsc 可执行文件
52
+ *
53
+ * 使用开发者工具自带的命令行版本(node_modules/wcc-exec),而不是 wcc.node 原生模块:
54
+ * 原生模块在 Node 进程里重复调用会随机触发 std::bad_alloc 崩溃,
55
+ * 子进程方式则天然隔离,单次编译只需几毫秒。
56
+ *
57
+ * 没有开发者工具时(如 Linux、CI),用微信官方 npm 包 miniprogram-compiler 自带的编译器。
58
+ * 它的编译内核较旧(20200413,开发者工具为 20211229):页面的编译结果相同,
59
+ * 只有模板运行时有少量差异,如旧版限制单页最多 16000 个节点。
60
+ */
61
+ interface CompilerBinaries {
62
+ wcc: string;
63
+ wcsc: string;
64
+ }
65
+ declare function findCompilerBinaries(): CompilerBinaries;
66
+
67
+ export { type CompilerBinaries, type ComponentTags, type WxmlCompileOptions, type WxssCompileOptions, type WxssCompileResult, compileWxml, compileWxss, findCompilerBinaries, parseWcscOutput, unescapeJsString };
package/dist/index.js ADDED
@@ -0,0 +1,188 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ compileWxml: () => compileWxml,
34
+ compileWxss: () => compileWxss,
35
+ findCompilerBinaries: () => findCompilerBinaries,
36
+ parseWcscOutput: () => parseWcscOutput,
37
+ unescapeJsString: () => unescapeJsString
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+
41
+ // src/wcc.ts
42
+ var import_fs2 = __toESM(require("fs"));
43
+ var import_os = __toESM(require("os"));
44
+ var import_path2 = __toESM(require("path"));
45
+
46
+ // src/exec.ts
47
+ var import_child_process = require("child_process");
48
+ var MAX_OUTPUT = 512 * 1024 * 1024;
49
+ function runCompiler(bin, args, cwd) {
50
+ return new Promise((resolve, reject) => {
51
+ (0, import_child_process.execFile)(bin, args, { cwd, maxBuffer: MAX_OUTPUT, encoding: "utf8" }, (error, stdout, stderr) => {
52
+ if (error) {
53
+ const detail = (stderr || stdout || error.message).trim();
54
+ reject(new Error(`${bin.split(/[\\/]/).pop()} \u7F16\u8BD1\u5931\u8D25\uFF1A
55
+ ${detail}`));
56
+ return;
57
+ }
58
+ resolve(stdout);
59
+ });
60
+ });
61
+ }
62
+
63
+ // src/locate.ts
64
+ var import_fs = __toESM(require("fs"));
65
+ var import_path = __toESM(require("path"));
66
+ var import_wxa_runner_extractor = require("@open-wxa/wxa-runner-extractor");
67
+ var cached = null;
68
+ function findCompilerBinaries() {
69
+ if (!cached) cached = locateCompilerBinaries((0, import_wxa_runner_extractor.findDevtoolsPackageDirs)());
70
+ return cached;
71
+ }
72
+ function locateCompilerBinaries(devtoolsDirs) {
73
+ const ext = process.platform === "win32" ? ".exe" : "";
74
+ const candidates = [];
75
+ if (process.env.WXA_WCC && process.env.WXA_WCSC) {
76
+ candidates.push({ wcc: process.env.WXA_WCC, wcsc: process.env.WXA_WCSC });
77
+ }
78
+ for (const dir of devtoolsDirs) {
79
+ const execDir = import_path.default.join(dir, "node_modules", "wcc-exec");
80
+ candidates.push({ wcc: import_path.default.join(execDir, "wcc" + ext), wcsc: import_path.default.join(execDir, "wcsc" + ext) });
81
+ }
82
+ const packaged = findPackagedCompiler(ext);
83
+ if (packaged) candidates.push(packaged);
84
+ const found = candidates.find((c) => import_fs.default.existsSync(c.wcc) && import_fs.default.existsSync(c.wcsc));
85
+ if (!found) {
86
+ throw new Error(
87
+ "\u6CA1\u6709\u627E\u5230 wcc/wcsc \u7F16\u8BD1\u5668\u3002\u8BF7\u5B89\u88C5\u5FAE\u4FE1\u5F00\u53D1\u8005\u5DE5\u5177\uFF0C\u6216\u91CD\u65B0\u5B89\u88C5\u4F9D\u8D56\u4EE5\u5B89\u88C5 miniprogram-compiler\uFF08Linux \u53EA\u652F\u6301 x86-64\uFF09\uFF0C\u6216\u901A\u8FC7 WXA_DEVTOOLS_PATH / WXA_WCC + WXA_WCSC \u6307\u5B9A\u4F4D\u7F6E\u3002"
88
+ );
89
+ }
90
+ if (found === packaged) {
91
+ for (const file of [found.wcc, found.wcsc]) {
92
+ try {
93
+ import_fs.default.accessSync(file, import_fs.default.constants.X_OK);
94
+ } catch {
95
+ import_fs.default.chmodSync(file, 493);
96
+ }
97
+ }
98
+ }
99
+ return found;
100
+ }
101
+ function findPackagedCompiler(ext) {
102
+ const platformDir = process.platform === "darwin" ? "mac" : process.platform === "win32" ? "windows" : process.platform === "linux" && process.arch === "x64" ? "linux" : null;
103
+ if (!platformDir) return null;
104
+ let root;
105
+ try {
106
+ root = import_path.default.dirname(require.resolve("miniprogram-compiler/package.json"));
107
+ } catch {
108
+ return null;
109
+ }
110
+ const dir = import_path.default.join(root, "bin", platformDir);
111
+ return { wcc: import_path.default.join(dir, "wcc" + ext), wcsc: import_path.default.join(dir, "wcsc" + ext) };
112
+ }
113
+
114
+ // src/wcc.ts
115
+ var MAX_INLINE_ARGS_LENGTH = 3e4;
116
+ async function compileWxml(options) {
117
+ const { wcc } = findCompilerBinaries();
118
+ const split = `>_<${Date.now() % 1e4}`;
119
+ const config = [options.components.length];
120
+ for (const component of options.components) {
121
+ config.push(`./${component.path}.wxml`, component.tags.length, ...component.tags);
122
+ }
123
+ const args = ["-d", "--split", split, options.cut ? "-xc" : "-cc", config.join(split)];
124
+ if (options.files.some((file) => file.endsWith(".wxs"))) {
125
+ args.unshift("-ds");
126
+ }
127
+ args.push(...options.files, "-gn", options.genfuncName || "$gwx");
128
+ if (args.join(" ").length <= MAX_INLINE_ARGS_LENGTH) {
129
+ return runCompiler(wcc, args, options.cwd);
130
+ }
131
+ const configFile = import_path2.default.join(import_os.default.tmpdir(), `wxa-runner-wcc-${process.pid}-${Date.now()}.txt`);
132
+ import_fs2.default.writeFileSync(configFile, args.join("\n"));
133
+ try {
134
+ return await runCompiler(wcc, ["--config-path", configFile], options.cwd);
135
+ } finally {
136
+ import_fs2.default.rmSync(configFile, { force: true });
137
+ }
138
+ }
139
+
140
+ // src/wcsc.ts
141
+ async function compileWxss(options) {
142
+ const { wcsc } = findCompilerBinaries();
143
+ const files = [...options.pageFiles, ...options.commonFiles];
144
+ if (files.length === 0) {
145
+ return { comm: "", pages: {} };
146
+ }
147
+ const args = ["-db", "-pc", String(options.pageFiles.length), ...files];
148
+ const raw = parseWcscOutput(await runCompiler(wcsc, args, options.cwd));
149
+ const pages = {};
150
+ for (const file of options.pageFiles) {
151
+ if (raw[file] !== void 0) pages[file.replace(/^\.\//, "")] = raw[file];
152
+ }
153
+ return { comm: raw.comm || "", pages };
154
+ }
155
+ function parseWcscOutput(output) {
156
+ const parts = output.split("=");
157
+ const result = {};
158
+ for (let i = 0; i + 1 < parts.length; i += 2) {
159
+ result[parts[i]] = unescapeJsString(parts[i + 1]);
160
+ }
161
+ return result;
162
+ }
163
+ var SIMPLE_ESCAPES = {
164
+ n: "\n",
165
+ t: " ",
166
+ r: "\r",
167
+ b: "\b",
168
+ f: "\f",
169
+ v: "\v",
170
+ "0": "\0"
171
+ };
172
+ function unescapeJsString(value) {
173
+ return value.replace(/\\(x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|[\s\S])/g, (_, seq) => {
174
+ if ((seq[0] === "x" || seq[0] === "u") && seq.length > 1) {
175
+ return String.fromCharCode(parseInt(seq.slice(1), 16));
176
+ }
177
+ return SIMPLE_ESCAPES[seq] ?? seq;
178
+ });
179
+ }
180
+ // Annotate the CommonJS export names for ESM import in node:
181
+ 0 && (module.exports = {
182
+ compileWxml,
183
+ compileWxss,
184
+ findCompilerBinaries,
185
+ parseWcscOutput,
186
+ unescapeJsString
187
+ });
188
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/wcc.ts","../src/exec.ts","../src/locate.ts","../src/wcsc.ts"],"sourcesContent":["/**\n * wxa-runner-compiler:官方 wcc / wcsc 编译器封装\n */\n\nexport { compileWxml } from './wcc';\nexport type { ComponentTags, WxmlCompileOptions } from './wcc';\nexport { compileWxss, parseWcscOutput, unescapeJsString } from './wcsc';\nexport type { WxssCompileOptions, WxssCompileResult } from './wcsc';\nexport { findCompilerBinaries } from './locate';\nexport type { CompilerBinaries } from './locate';\n","/**\n * WXML 编译(wcc)\n *\n * 所有 wxml/wxs 一次性编译成一个 $gwx 函数,模板 import/include 和 wxs 引用由 wcc 自己解析。\n */\n\nimport fs from 'fs';\nimport os from 'os';\nimport path from 'path';\nimport { runCompiler } from './exec';\nimport { findCompilerBinaries } from './locate';\n\nexport interface ComponentTags {\n /** 页面或组件路径,不带扩展名,如 \"pages/index/index\" */\n path: string;\n /** 该 wxml 中属于自定义组件(含抽象节点)的标签名 */\n tags: string[];\n}\n\nexport interface WxmlCompileOptions {\n /** 小程序根目录 */\n cwd: string;\n /** 相对 cwd 的 ./ 开头路径,包含 .wxml 和 .wxs */\n files: string[];\n components: ComponentTags[];\n /**\n * true:逻辑层使用的裁剪版(-xc),只保留组件结构信息;\n * false:渲染层使用的完整版(-cc)\n */\n cut: boolean;\n genfuncName?: string;\n}\n\n// Windows 命令行长度上限约 32K,超出时改用配置文件传参(开发者工具同样如此)\nconst MAX_INLINE_ARGS_LENGTH = 30000;\n\nexport async function compileWxml(options: WxmlCompileOptions): Promise<string> {\n const { wcc } = findCompilerBinaries();\n const split = `>_<${Date.now() % 10000}`;\n\n const config: Array<string | number> = [options.components.length];\n for (const component of options.components) {\n config.push(`./${component.path}.wxml`, component.tags.length, ...component.tags);\n }\n\n const args = ['-d', '--split', split, options.cut ? '-xc' : '-cc', config.join(split)];\n if (options.files.some(file => file.endsWith('.wxs'))) {\n args.unshift('-ds');\n }\n args.push(...options.files, '-gn', options.genfuncName || '$gwx');\n\n if (args.join(' ').length <= MAX_INLINE_ARGS_LENGTH) {\n return runCompiler(wcc, args, options.cwd);\n }\n\n const configFile = path.join(os.tmpdir(), `wxa-runner-wcc-${process.pid}-${Date.now()}.txt`);\n fs.writeFileSync(configFile, args.join('\\n'));\n try {\n return await runCompiler(wcc, ['--config-path', configFile], options.cwd);\n } finally {\n fs.rmSync(configFile, { force: true });\n }\n}\n","import { execFile } from 'child_process';\n\nconst MAX_OUTPUT = 512 * 1024 * 1024;\n\nexport function runCompiler(bin: string, args: string[], cwd: string): Promise<string> {\n return new Promise((resolve, reject) => {\n execFile(bin, args, { cwd, maxBuffer: MAX_OUTPUT, encoding: 'utf8' }, (error, stdout, stderr) => {\n if (error) {\n const detail = (stderr || stdout || error.message).trim();\n reject(new Error(`${bin.split(/[\\\\/]/).pop()} 编译失败:\\n${detail}`));\n return;\n }\n resolve(stdout);\n });\n });\n}\n","/**\n * 定位 wcc / wcsc 可执行文件\n *\n * 使用开发者工具自带的命令行版本(node_modules/wcc-exec),而不是 wcc.node 原生模块:\n * 原生模块在 Node 进程里重复调用会随机触发 std::bad_alloc 崩溃,\n * 子进程方式则天然隔离,单次编译只需几毫秒。\n *\n * 没有开发者工具时(如 Linux、CI),用微信官方 npm 包 miniprogram-compiler 自带的编译器。\n * 它的编译内核较旧(20200413,开发者工具为 20211229):页面的编译结果相同,\n * 只有模板运行时有少量差异,如旧版限制单页最多 16000 个节点。\n */\n\nimport fs from 'fs';\nimport path from 'path';\nimport { findDevtoolsPackageDirs } from '@open-wxa/wxa-runner-extractor';\n\nexport interface CompilerBinaries {\n wcc: string;\n wcsc: string;\n}\n\nlet cached: CompilerBinaries | null = null;\n\nexport function findCompilerBinaries(): CompilerBinaries {\n if (!cached) cached = locateCompilerBinaries(findDevtoolsPackageDirs());\n return cached;\n}\n\n/**\n * 依次查找:环境变量 WXA_WCC + WXA_WCSC、开发者工具、miniprogram-compiler\n *\n * @throws 都找不到时\n */\nexport function locateCompilerBinaries(devtoolsDirs: string[]): CompilerBinaries {\n const ext = process.platform === 'win32' ? '.exe' : '';\n const candidates: CompilerBinaries[] = [];\n\n if (process.env.WXA_WCC && process.env.WXA_WCSC) {\n candidates.push({ wcc: process.env.WXA_WCC, wcsc: process.env.WXA_WCSC });\n }\n for (const dir of devtoolsDirs) {\n const execDir = path.join(dir, 'node_modules', 'wcc-exec');\n candidates.push({ wcc: path.join(execDir, 'wcc' + ext), wcsc: path.join(execDir, 'wcsc' + ext) });\n }\n const packaged = findPackagedCompiler(ext);\n if (packaged) candidates.push(packaged);\n\n const found = candidates.find(c => fs.existsSync(c.wcc) && fs.existsSync(c.wcsc));\n if (!found) {\n throw new Error(\n '没有找到 wcc/wcsc 编译器。请安装微信开发者工具,或重新安装依赖以安装 miniprogram-compiler(Linux 只支持 x86-64),' +\n '或通过 WXA_DEVTOOLS_PATH / WXA_WCC + WXA_WCSC 指定位置。'\n );\n }\n // npm 包里的 Linux 版没有可执行权限\n if (found === packaged) {\n for (const file of [found.wcc, found.wcsc]) {\n try {\n fs.accessSync(file, fs.constants.X_OK);\n } catch {\n fs.chmodSync(file, 0o755);\n }\n }\n }\n return found;\n}\n\n/** miniprogram-compiler 里当前平台的编译器;它是可选依赖,没装上或平台不支持时返回 null */\nfunction findPackagedCompiler(ext: string): CompilerBinaries | null {\n const platformDir =\n process.platform === 'darwin' ? 'mac'\n : process.platform === 'win32' ? 'windows'\n : process.platform === 'linux' && process.arch === 'x64' ? 'linux'\n : null;\n if (!platformDir) return null;\n\n let root: string;\n try {\n root = path.dirname(require.resolve('miniprogram-compiler/package.json'));\n } catch {\n return null;\n }\n const dir = path.join(root, 'bin', platformDir);\n return { wcc: path.join(dir, 'wcc' + ext), wcsc: path.join(dir, 'wcsc' + ext) };\n}\n","/**\n * WXSS 编译(wcsc)\n *\n * 输出是 \"key=value=key=value\" 交替的字符串,value 是转义过的 JS 源码:\n * comm 公共运行时(setCssToHead、rpx 换算)以及非页面样式(app.wxss 等)的立即执行代码\n * ./pages/a.wxss 每个页面/组件一个 setCssToHead(...),返回的函数在页面创建时调用\n */\n\nimport { runCompiler } from './exec';\nimport { findCompilerBinaries } from './locate';\n\nexport interface WxssCompileOptions {\n cwd: string;\n /** 页面和组件的 wxss,./ 开头 */\n pageFiles: string[];\n /** 其余样式(app.wxss),以公共样式形式写入 comm */\n commonFiles: string[];\n}\n\nexport interface WxssCompileResult {\n comm: string;\n /** 键为不带 ./ 的路径,如 \"pages/index/index.wxss\" */\n pages: Record<string, string>;\n}\n\nexport async function compileWxss(options: WxssCompileOptions): Promise<WxssCompileResult> {\n const { wcsc } = findCompilerBinaries();\n const files = [...options.pageFiles, ...options.commonFiles];\n if (files.length === 0) {\n return { comm: '', pages: {} };\n }\n\n const args = ['-db', '-pc', String(options.pageFiles.length), ...files];\n const raw = parseWcscOutput(await runCompiler(wcsc, args, options.cwd));\n\n const pages: Record<string, string> = {};\n for (const file of options.pageFiles) {\n if (raw[file] !== undefined) pages[file.replace(/^\\.\\//, '')] = raw[file];\n }\n return { comm: raw.comm || '', pages };\n}\n\nexport function parseWcscOutput(output: string): Record<string, string> {\n const parts = output.split('=');\n const result: Record<string, string> = {};\n for (let i = 0; i + 1 < parts.length; i += 2) {\n result[parts[i]] = unescapeJsString(parts[i + 1]);\n }\n return result;\n}\n\nconst SIMPLE_ESCAPES: Record<string, string> = {\n n: '\\n', t: '\\t', r: '\\r', b: '\\b', f: '\\f', v: '\\v', '0': '\\0'\n};\n\nexport function unescapeJsString(value: string): string {\n return value.replace(/\\\\(x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|[\\s\\S])/g, (_, seq: string) => {\n if ((seq[0] === 'x' || seq[0] === 'u') && seq.length > 1) {\n return String.fromCharCode(parseInt(seq.slice(1), 16));\n }\n return SIMPLE_ESCAPES[seq] ?? seq;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMA,IAAAA,aAAe;AACf,gBAAe;AACf,IAAAC,eAAiB;;;ACRjB,2BAAyB;AAEzB,IAAM,aAAa,MAAM,OAAO;AAEzB,SAAS,YAAY,KAAa,MAAgB,KAA8B;AACrF,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,uCAAS,KAAK,MAAM,EAAE,KAAK,WAAW,YAAY,UAAU,OAAO,GAAG,CAAC,OAAO,QAAQ,WAAW;AAC/F,UAAI,OAAO;AACT,cAAM,UAAU,UAAU,UAAU,MAAM,SAAS,KAAK;AACxD,eAAO,IAAI,MAAM,GAAG,IAAI,MAAM,OAAO,EAAE,IAAI,CAAC;AAAA,EAAW,MAAM,EAAE,CAAC;AAChE;AAAA,MACF;AACA,cAAQ,MAAM;AAAA,IAChB,CAAC;AAAA,EACH,CAAC;AACH;;;ACHA,gBAAe;AACf,kBAAiB;AACjB,kCAAwC;AAOxC,IAAI,SAAkC;AAE/B,SAAS,uBAAyC;AACvD,MAAI,CAAC,OAAQ,UAAS,2BAAuB,qDAAwB,CAAC;AACtE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AG,EAAE,CAAC;AAAA,IACvD;AACA,WAAO,eAAe,GAAG,KAAK;AAAA,EAChC,CAAC;AACH;","names":["import_fs","import_path","path","fs","path","os","fs"]}
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@open-wxa/wxa-runner-compiler",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "description": "Wrapper around the official WXML/WXSS compilers (wcc/wcsc) shipped with WeChat DevTools",
5
+ "license": "MIT",
6
+ "author": "open-wxa",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/open-wxa/wxa-runner.git",
10
+ "directory": "packages/compiler"
11
+ },
12
+ "homepage": "https://github.com/open-wxa/wxa-runner#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/open-wxa/wxa-runner/issues"
15
+ },
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "dependencies": {
22
+ "@open-wxa/wxa-runner-extractor": "0.2.0"
23
+ },
24
+ "optionalDependencies": {
25
+ "miniprogram-compiler": "0.2.3"
26
+ },
27
+ "devDependencies": {
28
+ "tsup": "^8.0.1",
29
+ "typescript": "^5.3.2"
30
+ },
31
+ "engines": {
32
+ "node": ">=18"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public",
36
+ "registry": "https://registry.npmjs.org/"
37
+ },
38
+ "scripts": {
39
+ "build": "tsup"
40
+ }
6
41
  }