Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ The sync script:
- Normalizes `//go:generate` directives
- Copies `microsoft/TypeScript/tsc/testdata` → `testdata`
- Runs `go mod tidy` pre/post generation
- Runs `scripts/post-sync.sh` to re-apply local harness patches (e.g. stable help-version padding) and refresh version-sensitive baselines
- Set `SYNC_POST=0` to skip post-sync

Automated sync: the **Sync** workflow checks for new stable TypeScript ≥ 7.0.0 tags and opens a PR labeled `sync`. After merge, **Release Tag** pushes a matching git tag and **GoReleaser** publishes a GitHub Release (library-only; no binaries).

Expand Down
2 changes: 2 additions & 0 deletions README_zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ import "github.com/buke/typescript-go-internal/v7/pkg/ast"
- 规范化 `//go:generate` 指令
- 复制 `microsoft/TypeScript/tsc/testdata` → `testdata`
- 在生成前后运行 `go mod tidy`
- 运行 `scripts/post-sync.sh`,重新应用本地 harness 补丁(如稳定的 help 版本 padding)并刷新与版本相关的基线
- 设置 `SYNC_POST=0` 可跳过 post-sync

自动化:**Sync** workflow 会检查新的 TypeScript ≥ 7.0.0 稳定 tag 并开带 `sync` label 的 PR。合入后 **Release Tag** 会推送同名 git tag,**GoReleaser** 会创建 GitHub Release(仅库,无二进制)。

Expand Down
19 changes: 15 additions & 4 deletions pkg/execute/tsc/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

func PrintVersion(sys System, locale locale.Locale) {
fmt.Fprintln(sys.Writer(), diagnostics.Version_0.Localize(locale, core.Version()))
fmt.Fprintln(sys.Writer(), diagnostics.Version_0.Localize(locale, versionForDisplay(sys)))
}

func PrintHelp(sys System, locale locale.Locale, commandLine *tsoptions.ParsedCommandLine) {
Expand All @@ -24,6 +24,17 @@ func PrintHelp(sys System, locale locale.Locale, commandLine *tsoptions.ParsedCo
}
}

// versionForDisplay returns the version string used in CLI help/version output.
// Tests may set TS_TEST_VERSION so header padding is computed against the same
// string later written into baselines (see harnessutil.FakeTSVersion), instead of
// core.Version() which changes length across releases and shifts spacing.
func versionForDisplay(sys System) string {
if v := sys.GetEnvironmentVariable("TS_TEST_VERSION"); v != "" {
return v
}
return core.Version()
}

func getOptionsForHelp(commandLine *tsoptions.ParsedCommandLine) []*tsoptions.CommandLineOption {
// Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch")
opts := slices.Clone(tsoptions.OptionsDeclarations)
Expand Down Expand Up @@ -74,7 +85,7 @@ func printEasyHelp(sys System, locale locale.Locale, simpleOptions []*tsoptions.
output = append(output, " ", desc.Localize(locale), "\n", "\n")
}

msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Localize(locale) + " - " + diagnostics.Version_0.Localize(locale, core.Version())
msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Localize(locale) + " - " + diagnostics.Version_0.Localize(locale, versionForDisplay(sys))
output = append(output, getHeader(sys, msg)...)

output = append(output, colors.bold(diagnostics.COMMON_COMMANDS.Localize(locale)), "\n", "\n")
Expand Down Expand Up @@ -109,7 +120,7 @@ func printEasyHelp(sys System, locale locale.Locale, simpleOptions []*tsoptions.

func printAllHelp(sys System, locale locale.Locale, options []*tsoptions.CommandLineOption) {
var output []string
msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Localize(locale) + " - " + diagnostics.Version_0.Localize(locale, core.Version())
msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Localize(locale) + " - " + diagnostics.Version_0.Localize(locale, versionForDisplay(sys))
output = append(output, getHeader(sys, msg)...)

// ALL COMPILER OPTIONS section
Expand All @@ -134,7 +145,7 @@ func printAllHelp(sys System, locale locale.Locale, options []*tsoptions.Command

func PrintBuildHelp(sys System, locale locale.Locale, buildOptions []*tsoptions.CommandLineOption) {
var output []string
output = append(output, getHeader(sys, diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Localize(locale)+" - "+diagnostics.Version_0.Localize(locale, core.Version()))...)
output = append(output, getHeader(sys, diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Localize(locale)+" - "+diagnostics.Version_0.Localize(locale, versionForDisplay(sys)))...)
before := diagnostics.Using_build_b_will_make_tsc_behave_more_like_a_build_orchestrator_than_a_compiler_This_is_used_to_trigger_building_composite_projects_which_you_can_learn_more_about_at_0.Localize(locale, "https://aka.ms/tsc-composite-builds")
options := core.Filter(buildOptions, func(option *tsoptions.CommandLineOption) bool {
return option != &tsoptions.TscBuildOption
Expand Down
10 changes: 10 additions & 0 deletions pkg/execute/tsctests/sys.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ func newTestSys(tscInput *tscInput, forIncrementalCorrectness bool) *TestSys {
CurrentDirectory: cwd,
}, currentWrite)
sys.env = tscInput.env
if sys.env == nil {
sys.env = map[string]string{}
} else {
sys.env = maps.Clone(sys.env)
}
// Default TS_TEST_VERSION so help/version header padding matches FakeTSVersion
// (stable across core.Version() length changes). See scripts/post-sync.sh.
if _, ok := sys.env["TS_TEST_VERSION"]; !ok {
sys.env["TS_TEST_VERSION"] = harnessutil.FakeTSVersion
}
sys.forIncrementalCorrectness = forIncrementalCorrectness
sys.mockWatchBackend = NewMockWatchBackend()
sys.mockWatchBackend.DirectoryExists = sys.fs.FS.DirectoryExists
Expand Down
79 changes: 79 additions & 0 deletions scripts/patches/0001-ts-test-version-stable-help-padding.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
diff --git a/pkg/execute/tsc/help.go b/pkg/execute/tsc/help.go
index a05464ae3..e69e999c9 100644
--- a/pkg/execute/tsc/help.go
+++ b/pkg/execute/tsc/help.go
@@ -13,7 +13,7 @@ import (
)

func PrintVersion(sys System, locale locale.Locale) {
- fmt.Fprintln(sys.Writer(), diagnostics.Version_0.Localize(locale, core.Version()))
+ fmt.Fprintln(sys.Writer(), diagnostics.Version_0.Localize(locale, versionForDisplay(sys)))
}

func PrintHelp(sys System, locale locale.Locale, commandLine *tsoptions.ParsedCommandLine) {
@@ -24,6 +24,17 @@ func PrintHelp(sys System, locale locale.Locale, commandLine *tsoptions.ParsedCo
}
}

+// versionForDisplay returns the version string used in CLI help/version output.
+// Tests may set TS_TEST_VERSION so header padding is computed against the same
+// string later written into baselines (see harnessutil.FakeTSVersion), instead of
+// core.Version() which changes length across releases and shifts spacing.
+func versionForDisplay(sys System) string {
+ if v := sys.GetEnvironmentVariable("TS_TEST_VERSION"); v != "" {
+ return v
+ }
+ return core.Version()
+}
+
func getOptionsForHelp(commandLine *tsoptions.ParsedCommandLine) []*tsoptions.CommandLineOption {
// Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch")
opts := slices.Clone(tsoptions.OptionsDeclarations)
@@ -74,7 +85,7 @@ func printEasyHelp(sys System, locale locale.Locale, simpleOptions []*tsoptions.
output = append(output, " ", desc.Localize(locale), "\n", "\n")
}

- msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Localize(locale) + " - " + diagnostics.Version_0.Localize(locale, core.Version())
+ msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Localize(locale) + " - " + diagnostics.Version_0.Localize(locale, versionForDisplay(sys))
output = append(output, getHeader(sys, msg)...)

output = append(output, colors.bold(diagnostics.COMMON_COMMANDS.Localize(locale)), "\n", "\n")
@@ -109,7 +120,7 @@ func printEasyHelp(sys System, locale locale.Locale, simpleOptions []*tsoptions.

func printAllHelp(sys System, locale locale.Locale, options []*tsoptions.CommandLineOption) {
var output []string
- msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Localize(locale) + " - " + diagnostics.Version_0.Localize(locale, core.Version())
+ msg := diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Localize(locale) + " - " + diagnostics.Version_0.Localize(locale, versionForDisplay(sys))
output = append(output, getHeader(sys, msg)...)

// ALL COMPILER OPTIONS section
@@ -134,7 +145,7 @@ func printAllHelp(sys System, locale locale.Locale, options []*tsoptions.Command

func PrintBuildHelp(sys System, locale locale.Locale, buildOptions []*tsoptions.CommandLineOption) {
var output []string
- output = append(output, getHeader(sys, diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Localize(locale)+" - "+diagnostics.Version_0.Localize(locale, core.Version()))...)
+ output = append(output, getHeader(sys, diagnostics.X_tsc_Colon_The_TypeScript_Compiler.Localize(locale)+" - "+diagnostics.Version_0.Localize(locale, versionForDisplay(sys)))...)
before := diagnostics.Using_build_b_will_make_tsc_behave_more_like_a_build_orchestrator_than_a_compiler_This_is_used_to_trigger_building_composite_projects_which_you_can_learn_more_about_at_0.Localize(locale, "https://aka.ms/tsc-composite-builds")
options := core.Filter(buildOptions, func(option *tsoptions.CommandLineOption) bool {
return option != &tsoptions.TscBuildOption
diff --git a/pkg/execute/tsctests/sys.go b/pkg/execute/tsctests/sys.go
index a1b4923df..1a493e553 100644
--- a/pkg/execute/tsctests/sys.go
+++ b/pkg/execute/tsctests/sys.go
@@ -132,6 +132,16 @@ func newTestSys(tscInput *tscInput, forIncrementalCorrectness bool) *TestSys {
CurrentDirectory: cwd,
}, currentWrite)
sys.env = tscInput.env
+ if sys.env == nil {
+ sys.env = map[string]string{}
+ } else {
+ sys.env = maps.Clone(sys.env)
+ }
+ // Default TS_TEST_VERSION so help/version header padding matches FakeTSVersion
+ // (stable across core.Version() length changes). See scripts/post-sync.sh.
+ if _, ok := sys.env["TS_TEST_VERSION"]; !ok {
+ sys.env["TS_TEST_VERSION"] = harnessutil.FakeTSVersion
+ }
sys.forIncrementalCorrectness = forIncrementalCorrectness
sys.mockWatchBackend = NewMockWatchBackend()
sys.mockWatchBackend.DirectoryExists = sys.fs.FS.DirectoryExists
8 changes: 8 additions & 0 deletions scripts/patches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Sync patches

Patches in this directory are re-applied by `scripts/post-sync.sh` after every
`scripts/sync-internal.sh` run (unless `SYNC_POST=0`).

They encode local harness fixes that would otherwise be wiped when upstream
`tsc/internal` is copied into `pkg/`. Keep patches against a clean upstream-
synced tree (no local edits already applied).
70 changes: 70 additions & 0 deletions scripts/post-sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
# Post-sync fixes applied after mirroring microsoft/TypeScript/tsc into this repo.
# Kept separate so upstream copies do not wipe local harness stability patches.
#
# Current fixes:
# 1) Re-apply scripts/patches/*.patch (TS_TEST_VERSION help padding)
# 2) Refresh version-sensitive tsc help baselines to match FakeTSVersion padding
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT_DIR"

PATCH_DIR="${ROOT_DIR}/scripts/patches"
POST_SYNC="${SYNC_POST:-1}"

if [[ "${POST_SYNC}" != "1" ]]; then
echo "Skip post-sync (SYNC_POST=${POST_SYNC})"
exit 0
fi

echo "Running post-sync fixes..."

apply_patches() {
if [[ ! -d "${PATCH_DIR}" ]]; then
return 0
fi
local patch
shopt -s nullglob
for patch in "${PATCH_DIR}"/*.patch; do
echo "Applying $(basename "$patch")..."
if git apply --check "$patch" >/dev/null 2>&1; then
git apply "$patch"
elif grep -q 'TS_TEST_VERSION' pkg/execute/tsc/help.go 2>/dev/null; then
echo " already applied; skipping"
else
echo " ERROR: failed to apply $patch" >&2
git apply --check "$patch" || true
exit 1
fi
done
}

refresh_help_baselines() {
echo "Refreshing version-sensitive help baselines..."
# Failure writes testdata/baselines/local/...; we then accept into reference/.
GOWORK=off go test ./pkg/execute/tsctests/ -count=1 \
-run 'TestTscCommandline$/tsc/show_help_with_ExitStatus' >/dev/null 2>&1 || true

local loc="testdata/baselines/local/tsc/commandLine"
local ref="testdata/baselines/reference/tsc/commandLine"
mkdir -p "$ref"
local f
for f in \
show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped.js \
show-help-with-ExitStatus.DiagnosticsPresent_OutputsSkipped-when-host-cannot-provide-terminal-width.js
do
if [[ -f "${loc}/${f}" ]]; then
cp "${loc}/${f}" "${ref}/${f}"
echo " accepted ${f}"
fi
done

GOWORK=off go test ./pkg/execute/tsctests/ -count=1 \
-run 'TestTscCommandline$/tsc/show_help_with_ExitStatus'
}

apply_patches
refresh_help_baselines

echo "Post-sync complete."
6 changes: 6 additions & 0 deletions scripts/sync-internal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,10 @@ fi
# Ensure testdata is present in repo (copy from submodule)
copy_testdata

# Re-apply local harness patches and refresh version-sensitive baselines.
if [[ "${SYNC_POST:-1}" == "1" ]]; then
chmod +x scripts/post-sync.sh
./scripts/post-sync.sh
fi

echo "Sync complete."
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tsgo
ExitStatus:: DiagnosticsPresent_OutputsSkipped
Output::
Version FakeTSVersion
tsc: The TypeScript Compiler - Version FakeTSVersion  
tsc: The TypeScript Compiler - Version FakeTSVersion  
 TS 
COMMON COMMANDS

Expand Down