diff --git a/.github/scripts/max-line-length.sh b/.github/scripts/max-line-length.sh index febd2225e4..e8fdcd847f 100755 --- a/.github/scripts/max-line-length.sh +++ b/.github/scripts/max-line-length.sh @@ -44,7 +44,8 @@ for glob in "${glob_array[@]}"; do if [ $? -eq 1 ]; then found_lines=1 fi - done < <(find "$folder_path" -type f -name "$glob" -print0) + done < <(find "$folder_path" -type f -name "$glob" \ + ! -name "*.lock" ! -name "*.lock.*" ! -name "*-lock.*" -print0) done # Exit with appropriate code diff --git a/scripts/update-lockfiles.sh b/scripts/update-lockfiles.sh index 608db6d4a9..be03257c39 100755 --- a/scripts/update-lockfiles.sh +++ b/scripts/update-lockfiles.sh @@ -20,11 +20,55 @@ strip_twig() { sed 's/{{[^}]*}}/PLACEHOLDER/g' "$1" } +replace_first() { + # POSIX-portable first-match replacement (no GNU sed required). + # Exits with code 2 if the pattern is not found. + # Usage: replace_first + local file="$1" old="$2" new="$3" + awk -v o="$old" -v n="$new" -v done=0 \ + '{ if (!done && index($0, o)) { sub(o, n); done=1 } print } END { exit(done ? 0 : 2) }' \ + "$file" > "${file}.tmp" && mv "${file}.tmp" "$file" +} + +restore_twig_npm() { + # Replace PLACEHOLDER values in package-lock.json with the correct + # Twig expressions extracted from the corresponding package.json.twig. + # PLACEHOLDER appears in: root "name", root "version", + # packages[""] "name", "version", "license". + local lockfile="$1" + local twig_name="$2" + + replace_first "$lockfile" '"name": "PLACEHOLDER"' "\"name\": \"${twig_name}\"" + replace_first "$lockfile" '"version": "PLACEHOLDER"' '"version": "{{ sdk.version }}"' + replace_first "$lockfile" '"name": "PLACEHOLDER"' "\"name\": \"${twig_name}\"" + replace_first "$lockfile" '"version": "PLACEHOLDER"' '"version": "{{ sdk.version }}"' + replace_first "$lockfile" '"license": "PLACEHOLDER"' '"license": "{{ sdk.license }}"' + + if grep -q '"PLACEHOLDER"' "$lockfile"; then + echo "ERROR: unresolved PLACEHOLDER values remain in $lockfile" >&2 + return 1 + fi +} + +restore_twig_bun() { + # Replace PLACEHOLDER in bun.lock with the correct Twig expression. + local lockfile="$1" + local twig_name="$2" + + replace_first "$lockfile" '"name": "PLACEHOLDER"' "\"name\": \"${twig_name}\"" + + if grep -q '"PLACEHOLDER"' "$lockfile"; then + echo "ERROR: unresolved PLACEHOLDER values remain in $lockfile" >&2 + return 1 + fi +} + update_npm() { local lang="$1" local extra_flags="${2:-}" + local twig_name="$3" local template="$ROOT/templates/$lang/package.json.twig" - local dest="$ROOT/templates/$lang/package-lock.json" + local dest="$ROOT/templates/$lang/package-lock.json.twig" local dir="$WORKDIR/$lang" echo "→ $lang (npm)" @@ -33,32 +77,35 @@ update_npm() { # shellcheck disable=SC2086 (cd "$dir" && npm install --package-lock-only --ignore-scripts --silent $extra_flags 2>/dev/null) cp "$dir/package-lock.json" "$dest" - echo " updated templates/$lang/package-lock.json" + restore_twig_npm "$dest" "$twig_name" + echo " updated templates/$lang/package-lock.json.twig" } update_bun() { + local twig_name="$1" local dir="$WORKDIR/cli" local template="$ROOT/templates/cli/package.json.twig" - local dest="$ROOT/templates/cli/bun.lock" + local dest="$ROOT/templates/cli/bun.lock.twig" echo "→ cli (bun)" mkdir -p "$dir" strip_twig "$template" > "$dir/package.json" cd "$dir" && bun install --silent 2>/dev/null cp "$dir/bun.lock" "$dest" - echo " updated templates/cli/bun.lock" + restore_twig_bun "$dest" "$twig_name" + echo " updated templates/cli/bun.lock.twig" } case "$TARGET" in - web) update_npm web ;; - node) update_npm node ;; - react-native) update_npm react-native --legacy-peer-deps ;; - cli) update_bun ;; + web) update_npm web "" "{{ language.params.npmPackage }}" ;; + node) update_npm node "" "{{ language.params.npmPackage | caseDash }}" ;; + react-native) update_npm react-native --legacy-peer-deps "{{ language.params.npmPackage }}" ;; + cli) update_bun "{{ language.params.npmPackage|caseDash }}" ;; all) - update_npm web - update_npm node - update_npm react-native --legacy-peer-deps - update_bun + update_npm web "" "{{ language.params.npmPackage }}" + update_npm node "" "{{ language.params.npmPackage | caseDash }}" + update_npm react-native --legacy-peer-deps "{{ language.params.npmPackage }}" + update_bun "{{ language.params.npmPackage|caseDash }}" ;; *) echo "Unknown target: $TARGET. Use web | node | react-native | cli | all" diff --git a/src/SDK/Language/CLI.php b/src/SDK/Language/CLI.php index bfffcf2be7..e4aab58d7c 100644 --- a/src/SDK/Language/CLI.php +++ b/src/SDK/Language/CLI.php @@ -204,9 +204,9 @@ public function getFiles(): array 'template' => 'cli/bunfig.toml', ], [ - 'scope' => 'copy', + 'scope' => 'default', 'destination' => 'bun.lock', - 'template' => 'cli/bun.lock', + 'template' => 'cli/bun.lock.twig', ], [ 'scope' => 'default', diff --git a/src/SDK/Language/Node.php b/src/SDK/Language/Node.php index a202adbcda..b53ea74b39 100644 --- a/src/SDK/Language/Node.php +++ b/src/SDK/Language/Node.php @@ -256,9 +256,9 @@ public function getFiles(): array 'template' => 'node/.gitignore', ], [ - 'scope' => 'copy', + 'scope' => 'default', 'destination' => 'package-lock.json', - 'template' => 'node/package-lock.json', + 'template' => 'node/package-lock.json.twig', ], ]; } diff --git a/src/SDK/Language/ReactNative.php b/src/SDK/Language/ReactNative.php index dd3e2cae4d..6d508b5927 100644 --- a/src/SDK/Language/ReactNative.php +++ b/src/SDK/Language/ReactNative.php @@ -136,9 +136,9 @@ public function getFiles(): array 'template' => 'react-native/.gitignore', ], [ - 'scope' => 'copy', + 'scope' => 'default', 'destination' => 'package-lock.json', - 'template' => 'react-native/package-lock.json', + 'template' => 'react-native/package-lock.json.twig', ], ]; } diff --git a/src/SDK/Language/Web.php b/src/SDK/Language/Web.php index 00254ddb36..c0c20fc6ed 100644 --- a/src/SDK/Language/Web.php +++ b/src/SDK/Language/Web.php @@ -156,9 +156,9 @@ public function getFiles(): array 'template' => 'web/.gitignore', ], [ - 'scope' => 'copy', + 'scope' => 'default', 'destination' => 'package-lock.json', - 'template' => 'web/package-lock.json', + 'template' => 'web/package-lock.json.twig', ], ]; } diff --git a/templates/cli/bun.lock b/templates/cli/bun.lock.twig similarity index 99% rename from templates/cli/bun.lock rename to templates/cli/bun.lock.twig index d3ce3f5af3..a71de7faef 100644 --- a/templates/cli/bun.lock +++ b/templates/cli/bun.lock.twig @@ -3,7 +3,7 @@ "configVersion": 1, "workspaces": { "": { - "name": "PLACEHOLDER", + "name": "{{ language.params.npmPackage|caseDash }}", "dependencies": { "@appwrite.io/console": "*", "chalk": "4.1.2", diff --git a/templates/cli/lib/client.ts b/templates/cli/lib/client.ts index 2b199cb9d0..0b41e7bd31 100644 --- a/templates/cli/lib/client.ts +++ b/templates/cli/lib/client.ts @@ -156,6 +156,14 @@ class Client { return this; } + /** + * Get Headers + * + * Returns a copy of the current request headers, including any + * authentication headers. Handle with care. + * + * @returns {Headers} + */ getHeaders(): Headers { return { ...this.headers }; } diff --git a/templates/node/package-lock.json b/templates/node/package-lock.json.twig similarity index 99% rename from templates/node/package-lock.json rename to templates/node/package-lock.json.twig index db07c6809e..f3c64919c8 100644 --- a/templates/node/package-lock.json +++ b/templates/node/package-lock.json.twig @@ -1,13 +1,13 @@ { - "name": "PLACEHOLDER", - "version": "PLACEHOLDER", + "name": "{{ language.params.npmPackage | caseDash }}", + "version": "{{ sdk.version }}", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "PLACEHOLDER", - "version": "PLACEHOLDER", - "license": "PLACEHOLDER", + "name": "{{ language.params.npmPackage | caseDash }}", + "version": "{{ sdk.version }}", + "license": "{{ sdk.license }}", "dependencies": { "json-bigint": "1.0.0", "node-fetch-native-with-agent": "1.7.2" diff --git a/templates/node/src/client.ts.twig b/templates/node/src/client.ts.twig index 0b2b9d8af6..6f9ee40f93 100644 --- a/templates/node/src/client.ts.twig +++ b/templates/node/src/client.ts.twig @@ -180,6 +180,14 @@ class Client { return this; } + /** + * Get Headers + * + * Returns a copy of the current request headers, including any + * authentication headers. Handle with care. + * + * @returns {Headers} + */ getHeaders(): Headers { return { ...this.headers }; } diff --git a/templates/react-native/.gitignore b/templates/react-native/.gitignore index 8cf46aac21..f98e221f2d 100644 --- a/templates/react-native/.gitignore +++ b/templates/react-native/.gitignore @@ -1,8 +1,10 @@ node_modules/ dist/* !dist/cjs/ -!dist/cjs/package.json !dist/esm/ +dist/cjs/* +dist/esm/* +!dist/cjs/package.json !dist/esm/package.json types/ .DS_Store diff --git a/templates/react-native/package-lock.json b/templates/react-native/package-lock.json.twig similarity index 99% rename from templates/react-native/package-lock.json rename to templates/react-native/package-lock.json.twig index 65e5226ddb..eb1ba1a727 100644 --- a/templates/react-native/package-lock.json +++ b/templates/react-native/package-lock.json.twig @@ -1,13 +1,13 @@ { - "name": "PLACEHOLDER", - "version": "PLACEHOLDER", + "name": "{{ language.params.npmPackage }}", + "version": "{{ sdk.version }}", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "PLACEHOLDER", - "version": "PLACEHOLDER", - "license": "PLACEHOLDER", + "name": "{{ language.params.npmPackage }}", + "version": "{{ sdk.version }}", + "license": "{{ sdk.license }}", "dependencies": { "expo-file-system": "18.*.*", "json-bigint": "1.0.0", diff --git a/templates/react-native/src/client.ts.twig b/templates/react-native/src/client.ts.twig index 0fa220fcdf..4532f3805c 100644 --- a/templates/react-native/src/client.ts.twig +++ b/templates/react-native/src/client.ts.twig @@ -162,6 +162,14 @@ class Client { {% endfor %} }; + /** + * Get Headers + * + * Returns a copy of the current request headers, including any + * authentication headers. Handle with care. + * + * @returns {Headers} + */ getHeaders(): Headers { return { ...this.headers }; } diff --git a/templates/web/.gitignore b/templates/web/.gitignore index 8cf46aac21..f98e221f2d 100644 --- a/templates/web/.gitignore +++ b/templates/web/.gitignore @@ -1,8 +1,10 @@ node_modules/ dist/* !dist/cjs/ -!dist/cjs/package.json !dist/esm/ +dist/cjs/* +dist/esm/* +!dist/cjs/package.json !dist/esm/package.json types/ .DS_Store diff --git a/templates/web/package-lock.json b/templates/web/package-lock.json.twig similarity index 99% rename from templates/web/package-lock.json rename to templates/web/package-lock.json.twig index a86b719b93..b0a7a11953 100644 --- a/templates/web/package-lock.json +++ b/templates/web/package-lock.json.twig @@ -1,13 +1,13 @@ { - "name": "PLACEHOLDER", - "version": "PLACEHOLDER", + "name": "{{ language.params.npmPackage }}", + "version": "{{ sdk.version }}", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "PLACEHOLDER", - "version": "PLACEHOLDER", - "license": "PLACEHOLDER", + "name": "{{ language.params.npmPackage }}", + "version": "{{ sdk.version }}", + "license": "{{ sdk.license }}", "dependencies": { "json-bigint": "1.0.0" }, diff --git a/templates/web/src/client.ts.twig b/templates/web/src/client.ts.twig index 43e3b96e7e..628c7917a8 100644 --- a/templates/web/src/client.ts.twig +++ b/templates/web/src/client.ts.twig @@ -402,6 +402,14 @@ class Client { {%~ endfor %} }; + /** + * Get Headers + * + * Returns a copy of the current request headers, including any + * authentication headers. Handle with care. + * + * @returns {Headers} + */ getHeaders(): Headers { return { ...this.headers }; }