@coze-arch/cli 0.1.8-alpha.5d5f9d → 0.1.8-alpha.735a86

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.
@@ -119,9 +119,7 @@ cleanup_legacy_workspace() {
119
119
  done < <(find "$workspace_dir" -mindepth 1 -maxdepth 1 -print0)
120
120
  }
121
121
 
122
- # caches is reserved for the sibling prepare scripts of this project. They keep
123
- # regenerable framework output there (the Next helper points .next/dev into it), and that
124
- # output has to outlive an install, so this cleanup must not read it as leftover.
122
+ # Preserve existing project caches during dependency preparation.
125
123
  cleanup_legacy_shadow_project() {
126
124
  local entry name
127
125
  while IFS= read -r -d '' entry; do
@@ -5,10 +5,10 @@ project_type = "web"
5
5
 
6
6
  [dev]
7
7
  build = []
8
- run = ["python3", "-m", "http.server", "${DEPLOY_RUN_PORT}", "--bind", "0.0.0.0"]
8
+ run = [ "sh", "-c", "exec python3 -m http.server ${DEPLOY_RUN_PORT} --bind 0.0.0.0" ]
9
9
  run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/serve.ps1"]
10
10
 
11
11
  [deploy]
12
12
  build = []
13
- run = ["python3", "-m", "http.server", "${DEPLOY_RUN_PORT}", "--bind", "0.0.0.0"]
13
+ run = [ "sh", "-c", "exec python3 -m http.server ${DEPLOY_RUN_PORT} --bind 0.0.0.0" ]
14
14
  run_win = ["powershell.exe", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", "./scripts/serve.ps1"]
@@ -52,7 +52,7 @@ const eslintConfig = defineConfig([
52
52
  'server.js',
53
53
  'dist/',
54
54
  // Script files (CommonJS):
55
- 'scripts/**/*.js',
55
+ 'scripts/**/*.{js,cjs}',
56
56
  ]),
57
57
  ]);
58
58
 
@@ -1,18 +1,9 @@
1
1
  import type { NextConfig } from 'next';
2
- import path from 'path';
3
2
 
4
3
  const nextConfig: NextConfig = {
5
4
  // outputFileTracingRoot: path.resolve(__dirname, '../../'), // Uncomment and add 'import path from "path"' if needed
6
5
  /* config options here */
7
6
  serverExternalPackages: ['coze-coding-dev-sdk'],
8
- webpack: (config, { dev }) => {
9
- if (dev && config.cache && config.cache.type === 'filesystem') {
10
- config.cache.cacheDirectory = path.resolve(
11
- 'node_modules/.cache/next-webpack',
12
- );
13
- }
14
- return config;
15
- },
16
7
  allowedDevOrigins: ['*.dev.coze.site'],
17
8
  images: {
18
9
  remotePatterns: [
@@ -8,7 +8,7 @@ Write-Host "Installing dependencies..."
8
8
  if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
9
9
 
10
10
  Write-Host "Building the Next.js project..."
11
- & pnpm next build --webpack
11
+ & pnpm next build
12
12
  if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
13
13
 
14
14
  Write-Host "Bundling server with tsup..."
@@ -6,10 +6,10 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
10
 
11
11
  echo "Building the Next.js project..."
12
- pnpm next build --webpack
12
+ pnpm next build
13
13
 
14
14
  echo "Bundling server with tsup..."
15
15
  pnpm tsup src/server.ts --format cjs --platform node --target node20 --outDir dist --no-splitting --no-minify
@@ -28,7 +28,7 @@ Stop-ListeningProcess $port
28
28
 
29
29
  <% if (process.env.NODE_ENV === 'test') { %>
30
30
  $env:PORT = "$port"
31
- & pnpm next dev --webpack --hostname 0.0.0.0 --port $port
31
+ & pnpm next dev --hostname 0.0.0.0 --port $port
32
32
  exit $LASTEXITCODE
33
33
  <% } else { %>
34
34
  $logDirectory = if ($env:COZE_LOG_DIR) { $env:COZE_LOG_DIR } else { Join-Path $workspace "logs" }
@@ -45,7 +45,7 @@ if (Test-Path $pidFile) {
45
45
  $previousPort = $env:PORT
46
46
  $env:PORT = "$port"
47
47
  try {
48
- $process = Start-Process -FilePath $env:ComSpec -ArgumentList @("/d", "/s", "/c", "pnpm next dev --webpack --hostname 0.0.0.0 --port $port") -WorkingDirectory $workspace -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile -PassThru
48
+ $process = Start-Process -FilePath $env:ComSpec -ArgumentList @("/d", "/s", "/c", "pnpm next dev --hostname 0.0.0.0 --port $port") -WorkingDirectory $workspace -RedirectStandardOutput $logFile -RedirectStandardError $errorLogFile -PassThru
49
49
  } finally {
50
50
  if ($null -eq $previousPort) { Remove-Item Env:PORT -ErrorAction SilentlyContinue } else { $env:PORT = $previousPort }
51
51
  }
@@ -58,37 +58,17 @@ kill_port_if_listening() {
58
58
  echo "Port ${DEPLOY_RUN_PORT} cleared."
59
59
  }
60
60
 
61
- # Next 的路由清单由 watchpack 每次启动重新扫 src 下的 app/pages 目录现算,而 watchpack
62
- # 不会进入软链目录,软链子树里的 page/route 会被静默跳过:既不注册路由,也不打任何日志,
63
- # 表现为该路由一直 404 而 .next 里没有它的产物。这里只做提示,不改动源码。
64
- warn_source_symlinks() {
65
- local source_dir="${COZE_WORKSPACE_PATH}/src"
66
- local links link
67
- if [[ ! -e "${source_dir}" ]]; then
68
- return
69
- fi
70
- links=$(find "${source_dir}" -type l 2>/dev/null || true)
71
- if [[ -z "${links}" ]]; then
72
- return
73
- fi
74
- echo "Warning: 以下路径是软链,Next 不会进入其中,里面的 page/route 不会被编译:" >&2
75
- while IFS= read -r link; do
76
- echo " ${link}" >&2
77
- done <<< "${links}"
78
- }
79
-
80
61
  <% if (process.env.NODE_ENV === 'test') { %>
81
62
  echo "Clearing port ${DEPLOY_RUN_PORT} before start."
82
63
  kill_port_if_listening
83
64
  if [[ "${COZE_WEB_LOCAL_MIRROR:-}" != "1" ]]; then
84
- COZE_REUSE_NODE_MODULES=1 bash "${COZE_WORKSPACE_PATH}/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
65
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
85
66
  fi
86
- warn_source_symlinks
87
67
  echo "Starting HTTP service on port ${DEPLOY_RUN_PORT} for dev..."
88
68
 
89
69
  # 测试环境保持服务为前台进程,便于 e2e 收集输出并停止进程。
90
70
  # 开发环境直接使用 Next 的 dev CLI,避免云盘文件事件在 custom server 链路中丢失。
91
- exec node "${SCRIPT_DIR}/local-workspace.cjs" watch pnpm next dev --webpack --hostname 0.0.0.0 --port "${DEPLOY_RUN_PORT}"
71
+ exec node "${SCRIPT_DIR}/local-workspace.cjs" watch pnpm next dev --hostname 0.0.0.0 --port "${DEPLOY_RUN_PORT}"
92
72
  <% } else { %>
93
73
  LOG_DIR="${COZE_LOG_DIR:-${COZE_WORKSPACE_PATH}/logs}"
94
74
  LOG_FILE="${LOG_DIR}/app.log"
@@ -276,9 +256,8 @@ fi
276
256
  echo "Clearing port ${DEPLOY_RUN_PORT} before start."
277
257
  kill_port_if_listening
278
258
  if [[ "${COZE_WEB_LOCAL_MIRROR:-}" != "1" ]]; then
279
- COZE_REUSE_NODE_MODULES=1 bash "${COZE_WORKSPACE_PATH}/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
259
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
280
260
  fi
281
- warn_source_symlinks
282
261
  echo "Starting HTTP service on port ${DEPLOY_RUN_PORT} for dev..."
283
262
 
284
263
  mkdir -p "${LOG_DIR}"
@@ -286,7 +265,7 @@ mkdir -p "${LOG_DIR}"
286
265
 
287
266
  export PORT="${DEPLOY_RUN_PORT}"
288
267
  server_pid="$(spawn_detached "${COZE_WORKSPACE_PATH}" "${LOG_FILE}" \
289
- "$(command -v node)" "${SCRIPT_DIR}/local-workspace.cjs" watch "$(command -v pnpm)" next dev --webpack --hostname 0.0.0.0 --port "${DEPLOY_RUN_PORT}")"
268
+ "$(command -v node)" "${SCRIPT_DIR}/local-workspace.cjs" watch "$(command -v pnpm)" next dev --hostname 0.0.0.0 --port "${DEPLOY_RUN_PORT}")"
290
269
  if [[ -z "${server_pid}" ]]; then
291
270
  echo "Dev server failed to start: 未获取到后台进程 PID。" >&2
292
271
  dump_log
@@ -13,5 +13,5 @@ cd "${COZE_WORKSPACE_PATH}"
13
13
 
14
14
  echo "Installing dependencies..."
15
15
  if [[ "${COZE_WEB_LOCAL_MIRROR:-}" != "1" ]]; then
16
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
16
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
17
17
  fi
@@ -7,7 +7,7 @@ const hostname = process.env.HOSTNAME || 'localhost';
7
7
  const port = parseInt(process.env.PORT || '<%= port %>', 10);
8
8
 
9
9
  // Create Next.js app
10
- const app = next({ dev, hostname, port, webpack: true });
10
+ const app = next({ dev, hostname, port });
11
11
  const handle = app.getRequestHandler();
12
12
 
13
13
  app.prepare().then(() => {
@@ -6,7 +6,7 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
10
 
11
11
  echo "Building the Nuxt.js project..."
12
12
  pnpm nuxt build
@@ -13,7 +13,7 @@ cd "${COZE_WORKSPACE_PATH}"
13
13
 
14
14
  echo "Installing dependencies..."
15
15
  if [[ "${COZE_WEB_LOCAL_MIRROR:-}" != "1" ]]; then
16
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline
16
+ pnpm install --prefer-frozen-lockfile --prefer-offline
17
17
  fi
18
18
 
19
19
  echo "Preparing Nuxt project..."
@@ -119,9 +119,7 @@ cleanup_legacy_workspace() {
119
119
  done < <(find "$workspace_dir" -mindepth 1 -maxdepth 1 -print0)
120
120
  }
121
121
 
122
- # caches is reserved for the sibling prepare scripts of this project. They keep
123
- # regenerable framework output there (the Next helper points .next/dev into it), and that
124
- # output has to outlive an install, so this cleanup must not read it as leftover.
122
+ # Preserve existing project caches during dependency preparation.
125
123
  cleanup_legacy_shadow_project() {
126
124
  local entry name
127
125
  while IFS= read -r -d '' entry; do
@@ -6,7 +6,7 @@ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
6
6
  cd "${COZE_WORKSPACE_PATH}"
7
7
 
8
8
  echo "Installing dependencies..."
9
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
10
 
11
11
  echo "Building frontend with Vite..."
12
12
  pnpm vite build
@@ -13,5 +13,5 @@ cd "${COZE_WORKSPACE_PATH}"
13
13
 
14
14
  echo "Installing dependencies..."
15
15
  if [[ "${COZE_WEB_LOCAL_MIRROR:-}" != "1" ]]; then
16
- bash "$COZE_WORKSPACE_PATH/scripts/prepare-node-modules.sh" --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
16
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
17
17
  fi
package/lib/cli.js CHANGED
@@ -2114,7 +2114,7 @@ const EventBuilder = {
2114
2114
  };
2115
2115
 
2116
2116
  var name = "@coze-arch/cli";
2117
- var version = "0.1.8-alpha.5d5f9d";
2117
+ var version = "0.1.8-alpha.735a86";
2118
2118
  var description = "coze coding devtools cli";
2119
2119
  var license = "MIT";
2120
2120
  var author = "fanwenjie.fe@bytedance.com";
@@ -6402,9 +6402,11 @@ const createPatch = (template) => ({
6402
6402
  const replacements = new Map();
6403
6403
  replacements.set(HELPER, await fs$1.readFile(path.join(origin, HELPER), 'utf8'));
6404
6404
  for (const action of ACTIONS) {
6405
+ const content = await renderTemplate(path.join(origin, `${action}.sh`), { port: plan.port });
6405
6406
  replacements.set(
6406
6407
  `${action}.sh`,
6407
- await renderTemplate(path.join(origin, `${action}.sh`), { port: plan.port }),
6408
+ // The recognized legacy Next.js wrappers use Webpack; preserve their bundler.
6409
+ template === 'nextjs' ? content.replace(/\bnext dev\b/g, 'next dev --webpack') : content,
6408
6410
  );
6409
6411
  }
6410
6412
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/cli",
3
- "version": "0.1.8-alpha.5d5f9d",
3
+ "version": "0.1.8-alpha.735a86",
4
4
  "private": false,
5
5
  "description": "coze coding devtools cli",
6
6
  "license": "MIT",
@@ -1,122 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Keep Next development output off Coze Drive without moving production output.
3
- set -euo pipefail
4
-
5
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
6
- if [ "$(basename "$(dirname "$SCRIPT_DIR")")" = ".cozeproj" ]; then
7
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd -P)"
8
- else
9
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
10
- fi
11
-
12
- DRIVE_ROOT="${COZE_DRIVE_ROOT:-/Coze/Drive}"
13
- if [ -d "$DRIVE_ROOT" ]; then
14
- DRIVE_ROOT="$(cd "$DRIVE_ROOT" && pwd -P)"
15
- else
16
- DRIVE_ROOT="${DRIVE_ROOT%/}"
17
- fi
18
- case "$PROJECT_ROOT" in
19
- "$DRIVE_ROOT"|"$DRIVE_ROOT"/*) ;;
20
- *) exit 0 ;;
21
- esac
22
-
23
- # Next writes every on-demand development build into .next/dev. On Coze Drive each of
24
- # those writes goes through the sync daemon, so only that subtree moves to local disk.
25
- # Production output stays in the project directory, which keeps `next build` and
26
- # deployment unchanged.
27
- #
28
- # One local directory per project, shared with prepare-node-modules.sh: node_modules and
29
- # this cache sit side by side under WORK_DIR. The caches subdirectory is the slot that
30
- # script reserves for output that must survive an install, so nothing here is cleaned up
31
- # behind our back. PROJECT_ID has to stay identical to the one it computes.
32
- NM_ROOT="/tmp/nm"
33
- PROJECT_ID="$(basename "$PROJECT_ROOT")-$(printf '%s' "$PROJECT_ROOT" | cksum | awk '{print $1}')"
34
- WORK_DIR="$NM_ROOT/$PROJECT_ID"
35
- NEXT_ROOT="$PROJECT_ROOT/.next"
36
- NEXT_DEV="$NEXT_ROOT/dev"
37
- LEGACY_NEXT_ROOT="$WORK_DIR/.next"
38
- LOCAL_NEXT_DEV="$WORK_DIR/caches/next-dev"
39
-
40
- case "$LOCAL_NEXT_DEV" in
41
- "$DRIVE_ROOT"|"$DRIVE_ROOT"/*)
42
- echo "[next] local development output must not be on Coze Drive: $LOCAL_NEXT_DEV" >&2
43
- exit 1
44
- ;;
45
- esac
46
-
47
- # Coze Drive sync does not preserve symlinks: a synced copy of a link arrives as a
48
- # regular file holding the link target. Recognize the links this scheme creates so a
49
- # project that came back from sync repairs itself instead of failing to start.
50
- is_flattened_managed_link() {
51
- local candidate="$1" content=""
52
- [ -f "$candidate" ] || return 1
53
- [ ! -L "$candidate" ] || return 1
54
- [ "$(wc -c < "$candidate")" -le 4096 ] || return 1
55
- content="$(tr -d '\r\n' < "$candidate")"
56
- case "$content" in
57
- "$NM_ROOT"/*) return 0 ;;
58
- esac
59
- return 1
60
- }
61
-
62
- # Earlier versions linked the whole .next directory. Bring any production build made
63
- # back then into the project; from here on only .next/dev is redirected.
64
- restore_legacy_next_root() {
65
- local entry
66
- rm -f "$NEXT_ROOT"
67
- mkdir -p "$NEXT_ROOT"
68
- if [ -d "$LEGACY_NEXT_ROOT" ]; then
69
- while IFS= read -r -d '' entry; do
70
- mv "$entry" "$NEXT_ROOT/"
71
- done < <(find -P "$LEGACY_NEXT_ROOT" -mindepth 1 -maxdepth 1 -print0)
72
- rmdir "$LEGACY_NEXT_ROOT" 2>/dev/null || true
73
- fi
74
- }
75
-
76
- if [ -L "$NEXT_ROOT" ]; then
77
- case "$(readlink "$NEXT_ROOT")" in
78
- "$NM_ROOT"/*)
79
- echo "[next] Restoring legacy .next output to the project directory."
80
- restore_legacy_next_root
81
- ;;
82
- *)
83
- echo "[next] refusing to replace unmanaged .next symlink: $NEXT_ROOT" >&2
84
- exit 1
85
- ;;
86
- esac
87
- elif is_flattened_managed_link "$NEXT_ROOT"; then
88
- echo "[next] Recovering .next flattened by Coze Drive sync."
89
- restore_legacy_next_root
90
- elif [ -e "$NEXT_ROOT" ] && [ ! -d "$NEXT_ROOT" ]; then
91
- echo "[next] refusing to replace non-directory Next output: $NEXT_ROOT" >&2
92
- exit 1
93
- fi
94
-
95
- mkdir -p "$NEXT_ROOT" "$LOCAL_NEXT_DEV"
96
-
97
- if [ -L "$NEXT_DEV" ]; then
98
- if [ "$(readlink "$NEXT_DEV")" = "$LOCAL_NEXT_DEV" ]; then
99
- exit 0
100
- fi
101
- case "$(readlink "$NEXT_DEV")" in
102
- "$NM_ROOT"/*) rm "$NEXT_DEV" ;;
103
- *)
104
- echo "[next] refusing to replace unmanaged .next/dev symlink: $NEXT_DEV" >&2
105
- exit 1
106
- ;;
107
- esac
108
- elif [ -e "$NEXT_DEV" ]; then
109
- # .next/dev holds development output only, and Next regenerates it on demand.
110
- rm -rf "$NEXT_DEV"
111
- fi
112
-
113
- # A second dev start can win the race between the removal above and this link.
114
- if ! ln -s "$LOCAL_NEXT_DEV" "$NEXT_DEV" 2>/dev/null; then
115
- if [ -L "$NEXT_DEV" ] && [ "$(readlink "$NEXT_DEV")" = "$LOCAL_NEXT_DEV" ]; then
116
- exit 0
117
- fi
118
- echo "[next] failed to link development output: $NEXT_DEV" >&2
119
- exit 1
120
- fi
121
-
122
- echo "[next] Development output linked to $LOCAL_NEXT_DEV"