@coze-arch/cli 0.1.8-alpha.e237ba → 0.1.9-alpha.01bd9e

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.
Files changed (27) hide show
  1. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.ps1 +2 -2
  2. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +1 -1
  3. package/lib/__templates__/expo/client/package.json +1 -1
  4. package/lib/__templates__/nextjs/eslint.config.mjs +1 -1
  5. package/lib/__templates__/nextjs/next.config.ts +0 -9
  6. package/lib/__templates__/nextjs/scripts/build.ps1 +1 -1
  7. package/lib/__templates__/nextjs/scripts/build.sh +1 -1
  8. package/lib/__templates__/nextjs/scripts/dev.ps1 +2 -2
  9. package/lib/__templates__/nextjs/scripts/dev.sh +4 -25
  10. package/lib/__templates__/nextjs/scripts/prepare.sh +1 -1
  11. package/lib/__templates__/nextjs/src/server.ts +1 -1
  12. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +1 -1
  13. package/lib/__templates__/taro/.coze +2 -2
  14. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +6 -1
  15. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +10 -1
  16. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +56 -4
  17. package/lib/__templates__/taro/.cozeproj/scripts/local-workspace.cjs +351 -0
  18. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +16 -6
  19. package/lib/__templates__/taro/.cozeproj/scripts/taro-build.cjs +66 -0
  20. package/lib/__templates__/taro/.cozeproj/scripts/validate.sh +3 -0
  21. package/lib/__templates__/taro/package.json +5 -5
  22. package/lib/__templates__/vite/scripts/prepare.sh +1 -1
  23. package/lib/cli.js +19 -7
  24. package/package.json +1 -1
  25. package/lib/__templates__/nextjs/scripts/prepare-node-modules.sh +0 -380
  26. package/lib/__templates__/nuxt-vue/scripts/prepare-node-modules.sh +0 -380
  27. package/lib/__templates__/vite/scripts/prepare-node-modules.sh +0 -380
@@ -0,0 +1,351 @@
1
+ #!/usr/bin/env node
2
+ // Taro source is owned by Drive. Only these wrappers may write to the local workspace.
3
+ /* eslint-disable @typescript-eslint/no-require-imports -- Standalone CommonJS runtime shipped without CLI dependencies. */
4
+ const fs = require('node:fs');
5
+ const path = require('node:path');
6
+ const os = require('node:os');
7
+ const { createHash } = require('node:crypto');
8
+ const { spawn, execFileSync } = require('node:child_process');
9
+ const { setTimeout: delay } = require('node:timers/promises');
10
+
11
+ const scriptRoot = fs.realpathSync(path.resolve(__dirname, '..', '..'));
12
+ const source = fs.realpathSync(
13
+ process.env.COZE_TARO_LOCAL_ACTIVE === scriptRoot && process.env.COZE_TARO_SOURCE_PATH
14
+ ? process.env.COZE_TARO_SOURCE_PATH : scriptRoot,
15
+ );
16
+ const drivePath = path.resolve(process.env.COZE_DRIVE_ROOT || '/Coze/Drive');
17
+ const drive = fs.existsSync(drivePath) ? fs.realpathSync(drivePath) : drivePath;
18
+ const inside = (root, candidate) => candidate === root || candidate.startsWith(`${root}${path.sep}`);
19
+ const onDrive = inside(drive, source);
20
+ const digest = value => createHash('sha256').update(value).digest('hex');
21
+ // Separate from /tmp/nm: older dependency helpers clean unknown entries there.
22
+ const cacheRoot = path.join(os.tmpdir(), `coze-taro-${process.getuid()}`);
23
+ const projectCache = path.join(cacheRoot, digest(source));
24
+ const exclusions = [
25
+ 'node_modules', '.git', '/logs', '.pnpm-store', '.next', '.nuxt', '.output',
26
+ '/dist', '/dist-web', '/dist-tt', '/server/dist', '/dist-server', '.cache', '.turbo', '*.tsbuildinfo',
27
+ '.eslintcache', '.stylelintcache', '/next-env.d.ts',
28
+ ];
29
+ const outputDirs = ['dist', 'dist-web', 'dist-tt', 'server/dist'];
30
+ const taroOutputDirs = {
31
+ web: 'dist-web',
32
+ h5: 'dist-web',
33
+ weapp: 'dist',
34
+ tt: 'dist-tt',
35
+ };
36
+ const installArgs = ['install', '--prefer-frozen-lockfile', '--prefer-offline'];
37
+ let interrupted = false;
38
+ const children = new Set();
39
+
40
+ function stopTree(child) {
41
+ if (!child.pid || child.exitCode !== null) return;
42
+ // Keep descendants in the detached launcher's group so readiness ownership works.
43
+ // Also stop grandchildren when the test/foreground path is signalled directly.
44
+ let rows = [];
45
+ try {
46
+ rows = execFileSync('ps', ['-axo', 'pid=,ppid='], { encoding: 'utf8' })
47
+ .trim().split('\n').map(line => line.trim().split(/\s+/).map(Number));
48
+ } catch { /* The launcher still owns and reaps its process group. */ }
49
+ const pids = [child.pid];
50
+ for (let i = 0; i < pids.length; i++) {
51
+ for (const [pid, parent] of rows) if (parent === pids[i]) pids.push(pid);
52
+ }
53
+ for (const pid of pids.reverse()) {
54
+ try { process.kill(pid, 'SIGTERM'); } catch { /* Already exited. */ }
55
+ }
56
+ const timer = setTimeout(() => {
57
+ for (const pid of pids) {
58
+ try { process.kill(pid, 'SIGKILL'); } catch { /* Already exited. */ }
59
+ }
60
+ }, 2000);
61
+ timer.unref();
62
+ }
63
+
64
+ for (const signal of ['SIGINT', 'SIGTERM']) {
65
+ process.on(signal, () => {
66
+ interrupted = true;
67
+ process.exitCode = signal === 'SIGINT' ? 130 : 143;
68
+ for (const child of children) stopTree(child);
69
+ });
70
+ }
71
+
72
+ function run(command, args, cwd, env = process.env) {
73
+ if (interrupted) return Promise.reject(new Error('Interrupted'));
74
+ return new Promise((resolve, reject) => {
75
+ const child = spawn(command, args, { cwd, env, stdio: 'inherit' });
76
+ children.add(child);
77
+ child.once('error', error => { children.delete(child); reject(error); });
78
+ child.once('exit', (code, signal) => {
79
+ children.delete(child);
80
+ if (code === 0) resolve();
81
+ else reject(new Error(`${command} exited with ${signal || code}`));
82
+ });
83
+ });
84
+ }
85
+
86
+ function ensureCache() {
87
+ for (const dir of [cacheRoot, projectCache]) {
88
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
89
+ if (fs.lstatSync(dir).isSymbolicLink() || fs.statSync(dir).uid !== process.getuid()) {
90
+ throw new Error(`Refusing unmanaged workspace directory: ${dir}`);
91
+ }
92
+ if (inside(drive, fs.realpathSync(dir))) {
93
+ throw new Error(`Local workspace must be outside Coze Drive: ${dir}`);
94
+ }
95
+ }
96
+ }
97
+
98
+ async function locked(action, name = 'sync') {
99
+ const lock = path.join(projectCache, `${name}.lock`);
100
+ const started = Date.now();
101
+ let missingOwner = 0;
102
+ while (true) {
103
+ if (interrupted) throw new Error('Interrupted');
104
+ try { fs.mkdirSync(lock); break; } catch (error) {
105
+ if (error.code !== 'EEXIST') throw error;
106
+ }
107
+ let alive = false;
108
+ try {
109
+ const pid = Number(fs.readFileSync(path.join(lock, 'pid'), 'utf8'));
110
+ if (Number.isInteger(pid) && pid > 0) { process.kill(pid, 0); alive = true; }
111
+ } catch (error) { if (error.code === 'EPERM') alive = true; }
112
+ missingOwner = alive ? 0 : missingOwner + 1;
113
+ if (missingOwner >= 2) {
114
+ const stale = `${lock}.stale-${process.pid}`;
115
+ try {
116
+ fs.renameSync(lock, stale);
117
+ fs.rmSync(stale, { recursive: true });
118
+ } catch (error) { if (error.code !== 'ENOENT') throw error; }
119
+ missingOwner = 0;
120
+ continue;
121
+ }
122
+ if (Date.now() - started > 120000) throw new Error(`Timed out waiting for ${lock}`);
123
+ await delay(500);
124
+ }
125
+ fs.writeFileSync(path.join(lock, 'pid'), String(process.pid));
126
+ try { return await action(); }
127
+ finally { fs.rmSync(lock, { recursive: true, force: true }); }
128
+ }
129
+
130
+ async function sync(local) {
131
+ if (!fs.existsSync(path.join(source, 'package.json'))) {
132
+ throw new Error(`Source project is unavailable: ${source}`);
133
+ }
134
+ fs.mkdirSync(local, { recursive: true });
135
+ if (fs.realpathSync(local) !== local) throw new Error(`Refusing workspace symlink: ${local}`);
136
+ // Checksums catch same-size edits with unchanged/epoch Drive mtimes. Do not use -t:
137
+ // changed local files get fresh mtimes and unchanged files retain watcher snapshots.
138
+ // Materialize source links so the framework never follows them back onto Drive.
139
+ await run('rsync', [
140
+ '-rLp', '--checksum', '--delete', '--delay-updates',
141
+ ...exclusions.map(entry => `--exclude=${entry}`), `${source}/`, `${local}/`,
142
+ ], source);
143
+ }
144
+
145
+ function readOptional(file) {
146
+ try { return fs.readFileSync(file); }
147
+ catch (error) { if (error.code === 'ENOENT') return Buffer.alloc(0); throw error; }
148
+ }
149
+
150
+ function installInput(root) {
151
+ const hash = createHash('sha256');
152
+ const visit = (dir, all = false) => {
153
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
154
+ if (['node_modules', '.git', 'logs', '.pnpm-store', '.next', '.nuxt', '.output', 'dist', 'dist-web', 'dist-tt', 'dist-server', '.cache', '.turbo'].includes(entry.name)) continue;
155
+ const file = path.join(dir, entry.name);
156
+ // Follow source links just as rsync -L does, while detecting loops explicitly.
157
+ const real = fs.realpathSync(file);
158
+ if (entry.isDirectory() || (entry.isSymbolicLink() && fs.statSync(file).isDirectory())) {
159
+ if (ancestors.has(real)) throw new Error(`Source symlink cycle: ${file}`);
160
+ ancestors.add(real);
161
+ visit(file, all || entry.name === 'patches');
162
+ ancestors.delete(real);
163
+ }
164
+ else if (all || ['package.json', 'pnpm-lock.yaml', 'pnpm-workspace.yaml', '.npmrc', '.pnpmfile.cjs', '.pnpmfile.js'].includes(entry.name)) {
165
+ hash.update(path.relative(root, file)).update('\0').update(readOptional(file)).update('\0');
166
+ }
167
+ }
168
+ };
169
+ const ancestors = new Set([fs.realpathSync(root)]);
170
+ visit(root);
171
+ return hash.digest('hex');
172
+ }
173
+
174
+ function localEnv(local) {
175
+ return {
176
+ ...process.env,
177
+ COZE_TARO_LOCAL_ACTIVE: local,
178
+ COZE_TARO_SOURCE_PATH: source,
179
+ COZE_TARO_LOCAL_MIRROR: onDrive ? '1' : '',
180
+ COZE_WORKSPACE_PATH: local,
181
+ // Keep the existing discoverable log/PID location in the source project.
182
+ COZE_LOG_DIR: process.env.COZE_LOG_DIR || path.join(source, 'logs'),
183
+ PWD: local,
184
+ INIT_CWD: local,
185
+ ...(onDrive ? { npm_config_store_dir: path.join(cacheRoot, 'store') } : {}),
186
+ };
187
+ }
188
+
189
+ async function install(local, mode) {
190
+ const state = path.join(projectCache, `${mode}.install`);
191
+ const version = execFileSync('pnpm', ['--version'], { encoding: 'utf8' }).trim();
192
+ const fingerprint = () => digest([
193
+ installInput(local), version, process.version, process.env.NODE_ENV,
194
+ process.env.npm_config_production, process.env.NPM_CONFIG_PRODUCTION,
195
+ process.env.PNPM_CONFIG_PRODUCTION,
196
+ ].join('\n'));
197
+ // Lifecycle scripts may generate files from arbitrary source, so do not reuse
198
+ // their install based on dependency metadata alone. Read manifests as text here
199
+ // (no executable hooks or private CLI dependencies in the standalone helper).
200
+ const manifest = readOptional(path.join(local, 'package.json')).toString();
201
+ const hasLifecycle = /"(?:install|postinstall|prepare)"\s*:/.test(manifest);
202
+ const hasHooks = ['.pnpmfile.cjs', '.pnpmfile.js'].some(file => fs.existsSync(path.join(local, file))) ||
203
+ /^\s*pnpmfile\s*=/m.test(readOptional(path.join(local, '.npmrc')).toString());
204
+ if (!hasLifecycle && !hasHooks && readOptional(state).toString() === fingerprint() &&
205
+ fs.existsSync(path.join(local, 'node_modules', '.modules.yaml'))) return;
206
+ fs.rmSync(state, { force: true });
207
+ const before = installInput(source);
208
+ if (before !== installInput(local)) {
209
+ throw new Error('Dependency inputs changed during sync; rerun dev_build.sh.');
210
+ }
211
+ await run('pnpm', [...installArgs, '--store-dir', path.join(cacheRoot, 'store')], local, localEnv(local));
212
+ if (before !== installInput(source)) {
213
+ throw new Error('Dependency inputs changed on Drive during installation; rerun dev_build.sh. Lockfile was not overwritten.');
214
+ }
215
+ const lockfile = path.join(local, 'pnpm-lock.yaml');
216
+ if (fs.existsSync(lockfile) && !readOptional(lockfile).equals(readOptional(path.join(source, 'pnpm-lock.yaml')))) {
217
+ const temporary = path.join(source, `.pnpm-lock.yaml.${process.pid}.tmp`);
218
+ try {
219
+ fs.copyFileSync(lockfile, temporary);
220
+ fs.renameSync(temporary, path.join(source, 'pnpm-lock.yaml'));
221
+ } finally { fs.rmSync(temporary, { force: true }); }
222
+ }
223
+ fs.writeFileSync(state, fingerprint());
224
+ }
225
+
226
+ async function watch(args) {
227
+ const local = fs.realpathSync(process.env.COZE_TARO_LOCAL_ACTIVE || path.resolve(__dirname, '..', '..'));
228
+ if (!onDrive) return run(args[0], args.slice(1), local);
229
+ ensureCache();
230
+ if (local !== path.join(fs.realpathSync(projectCache), 'dev')) {
231
+ throw new Error(`Refusing to watch an unmanaged workspace: ${local}`);
232
+ }
233
+ const preparedInput = installInput(local);
234
+ let running = true;
235
+ let syncError;
236
+ const command = run(args[0], args.slice(1), local).finally(() => { running = false; });
237
+ const poll = (async () => {
238
+ while (running && !interrupted) {
239
+ await delay(1000);
240
+ if (!running || interrupted) break;
241
+ try {
242
+ await locked(async () => {
243
+ await sync(local);
244
+ if (installInput(local) !== preparedInput) {
245
+ throw new Error('Dependency inputs changed; rerun dev_build.sh and dev_run.sh before previewing.');
246
+ }
247
+ });
248
+ }
249
+ catch (error) {
250
+ syncError = error;
251
+ for (const child of children) stopTree(child);
252
+ break;
253
+ }
254
+ }
255
+ })();
256
+ const results = await Promise.allSettled([command, poll]);
257
+ if (syncError) throw syncError;
258
+ if (results[0].status === 'rejected') throw results[0].reason;
259
+ }
260
+
261
+ async function syncOutputBack(local, outputs = outputDirs) {
262
+ for (const output of outputs) {
263
+ const localOutput = path.join(local, output);
264
+ const sourceOutput = path.join(source, output);
265
+ if (!fs.existsSync(localOutput)) continue;
266
+ fs.rmSync(sourceOutput, { recursive: true, force: true });
267
+ fs.mkdirSync(path.dirname(sourceOutput), { recursive: true });
268
+ await run('rsync', ['-a', '--delete', `${localOutput}/`, `${sourceOutput}/`], local);
269
+ }
270
+ }
271
+
272
+ function cleanOutputs(local, outputs = outputDirs) {
273
+ for (const output of outputs) {
274
+ fs.rmSync(path.join(local, output), { recursive: true, force: true });
275
+ }
276
+ }
277
+
278
+ function taroBuildOutput(args) {
279
+ const target = args[1] === 'h5' ? 'web' : args[1];
280
+ const output = taroOutputDirs[target];
281
+ if (!output) throw new Error(`Unknown Taro build target: ${args[1] || ''}`);
282
+ return output;
283
+ }
284
+
285
+ function runScript(script, local, args) {
286
+ const scriptPath = path.join(local, '.cozeproj', 'scripts', script);
287
+ if (script.endsWith('.cjs')) {
288
+ return run(process.execPath, [scriptPath, ...args], local, localEnv(local));
289
+ }
290
+ return run('bash', [scriptPath, ...args], local, localEnv(local));
291
+ }
292
+
293
+ async function main() {
294
+ const [action, ...args] = process.argv.slice(2);
295
+ if (action === 'watch') return watch(args);
296
+ if (!['prepare', 'dev', 'build', 'pack', 'validate', 'taro-build'].includes(action)) throw new Error(`Unknown Taro action: ${action}`);
297
+ const scriptByAction = {
298
+ prepare: 'dev_build.sh',
299
+ dev: 'dev_run.sh',
300
+ build: 'deploy_build.sh',
301
+ pack: 'pack.sh',
302
+ validate: 'validate.sh',
303
+ 'taro-build': 'taro-build.cjs',
304
+ };
305
+ if (!onDrive) {
306
+ return runScript(scriptByAction[action], source, args);
307
+ }
308
+ ensureCache();
309
+ const mode = action === 'validate' ? 'check' : action === 'build' || action === 'pack' || action === 'taro-build' ? 'build' : 'dev';
310
+ const local = path.join(fs.realpathSync(projectCache), mode);
311
+ console.log(`[taro] Source: ${source}\n[taro] Local ${mode} workspace: ${local}`);
312
+ if (action === 'taro-build') {
313
+ const output = taroBuildOutput(args);
314
+ return locked(async () => {
315
+ await sync(local);
316
+ await install(local, mode);
317
+ cleanOutputs(local, [output]);
318
+ await runScript(scriptByAction[action], local, args);
319
+ await locked(async () => {
320
+ await syncOutputBack(local, [output]);
321
+ }, 'output');
322
+ }, mode);
323
+ }
324
+ if (action === 'validate') {
325
+ return locked(async () => {
326
+ await locked(async () => {
327
+ await sync(local);
328
+ await install(local, mode);
329
+ });
330
+ await runScript('validate.sh', local, args);
331
+ }, 'check');
332
+ }
333
+ await locked(async () => {
334
+ await sync(local);
335
+ await install(local, mode);
336
+ }, mode);
337
+ if (action === 'build' || action === 'pack') {
338
+ cleanOutputs(local);
339
+ }
340
+ await runScript(scriptByAction[action], local, args);
341
+ if (action === 'build' || action === 'pack') {
342
+ await locked(async () => {
343
+ await syncOutputBack(local);
344
+ }, 'output');
345
+ }
346
+ }
347
+
348
+ main().catch(error => {
349
+ console.error(`[taro] ${error.message}`);
350
+ process.exitCode = process.exitCode || 1;
351
+ });
@@ -1,13 +1,18 @@
1
1
  #!/bin/bash
2
+ set -Eeuo pipefail
2
3
 
3
4
  ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
+ if [[ "${COZE_TARO_LOCAL_ACTIVE:-}" != "${ROOT_DIR}" ]]; then
6
+ exec node "$ROOT_DIR/.cozeproj/scripts/local-workspace.cjs" pack "$@"
7
+ fi
4
8
  COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-${ROOT_DIR}}"
5
9
  export COZE_WORKSPACE_PATH
6
10
 
7
11
  cd "${COZE_WORKSPACE_PATH}"
8
12
 
9
- # build_weapp.sh - 通过 PID 文件精确杀掉自己上次的构建进程
10
- PID_FILE="/tmp/coze-build_weapp.pid"
13
+ LOG_DIR="${COZE_LOG_DIR:-/tmp}"
14
+ mkdir -p "$LOG_DIR"
15
+ PID_FILE="$LOG_DIR/coze-build_weapp.pid"
11
16
 
12
17
  # 杀掉上次的构建进程组
13
18
  if [ -f "$PID_FILE" ]; then
@@ -21,11 +26,16 @@ if [ -f "$PID_FILE" ]; then
21
26
  rm -f "$PID_FILE"
22
27
  fi
23
28
 
24
- # 用 setsid 创建新的进程组,方便下次整组杀掉
25
- setsid pnpm build:pack &
26
- echo $! > "$PID_FILE"
29
+ # 用 setsid 创建新的进程组,方便下次整组杀掉;无 setsid 的环境退化为普通后台进程。
30
+ if command -v setsid >/dev/null 2>&1; then
31
+ setsid pnpm build:pack &
32
+ else
33
+ pnpm build:pack &
34
+ fi
35
+ BUILD_PID=$!
36
+ echo "$BUILD_PID" > "$PID_FILE"
27
37
 
28
38
  echo "构建已启动 (PID: $(cat $PID_FILE))"
29
39
 
30
- wait $!
40
+ wait "$BUILD_PID"
31
41
  rm -f "$PID_FILE"
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable @typescript-eslint/no-require-imports -- Standalone CommonJS runtime shipped without CLI dependencies. */
3
+ const fs = require('node:fs');
4
+ const path = require('node:path');
5
+ const { spawn } = require('node:child_process');
6
+
7
+ const scriptRoot = fs.realpathSync(path.resolve(__dirname, '..', '..'));
8
+ const [action, target, ...extraArgs] = process.argv.slice(2);
9
+ const normalizedTarget = target === 'h5' ? 'web' : target;
10
+ const taroTypeByTarget = {
11
+ web: 'h5',
12
+ weapp: 'weapp',
13
+ tt: 'tt',
14
+ };
15
+ const validTargets = new Set(['web', 'weapp', 'tt']);
16
+ const validActions = new Set(['build', 'preview']);
17
+
18
+ function run(command, args, options = {}) {
19
+ const child = spawn(command, args, {
20
+ cwd: options.cwd || process.cwd(),
21
+ env: options.env || process.env,
22
+ stdio: 'inherit',
23
+ });
24
+ child.once('exit', (code, signal) => {
25
+ if (signal) {
26
+ process.kill(process.pid, signal);
27
+ return;
28
+ }
29
+ process.exit(code || 0);
30
+ });
31
+ child.once('error', error => {
32
+ console.error(error.message);
33
+ process.exit(1);
34
+ });
35
+ }
36
+
37
+ if (!validActions.has(action) || !validTargets.has(normalizedTarget)) {
38
+ console.error('Usage: taro-build.cjs <build|preview> <web|weapp|tt|h5> [...args]');
39
+ process.exit(1);
40
+ }
41
+
42
+ if (action === 'preview' && normalizedTarget === 'web') {
43
+ console.error('Taro preview is only supported for weapp or tt.');
44
+ process.exit(1);
45
+ }
46
+
47
+ if (process.env.COZE_TARO_LOCAL_ACTIVE !== scriptRoot) {
48
+ run(process.execPath, [
49
+ path.join(scriptRoot, '.cozeproj', 'scripts', 'local-workspace.cjs'),
50
+ 'taro-build',
51
+ action,
52
+ normalizedTarget,
53
+ ...extraArgs,
54
+ ], { cwd: scriptRoot });
55
+ return;
56
+ }
57
+
58
+ const taroArgs = ['exec', 'taro', 'build', '--type', taroTypeByTarget[normalizedTarget]];
59
+ if (action === 'preview') {
60
+ taroArgs.push('--preview');
61
+ }
62
+ taroArgs.push(...extraArgs);
63
+
64
+ run('pnpm', taroArgs, {
65
+ cwd: process.env.COZE_WORKSPACE_PATH || scriptRoot,
66
+ });
@@ -2,6 +2,9 @@
2
2
  set -Eeuo pipefail
3
3
 
4
4
  ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5
+ if [[ "${COZE_TARO_LOCAL_ACTIVE:-}" != "${ROOT_DIR}" ]]; then
6
+ exec node "$ROOT_DIR/.cozeproj/scripts/local-workspace.cjs" validate "$@"
7
+ fi
5
8
  COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-${ROOT_DIR}}"
6
9
  export COZE_WORKSPACE_PATH
7
10
 
@@ -7,9 +7,9 @@
7
7
  "build": "pnpm exec concurrently --kill-others-on-fail --kill-signal SIGKILL -n lint,tsc,web,weapp,tt,server -c red,blue,green,yellow,cyan,magenta \"pnpm lint:build\" \"pnpm tsc\" \"pnpm build:web\" \"pnpm build:weapp\" \"pnpm build:tt\" \"pnpm build:server\"",
8
8
  "build:pack": "pnpm exec concurrently --kill-others-on-fail --kill-signal SIGKILL -n weapp,tt -c yellow,cyan \"pnpm build:weapp\" \"pnpm build:tt\"",
9
9
  "build:server": "pnpm --filter server build",
10
- "build:tt": "taro build --type tt",
11
- "build:weapp": "taro build --type weapp",
12
- "build:web": "taro build --type h5",
10
+ "build:tt": "node .cozeproj/scripts/taro-build.cjs build tt",
11
+ "build:weapp": "node .cozeproj/scripts/taro-build.cjs build weapp",
12
+ "build:web": "node .cozeproj/scripts/taro-build.cjs build web",
13
13
  "dev": "pnpm exec concurrently --kill-others --kill-signal SIGKILL -n web,server -c blue,green \"pnpm dev:web\" \"pnpm dev:server\"",
14
14
  "dev:server": "pnpm --filter server dev",
15
15
  "dev:tt": "taro build --type tt --watch",
@@ -22,8 +22,8 @@
22
22
  "lint:build": "eslint \"src/**/*.{js,jsx,ts,tsx,css}\" --max-warnings=0 --quiet",
23
23
  "lint:fix": "eslint \"src/**/*.{js,jsx,ts,tsx,css}\" --fix",
24
24
  "new": "taro new",
25
- "preview:tt": "taro build --type tt --preview",
26
- "preview:weapp": "taro build --type weapp --preview",
25
+ "preview:tt": "node .cozeproj/scripts/taro-build.cjs preview tt",
26
+ "preview:weapp": "node .cozeproj/scripts/taro-build.cjs preview weapp",
27
27
  "tsc": "npx tsc --noEmit --skipLibCheck",
28
28
  "validate": "pnpm exec concurrently --kill-others-on-fail --kill-signal SIGKILL -n lint,tsc -c red,blue \"pnpm lint:build\" \"pnpm tsc\""
29
29
  },
@@ -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.e237ba";
2117
+ var version = "0.1.9-alpha.01bd9e";
2118
2118
  var description = "coze coding devtools cli";
2119
2119
  var license = "MIT";
2120
2120
  var author = "fanwenjie.fe@bytedance.com";
@@ -6335,7 +6335,9 @@ const planUpgrade = async (
6335
6335
  for (const action of ACTIONS) {
6336
6336
  const file = path.join(context.projectFolder, 'scripts', `${action}.sh`);
6337
6337
  try {
6338
- if (!(await fs$1.lstat(file)).isFile()) return null;
6338
+ if (!(await fs$1.lstat(file)).isFile()) {
6339
+ return null;
6340
+ }
6339
6341
  const text = await fs$1.readFile(file, 'utf8');
6340
6342
  const match = text.match(/^PORT=[^\n]*?(\d{2,5})/m);
6341
6343
  if (match) {
@@ -6349,10 +6351,14 @@ const planUpgrade = async (
6349
6351
  line.replace(/\d+/g, '5000'),
6350
6352
  );
6351
6353
  const hash = crypto.createHash('sha256').update(normalized).digest('hex');
6352
- if (!LEGACY[template][action].includes(hash)) return null;
6354
+ if (!LEGACY[template][action].includes(hash)) {
6355
+ return null;
6356
+ }
6353
6357
  scripts.set(action, text);
6354
6358
  } catch (error) {
6355
- if ((error ).code === 'ENOENT') return null;
6359
+ if ((error ).code === 'ENOENT') {
6360
+ return null;
6361
+ }
6356
6362
  throw error;
6357
6363
  }
6358
6364
  }
@@ -6361,7 +6367,9 @@ const planUpgrade = async (
6361
6367
  await fs$1.lstat(path.join(context.projectFolder, 'scripts', HELPER));
6362
6368
  return null;
6363
6369
  } catch (error) {
6364
- if ((error ).code !== 'ENOENT') throw error;
6370
+ if ((error ).code !== 'ENOENT') {
6371
+ throw error;
6372
+ }
6365
6373
  }
6366
6374
  return port === undefined ? null : { port, scripts };
6367
6375
  };
@@ -6402,9 +6410,11 @@ const createPatch = (template) => ({
6402
6410
  const replacements = new Map();
6403
6411
  replacements.set(HELPER, await fs$1.readFile(path.join(origin, HELPER), 'utf8'));
6404
6412
  for (const action of ACTIONS) {
6413
+ const content = await renderTemplate(path.join(origin, `${action}.sh`), { port: plan.port });
6405
6414
  replacements.set(
6406
6415
  `${action}.sh`,
6407
- await renderTemplate(path.join(origin, `${action}.sh`), { port: plan.port }),
6416
+ // The recognized legacy Next.js wrappers use Webpack; preserve their bundler.
6417
+ template === 'nextjs' ? content.replace(/\bnext dev\b/g, 'next dev --webpack') : content,
6408
6418
  );
6409
6419
  }
6410
6420
  try {
@@ -6425,7 +6435,9 @@ const createPatch = (template) => ({
6425
6435
  throw error;
6426
6436
  }
6427
6437
  const dev = context.cozeConfig.dev;
6428
- if (dev) dev.deps = [...new Set([...(dev.deps || []), 'rsync'])];
6438
+ if (dev) {
6439
+ dev.deps = [...new Set([...(dev.deps || []), 'rsync'])];
6440
+ }
6429
6441
  return {
6430
6442
  applied: true, patchId,
6431
6443
  message: 'Web development wrappers now sync Drive source and execute on local disk',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/cli",
3
- "version": "0.1.8-alpha.e237ba",
3
+ "version": "0.1.9-alpha.01bd9e",
4
4
  "private": false,
5
5
  "description": "coze coding devtools cli",
6
6
  "license": "MIT",