-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1112 from chromaui/tom/cap-2327-track-hasrouter-a…
…nd-haspagecomponents-on-build-events Detect `context.projectMetadata.hasRouter` and send to the index
- Loading branch information
Showing
10 changed files
with
245 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,29 @@ | ||
import { expect, it } from 'vitest'; | ||
|
||
import { getHasRouter } from './getHasRouter'; | ||
|
||
it('returns true if there is a routing package in package.json', async () => { | ||
expect( | ||
getHasRouter({ | ||
dependencies: { | ||
react: '^18', | ||
'react-dom': '^18', | ||
'react-router': '^6', | ||
}, | ||
}) | ||
).toBe(true); | ||
}); | ||
|
||
it('sreturns false if there is a routing package in package.json dependenices', async () => { | ||
expect( | ||
getHasRouter({ | ||
dependencies: { | ||
react: '^18', | ||
'react-dom': '^18', | ||
}, | ||
devDependencies: { | ||
'react-router': '^6', | ||
}, | ||
}) | ||
).toBe(false); | ||
}); |
This file contains 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,38 @@ | ||
import type { Context } from '../types'; | ||
|
||
const routerPackages = new Set([ | ||
'react-router', | ||
'react-router-dom', | ||
'remix', | ||
'@tanstack/react-router', | ||
'expo-router', | ||
'@reach/router', | ||
'react-easy-router', | ||
'@remix-run/router', | ||
'wouter', | ||
'wouter-preact', | ||
'preact-router', | ||
'vue-router', | ||
'unplugin-vue-router', | ||
'@angular/router', | ||
'@solidjs/router', | ||
|
||
// metaframeworks that imply routing | ||
'next', | ||
'react-scripts', | ||
'gatsby', | ||
'nuxt', | ||
'@sveltejs/kit', | ||
]); | ||
|
||
/** | ||
* @param packageJson The package JSON of the project (from context) | ||
* | ||
* @returns boolean Does this project use a routing package? | ||
*/ | ||
export function getHasRouter(packageJson: Context['packageJson']) { | ||
// NOTE: we just check real dependencies; if it is in dev dependencies, it may just be an example | ||
return Object.keys(packageJson?.dependencies ?? {}).some((depName) => | ||
routerPackages.has(depName) | ||
); | ||
} |
This file contains 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 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 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 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 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