@coze-arch/cli 0.0.1-alpha.ef0249 → 0.0.1-alpha.f11735

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.
@@ -1,4 +1,5 @@
1
1
  import type { Metadata } from 'next';
2
+ import { Inspector } from 'react-dev-inspector';
2
3
  import './globals.css';
3
4
 
4
5
  export const metadata: Metadata = {
@@ -60,11 +61,12 @@ export default function RootLayout({
60
61
  }: Readonly<{
61
62
  children: React.ReactNode;
62
63
  }>) {
64
+ const isDev = process.env.NODE_ENV === 'development';
65
+
63
66
  return (
64
67
  <html lang="en">
65
- <body
66
- className={`antialiased`}
67
- >
68
+ <body className={`antialiased`}>
69
+ {isDev && <Inspector />}
68
70
  {children}
69
71
  </body>
70
72
  </html>
package/lib/cli.js CHANGED
@@ -8,8 +8,8 @@ var shelljs = require('shelljs');
8
8
  var perf_hooks = require('perf_hooks');
9
9
  var fs$1 = require('fs/promises');
10
10
  var os = require('os');
11
- var toml = require('@iarna/toml');
12
11
  var jsYaml = require('js-yaml');
12
+ var toml = require('@iarna/toml');
13
13
  var child_process = require('child_process');
14
14
  var addFormats = require('ajv-formats');
15
15
  var Ajv = require('ajv');
@@ -585,7 +585,7 @@ const executeWarmup = async (
585
585
  /**
586
586
  * 注册 warmup 命令到 program
587
587
  */
588
- const registerCommand$2 = program => {
588
+ const registerCommand$3 = program => {
589
589
  program
590
590
  .command('warmup')
591
591
  .description('Pre-install dependencies for templates to speed up init')
@@ -727,7 +727,7 @@ const parseConfigContent = (content) => {
727
727
  return config ;
728
728
  } catch (error) {
729
729
  // TOML 解析失败,继续尝试其他格式
730
- // eslint-disable-next-line no-console
730
+
731
731
  console.debug('TOML parse failed:', error);
732
732
  }
733
733
 
@@ -739,7 +739,7 @@ const parseConfigContent = (content) => {
739
739
  }
740
740
  } catch (error) {
741
741
  // YAML 解析失败,继续尝试其他格式
742
- // eslint-disable-next-line no-console
742
+
743
743
  console.debug('YAML parse failed:', error);
744
744
  }
745
745
 
@@ -823,8 +823,232 @@ const getCommandConfig = (
823
823
  return commandConfig;
824
824
  };
825
825
 
826
- function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }
826
+ // ABOUTME: Fix rule to comment out problematic outputFileTracingRoot config in Next.js projects
827
+ // ABOUTME: This config can cause issues in monorepo environments and should be removed
828
+
829
+
830
+
831
+
832
+ /**
833
+ * 检查是否为 Next.js 项目
834
+ */
835
+ const isNextProject = (projectFolder) => {
836
+ const packageJsonPath = path.join(projectFolder, 'package.json');
837
+
838
+ if (!fs.existsSync(packageJsonPath)) {
839
+ return false;
840
+ }
841
+
842
+ try {
843
+ // eslint-disable-next-line no-restricted-syntax
844
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
845
+ const deps = {
846
+ ...packageJson.dependencies,
847
+ ...packageJson.devDependencies,
848
+ };
849
+
850
+ return 'next' in deps;
851
+ } catch (e) {
852
+ return false;
853
+ }
854
+ };
855
+
856
+ /**
857
+ * 查找 Next.js 配置文件
858
+ */
859
+ const findNextConfigFile = (projectFolder) => {
860
+ const possibleConfigs = [
861
+ 'next.config.ts',
862
+ 'next.config.js',
863
+ 'next.config.mjs',
864
+ ];
865
+
866
+ for (const configFile of possibleConfigs) {
867
+ const configPath = path.join(projectFolder, configFile);
868
+ if (fs.existsSync(configPath)) {
869
+ return configPath;
870
+ }
871
+ }
872
+
873
+ return null;
874
+ };
875
+
876
+ /**
877
+ * 注释掉 outputFileTracingRoot 配置
878
+ */
879
+ const commentOutOutputTracingRoot = (
880
+ configPath,
881
+ ) => {
882
+ let content = fs.readFileSync(configPath, 'utf-8');
883
+ let modified = false;
884
+ let originalLine = null;
885
+
886
+ // 匹配包含 outputFileTracingRoot 的行(尚未被注释的)
887
+ // 支持 path.resolve(...) 后面有空格,然后可选逗号
888
+ // 只匹配单行配置,不匹配跨多行的配置
889
+ const pattern =
890
+ /^(\s*)(outputFileTracingRoot:\s*path\.resolve\([^\n\r)]+\)\s*,?)\s*$/gm;
891
+
892
+ const matches = content.match(pattern);
893
+
894
+ if (matches && matches.length > 0) {
895
+ originalLine = matches[0].trim();
896
+
897
+ // 在匹配的行前添加 // 注释
898
+ content = content.replace(pattern, '$1// $2');
899
+ modified = true;
900
+
901
+ fs.writeFileSync(configPath, content, 'utf-8');
902
+ }
903
+
904
+ return { modified, originalLine };
905
+ };
906
+
907
+ // start_aigc
908
+ /**
909
+ * Fix 规则:注释掉 Next.js 项目中的 outputFileTracingRoot 配置
910
+ * 这个配置在 monorepo 环境中可能会导致问题
911
+ */
912
+ const fixNextOutputTracingRoot = context => {
913
+ const ruleName = 'next-output-tracing-root';
914
+
915
+ // 1. 检查是否为 Next.js 项目
916
+ if (!isNextProject(context.projectFolder)) {
917
+ return {
918
+ ruleName,
919
+ applied: false,
920
+ message: 'Not a Next.js project, skipping',
921
+ };
922
+ }
923
+
924
+ // 2. 查找 Next.js 配置文件
925
+ const configPath = findNextConfigFile(context.projectFolder);
926
+
927
+ if (!configPath) {
928
+ return {
929
+ ruleName,
930
+ applied: false,
931
+ message: 'Next.js config file not found, skipping',
932
+ };
933
+ }
934
+
935
+ // 3. 注释掉 outputFileTracingRoot 配置
936
+ const { modified, originalLine } = commentOutOutputTracingRoot(configPath);
937
+
938
+ if (modified && originalLine) {
939
+ logger.success(
940
+ `Commented out outputFileTracingRoot in ${configPath.split('/').pop()}`,
941
+ );
942
+ logger.info(` Original: ${originalLine}`);
943
+
944
+ return {
945
+ ruleName,
946
+ applied: true,
947
+ message: `Successfully commented out: ${originalLine}`,
948
+ };
949
+ }
950
+
951
+ return {
952
+ ruleName,
953
+ applied: false,
954
+ message: 'No outputFileTracingRoot config found, skipping',
955
+ };
956
+ };
957
+ // end_aigc
958
+
959
+ /**
960
+ * 所有修复规则的数组
961
+ * 按顺序执行,新增规则直接添加到数组中
962
+ */
963
+ const rules = [
964
+ // Next.js related fixes
965
+ fixNextOutputTracingRoot,
966
+
967
+ // Add more rules here
968
+ ] ;
969
+
970
+ // ABOUTME: Fix command for resolving legacy issues from previous project versions
971
+ // ABOUTME: Applies a series of fix rules defined in the fix-rules directory
972
+
973
+
974
+ // start_aigc
975
+ /**
976
+ * 执行 fix 命令的内部实现
977
+ */
978
+ const executeFix = async (options = {}) => {
979
+ try {
980
+ const cwd = process.cwd();
981
+ const projectFolder = options.directory
982
+ ? path.resolve(cwd, options.directory)
983
+ : cwd;
984
+
985
+ logger.info(`Running fix command on: ${projectFolder}`);
986
+ logger.info(`Found ${rules.length} fix rule(s) to apply\n`);
987
+
988
+ const context = {
989
+ cwd,
990
+ projectFolder,
991
+ };
992
+
993
+ let appliedCount = 0;
994
+ let skippedCount = 0;
995
+
996
+ // 依次执行所有修复规则
997
+ for (const rule of rules) {
998
+ try {
999
+ const result = await Promise.resolve(rule(context));
1000
+
1001
+ if (result.applied) {
1002
+ appliedCount++;
1003
+ logger.success(`✓ ${result.ruleName}: ${result.message}`);
1004
+ } else {
1005
+ skippedCount++;
1006
+ logger.info(`○ ${result.ruleName}: ${result.message}`);
1007
+ }
1008
+ } catch (error) {
1009
+ logger.error(
1010
+ `✗ Rule execution failed: ${error instanceof Error ? error.message : String(error)}`,
1011
+ );
1012
+ }
1013
+ }
1014
+
1015
+ // 输出汇总信息
1016
+ logger.info(
1017
+ `\nSummary: ${appliedCount} fixed, ${skippedCount} skipped, ${rules.length} total`,
1018
+ );
1019
+
1020
+ if (appliedCount > 0) {
1021
+ logger.success('\nFixes applied successfully!');
1022
+ } else {
1023
+ logger.info('\nNo fixes needed');
1024
+ }
1025
+ } catch (error) {
1026
+ logger.error('Failed to run fix command:');
1027
+ logger.error(error instanceof Error ? error.message : String(error));
1028
+ process.exit(1);
1029
+ }
1030
+ };
1031
+ // end_aigc
827
1032
 
1033
+ /**
1034
+ * 注册 fix 命令到 program
1035
+ */
1036
+ const registerCommand$2 = program => {
1037
+ program
1038
+ .command('fix')
1039
+ .description(
1040
+ 'Fix legacy issues from previous versions (e.g., problematic configs)',
1041
+ )
1042
+ .argument(
1043
+ '[directory]',
1044
+ 'Target directory to fix (defaults to current directory)',
1045
+ )
1046
+ .action(async (directory) => {
1047
+ await executeFix({ directory });
1048
+ });
1049
+ };
1050
+
1051
+ function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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; }
828
1052
  /**
829
1053
  * 日志文件名常量
830
1054
  */
@@ -880,15 +1104,27 @@ const executeRun = async (
880
1104
  try {
881
1105
  logger.info(`Running ${commandName} command...`);
882
1106
 
883
- // 1. 加载 .coze 配置
1107
+ // 1. 对于 build 命令,先执行 fix 以确保项目配置正确
1108
+ if (['dev', 'build'].includes(commandName)) {
1109
+ logger.info('\n🔧 Running fix command before build...\n');
1110
+ try {
1111
+ await executeFix();
1112
+ // eslint-disable-next-line @coze-arch/no-empty-catch
1113
+ } catch (e) {
1114
+ // just ignore
1115
+ }
1116
+ logger.info('');
1117
+ }
1118
+
1119
+ // 2. 加载 .coze 配置
884
1120
  const config = await loadCozeConfig();
885
1121
  const commandArgs = getCommandConfig(config, commandName);
886
1122
 
887
- // 2. 准备日志
1123
+ // 3. 准备日志
888
1124
  const logFilePath = resolveLogFilePath(options.logFile);
889
1125
  const logStream = createLogStream(logFilePath);
890
1126
 
891
- // 3. 执行命令
1127
+ // 4. 执行命令
892
1128
  const commandString = commandArgs.join(' ');
893
1129
 
894
1130
  logger.info(`Executing: ${commandString}`);
@@ -1885,13 +2121,14 @@ const registerCommand = program => {
1885
2121
  });
1886
2122
  };
1887
2123
 
1888
- var version = "0.0.1-alpha.ef0249";
2124
+ var version = "0.0.1-alpha.f11735";
1889
2125
  var packageJson = {
1890
2126
  version: version};
1891
2127
 
1892
2128
  const commands = [
1893
2129
  registerCommand,
1894
2130
  registerCommand$1,
2131
+ registerCommand$3,
1895
2132
  registerCommand$2,
1896
2133
  ];
1897
2134
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/cli",
3
- "version": "0.0.1-alpha.ef0249",
3
+ "version": "0.0.1-alpha.f11735",
4
4
  "private": false,
5
5
  "description": "coze coding devtools cli",
6
6
  "license": "MIT",