Skip to content

Commit 36cdb34

Browse files
authored
Merge pull request #1407 from appwrite/fix/ts-sdk-review-comments
fix: resolve TS SDK review comments
2 parents 840b8e6 + caea44f commit 36cdb34

16 files changed

Lines changed: 123 additions & 39 deletions

File tree

.github/scripts/max-line-length.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ for glob in "${glob_array[@]}"; do
4444
if [ $? -eq 1 ]; then
4545
found_lines=1
4646
fi
47-
done < <(find "$folder_path" -type f -name "$glob" -print0)
47+
done < <(find "$folder_path" -type f -name "$glob" \
48+
! -name "*.lock" ! -name "*.lock.*" ! -name "*-lock.*" -print0)
4849
done
4950

5051
# Exit with appropriate code

scripts/update-lockfiles.sh

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,55 @@ strip_twig() {
2020
sed 's/{{[^}]*}}/PLACEHOLDER/g' "$1"
2121
}
2222

23+
replace_first() {
24+
# POSIX-portable first-match replacement (no GNU sed required).
25+
# Exits with code 2 if the pattern is not found.
26+
# Usage: replace_first <file> <literal_old> <literal_new>
27+
local file="$1" old="$2" new="$3"
28+
awk -v o="$old" -v n="$new" -v done=0 \
29+
'{ if (!done && index($0, o)) { sub(o, n); done=1 } print } END { exit(done ? 0 : 2) }' \
30+
"$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
31+
}
32+
33+
restore_twig_npm() {
34+
# Replace PLACEHOLDER values in package-lock.json with the correct
35+
# Twig expressions extracted from the corresponding package.json.twig.
36+
# PLACEHOLDER appears in: root "name", root "version",
37+
# packages[""] "name", "version", "license".
38+
local lockfile="$1"
39+
local twig_name="$2"
40+
41+
replace_first "$lockfile" '"name": "PLACEHOLDER"' "\"name\": \"${twig_name}\""
42+
replace_first "$lockfile" '"version": "PLACEHOLDER"' '"version": "{{ sdk.version }}"'
43+
replace_first "$lockfile" '"name": "PLACEHOLDER"' "\"name\": \"${twig_name}\""
44+
replace_first "$lockfile" '"version": "PLACEHOLDER"' '"version": "{{ sdk.version }}"'
45+
replace_first "$lockfile" '"license": "PLACEHOLDER"' '"license": "{{ sdk.license }}"'
46+
47+
if grep -q '"PLACEHOLDER"' "$lockfile"; then
48+
echo "ERROR: unresolved PLACEHOLDER values remain in $lockfile" >&2
49+
return 1
50+
fi
51+
}
52+
53+
restore_twig_bun() {
54+
# Replace PLACEHOLDER in bun.lock with the correct Twig expression.
55+
local lockfile="$1"
56+
local twig_name="$2"
57+
58+
replace_first "$lockfile" '"name": "PLACEHOLDER"' "\"name\": \"${twig_name}\""
59+
60+
if grep -q '"PLACEHOLDER"' "$lockfile"; then
61+
echo "ERROR: unresolved PLACEHOLDER values remain in $lockfile" >&2
62+
return 1
63+
fi
64+
}
65+
2366
update_npm() {
2467
local lang="$1"
2568
local extra_flags="${2:-}"
69+
local twig_name="$3"
2670
local template="$ROOT/templates/$lang/package.json.twig"
27-
local dest="$ROOT/templates/$lang/package-lock.json"
71+
local dest="$ROOT/templates/$lang/package-lock.json.twig"
2872
local dir="$WORKDIR/$lang"
2973

3074
echo "$lang (npm)"
@@ -33,32 +77,35 @@ update_npm() {
3377
# shellcheck disable=SC2086
3478
(cd "$dir" && npm install --package-lock-only --ignore-scripts --silent $extra_flags 2>/dev/null)
3579
cp "$dir/package-lock.json" "$dest"
36-
echo " updated templates/$lang/package-lock.json"
80+
restore_twig_npm "$dest" "$twig_name"
81+
echo " updated templates/$lang/package-lock.json.twig"
3782
}
3883

3984
update_bun() {
85+
local twig_name="$1"
4086
local dir="$WORKDIR/cli"
4187
local template="$ROOT/templates/cli/package.json.twig"
42-
local dest="$ROOT/templates/cli/bun.lock"
88+
local dest="$ROOT/templates/cli/bun.lock.twig"
4389

4490
echo "→ cli (bun)"
4591
mkdir -p "$dir"
4692
strip_twig "$template" > "$dir/package.json"
4793
cd "$dir" && bun install --silent 2>/dev/null
4894
cp "$dir/bun.lock" "$dest"
49-
echo " updated templates/cli/bun.lock"
95+
restore_twig_bun "$dest" "$twig_name"
96+
echo " updated templates/cli/bun.lock.twig"
5097
}
5198

5299
case "$TARGET" in
53-
web) update_npm web ;;
54-
node) update_npm node ;;
55-
react-native) update_npm react-native --legacy-peer-deps ;;
56-
cli) update_bun ;;
100+
web) update_npm web "" "{{ language.params.npmPackage }}" ;;
101+
node) update_npm node "" "{{ language.params.npmPackage | caseDash }}" ;;
102+
react-native) update_npm react-native --legacy-peer-deps "{{ language.params.npmPackage }}" ;;
103+
cli) update_bun "{{ language.params.npmPackage|caseDash }}" ;;
57104
all)
58-
update_npm web
59-
update_npm node
60-
update_npm react-native --legacy-peer-deps
61-
update_bun
105+
update_npm web "" "{{ language.params.npmPackage }}"
106+
update_npm node "" "{{ language.params.npmPackage | caseDash }}"
107+
update_npm react-native --legacy-peer-deps "{{ language.params.npmPackage }}"
108+
update_bun "{{ language.params.npmPackage|caseDash }}"
62109
;;
63110
*)
64111
echo "Unknown target: $TARGET. Use web | node | react-native | cli | all"

src/SDK/Language/CLI.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ public function getFiles(): array
204204
'template' => 'cli/bunfig.toml',
205205
],
206206
[
207-
'scope' => 'copy',
207+
'scope' => 'default',
208208
'destination' => 'bun.lock',
209-
'template' => 'cli/bun.lock',
209+
'template' => 'cli/bun.lock.twig',
210210
],
211211
[
212212
'scope' => 'default',

src/SDK/Language/Node.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ public function getFiles(): array
256256
'template' => 'node/.gitignore',
257257
],
258258
[
259-
'scope' => 'copy',
259+
'scope' => 'default',
260260
'destination' => 'package-lock.json',
261-
'template' => 'node/package-lock.json',
261+
'template' => 'node/package-lock.json.twig',
262262
],
263263
];
264264
}

src/SDK/Language/ReactNative.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ public function getFiles(): array
136136
'template' => 'react-native/.gitignore',
137137
],
138138
[
139-
'scope' => 'copy',
139+
'scope' => 'default',
140140
'destination' => 'package-lock.json',
141-
'template' => 'react-native/package-lock.json',
141+
'template' => 'react-native/package-lock.json.twig',
142142
],
143143
];
144144
}

src/SDK/Language/Web.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ public function getFiles(): array
156156
'template' => 'web/.gitignore',
157157
],
158158
[
159-
'scope' => 'copy',
159+
'scope' => 'default',
160160
'destination' => 'package-lock.json',
161-
'template' => 'web/package-lock.json',
161+
'template' => 'web/package-lock.json.twig',
162162
],
163163
];
164164
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"configVersion": 1,
44
"workspaces": {
55
"": {
6-
"name": "PLACEHOLDER",
6+
"name": "{{ language.params.npmPackage|caseDash }}",
77
"dependencies": {
88
"@appwrite.io/console": "*",
99
"chalk": "4.1.2",

templates/cli/lib/client.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ class Client {
156156
return this;
157157
}
158158

159+
/**
160+
* Get Headers
161+
*
162+
* Returns a copy of the current request headers, including any
163+
* authentication headers. Handle with care.
164+
*
165+
* @returns {Headers}
166+
*/
159167
getHeaders(): Headers {
160168
return { ...this.headers };
161169
}
Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/node/src/client.ts.twig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ class Client {
180180
return this;
181181
}
182182

183+
/**
184+
* Get Headers
185+
*
186+
* Returns a copy of the current request headers, including any
187+
* authentication headers. Handle with care.
188+
*
189+
* @returns {Headers}
190+
*/
183191
getHeaders(): Headers {
184192
return { ...this.headers };
185193
}

0 commit comments

Comments
 (0)