Repository navigation
Expand file tree
/
Copy pathvendor-tsgo.sh
More file actions
executable file
·63 lines (50 loc) · 2.06 KB
/
Copy pathvendor-tsgo.sh
File metadata and controls
executable file
·63 lines (50 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
COMMIT_FILE="$SCRIPT_DIR/TSGO_COMMIT"
# Portable in-place sed (macOS needs -i '', Linux needs -i)
if [[ "$(uname)" == "Darwin" ]]; then
SEDI=(sed -i '')
else
SEDI=(sed -i)
fi
# Read pinned commit hash
if [[ ! -f "$COMMIT_FILE" ]]; then
echo "Error: TSGO_COMMIT file not found." >&2
exit 1
fi
TSGO_REF=$(tr -d '[:space:]' < "$COMMIT_FILE")
if [[ -z "$TSGO_REF" ]]; then
echo "Error: TSGO_COMMIT is empty." >&2
exit 1
fi
VENDOR_DIR="_vendor/typescript-go"
# Clean previous vendor
rm -rf "$VENDOR_DIR"
mkdir -p "_vendor"
# Clone the pinned commit (shallow)
echo "Cloning microsoft/typescript-go at $TSGO_REF..."
git init "$VENDOR_DIR"
git -C "$VENDOR_DIR" remote add origin https://github.com/microsoft/typescript-go.git
git -C "$VENDOR_DIR" fetch --depth 1 origin "$TSGO_REF"
git -C "$VENDOR_DIR" checkout FETCH_HEAD
# Remove git history and stuff we don't need
rm -rf "$VENDOR_DIR/.git" "$VENDOR_DIR/_tools" "$VENDOR_DIR/cmd" "$VENDOR_DIR/_submodules" "$VENDOR_DIR/testdata"
# Rename internal/ to pkg/
echo "Renaming internal/ -> pkg/..."
mv "$VENDOR_DIR/internal" "$VENDOR_DIR/pkg"
# Rewrite all import paths: internal/ -> pkg/
echo "Rewriting import paths..."
find "$VENDOR_DIR" -name "*.go" -type f -exec "${SEDI[@]}" \
's|github.com/microsoft/typescript-go/internal/|github.com/microsoft/typescript-go/pkg/|g' {} +
# Rewrite the module name in go.mod so we can use a replace directive
echo "Patching go.mod..."
"${SEDI[@]}" 's|^module github.com/microsoft/typescript-go|module goodchanges/tsgo-vendor|' "$VENDOR_DIR/go.mod"
# Also rewrite self-references if any exist beyond internal/
find "$VENDOR_DIR" -name "*.go" -type f -exec "${SEDI[@]}" \
's|github.com/microsoft/typescript-go|goodchanges/tsgo-vendor|g' {} +
# Fix go.mod replace path references too
"${SEDI[@]}" 's|github.com/microsoft/typescript-go|goodchanges/tsgo-vendor|g' "$VENDOR_DIR/go.mod"
echo "Done. Vendored tsgo at $VENDOR_DIR"
echo "Module: goodchanges/tsgo-vendor"
echo "Import packages like: goodchanges/tsgo-vendor/pkg/parser"