hydrogen
hydrogen copied to clipboard
Add versioned template feature for scaffolding Hydrogen projects
WHY are these changes introduced?
Enables developers to scaffold Hydrogen projects from specific historical versions, ensuring compatibility with existing storefronts and allowing teams to maintain version consistency across projects.
WHAT is this pull request doing?
Introduces a versioned template feature that allows scaffolding Hydrogen projects from any previously released version of @shopify/hydrogen.
New CLI Commands
# Via npm create
npm create @shopify/hydrogen@latest -- --version 2025.4.0
# Via npx
npx @shopify/cli-hydrogen init --version 2025.4.0
# With quickstart
npm create @shopify/hydrogen@latest -- --version 2025.1.0 --quickstart
Implementation Details
New files:
packages/cli/src/lib/onboarding/versioned.ts- Core logic for versioned template setuppackages/cli/src/lib/version-finder.ts- GitHub API integration to find commits for specific versions- Tests for versioned template functionality and version finder
Modified files:
packages/create-hydrogen/src/create-app.ts- Added--versionflag parsingpackages/cli/src/commands/hydrogen/init.ts- Added version option to init commandpackages/cli/src/lib/onboarding/index.ts- Routes to versioned setup when version specified
Key Features
- Exact version scaffolding - Fetches the skeleton template from the exact commit of the specified Hydrogen release
- Dependency pinning - Pins all dependencies to versions from that release's package-lock.json
- GitHub API integration - Uses GitHub API to resolve version tags to commits (supports
GITHUB_TOKENfor rate limit bypass) - Version validation - Only accepts valid Hydrogen version formats (YYYY.MM.P where MM is 1, 4, 7, or 10)
- Full CLI option support - Works with all existing init options (language, styling, i18n, routes, etc.)
HOW to test your changes?
Test 1: Verify versioned template works with existing version
# Build the CLI
cd packages/cli
npm run build
# Test with a known version
cd /tmp
npx /path/to/hydrogen/packages/cli/dist/create-app.js --path test-2025-4-0 --version 2025.4.0 --quickstart
# Verify the generated project
cd test-2025-4-0
grep '"@shopify/hydrogen": "2025.4.0"' package.json
Expected: Project scaffolds successfully with Hydrogen 2025.4.0
Test 2: Verify authentication bypasses rate limit
# With GitHub token
export GITHUB_TOKEN=your_github_token
cd /tmp
npx /path/to/hydrogen/packages/cli/dist/create-app.js --path test-auth --version 2025.1.0 --quickstart
Expected: Project scaffolds successfully even if rate limit was previously hit
Test 3: Verify tests pass
cd packages/cli
npx vitest src/lib/version-finder.test.ts --run
npx vitest src/lib/onboarding/versioned.test.ts --run
Expected: All tests pass with exit code 0 and no unhandled promise rejections
Checklist
- [ ] I've read the Contributing Guidelines
- [ ] I've considered possible cross-platform impacts (Mac, Linux, Windows)
- [ ] I've added a changeset if this PR contains user-facing or noteworthy changes
- [ ] I've added tests to cover my changes
- [ ] I've added or updated the documentation