Files
swc/scripts/patch-project.sh
Donny/강동윤andGitHub df9238ef39 chore: migrate Yarn to pnpm (#11845)
**Description:**

Migrate first-party package management from Yarn to pnpm 10.33.3. This
updates root package-manager metadata, workspace configuration,
lockfiles, npm/pnpm config, scripts, documentation snippets, GitHub
Actions setup/cache/publish paths, Docker workflow commands, and Rust
test helpers that locate JS executables or install/build helper
packages.

The pnpm install uses hoisted node_modules compatibility mode to
preserve existing package layout assumptions. Vendored fixtures,
third-party corpus data, and external-project package-manager support
paths are intentionally left alone.

Validation performed:

- `pnpm --version` -> `10.33.3`
- `pnpm install --frozen-lockfile`
- `pnpm build:dev`
- `pnpm test:core`
- `pnpm test:minifier`
- `pnpm test:html`
- `pnpm test:react-compiler`
- `pnpm --filter @swc/types build`
- `pnpm --filter @swc/helpers build`
- `cargo fmt --all`
- `cargo clippy --all --all-targets -- -D warnings`
- `cargo test -p testing`
- `cargo test -p swc --test exec`
- `./crates/swc_ecma_minifier/scripts/exec.sh`
- `./crates/swc_ecma_minifier/scripts/test.sh`
- `cargo test -p swc_ecma_minifier`
- `pnpm publish --dry-run --no-git-checks --access public --force` in
`packages/types`

Note: full `actionlint .github/workflows/*.yml` still reports
pre-existing workflow issues such as old action versions and the
existing `matrix.settings.setup` static analysis warning. The newly
touched `publish-misc-packages.yml` passes standalone `actionlint`.

**BREAKING CHANGE:**

None.

**Related issue (if exists):**

None.
2026-05-12 13:12:27 +09:00

70 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -eu
# Check if path argument is provided
if [ $# -eq 0 ]; then
echo -e "\033[31mError\033[0m: Please provide a path to the directory containing \033[33mpackage.json\033[0m whose \033[33m@swc/core\033[0m dependency you want to patch"
exit 1
fi
TARGET_DIR="$1"
CURRENT_DIR=$(pwd)
# Validate target directory exists
if [ ! -d "$TARGET_DIR" ]; then
echo -e "\033[31mError\033[0m: Directory \033[33m$TARGET_DIR\033[0m does not exist"
exit 1
fi
# Add patch section to Cargo.toml
echo '[patch.crates-io]' >> bindings/Cargo.toml
./scripts/cargo/patch-section.sh >> bindings/Cargo.toml
# Update cargo dependencies
(cd bindings && cargo update -p swc_core -p swc_ts_fast_strip)
# Build the project
pnpm build:dev
# Check if package.json exists in target directory
if [ ! -f "$TARGET_DIR/package.json" ]; then
echo -e "\033[31mError\033[0m: \033[33mpackage.json\033[0m not found in \033[33m$TARGET_DIR\033[0m"
exit 1
fi
# Check if @swc/core exists in package.json
if ! grep -q '"@swc/core"' "$TARGET_DIR/package.json"; then
echo
echo -e "\033[31mError\033[0m: \033[33m@swc/core\033[0m not found in \033[33mpackage.json\033[0m"
echo
echo "Please run the following commands:"
echo
if [ -f "$TARGET_DIR/yarn.lock" ]; then
echo -e " \033[32m$\033[0m cd $TARGET_DIR"
echo -e " \033[32m$\033[0m yarn add -D \033[33m@swc/core\033[0m"
elif [ -f "$TARGET_DIR/package-lock.json" ]; then
echo -e " \033[32m$\033[0m cd $TARGET_DIR"
echo -e " \033[32m$\033[0m npm install --save-dev \033[33m@swc/core\033[0m"
elif [ -f "$TARGET_DIR/pnpm-lock.yaml" ]; then
echo -e " \033[32m$\033[0m cd $TARGET_DIR"
echo -e " \033[32m$\033[0m pnpm add -D @swc/core"
else
echo -e " Please add \033[33m@swc/core\033[0m to your devDependencies and install using your package manager"
fi
echo
echo "Then run:"
echo
echo -e " \033[32m$\033[0m cd $CURRENT_DIR"
echo -e " \033[32m$\033[0m git restore bindings/Cargo.toml bindings/Cargo.lock"
echo
echo "After that, you can run this script again."
exit 1
fi
# Update @swc/core in package.json
TEMP_FILE=$(mktemp)
sed 's#"@swc/core": "[^"]*"#"@swc/core": "'"$CURRENT_DIR"'/packages/core"#' "$TARGET_DIR/package.json" > "$TEMP_FILE"
mv "$TEMP_FILE" "$TARGET_DIR/package.json"
echo "Successfully patched @swc/core in $TARGET_DIR/package.json"