-
Notifications
You must be signed in to change notification settings - Fork 6k
feat: Add Vercel hosting support alongside Netlify #5057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1947e1a
feat: Add Vercel hosting support alongside Netlify
mattcarrollcode 39b9ea5
fix: Adjust vercel.json paths for Vercel root directory config
mattcarrollcode 4aa88d4
feat: Generate vercel.json redirects from Netlify _redirects
mattcarrollcode 4d6e22a
fix: Add permissions block to workflow, use replaceAll for wildcards
mattcarrollcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,3 +33,5 @@ website/build/ | |
| !.yarn/releases | ||
| !.yarn/sdks | ||
| !.yarn/versions | ||
| .vercel | ||
| .env*.local | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /** | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import fs from 'node:fs'; | ||
| import path from 'node:path'; | ||
|
|
||
| const REPO_ROOT = path.resolve(import.meta.dirname, '../..'); | ||
| const REDIRECTS_PATH = path.join(REPO_ROOT, 'website/static/_redirects'); | ||
| const VERSIONS_PATH = path.join(REPO_ROOT, 'website/versions.json'); | ||
| const VERCEL_JSON_PATH = path.join(REPO_ROOT, 'vercel.json'); | ||
|
|
||
| interface VercelRedirect { | ||
| source: string; | ||
| destination: string; | ||
| permanent: boolean; | ||
| } | ||
|
|
||
| function isPartialSegmentWildcard(source: string): boolean { | ||
| return source.split('/').some(seg => seg.includes('*') && seg !== '*'); | ||
| } | ||
|
|
||
| function expandPartialWildcard( | ||
| source: string, | ||
| destination: string | ||
| ): VercelRedirect[] { | ||
| const segments = source.split('/'); | ||
| const wildcardSeg = segments.find(seg => seg.includes('*') && seg !== '*')!; | ||
| const prefix = wildcardSeg.replace('*', ''); | ||
Check failureCode scanning / CodeQL Incomplete string escaping or encoding High
This replaces only the first occurrence of '*'.
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
|
|
||
| // Infer docs directory from destination path | ||
| // e.g. /docs/next/legacy/native-modules-:splat → docs/legacy/ | ||
| const destDir = destination | ||
| .replace(/^\/docs\/next\//, '') | ||
| .replace(/\/[^/]*$/, ''); | ||
| const searchDir = path.join(REPO_ROOT, 'docs', destDir); | ||
|
|
||
| let files: string[]; | ||
| try { | ||
| files = fs | ||
| .readdirSync(searchDir) | ||
| .filter(f => f.startsWith(prefix) && /\.mdx?$/.test(f)) | ||
| .map(f => f.replace(/\.mdx?$/, '')); | ||
| } catch { | ||
| console.warn( | ||
| `Warning: Could not read ${searchDir} for expanding ${source}` | ||
| ); | ||
| return []; | ||
| } | ||
|
|
||
| return files.map(filename => { | ||
| const suffix = filename.slice(prefix.length); | ||
| return { | ||
| source: source.replace(`${prefix}*`, filename), | ||
| destination: destination.replace(':splat', suffix), | ||
| permanent: true, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| function syncRedirects(): void { | ||
| const latestVersion: string = JSON.parse( | ||
| fs.readFileSync(VERSIONS_PATH, 'utf8') | ||
| )[0]; | ||
|
|
||
| const lines = fs.readFileSync(REDIRECTS_PATH, 'utf8').split('\n'); | ||
| const redirects: VercelRedirect[] = []; | ||
|
|
||
| for (const line of lines) { | ||
| const trimmed = line.trim(); | ||
| if (!trimmed || trimmed.startsWith('#')) continue; | ||
|
|
||
| const parts = trimmed.split(/\s+/); | ||
| if (parts.length < 2) continue; | ||
|
|
||
| let [source, destination] = parts; | ||
|
|
||
| // Strip full URL sources to path only | ||
| if (source.startsWith('http://') || source.startsWith('https://')) { | ||
| try { | ||
| source = new URL(source).pathname; | ||
| } catch { | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| // Convert same-domain full URL destinations to relative paths | ||
| if (destination.startsWith('https://reactnative.dev/')) { | ||
| destination = destination.replace('https://reactnative.dev', ''); | ||
| } | ||
|
|
||
| // Replace $LATEST_VERSION$ placeholder with actual version | ||
| source = source.replaceAll('$LATEST_VERSION$', latestVersion); | ||
| destination = destination.replaceAll('$LATEST_VERSION$', latestVersion); | ||
|
|
||
| // Handle partial-segment wildcards (e.g., native-modules-*) | ||
| // Vercel doesn't support wildcards within a path segment, so enumerate | ||
| if (isPartialSegmentWildcard(source)) { | ||
| redirects.push(...expandPartialWildcard(source, destination)); | ||
| continue; | ||
| } | ||
|
|
||
| // Convert Netlify wildcard syntax to Vercel format | ||
| // Netlify: /* and :splat → Vercel: /:path* | ||
| source = source.replace(/\*$/, ':path*'); | ||
| destination = destination.replace(':splat', ':path*'); | ||
|
|
||
| redirects.push({source, destination, permanent: true}); | ||
| } | ||
|
|
||
| const vercelJson = JSON.parse(fs.readFileSync(VERCEL_JSON_PATH, 'utf8')); | ||
| vercelJson.redirects = redirects; | ||
| fs.writeFileSync( | ||
| VERCEL_JSON_PATH, | ||
| JSON.stringify(vercelJson, null, 2) + '\n' | ||
| ); | ||
|
|
||
| console.log(`Synced ${redirects.length} redirects to vercel.json`); | ||
| } | ||
|
|
||
| syncRedirects(); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.