@coze-arch/cli 0.0.10-alpha.11b7ea → 0.0.10-alpha.4d3da6
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/lib/cli.js +487 -505
- package/package.json +1 -1
package/lib/cli.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
var commander = require('commander');
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var fs = require('fs');
|
|
7
|
-
var debug
|
|
7
|
+
var debug = require('debug');
|
|
8
8
|
var node_http = require('node:http');
|
|
9
9
|
var node_https = require('node:https');
|
|
10
10
|
var node_path = require('node:path');
|
|
@@ -15,6 +15,7 @@ var fs$1 = require('fs/promises');
|
|
|
15
15
|
var os = require('os');
|
|
16
16
|
var jsYaml = require('js-yaml');
|
|
17
17
|
var toml = require('@iarna/toml');
|
|
18
|
+
require('crypto');
|
|
18
19
|
var fastGlob = require('fast-glob');
|
|
19
20
|
var child_process = require('child_process');
|
|
20
21
|
var addFormats = require('ajv-formats');
|
|
@@ -1491,7 +1492,7 @@ var browserClient = createBaseClient();
|
|
|
1491
1492
|
|
|
1492
1493
|
|
|
1493
1494
|
|
|
1494
|
-
const log$7 = debug
|
|
1495
|
+
const log$7 = debug('slardar:transport');
|
|
1495
1496
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
1496
1497
|
const noop = () => {};
|
|
1497
1498
|
|
|
@@ -1627,14 +1628,14 @@ function createNodeTransport() {
|
|
|
1627
1628
|
};
|
|
1628
1629
|
}
|
|
1629
1630
|
|
|
1630
|
-
function _nullishCoalesce$
|
|
1631
|
+
function _nullishCoalesce$9(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$m(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
|
|
1631
1632
|
* Slardar CLI Reporter 主类
|
|
1632
1633
|
* 封装 @slardar/base 的初始化和上报逻辑
|
|
1633
1634
|
*/
|
|
1634
1635
|
|
|
1635
1636
|
// 创建 debug 实例
|
|
1636
1637
|
// 使用方式: DEBUG=slardar:* your-cli-command
|
|
1637
|
-
const log$6 = debug
|
|
1638
|
+
const log$6 = debug('slardar:reporter');
|
|
1638
1639
|
|
|
1639
1640
|
/**
|
|
1640
1641
|
* Slardar CLI Reporter
|
|
@@ -1684,7 +1685,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1684
1685
|
release: config.release,
|
|
1685
1686
|
env: config.env,
|
|
1686
1687
|
name: config.name,
|
|
1687
|
-
useLocalConfig: _nullishCoalesce$
|
|
1688
|
+
useLocalConfig: _nullishCoalesce$9(config.useLocalConfig, () => ( false)), // 默认使用服务端配置
|
|
1688
1689
|
domain: config.domain,
|
|
1689
1690
|
// 设置本地采样率为 100%,确保事件不被过滤
|
|
1690
1691
|
sample: {
|
|
@@ -1699,7 +1700,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1699
1700
|
this.client.on('send', (ev) => {
|
|
1700
1701
|
log$6(
|
|
1701
1702
|
'send hook called for event: %s',
|
|
1702
|
-
(_optionalChain$
|
|
1703
|
+
(_optionalChain$m([ev, 'optionalAccess', _ => _.ev_type]) ) || 'unknown',
|
|
1703
1704
|
);
|
|
1704
1705
|
});
|
|
1705
1706
|
|
|
@@ -1757,7 +1758,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1757
1758
|
)
|
|
1758
1759
|
: undefined;
|
|
1759
1760
|
|
|
1760
|
-
_optionalChain$
|
|
1761
|
+
_optionalChain$m([this, 'access', _2 => _2.client, 'access', _3 => _3.sendEvent, 'optionalCall', _4 => _4({
|
|
1761
1762
|
name,
|
|
1762
1763
|
metrics: cleanMetrics ,
|
|
1763
1764
|
categories: cleanCategories ,
|
|
@@ -1828,7 +1829,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1828
1829
|
log$6('Reporting JS error:', {
|
|
1829
1830
|
name: error.name,
|
|
1830
1831
|
message: error.message.slice(0, 100),
|
|
1831
|
-
stack: _optionalChain$
|
|
1832
|
+
stack: _optionalChain$m([error, 'access', _5 => _5.stack, 'optionalAccess', _6 => _6.slice, 'call', _7 => _7(0, 200)]),
|
|
1832
1833
|
extra,
|
|
1833
1834
|
source,
|
|
1834
1835
|
});
|
|
@@ -1848,7 +1849,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1848
1849
|
if (!this.ensureInitialized()) {
|
|
1849
1850
|
return;
|
|
1850
1851
|
}
|
|
1851
|
-
_optionalChain$
|
|
1852
|
+
_optionalChain$m([this, 'access', _8 => _8.client, 'access', _9 => _9.context, 'optionalAccess', _10 => _10.set, 'call', _11 => _11(key, value)]);
|
|
1852
1853
|
}
|
|
1853
1854
|
|
|
1854
1855
|
/**
|
|
@@ -1859,7 +1860,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1859
1860
|
return;
|
|
1860
1861
|
}
|
|
1861
1862
|
log$6('Merging context:', context);
|
|
1862
|
-
_optionalChain$
|
|
1863
|
+
_optionalChain$m([this, 'access', _12 => _12.client, 'access', _13 => _13.context, 'optionalAccess', _14 => _14.merge, 'call', _15 => _15(context)]);
|
|
1863
1864
|
}
|
|
1864
1865
|
|
|
1865
1866
|
/**
|
|
@@ -1869,7 +1870,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1869
1870
|
if (!this.ensureInitialized()) {
|
|
1870
1871
|
return;
|
|
1871
1872
|
}
|
|
1872
|
-
_optionalChain$
|
|
1873
|
+
_optionalChain$m([this, 'access', _16 => _16.client, 'access', _17 => _17.context, 'optionalAccess', _18 => _18.delete, 'call', _19 => _19(key)]);
|
|
1873
1874
|
}
|
|
1874
1875
|
|
|
1875
1876
|
/**
|
|
@@ -1879,7 +1880,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1879
1880
|
if (!this.ensureInitialized()) {
|
|
1880
1881
|
return;
|
|
1881
1882
|
}
|
|
1882
|
-
_optionalChain$
|
|
1883
|
+
_optionalChain$m([this, 'access', _20 => _20.client, 'access', _21 => _21.context, 'optionalAccess', _22 => _22.clear, 'call', _23 => _23()]);
|
|
1883
1884
|
}
|
|
1884
1885
|
|
|
1885
1886
|
/**
|
|
@@ -1916,7 +1917,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1916
1917
|
return;
|
|
1917
1918
|
}
|
|
1918
1919
|
log$6('Flushing Slardar data...');
|
|
1919
|
-
_optionalChain$
|
|
1920
|
+
_optionalChain$m([this, 'access', _24 => _24.client, 'access', _25 => _25.getSender, 'optionalCall', _26 => _26(), 'optionalAccess', _27 => _27.flush, 'call', _28 => _28()]);
|
|
1920
1921
|
log$6('Waiting %dms for events to be sent...', waitMs);
|
|
1921
1922
|
await new Promise(resolve => setTimeout(resolve, waitMs));
|
|
1922
1923
|
log$6('Slardar data flushed');
|
|
@@ -1935,7 +1936,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
|
|
|
1935
1936
|
*/
|
|
1936
1937
|
const reporter = new SlardarCLIReporter();
|
|
1937
1938
|
|
|
1938
|
-
function _optionalChain$
|
|
1939
|
+
function _optionalChain$l(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1939
1940
|
|
|
1940
1941
|
|
|
1941
1942
|
|
|
@@ -1995,11 +1996,11 @@ const EventBuilder = {
|
|
|
1995
1996
|
name: CLI_EVENTS.CLI_COMMAND,
|
|
1996
1997
|
categories: {
|
|
1997
1998
|
command,
|
|
1998
|
-
args: _optionalChain$
|
|
1999
|
+
args: _optionalChain$l([options, 'optionalAccess', _ => _.args]),
|
|
1999
2000
|
status: 'running' ,
|
|
2000
|
-
..._optionalChain$
|
|
2001
|
+
..._optionalChain$l([options, 'optionalAccess', _2 => _2.categories]),
|
|
2001
2002
|
},
|
|
2002
|
-
metrics: _optionalChain$
|
|
2003
|
+
metrics: _optionalChain$l([options, 'optionalAccess', _3 => _3.metrics]),
|
|
2003
2004
|
};
|
|
2004
2005
|
},
|
|
2005
2006
|
|
|
@@ -2020,13 +2021,13 @@ const EventBuilder = {
|
|
|
2020
2021
|
name: CLI_EVENTS.CLI_COMMAND_COMPLETE,
|
|
2021
2022
|
categories: {
|
|
2022
2023
|
command,
|
|
2023
|
-
args: _optionalChain$
|
|
2024
|
+
args: _optionalChain$l([options, 'optionalAccess', _4 => _4.args]),
|
|
2024
2025
|
status: success ? ('success' ) : ('fail' ),
|
|
2025
|
-
..._optionalChain$
|
|
2026
|
+
..._optionalChain$l([options, 'optionalAccess', _5 => _5.categories]),
|
|
2026
2027
|
},
|
|
2027
2028
|
metrics: {
|
|
2028
2029
|
duration,
|
|
2029
|
-
...(_optionalChain$
|
|
2030
|
+
...(_optionalChain$l([options, 'optionalAccess', _6 => _6.errorCode]) && { errorCode: options.errorCode }),
|
|
2030
2031
|
},
|
|
2031
2032
|
};
|
|
2032
2033
|
},
|
|
@@ -2047,12 +2048,12 @@ const EventBuilder = {
|
|
|
2047
2048
|
name: CLI_EVENTS.NETWORK_REQUEST,
|
|
2048
2049
|
categories: {
|
|
2049
2050
|
url,
|
|
2050
|
-
method: _optionalChain$
|
|
2051
|
-
statusCode: _optionalChain$
|
|
2052
|
-
status: _optionalChain$
|
|
2051
|
+
method: _optionalChain$l([options, 'optionalAccess', _7 => _7.method]) || 'GET',
|
|
2052
|
+
statusCode: _optionalChain$l([options, 'optionalAccess', _8 => _8.statusCode, 'optionalAccess', _9 => _9.toString, 'call', _10 => _10()]),
|
|
2053
|
+
status: _optionalChain$l([options, 'optionalAccess', _11 => _11.success]) ? ('success' ) : ('fail' ),
|
|
2053
2054
|
},
|
|
2054
2055
|
metrics: {
|
|
2055
|
-
duration: _optionalChain$
|
|
2056
|
+
duration: _optionalChain$l([options, 'optionalAccess', _12 => _12.duration]),
|
|
2056
2057
|
},
|
|
2057
2058
|
};
|
|
2058
2059
|
},
|
|
@@ -2074,11 +2075,11 @@ const EventBuilder = {
|
|
|
2074
2075
|
categories: {
|
|
2075
2076
|
operation,
|
|
2076
2077
|
filePath,
|
|
2077
|
-
status: _optionalChain$
|
|
2078
|
+
status: _optionalChain$l([options, 'optionalAccess', _13 => _13.success]) ? ('success' ) : ('fail' ),
|
|
2078
2079
|
},
|
|
2079
2080
|
metrics: {
|
|
2080
|
-
duration: _optionalChain$
|
|
2081
|
-
fileSize: _optionalChain$
|
|
2081
|
+
duration: _optionalChain$l([options, 'optionalAccess', _14 => _14.duration]),
|
|
2082
|
+
fileSize: _optionalChain$l([options, 'optionalAccess', _15 => _15.fileSize]),
|
|
2082
2083
|
},
|
|
2083
2084
|
};
|
|
2084
2085
|
},
|
|
@@ -2106,7 +2107,7 @@ const EventBuilder = {
|
|
|
2106
2107
|
};
|
|
2107
2108
|
|
|
2108
2109
|
var name = "@coze-arch/cli";
|
|
2109
|
-
var version = "0.0.10-alpha.
|
|
2110
|
+
var version = "0.0.10-alpha.4d3da6";
|
|
2110
2111
|
var description = "coze coding devtools cli";
|
|
2111
2112
|
var license = "MIT";
|
|
2112
2113
|
var author = "fanwenjie.fe@bytedance.com";
|
|
@@ -2212,11 +2213,11 @@ var packageJson = {
|
|
|
2212
2213
|
cozePublishConfig: cozePublishConfig
|
|
2213
2214
|
};
|
|
2214
2215
|
|
|
2215
|
-
function _optionalChain$
|
|
2216
|
+
function _optionalChain$k(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/**
|
|
2216
2217
|
* Slardar 监控初始化和上报
|
|
2217
2218
|
*/
|
|
2218
2219
|
|
|
2219
|
-
const log$5 = debug
|
|
2220
|
+
const log$5 = debug('slardar:cli');
|
|
2220
2221
|
|
|
2221
2222
|
/**
|
|
2222
2223
|
* 安全执行函数包装器
|
|
@@ -2315,11 +2316,11 @@ const reportCommandComplete = safeRun(
|
|
|
2315
2316
|
,
|
|
2316
2317
|
) => {
|
|
2317
2318
|
const event = EventBuilder.cliCommandComplete(command, success, duration, {
|
|
2318
|
-
args: _optionalChain$
|
|
2319
|
-
errorCode: _optionalChain$
|
|
2319
|
+
args: _optionalChain$k([options, 'optionalAccess', _ => _.args]),
|
|
2320
|
+
errorCode: _optionalChain$k([options, 'optionalAccess', _2 => _2.errorCode]),
|
|
2320
2321
|
categories: {
|
|
2321
|
-
...(_optionalChain$
|
|
2322
|
-
..._optionalChain$
|
|
2322
|
+
...(_optionalChain$k([options, 'optionalAccess', _3 => _3.errorMessage]) && { errorMessage: options.errorMessage }),
|
|
2323
|
+
..._optionalChain$k([options, 'optionalAccess', _4 => _4.categories]),
|
|
2323
2324
|
},
|
|
2324
2325
|
});
|
|
2325
2326
|
reporter.sendEvent(event.name, event.metrics, event.categories);
|
|
@@ -2378,7 +2379,7 @@ const flushSlardar = safeRun('flushSlardar', async () => {
|
|
|
2378
2379
|
await reporter.flush();
|
|
2379
2380
|
});
|
|
2380
2381
|
|
|
2381
|
-
function _nullishCoalesce$
|
|
2382
|
+
function _nullishCoalesce$8(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$j(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var LogLevel; (function (LogLevel) {
|
|
2382
2383
|
const ERROR = 0; LogLevel[LogLevel["ERROR"] = ERROR] = "ERROR";
|
|
2383
2384
|
const WARN = 1; LogLevel[LogLevel["WARN"] = WARN] = "WARN";
|
|
2384
2385
|
const SUCCESS = 2; LogLevel[LogLevel["SUCCESS"] = SUCCESS] = "SUCCESS";
|
|
@@ -2416,7 +2417,7 @@ class Logger {
|
|
|
2416
2417
|
|
|
2417
2418
|
constructor(options = {}) {
|
|
2418
2419
|
this.level = this.parseLogLevel(options.level);
|
|
2419
|
-
this.useColor = _nullishCoalesce$
|
|
2420
|
+
this.useColor = _nullishCoalesce$8(options.useColor, () => ( this.isColorSupported()));
|
|
2420
2421
|
this.prefix = options.prefix;
|
|
2421
2422
|
}
|
|
2422
2423
|
|
|
@@ -2425,7 +2426,7 @@ class Logger {
|
|
|
2425
2426
|
return level;
|
|
2426
2427
|
}
|
|
2427
2428
|
|
|
2428
|
-
const envLevel = _optionalChain$
|
|
2429
|
+
const envLevel = _optionalChain$j([process, 'access', _ => _.env, 'access', _2 => _2.LOG_LEVEL, 'optionalAccess', _3 => _3.toLowerCase, 'call', _4 => _4()]);
|
|
2429
2430
|
if (envLevel && envLevel in LOG_LEVEL_MAP) {
|
|
2430
2431
|
return LOG_LEVEL_MAP[envLevel];
|
|
2431
2432
|
}
|
|
@@ -2437,7 +2438,7 @@ class Logger {
|
|
|
2437
2438
|
// 简单检测:Node.js 环境且支持 TTY
|
|
2438
2439
|
return (
|
|
2439
2440
|
typeof process !== 'undefined' &&
|
|
2440
|
-
_optionalChain$
|
|
2441
|
+
_optionalChain$j([process, 'access', _5 => _5.stdout, 'optionalAccess', _6 => _6.isTTY]) === true &&
|
|
2441
2442
|
process.env.NO_COLOR === undefined
|
|
2442
2443
|
);
|
|
2443
2444
|
}
|
|
@@ -2462,7 +2463,7 @@ class Logger {
|
|
|
2462
2463
|
|
|
2463
2464
|
const icon = this.colorize(options.icon, options.color);
|
|
2464
2465
|
const prefix = this.prefix ? `${icon} ${this.prefix}` : icon;
|
|
2465
|
-
console.log(prefix, options.message, ...(_nullishCoalesce$
|
|
2466
|
+
console.log(prefix, options.message, ...(_nullishCoalesce$8(options.args, () => ( []))));
|
|
2466
2467
|
}
|
|
2467
2468
|
|
|
2468
2469
|
error(message, ...args) {
|
|
@@ -3276,7 +3277,7 @@ const registerCommand$4 = program => {
|
|
|
3276
3277
|
});
|
|
3277
3278
|
};
|
|
3278
3279
|
|
|
3279
|
-
function _optionalChain$
|
|
3280
|
+
function _optionalChain$i(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3280
3281
|
// Safe JSON parsing utilities with type safety and error handling
|
|
3281
3282
|
// Provides fallback values, validation, and error monitoring capabilities
|
|
3282
3283
|
|
|
@@ -3376,12 +3377,12 @@ function safeJsonParse(
|
|
|
3376
3377
|
const parsed = JSON.parse(String(input));
|
|
3377
3378
|
|
|
3378
3379
|
// Optional validation
|
|
3379
|
-
if (_optionalChain$
|
|
3380
|
+
if (_optionalChain$i([options, 'optionalAccess', _ => _.validate])) {
|
|
3380
3381
|
if (options.validate(parsed)) {
|
|
3381
3382
|
return parsed;
|
|
3382
3383
|
} else {
|
|
3383
3384
|
const validationError = new Error('JSON validation failed');
|
|
3384
|
-
_optionalChain$
|
|
3385
|
+
_optionalChain$i([options, 'access', _2 => _2.onError, 'optionalCall', _3 => _3(validationError, input)]);
|
|
3385
3386
|
|
|
3386
3387
|
if (options.throwOnValidationError) {
|
|
3387
3388
|
throw validationError;
|
|
@@ -3393,15 +3394,15 @@ function safeJsonParse(
|
|
|
3393
3394
|
return parsed;
|
|
3394
3395
|
} catch (error) {
|
|
3395
3396
|
// Re-throw validation errors when throwOnValidationError is true
|
|
3396
|
-
if (error instanceof Error && error.message === 'JSON validation failed' && _optionalChain$
|
|
3397
|
+
if (error instanceof Error && error.message === 'JSON validation failed' && _optionalChain$i([options, 'optionalAccess', _4 => _4.throwOnValidationError])) {
|
|
3397
3398
|
throw error;
|
|
3398
3399
|
}
|
|
3399
|
-
_optionalChain$
|
|
3400
|
+
_optionalChain$i([options, 'optionalAccess', _5 => _5.onError, 'optionalCall', _6 => _6(error , input)]);
|
|
3400
3401
|
return defaultValue;
|
|
3401
3402
|
}
|
|
3402
3403
|
}
|
|
3403
3404
|
|
|
3404
|
-
function _optionalChain$
|
|
3405
|
+
function _optionalChain$h(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
3405
3406
|
|
|
3406
3407
|
|
|
3407
3408
|
/**
|
|
@@ -3442,6 +3443,17 @@ const parseConfigContent = (content) => {
|
|
|
3442
3443
|
return null;
|
|
3443
3444
|
};
|
|
3444
3445
|
|
|
3446
|
+
/**
|
|
3447
|
+
* 仅按 TOML 解析 .coze
|
|
3448
|
+
*/
|
|
3449
|
+
const parseTomlConfigContent = (content) => {
|
|
3450
|
+
try {
|
|
3451
|
+
return toml.parse(content) ;
|
|
3452
|
+
} catch (e) {
|
|
3453
|
+
return null;
|
|
3454
|
+
}
|
|
3455
|
+
};
|
|
3456
|
+
|
|
3445
3457
|
/**
|
|
3446
3458
|
* 加载 .coze 配置文件
|
|
3447
3459
|
*
|
|
@@ -3475,6 +3487,72 @@ const loadCozeConfig = async (
|
|
|
3475
3487
|
return config;
|
|
3476
3488
|
};
|
|
3477
3489
|
|
|
3490
|
+
/**
|
|
3491
|
+
* 读取 TOML 格式的 .coze 配置
|
|
3492
|
+
*/
|
|
3493
|
+
const loadTomlCozeConfig = async (
|
|
3494
|
+
projectPath = process.cwd(),
|
|
3495
|
+
) => {
|
|
3496
|
+
const cozeConfigPath = path.join(projectPath, '.coze');
|
|
3497
|
+
|
|
3498
|
+
let content;
|
|
3499
|
+
try {
|
|
3500
|
+
content = await fs$1.readFile(cozeConfigPath, 'utf-8');
|
|
3501
|
+
} catch (error) {
|
|
3502
|
+
throw new Error(
|
|
3503
|
+
`.coze config file not found in ${projectPath}\n` +
|
|
3504
|
+
'Please ensure you are in a project directory initialized with coze-coding.\n' +
|
|
3505
|
+
`Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
3506
|
+
);
|
|
3507
|
+
}
|
|
3508
|
+
|
|
3509
|
+
const config = parseTomlConfigContent(content);
|
|
3510
|
+
if (!config) {
|
|
3511
|
+
throw new Error(
|
|
3512
|
+
'Failed to parse .coze config file as TOML.\n' +
|
|
3513
|
+
'Please ensure the file is valid TOML format.',
|
|
3514
|
+
);
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
return config;
|
|
3518
|
+
};
|
|
3519
|
+
|
|
3520
|
+
/**
|
|
3521
|
+
* 将 .coze 配置写回 TOML 文件
|
|
3522
|
+
*/
|
|
3523
|
+
const saveTomlCozeConfig = async (
|
|
3524
|
+
config,
|
|
3525
|
+
projectPath = process.cwd(),
|
|
3526
|
+
) => {
|
|
3527
|
+
const cozeConfigPath = path.join(projectPath, '.coze');
|
|
3528
|
+
await fs$1.writeFile(
|
|
3529
|
+
cozeConfigPath,
|
|
3530
|
+
toml.stringify(config ),
|
|
3531
|
+
'utf-8',
|
|
3532
|
+
);
|
|
3533
|
+
};
|
|
3534
|
+
|
|
3535
|
+
/**
|
|
3536
|
+
* 更新项目 patch 元数据并写回 .coze
|
|
3537
|
+
*/
|
|
3538
|
+
const saveProjectPatchState = async (
|
|
3539
|
+
projectPath,
|
|
3540
|
+
state
|
|
3541
|
+
|
|
3542
|
+
|
|
3543
|
+
|
|
3544
|
+
,
|
|
3545
|
+
) => {
|
|
3546
|
+
const config = await loadTomlCozeConfig(projectPath);
|
|
3547
|
+
config.project = {
|
|
3548
|
+
...(config.project || {}),
|
|
3549
|
+
template: state.template,
|
|
3550
|
+
version: state.version,
|
|
3551
|
+
appliedPatches: state.appliedPatches,
|
|
3552
|
+
};
|
|
3553
|
+
await saveTomlCozeConfig(config, projectPath);
|
|
3554
|
+
};
|
|
3555
|
+
|
|
3478
3556
|
/**
|
|
3479
3557
|
* 获取指定命令的配置
|
|
3480
3558
|
*
|
|
@@ -3491,13 +3569,13 @@ const getCommandConfig = (
|
|
|
3491
3569
|
// 根据命令名称映射到配置路径
|
|
3492
3570
|
switch (commandName) {
|
|
3493
3571
|
case 'dev':
|
|
3494
|
-
commandConfig = _optionalChain$
|
|
3572
|
+
commandConfig = _optionalChain$h([config, 'access', _ => _.dev, 'optionalAccess', _2 => _2.run]);
|
|
3495
3573
|
break;
|
|
3496
3574
|
case 'build':
|
|
3497
|
-
commandConfig = _optionalChain$
|
|
3575
|
+
commandConfig = _optionalChain$h([config, 'access', _3 => _3.deploy, 'optionalAccess', _4 => _4.build]);
|
|
3498
3576
|
break;
|
|
3499
3577
|
case 'start':
|
|
3500
|
-
commandConfig = _optionalChain$
|
|
3578
|
+
commandConfig = _optionalChain$h([config, 'access', _5 => _5.deploy, 'optionalAccess', _6 => _6.run]);
|
|
3501
3579
|
break;
|
|
3502
3580
|
default:
|
|
3503
3581
|
throw new Error(`Unknown command: ${commandName}`);
|
|
@@ -3548,7 +3626,7 @@ function isNode(node) {
|
|
|
3548
3626
|
}
|
|
3549
3627
|
const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
|
|
3550
3628
|
|
|
3551
|
-
function _optionalChain$
|
|
3629
|
+
function _optionalChain$g(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
3552
3630
|
const BREAK = Symbol('break visit');
|
|
3553
3631
|
const SKIP = Symbol('skip children');
|
|
3554
3632
|
const REMOVE = Symbol('remove node');
|
|
@@ -3661,15 +3739,15 @@ function callVisitor(key, node, visitor, path) {
|
|
|
3661
3739
|
if (typeof visitor === 'function')
|
|
3662
3740
|
return visitor(key, node, path);
|
|
3663
3741
|
if (isMap(node))
|
|
3664
|
-
return _optionalChain$
|
|
3742
|
+
return _optionalChain$g([visitor, 'access', _ => _.Map, 'optionalCall', _2 => _2(key, node, path)]);
|
|
3665
3743
|
if (isSeq(node))
|
|
3666
|
-
return _optionalChain$
|
|
3744
|
+
return _optionalChain$g([visitor, 'access', _3 => _3.Seq, 'optionalCall', _4 => _4(key, node, path)]);
|
|
3667
3745
|
if (isPair(node))
|
|
3668
|
-
return _optionalChain$
|
|
3746
|
+
return _optionalChain$g([visitor, 'access', _5 => _5.Pair, 'optionalCall', _6 => _6(key, node, path)]);
|
|
3669
3747
|
if (isScalar(node))
|
|
3670
|
-
return _optionalChain$
|
|
3748
|
+
return _optionalChain$g([visitor, 'access', _7 => _7.Scalar, 'optionalCall', _8 => _8(key, node, path)]);
|
|
3671
3749
|
if (isAlias(node))
|
|
3672
|
-
return _optionalChain$
|
|
3750
|
+
return _optionalChain$g([visitor, 'access', _9 => _9.Alias, 'optionalCall', _10 => _10(key, node, path)]);
|
|
3673
3751
|
return undefined;
|
|
3674
3752
|
}
|
|
3675
3753
|
function replaceNode(key, path, node) {
|
|
@@ -3760,7 +3838,7 @@ function applyReviver(reviver, obj, key, val) {
|
|
|
3760
3838
|
return reviver.call(obj, key, val);
|
|
3761
3839
|
}
|
|
3762
3840
|
|
|
3763
|
-
function _optionalChain$
|
|
3841
|
+
function _optionalChain$f(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
3764
3842
|
/**
|
|
3765
3843
|
* Recursively convert any node or its contents to native JavaScript
|
|
3766
3844
|
*
|
|
@@ -3790,7 +3868,7 @@ function toJS(value, arg, ctx) {
|
|
|
3790
3868
|
ctx.onCreate(res);
|
|
3791
3869
|
return res;
|
|
3792
3870
|
}
|
|
3793
|
-
if (typeof value === 'bigint' && !_optionalChain$
|
|
3871
|
+
if (typeof value === 'bigint' && !_optionalChain$f([ctx, 'optionalAccess', _ => _.keep]))
|
|
3794
3872
|
return Number(value);
|
|
3795
3873
|
return value;
|
|
3796
3874
|
}
|
|
@@ -3828,7 +3906,7 @@ class NodeBase {
|
|
|
3828
3906
|
}
|
|
3829
3907
|
}
|
|
3830
3908
|
|
|
3831
|
-
function _optionalChain$
|
|
3909
|
+
function _optionalChain$e(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
3832
3910
|
class Alias extends NodeBase {
|
|
3833
3911
|
constructor(source) {
|
|
3834
3912
|
super(ALIAS);
|
|
@@ -3845,7 +3923,7 @@ class Alias extends NodeBase {
|
|
|
3845
3923
|
*/
|
|
3846
3924
|
resolve(doc, ctx) {
|
|
3847
3925
|
let nodes;
|
|
3848
|
-
if (_optionalChain$
|
|
3926
|
+
if (_optionalChain$e([ctx, 'optionalAccess', _ => _.aliasResolveCache])) {
|
|
3849
3927
|
nodes = ctx.aliasResolveCache;
|
|
3850
3928
|
}
|
|
3851
3929
|
else {
|
|
@@ -3884,7 +3962,7 @@ class Alias extends NodeBase {
|
|
|
3884
3962
|
data = anchors.get(source);
|
|
3885
3963
|
}
|
|
3886
3964
|
/* istanbul ignore if */
|
|
3887
|
-
if (_optionalChain$
|
|
3965
|
+
if (_optionalChain$e([data, 'optionalAccess', _2 => _2.res]) === undefined) {
|
|
3888
3966
|
const msg = 'This should not happen: Alias anchor was not resolved?';
|
|
3889
3967
|
throw new ReferenceError(msg);
|
|
3890
3968
|
}
|
|
@@ -3936,7 +4014,7 @@ function getAliasCount(doc, node, anchors) {
|
|
|
3936
4014
|
return 1;
|
|
3937
4015
|
}
|
|
3938
4016
|
|
|
3939
|
-
function _optionalChain$
|
|
4017
|
+
function _optionalChain$d(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
3940
4018
|
const isScalarValue = (value) => !value || (typeof value !== 'function' && typeof value !== 'object');
|
|
3941
4019
|
class Scalar extends NodeBase {
|
|
3942
4020
|
constructor(value) {
|
|
@@ -3944,7 +4022,7 @@ class Scalar extends NodeBase {
|
|
|
3944
4022
|
this.value = value;
|
|
3945
4023
|
}
|
|
3946
4024
|
toJSON(arg, ctx) {
|
|
3947
|
-
return _optionalChain$
|
|
4025
|
+
return _optionalChain$d([ctx, 'optionalAccess', _ => _.keep]) ? this.value : toJS(this.value, arg, ctx);
|
|
3948
4026
|
}
|
|
3949
4027
|
toString() {
|
|
3950
4028
|
return String(this.value);
|
|
@@ -3956,17 +4034,17 @@ Scalar.PLAIN = 'PLAIN';
|
|
|
3956
4034
|
Scalar.QUOTE_DOUBLE = 'QUOTE_DOUBLE';
|
|
3957
4035
|
Scalar.QUOTE_SINGLE = 'QUOTE_SINGLE';
|
|
3958
4036
|
|
|
3959
|
-
function _nullishCoalesce$
|
|
4037
|
+
function _nullishCoalesce$7(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$c(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
3960
4038
|
const defaultTagPrefix = 'tag:yaml.org,2002:';
|
|
3961
4039
|
function findTagObject(value, tagName, tags) {
|
|
3962
4040
|
if (tagName) {
|
|
3963
4041
|
const match = tags.filter(t => t.tag === tagName);
|
|
3964
|
-
const tagObj = _nullishCoalesce$
|
|
4042
|
+
const tagObj = _nullishCoalesce$7(match.find(t => !t.format), () => ( match[0]));
|
|
3965
4043
|
if (!tagObj)
|
|
3966
4044
|
throw new Error(`Tag ${tagName} not found`);
|
|
3967
4045
|
return tagObj;
|
|
3968
4046
|
}
|
|
3969
|
-
return tags.find(t => _optionalChain$
|
|
4047
|
+
return tags.find(t => _optionalChain$c([t, 'access', _ => _.identify, 'optionalCall', _2 => _2(value)]) && !t.format);
|
|
3970
4048
|
}
|
|
3971
4049
|
function createNode(value, tagName, ctx) {
|
|
3972
4050
|
if (isDocument(value))
|
|
@@ -3974,7 +4052,7 @@ function createNode(value, tagName, ctx) {
|
|
|
3974
4052
|
if (isNode(value))
|
|
3975
4053
|
return value;
|
|
3976
4054
|
if (isPair(value)) {
|
|
3977
|
-
const map = _optionalChain$
|
|
4055
|
+
const map = _optionalChain$c([ctx, 'access', _3 => _3.schema, 'access', _4 => _4[MAP], 'access', _5 => _5.createNode, 'optionalCall', _6 => _6(ctx.schema, null, ctx)]);
|
|
3978
4056
|
map.items.push(value);
|
|
3979
4057
|
return map;
|
|
3980
4058
|
}
|
|
@@ -3993,7 +4071,7 @@ function createNode(value, tagName, ctx) {
|
|
|
3993
4071
|
if (aliasDuplicateObjects && value && typeof value === 'object') {
|
|
3994
4072
|
ref = sourceObjects.get(value);
|
|
3995
4073
|
if (ref) {
|
|
3996
|
-
_nullishCoalesce$
|
|
4074
|
+
_nullishCoalesce$7(ref.anchor, () => ( (ref.anchor = onAnchor(value))));
|
|
3997
4075
|
return new Alias(ref.anchor);
|
|
3998
4076
|
}
|
|
3999
4077
|
else {
|
|
@@ -4001,7 +4079,7 @@ function createNode(value, tagName, ctx) {
|
|
|
4001
4079
|
sourceObjects.set(value, ref);
|
|
4002
4080
|
}
|
|
4003
4081
|
}
|
|
4004
|
-
if (_optionalChain$
|
|
4082
|
+
if (_optionalChain$c([tagName, 'optionalAccess', _7 => _7.startsWith, 'call', _8 => _8('!!')]))
|
|
4005
4083
|
tagName = defaultTagPrefix + tagName.slice(2);
|
|
4006
4084
|
let tagObj = findTagObject(value, tagName, schema.tags);
|
|
4007
4085
|
if (!tagObj) {
|
|
@@ -4026,9 +4104,9 @@ function createNode(value, tagName, ctx) {
|
|
|
4026
4104
|
onTagObj(tagObj);
|
|
4027
4105
|
delete ctx.onTagObj;
|
|
4028
4106
|
}
|
|
4029
|
-
const node = _optionalChain$
|
|
4107
|
+
const node = _optionalChain$c([tagObj, 'optionalAccess', _9 => _9.createNode])
|
|
4030
4108
|
? tagObj.createNode(ctx.schema, value, ctx)
|
|
4031
|
-
: typeof _optionalChain$
|
|
4109
|
+
: typeof _optionalChain$c([tagObj, 'optionalAccess', _10 => _10.nodeClass, 'optionalAccess', _11 => _11.from]) === 'function'
|
|
4032
4110
|
? tagObj.nodeClass.from(ctx.schema, value, ctx)
|
|
4033
4111
|
: new Scalar(value);
|
|
4034
4112
|
if (tagName)
|
|
@@ -4346,7 +4424,7 @@ function consumeMoreIndentedLines(text, i, indent) {
|
|
|
4346
4424
|
return end;
|
|
4347
4425
|
}
|
|
4348
4426
|
|
|
4349
|
-
function _optionalChain$
|
|
4427
|
+
function _optionalChain$b(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
4350
4428
|
const getFoldOptions = (ctx, isBlock) => ({
|
|
4351
4429
|
indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
|
|
4352
4430
|
lineWidth: ctx.options.lineWidth,
|
|
@@ -4631,9 +4709,9 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
4631
4709
|
// booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
|
|
4632
4710
|
// and others in v1.1.
|
|
4633
4711
|
if (actualString) {
|
|
4634
|
-
const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && _optionalChain$
|
|
4712
|
+
const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && _optionalChain$b([tag, 'access', _ => _.test, 'optionalAccess', _2 => _2.test, 'call', _3 => _3(str)]);
|
|
4635
4713
|
const { compat, tags } = ctx.doc.schema;
|
|
4636
|
-
if (tags.some(test) || _optionalChain$
|
|
4714
|
+
if (tags.some(test) || _optionalChain$b([compat, 'optionalAccess', _4 => _4.some, 'call', _5 => _5(test)]))
|
|
4637
4715
|
return quotedString(value, ctx);
|
|
4638
4716
|
}
|
|
4639
4717
|
return implicitKey
|
|
@@ -4679,7 +4757,7 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
|
|
|
4679
4757
|
return res;
|
|
4680
4758
|
}
|
|
4681
4759
|
|
|
4682
|
-
function _nullishCoalesce$
|
|
4760
|
+
function _nullishCoalesce$6(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$a(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
4683
4761
|
function createStringifyContext(doc, options) {
|
|
4684
4762
|
const opt = Object.assign({
|
|
4685
4763
|
blockQuote: true,
|
|
@@ -4726,27 +4804,27 @@ function getTagObject(tags, item) {
|
|
|
4726
4804
|
if (item.tag) {
|
|
4727
4805
|
const match = tags.filter(t => t.tag === item.tag);
|
|
4728
4806
|
if (match.length > 0)
|
|
4729
|
-
return _nullishCoalesce$
|
|
4807
|
+
return _nullishCoalesce$6(match.find(t => t.format === item.format), () => ( match[0]));
|
|
4730
4808
|
}
|
|
4731
4809
|
let tagObj = undefined;
|
|
4732
4810
|
let obj;
|
|
4733
4811
|
if (isScalar(item)) {
|
|
4734
4812
|
obj = item.value;
|
|
4735
|
-
let match = tags.filter(t => _optionalChain$
|
|
4813
|
+
let match = tags.filter(t => _optionalChain$a([t, 'access', _ => _.identify, 'optionalCall', _2 => _2(obj)]));
|
|
4736
4814
|
if (match.length > 1) {
|
|
4737
4815
|
const testMatch = match.filter(t => t.test);
|
|
4738
4816
|
if (testMatch.length > 0)
|
|
4739
4817
|
match = testMatch;
|
|
4740
4818
|
}
|
|
4741
4819
|
tagObj =
|
|
4742
|
-
_nullishCoalesce$
|
|
4820
|
+
_nullishCoalesce$6(match.find(t => t.format === item.format), () => ( match.find(t => !t.format)));
|
|
4743
4821
|
}
|
|
4744
4822
|
else {
|
|
4745
4823
|
obj = item;
|
|
4746
4824
|
tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
|
|
4747
4825
|
}
|
|
4748
4826
|
if (!tagObj) {
|
|
4749
|
-
const name = _nullishCoalesce$
|
|
4827
|
+
const name = _nullishCoalesce$6(_optionalChain$a([obj, 'optionalAccess', _3 => _3.constructor, 'optionalAccess', _4 => _4.name]), () => ( (obj === null ? 'null' : typeof obj)));
|
|
4750
4828
|
throw new Error(`Tag not resolved for ${name} value`);
|
|
4751
4829
|
}
|
|
4752
4830
|
return tagObj;
|
|
@@ -4761,7 +4839,7 @@ function stringifyProps(node, tagObj, { anchors, doc }) {
|
|
|
4761
4839
|
anchors.add(anchor);
|
|
4762
4840
|
props.push(`&${anchor}`);
|
|
4763
4841
|
}
|
|
4764
|
-
const tag = _nullishCoalesce$
|
|
4842
|
+
const tag = _nullishCoalesce$6(node.tag, () => ( (tagObj.default ? null : tagObj.tag)));
|
|
4765
4843
|
if (tag)
|
|
4766
4844
|
props.push(doc.directives.tagString(tag));
|
|
4767
4845
|
return props.join(' ');
|
|
@@ -4772,7 +4850,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
4772
4850
|
if (isAlias(item)) {
|
|
4773
4851
|
if (ctx.doc.directives)
|
|
4774
4852
|
return item.toString(ctx);
|
|
4775
|
-
if (_optionalChain$
|
|
4853
|
+
if (_optionalChain$a([ctx, 'access', _5 => _5.resolvedAliases, 'optionalAccess', _6 => _6.has, 'call', _7 => _7(item)])) {
|
|
4776
4854
|
throw new TypeError(`Cannot stringify circular structure without alias nodes`);
|
|
4777
4855
|
}
|
|
4778
4856
|
else {
|
|
@@ -4787,10 +4865,10 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
4787
4865
|
const node = isNode(item)
|
|
4788
4866
|
? item
|
|
4789
4867
|
: ctx.doc.createNode(item, { onTagObj: o => (tagObj = o) });
|
|
4790
|
-
_nullishCoalesce$
|
|
4868
|
+
_nullishCoalesce$6(tagObj, () => ( (tagObj = getTagObject(ctx.doc.schema.tags, node))));
|
|
4791
4869
|
const props = stringifyProps(node, tagObj, ctx);
|
|
4792
4870
|
if (props.length > 0)
|
|
4793
|
-
ctx.indentAtStart = (_nullishCoalesce$
|
|
4871
|
+
ctx.indentAtStart = (_nullishCoalesce$6(ctx.indentAtStart, () => ( 0))) + props.length + 1;
|
|
4794
4872
|
const str = typeof tagObj.stringify === 'function'
|
|
4795
4873
|
? tagObj.stringify(node, ctx, onComment, onChompKeep)
|
|
4796
4874
|
: isScalar(node)
|
|
@@ -4803,7 +4881,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
|
|
|
4803
4881
|
: `${props}\n${ctx.indent}${str}`;
|
|
4804
4882
|
}
|
|
4805
4883
|
|
|
4806
|
-
function _nullishCoalesce$
|
|
4884
|
+
function _nullishCoalesce$5(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
4807
4885
|
function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
|
|
4808
4886
|
const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;
|
|
4809
4887
|
let keyComment = (isNode(key) && key.comment) || null;
|
|
@@ -4913,7 +4991,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
|
|
|
4913
4991
|
const vs0 = valueStr[0];
|
|
4914
4992
|
const nl0 = valueStr.indexOf('\n');
|
|
4915
4993
|
const hasNewline = nl0 !== -1;
|
|
4916
|
-
const flow = _nullishCoalesce$
|
|
4994
|
+
const flow = _nullishCoalesce$5(_nullishCoalesce$5(ctx.inFlow, () => ( value.flow)), () => ( value.items.length === 0));
|
|
4917
4995
|
if (hasNewline || !flow) {
|
|
4918
4996
|
let hasPropsLine = false;
|
|
4919
4997
|
if (hasNewline && (vs0 === '&' || vs0 === '!')) {
|
|
@@ -4954,7 +5032,7 @@ function warn(logLevel, warning) {
|
|
|
4954
5032
|
}
|
|
4955
5033
|
}
|
|
4956
5034
|
|
|
4957
|
-
function _optionalChain$
|
|
5035
|
+
function _optionalChain$9(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
4958
5036
|
// If the value associated with a merge key is a single mapping node, each of
|
|
4959
5037
|
// its key/value pairs is inserted into the current mapping, unless the key
|
|
4960
5038
|
// already exists in it. If the value associated with the merge key is a
|
|
@@ -4978,7 +5056,7 @@ const isMergeKey = (ctx, key) => (merge.identify(key) ||
|
|
|
4978
5056
|
(isScalar(key) &&
|
|
4979
5057
|
(!key.type || key.type === Scalar.PLAIN) &&
|
|
4980
5058
|
merge.identify(key.value))) &&
|
|
4981
|
-
_optionalChain$
|
|
5059
|
+
_optionalChain$9([ctx, 'optionalAccess', _ => _.doc, 'access', _2 => _2.schema, 'access', _3 => _3.tags, 'access', _4 => _4.some, 'call', _5 => _5(tag => tag.tag === merge.tag && tag.default)]);
|
|
4982
5060
|
function addMergeToJSMap(ctx, map, value) {
|
|
4983
5061
|
value = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
4984
5062
|
if (isSeq(value))
|
|
@@ -5015,7 +5093,7 @@ function mergeValue(ctx, map, value) {
|
|
|
5015
5093
|
return map;
|
|
5016
5094
|
}
|
|
5017
5095
|
|
|
5018
|
-
function _optionalChain$
|
|
5096
|
+
function _optionalChain$8(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
5019
5097
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
5020
5098
|
if (isNode(key) && key.addToJSMap)
|
|
5021
5099
|
key.addToJSMap(ctx, map, value);
|
|
@@ -5052,7 +5130,7 @@ function stringifyKey(key, jsKey, ctx) {
|
|
|
5052
5130
|
// eslint-disable-next-line @typescript-eslint/no-base-to-string
|
|
5053
5131
|
if (typeof jsKey !== 'object')
|
|
5054
5132
|
return String(jsKey);
|
|
5055
|
-
if (isNode(key) && _optionalChain$
|
|
5133
|
+
if (isNode(key) && _optionalChain$8([ctx, 'optionalAccess', _ => _.doc])) {
|
|
5056
5134
|
const strCtx = createStringifyContext(ctx.doc, {});
|
|
5057
5135
|
strCtx.anchors = new Set();
|
|
5058
5136
|
for (const node of ctx.anchors.keys())
|
|
@@ -5072,7 +5150,7 @@ function stringifyKey(key, jsKey, ctx) {
|
|
|
5072
5150
|
return JSON.stringify(jsKey);
|
|
5073
5151
|
}
|
|
5074
5152
|
|
|
5075
|
-
function _optionalChain$
|
|
5153
|
+
function _optionalChain$7(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
5076
5154
|
function createPair(key, value, ctx) {
|
|
5077
5155
|
const k = createNode(key, undefined, ctx);
|
|
5078
5156
|
const v = createNode(value, undefined, ctx);
|
|
@@ -5093,19 +5171,19 @@ class Pair {
|
|
|
5093
5171
|
return new Pair(key, value);
|
|
5094
5172
|
}
|
|
5095
5173
|
toJSON(_, ctx) {
|
|
5096
|
-
const pair = _optionalChain$
|
|
5174
|
+
const pair = _optionalChain$7([ctx, 'optionalAccess', _2 => _2.mapAsMap]) ? new Map() : {};
|
|
5097
5175
|
return addPairToJSMap(ctx, pair, this);
|
|
5098
5176
|
}
|
|
5099
5177
|
toString(ctx, onComment, onChompKeep) {
|
|
5100
|
-
return _optionalChain$
|
|
5178
|
+
return _optionalChain$7([ctx, 'optionalAccess', _3 => _3.doc])
|
|
5101
5179
|
? stringifyPair(this, ctx, onComment, onChompKeep)
|
|
5102
5180
|
: JSON.stringify(this);
|
|
5103
5181
|
}
|
|
5104
5182
|
}
|
|
5105
5183
|
|
|
5106
|
-
function _nullishCoalesce$
|
|
5184
|
+
function _nullishCoalesce$4(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$6(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
5107
5185
|
function stringifyCollection(collection, ctx, options) {
|
|
5108
|
-
const flow = _nullishCoalesce$
|
|
5186
|
+
const flow = _nullishCoalesce$4(ctx.inFlow, () => ( collection.flow));
|
|
5109
5187
|
const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;
|
|
5110
5188
|
return stringify(collection, ctx, options);
|
|
5111
5189
|
}
|
|
@@ -5197,7 +5275,7 @@ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
|
|
|
5197
5275
|
if (iv.commentBefore)
|
|
5198
5276
|
reqNewline = true;
|
|
5199
5277
|
}
|
|
5200
|
-
else if (item.value == null && _optionalChain$
|
|
5278
|
+
else if (item.value == null && _optionalChain$6([ik, 'optionalAccess', _ => _.comment])) {
|
|
5201
5279
|
comment = ik.comment;
|
|
5202
5280
|
}
|
|
5203
5281
|
}
|
|
@@ -5252,7 +5330,7 @@ function addCommentBefore({ indent, options: { commentString } }, lines, comment
|
|
|
5252
5330
|
}
|
|
5253
5331
|
}
|
|
5254
5332
|
|
|
5255
|
-
function _nullishCoalesce$
|
|
5333
|
+
function _nullishCoalesce$3(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
5256
5334
|
function findPair(items, key) {
|
|
5257
5335
|
const k = isScalar(key) ? key.value : key;
|
|
5258
5336
|
for (const it of items) {
|
|
@@ -5313,12 +5391,12 @@ class YAMLMap extends Collection {
|
|
|
5313
5391
|
_pair = pair;
|
|
5314
5392
|
else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
|
|
5315
5393
|
// In TypeScript, this never happens.
|
|
5316
|
-
_pair = new Pair(pair, _optionalChain$
|
|
5394
|
+
_pair = new Pair(pair, _optionalChain$5([pair, 'optionalAccess', _2 => _2.value]));
|
|
5317
5395
|
}
|
|
5318
5396
|
else
|
|
5319
5397
|
_pair = new Pair(pair.key, pair.value);
|
|
5320
5398
|
const prev = findPair(this.items, _pair.key);
|
|
5321
|
-
const sortEntries = _optionalChain$
|
|
5399
|
+
const sortEntries = _optionalChain$5([this, 'access', _3 => _3.schema, 'optionalAccess', _4 => _4.sortMapEntries]);
|
|
5322
5400
|
if (prev) {
|
|
5323
5401
|
if (!overwrite)
|
|
5324
5402
|
throw new Error(`Key ${_pair.key} already set`);
|
|
@@ -5348,8 +5426,8 @@ class YAMLMap extends Collection {
|
|
|
5348
5426
|
}
|
|
5349
5427
|
get(key, keepScalar) {
|
|
5350
5428
|
const it = findPair(this.items, key);
|
|
5351
|
-
const node = _optionalChain$
|
|
5352
|
-
return _nullishCoalesce$
|
|
5429
|
+
const node = _optionalChain$5([it, 'optionalAccess', _5 => _5.value]);
|
|
5430
|
+
return _nullishCoalesce$3((!keepScalar && isScalar(node) ? node.value : node), () => ( undefined));
|
|
5353
5431
|
}
|
|
5354
5432
|
has(key) {
|
|
5355
5433
|
return !!findPair(this.items, key);
|
|
@@ -5363,8 +5441,8 @@ class YAMLMap extends Collection {
|
|
|
5363
5441
|
* @returns Instance of Type, Map, or Object
|
|
5364
5442
|
*/
|
|
5365
5443
|
toJSON(_, ctx, Type) {
|
|
5366
|
-
const map = Type ? new Type() : _optionalChain$
|
|
5367
|
-
if (_optionalChain$
|
|
5444
|
+
const map = Type ? new Type() : _optionalChain$5([ctx, 'optionalAccess', _6 => _6.mapAsMap]) ? new Map() : {};
|
|
5445
|
+
if (_optionalChain$5([ctx, 'optionalAccess', _7 => _7.onCreate]))
|
|
5368
5446
|
ctx.onCreate(map);
|
|
5369
5447
|
for (const item of this.items)
|
|
5370
5448
|
addPairToJSMap(ctx, map, item);
|
|
@@ -5389,7 +5467,7 @@ class YAMLMap extends Collection {
|
|
|
5389
5467
|
}
|
|
5390
5468
|
}
|
|
5391
5469
|
|
|
5392
|
-
function _optionalChain$
|
|
5470
|
+
function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
5393
5471
|
class YAMLSeq extends Collection {
|
|
5394
5472
|
static get tagName() {
|
|
5395
5473
|
return 'tag:yaml.org,2002:seq';
|
|
@@ -5452,7 +5530,7 @@ class YAMLSeq extends Collection {
|
|
|
5452
5530
|
}
|
|
5453
5531
|
toJSON(_, ctx) {
|
|
5454
5532
|
const seq = [];
|
|
5455
|
-
if (_optionalChain$
|
|
5533
|
+
if (_optionalChain$4([ctx, 'optionalAccess', _2 => _2.onCreate]))
|
|
5456
5534
|
ctx.onCreate(seq);
|
|
5457
5535
|
let i = 0;
|
|
5458
5536
|
for (const item of this.items)
|
|
@@ -5531,7 +5609,7 @@ function createPairs(schema, iterable, ctx) {
|
|
|
5531
5609
|
return pairs;
|
|
5532
5610
|
}
|
|
5533
5611
|
|
|
5534
|
-
function _optionalChain$
|
|
5612
|
+
function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
5535
5613
|
class YAMLOMap extends YAMLSeq {
|
|
5536
5614
|
constructor() {
|
|
5537
5615
|
super();
|
|
@@ -5550,7 +5628,7 @@ class YAMLOMap extends YAMLSeq {
|
|
|
5550
5628
|
if (!ctx)
|
|
5551
5629
|
return super.toJSON(_);
|
|
5552
5630
|
const map = new Map();
|
|
5553
|
-
if (_optionalChain$
|
|
5631
|
+
if (_optionalChain$3([ctx, 'optionalAccess', _2 => _2.onCreate]))
|
|
5554
5632
|
ctx.onCreate(map);
|
|
5555
5633
|
for (const pair of this.items) {
|
|
5556
5634
|
let key, value;
|
|
@@ -5902,273 +5980,126 @@ const detectProjectType = async (
|
|
|
5902
5980
|
};
|
|
5903
5981
|
};
|
|
5904
5982
|
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
* @param expectedType - 期望的项目类型
|
|
5910
|
-
* @returns 是否匹配
|
|
5911
|
-
*
|
|
5912
|
-
* @example
|
|
5913
|
-
* ```typescript
|
|
5914
|
-
* if (await isProjectType('/path/to/project', ProjectType.NEXTJS)) {
|
|
5915
|
-
* console.log('This is a Next.js project');
|
|
5916
|
-
* }
|
|
5917
|
-
* ```
|
|
5918
|
-
*/
|
|
5919
|
-
const isProjectType = async (
|
|
5983
|
+
const isDirectoryEmpty = async (projectPath) =>
|
|
5984
|
+
(await fs$1.readdir(projectPath)).length === 0;
|
|
5985
|
+
|
|
5986
|
+
const detectTemplateKey = async (
|
|
5920
5987
|
projectPath,
|
|
5921
|
-
expectedType,
|
|
5922
5988
|
) => {
|
|
5923
5989
|
const result = await detectProjectType(projectPath);
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
// ABOUTME: Fix rule to replace npx commands with pnpm in shell scripts (dev.sh, build.sh)
|
|
5928
|
-
// ABOUTME: This fixes module resolution issues when using npx in certain project types
|
|
5929
|
-
// ABOUTME: See: /Users/bytedance/Downloads/projects2/docs/npx-pnpm-module-resolution-issue.md
|
|
5930
|
-
|
|
5931
|
-
|
|
5932
|
-
|
|
5933
|
-
const debug$1 = debug$2('coze-init:fix');
|
|
5934
|
-
|
|
5935
|
-
/**
|
|
5936
|
-
* 需要应用此修复的项目类型
|
|
5937
|
-
*/
|
|
5938
|
-
const SUPPORTED_PROJECT_TYPES = [
|
|
5939
|
-
ProjectType.NEXTJS,
|
|
5940
|
-
ProjectType.VITE,
|
|
5941
|
-
ProjectType.NUXT,
|
|
5942
|
-
] ;
|
|
5943
|
-
|
|
5944
|
-
/**
|
|
5945
|
-
* 需要处理的脚本文件列表
|
|
5946
|
-
*/
|
|
5947
|
-
const SCRIPT_FILES = ['dev.sh', 'build.sh'] ;
|
|
5948
|
-
|
|
5949
|
-
/**
|
|
5950
|
-
* 脚本文件修改结果
|
|
5951
|
-
*/
|
|
5952
|
-
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
5957
|
-
|
|
5958
|
-
|
|
5959
|
-
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5966
|
-
|
|
5967
|
-
|
|
5968
|
-
|
|
5969
|
-
|
|
5970
|
-
|
|
5971
|
-
/**
|
|
5972
|
-
* 替换 shell 脚本中的 npx 为 pnpm
|
|
5973
|
-
*/
|
|
5974
|
-
const replaceNpxInShellScript = async (
|
|
5975
|
-
scriptPath,
|
|
5976
|
-
) => {
|
|
5977
|
-
debug$1(`Reading script file: ${scriptPath}`);
|
|
5978
|
-
const content = await fs$1.readFile(scriptPath, 'utf-8');
|
|
5979
|
-
debug$1(`File content length: ${content.length} bytes`);
|
|
5980
|
-
|
|
5981
|
-
const lines = content.split('\n');
|
|
5982
|
-
debug$1(`Total lines: ${lines.length}`);
|
|
5983
|
-
|
|
5984
|
-
const modifiedLines = [];
|
|
5985
|
-
const fromLines = [];
|
|
5986
|
-
const toLines = [];
|
|
5987
|
-
|
|
5988
|
-
let hasChanges = false;
|
|
5989
|
-
|
|
5990
|
-
for (let i = 0; i < lines.length; i++) {
|
|
5991
|
-
const line = lines[i];
|
|
5992
|
-
// 检查是否包含 npx 命令
|
|
5993
|
-
// 匹配 npx 后面跟着空格和命令
|
|
5994
|
-
const npxPattern = /\bnpx\s+/g;
|
|
5995
|
-
|
|
5996
|
-
if (npxPattern.test(line)) {
|
|
5997
|
-
debug$1(`Found npx at line ${i + 1}: ${line}`);
|
|
5998
|
-
const originalLine = line;
|
|
5999
|
-
// 替换所有 npx 为 pnpm
|
|
6000
|
-
const newLine = line.replace(/\bnpx\s+/g, 'pnpm ');
|
|
6001
|
-
|
|
6002
|
-
if (newLine !== originalLine) {
|
|
6003
|
-
debug$1(` Replaced to: ${newLine}`);
|
|
6004
|
-
modifiedLines.push(newLine);
|
|
6005
|
-
fromLines.push(originalLine);
|
|
6006
|
-
toLines.push(newLine);
|
|
6007
|
-
hasChanges = true;
|
|
6008
|
-
} else {
|
|
6009
|
-
modifiedLines.push(line);
|
|
6010
|
-
}
|
|
6011
|
-
} else {
|
|
6012
|
-
modifiedLines.push(line);
|
|
6013
|
-
}
|
|
5990
|
+
if (!result.detected) {
|
|
5991
|
+
return null;
|
|
6014
5992
|
}
|
|
6015
5993
|
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6020
|
-
|
|
6021
|
-
|
|
5994
|
+
switch (result.type) {
|
|
5995
|
+
case ProjectType.NEXTJS:
|
|
5996
|
+
return 'nextjs';
|
|
5997
|
+
case ProjectType.VITE:
|
|
5998
|
+
return 'vite';
|
|
5999
|
+
case ProjectType.NUXT:
|
|
6000
|
+
return 'nuxt-vue';
|
|
6001
|
+
case ProjectType.EXPO:
|
|
6002
|
+
return 'expo';
|
|
6003
|
+
case ProjectType.TARO:
|
|
6004
|
+
return 'taro';
|
|
6005
|
+
default:
|
|
6006
|
+
return null;
|
|
6022
6007
|
}
|
|
6023
|
-
|
|
6024
|
-
return { modified: hasChanges, from: fromLines, to: toLines };
|
|
6025
6008
|
};
|
|
6026
6009
|
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
*/
|
|
6030
|
-
const replaceNpxWithPnpm = async (
|
|
6031
|
-
projectFolder,
|
|
6032
|
-
) => {
|
|
6033
|
-
const scriptsDir = path.join(projectFolder, 'scripts');
|
|
6034
|
-
debug$1(`Checking scripts directory: ${scriptsDir}`);
|
|
6035
|
-
|
|
6036
|
-
const changedFiles = [];
|
|
6037
|
-
|
|
6038
|
-
// 检查 scripts 目录是否存在
|
|
6039
|
-
const scriptsDirExists = await isDirExists(scriptsDir);
|
|
6040
|
-
debug$1(`Scripts directory exists: ${scriptsDirExists}`);
|
|
6010
|
+
const SCRIPT_FILES = ['dev.sh', 'build.sh'] ;
|
|
6011
|
+
const SUPPORTED_TEMPLATES = new Set(['nextjs', 'vite', 'nuxt-vue']);
|
|
6041
6012
|
|
|
6042
|
-
|
|
6043
|
-
|
|
6013
|
+
const hasNpxInScripts = async (projectFolder) => {
|
|
6014
|
+
const scriptsDir = path.join(projectFolder, 'scripts');
|
|
6015
|
+
if (!(await isDirExists(scriptsDir))) {
|
|
6016
|
+
return false;
|
|
6044
6017
|
}
|
|
6045
6018
|
|
|
6046
|
-
// 处理每个脚本文件
|
|
6047
6019
|
for (const fileName of SCRIPT_FILES) {
|
|
6048
6020
|
const scriptPath = path.join(scriptsDir, fileName);
|
|
6049
|
-
|
|
6050
|
-
|
|
6051
|
-
const exists = await isFileExists(scriptPath);
|
|
6052
|
-
debug$1(` File exists: ${exists}`);
|
|
6053
|
-
|
|
6054
|
-
if (!exists) {
|
|
6021
|
+
if (!(await isFileExists(scriptPath))) {
|
|
6055
6022
|
continue;
|
|
6056
6023
|
}
|
|
6057
6024
|
|
|
6058
|
-
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
if (result.modified) {
|
|
6062
|
-
debug$1(` File was modified with ${result.from.length} change(s)`);
|
|
6063
|
-
changedFiles.push({
|
|
6064
|
-
fileName,
|
|
6065
|
-
from: result.from,
|
|
6066
|
-
to: result.to,
|
|
6067
|
-
});
|
|
6068
|
-
}
|
|
6069
|
-
} catch (error) {
|
|
6070
|
-
logger.error(`Failed to process ${fileName}:`, error);
|
|
6071
|
-
debug$1(
|
|
6072
|
-
` Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
6073
|
-
);
|
|
6025
|
+
const content = await fs$1.readFile(scriptPath, 'utf-8');
|
|
6026
|
+
if (/\bnpx\s+/.test(content)) {
|
|
6027
|
+
return true;
|
|
6074
6028
|
}
|
|
6075
6029
|
}
|
|
6076
6030
|
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
return {
|
|
6080
|
-
modified: changedFiles.length > 0,
|
|
6081
|
-
changedFiles,
|
|
6082
|
-
};
|
|
6031
|
+
return false;
|
|
6083
6032
|
};
|
|
6084
6033
|
|
|
6085
|
-
|
|
6086
|
-
|
|
6087
|
-
|
|
6088
|
-
|
|
6089
|
-
|
|
6090
|
-
|
|
6091
|
-
const fixReplaceNpxWithPnpm = async context => {
|
|
6092
|
-
const ruleName = 'replace-npx-with-pnpm';
|
|
6093
|
-
|
|
6094
|
-
debug$1(`Starting fix rule: ${ruleName}`);
|
|
6095
|
-
debug$1(`Project folder: ${context.projectFolder}`);
|
|
6096
|
-
|
|
6097
|
-
// 1. 检测项目类型
|
|
6098
|
-
const projectDetection = await detectProjectType(context.projectFolder);
|
|
6099
|
-
debug$1(`Project detection result: ${JSON.stringify(projectDetection)}`);
|
|
6100
|
-
|
|
6101
|
-
if (!projectDetection.detected) {
|
|
6102
|
-
return {
|
|
6103
|
-
ruleName,
|
|
6104
|
-
applied: false,
|
|
6105
|
-
message: 'Project type not detected, skipping',
|
|
6106
|
-
};
|
|
6107
|
-
}
|
|
6108
|
-
|
|
6109
|
-
// 2. 检查是否为支持的项目类型
|
|
6110
|
-
const isSupportedType = (
|
|
6111
|
-
SUPPORTED_PROJECT_TYPES
|
|
6112
|
-
).includes(projectDetection.type);
|
|
6113
|
-
|
|
6114
|
-
debug$1(`Is supported type: ${isSupportedType}`);
|
|
6115
|
-
debug$1(`Supported types: ${SUPPORTED_PROJECT_TYPES.join(', ')}`);
|
|
6116
|
-
|
|
6117
|
-
if (!isSupportedType) {
|
|
6118
|
-
return {
|
|
6119
|
-
ruleName,
|
|
6120
|
-
applied: false,
|
|
6121
|
-
message: 'Project type not supported for this fix, skipping',
|
|
6122
|
-
};
|
|
6123
|
-
}
|
|
6124
|
-
|
|
6125
|
-
logger.info(`Detected ${projectDetection.type} project`);
|
|
6126
|
-
|
|
6127
|
-
// 3. 执行替换
|
|
6128
|
-
debug$1('Starting npx replacement...');
|
|
6129
|
-
const replaceResult = await replaceNpxWithPnpm(context.projectFolder);
|
|
6034
|
+
const applyReplaceNpxWithPnpm = async (
|
|
6035
|
+
context,
|
|
6036
|
+
patchId,
|
|
6037
|
+
) => {
|
|
6038
|
+
const scriptsDir = path.join(context.projectFolder, 'scripts');
|
|
6039
|
+
let changedFiles = 0;
|
|
6130
6040
|
|
|
6131
|
-
if (!
|
|
6041
|
+
if (!(await isDirExists(scriptsDir))) {
|
|
6132
6042
|
return {
|
|
6133
|
-
ruleName,
|
|
6134
6043
|
applied: false,
|
|
6135
|
-
|
|
6044
|
+
patchId,
|
|
6045
|
+
message: 'scripts directory not found, skipping',
|
|
6136
6046
|
};
|
|
6137
6047
|
}
|
|
6138
6048
|
|
|
6139
|
-
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6049
|
+
for (const fileName of SCRIPT_FILES) {
|
|
6050
|
+
const scriptPath = path.join(scriptsDir, fileName);
|
|
6051
|
+
if (!(await isFileExists(scriptPath))) {
|
|
6052
|
+
continue;
|
|
6053
|
+
}
|
|
6143
6054
|
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
logger.info(` + ${file.to[i]}`);
|
|
6055
|
+
const content = await fs$1.readFile(scriptPath, 'utf-8');
|
|
6056
|
+
const nextContent = content.replace(/\bnpx\s+/g, 'pnpm ');
|
|
6057
|
+
if (nextContent === content) {
|
|
6058
|
+
continue;
|
|
6149
6059
|
}
|
|
6060
|
+
|
|
6061
|
+
await fs$1.writeFile(scriptPath, nextContent, 'utf-8');
|
|
6062
|
+
changedFiles++;
|
|
6063
|
+
logger.info(`Patched scripts/${fileName}: replaced npx with pnpm`);
|
|
6150
6064
|
}
|
|
6151
6065
|
|
|
6152
6066
|
return {
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
message:
|
|
6067
|
+
applied: changedFiles > 0,
|
|
6068
|
+
patchId,
|
|
6069
|
+
message:
|
|
6070
|
+
changedFiles > 0
|
|
6071
|
+
? `Replaced npx with pnpm in ${changedFiles} file(s)`
|
|
6072
|
+
: 'No npx commands found in shell scripts, skipping',
|
|
6156
6073
|
};
|
|
6157
6074
|
};
|
|
6158
6075
|
|
|
6159
|
-
|
|
6160
|
-
|
|
6161
|
-
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6076
|
+
const createReplaceNpxWithPnpmPatch = (
|
|
6077
|
+
template,
|
|
6078
|
+
) => ({
|
|
6079
|
+
id: `${template}/replace-npx-with-pnpm@0.0.10`,
|
|
6080
|
+
template,
|
|
6081
|
+
operations: [
|
|
6082
|
+
{
|
|
6083
|
+
kind: 'file-patch',
|
|
6084
|
+
file: 'scripts/dev.sh',
|
|
6085
|
+
description: 'Replace npx with pnpm in shell scripts',
|
|
6086
|
+
},
|
|
6087
|
+
{
|
|
6088
|
+
kind: 'file-patch',
|
|
6089
|
+
file: 'scripts/build.sh',
|
|
6090
|
+
description: 'Replace npx with pnpm in shell scripts',
|
|
6091
|
+
},
|
|
6092
|
+
],
|
|
6093
|
+
shouldApply: async context =>
|
|
6094
|
+
SUPPORTED_TEMPLATES.has(context.template) &&
|
|
6095
|
+
(await hasNpxInScripts(context.projectFolder)),
|
|
6096
|
+
apply: async context =>
|
|
6097
|
+
applyReplaceNpxWithPnpm(
|
|
6098
|
+
context,
|
|
6099
|
+
`${template}/replace-npx-with-pnpm@0.0.10`,
|
|
6100
|
+
),
|
|
6101
|
+
});
|
|
6168
6102
|
|
|
6169
|
-
/**
|
|
6170
|
-
* 查找 Next.js 配置文件
|
|
6171
|
-
*/
|
|
6172
6103
|
const findNextConfigFile = async (
|
|
6173
6104
|
projectFolder,
|
|
6174
6105
|
) => {
|
|
@@ -6188,221 +6119,256 @@ const findNextConfigFile = async (
|
|
|
6188
6119
|
return null;
|
|
6189
6120
|
};
|
|
6190
6121
|
|
|
6191
|
-
|
|
6192
|
-
* 注释掉 outputFileTracingRoot 配置
|
|
6193
|
-
*/
|
|
6194
|
-
const commentOutOutputTracingRoot = async (
|
|
6122
|
+
const getUncommentedTracingRootLine = async (
|
|
6195
6123
|
configPath,
|
|
6196
6124
|
) => {
|
|
6197
|
-
|
|
6198
|
-
let modified = false;
|
|
6199
|
-
let originalLine = null;
|
|
6200
|
-
|
|
6201
|
-
// 匹配包含 outputFileTracingRoot 的行(尚未被注释的)
|
|
6202
|
-
// 支持 path.resolve(...) 后面有空格,然后可选逗号
|
|
6203
|
-
// 只匹配单行配置,不匹配跨多行的配置
|
|
6125
|
+
const content = await fs$1.readFile(configPath, 'utf-8');
|
|
6204
6126
|
const pattern =
|
|
6205
6127
|
/^(\s*)(outputFileTracingRoot:\s*path\.resolve\([^\n\r)]+\)\s*,?)\s*$/gm;
|
|
6206
6128
|
|
|
6207
6129
|
const matches = content.match(pattern);
|
|
6130
|
+
return matches && matches.length > 0 ? matches[0].trim() : null;
|
|
6131
|
+
};
|
|
6208
6132
|
|
|
6209
|
-
|
|
6210
|
-
|
|
6211
|
-
|
|
6212
|
-
|
|
6213
|
-
|
|
6214
|
-
|
|
6133
|
+
const commentOutOutputTracingRoot = async (
|
|
6134
|
+
configPath,
|
|
6135
|
+
) => {
|
|
6136
|
+
const content = await fs$1.readFile(configPath, 'utf-8');
|
|
6137
|
+
const pattern =
|
|
6138
|
+
/^(\s*)(outputFileTracingRoot:\s*path\.resolve\([^\n\r)]+\)\s*,?)\s*$/gm;
|
|
6139
|
+
const matches = content.match(pattern);
|
|
6215
6140
|
|
|
6216
|
-
|
|
6141
|
+
if (!matches || matches.length === 0) {
|
|
6142
|
+
return null;
|
|
6217
6143
|
}
|
|
6218
6144
|
|
|
6219
|
-
|
|
6145
|
+
const originalLine = matches[0].trim();
|
|
6146
|
+
const nextContent = content.replace(pattern, '$1// $2');
|
|
6147
|
+
await fs$1.writeFile(configPath, nextContent, 'utf-8');
|
|
6148
|
+
return originalLine;
|
|
6220
6149
|
};
|
|
6221
6150
|
|
|
6222
|
-
|
|
6223
|
-
* Fix 规则:注释掉 Next.js 项目中的 outputFileTracingRoot 配置
|
|
6224
|
-
* 这个配置在 monorepo 环境中可能会导致问题
|
|
6225
|
-
*/
|
|
6226
|
-
const fixNextOutputTracingRoot = async context => {
|
|
6227
|
-
const ruleName = 'next-output-tracing-root';
|
|
6151
|
+
const PATCH_ID = 'nextjs/next-output-tracing-root@0.0.10';
|
|
6228
6152
|
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6153
|
+
const patchNextOutputTracingRoot = {
|
|
6154
|
+
id: PATCH_ID,
|
|
6155
|
+
template: 'nextjs',
|
|
6156
|
+
operations: [
|
|
6157
|
+
{
|
|
6158
|
+
kind: 'file-patch',
|
|
6159
|
+
file: 'next.config.ts',
|
|
6160
|
+
description: 'Comment out problematic outputFileTracingRoot config',
|
|
6161
|
+
},
|
|
6162
|
+
],
|
|
6163
|
+
shouldApply: async context => {
|
|
6164
|
+
if (context.template !== 'nextjs') {
|
|
6165
|
+
return false;
|
|
6166
|
+
}
|
|
6237
6167
|
|
|
6238
|
-
|
|
6239
|
-
|
|
6168
|
+
const configPath = await findNextConfigFile(context.projectFolder);
|
|
6169
|
+
if (!configPath) {
|
|
6170
|
+
return false;
|
|
6171
|
+
}
|
|
6240
6172
|
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6173
|
+
return (await getUncommentedTracingRootLine(configPath)) !== null;
|
|
6174
|
+
},
|
|
6175
|
+
apply: async (context) => {
|
|
6176
|
+
const configPath = await findNextConfigFile(context.projectFolder);
|
|
6177
|
+
if (!configPath) {
|
|
6178
|
+
return {
|
|
6179
|
+
applied: false,
|
|
6180
|
+
patchId: PATCH_ID,
|
|
6181
|
+
message: 'Next.js config file not found, skipping',
|
|
6182
|
+
};
|
|
6183
|
+
}
|
|
6248
6184
|
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6185
|
+
const originalLine = await commentOutOutputTracingRoot(configPath);
|
|
6186
|
+
if (!originalLine) {
|
|
6187
|
+
return {
|
|
6188
|
+
applied: false,
|
|
6189
|
+
patchId: PATCH_ID,
|
|
6190
|
+
message: 'No outputFileTracingRoot config found, skipping',
|
|
6191
|
+
};
|
|
6192
|
+
}
|
|
6252
6193
|
|
|
6253
|
-
|
|
6254
|
-
|
|
6255
|
-
`Commented out outputFileTracingRoot in ${configPath.split('/').pop()}`,
|
|
6194
|
+
logger.info(
|
|
6195
|
+
`Patched ${configPath.split('/').pop()}: commented out ${originalLine}`,
|
|
6256
6196
|
);
|
|
6257
|
-
logger.info(` Original: ${originalLine}`);
|
|
6258
6197
|
|
|
6259
6198
|
return {
|
|
6260
|
-
ruleName,
|
|
6261
6199
|
applied: true,
|
|
6200
|
+
patchId: PATCH_ID,
|
|
6262
6201
|
message: `Successfully commented out: ${originalLine}`,
|
|
6263
6202
|
};
|
|
6264
|
-
}
|
|
6265
|
-
|
|
6266
|
-
return {
|
|
6267
|
-
ruleName,
|
|
6268
|
-
applied: false,
|
|
6269
|
-
message: 'No outputFileTracingRoot config found, skipping',
|
|
6270
|
-
};
|
|
6203
|
+
},
|
|
6271
6204
|
};
|
|
6272
6205
|
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
fixReplaceNpxWithPnpm,
|
|
6206
|
+
const patches = [
|
|
6207
|
+
createReplaceNpxWithPnpmPatch('nextjs'),
|
|
6208
|
+
createReplaceNpxWithPnpmPatch('vite'),
|
|
6209
|
+
createReplaceNpxWithPnpmPatch('nuxt-vue'),
|
|
6210
|
+
patchNextOutputTracingRoot,
|
|
6211
|
+
] ;
|
|
6280
6212
|
|
|
6281
|
-
|
|
6282
|
-
|
|
6213
|
+
const getTemplatePatches = (
|
|
6214
|
+
template,
|
|
6215
|
+
) =>
|
|
6216
|
+
patches.filter(patch => patch.template === template);
|
|
6283
6217
|
|
|
6284
|
-
|
|
6285
|
-
|
|
6218
|
+
function _nullishCoalesce$2(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
6219
|
+
const DEFAULT_LEGACY_VERSION = 'legacy';
|
|
6286
6220
|
|
|
6287
|
-
|
|
6288
|
-
|
|
6221
|
+
const loadExistingTomlConfig = async (
|
|
6222
|
+
projectFolder,
|
|
6223
|
+
) => {
|
|
6224
|
+
try {
|
|
6225
|
+
await fs$1.access(path.resolve(projectFolder, '.coze'));
|
|
6226
|
+
} catch (e) {
|
|
6227
|
+
return null;
|
|
6228
|
+
}
|
|
6289
6229
|
|
|
6230
|
+
return loadTomlCozeConfig(projectFolder);
|
|
6231
|
+
};
|
|
6290
6232
|
|
|
6291
|
-
const
|
|
6233
|
+
const writePatchState = async (
|
|
6234
|
+
projectFolder,
|
|
6235
|
+
config,
|
|
6236
|
+
state
|
|
6292
6237
|
|
|
6293
|
-
const JSON_INDENT_SPACES = 2;
|
|
6294
6238
|
|
|
6295
|
-
|
|
6296
|
-
|
|
6297
|
-
* 执行 fix 命令的内部实现
|
|
6298
|
-
*/
|
|
6299
|
-
const executeFix = async (
|
|
6300
|
-
options = {},
|
|
6239
|
+
|
|
6240
|
+
,
|
|
6301
6241
|
) => {
|
|
6302
|
-
|
|
6303
|
-
|
|
6304
|
-
|
|
6305
|
-
|
|
6306
|
-
|
|
6242
|
+
config.project = {
|
|
6243
|
+
...(config.project || {}),
|
|
6244
|
+
template: state.template,
|
|
6245
|
+
version: state.version,
|
|
6246
|
+
appliedPatches: state.appliedPatches,
|
|
6247
|
+
};
|
|
6307
6248
|
|
|
6308
|
-
|
|
6309
|
-
|
|
6310
|
-
logger.info(`Found ${rules.length} fix rule(s) to apply\n`);
|
|
6249
|
+
await saveTomlCozeConfig(config, projectFolder);
|
|
6250
|
+
};
|
|
6311
6251
|
|
|
6312
|
-
|
|
6313
|
-
|
|
6314
|
-
|
|
6315
|
-
|
|
6252
|
+
const executePatch = async (
|
|
6253
|
+
options = {},
|
|
6254
|
+
) => {
|
|
6255
|
+
const cwd = process.cwd();
|
|
6256
|
+
const projectFolder = options.directory
|
|
6257
|
+
? path.resolve(cwd, options.directory)
|
|
6258
|
+
: cwd;
|
|
6316
6259
|
|
|
6317
|
-
|
|
6318
|
-
|
|
6319
|
-
|
|
6260
|
+
if (await isDirectoryEmpty(projectFolder)) {
|
|
6261
|
+
logger.info(`Patch skipped: ${projectFolder} is empty`);
|
|
6262
|
+
return;
|
|
6263
|
+
}
|
|
6320
6264
|
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
|
|
6265
|
+
const config = await loadExistingTomlConfig(projectFolder);
|
|
6266
|
+
if (!config) {
|
|
6267
|
+
logger.info('Patch skipped: .coze file not found');
|
|
6268
|
+
return;
|
|
6269
|
+
}
|
|
6324
6270
|
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
const rule = rules[i];
|
|
6328
|
-
const ruleNumber = i + 1;
|
|
6271
|
+
const template =
|
|
6272
|
+
_optionalChain$2([config, 'access', _ => _.project, 'optionalAccess', _2 => _2.template]) || (await detectTemplateKey(projectFolder));
|
|
6329
6273
|
|
|
6330
|
-
|
|
6331
|
-
|
|
6274
|
+
if (!template) {
|
|
6275
|
+
logger.info('Patch skipped: template not detected');
|
|
6276
|
+
return;
|
|
6277
|
+
}
|
|
6332
6278
|
|
|
6333
|
-
|
|
6334
|
-
|
|
6335
|
-
const duration = Date.now() - startTime;
|
|
6279
|
+
const appliedPatches = [...(_optionalChain$2([config, 'access', _3 => _3.project, 'optionalAccess', _4 => _4.appliedPatches]) || [])];
|
|
6280
|
+
const projectVersion = _optionalChain$2([config, 'access', _5 => _5.project, 'optionalAccess', _6 => _6.version]);
|
|
6336
6281
|
|
|
6337
|
-
|
|
6338
|
-
|
|
6282
|
+
const context = {
|
|
6283
|
+
cwd,
|
|
6284
|
+
projectFolder,
|
|
6285
|
+
template,
|
|
6286
|
+
projectVersion,
|
|
6287
|
+
appliedPatches,
|
|
6288
|
+
cozeConfig: config,
|
|
6289
|
+
};
|
|
6339
6290
|
|
|
6340
|
-
|
|
6341
|
-
|
|
6342
|
-
|
|
6343
|
-
} else {
|
|
6344
|
-
skippedCount++;
|
|
6345
|
-
logger.info(`○ ${result.ruleName}: ${result.message}`);
|
|
6346
|
-
}
|
|
6291
|
+
const candidatePatches = getTemplatePatches(template).filter(
|
|
6292
|
+
patch => patch.disabled !== true && !appliedPatches.includes(patch.id),
|
|
6293
|
+
);
|
|
6347
6294
|
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
6352
|
-
|
|
6353
|
-
|
|
6295
|
+
const matchedPatches = [];
|
|
6296
|
+
for (const patch of candidatePatches) {
|
|
6297
|
+
if (await patch.shouldApply(context)) {
|
|
6298
|
+
matchedPatches.push(patch);
|
|
6299
|
+
}
|
|
6300
|
+
}
|
|
6354
6301
|
|
|
6355
|
-
|
|
6356
|
-
|
|
6357
|
-
|
|
6358
|
-
|
|
6302
|
+
if (matchedPatches.length === 0) {
|
|
6303
|
+
logger.info('No patch matched current project state');
|
|
6304
|
+
return;
|
|
6305
|
+
}
|
|
6359
6306
|
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
}
|
|
6307
|
+
if (options.dryRun) {
|
|
6308
|
+
logger.info(`Detected template: ${template}`);
|
|
6309
|
+
logger.info(`Current version: ${_nullishCoalesce$2(projectVersion, () => ( DEFAULT_LEGACY_VERSION))}`);
|
|
6310
|
+
logger.info(`Applied patches: ${appliedPatches.join(', ') || '(none)'}`);
|
|
6311
|
+
logger.info('Matched patches:');
|
|
6312
|
+
matchedPatches.forEach(patch => {
|
|
6313
|
+
logger.info(` - ${patch.id}`);
|
|
6314
|
+
patch.operations.forEach(operation => {
|
|
6315
|
+
if ('file' in operation) {
|
|
6316
|
+
logger.info(
|
|
6317
|
+
` ${operation.kind}: ${operation.file} - ${operation.description}`,
|
|
6318
|
+
);
|
|
6319
|
+
} else {
|
|
6320
|
+
logger.info(` ${operation.kind}: ${operation.description}`);
|
|
6321
|
+
}
|
|
6322
|
+
});
|
|
6323
|
+
});
|
|
6324
|
+
return;
|
|
6325
|
+
}
|
|
6363
6326
|
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6327
|
+
let hasWrittenPatchState = Boolean(_optionalChain$2([config, 'access', _7 => _7.project, 'optionalAccess', _8 => _8.template]));
|
|
6328
|
+
for (const patch of matchedPatches) {
|
|
6329
|
+
const result = await patch.apply({
|
|
6330
|
+
...context,
|
|
6331
|
+
appliedPatches,
|
|
6332
|
+
});
|
|
6369
6333
|
|
|
6370
|
-
if (
|
|
6371
|
-
logger.
|
|
6372
|
-
|
|
6373
|
-
logger.warn('\nSome fixes failed, check logs above for details');
|
|
6374
|
-
} else {
|
|
6375
|
-
logger.info('\nNo fixes needed');
|
|
6334
|
+
if (!result.applied) {
|
|
6335
|
+
logger.info(`○ ${patch.id}: ${result.message}`);
|
|
6336
|
+
continue;
|
|
6376
6337
|
}
|
|
6377
|
-
} catch (error) {
|
|
6378
|
-
logger.error('Failed to run fix command:');
|
|
6379
|
-
logger.error(error instanceof Error ? error.message : String(error));
|
|
6380
6338
|
|
|
6381
|
-
|
|
6382
|
-
|
|
6383
|
-
|
|
6339
|
+
if (!hasWrittenPatchState) {
|
|
6340
|
+
await writePatchState(projectFolder, config, {
|
|
6341
|
+
template,
|
|
6342
|
+
version: DEFAULT_LEGACY_VERSION,
|
|
6343
|
+
appliedPatches,
|
|
6344
|
+
});
|
|
6345
|
+
hasWrittenPatchState = true;
|
|
6384
6346
|
}
|
|
6385
6347
|
|
|
6386
|
-
|
|
6348
|
+
appliedPatches.push(patch.id);
|
|
6349
|
+
await writePatchState(projectFolder, config, {
|
|
6350
|
+
template,
|
|
6351
|
+
version: _optionalChain$2([config, 'access', _9 => _9.project, 'optionalAccess', _10 => _10.version]) || DEFAULT_LEGACY_VERSION,
|
|
6352
|
+
appliedPatches,
|
|
6353
|
+
});
|
|
6354
|
+
logger.success(`✓ ${patch.id}: ${result.message}`);
|
|
6387
6355
|
}
|
|
6388
6356
|
};
|
|
6389
|
-
// end_aigc
|
|
6390
6357
|
|
|
6391
|
-
/**
|
|
6392
|
-
* 注册 fix 命令到 program
|
|
6393
|
-
*/
|
|
6394
6358
|
const registerCommand$3 = program => {
|
|
6395
6359
|
program
|
|
6396
|
-
.command('
|
|
6397
|
-
.description(
|
|
6398
|
-
'Fix legacy issues from previous versions (e.g., problematic configs)',
|
|
6399
|
-
)
|
|
6360
|
+
.command('patch')
|
|
6361
|
+
.description('Apply template patches for existing projects')
|
|
6400
6362
|
.argument(
|
|
6401
6363
|
'[directory]',
|
|
6402
|
-
'Target directory to
|
|
6364
|
+
'Target directory to patch (defaults to current directory)',
|
|
6403
6365
|
)
|
|
6404
|
-
.
|
|
6405
|
-
|
|
6366
|
+
.option('--dry-run', 'Show matched patches without modifying files')
|
|
6367
|
+
.action(async (directory, command) => {
|
|
6368
|
+
await executePatch({
|
|
6369
|
+
directory,
|
|
6370
|
+
dryRun: _optionalChain$2([command, 'optionalAccess', _11 => _11.dryRun]),
|
|
6371
|
+
});
|
|
6406
6372
|
});
|
|
6407
6373
|
};
|
|
6408
6374
|
|
|
@@ -6463,12 +6429,12 @@ const executeRun = async (
|
|
|
6463
6429
|
// 上报命令开始
|
|
6464
6430
|
reportCommandStart(commandName, JSON.stringify(options));
|
|
6465
6431
|
|
|
6466
|
-
// 1. 对于 build 命令,先执行
|
|
6432
|
+
// 1. 对于 build/dev 命令,先执行 patch 以确保项目配置正确
|
|
6467
6433
|
if (['dev', 'build'].includes(commandName)) {
|
|
6468
|
-
logger.info('\n🔧 Running
|
|
6434
|
+
logger.info('\n🔧 Running patch command before execution...\n');
|
|
6469
6435
|
const fixStartTime = Date.now();
|
|
6470
6436
|
try {
|
|
6471
|
-
await
|
|
6437
|
+
await executePatch();
|
|
6472
6438
|
// eslint-disable-next-line @coze-arch/no-empty-catch
|
|
6473
6439
|
} catch (e) {
|
|
6474
6440
|
// just ignore
|
|
@@ -6706,7 +6672,7 @@ const registerCommand$2 = program => {
|
|
|
6706
6672
|
|
|
6707
6673
|
|
|
6708
6674
|
|
|
6709
|
-
const log$4 = debug
|
|
6675
|
+
const log$4 = debug('coze:routes:nuxt');
|
|
6710
6676
|
|
|
6711
6677
|
/**
|
|
6712
6678
|
* Convert Nuxt file path to route path
|
|
@@ -6946,7 +6912,7 @@ const scanNuxtRoutes = async (cwd) => {
|
|
|
6946
6912
|
|
|
6947
6913
|
|
|
6948
6914
|
|
|
6949
|
-
const log$3 = debug
|
|
6915
|
+
const log$3 = debug('coze:routes:nextjs');
|
|
6950
6916
|
|
|
6951
6917
|
/**
|
|
6952
6918
|
* Convert Next.js file path to route path
|
|
@@ -7287,7 +7253,7 @@ const getOutputFilePath = (cwd, outputPath) =>
|
|
|
7287
7253
|
|
|
7288
7254
|
|
|
7289
7255
|
|
|
7290
|
-
const log$2 = debug
|
|
7256
|
+
const log$2 = debug('coze:routes:detect');
|
|
7291
7257
|
|
|
7292
7258
|
/**
|
|
7293
7259
|
* Check if any of the specified files exist
|
|
@@ -7392,7 +7358,7 @@ const detectTemplate = (cwd) => {
|
|
|
7392
7358
|
// ABOUTME: Orchestrates template detection, route scanning, and polling-based updates
|
|
7393
7359
|
|
|
7394
7360
|
|
|
7395
|
-
const log$1 = debug
|
|
7361
|
+
const log$1 = debug('coze:routes:scanner');
|
|
7396
7362
|
|
|
7397
7363
|
/**
|
|
7398
7364
|
* Scan routes based on template type
|
|
@@ -7493,7 +7459,7 @@ const scanRoutesOnce = async (
|
|
|
7493
7459
|
function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// Route manifest generation command
|
|
7494
7460
|
|
|
7495
7461
|
|
|
7496
|
-
const log = debug
|
|
7462
|
+
const log = debug('coze:routes');
|
|
7497
7463
|
|
|
7498
7464
|
/**
|
|
7499
7465
|
* Execute routes command implementation
|
|
@@ -8649,7 +8615,22 @@ const executeTemplateEngineStep = async ctx => {
|
|
|
8649
8615
|
};
|
|
8650
8616
|
|
|
8651
8617
|
/**
|
|
8652
|
-
* 步骤2:
|
|
8618
|
+
* 步骤2: 写入 patch 项目元数据
|
|
8619
|
+
*/
|
|
8620
|
+
const writePatchMetadataStep = async ctx => {
|
|
8621
|
+
if (!ctx.absoluteOutputPath) {
|
|
8622
|
+
return;
|
|
8623
|
+
}
|
|
8624
|
+
|
|
8625
|
+
await saveProjectPatchState(ctx.absoluteOutputPath, {
|
|
8626
|
+
template: ctx.templateName,
|
|
8627
|
+
version: packageJson.version,
|
|
8628
|
+
appliedPatches: [],
|
|
8629
|
+
});
|
|
8630
|
+
};
|
|
8631
|
+
|
|
8632
|
+
/**
|
|
8633
|
+
* 步骤3: 检查 package.json 是否存在
|
|
8653
8634
|
*/
|
|
8654
8635
|
const checkPackageJsonStep = ctx => {
|
|
8655
8636
|
if (!ctx.absoluteOutputPath) {
|
|
@@ -8661,7 +8642,7 @@ const checkPackageJsonStep = ctx => {
|
|
|
8661
8642
|
};
|
|
8662
8643
|
|
|
8663
8644
|
/**
|
|
8664
|
-
* 步骤
|
|
8645
|
+
* 步骤4: 安装依赖
|
|
8665
8646
|
*/
|
|
8666
8647
|
const installDependenciesStep = ctx => {
|
|
8667
8648
|
if (!ctx.absoluteOutputPath) {
|
|
@@ -8709,7 +8690,7 @@ const installDependenciesStep = ctx => {
|
|
|
8709
8690
|
};
|
|
8710
8691
|
|
|
8711
8692
|
/**
|
|
8712
|
-
* 步骤
|
|
8693
|
+
* 步骤5: 执行完成钩子
|
|
8713
8694
|
*/
|
|
8714
8695
|
const executeCompleteHookStep = async ctx => {
|
|
8715
8696
|
if (!ctx.absoluteOutputPath || !ctx.templateConfig || !ctx.context) {
|
|
@@ -8726,7 +8707,7 @@ const executeCompleteHookStep = async ctx => {
|
|
|
8726
8707
|
};
|
|
8727
8708
|
|
|
8728
8709
|
/**
|
|
8729
|
-
* 步骤
|
|
8710
|
+
* 步骤6: 初始化 Git 仓库
|
|
8730
8711
|
*/
|
|
8731
8712
|
const gitInitStep = ctx => {
|
|
8732
8713
|
if (!ctx.absoluteOutputPath) {
|
|
@@ -8742,7 +8723,7 @@ const gitInitStep = ctx => {
|
|
|
8742
8723
|
};
|
|
8743
8724
|
|
|
8744
8725
|
/**
|
|
8745
|
-
* 步骤
|
|
8726
|
+
* 步骤7: 提交 Git 变更
|
|
8746
8727
|
*/
|
|
8747
8728
|
const gitCommitStep = ctx => {
|
|
8748
8729
|
if (!ctx.absoluteOutputPath) {
|
|
@@ -8758,7 +8739,7 @@ const gitCommitStep = ctx => {
|
|
|
8758
8739
|
};
|
|
8759
8740
|
|
|
8760
8741
|
/**
|
|
8761
|
-
* 步骤
|
|
8742
|
+
* 步骤8: 启动开发服务器
|
|
8762
8743
|
*/
|
|
8763
8744
|
const startDevServerStep = ctx => {
|
|
8764
8745
|
if (!ctx.absoluteOutputPath) {
|
|
@@ -8792,6 +8773,7 @@ const startDevServerStep = ctx => {
|
|
|
8792
8773
|
*/
|
|
8793
8774
|
const initSteps = [
|
|
8794
8775
|
executeTemplateEngineStep,
|
|
8776
|
+
writePatchMetadataStep,
|
|
8795
8777
|
checkPackageJsonStep,
|
|
8796
8778
|
installDependenciesStep,
|
|
8797
8779
|
executeCompleteHookStep,
|