@coze-arch/cli 0.1.4-alpha.fb90f3 → 0.1.5-alpha.2e246f

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 (42) hide show
  1. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.ps1 +1 -1
  2. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +3 -3
  3. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.ps1 +3 -3
  4. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +0 -2
  5. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +3 -3
  6. package/lib/__templates__/expo/client/components/Screen.tsx +25 -65
  7. package/lib/__templates__/expo/client/heroui/components/toast/toast.tsx +2 -6
  8. package/lib/__templates__/expo/client/heroui/helpers/internal/hooks/use-controllable-state.ts +1 -1
  9. package/lib/__templates__/nextjs/.babelrc +15 -0
  10. package/lib/__templates__/nextjs/eslint.config.mjs +5 -11
  11. package/lib/__templates__/nextjs/next.config.ts +0 -10
  12. package/lib/__templates__/nextjs/package.json +6 -3
  13. package/lib/__templates__/nextjs/pnpm-lock.yaml +1071 -136
  14. package/lib/__templates__/nextjs/scripts/build.ps1 +1 -1
  15. package/lib/__templates__/nextjs/scripts/build.sh +2 -3
  16. package/lib/__templates__/nextjs/scripts/dev.sh +3 -6
  17. package/lib/__templates__/nextjs/scripts/prepare.sh +4 -1
  18. package/lib/__templates__/nextjs/src/app/layout.tsx +4 -0
  19. package/lib/__templates__/nextjs/src/server.ts +1 -1
  20. package/lib/__templates__/nextjs/template.config.js +59 -0
  21. package/lib/__templates__/nuxt-vue/scripts/build.sh +1 -1
  22. package/lib/__templates__/nuxt-vue/scripts/dev.sh +0 -2
  23. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +4 -1
  24. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +2 -3
  25. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +0 -3
  26. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +1 -3
  27. package/lib/__templates__/vite/scripts/build.ps1 +1 -4
  28. package/lib/__templates__/vite/scripts/build.sh +1 -1
  29. package/lib/__templates__/vite/scripts/dev.ps1 +23 -7
  30. package/lib/__templates__/vite/scripts/dev.sh +0 -2
  31. package/lib/__templates__/vite/scripts/ensure-deps.ps1 +33 -0
  32. package/lib/__templates__/vite/scripts/prepare.ps1 +1 -6
  33. package/lib/__templates__/vite/scripts/prepare.sh +4 -1
  34. package/lib/__templates__/vite/template.config.js +59 -0
  35. package/lib/cli.js +19 -38
  36. package/package.json +1 -1
  37. package/lib/__templates__/expo/.cozeproj/scripts/prepare-node-modules.sh +0 -149
  38. package/lib/__templates__/nextjs/scripts/prepare-next-output.sh +0 -62
  39. package/lib/__templates__/nextjs/scripts/prepare-node-modules.sh +0 -149
  40. package/lib/__templates__/nuxt-vue/scripts/prepare-node-modules.sh +0 -149
  41. package/lib/__templates__/taro/.cozeproj/scripts/prepare-node-modules.sh +0 -149
  42. package/lib/__templates__/vite/scripts/prepare-node-modules.sh +0 -149
@@ -1,149 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Install dependencies on local disk and expose them to the source tree by symlink.
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
- command -v pnpm >/dev/null 2>&1 || {
13
- echo "[node_modules] pnpm is required" >&2
14
- exit 1
15
- }
16
-
17
- DRIVE_ROOT="${COZE_DRIVE_ROOT:-/Coze/Drive}"
18
- if [ -d "$DRIVE_ROOT" ]; then
19
- DRIVE_ROOT="$(cd "$DRIVE_ROOT" && pwd -P)"
20
- else
21
- DRIVE_ROOT="${DRIVE_ROOT%/}"
22
- fi
23
- case "$PROJECT_ROOT" in
24
- "$DRIVE_ROOT"|"$DRIVE_ROOT"/*) ;;
25
- *)
26
- (cd "$PROJECT_ROOT" && pnpm install "$@")
27
- exit 0
28
- ;;
29
- esac
30
-
31
- NM_ROOT="/tmp/nm"
32
- PROJECT_ID="$(basename "$PROJECT_ROOT")-$(printf '%s' "$PROJECT_ROOT" | cksum | awk '{print $1}')"
33
- mkdir -p "$NM_ROOT"
34
- WORK_DIR="$NM_ROOT/$PROJECT_ID"
35
- case "$WORK_DIR" in
36
- "$DRIVE_ROOT"|"$DRIVE_ROOT"/*)
37
- echo "[node_modules] local dependency directory must not be on Coze Drive: $WORK_DIR" >&2
38
- exit 1
39
- ;;
40
- esac
41
-
42
- LOCK_DIR="$NM_ROOT/$PROJECT_ID.lock"
43
- while ! mkdir "$LOCK_DIR" 2>/dev/null; do
44
- echo "[node_modules] Waiting for another dependency preparation for this project..."
45
- sleep 1
46
- done
47
- trap 'rmdir "$LOCK_DIR" 2>/dev/null || true' EXIT
48
-
49
- mkdir -p "$WORK_DIR"
50
-
51
- # Mirror the project with symlinks. node_modules and managed compiler output
52
- # stay real in WORK_DIR; workspace directories stay real there too.
53
- mirror_root() {
54
- local entry name
55
- while IFS= read -r -d '' entry; do
56
- name="$(basename "$entry")"
57
- case "$name" in
58
- node_modules|pnpm-lock.yaml|.next) continue ;;
59
- client|server)
60
- [ -f "$PROJECT_ROOT/$name/package.json" ] && continue
61
- ;;
62
- esac
63
- rm -rf "$entry"
64
- done < <(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -print0)
65
-
66
- while IFS= read -r -d '' entry; do
67
- name="$(basename "$entry")"
68
- case "$name" in
69
- node_modules|pnpm-lock.yaml|.next) continue ;;
70
- client|server)
71
- [ -f "$entry/package.json" ] && continue
72
- ;;
73
- esac
74
- ln -s "$entry" "$WORK_DIR/$name"
75
- done < <(find "$PROJECT_ROOT" -mindepth 1 -maxdepth 1 -print0)
76
- }
77
-
78
- mirror_workspace() {
79
- local workspace="$1" source_dir="$PROJECT_ROOT/$1" work_dir="$WORK_DIR/$1"
80
- local entry name
81
- if [ -L "$work_dir" ] || { [ -e "$work_dir" ] && [ ! -d "$work_dir" ]; }; then
82
- rm -rf "$work_dir"
83
- fi
84
- mkdir -p "$work_dir"
85
-
86
- while IFS= read -r -d '' entry; do
87
- [ "$(basename "$entry")" = "node_modules" ] || rm -rf "$entry"
88
- done < <(find "$work_dir" -mindepth 1 -maxdepth 1 -print0)
89
-
90
- while IFS= read -r -d '' entry; do
91
- name="$(basename "$entry")"
92
- [ "$name" = "node_modules" ] || ln -s "$entry" "$work_dir/$name"
93
- done < <(find "$source_dir" -mindepth 1 -maxdepth 1 -print0)
94
- }
95
-
96
- mirror_root
97
- for workspace in client server; do
98
- if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
99
- mirror_workspace "$workspace"
100
- fi
101
- done
102
-
103
- # pnpm refuses to update a symlinked lockfile, so install against a local copy.
104
- rm -rf "$WORK_DIR/pnpm-lock.yaml"
105
- if [ -f "$PROJECT_ROOT/pnpm-lock.yaml" ]; then
106
- cp "$PROJECT_ROOT/pnpm-lock.yaml" "$WORK_DIR/pnpm-lock.yaml"
107
- fi
108
-
109
- echo "[node_modules] Installing dependencies in $WORK_DIR"
110
- if ! (cd "$WORK_DIR" && pnpm install "$@"); then
111
- rm -f "$WORK_DIR/pnpm-lock.yaml"
112
- exit 1
113
- fi
114
-
115
- if [ -f "$WORK_DIR/pnpm-lock.yaml" ]; then
116
- temporary_lockfile="$(mktemp "$PROJECT_ROOT/.pnpm-lock.yaml.XXXXXX")"
117
- cp "$WORK_DIR/pnpm-lock.yaml" "$temporary_lockfile"
118
- chmod 0644 "$temporary_lockfile"
119
- mv -f "$temporary_lockfile" "$PROJECT_ROOT/pnpm-lock.yaml"
120
- fi
121
-
122
- link_node_modules() {
123
- local source_dir="$1" target_dir="$2"
124
- local current=""
125
- mkdir -p "$target_dir"
126
- if [ -L "$source_dir/node_modules" ]; then
127
- current="$(readlink "$source_dir/node_modules")"
128
- case "$current" in
129
- "$NM_ROOT"/*/node_modules|"$NM_ROOT"/*/*/node_modules) ;;
130
- *)
131
- echo "[node_modules] refusing to replace unmanaged symlink: $source_dir/node_modules" >&2
132
- exit 1
133
- ;;
134
- esac
135
- rm "$source_dir/node_modules"
136
- elif [ -e "$source_dir/node_modules" ]; then
137
- rm -rf "$source_dir/node_modules"
138
- fi
139
- ln -s "$target_dir" "$source_dir/node_modules"
140
- }
141
-
142
- link_node_modules "$PROJECT_ROOT" "$WORK_DIR/node_modules"
143
- for workspace in client server; do
144
- if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
145
- link_node_modules "$PROJECT_ROOT/$workspace" "$WORK_DIR/$workspace/node_modules"
146
- fi
147
- done
148
-
149
- echo "[node_modules] Dependencies ready"
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Keep Next.js compiler output off Coze Drive while leaving source files in place.
3
- set -euo pipefail
4
-
5
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
6
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
7
-
8
- DRIVE_ROOT="${COZE_DRIVE_ROOT:-/Coze/Drive}"
9
- if [ -d "$DRIVE_ROOT" ]; then
10
- DRIVE_ROOT="$(cd "$DRIVE_ROOT" && pwd -P)"
11
- else
12
- DRIVE_ROOT="${DRIVE_ROOT%/}"
13
- fi
14
- case "$PROJECT_ROOT" in
15
- "$DRIVE_ROOT"|"$DRIVE_ROOT"/*) ;;
16
- *) exit 0 ;;
17
- esac
18
-
19
- NM_ROOT="/tmp/nm"
20
- PROJECT_ID="$(basename "$PROJECT_ROOT")-$(printf '%s' "$PROJECT_ROOT" | cksum | awk '{print $1}')"
21
- NEXT_DIR="$NM_ROOT/$PROJECT_ID/.next"
22
- LEGACY_NEXT_DIR="$NM_ROOT/next/$PROJECT_ID"
23
-
24
- if [ -L "$NEXT_DIR" ]; then
25
- current="$(readlink "$NEXT_DIR")"
26
- if [ "$current" = "$PROJECT_ROOT/.next" ]; then
27
- rm "$NEXT_DIR"
28
- else
29
- echo "[next] refusing to replace unmanaged local output symlink: $NEXT_DIR" >&2
30
- exit 1
31
- fi
32
- elif [ -e "$NEXT_DIR" ] && [ ! -d "$NEXT_DIR" ]; then
33
- echo "[next] local output path is not a directory: $NEXT_DIR" >&2
34
- exit 1
35
- fi
36
- mkdir -p "$NEXT_DIR"
37
-
38
- if [ -L "$PROJECT_ROOT/.next" ]; then
39
- current="$(readlink "$PROJECT_ROOT/.next")"
40
- if [ "$current" = "$NEXT_DIR" ]; then
41
- exit 0
42
- fi
43
- if [ "$current" = "$LEGACY_NEXT_DIR" ]; then
44
- rm "$PROJECT_ROOT/.next"
45
- else
46
- echo "[next] refusing to replace unmanaged symlink: $PROJECT_ROOT/.next" >&2
47
- exit 1
48
- fi
49
- fi
50
-
51
- if [ -e "$PROJECT_ROOT/.next" ]; then
52
- rm -rf "$PROJECT_ROOT/.next"
53
- fi
54
-
55
- if ! ln -s "$NEXT_DIR" "$PROJECT_ROOT/.next"; then
56
- if [ ! -L "$PROJECT_ROOT/.next" ] || [ "$(readlink "$PROJECT_ROOT/.next")" != "$NEXT_DIR" ]; then
57
- echo "[next] failed to link $PROJECT_ROOT/.next to $NEXT_DIR" >&2
58
- exit 1
59
- fi
60
- fi
61
-
62
- echo "[next] Compiler output ready at $NEXT_DIR"
@@ -1,149 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Install dependencies on local disk and expose them to the source tree by symlink.
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
- command -v pnpm >/dev/null 2>&1 || {
13
- echo "[node_modules] pnpm is required" >&2
14
- exit 1
15
- }
16
-
17
- DRIVE_ROOT="${COZE_DRIVE_ROOT:-/Coze/Drive}"
18
- if [ -d "$DRIVE_ROOT" ]; then
19
- DRIVE_ROOT="$(cd "$DRIVE_ROOT" && pwd -P)"
20
- else
21
- DRIVE_ROOT="${DRIVE_ROOT%/}"
22
- fi
23
- case "$PROJECT_ROOT" in
24
- "$DRIVE_ROOT"|"$DRIVE_ROOT"/*) ;;
25
- *)
26
- (cd "$PROJECT_ROOT" && pnpm install "$@")
27
- exit 0
28
- ;;
29
- esac
30
-
31
- NM_ROOT="/tmp/nm"
32
- PROJECT_ID="$(basename "$PROJECT_ROOT")-$(printf '%s' "$PROJECT_ROOT" | cksum | awk '{print $1}')"
33
- mkdir -p "$NM_ROOT"
34
- WORK_DIR="$NM_ROOT/$PROJECT_ID"
35
- case "$WORK_DIR" in
36
- "$DRIVE_ROOT"|"$DRIVE_ROOT"/*)
37
- echo "[node_modules] local dependency directory must not be on Coze Drive: $WORK_DIR" >&2
38
- exit 1
39
- ;;
40
- esac
41
-
42
- LOCK_DIR="$NM_ROOT/$PROJECT_ID.lock"
43
- while ! mkdir "$LOCK_DIR" 2>/dev/null; do
44
- echo "[node_modules] Waiting for another dependency preparation for this project..."
45
- sleep 1
46
- done
47
- trap 'rmdir "$LOCK_DIR" 2>/dev/null || true' EXIT
48
-
49
- mkdir -p "$WORK_DIR"
50
-
51
- # Mirror the project with symlinks. node_modules and managed compiler output
52
- # stay real in WORK_DIR; workspace directories stay real there too.
53
- mirror_root() {
54
- local entry name
55
- while IFS= read -r -d '' entry; do
56
- name="$(basename "$entry")"
57
- case "$name" in
58
- node_modules|pnpm-lock.yaml|.next) continue ;;
59
- client|server)
60
- [ -f "$PROJECT_ROOT/$name/package.json" ] && continue
61
- ;;
62
- esac
63
- rm -rf "$entry"
64
- done < <(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -print0)
65
-
66
- while IFS= read -r -d '' entry; do
67
- name="$(basename "$entry")"
68
- case "$name" in
69
- node_modules|pnpm-lock.yaml|.next) continue ;;
70
- client|server)
71
- [ -f "$entry/package.json" ] && continue
72
- ;;
73
- esac
74
- ln -s "$entry" "$WORK_DIR/$name"
75
- done < <(find "$PROJECT_ROOT" -mindepth 1 -maxdepth 1 -print0)
76
- }
77
-
78
- mirror_workspace() {
79
- local workspace="$1" source_dir="$PROJECT_ROOT/$1" work_dir="$WORK_DIR/$1"
80
- local entry name
81
- if [ -L "$work_dir" ] || { [ -e "$work_dir" ] && [ ! -d "$work_dir" ]; }; then
82
- rm -rf "$work_dir"
83
- fi
84
- mkdir -p "$work_dir"
85
-
86
- while IFS= read -r -d '' entry; do
87
- [ "$(basename "$entry")" = "node_modules" ] || rm -rf "$entry"
88
- done < <(find "$work_dir" -mindepth 1 -maxdepth 1 -print0)
89
-
90
- while IFS= read -r -d '' entry; do
91
- name="$(basename "$entry")"
92
- [ "$name" = "node_modules" ] || ln -s "$entry" "$work_dir/$name"
93
- done < <(find "$source_dir" -mindepth 1 -maxdepth 1 -print0)
94
- }
95
-
96
- mirror_root
97
- for workspace in client server; do
98
- if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
99
- mirror_workspace "$workspace"
100
- fi
101
- done
102
-
103
- # pnpm refuses to update a symlinked lockfile, so install against a local copy.
104
- rm -rf "$WORK_DIR/pnpm-lock.yaml"
105
- if [ -f "$PROJECT_ROOT/pnpm-lock.yaml" ]; then
106
- cp "$PROJECT_ROOT/pnpm-lock.yaml" "$WORK_DIR/pnpm-lock.yaml"
107
- fi
108
-
109
- echo "[node_modules] Installing dependencies in $WORK_DIR"
110
- if ! (cd "$WORK_DIR" && pnpm install "$@"); then
111
- rm -f "$WORK_DIR/pnpm-lock.yaml"
112
- exit 1
113
- fi
114
-
115
- if [ -f "$WORK_DIR/pnpm-lock.yaml" ]; then
116
- temporary_lockfile="$(mktemp "$PROJECT_ROOT/.pnpm-lock.yaml.XXXXXX")"
117
- cp "$WORK_DIR/pnpm-lock.yaml" "$temporary_lockfile"
118
- chmod 0644 "$temporary_lockfile"
119
- mv -f "$temporary_lockfile" "$PROJECT_ROOT/pnpm-lock.yaml"
120
- fi
121
-
122
- link_node_modules() {
123
- local source_dir="$1" target_dir="$2"
124
- local current=""
125
- mkdir -p "$target_dir"
126
- if [ -L "$source_dir/node_modules" ]; then
127
- current="$(readlink "$source_dir/node_modules")"
128
- case "$current" in
129
- "$NM_ROOT"/*/node_modules|"$NM_ROOT"/*/*/node_modules) ;;
130
- *)
131
- echo "[node_modules] refusing to replace unmanaged symlink: $source_dir/node_modules" >&2
132
- exit 1
133
- ;;
134
- esac
135
- rm "$source_dir/node_modules"
136
- elif [ -e "$source_dir/node_modules" ]; then
137
- rm -rf "$source_dir/node_modules"
138
- fi
139
- ln -s "$target_dir" "$source_dir/node_modules"
140
- }
141
-
142
- link_node_modules "$PROJECT_ROOT" "$WORK_DIR/node_modules"
143
- for workspace in client server; do
144
- if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
145
- link_node_modules "$PROJECT_ROOT/$workspace" "$WORK_DIR/$workspace/node_modules"
146
- fi
147
- done
148
-
149
- echo "[node_modules] Dependencies ready"
@@ -1,149 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Install dependencies on local disk and expose them to the source tree by symlink.
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
- command -v pnpm >/dev/null 2>&1 || {
13
- echo "[node_modules] pnpm is required" >&2
14
- exit 1
15
- }
16
-
17
- DRIVE_ROOT="${COZE_DRIVE_ROOT:-/Coze/Drive}"
18
- if [ -d "$DRIVE_ROOT" ]; then
19
- DRIVE_ROOT="$(cd "$DRIVE_ROOT" && pwd -P)"
20
- else
21
- DRIVE_ROOT="${DRIVE_ROOT%/}"
22
- fi
23
- case "$PROJECT_ROOT" in
24
- "$DRIVE_ROOT"|"$DRIVE_ROOT"/*) ;;
25
- *)
26
- (cd "$PROJECT_ROOT" && pnpm install "$@")
27
- exit 0
28
- ;;
29
- esac
30
-
31
- NM_ROOT="/tmp/nm"
32
- PROJECT_ID="$(basename "$PROJECT_ROOT")-$(printf '%s' "$PROJECT_ROOT" | cksum | awk '{print $1}')"
33
- mkdir -p "$NM_ROOT"
34
- WORK_DIR="$NM_ROOT/$PROJECT_ID"
35
- case "$WORK_DIR" in
36
- "$DRIVE_ROOT"|"$DRIVE_ROOT"/*)
37
- echo "[node_modules] local dependency directory must not be on Coze Drive: $WORK_DIR" >&2
38
- exit 1
39
- ;;
40
- esac
41
-
42
- LOCK_DIR="$NM_ROOT/$PROJECT_ID.lock"
43
- while ! mkdir "$LOCK_DIR" 2>/dev/null; do
44
- echo "[node_modules] Waiting for another dependency preparation for this project..."
45
- sleep 1
46
- done
47
- trap 'rmdir "$LOCK_DIR" 2>/dev/null || true' EXIT
48
-
49
- mkdir -p "$WORK_DIR"
50
-
51
- # Mirror the project with symlinks. node_modules and managed compiler output
52
- # stay real in WORK_DIR; workspace directories stay real there too.
53
- mirror_root() {
54
- local entry name
55
- while IFS= read -r -d '' entry; do
56
- name="$(basename "$entry")"
57
- case "$name" in
58
- node_modules|pnpm-lock.yaml|.next) continue ;;
59
- client|server)
60
- [ -f "$PROJECT_ROOT/$name/package.json" ] && continue
61
- ;;
62
- esac
63
- rm -rf "$entry"
64
- done < <(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -print0)
65
-
66
- while IFS= read -r -d '' entry; do
67
- name="$(basename "$entry")"
68
- case "$name" in
69
- node_modules|pnpm-lock.yaml|.next) continue ;;
70
- client|server)
71
- [ -f "$entry/package.json" ] && continue
72
- ;;
73
- esac
74
- ln -s "$entry" "$WORK_DIR/$name"
75
- done < <(find "$PROJECT_ROOT" -mindepth 1 -maxdepth 1 -print0)
76
- }
77
-
78
- mirror_workspace() {
79
- local workspace="$1" source_dir="$PROJECT_ROOT/$1" work_dir="$WORK_DIR/$1"
80
- local entry name
81
- if [ -L "$work_dir" ] || { [ -e "$work_dir" ] && [ ! -d "$work_dir" ]; }; then
82
- rm -rf "$work_dir"
83
- fi
84
- mkdir -p "$work_dir"
85
-
86
- while IFS= read -r -d '' entry; do
87
- [ "$(basename "$entry")" = "node_modules" ] || rm -rf "$entry"
88
- done < <(find "$work_dir" -mindepth 1 -maxdepth 1 -print0)
89
-
90
- while IFS= read -r -d '' entry; do
91
- name="$(basename "$entry")"
92
- [ "$name" = "node_modules" ] || ln -s "$entry" "$work_dir/$name"
93
- done < <(find "$source_dir" -mindepth 1 -maxdepth 1 -print0)
94
- }
95
-
96
- mirror_root
97
- for workspace in client server; do
98
- if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
99
- mirror_workspace "$workspace"
100
- fi
101
- done
102
-
103
- # pnpm refuses to update a symlinked lockfile, so install against a local copy.
104
- rm -rf "$WORK_DIR/pnpm-lock.yaml"
105
- if [ -f "$PROJECT_ROOT/pnpm-lock.yaml" ]; then
106
- cp "$PROJECT_ROOT/pnpm-lock.yaml" "$WORK_DIR/pnpm-lock.yaml"
107
- fi
108
-
109
- echo "[node_modules] Installing dependencies in $WORK_DIR"
110
- if ! (cd "$WORK_DIR" && pnpm install "$@"); then
111
- rm -f "$WORK_DIR/pnpm-lock.yaml"
112
- exit 1
113
- fi
114
-
115
- if [ -f "$WORK_DIR/pnpm-lock.yaml" ]; then
116
- temporary_lockfile="$(mktemp "$PROJECT_ROOT/.pnpm-lock.yaml.XXXXXX")"
117
- cp "$WORK_DIR/pnpm-lock.yaml" "$temporary_lockfile"
118
- chmod 0644 "$temporary_lockfile"
119
- mv -f "$temporary_lockfile" "$PROJECT_ROOT/pnpm-lock.yaml"
120
- fi
121
-
122
- link_node_modules() {
123
- local source_dir="$1" target_dir="$2"
124
- local current=""
125
- mkdir -p "$target_dir"
126
- if [ -L "$source_dir/node_modules" ]; then
127
- current="$(readlink "$source_dir/node_modules")"
128
- case "$current" in
129
- "$NM_ROOT"/*/node_modules|"$NM_ROOT"/*/*/node_modules) ;;
130
- *)
131
- echo "[node_modules] refusing to replace unmanaged symlink: $source_dir/node_modules" >&2
132
- exit 1
133
- ;;
134
- esac
135
- rm "$source_dir/node_modules"
136
- elif [ -e "$source_dir/node_modules" ]; then
137
- rm -rf "$source_dir/node_modules"
138
- fi
139
- ln -s "$target_dir" "$source_dir/node_modules"
140
- }
141
-
142
- link_node_modules "$PROJECT_ROOT" "$WORK_DIR/node_modules"
143
- for workspace in client server; do
144
- if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
145
- link_node_modules "$PROJECT_ROOT/$workspace" "$WORK_DIR/$workspace/node_modules"
146
- fi
147
- done
148
-
149
- echo "[node_modules] Dependencies ready"
@@ -1,149 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Install dependencies on local disk and expose them to the source tree by symlink.
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
- command -v pnpm >/dev/null 2>&1 || {
13
- echo "[node_modules] pnpm is required" >&2
14
- exit 1
15
- }
16
-
17
- DRIVE_ROOT="${COZE_DRIVE_ROOT:-/Coze/Drive}"
18
- if [ -d "$DRIVE_ROOT" ]; then
19
- DRIVE_ROOT="$(cd "$DRIVE_ROOT" && pwd -P)"
20
- else
21
- DRIVE_ROOT="${DRIVE_ROOT%/}"
22
- fi
23
- case "$PROJECT_ROOT" in
24
- "$DRIVE_ROOT"|"$DRIVE_ROOT"/*) ;;
25
- *)
26
- (cd "$PROJECT_ROOT" && pnpm install "$@")
27
- exit 0
28
- ;;
29
- esac
30
-
31
- NM_ROOT="/tmp/nm"
32
- PROJECT_ID="$(basename "$PROJECT_ROOT")-$(printf '%s' "$PROJECT_ROOT" | cksum | awk '{print $1}')"
33
- mkdir -p "$NM_ROOT"
34
- WORK_DIR="$NM_ROOT/$PROJECT_ID"
35
- case "$WORK_DIR" in
36
- "$DRIVE_ROOT"|"$DRIVE_ROOT"/*)
37
- echo "[node_modules] local dependency directory must not be on Coze Drive: $WORK_DIR" >&2
38
- exit 1
39
- ;;
40
- esac
41
-
42
- LOCK_DIR="$NM_ROOT/$PROJECT_ID.lock"
43
- while ! mkdir "$LOCK_DIR" 2>/dev/null; do
44
- echo "[node_modules] Waiting for another dependency preparation for this project..."
45
- sleep 1
46
- done
47
- trap 'rmdir "$LOCK_DIR" 2>/dev/null || true' EXIT
48
-
49
- mkdir -p "$WORK_DIR"
50
-
51
- # Mirror the project with symlinks. node_modules and managed compiler output
52
- # stay real in WORK_DIR; workspace directories stay real there too.
53
- mirror_root() {
54
- local entry name
55
- while IFS= read -r -d '' entry; do
56
- name="$(basename "$entry")"
57
- case "$name" in
58
- node_modules|pnpm-lock.yaml|.next) continue ;;
59
- client|server)
60
- [ -f "$PROJECT_ROOT/$name/package.json" ] && continue
61
- ;;
62
- esac
63
- rm -rf "$entry"
64
- done < <(find "$WORK_DIR" -mindepth 1 -maxdepth 1 -print0)
65
-
66
- while IFS= read -r -d '' entry; do
67
- name="$(basename "$entry")"
68
- case "$name" in
69
- node_modules|pnpm-lock.yaml|.next) continue ;;
70
- client|server)
71
- [ -f "$entry/package.json" ] && continue
72
- ;;
73
- esac
74
- ln -s "$entry" "$WORK_DIR/$name"
75
- done < <(find "$PROJECT_ROOT" -mindepth 1 -maxdepth 1 -print0)
76
- }
77
-
78
- mirror_workspace() {
79
- local workspace="$1" source_dir="$PROJECT_ROOT/$1" work_dir="$WORK_DIR/$1"
80
- local entry name
81
- if [ -L "$work_dir" ] || { [ -e "$work_dir" ] && [ ! -d "$work_dir" ]; }; then
82
- rm -rf "$work_dir"
83
- fi
84
- mkdir -p "$work_dir"
85
-
86
- while IFS= read -r -d '' entry; do
87
- [ "$(basename "$entry")" = "node_modules" ] || rm -rf "$entry"
88
- done < <(find "$work_dir" -mindepth 1 -maxdepth 1 -print0)
89
-
90
- while IFS= read -r -d '' entry; do
91
- name="$(basename "$entry")"
92
- [ "$name" = "node_modules" ] || ln -s "$entry" "$work_dir/$name"
93
- done < <(find "$source_dir" -mindepth 1 -maxdepth 1 -print0)
94
- }
95
-
96
- mirror_root
97
- for workspace in client server; do
98
- if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
99
- mirror_workspace "$workspace"
100
- fi
101
- done
102
-
103
- # pnpm refuses to update a symlinked lockfile, so install against a local copy.
104
- rm -rf "$WORK_DIR/pnpm-lock.yaml"
105
- if [ -f "$PROJECT_ROOT/pnpm-lock.yaml" ]; then
106
- cp "$PROJECT_ROOT/pnpm-lock.yaml" "$WORK_DIR/pnpm-lock.yaml"
107
- fi
108
-
109
- echo "[node_modules] Installing dependencies in $WORK_DIR"
110
- if ! (cd "$WORK_DIR" && pnpm install "$@"); then
111
- rm -f "$WORK_DIR/pnpm-lock.yaml"
112
- exit 1
113
- fi
114
-
115
- if [ -f "$WORK_DIR/pnpm-lock.yaml" ]; then
116
- temporary_lockfile="$(mktemp "$PROJECT_ROOT/.pnpm-lock.yaml.XXXXXX")"
117
- cp "$WORK_DIR/pnpm-lock.yaml" "$temporary_lockfile"
118
- chmod 0644 "$temporary_lockfile"
119
- mv -f "$temporary_lockfile" "$PROJECT_ROOT/pnpm-lock.yaml"
120
- fi
121
-
122
- link_node_modules() {
123
- local source_dir="$1" target_dir="$2"
124
- local current=""
125
- mkdir -p "$target_dir"
126
- if [ -L "$source_dir/node_modules" ]; then
127
- current="$(readlink "$source_dir/node_modules")"
128
- case "$current" in
129
- "$NM_ROOT"/*/node_modules|"$NM_ROOT"/*/*/node_modules) ;;
130
- *)
131
- echo "[node_modules] refusing to replace unmanaged symlink: $source_dir/node_modules" >&2
132
- exit 1
133
- ;;
134
- esac
135
- rm "$source_dir/node_modules"
136
- elif [ -e "$source_dir/node_modules" ]; then
137
- rm -rf "$source_dir/node_modules"
138
- fi
139
- ln -s "$target_dir" "$source_dir/node_modules"
140
- }
141
-
142
- link_node_modules "$PROJECT_ROOT" "$WORK_DIR/node_modules"
143
- for workspace in client server; do
144
- if [ -f "$PROJECT_ROOT/$workspace/package.json" ]; then
145
- link_node_modules "$PROJECT_ROOT/$workspace" "$WORK_DIR/$workspace/node_modules"
146
- fi
147
- done
148
-
149
- echo "[node_modules] Dependencies ready"