Skip to content

Commit fe5789e

Browse files
authored
fix(init): auto-fix git symlinks when core.symlinks is false (#1353)
## Problem This repository contains git symlinks in `packages/core/` that reference files in the upstream `vite/` directory: - `packages/core/vite-rolldown.config.ts` → `../../vite/packages/vite/rolldown.config.ts` - `packages/core/rollupLicensePlugin.ts` → `../../vite/packages/vite/rollupLicensePlugin.ts` In a fresh Windows clone of this repository, `core.symlinks` can be `false`. In that case, git checks out these entries as plain text files containing the target path instead of actual symlinks. This causes the build to fail with `Unexpected token`, because the files are imported as TypeScript modules but only contain a path string. ## Solution Add a `_fix_symlinks` recipe to `justfile` and run it as part of `just init`. The recipe checks `core.symlinks`, and when it is not `true`, it enables it and re-checks out all tracked symlink entries. Both unix and Windows implementations are included. The recipe is idempotent: when `core.symlinks=true`, it does nothing. ## Test plan - Verified on Windows with a fresh `git clone` of this repository that `core.symlinks=false` and the symlinks are checked out incorrectly - Ran `just _fix_symlinks` on Windows via PowerShell and confirmed the symlinks were restored - Ran the unix `_fix_symlinks` commands manually in Git Bash and confirmed the symlinks were restored - Confirmed idempotency: running the recipe again with `core.symlinks=true` is a no-op
1 parent 31e90b9 commit fe5789e

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

justfile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,30 @@ _clean_dist:
1616
_clean_dist:
1717
Remove-Item -Path 'packages/*/dist' -Recurse -Force -ErrorAction SilentlyContinue
1818

19-
init: _clean_dist
19+
init: _clean_dist _fix_symlinks
2020
cargo binstall watchexec-cli cargo-insta typos-cli cargo-shear dprint taplo-cli -y
2121
node packages/tools/src/index.ts sync-remote
2222
pnpm install
2323
pnpm -C docs install
2424

25+
[unix]
26+
_fix_symlinks:
27+
#!/usr/bin/env bash
28+
if [ "$(git config --get core.symlinks)" != "true" ]; then \
29+
echo "Enabling core.symlinks and re-checking out symlinks..."; \
30+
git config core.symlinks true; \
31+
git ls-files -s | grep '^120000' | cut -f2 | while read -r f; do git checkout -- "$f"; done; \
32+
fi
33+
34+
[windows]
35+
_fix_symlinks:
36+
$symlinks = git config --get core.symlinks; \
37+
if ($symlinks -ne 'true') { \
38+
Write-Host 'Enabling core.symlinks and re-checking out symlinks...'; \
39+
git config core.symlinks true; \
40+
git ls-files -s | Where-Object { $_ -match '^120000' } | ForEach-Object { ($_ -split "`t", 2)[1] } | ForEach-Object { git checkout -- $_ }; \
41+
}
42+
2543
build:
2644
pnpm install
2745
pnpm --filter @rolldown/pluginutils build

0 commit comments

Comments
 (0)