@coze-arch/cli 0.0.11-alpha.47b93c → 0.0.12

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 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 = require('debug');
7
+ var debug$2 = 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,7 +15,6 @@ 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
- var crypto = require('crypto');
19
18
  var fastGlob = require('fast-glob');
20
19
  var child_process = require('child_process');
21
20
  var addFormats = require('ajv-formats');
@@ -1492,7 +1491,7 @@ var browserClient = createBaseClient();
1492
1491
 
1493
1492
 
1494
1493
 
1495
- const log$7 = debug('slardar:transport');
1494
+ const log$7 = debug$2('slardar:transport');
1496
1495
  // eslint-disable-next-line @typescript-eslint/no-empty-function
1497
1496
  const noop = () => {};
1498
1497
 
@@ -1628,14 +1627,14 @@ function createNodeTransport() {
1628
1627
  };
1629
1628
  }
1630
1629
 
1631
- function _nullishCoalesce$9(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$o(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; }/**
1630
+ function _nullishCoalesce$8(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }/**
1632
1631
  * Slardar CLI Reporter 主类
1633
1632
  * 封装 @slardar/base 的初始化和上报逻辑
1634
1633
  */
1635
1634
 
1636
1635
  // 创建 debug 实例
1637
1636
  // 使用方式: DEBUG=slardar:* your-cli-command
1638
- const log$6 = debug('slardar:reporter');
1637
+ const log$6 = debug$2('slardar:reporter');
1639
1638
 
1640
1639
  /**
1641
1640
  * Slardar CLI Reporter
@@ -1685,7 +1684,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
1685
1684
  release: config.release,
1686
1685
  env: config.env,
1687
1686
  name: config.name,
1688
- useLocalConfig: _nullishCoalesce$9(config.useLocalConfig, () => ( false)), // 默认使用服务端配置
1687
+ useLocalConfig: _nullishCoalesce$8(config.useLocalConfig, () => ( false)), // 默认使用服务端配置
1689
1688
  domain: config.domain,
1690
1689
  // 设置本地采样率为 100%,确保事件不被过滤
1691
1690
  sample: {
@@ -1700,7 +1699,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
1700
1699
  this.client.on('send', (ev) => {
1701
1700
  log$6(
1702
1701
  'send hook called for event: %s',
1703
- (_optionalChain$o([ev, 'optionalAccess', _ => _.ev_type]) ) || 'unknown',
1702
+ (_optionalChain$l([ev, 'optionalAccess', _ => _.ev_type]) ) || 'unknown',
1704
1703
  );
1705
1704
  });
1706
1705
 
@@ -1758,7 +1757,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
1758
1757
  )
1759
1758
  : undefined;
1760
1759
 
1761
- _optionalChain$o([this, 'access', _2 => _2.client, 'access', _3 => _3.sendEvent, 'optionalCall', _4 => _4({
1760
+ _optionalChain$l([this, 'access', _2 => _2.client, 'access', _3 => _3.sendEvent, 'optionalCall', _4 => _4({
1762
1761
  name,
1763
1762
  metrics: cleanMetrics ,
1764
1763
  categories: cleanCategories ,
@@ -1829,7 +1828,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
1829
1828
  log$6('Reporting JS error:', {
1830
1829
  name: error.name,
1831
1830
  message: error.message.slice(0, 100),
1832
- stack: _optionalChain$o([error, 'access', _5 => _5.stack, 'optionalAccess', _6 => _6.slice, 'call', _7 => _7(0, 200)]),
1831
+ stack: _optionalChain$l([error, 'access', _5 => _5.stack, 'optionalAccess', _6 => _6.slice, 'call', _7 => _7(0, 200)]),
1833
1832
  extra,
1834
1833
  source,
1835
1834
  });
@@ -1849,7 +1848,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
1849
1848
  if (!this.ensureInitialized()) {
1850
1849
  return;
1851
1850
  }
1852
- _optionalChain$o([this, 'access', _8 => _8.client, 'access', _9 => _9.context, 'optionalAccess', _10 => _10.set, 'call', _11 => _11(key, value)]);
1851
+ _optionalChain$l([this, 'access', _8 => _8.client, 'access', _9 => _9.context, 'optionalAccess', _10 => _10.set, 'call', _11 => _11(key, value)]);
1853
1852
  }
1854
1853
 
1855
1854
  /**
@@ -1860,7 +1859,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
1860
1859
  return;
1861
1860
  }
1862
1861
  log$6('Merging context:', context);
1863
- _optionalChain$o([this, 'access', _12 => _12.client, 'access', _13 => _13.context, 'optionalAccess', _14 => _14.merge, 'call', _15 => _15(context)]);
1862
+ _optionalChain$l([this, 'access', _12 => _12.client, 'access', _13 => _13.context, 'optionalAccess', _14 => _14.merge, 'call', _15 => _15(context)]);
1864
1863
  }
1865
1864
 
1866
1865
  /**
@@ -1870,7 +1869,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
1870
1869
  if (!this.ensureInitialized()) {
1871
1870
  return;
1872
1871
  }
1873
- _optionalChain$o([this, 'access', _16 => _16.client, 'access', _17 => _17.context, 'optionalAccess', _18 => _18.delete, 'call', _19 => _19(key)]);
1872
+ _optionalChain$l([this, 'access', _16 => _16.client, 'access', _17 => _17.context, 'optionalAccess', _18 => _18.delete, 'call', _19 => _19(key)]);
1874
1873
  }
1875
1874
 
1876
1875
  /**
@@ -1880,7 +1879,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
1880
1879
  if (!this.ensureInitialized()) {
1881
1880
  return;
1882
1881
  }
1883
- _optionalChain$o([this, 'access', _20 => _20.client, 'access', _21 => _21.context, 'optionalAccess', _22 => _22.clear, 'call', _23 => _23()]);
1882
+ _optionalChain$l([this, 'access', _20 => _20.client, 'access', _21 => _21.context, 'optionalAccess', _22 => _22.clear, 'call', _23 => _23()]);
1884
1883
  }
1885
1884
 
1886
1885
  /**
@@ -1917,7 +1916,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
1917
1916
  return;
1918
1917
  }
1919
1918
  log$6('Flushing Slardar data...');
1920
- _optionalChain$o([this, 'access', _24 => _24.client, 'access', _25 => _25.getSender, 'optionalCall', _26 => _26(), 'optionalAccess', _27 => _27.flush, 'call', _28 => _28()]);
1919
+ _optionalChain$l([this, 'access', _24 => _24.client, 'access', _25 => _25.getSender, 'optionalCall', _26 => _26(), 'optionalAccess', _27 => _27.flush, 'call', _28 => _28()]);
1921
1920
  log$6('Waiting %dms for events to be sent...', waitMs);
1922
1921
  await new Promise(resolve => setTimeout(resolve, waitMs));
1923
1922
  log$6('Slardar data flushed');
@@ -1936,7 +1935,7 @@ class SlardarCLIReporter {constructor() { SlardarCLIReporter.prototype.__init.ca
1936
1935
  */
1937
1936
  const reporter = new SlardarCLIReporter();
1938
1937
 
1939
- function _optionalChain$n(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; }
1938
+ 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; }
1940
1939
 
1941
1940
 
1942
1941
 
@@ -1996,11 +1995,11 @@ const EventBuilder = {
1996
1995
  name: CLI_EVENTS.CLI_COMMAND,
1997
1996
  categories: {
1998
1997
  command,
1999
- args: _optionalChain$n([options, 'optionalAccess', _ => _.args]),
1998
+ args: _optionalChain$k([options, 'optionalAccess', _ => _.args]),
2000
1999
  status: 'running' ,
2001
- ..._optionalChain$n([options, 'optionalAccess', _2 => _2.categories]),
2000
+ ..._optionalChain$k([options, 'optionalAccess', _2 => _2.categories]),
2002
2001
  },
2003
- metrics: _optionalChain$n([options, 'optionalAccess', _3 => _3.metrics]),
2002
+ metrics: _optionalChain$k([options, 'optionalAccess', _3 => _3.metrics]),
2004
2003
  };
2005
2004
  },
2006
2005
 
@@ -2021,13 +2020,13 @@ const EventBuilder = {
2021
2020
  name: CLI_EVENTS.CLI_COMMAND_COMPLETE,
2022
2021
  categories: {
2023
2022
  command,
2024
- args: _optionalChain$n([options, 'optionalAccess', _4 => _4.args]),
2023
+ args: _optionalChain$k([options, 'optionalAccess', _4 => _4.args]),
2025
2024
  status: success ? ('success' ) : ('fail' ),
2026
- ..._optionalChain$n([options, 'optionalAccess', _5 => _5.categories]),
2025
+ ..._optionalChain$k([options, 'optionalAccess', _5 => _5.categories]),
2027
2026
  },
2028
2027
  metrics: {
2029
2028
  duration,
2030
- ...(_optionalChain$n([options, 'optionalAccess', _6 => _6.errorCode]) && { errorCode: options.errorCode }),
2029
+ ...(_optionalChain$k([options, 'optionalAccess', _6 => _6.errorCode]) && { errorCode: options.errorCode }),
2031
2030
  },
2032
2031
  };
2033
2032
  },
@@ -2048,12 +2047,12 @@ const EventBuilder = {
2048
2047
  name: CLI_EVENTS.NETWORK_REQUEST,
2049
2048
  categories: {
2050
2049
  url,
2051
- method: _optionalChain$n([options, 'optionalAccess', _7 => _7.method]) || 'GET',
2052
- statusCode: _optionalChain$n([options, 'optionalAccess', _8 => _8.statusCode, 'optionalAccess', _9 => _9.toString, 'call', _10 => _10()]),
2053
- status: _optionalChain$n([options, 'optionalAccess', _11 => _11.success]) ? ('success' ) : ('fail' ),
2050
+ method: _optionalChain$k([options, 'optionalAccess', _7 => _7.method]) || 'GET',
2051
+ statusCode: _optionalChain$k([options, 'optionalAccess', _8 => _8.statusCode, 'optionalAccess', _9 => _9.toString, 'call', _10 => _10()]),
2052
+ status: _optionalChain$k([options, 'optionalAccess', _11 => _11.success]) ? ('success' ) : ('fail' ),
2054
2053
  },
2055
2054
  metrics: {
2056
- duration: _optionalChain$n([options, 'optionalAccess', _12 => _12.duration]),
2055
+ duration: _optionalChain$k([options, 'optionalAccess', _12 => _12.duration]),
2057
2056
  },
2058
2057
  };
2059
2058
  },
@@ -2075,11 +2074,11 @@ const EventBuilder = {
2075
2074
  categories: {
2076
2075
  operation,
2077
2076
  filePath,
2078
- status: _optionalChain$n([options, 'optionalAccess', _13 => _13.success]) ? ('success' ) : ('fail' ),
2077
+ status: _optionalChain$k([options, 'optionalAccess', _13 => _13.success]) ? ('success' ) : ('fail' ),
2079
2078
  },
2080
2079
  metrics: {
2081
- duration: _optionalChain$n([options, 'optionalAccess', _14 => _14.duration]),
2082
- fileSize: _optionalChain$n([options, 'optionalAccess', _15 => _15.fileSize]),
2080
+ duration: _optionalChain$k([options, 'optionalAccess', _14 => _14.duration]),
2081
+ fileSize: _optionalChain$k([options, 'optionalAccess', _15 => _15.fileSize]),
2083
2082
  },
2084
2083
  };
2085
2084
  },
@@ -2107,7 +2106,7 @@ const EventBuilder = {
2107
2106
  };
2108
2107
 
2109
2108
  var name = "@coze-arch/cli";
2110
- var version = "0.0.11-alpha.47b93c";
2109
+ var version = "0.0.12";
2111
2110
  var description = "coze coding devtools cli";
2112
2111
  var license = "MIT";
2113
2112
  var author = "fanwenjie.fe@bytedance.com";
@@ -2213,11 +2212,11 @@ var packageJson = {
2213
2212
  cozePublishConfig: cozePublishConfig
2214
2213
  };
2215
2214
 
2216
- 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; }/**
2215
+ 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; }/**
2217
2216
  * Slardar 监控初始化和上报
2218
2217
  */
2219
2218
 
2220
- const log$5 = debug('slardar:cli');
2219
+ const log$5 = debug$2('slardar:cli');
2221
2220
 
2222
2221
  /**
2223
2222
  * 安全执行函数包装器
@@ -2316,11 +2315,11 @@ const reportCommandComplete = safeRun(
2316
2315
  ,
2317
2316
  ) => {
2318
2317
  const event = EventBuilder.cliCommandComplete(command, success, duration, {
2319
- args: _optionalChain$m([options, 'optionalAccess', _ => _.args]),
2320
- errorCode: _optionalChain$m([options, 'optionalAccess', _2 => _2.errorCode]),
2318
+ args: _optionalChain$j([options, 'optionalAccess', _ => _.args]),
2319
+ errorCode: _optionalChain$j([options, 'optionalAccess', _2 => _2.errorCode]),
2321
2320
  categories: {
2322
- ...(_optionalChain$m([options, 'optionalAccess', _3 => _3.errorMessage]) && { errorMessage: options.errorMessage }),
2323
- ..._optionalChain$m([options, 'optionalAccess', _4 => _4.categories]),
2321
+ ...(_optionalChain$j([options, 'optionalAccess', _3 => _3.errorMessage]) && { errorMessage: options.errorMessage }),
2322
+ ..._optionalChain$j([options, 'optionalAccess', _4 => _4.categories]),
2324
2323
  },
2325
2324
  });
2326
2325
  reporter.sendEvent(event.name, event.metrics, event.categories);
@@ -2379,7 +2378,7 @@ const flushSlardar = safeRun('flushSlardar', async () => {
2379
2378
  await reporter.flush();
2380
2379
  });
2381
2380
 
2382
- function _nullishCoalesce$8(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }var LogLevel; (function (LogLevel) {
2381
+ function _nullishCoalesce$7(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }var LogLevel; (function (LogLevel) {
2383
2382
  const ERROR = 0; LogLevel[LogLevel["ERROR"] = ERROR] = "ERROR";
2384
2383
  const WARN = 1; LogLevel[LogLevel["WARN"] = WARN] = "WARN";
2385
2384
  const SUCCESS = 2; LogLevel[LogLevel["SUCCESS"] = SUCCESS] = "SUCCESS";
@@ -2417,7 +2416,7 @@ class Logger {
2417
2416
 
2418
2417
  constructor(options = {}) {
2419
2418
  this.level = this.parseLogLevel(options.level);
2420
- this.useColor = _nullishCoalesce$8(options.useColor, () => ( this.isColorSupported()));
2419
+ this.useColor = _nullishCoalesce$7(options.useColor, () => ( this.isColorSupported()));
2421
2420
  this.prefix = options.prefix;
2422
2421
  }
2423
2422
 
@@ -2426,7 +2425,7 @@ class Logger {
2426
2425
  return level;
2427
2426
  }
2428
2427
 
2429
- const envLevel = _optionalChain$l([process, 'access', _ => _.env, 'access', _2 => _2.LOG_LEVEL, 'optionalAccess', _3 => _3.toLowerCase, 'call', _4 => _4()]);
2428
+ const envLevel = _optionalChain$i([process, 'access', _ => _.env, 'access', _2 => _2.LOG_LEVEL, 'optionalAccess', _3 => _3.toLowerCase, 'call', _4 => _4()]);
2430
2429
  if (envLevel && envLevel in LOG_LEVEL_MAP) {
2431
2430
  return LOG_LEVEL_MAP[envLevel];
2432
2431
  }
@@ -2438,7 +2437,7 @@ class Logger {
2438
2437
  // 简单检测:Node.js 环境且支持 TTY
2439
2438
  return (
2440
2439
  typeof process !== 'undefined' &&
2441
- _optionalChain$l([process, 'access', _5 => _5.stdout, 'optionalAccess', _6 => _6.isTTY]) === true &&
2440
+ _optionalChain$i([process, 'access', _5 => _5.stdout, 'optionalAccess', _6 => _6.isTTY]) === true &&
2442
2441
  process.env.NO_COLOR === undefined
2443
2442
  );
2444
2443
  }
@@ -2463,7 +2462,7 @@ class Logger {
2463
2462
 
2464
2463
  const icon = this.colorize(options.icon, options.color);
2465
2464
  const prefix = this.prefix ? `${icon} ${this.prefix}` : icon;
2466
- console.log(prefix, options.message, ...(_nullishCoalesce$8(options.args, () => ( []))));
2465
+ console.log(prefix, options.message, ...(_nullishCoalesce$7(options.args, () => ( []))));
2467
2466
  }
2468
2467
 
2469
2468
  error(message, ...args) {
@@ -3277,7 +3276,7 @@ const registerCommand$4 = program => {
3277
3276
  });
3278
3277
  };
3279
3278
 
3280
- 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; }/* eslint-disable @typescript-eslint/no-explicit-any */
3279
+ 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; }/* eslint-disable @typescript-eslint/no-explicit-any */
3281
3280
  // Safe JSON parsing utilities with type safety and error handling
3282
3281
  // Provides fallback values, validation, and error monitoring capabilities
3283
3282
 
@@ -3377,12 +3376,12 @@ function safeJsonParse(
3377
3376
  const parsed = JSON.parse(String(input));
3378
3377
 
3379
3378
  // Optional validation
3380
- if (_optionalChain$k([options, 'optionalAccess', _ => _.validate])) {
3379
+ if (_optionalChain$h([options, 'optionalAccess', _ => _.validate])) {
3381
3380
  if (options.validate(parsed)) {
3382
3381
  return parsed;
3383
3382
  } else {
3384
3383
  const validationError = new Error('JSON validation failed');
3385
- _optionalChain$k([options, 'access', _2 => _2.onError, 'optionalCall', _3 => _3(validationError, input)]);
3384
+ _optionalChain$h([options, 'access', _2 => _2.onError, 'optionalCall', _3 => _3(validationError, input)]);
3386
3385
 
3387
3386
  if (options.throwOnValidationError) {
3388
3387
  throw validationError;
@@ -3394,10 +3393,10 @@ function safeJsonParse(
3394
3393
  return parsed;
3395
3394
  } catch (error) {
3396
3395
  // Re-throw validation errors when throwOnValidationError is true
3397
- if (error instanceof Error && error.message === 'JSON validation failed' && _optionalChain$k([options, 'optionalAccess', _4 => _4.throwOnValidationError])) {
3396
+ if (error instanceof Error && error.message === 'JSON validation failed' && _optionalChain$h([options, 'optionalAccess', _4 => _4.throwOnValidationError])) {
3398
3397
  throw error;
3399
3398
  }
3400
- _optionalChain$k([options, 'optionalAccess', _5 => _5.onError, 'optionalCall', _6 => _6(error , input)]);
3399
+ _optionalChain$h([options, 'optionalAccess', _5 => _5.onError, 'optionalCall', _6 => _6(error , input)]);
3401
3400
  return defaultValue;
3402
3401
  }
3403
3402
  }
@@ -3437,7 +3436,7 @@ function isNode(node) {
3437
3436
  }
3438
3437
  const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
3439
3438
 
3440
- 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; }
3439
+ 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; }
3441
3440
  const BREAK = Symbol('break visit');
3442
3441
  const SKIP = Symbol('skip children');
3443
3442
  const REMOVE = Symbol('remove node');
@@ -3550,15 +3549,15 @@ function callVisitor(key, node, visitor, path) {
3550
3549
  if (typeof visitor === 'function')
3551
3550
  return visitor(key, node, path);
3552
3551
  if (isMap(node))
3553
- return _optionalChain$j([visitor, 'access', _ => _.Map, 'optionalCall', _2 => _2(key, node, path)]);
3552
+ return _optionalChain$g([visitor, 'access', _ => _.Map, 'optionalCall', _2 => _2(key, node, path)]);
3554
3553
  if (isSeq(node))
3555
- return _optionalChain$j([visitor, 'access', _3 => _3.Seq, 'optionalCall', _4 => _4(key, node, path)]);
3554
+ return _optionalChain$g([visitor, 'access', _3 => _3.Seq, 'optionalCall', _4 => _4(key, node, path)]);
3556
3555
  if (isPair(node))
3557
- return _optionalChain$j([visitor, 'access', _5 => _5.Pair, 'optionalCall', _6 => _6(key, node, path)]);
3556
+ return _optionalChain$g([visitor, 'access', _5 => _5.Pair, 'optionalCall', _6 => _6(key, node, path)]);
3558
3557
  if (isScalar(node))
3559
- return _optionalChain$j([visitor, 'access', _7 => _7.Scalar, 'optionalCall', _8 => _8(key, node, path)]);
3558
+ return _optionalChain$g([visitor, 'access', _7 => _7.Scalar, 'optionalCall', _8 => _8(key, node, path)]);
3560
3559
  if (isAlias(node))
3561
- return _optionalChain$j([visitor, 'access', _9 => _9.Alias, 'optionalCall', _10 => _10(key, node, path)]);
3560
+ return _optionalChain$g([visitor, 'access', _9 => _9.Alias, 'optionalCall', _10 => _10(key, node, path)]);
3562
3561
  return undefined;
3563
3562
  }
3564
3563
  function replaceNode(key, path, node) {
@@ -3649,7 +3648,7 @@ function applyReviver(reviver, obj, key, val) {
3649
3648
  return reviver.call(obj, key, val);
3650
3649
  }
3651
3650
 
3652
- 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; }
3651
+ 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; }
3653
3652
  /**
3654
3653
  * Recursively convert any node or its contents to native JavaScript
3655
3654
  *
@@ -3679,7 +3678,7 @@ function toJS(value, arg, ctx) {
3679
3678
  ctx.onCreate(res);
3680
3679
  return res;
3681
3680
  }
3682
- if (typeof value === 'bigint' && !_optionalChain$i([ctx, 'optionalAccess', _ => _.keep]))
3681
+ if (typeof value === 'bigint' && !_optionalChain$f([ctx, 'optionalAccess', _ => _.keep]))
3683
3682
  return Number(value);
3684
3683
  return value;
3685
3684
  }
@@ -3717,7 +3716,7 @@ class NodeBase {
3717
3716
  }
3718
3717
  }
3719
3718
 
3720
- 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; }
3719
+ 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; }
3721
3720
  class Alias extends NodeBase {
3722
3721
  constructor(source) {
3723
3722
  super(ALIAS);
@@ -3734,7 +3733,7 @@ class Alias extends NodeBase {
3734
3733
  */
3735
3734
  resolve(doc, ctx) {
3736
3735
  let nodes;
3737
- if (_optionalChain$h([ctx, 'optionalAccess', _ => _.aliasResolveCache])) {
3736
+ if (_optionalChain$e([ctx, 'optionalAccess', _ => _.aliasResolveCache])) {
3738
3737
  nodes = ctx.aliasResolveCache;
3739
3738
  }
3740
3739
  else {
@@ -3773,7 +3772,7 @@ class Alias extends NodeBase {
3773
3772
  data = anchors.get(source);
3774
3773
  }
3775
3774
  /* istanbul ignore if */
3776
- if (_optionalChain$h([data, 'optionalAccess', _2 => _2.res]) === undefined) {
3775
+ if (_optionalChain$e([data, 'optionalAccess', _2 => _2.res]) === undefined) {
3777
3776
  const msg = 'This should not happen: Alias anchor was not resolved?';
3778
3777
  throw new ReferenceError(msg);
3779
3778
  }
@@ -3825,7 +3824,7 @@ function getAliasCount(doc, node, anchors) {
3825
3824
  return 1;
3826
3825
  }
3827
3826
 
3828
- 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; }
3827
+ 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; }
3829
3828
  const isScalarValue = (value) => !value || (typeof value !== 'function' && typeof value !== 'object');
3830
3829
  class Scalar extends NodeBase {
3831
3830
  constructor(value) {
@@ -3833,7 +3832,7 @@ class Scalar extends NodeBase {
3833
3832
  this.value = value;
3834
3833
  }
3835
3834
  toJSON(arg, ctx) {
3836
- return _optionalChain$g([ctx, 'optionalAccess', _ => _.keep]) ? this.value : toJS(this.value, arg, ctx);
3835
+ return _optionalChain$d([ctx, 'optionalAccess', _ => _.keep]) ? this.value : toJS(this.value, arg, ctx);
3837
3836
  }
3838
3837
  toString() {
3839
3838
  return String(this.value);
@@ -3845,17 +3844,17 @@ Scalar.PLAIN = 'PLAIN';
3845
3844
  Scalar.QUOTE_DOUBLE = 'QUOTE_DOUBLE';
3846
3845
  Scalar.QUOTE_SINGLE = 'QUOTE_SINGLE';
3847
3846
 
3848
- function _nullishCoalesce$7(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }
3847
+ function _nullishCoalesce$6(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; }
3849
3848
  const defaultTagPrefix = 'tag:yaml.org,2002:';
3850
3849
  function findTagObject(value, tagName, tags) {
3851
3850
  if (tagName) {
3852
3851
  const match = tags.filter(t => t.tag === tagName);
3853
- const tagObj = _nullishCoalesce$7(match.find(t => !t.format), () => ( match[0]));
3852
+ const tagObj = _nullishCoalesce$6(match.find(t => !t.format), () => ( match[0]));
3854
3853
  if (!tagObj)
3855
3854
  throw new Error(`Tag ${tagName} not found`);
3856
3855
  return tagObj;
3857
3856
  }
3858
- return tags.find(t => _optionalChain$f([t, 'access', _ => _.identify, 'optionalCall', _2 => _2(value)]) && !t.format);
3857
+ return tags.find(t => _optionalChain$c([t, 'access', _ => _.identify, 'optionalCall', _2 => _2(value)]) && !t.format);
3859
3858
  }
3860
3859
  function createNode(value, tagName, ctx) {
3861
3860
  if (isDocument(value))
@@ -3863,7 +3862,7 @@ function createNode(value, tagName, ctx) {
3863
3862
  if (isNode(value))
3864
3863
  return value;
3865
3864
  if (isPair(value)) {
3866
- const map = _optionalChain$f([ctx, 'access', _3 => _3.schema, 'access', _4 => _4[MAP], 'access', _5 => _5.createNode, 'optionalCall', _6 => _6(ctx.schema, null, ctx)]);
3865
+ const map = _optionalChain$c([ctx, 'access', _3 => _3.schema, 'access', _4 => _4[MAP], 'access', _5 => _5.createNode, 'optionalCall', _6 => _6(ctx.schema, null, ctx)]);
3867
3866
  map.items.push(value);
3868
3867
  return map;
3869
3868
  }
@@ -3882,7 +3881,7 @@ function createNode(value, tagName, ctx) {
3882
3881
  if (aliasDuplicateObjects && value && typeof value === 'object') {
3883
3882
  ref = sourceObjects.get(value);
3884
3883
  if (ref) {
3885
- _nullishCoalesce$7(ref.anchor, () => ( (ref.anchor = onAnchor(value))));
3884
+ _nullishCoalesce$6(ref.anchor, () => ( (ref.anchor = onAnchor(value))));
3886
3885
  return new Alias(ref.anchor);
3887
3886
  }
3888
3887
  else {
@@ -3890,7 +3889,7 @@ function createNode(value, tagName, ctx) {
3890
3889
  sourceObjects.set(value, ref);
3891
3890
  }
3892
3891
  }
3893
- if (_optionalChain$f([tagName, 'optionalAccess', _7 => _7.startsWith, 'call', _8 => _8('!!')]))
3892
+ if (_optionalChain$c([tagName, 'optionalAccess', _7 => _7.startsWith, 'call', _8 => _8('!!')]))
3894
3893
  tagName = defaultTagPrefix + tagName.slice(2);
3895
3894
  let tagObj = findTagObject(value, tagName, schema.tags);
3896
3895
  if (!tagObj) {
@@ -3915,9 +3914,9 @@ function createNode(value, tagName, ctx) {
3915
3914
  onTagObj(tagObj);
3916
3915
  delete ctx.onTagObj;
3917
3916
  }
3918
- const node = _optionalChain$f([tagObj, 'optionalAccess', _9 => _9.createNode])
3917
+ const node = _optionalChain$c([tagObj, 'optionalAccess', _9 => _9.createNode])
3919
3918
  ? tagObj.createNode(ctx.schema, value, ctx)
3920
- : typeof _optionalChain$f([tagObj, 'optionalAccess', _10 => _10.nodeClass, 'optionalAccess', _11 => _11.from]) === 'function'
3919
+ : typeof _optionalChain$c([tagObj, 'optionalAccess', _10 => _10.nodeClass, 'optionalAccess', _11 => _11.from]) === 'function'
3921
3920
  ? tagObj.nodeClass.from(ctx.schema, value, ctx)
3922
3921
  : new Scalar(value);
3923
3922
  if (tagName)
@@ -4235,7 +4234,7 @@ function consumeMoreIndentedLines(text, i, indent) {
4235
4234
  return end;
4236
4235
  }
4237
4236
 
4238
- 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; }
4237
+ 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; }
4239
4238
  const getFoldOptions = (ctx, isBlock) => ({
4240
4239
  indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
4241
4240
  lineWidth: ctx.options.lineWidth,
@@ -4520,9 +4519,9 @@ function plainString(item, ctx, onComment, onChompKeep) {
4520
4519
  // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
4521
4520
  // and others in v1.1.
4522
4521
  if (actualString) {
4523
- const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && _optionalChain$e([tag, 'access', _ => _.test, 'optionalAccess', _2 => _2.test, 'call', _3 => _3(str)]);
4522
+ 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)]);
4524
4523
  const { compat, tags } = ctx.doc.schema;
4525
- if (tags.some(test) || _optionalChain$e([compat, 'optionalAccess', _4 => _4.some, 'call', _5 => _5(test)]))
4524
+ if (tags.some(test) || _optionalChain$b([compat, 'optionalAccess', _4 => _4.some, 'call', _5 => _5(test)]))
4526
4525
  return quotedString(value, ctx);
4527
4526
  }
4528
4527
  return implicitKey
@@ -4568,7 +4567,7 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
4568
4567
  return res;
4569
4568
  }
4570
4569
 
4571
- function _nullishCoalesce$6(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }
4570
+ function _nullishCoalesce$5(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; }
4572
4571
  function createStringifyContext(doc, options) {
4573
4572
  const opt = Object.assign({
4574
4573
  blockQuote: true,
@@ -4615,27 +4614,27 @@ function getTagObject(tags, item) {
4615
4614
  if (item.tag) {
4616
4615
  const match = tags.filter(t => t.tag === item.tag);
4617
4616
  if (match.length > 0)
4618
- return _nullishCoalesce$6(match.find(t => t.format === item.format), () => ( match[0]));
4617
+ return _nullishCoalesce$5(match.find(t => t.format === item.format), () => ( match[0]));
4619
4618
  }
4620
4619
  let tagObj = undefined;
4621
4620
  let obj;
4622
4621
  if (isScalar(item)) {
4623
4622
  obj = item.value;
4624
- let match = tags.filter(t => _optionalChain$d([t, 'access', _ => _.identify, 'optionalCall', _2 => _2(obj)]));
4623
+ let match = tags.filter(t => _optionalChain$a([t, 'access', _ => _.identify, 'optionalCall', _2 => _2(obj)]));
4625
4624
  if (match.length > 1) {
4626
4625
  const testMatch = match.filter(t => t.test);
4627
4626
  if (testMatch.length > 0)
4628
4627
  match = testMatch;
4629
4628
  }
4630
4629
  tagObj =
4631
- _nullishCoalesce$6(match.find(t => t.format === item.format), () => ( match.find(t => !t.format)));
4630
+ _nullishCoalesce$5(match.find(t => t.format === item.format), () => ( match.find(t => !t.format)));
4632
4631
  }
4633
4632
  else {
4634
4633
  obj = item;
4635
4634
  tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
4636
4635
  }
4637
4636
  if (!tagObj) {
4638
- const name = _nullishCoalesce$6(_optionalChain$d([obj, 'optionalAccess', _3 => _3.constructor, 'optionalAccess', _4 => _4.name]), () => ( (obj === null ? 'null' : typeof obj)));
4637
+ const name = _nullishCoalesce$5(_optionalChain$a([obj, 'optionalAccess', _3 => _3.constructor, 'optionalAccess', _4 => _4.name]), () => ( (obj === null ? 'null' : typeof obj)));
4639
4638
  throw new Error(`Tag not resolved for ${name} value`);
4640
4639
  }
4641
4640
  return tagObj;
@@ -4650,7 +4649,7 @@ function stringifyProps(node, tagObj, { anchors, doc }) {
4650
4649
  anchors.add(anchor);
4651
4650
  props.push(`&${anchor}`);
4652
4651
  }
4653
- const tag = _nullishCoalesce$6(node.tag, () => ( (tagObj.default ? null : tagObj.tag)));
4652
+ const tag = _nullishCoalesce$5(node.tag, () => ( (tagObj.default ? null : tagObj.tag)));
4654
4653
  if (tag)
4655
4654
  props.push(doc.directives.tagString(tag));
4656
4655
  return props.join(' ');
@@ -4661,7 +4660,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
4661
4660
  if (isAlias(item)) {
4662
4661
  if (ctx.doc.directives)
4663
4662
  return item.toString(ctx);
4664
- if (_optionalChain$d([ctx, 'access', _5 => _5.resolvedAliases, 'optionalAccess', _6 => _6.has, 'call', _7 => _7(item)])) {
4663
+ if (_optionalChain$a([ctx, 'access', _5 => _5.resolvedAliases, 'optionalAccess', _6 => _6.has, 'call', _7 => _7(item)])) {
4665
4664
  throw new TypeError(`Cannot stringify circular structure without alias nodes`);
4666
4665
  }
4667
4666
  else {
@@ -4676,10 +4675,10 @@ function stringify(item, ctx, onComment, onChompKeep) {
4676
4675
  const node = isNode(item)
4677
4676
  ? item
4678
4677
  : ctx.doc.createNode(item, { onTagObj: o => (tagObj = o) });
4679
- _nullishCoalesce$6(tagObj, () => ( (tagObj = getTagObject(ctx.doc.schema.tags, node))));
4678
+ _nullishCoalesce$5(tagObj, () => ( (tagObj = getTagObject(ctx.doc.schema.tags, node))));
4680
4679
  const props = stringifyProps(node, tagObj, ctx);
4681
4680
  if (props.length > 0)
4682
- ctx.indentAtStart = (_nullishCoalesce$6(ctx.indentAtStart, () => ( 0))) + props.length + 1;
4681
+ ctx.indentAtStart = (_nullishCoalesce$5(ctx.indentAtStart, () => ( 0))) + props.length + 1;
4683
4682
  const str = typeof tagObj.stringify === 'function'
4684
4683
  ? tagObj.stringify(node, ctx, onComment, onChompKeep)
4685
4684
  : isScalar(node)
@@ -4692,7 +4691,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
4692
4691
  : `${props}\n${ctx.indent}${str}`;
4693
4692
  }
4694
4693
 
4695
- function _nullishCoalesce$5(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
4694
+ function _nullishCoalesce$4(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
4696
4695
  function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
4697
4696
  const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;
4698
4697
  let keyComment = (isNode(key) && key.comment) || null;
@@ -4802,7 +4801,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
4802
4801
  const vs0 = valueStr[0];
4803
4802
  const nl0 = valueStr.indexOf('\n');
4804
4803
  const hasNewline = nl0 !== -1;
4805
- const flow = _nullishCoalesce$5(_nullishCoalesce$5(ctx.inFlow, () => ( value.flow)), () => ( value.items.length === 0));
4804
+ const flow = _nullishCoalesce$4(_nullishCoalesce$4(ctx.inFlow, () => ( value.flow)), () => ( value.items.length === 0));
4806
4805
  if (hasNewline || !flow) {
4807
4806
  let hasPropsLine = false;
4808
4807
  if (hasNewline && (vs0 === '&' || vs0 === '!')) {
@@ -4843,7 +4842,7 @@ function warn(logLevel, warning) {
4843
4842
  }
4844
4843
  }
4845
4844
 
4846
- 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; }
4845
+ 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; }
4847
4846
  // If the value associated with a merge key is a single mapping node, each of
4848
4847
  // its key/value pairs is inserted into the current mapping, unless the key
4849
4848
  // already exists in it. If the value associated with the merge key is a
@@ -4867,7 +4866,7 @@ const isMergeKey = (ctx, key) => (merge.identify(key) ||
4867
4866
  (isScalar(key) &&
4868
4867
  (!key.type || key.type === Scalar.PLAIN) &&
4869
4868
  merge.identify(key.value))) &&
4870
- _optionalChain$c([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)]);
4869
+ _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)]);
4871
4870
  function addMergeToJSMap(ctx, map, value) {
4872
4871
  value = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;
4873
4872
  if (isSeq(value))
@@ -4904,7 +4903,7 @@ function mergeValue(ctx, map, value) {
4904
4903
  return map;
4905
4904
  }
4906
4905
 
4907
- 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; }
4906
+ 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; }
4908
4907
  function addPairToJSMap(ctx, map, { key, value }) {
4909
4908
  if (isNode(key) && key.addToJSMap)
4910
4909
  key.addToJSMap(ctx, map, value);
@@ -4941,7 +4940,7 @@ function stringifyKey(key, jsKey, ctx) {
4941
4940
  // eslint-disable-next-line @typescript-eslint/no-base-to-string
4942
4941
  if (typeof jsKey !== 'object')
4943
4942
  return String(jsKey);
4944
- if (isNode(key) && _optionalChain$b([ctx, 'optionalAccess', _ => _.doc])) {
4943
+ if (isNode(key) && _optionalChain$8([ctx, 'optionalAccess', _ => _.doc])) {
4945
4944
  const strCtx = createStringifyContext(ctx.doc, {});
4946
4945
  strCtx.anchors = new Set();
4947
4946
  for (const node of ctx.anchors.keys())
@@ -4961,7 +4960,7 @@ function stringifyKey(key, jsKey, ctx) {
4961
4960
  return JSON.stringify(jsKey);
4962
4961
  }
4963
4962
 
4964
- 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; }
4963
+ 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; }
4965
4964
  function createPair(key, value, ctx) {
4966
4965
  const k = createNode(key, undefined, ctx);
4967
4966
  const v = createNode(value, undefined, ctx);
@@ -4982,19 +4981,19 @@ class Pair {
4982
4981
  return new Pair(key, value);
4983
4982
  }
4984
4983
  toJSON(_, ctx) {
4985
- const pair = _optionalChain$a([ctx, 'optionalAccess', _2 => _2.mapAsMap]) ? new Map() : {};
4984
+ const pair = _optionalChain$7([ctx, 'optionalAccess', _2 => _2.mapAsMap]) ? new Map() : {};
4986
4985
  return addPairToJSMap(ctx, pair, this);
4987
4986
  }
4988
4987
  toString(ctx, onComment, onChompKeep) {
4989
- return _optionalChain$a([ctx, 'optionalAccess', _3 => _3.doc])
4988
+ return _optionalChain$7([ctx, 'optionalAccess', _3 => _3.doc])
4990
4989
  ? stringifyPair(this, ctx, onComment, onChompKeep)
4991
4990
  : JSON.stringify(this);
4992
4991
  }
4993
4992
  }
4994
4993
 
4995
- function _nullishCoalesce$4(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }
4994
+ function _nullishCoalesce$3(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; }
4996
4995
  function stringifyCollection(collection, ctx, options) {
4997
- const flow = _nullishCoalesce$4(ctx.inFlow, () => ( collection.flow));
4996
+ const flow = _nullishCoalesce$3(ctx.inFlow, () => ( collection.flow));
4998
4997
  const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;
4999
4998
  return stringify(collection, ctx, options);
5000
4999
  }
@@ -5086,7 +5085,7 @@ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
5086
5085
  if (iv.commentBefore)
5087
5086
  reqNewline = true;
5088
5087
  }
5089
- else if (item.value == null && _optionalChain$9([ik, 'optionalAccess', _ => _.comment])) {
5088
+ else if (item.value == null && _optionalChain$6([ik, 'optionalAccess', _ => _.comment])) {
5090
5089
  comment = ik.comment;
5091
5090
  }
5092
5091
  }
@@ -5141,7 +5140,7 @@ function addCommentBefore({ indent, options: { commentString } }, lines, comment
5141
5140
  }
5142
5141
  }
5143
5142
 
5144
- function _nullishCoalesce$3(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }
5143
+ function _nullishCoalesce$2(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; }
5145
5144
  function findPair(items, key) {
5146
5145
  const k = isScalar(key) ? key.value : key;
5147
5146
  for (const it of items) {
@@ -5202,12 +5201,12 @@ class YAMLMap extends Collection {
5202
5201
  _pair = pair;
5203
5202
  else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
5204
5203
  // In TypeScript, this never happens.
5205
- _pair = new Pair(pair, _optionalChain$8([pair, 'optionalAccess', _2 => _2.value]));
5204
+ _pair = new Pair(pair, _optionalChain$5([pair, 'optionalAccess', _2 => _2.value]));
5206
5205
  }
5207
5206
  else
5208
5207
  _pair = new Pair(pair.key, pair.value);
5209
5208
  const prev = findPair(this.items, _pair.key);
5210
- const sortEntries = _optionalChain$8([this, 'access', _3 => _3.schema, 'optionalAccess', _4 => _4.sortMapEntries]);
5209
+ const sortEntries = _optionalChain$5([this, 'access', _3 => _3.schema, 'optionalAccess', _4 => _4.sortMapEntries]);
5211
5210
  if (prev) {
5212
5211
  if (!overwrite)
5213
5212
  throw new Error(`Key ${_pair.key} already set`);
@@ -5237,8 +5236,8 @@ class YAMLMap extends Collection {
5237
5236
  }
5238
5237
  get(key, keepScalar) {
5239
5238
  const it = findPair(this.items, key);
5240
- const node = _optionalChain$8([it, 'optionalAccess', _5 => _5.value]);
5241
- return _nullishCoalesce$3((!keepScalar && isScalar(node) ? node.value : node), () => ( undefined));
5239
+ const node = _optionalChain$5([it, 'optionalAccess', _5 => _5.value]);
5240
+ return _nullishCoalesce$2((!keepScalar && isScalar(node) ? node.value : node), () => ( undefined));
5242
5241
  }
5243
5242
  has(key) {
5244
5243
  return !!findPair(this.items, key);
@@ -5252,8 +5251,8 @@ class YAMLMap extends Collection {
5252
5251
  * @returns Instance of Type, Map, or Object
5253
5252
  */
5254
5253
  toJSON(_, ctx, Type) {
5255
- const map = Type ? new Type() : _optionalChain$8([ctx, 'optionalAccess', _6 => _6.mapAsMap]) ? new Map() : {};
5256
- if (_optionalChain$8([ctx, 'optionalAccess', _7 => _7.onCreate]))
5254
+ const map = Type ? new Type() : _optionalChain$5([ctx, 'optionalAccess', _6 => _6.mapAsMap]) ? new Map() : {};
5255
+ if (_optionalChain$5([ctx, 'optionalAccess', _7 => _7.onCreate]))
5257
5256
  ctx.onCreate(map);
5258
5257
  for (const item of this.items)
5259
5258
  addPairToJSMap(ctx, map, item);
@@ -5278,7 +5277,7 @@ class YAMLMap extends Collection {
5278
5277
  }
5279
5278
  }
5280
5279
 
5281
- 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; }
5280
+ 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; }
5282
5281
  class YAMLSeq extends Collection {
5283
5282
  static get tagName() {
5284
5283
  return 'tag:yaml.org,2002:seq';
@@ -5341,7 +5340,7 @@ class YAMLSeq extends Collection {
5341
5340
  }
5342
5341
  toJSON(_, ctx) {
5343
5342
  const seq = [];
5344
- if (_optionalChain$7([ctx, 'optionalAccess', _2 => _2.onCreate]))
5343
+ if (_optionalChain$4([ctx, 'optionalAccess', _2 => _2.onCreate]))
5345
5344
  ctx.onCreate(seq);
5346
5345
  let i = 0;
5347
5346
  for (const item of this.items)
@@ -5420,7 +5419,7 @@ function createPairs(schema, iterable, ctx) {
5420
5419
  return pairs;
5421
5420
  }
5422
5421
 
5423
- 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; }
5422
+ 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; }
5424
5423
  class YAMLOMap extends YAMLSeq {
5425
5424
  constructor() {
5426
5425
  super();
@@ -5439,7 +5438,7 @@ class YAMLOMap extends YAMLSeq {
5439
5438
  if (!ctx)
5440
5439
  return super.toJSON(_);
5441
5440
  const map = new Map();
5442
- if (_optionalChain$6([ctx, 'optionalAccess', _2 => _2.onCreate]))
5441
+ if (_optionalChain$3([ctx, 'optionalAccess', _2 => _2.onCreate]))
5443
5442
  ctx.onCreate(map);
5444
5443
  for (const pair of this.items) {
5445
5444
  let key, value;
@@ -5557,7 +5556,9 @@ const isDirExists = async (file) => {
5557
5556
  }
5558
5557
  };
5559
5558
 
5560
- 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; }// ABOUTME: Project type detection utility
5559
+ // ABOUTME: Project type detection utility
5560
+ // ABOUTME: Detect project type (Next.js, Vite, Nuxt, etc.) by analyzing project files
5561
+
5561
5562
 
5562
5563
  /**
5563
5564
  * 支持的项目类型枚举
@@ -5610,8 +5611,6 @@ var ProjectType; (function (ProjectType) {
5610
5611
 
5611
5612
 
5612
5613
 
5613
-
5614
-
5615
5614
 
5616
5615
 
5617
5616
 
@@ -5658,15 +5657,6 @@ const collectProjectInfo = async (
5658
5657
  }
5659
5658
  }
5660
5659
 
5661
- const scripts = Object.entries(
5662
- (_optionalChain$5([packageJson, 'optionalAccess', _ => _.scripts]) ) || {},
5663
- ).reduce((acc, [name, script]) => {
5664
- if (typeof script === 'string') {
5665
- acc[name] = script;
5666
- }
5667
- return acc;
5668
- }, {});
5669
-
5670
5660
  // 3. 检查可能的配置文件(并发检查)
5671
5661
  const configFileCandidates = [
5672
5662
  // Next.js
@@ -5700,29 +5690,13 @@ const collectProjectInfo = async (
5700
5690
  return {
5701
5691
  packageJson,
5702
5692
  dependencies,
5703
- scripts,
5704
5693
  configFiles,
5705
5694
  };
5706
5695
  };
5707
5696
 
5708
- const hasTaroDependency = (info) =>
5709
- Array.from(info.dependencies).some(
5710
- dep => dep === '@tarojs/taro' || dep.startsWith('@tarojs/'),
5711
- );
5712
-
5713
- const hasTaroConfigFile = (info) =>
5714
- info.configFiles.has('config/index.js') || info.configFiles.has('config/index.ts');
5715
-
5716
- const hasTaroScript = (info) =>
5717
- Object.entries(info.scripts).some(
5718
- ([name, script]) =>
5719
- /^(build|dev|preview):(weapp|tt|h5)$/.test(name) ||
5720
- /\btaro\s+build\b/.test(script),
5721
- );
5722
-
5723
5697
  /**
5724
5698
  * 项目类型检测规则列表
5725
- * 按优先级排序:Next.js > Nuxt > Taro > Vite > Expo
5699
+ * 按优先级排序:Next.js > Nuxt > Vite > Expo > Taro
5726
5700
  */
5727
5701
  const DETECTION_RULES = [
5728
5702
  {
@@ -5743,12 +5717,6 @@ const DETECTION_RULES = [
5743
5717
  info.configFiles.has('nuxt.config.mjs'),
5744
5718
  reason: 'Found Nuxt dependencies or config files',
5745
5719
  },
5746
- {
5747
- type: ProjectType.TARO,
5748
- check: info =>
5749
- hasTaroDependency(info) || (hasTaroConfigFile(info) && hasTaroScript(info)),
5750
- reason: 'Found Taro dependencies or config files with Taro scripts',
5751
- },
5752
5720
  {
5753
5721
  type: ProjectType.VITE,
5754
5722
  check: info =>
@@ -5764,6 +5732,15 @@ const DETECTION_RULES = [
5764
5732
  info.dependencies.has('expo') || info.dependencies.has('react-native'),
5765
5733
  reason: 'Found Expo/React Native dependencies',
5766
5734
  },
5735
+ {
5736
+ type: ProjectType.TARO,
5737
+ check: info =>
5738
+ info.dependencies.has('@tarojs/taro') ||
5739
+ info.dependencies.has('@tarojs/cli') ||
5740
+ info.configFiles.has('config/index.js') ||
5741
+ info.configFiles.has('config/index.ts'),
5742
+ reason: 'Found Taro dependencies or config files',
5743
+ },
5767
5744
  ];
5768
5745
 
5769
5746
  /**
@@ -5813,7 +5790,29 @@ const detectProjectType = async (
5813
5790
  };
5814
5791
  };
5815
5792
 
5816
- 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; }
5793
+ /**
5794
+ * 检查项目是否为指定类型
5795
+ *
5796
+ * @param projectPath - 项目根目录的绝对路径
5797
+ * @param expectedType - 期望的项目类型
5798
+ * @returns 是否匹配
5799
+ *
5800
+ * @example
5801
+ * ```typescript
5802
+ * if (await isProjectType('/path/to/project', ProjectType.NEXTJS)) {
5803
+ * console.log('This is a Next.js project');
5804
+ * }
5805
+ * ```
5806
+ */
5807
+ const isProjectType = async (
5808
+ projectPath,
5809
+ expectedType,
5810
+ ) => {
5811
+ const result = await detectProjectType(projectPath);
5812
+ return result.detected && result.type === expectedType;
5813
+ };
5814
+
5815
+ 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; }
5817
5816
 
5818
5817
 
5819
5818
  /**
@@ -5854,17 +5853,6 @@ const parseConfigContent = (content) => {
5854
5853
  return null;
5855
5854
  };
5856
5855
 
5857
- /**
5858
- * 仅按 TOML 解析 .coze
5859
- */
5860
- const parseTomlConfigContent = (content) => {
5861
- try {
5862
- return toml.parse(content) ;
5863
- } catch (e) {
5864
- return null;
5865
- }
5866
- };
5867
-
5868
5856
  /**
5869
5857
  * 加载 .coze 配置文件
5870
5858
  *
@@ -5898,80 +5886,6 @@ const loadCozeConfig = async (
5898
5886
  return config;
5899
5887
  };
5900
5888
 
5901
- /**
5902
- * 读取 TOML 格式的 .coze 配置
5903
- */
5904
- const loadTomlCozeConfig = async (
5905
- projectPath = process.cwd(),
5906
- ) => {
5907
- const cozeConfigPath = path.join(projectPath, '.coze');
5908
-
5909
- let content;
5910
- try {
5911
- content = await fs$1.readFile(cozeConfigPath, 'utf-8');
5912
- } catch (error) {
5913
- throw new Error(
5914
- `.coze config file not found in ${projectPath}\n` +
5915
- 'Please ensure you are in a project directory initialized with coze-coding.\n' +
5916
- `Error: ${error instanceof Error ? error.message : String(error)}`,
5917
- );
5918
- }
5919
-
5920
- const config = parseTomlConfigContent(content);
5921
- if (!config) {
5922
- throw new Error(
5923
- 'Failed to parse .coze config file as TOML.\n' +
5924
- 'Please ensure the file is valid TOML format.',
5925
- );
5926
- }
5927
-
5928
- return config;
5929
- };
5930
-
5931
- /**
5932
- * 将 .coze 配置写回 TOML 文件
5933
- */
5934
- const saveTomlCozeConfig = async (
5935
- config,
5936
- projectPath = process.cwd(),
5937
- ) => {
5938
- const cozeConfigPath = path.join(projectPath, '.coze');
5939
- const tempCozeConfigPath = path.join(
5940
- projectPath,
5941
- `.coze.tmp-${process.pid}-${Date.now()}`,
5942
- );
5943
- const content = toml.stringify(config );
5944
-
5945
- try {
5946
- await fs$1.writeFile(tempCozeConfigPath, content, 'utf-8');
5947
- await fs$1.rename(tempCozeConfigPath, cozeConfigPath);
5948
- } catch (error) {
5949
- await fs$1.rm(tempCozeConfigPath, { force: true }).catch(() => undefined);
5950
- throw error;
5951
- }
5952
- };
5953
-
5954
- /**
5955
- * 更新项目 patch 元数据并写回 .coze
5956
- */
5957
- const saveProjectPatchState = async (
5958
- projectPath,
5959
- state
5960
-
5961
-
5962
-
5963
- ,
5964
- ) => {
5965
- const config = await loadTomlCozeConfig(projectPath);
5966
- config.project = {
5967
- ...(config.project || {}),
5968
- template: state.template,
5969
- version: state.version,
5970
- appliedPatches: state.appliedPatches,
5971
- };
5972
- await saveTomlCozeConfig(config, projectPath);
5973
- };
5974
-
5975
5889
  /**
5976
5890
  * 获取指定命令的配置
5977
5891
  *
@@ -5988,13 +5902,13 @@ const getCommandConfig = (
5988
5902
  // 根据命令名称映射到配置路径
5989
5903
  switch (commandName) {
5990
5904
  case 'dev':
5991
- commandConfig = _optionalChain$4([config, 'access', _ => _.dev, 'optionalAccess', _2 => _2.run]);
5905
+ commandConfig = _optionalChain$2([config, 'access', _ => _.dev, 'optionalAccess', _2 => _2.run]);
5992
5906
  break;
5993
5907
  case 'build':
5994
- commandConfig = _optionalChain$4([config, 'access', _3 => _3.deploy, 'optionalAccess', _4 => _4.build]);
5908
+ commandConfig = _optionalChain$2([config, 'access', _3 => _3.deploy, 'optionalAccess', _4 => _4.build]);
5995
5909
  break;
5996
5910
  case 'start':
5997
- commandConfig = _optionalChain$4([config, 'access', _5 => _5.deploy, 'optionalAccess', _6 => _6.run]);
5911
+ commandConfig = _optionalChain$2([config, 'access', _5 => _5.deploy, 'optionalAccess', _6 => _6.run]);
5998
5912
  break;
5999
5913
  default:
6000
5914
  throw new Error(`Unknown command: ${commandName}`);
@@ -6010,341 +5924,251 @@ const getCommandConfig = (
6010
5924
  return commandConfig;
6011
5925
  };
6012
5926
 
6013
- const isDirectoryEmpty = async (projectPath) =>
6014
- (await fs$1.readdir(projectPath)).length === 0;
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
6015
5930
 
6016
- const detectTemplateKey = async (
6017
- projectPath,
6018
- ) => {
6019
- const result = await detectProjectType(projectPath);
6020
- if (!result.detected) {
6021
- return null;
6022
- }
6023
5931
 
6024
- switch (result.type) {
6025
- case ProjectType.NEXTJS:
6026
- return 'nextjs';
6027
- case ProjectType.VITE:
6028
- return 'vite';
6029
- case ProjectType.NUXT:
6030
- return 'nuxt-vue';
6031
- case ProjectType.EXPO:
6032
- return 'expo';
6033
- case ProjectType.TARO:
6034
- return 'taro';
6035
- default:
6036
- return null;
6037
- }
6038
- };
6039
5932
 
6040
- 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; }
5933
+ const debug$1 = debug$2('coze-init:fix');
6041
5934
 
5935
+ /**
5936
+ * 需要应用此修复的项目类型
5937
+ */
5938
+ const SUPPORTED_PROJECT_TYPES = [
5939
+ ProjectType.NEXTJS,
5940
+ ProjectType.VITE,
5941
+ ProjectType.NUXT,
5942
+ ] ;
6042
5943
 
6043
- const PATCH_ID$2 = 'taro/update-pack-script-for-tt-build@0.0.13';
6044
- const PACKAGE_JSON_FILE = 'package.json';
6045
- const PACK_SCRIPT_FILE = '.cozeproj/scripts/pack.sh';
6046
- const LEGACY_PACK_SCRIPT_HASHES = new Set([
6047
- '987575c08e1c32ce7bc553e1668b3ad8faad5623343fd0d21fea34d39f25a56d',
6048
- '5e1a1a745f165b09717ffa4b83caac19d03e79e42b273cdd5532df58ac08625d',
6049
- ]);
6050
- const TARGET_PACK_SCRIPT = `# pack.sh - 通过 PID 文件精确杀掉自己上次的构建进程
6051
- WEAPP_PID_FILE="/tmp/coze-build_weapp.pid"
6052
- TT_PID_FILE="/tmp/coze-build_tt.pid"
6053
-
6054
- cleanup_previous_build() {
6055
- PID_FILE="$1"
6056
- BUILD_NAME="$2"
6057
-
6058
- if [ -f "$PID_FILE" ]; then
6059
- OLD_PID=$(cat "$PID_FILE")
6060
- if kill -0 "$OLD_PID" 2>/dev/null; then
6061
- echo "正在终止上次的 \${BUILD_NAME} 构建进程组 (PID: $OLD_PID)..."
6062
- # kill 负数 PID = 杀掉整个进程组
6063
- kill -9 -"$OLD_PID" 2>/dev/null
6064
- sleep 1
6065
- fi
6066
- rm -f "$PID_FILE"
6067
- fi
6068
- }
5944
+ /**
5945
+ * 需要处理的脚本文件列表
5946
+ */
5947
+ const SCRIPT_FILES = ['dev.sh', 'build.sh'] ;
6069
5948
 
6070
- cleanup_previous_build "$WEAPP_PID_FILE" "weapp"
6071
- cleanup_previous_build "$TT_PID_FILE" "tt"
5949
+ /**
5950
+ * 脚本文件修改结果
5951
+ */
6072
5952
 
6073
- setsid sh -c 'export OUTPUT_ROOT=dist; pnpm build:weapp' &
6074
- WEAPP_PID=$!
6075
- echo "$WEAPP_PID" > "$WEAPP_PID_FILE"
6076
5953
 
6077
- setsid sh -c 'export OUTPUT_ROOT=dist-tt; pnpm build:tt' &
6078
- TT_PID=$!
6079
- echo "$TT_PID" > "$TT_PID_FILE"
6080
5954
 
6081
- echo "构建已并发启动 (weapp PID: $WEAPP_PID, tt PID: $TT_PID)"
6082
5955
 
6083
- WEAPP_STATUS=0
6084
- TT_STATUS=0
6085
5956
 
6086
- wait "$WEAPP_PID" || WEAPP_STATUS=$?
6087
- wait "$TT_PID" || TT_STATUS=$?
6088
5957
 
6089
- rm -f "$WEAPP_PID_FILE" "$TT_PID_FILE"
6090
5958
 
6091
- if [ "$WEAPP_STATUS" -ne 0 ]; then
6092
- exit "$WEAPP_STATUS"
6093
- fi
6094
5959
 
6095
- if [ "$TT_STATUS" -ne 0 ]; then
6096
- exit "$TT_STATUS"
6097
- fi
6098
- `;
6099
5960
 
6100
5961
 
6101
5962
 
6102
5963
 
6103
5964
 
6104
- const getProjectPackScriptPath = (projectFolder) =>
6105
- path.join(projectFolder, PACK_SCRIPT_FILE);
6106
5965
 
6107
- const hashContent = (content) =>
6108
- crypto.createHash('sha256').update(content).digest('hex');
6109
5966
 
6110
- const readPackageScripts = async (
6111
- projectFolder,
5967
+
5968
+
5969
+
5970
+
5971
+ /**
5972
+ * 替换 shell 脚本中的 npx 为 pnpm
5973
+ */
5974
+ const replaceNpxInShellScript = async (
5975
+ scriptPath,
6112
5976
  ) => {
6113
- const packageJsonPath = path.join(projectFolder, PACKAGE_JSON_FILE);
6114
- if (!(await isFileExists(packageJsonPath))) {
6115
- return null;
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
+ }
6116
6014
  }
6117
6015
 
6118
- const packageJsonContent = await fs$1.readFile(packageJsonPath, 'utf-8');
6119
- const packageJson = safeJsonParse(packageJsonContent, null);
6016
+ if (hasChanges) {
6017
+ debug$1(`Writing changes to ${scriptPath}`);
6018
+ const newContent = modifiedLines.join('\n');
6019
+ await fs$1.writeFile(scriptPath, newContent, 'utf-8');
6020
+ } else {
6021
+ debug$1(`No changes needed for ${scriptPath}`);
6022
+ }
6120
6023
 
6121
- return _optionalChain$3([packageJson, 'optionalAccess', _ => _.scripts]) || null;
6024
+ return { modified: hasChanges, from: fromLines, to: toLines };
6122
6025
  };
6123
6026
 
6124
- const hasBuildTtScript = async (projectFolder) => {
6125
- const scripts = await readPackageScripts(projectFolder);
6126
- return typeof _optionalChain$3([scripts, 'optionalAccess', _2 => _2['build:tt']]) === 'string';
6127
- };
6027
+ /**
6028
+ * 替换项目脚本目录中的 npx 为 pnpm
6029
+ */
6030
+ const replaceNpxWithPnpm = async (
6031
+ projectFolder,
6032
+ ) => {
6033
+ const scriptsDir = path.join(projectFolder, 'scripts');
6034
+ debug$1(`Checking scripts directory: ${scriptsDir}`);
6128
6035
 
6129
- const hasLegacyPackScript = async (projectFolder) => {
6130
- const packScriptPath = getProjectPackScriptPath(projectFolder);
6131
- if (!(await isFileExists(packScriptPath))) {
6132
- return false;
6036
+ const changedFiles = [];
6037
+
6038
+ // 检查 scripts 目录是否存在
6039
+ const scriptsDirExists = await isDirExists(scriptsDir);
6040
+ debug$1(`Scripts directory exists: ${scriptsDirExists}`);
6041
+
6042
+ if (!scriptsDirExists) {
6043
+ return { modified: false, changedFiles: [] };
6133
6044
  }
6134
6045
 
6135
- const content = await fs$1.readFile(packScriptPath, 'utf-8');
6136
- return LEGACY_PACK_SCRIPT_HASHES.has(hashContent(content));
6137
- };
6046
+ // 处理每个脚本文件
6047
+ for (const fileName of SCRIPT_FILES) {
6048
+ const scriptPath = path.join(scriptsDir, fileName);
6049
+ debug$1(`Checking script file: ${scriptPath}`);
6138
6050
 
6139
- const patchTaroPackScript = {
6140
- id: PATCH_ID$2,
6141
- template: 'taro',
6142
- operations: [
6143
- {
6144
- kind: 'file-patch',
6145
- file: PACK_SCRIPT_FILE,
6146
- description:
6147
- 'Update legacy taro pack script to build weapp and tt outputs',
6148
- },
6149
- ],
6150
- shouldApply: async context =>
6151
- context.template === 'taro' &&
6152
- (await hasBuildTtScript(context.projectFolder)) &&
6153
- (await hasLegacyPackScript(context.projectFolder)),
6154
- apply: async (context) => {
6155
- if (context.template !== 'taro') {
6156
- return {
6157
- applied: false,
6158
- patchId: PATCH_ID$2,
6159
- message: 'Only applies to taro projects, skipping',
6160
- };
6161
- }
6051
+ const exists = await isFileExists(scriptPath);
6052
+ debug$1(` File exists: ${exists}`);
6162
6053
 
6163
- if (!(await hasBuildTtScript(context.projectFolder))) {
6164
- return {
6165
- applied: false,
6166
- patchId: PATCH_ID$2,
6167
- message: 'package.json does not contain build:tt, skipping',
6168
- };
6054
+ if (!exists) {
6055
+ continue;
6169
6056
  }
6170
6057
 
6171
- if (!(await hasLegacyPackScript(context.projectFolder))) {
6172
- return {
6173
- applied: false,
6174
- patchId: PATCH_ID$2,
6175
- message: 'pack.sh does not match legacy template hash, skipping',
6176
- };
6058
+ try {
6059
+ const result = await replaceNpxInShellScript(scriptPath);
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
+ );
6177
6074
  }
6075
+ }
6178
6076
 
6179
- const targetPath = getProjectPackScriptPath(context.projectFolder);
6180
- await fs$1.writeFile(targetPath, TARGET_PACK_SCRIPT, 'utf-8');
6181
-
6182
- logger.info(
6183
- `Patched ${PACK_SCRIPT_FILE}: updated taro multi-target pack script`,
6184
- );
6077
+ debug$1(`Total files modified: ${changedFiles.length}`);
6185
6078
 
6186
- return {
6187
- applied: true,
6188
- patchId: PATCH_ID$2,
6189
- message: 'Updated legacy pack.sh to build weapp and tt targets',
6190
- };
6191
- },
6079
+ return {
6080
+ modified: changedFiles.length > 0,
6081
+ changedFiles,
6082
+ };
6192
6083
  };
6193
6084
 
6194
- const PATCH_ID$1 = 'taro/add-agents-md@0.0.13';
6195
- const AGENTS_FILE = 'AGENTS.md';
6196
- const getTemplateAgentsPath = () =>
6197
- path.join(getTemplatesDir(), 'taro', AGENTS_FILE);
6198
-
6199
- const getProjectAgentsPath = (projectFolder) =>
6200
- path.join(projectFolder, AGENTS_FILE);
6201
-
6202
- const readTemplateAgentsContent = async () =>
6203
- fs$1.readFile(getTemplateAgentsPath(), 'utf-8');
6204
-
6205
- const patchTaroAgentsMd = {
6206
- id: PATCH_ID$1,
6207
- template: 'taro',
6208
- operations: [
6209
- {
6210
- kind: 'create-file',
6211
- file: AGENTS_FILE,
6212
- description:
6213
- 'Add template AGENTS.md to taro projects that do not have one',
6214
- },
6215
- ],
6216
- shouldApply: async context =>
6217
- context.template === 'taro' &&
6218
- !(await isFileExists(getProjectAgentsPath(context.projectFolder))),
6219
- apply: async (context) => {
6220
- if (context.template !== 'taro') {
6221
- return {
6222
- applied: false,
6223
- patchId: PATCH_ID$1,
6224
- message: 'Only applies to taro projects, skipping',
6225
- };
6226
- }
6085
+ /**
6086
+ * Fix 规则:将 scripts/ 目录下的 shell 脚本中的 npx 命令替换为 pnpm
6087
+ *
6088
+ * 背景:在某些项目类型(Next.js、Vite、Nuxt)中,使用 npx 可能会导致模块解析问题。
6089
+ * 将 npx 替换为 pnpm 可以确保使用项目本地安装的依赖,避免版本冲突和解析错误。
6090
+ */
6091
+ const fixReplaceNpxWithPnpm = async context => {
6092
+ const ruleName = 'replace-npx-with-pnpm';
6227
6093
 
6228
- const targetPath = getProjectAgentsPath(context.projectFolder);
6229
- if (await isFileExists(targetPath)) {
6230
- return {
6231
- applied: false,
6232
- patchId: PATCH_ID$1,
6233
- message: 'AGENTS.md already exists, skipping',
6234
- };
6235
- }
6094
+ debug$1(`Starting fix rule: ${ruleName}`);
6095
+ debug$1(`Project folder: ${context.projectFolder}`);
6236
6096
 
6237
- const templateContent = await readTemplateAgentsContent();
6238
- await fs$1.writeFile(targetPath, templateContent, 'utf-8');
6097
+ // 1. 检测项目类型
6098
+ const projectDetection = await detectProjectType(context.projectFolder);
6099
+ debug$1(`Project detection result: ${JSON.stringify(projectDetection)}`);
6239
6100
 
6101
+ if (!projectDetection.detected) {
6240
6102
  return {
6241
- applied: true,
6242
- patchId: PATCH_ID$1,
6243
- message: 'Created AGENTS.md from taro template',
6103
+ ruleName,
6104
+ applied: false,
6105
+ message: 'Project type not detected, skipping',
6244
6106
  };
6245
- },
6246
- };
6247
-
6248
- const SCRIPT_FILES = ['dev.sh', 'build.sh'] ;
6249
- const SUPPORTED_TEMPLATES = new Set(['nextjs', 'vite', 'nuxt-vue']);
6250
-
6251
- const hasNpxInScripts = async (projectFolder) => {
6252
- const scriptsDir = path.join(projectFolder, 'scripts');
6253
- if (!(await isDirExists(scriptsDir))) {
6254
- return false;
6255
6107
  }
6256
6108
 
6257
- for (const fileName of SCRIPT_FILES) {
6258
- const scriptPath = path.join(scriptsDir, fileName);
6259
- if (!(await isFileExists(scriptPath))) {
6260
- continue;
6261
- }
6109
+ // 2. 检查是否为支持的项目类型
6110
+ const isSupportedType = (
6111
+ SUPPORTED_PROJECT_TYPES
6112
+ ).includes(projectDetection.type);
6262
6113
 
6263
- const content = await fs$1.readFile(scriptPath, 'utf-8');
6264
- if (/\bnpx\s+/.test(content)) {
6265
- return true;
6266
- }
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
+ };
6267
6123
  }
6268
6124
 
6269
- return false;
6270
- };
6125
+ logger.info(`Detected ${projectDetection.type} project`);
6271
6126
 
6272
- const applyReplaceNpxWithPnpm = async (
6273
- context,
6274
- patchId,
6275
- ) => {
6276
- const scriptsDir = path.join(context.projectFolder, 'scripts');
6277
- let changedFiles = 0;
6127
+ // 3. 执行替换
6128
+ debug$1('Starting npx replacement...');
6129
+ const replaceResult = await replaceNpxWithPnpm(context.projectFolder);
6278
6130
 
6279
- if (!(await isDirExists(scriptsDir))) {
6131
+ if (!replaceResult.modified) {
6280
6132
  return {
6133
+ ruleName,
6281
6134
  applied: false,
6282
- patchId,
6283
- message: 'scripts directory not found, skipping',
6135
+ message: 'No npx commands found in shell scripts, skipping',
6284
6136
  };
6285
6137
  }
6286
6138
 
6287
- for (const fileName of SCRIPT_FILES) {
6288
- const scriptPath = path.join(scriptsDir, fileName);
6289
- if (!(await isFileExists(scriptPath))) {
6290
- continue;
6291
- }
6139
+ // 4. 输出修改信息
6140
+ logger.success(
6141
+ `Replaced npx with pnpm in ${replaceResult.changedFiles.length} file(s)`,
6142
+ );
6292
6143
 
6293
- const content = await fs$1.readFile(scriptPath, 'utf-8');
6294
- const nextContent = content.replace(/\bnpx\s+/g, 'pnpm ');
6295
- if (nextContent === content) {
6296
- continue;
6144
+ for (const file of replaceResult.changedFiles) {
6145
+ logger.info(` scripts/${file.fileName}:`);
6146
+ for (let i = 0; i < file.from.length; i++) {
6147
+ logger.info(` - ${file.from[i]}`);
6148
+ logger.info(` + ${file.to[i]}`);
6297
6149
  }
6298
-
6299
- await fs$1.writeFile(scriptPath, nextContent, 'utf-8');
6300
- changedFiles++;
6301
- logger.info(`Patched scripts/${fileName}: replaced npx with pnpm`);
6302
6150
  }
6303
6151
 
6304
6152
  return {
6305
- applied: changedFiles > 0,
6306
- patchId,
6307
- message:
6308
- changedFiles > 0
6309
- ? `Replaced npx with pnpm in ${changedFiles} file(s)`
6310
- : 'No npx commands found in shell scripts, skipping',
6153
+ ruleName,
6154
+ applied: true,
6155
+ message: `Successfully replaced npx with pnpm in ${replaceResult.changedFiles.length} file(s)`,
6311
6156
  };
6312
6157
  };
6313
6158
 
6314
- const createReplaceNpxWithPnpmPatch = (
6315
- template,
6316
- ) => ({
6317
- id: `${template}/replace-npx-with-pnpm@0.0.13`,
6318
- template,
6319
- operations: [
6320
- {
6321
- kind: 'file-patch',
6322
- file: 'scripts/dev.sh',
6323
- description: 'Replace npx with pnpm in shell scripts',
6324
- },
6325
- {
6326
- kind: 'file-patch',
6327
- file: 'scripts/build.sh',
6328
- description: 'Replace npx with pnpm in shell scripts',
6329
- },
6330
- ],
6331
- shouldApply: async context =>
6332
- SUPPORTED_TEMPLATES.has(context.template) &&
6333
- (await hasNpxInScripts(context.projectFolder)),
6334
- apply: async context =>
6335
- applyReplaceNpxWithPnpm(
6336
- context,
6337
- `${template}/replace-npx-with-pnpm@0.0.10`,
6338
- ),
6339
- });
6159
+ // ABOUTME: Fix rule to comment out problematic outputFileTracingRoot config in Next.js projects
6160
+ // ABOUTME: This config can cause issues in monorepo environments and should be removed
6340
6161
 
6341
- const replaceNpxWithPnpmPatchNextjs =
6342
- createReplaceNpxWithPnpmPatch('nextjs');
6343
- const replaceNpxWithPnpmPatchVite =
6344
- createReplaceNpxWithPnpmPatch('vite');
6345
- const replaceNpxWithPnpmPatchNuxtVue =
6346
- createReplaceNpxWithPnpmPatch('nuxt-vue');
6347
6162
 
6163
+ /**
6164
+ * 检查是否为 Next.js 项目
6165
+ */
6166
+ const isNextProject = async (projectFolder) =>
6167
+ isProjectType(projectFolder, ProjectType.NEXTJS);
6168
+
6169
+ /**
6170
+ * 查找 Next.js 配置文件
6171
+ */
6348
6172
  const findNextConfigFile = async (
6349
6173
  projectFolder,
6350
6174
  ) => {
@@ -6364,265 +6188,221 @@ const findNextConfigFile = async (
6364
6188
  return null;
6365
6189
  };
6366
6190
 
6367
- const getUncommentedTracingRootLine = async (
6191
+ /**
6192
+ * 注释掉 outputFileTracingRoot 配置
6193
+ */
6194
+ const commentOutOutputTracingRoot = async (
6368
6195
  configPath,
6369
6196
  ) => {
6370
- const content = await fs$1.readFile(configPath, 'utf-8');
6197
+ let content = await fs$1.readFile(configPath, 'utf-8');
6198
+ let modified = false;
6199
+ let originalLine = null;
6200
+
6201
+ // 匹配包含 outputFileTracingRoot 的行(尚未被注释的)
6202
+ // 支持 path.resolve(...) 后面有空格,然后可选逗号
6203
+ // 只匹配单行配置,不匹配跨多行的配置
6371
6204
  const pattern =
6372
6205
  /^(\s*)(outputFileTracingRoot:\s*path\.resolve\([^\n\r)]+\)\s*,?)\s*$/gm;
6373
6206
 
6374
6207
  const matches = content.match(pattern);
6375
- return matches && matches.length > 0 ? matches[0].trim() : null;
6376
- };
6377
6208
 
6378
- const commentOutOutputTracingRoot = async (
6379
- configPath,
6380
- ) => {
6381
- const content = await fs$1.readFile(configPath, 'utf-8');
6382
- const pattern =
6383
- /^(\s*)(outputFileTracingRoot:\s*path\.resolve\([^\n\r)]+\)\s*,?)\s*$/gm;
6384
- const matches = content.match(pattern);
6209
+ if (matches && matches.length > 0) {
6210
+ originalLine = matches[0].trim();
6385
6211
 
6386
- if (!matches || matches.length === 0) {
6387
- return null;
6212
+ // 在匹配的行前添加 // 注释
6213
+ content = content.replace(pattern, '$1// $2');
6214
+ modified = true;
6215
+
6216
+ await fs$1.writeFile(configPath, content, 'utf-8');
6388
6217
  }
6389
6218
 
6390
- const originalLine = matches[0].trim();
6391
- const nextContent = content.replace(pattern, '$1// $2');
6392
- await fs$1.writeFile(configPath, nextContent, 'utf-8');
6393
- return originalLine;
6219
+ return { modified, originalLine };
6394
6220
  };
6395
6221
 
6396
- const PATCH_ID = 'nextjs/next-output-tracing-root@0.0.13';
6222
+ /**
6223
+ * Fix 规则:注释掉 Next.js 项目中的 outputFileTracingRoot 配置
6224
+ * 这个配置在 monorepo 环境中可能会导致问题
6225
+ */
6226
+ const fixNextOutputTracingRoot = async context => {
6227
+ const ruleName = 'next-output-tracing-root';
6397
6228
 
6398
- const patchNextOutputTracingRoot = {
6399
- id: PATCH_ID,
6400
- template: 'nextjs',
6401
- operations: [
6402
- {
6403
- kind: 'file-patch',
6404
- file: 'next.config.ts',
6405
- description: 'Comment out problematic outputFileTracingRoot config',
6406
- },
6407
- ],
6408
- shouldApply: async context => {
6409
- if (context.template !== 'nextjs') {
6410
- return false;
6411
- }
6229
+ // 1. 检查是否为 Next.js 项目
6230
+ if (!(await isNextProject(context.projectFolder))) {
6231
+ return {
6232
+ ruleName,
6233
+ applied: false,
6234
+ message: 'Not a Next.js project, skipping',
6235
+ };
6236
+ }
6412
6237
 
6413
- const configPath = await findNextConfigFile(context.projectFolder);
6414
- if (!configPath) {
6415
- return false;
6416
- }
6238
+ // 2. 查找 Next.js 配置文件
6239
+ const configPath = await findNextConfigFile(context.projectFolder);
6417
6240
 
6418
- return (await getUncommentedTracingRootLine(configPath)) !== null;
6419
- },
6420
- apply: async (context) => {
6421
- const configPath = await findNextConfigFile(context.projectFolder);
6422
- if (!configPath) {
6423
- return {
6424
- applied: false,
6425
- patchId: PATCH_ID,
6426
- message: 'Next.js config file not found, skipping',
6427
- };
6428
- }
6241
+ if (!configPath) {
6242
+ return {
6243
+ ruleName,
6244
+ applied: false,
6245
+ message: 'Next.js config file not found, skipping',
6246
+ };
6247
+ }
6429
6248
 
6430
- const originalLine = await commentOutOutputTracingRoot(configPath);
6431
- if (!originalLine) {
6432
- return {
6433
- applied: false,
6434
- patchId: PATCH_ID,
6435
- message: 'No outputFileTracingRoot config found, skipping',
6436
- };
6437
- }
6249
+ // 3. 注释掉 outputFileTracingRoot 配置
6250
+ const { modified, originalLine } =
6251
+ await commentOutOutputTracingRoot(configPath);
6438
6252
 
6439
- logger.info(
6440
- `Patched ${configPath.split('/').pop()}: commented out ${originalLine}`,
6253
+ if (modified && originalLine) {
6254
+ logger.success(
6255
+ `Commented out outputFileTracingRoot in ${configPath.split('/').pop()}`,
6441
6256
  );
6257
+ logger.info(` Original: ${originalLine}`);
6442
6258
 
6443
6259
  return {
6260
+ ruleName,
6444
6261
  applied: true,
6445
- patchId: PATCH_ID,
6446
6262
  message: `Successfully commented out: ${originalLine}`,
6447
6263
  };
6448
- },
6449
- };
6450
-
6451
- const patches = [
6452
- replaceNpxWithPnpmPatchNextjs,
6453
- replaceNpxWithPnpmPatchVite,
6454
- replaceNpxWithPnpmPatchNuxtVue,
6455
- patchNextOutputTracingRoot,
6456
- patchTaroAgentsMd,
6457
- patchTaroPackScript,
6458
- ] ;
6459
-
6460
- const getTemplatePatches = (
6461
- template,
6462
- ) =>
6463
- patches.filter(patch => patch.template === template);
6464
-
6465
- 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; }
6466
- const DEFAULT_LEGACY_VERSION = 'legacy';
6467
-
6468
- const loadExistingTomlConfig = async (
6469
- projectFolder,
6470
- ) => {
6471
- try {
6472
- await fs$1.access(path.resolve(projectFolder, '.coze'));
6473
- } catch (e) {
6474
- return null;
6475
6264
  }
6476
6265
 
6477
- return loadTomlCozeConfig(projectFolder);
6266
+ return {
6267
+ ruleName,
6268
+ applied: false,
6269
+ message: 'No outputFileTracingRoot config found, skipping',
6270
+ };
6478
6271
  };
6479
6272
 
6480
- const writePatchState = async (
6481
- projectFolder,
6482
- config,
6483
- state
6484
-
6485
-
6486
-
6487
- ,
6488
- ) => {
6489
- config.project = {
6490
- ...(config.project || {}),
6491
- template: state.template,
6492
- version: state.version,
6493
- appliedPatches: state.appliedPatches,
6494
- };
6273
+ /**
6274
+ * 所有修复规则的数组
6275
+ * 按顺序执行,新增规则直接添加到数组中
6276
+ */
6277
+ const rules = [
6278
+ // Package manager fixes (should run first)
6279
+ fixReplaceNpxWithPnpm,
6495
6280
 
6496
- await saveTomlCozeConfig(config, projectFolder);
6497
- };
6281
+ // Next.js related fixes
6282
+ fixNextOutputTracingRoot,
6498
6283
 
6499
- const getNextPatchState = (
6500
- config,
6501
- template,
6502
- appliedPatches,
6503
- patchId,
6284
+ // Add more rules here
6285
+ ] ;
6504
6286
 
6287
+ // ABOUTME: Fix command for resolving legacy issues from previous project versions
6288
+ // ABOUTME: Applies a series of fix rules defined in the fix-rules directory
6505
6289
 
6506
6290
 
6291
+ const debug = debug$2('coze-init:fix');
6507
6292
 
6508
- ) => ({
6509
- template,
6510
- version: _optionalChain$2([config, 'access', _ => _.project, 'optionalAccess', _2 => _2.version]) || DEFAULT_LEGACY_VERSION,
6511
- appliedPatches: [...appliedPatches, patchId],
6512
- });
6293
+ const JSON_INDENT_SPACES = 2;
6513
6294
 
6514
- const executePatch = async (
6295
+ // start_aigc
6296
+ /**
6297
+ * 执行 fix 命令的内部实现
6298
+ */
6299
+ const executeFix = async (
6515
6300
  options = {},
6516
6301
  ) => {
6517
- const cwd = process.cwd();
6518
- const projectFolder = options.directory
6519
- ? path.resolve(cwd, options.directory)
6520
- : cwd;
6521
-
6522
- if (await isDirectoryEmpty(projectFolder)) {
6523
- logger.info(`Patch skipped: ${projectFolder} is empty`);
6524
- return;
6525
- }
6302
+ try {
6303
+ const cwd = process.cwd();
6304
+ const projectFolder = options.directory
6305
+ ? path.resolve(cwd, options.directory)
6306
+ : cwd;
6526
6307
 
6527
- const config = await loadExistingTomlConfig(projectFolder);
6528
- if (!config) {
6529
- logger.info('Patch skipped: .coze file not found');
6530
- return;
6531
- }
6308
+ logger.info(`Running fix command on: ${projectFolder}`);
6309
+ debug(`Current working directory: ${cwd}`);
6310
+ logger.info(`Found ${rules.length} fix rule(s) to apply\n`);
6532
6311
 
6533
- const template =
6534
- _optionalChain$2([config, 'access', _3 => _3.project, 'optionalAccess', _4 => _4.template]) || (await detectTemplateKey(projectFolder));
6312
+ const context = {
6313
+ cwd,
6314
+ projectFolder,
6315
+ };
6535
6316
 
6536
- if (!template) {
6537
- logger.info('Patch skipped: template not detected');
6538
- return;
6539
- }
6317
+ debug(
6318
+ `Fix context: ${JSON.stringify(context, null, JSON_INDENT_SPACES)}\n`,
6319
+ );
6540
6320
 
6541
- const appliedPatches = [...(_optionalChain$2([config, 'access', _5 => _5.project, 'optionalAccess', _6 => _6.appliedPatches]) || [])];
6542
- const projectVersion = _optionalChain$2([config, 'access', _7 => _7.project, 'optionalAccess', _8 => _8.version]);
6321
+ let appliedCount = 0;
6322
+ let skippedCount = 0;
6323
+ let errorCount = 0;
6543
6324
 
6544
- const context = {
6545
- cwd,
6546
- projectFolder,
6547
- template,
6548
- projectVersion,
6549
- appliedPatches,
6550
- cozeConfig: config,
6551
- };
6325
+ // 依次执行所有修复规则
6326
+ for (let i = 0; i < rules.length; i++) {
6327
+ const rule = rules[i];
6328
+ const ruleNumber = i + 1;
6552
6329
 
6553
- const candidatePatches = getTemplatePatches(template).filter(
6554
- patch => patch.disabled !== true && !appliedPatches.includes(patch.id),
6555
- );
6330
+ try {
6331
+ debug(`[${ruleNumber}/${rules.length}] Starting rule execution...`);
6556
6332
 
6557
- const matchedPatches = [];
6558
- for (const patch of candidatePatches) {
6559
- if (await patch.shouldApply(context)) {
6560
- matchedPatches.push(patch);
6561
- }
6562
- }
6333
+ const startTime = Date.now();
6334
+ const result = await Promise.resolve(rule(context));
6335
+ const duration = Date.now() - startTime;
6563
6336
 
6564
- if (matchedPatches.length === 0) {
6565
- logger.info('No patch matched current project state');
6566
- return;
6567
- }
6337
+ debug(`Rule execution completed in ${duration}ms`);
6338
+ debug(`Result: ${JSON.stringify(result, null, JSON_INDENT_SPACES)}`);
6568
6339
 
6569
- if (options.dryRun) {
6570
- logger.info(`Detected template: ${template}`);
6571
- logger.info(`Current version: ${_nullishCoalesce$2(projectVersion, () => ( DEFAULT_LEGACY_VERSION))}`);
6572
- logger.info(`Applied patches: ${appliedPatches.join(', ') || '(none)'}`);
6573
- logger.info('Matched patches:');
6574
- matchedPatches.forEach(patch => {
6575
- logger.info(` - ${patch.id}`);
6576
- patch.operations.forEach(operation => {
6577
- if ('file' in operation) {
6578
- logger.info(
6579
- ` ${operation.kind}: ${operation.file} - ${operation.description}`,
6580
- );
6340
+ if (result.applied) {
6341
+ appliedCount++;
6342
+ logger.success(`✓ ${result.ruleName}: ${result.message}`);
6581
6343
  } else {
6582
- logger.info(` ${operation.kind}: ${operation.description}`);
6344
+ skippedCount++;
6345
+ logger.info(`○ ${result.ruleName}: ${result.message}`);
6583
6346
  }
6584
- });
6585
- });
6586
- return;
6587
- }
6588
6347
 
6589
- for (const patch of matchedPatches) {
6590
- const result = await patch.apply({
6591
- ...context,
6592
- appliedPatches,
6593
- });
6348
+ debug(''); // Empty line for readability
6349
+ } catch (error) {
6350
+ errorCount++;
6351
+ const errorMessage =
6352
+ error instanceof Error ? error.message : String(error);
6353
+ logger.error(`✗ Rule execution failed: ${errorMessage}`);
6594
6354
 
6595
- if (!result.applied) {
6596
- logger.info(`○ ${patch.id}: ${result.message}`);
6597
- continue;
6355
+ // 输出详细的错误堆栈信息(仅在 debug 模式下)
6356
+ if (error instanceof Error && error.stack) {
6357
+ debug(`Error stack trace:\n${error.stack}`);
6358
+ }
6359
+
6360
+ debug(''); // Empty line for readability
6361
+ }
6598
6362
  }
6599
6363
 
6600
- const nextState = getNextPatchState(
6601
- config,
6602
- template,
6603
- appliedPatches,
6604
- patch.id,
6364
+ // 输出汇总信息
6365
+ debug('\n=== Fix Command Summary ===');
6366
+ logger.info(
6367
+ `\nSummary: ${appliedCount} fixed, ${skippedCount} skipped, ${errorCount} errors, ${rules.length} total`,
6605
6368
  );
6606
- await writePatchState(projectFolder, config, nextState);
6607
- appliedPatches.push(patch.id);
6608
- logger.success(`✓ ${patch.id}: ${result.message}`);
6369
+
6370
+ if (appliedCount > 0) {
6371
+ logger.success('\nFixes applied successfully!');
6372
+ } else if (errorCount > 0) {
6373
+ logger.warn('\nSome fixes failed, check logs above for details');
6374
+ } else {
6375
+ logger.info('\nNo fixes needed');
6376
+ }
6377
+ } catch (error) {
6378
+ logger.error('Failed to run fix command:');
6379
+ logger.error(error instanceof Error ? error.message : String(error));
6380
+
6381
+ // 输出详细的错误信息
6382
+ if (error instanceof Error && error.stack) {
6383
+ debug(`Error stack trace:\n${error.stack}`);
6384
+ }
6385
+
6386
+ process.exit(1);
6609
6387
  }
6610
6388
  };
6389
+ // end_aigc
6611
6390
 
6391
+ /**
6392
+ * 注册 fix 命令到 program
6393
+ */
6612
6394
  const registerCommand$3 = program => {
6613
6395
  program
6614
- .command('patch')
6615
- .description('Apply template patches for existing projects')
6396
+ .command('fix')
6397
+ .description(
6398
+ 'Fix legacy issues from previous versions (e.g., problematic configs)',
6399
+ )
6616
6400
  .argument(
6617
6401
  '[directory]',
6618
- 'Target directory to patch (defaults to current directory)',
6402
+ 'Target directory to fix (defaults to current directory)',
6619
6403
  )
6620
- .option('--dry-run', 'Show matched patches without modifying files')
6621
- .action(async (directory, command) => {
6622
- await executePatch({
6623
- directory,
6624
- dryRun: _optionalChain$2([command, 'optionalAccess', _9 => _9.dryRun]),
6625
- });
6404
+ .action(async (directory) => {
6405
+ await executeFix({ directory });
6626
6406
  });
6627
6407
  };
6628
6408
 
@@ -6720,12 +6500,12 @@ const executeRun = async (
6720
6500
  // 上报命令开始
6721
6501
  reportCommandStart(commandName, JSON.stringify(options), { projectType });
6722
6502
 
6723
- // 1. 对于 build/dev 命令,先执行 patch 以确保项目配置正确
6503
+ // 1. 对于 build 命令,先执行 fix 以确保项目配置正确
6724
6504
  if (['dev', 'build'].includes(commandName)) {
6725
- logger.info('\n🔧 Running patch command before execution...\n');
6505
+ logger.info('\n🔧 Running fix command before build...\n');
6726
6506
  const fixStartTime = Date.now();
6727
6507
  try {
6728
- await executePatch();
6508
+ await executeFix();
6729
6509
  // eslint-disable-next-line @coze-arch/no-empty-catch, @coze-arch/use-error-in-catch -- intentionally ignored
6730
6510
  } catch (_e) {
6731
6511
  // fix errors are intentionally ignored to allow the main command to proceed
@@ -6908,7 +6688,7 @@ const registerCommand$2 = program => {
6908
6688
 
6909
6689
 
6910
6690
 
6911
- const log$4 = debug('coze:routes:nuxt');
6691
+ const log$4 = debug$2('coze:routes:nuxt');
6912
6692
 
6913
6693
  /**
6914
6694
  * Convert Nuxt file path to route path
@@ -7148,7 +6928,7 @@ const scanNuxtRoutes = async (cwd) => {
7148
6928
 
7149
6929
 
7150
6930
 
7151
- const log$3 = debug('coze:routes:nextjs');
6931
+ const log$3 = debug$2('coze:routes:nextjs');
7152
6932
 
7153
6933
  /**
7154
6934
  * Convert Next.js file path to route path
@@ -7489,7 +7269,7 @@ const getOutputFilePath = (cwd, outputPath) =>
7489
7269
 
7490
7270
 
7491
7271
 
7492
- const log$2 = debug('coze:routes:detect');
7272
+ const log$2 = debug$2('coze:routes:detect');
7493
7273
 
7494
7274
  /**
7495
7275
  * Check if any of the specified files exist
@@ -7594,7 +7374,7 @@ const detectTemplate = (cwd) => {
7594
7374
  // ABOUTME: Orchestrates template detection, route scanning, and polling-based updates
7595
7375
 
7596
7376
 
7597
- const log$1 = debug('coze:routes:scanner');
7377
+ const log$1 = debug$2('coze:routes:scanner');
7598
7378
 
7599
7379
  /**
7600
7380
  * Scan routes based on template type
@@ -7695,7 +7475,7 @@ const scanRoutesOnce = async (
7695
7475
  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
7696
7476
 
7697
7477
 
7698
- const log = debug('coze:routes');
7478
+ const log = debug$2('coze:routes');
7699
7479
 
7700
7480
  /**
7701
7481
  * Execute routes command implementation
@@ -8851,22 +8631,7 @@ const executeTemplateEngineStep = async ctx => {
8851
8631
  };
8852
8632
 
8853
8633
  /**
8854
- * 步骤2: 写入 patch 项目元数据
8855
- */
8856
- const writePatchMetadataStep = async ctx => {
8857
- if (!ctx.absoluteOutputPath) {
8858
- return;
8859
- }
8860
-
8861
- await saveProjectPatchState(ctx.absoluteOutputPath, {
8862
- template: ctx.templateName,
8863
- version: packageJson.version,
8864
- appliedPatches: [],
8865
- });
8866
- };
8867
-
8868
- /**
8869
- * 步骤3: 检查 package.json 是否存在
8634
+ * 步骤2: 检查 package.json 是否存在
8870
8635
  */
8871
8636
  const checkPackageJsonStep = ctx => {
8872
8637
  if (!ctx.absoluteOutputPath) {
@@ -8878,7 +8643,7 @@ const checkPackageJsonStep = ctx => {
8878
8643
  };
8879
8644
 
8880
8645
  /**
8881
- * 步骤4: 安装依赖
8646
+ * 步骤3: 安装依赖
8882
8647
  */
8883
8648
  const installDependenciesStep = ctx => {
8884
8649
  if (!ctx.absoluteOutputPath) {
@@ -8926,7 +8691,7 @@ const installDependenciesStep = ctx => {
8926
8691
  };
8927
8692
 
8928
8693
  /**
8929
- * 步骤5: 执行完成钩子
8694
+ * 步骤4: 执行完成钩子
8930
8695
  */
8931
8696
  const executeCompleteHookStep = async ctx => {
8932
8697
  if (!ctx.absoluteOutputPath || !ctx.templateConfig || !ctx.context) {
@@ -8943,7 +8708,7 @@ const executeCompleteHookStep = async ctx => {
8943
8708
  };
8944
8709
 
8945
8710
  /**
8946
- * 步骤6: 初始化 Git 仓库
8711
+ * 步骤5: 初始化 Git 仓库
8947
8712
  */
8948
8713
  const gitInitStep = ctx => {
8949
8714
  if (!ctx.absoluteOutputPath) {
@@ -8959,7 +8724,7 @@ const gitInitStep = ctx => {
8959
8724
  };
8960
8725
 
8961
8726
  /**
8962
- * 步骤7: 提交 Git 变更
8727
+ * 步骤6: 提交 Git 变更
8963
8728
  */
8964
8729
  const gitCommitStep = ctx => {
8965
8730
  if (!ctx.absoluteOutputPath) {
@@ -8975,7 +8740,7 @@ const gitCommitStep = ctx => {
8975
8740
  };
8976
8741
 
8977
8742
  /**
8978
- * 步骤8: 启动开发服务器
8743
+ * 步骤7: 启动开发服务器
8979
8744
  */
8980
8745
  const startDevServerStep = ctx => {
8981
8746
  if (!ctx.absoluteOutputPath) {
@@ -9009,7 +8774,6 @@ const startDevServerStep = ctx => {
9009
8774
  */
9010
8775
  const initSteps = [
9011
8776
  executeTemplateEngineStep,
9012
- writePatchMetadataStep,
9013
8777
  checkPackageJsonStep,
9014
8778
  installDependenciesStep,
9015
8779
  executeCompleteHookStep,