-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjustfile
More file actions
96 lines (86 loc) · 4.59 KB
/
Copy pathjustfile
File metadata and controls
96 lines (86 loc) · 4.59 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# This repo vendors the React Compiler (Rust port) from react/react's main branch
# into ./react-compiler, then (editing only Cargo.toml for crate naming) sets each
# crate's published name to `forked_react_compiler_*` while keeping the lib/import
# name, source, and directories as upstream's `react_compiler_*`, and adds the
# metadata + `publish` flags to release `forked_react_compiler` and its deps to crates.io.
#
# The oxc-project org ruleset forbids merge commits, so the vendor is a linear
# snapshot (not `git subtree`): each `sync` re-extracts upstream's `compiler/`,
# re-runs the transform tool (./codemod), re-applies ./patches, and commits once.
# Both are re-applied every sync because the snapshot is taken fresh.
#
# just import # one-time: create ./react-compiler (transformed)
# just sync # update ./react-compiler to the latest upstream state (re-transformed)
# just codemod # (re)run codemod on ./react-compiler in place
# just patch # apply ./patches/*.patch (Rust source changes the codemod can't express)
# just check # cargo check the vendored workspace
# just publish-dry # dry-run publishing the whole set (cargo publish --workspace --dry-run)
# just publish # publish forked_react_compiler + its deps via cargo-release-oxc
# just status # show which upstream commit is currently vendored
react_repo := "https://github.com/react/react.git"
git_ref := "main"
src_dir := "compiler" # path of the compiler inside the react monorepo
prefix := "react-compiler" # where it lives in THIS repo
# Show available recipes
default:
@just --list
# One-time import (same operation as sync; kept for discoverability)
import: sync
# Snapshot react's `compiler/` into ./{{prefix}}, set published names to forked_react_compiler_*, commit once
sync:
#!/usr/bin/env bash
set -euo pipefail
git fetch --depth=1 --no-tags {{react_repo}} {{git_ref}}
upstream="$(git rev-parse FETCH_HEAD)"
tree="$(git rev-parse "FETCH_HEAD:{{src_dir}}")"
# Preserve the currently-published version across the wipe so cargo-release-oxc
# stays the single source of truth — the codemod re-stamps whatever is committed
# rather than inventing a number.
version="$(sed -n 's/^version = "\(.*\)"/\1/p' {{prefix}}/Cargo.toml | head -1)"
version="${version:-0.1.0}"
git rm -r --cached --quiet --ignore-unmatch {{prefix}}
rm -rf {{prefix}}
git read-tree --prefix={{prefix}}/ -u "$tree"
just codemod "$version"
just patch
git add -A {{prefix}}
if git diff --cached --quiet -- {{prefix}}; then
echo "{{prefix}} already at react {{git_ref}} @ ${upstream} — nothing to commit."
else
git commit -q -m "vendor: react-compiler from {{git_ref}} @ ${upstream} (forked_react_compiler)"
echo "Committed {{prefix}} @ ${upstream}."
fi
# (Re)run codemod on ./{{prefix}}: published names, workspace deps, publish flags, LICENSE, oxc_release.toml.
# `version` defaults to the version already in the tree (cargo-release-oxc owns the bumps).
codemod version=`sed -n 's/^version = "\(.*\)"/\1/p' react-compiler/Cargo.toml 2>/dev/null | head -1`:
cargo run --quiet -p codemod -- {{prefix}} {{version}}
# Apply local source patches in ./patches over the freshly-synced upstream tree.
# These are changes the codemod can't express (Rust source, not Cargo.toml) — e.g.
# having `compile_program` return the compiled AST by value instead of a JSON
# string, so the oxc/swc front-ends skip a serialize→deserialize round-trip.
# `git apply` fails loudly if upstream drifts, so a stale patch surfaces at sync.
patch:
#!/usr/bin/env bash
set -euo pipefail
shopt -s nullglob
for p in patches/*.patch; do
echo "Applying $p"
git apply "$p"
done
# Type-check the vendored workspace
check:
cd {{prefix}} && cargo check --workspace
# Dry-run publishing the whole publishable set (cargo's workspace publish handles inter-crate deps)
publish-dry:
cd {{prefix}} && cargo publish --workspace --dry-run
# Needs cargo-release-oxc (`cargo install --git https://github.com/oxc-project/cargo-release-oxc`),
# a clean git tree, and CARGO_REGISTRY_TOKEN.
# Publish forked_react_compiler + its deps in order, skipping publish=false crates
publish:
cd {{prefix}} && cargo release-oxc publish --release crates
# Show the upstream commit currently vendored
status:
#!/usr/bin/env bash
set -euo pipefail
line="$(git log -1 --grep='^vendor: react-compiler' --format='%h %ci%n%s' 2>/dev/null || true)"
if [ -n "$line" ]; then echo "$line"; else echo "Nothing vendored yet — run 'just import'."; fi