Files
dev/third_party/pi/scripts/update-source-imports-to-ts.sh
alexion 4def357d09 chore(vendor): import pi 0.85.1
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree.

git-subtree-dir: third_party/pi

git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
2026-09-14 10:48:47 -04:00

11 lines
689 B
Bash

#!/usr/bin/env bash
set -euo pipefail
# Rewrites relative source import specifiers in package source directories from .js to .ts.
# TypeScript's rewriteRelativeImportExtensions option rewrites these back to .js in emitted output.
find packages -mindepth 2 -maxdepth 2 -type d -name src -print0 |
while IFS= read -r -d '' src_dir; do
find "$src_dir" -type f -name '*.ts' -print0
done |
xargs -0 perl -0pi -e 's/(\b(?:from|import)\b\s*\(?\s*["\x27])(\.{1,2}\/[^"\x27\r\n]+)\.js(["\x27]\s*\)?)/$1$2.ts$3/g; s/(\bdeclare\s+module\s+["\x27])(\.{1,2}\/[^"\x27\r\n]+)\.js(["\x27])/$1$2.ts$3/g; s/(\bimportNodeOnlyProvider\(\s*["\x27])(\.{1,2}\/[^"\x27\r\n]+)\.js(["\x27]\s*\))/$1$2.ts$3/g'