Skip to content
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

refactor(react-query): parse api list for status table from build files #1113

Merged
merged 15 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(react-query): add getExportAPIsWithoutSuspensive
  • Loading branch information
gwansikk committed Jul 23, 2024
commit 22c685f4ed43b827ca1b871677a1654e0e25cbe6
22 changes: 22 additions & 0 deletions packages/react-query/src/scripts/utils/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,25 @@ export function getTargetSuspensiveReactQueryAPIs(): string[] {

return results
}

export function getExportAPIsWithoutSuspensive(): string[] {
const indexFileContent = getIndexFileContent(__dirname, '../../')

const modules = indexFileContent.matchAll(/export \* from ['"]([^'"]+)['"]/g)
const results: string[] = []

for (const [, moduleName] of modules) {
if (!moduleName.includes('@suspensive/react-query')) {
const module = loadModule<Record<string, unknown>>(moduleName)

if (!module.isSuccess) {
console.warn('[@suspensive/react-query]', 'Module not found:', moduleName)
exit(1)
}

results.push(...Object.keys(module.exports).reverse())
}
}

return results
}
28 changes: 13 additions & 15 deletions packages/react-query/src/scripts/utils/table.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Table from 'cli-table3'
import {
getExportAPIsWithoutSuspensive,
getPackageJson,
getSuspensiveReactQueryPackageJson,
getTanStackReactQueryPackageJson,
Expand All @@ -11,33 +12,30 @@ export function getStatusTable(currentTargetVersion: string) {
const tanStackReactQueryPackageJson = getTanStackReactQueryPackageJson()
const tanStackReactQueryMajorVersion = tanStackReactQueryPackageJson.version.split('.')[0]
const targetSuspensiveReactQueryPackageJson = getSuspensiveReactQueryPackageJson(tanStackReactQueryMajorVersion)
const targetSuspensiveReactQueryAPIs = getTargetSuspensiveReactQueryAPIs()
const isCompatible = currentTargetVersion === tanStackReactQueryMajorVersion
const suspensiveAPIs = getTargetSuspensiveReactQueryAPIs()
const exportAPIs = getExportAPIsWithoutSuspensive()
const peerDependencyDescription = exportAPIs.length > 0 ? `You can use ${exportAPIs.join(', ')}` : ''

const table = new Table({
head: [packageJson.name, 'result', 'status', 'advice'],
head: [packageJson.name, 'result', 'status', 'description'],
style: { head: [] },
})

table.push(['version', packageJson.version, '🟢', ''])
table.push(['version', packageJson.version, '🟢'])
table.push([
'export',
`@suspensive/react-query-${currentTargetVersion}@${targetSuspensiveReactQueryPackageJson.version}`,
'🟢',
'',
`You can use ${suspensiveAPIs.join(', ')}`,
])
table.push([
'peerDependency',
`@tanstack/react-query@${tanStackReactQueryMajorVersion}`,
currentTargetVersion === tanStackReactQueryMajorVersion ? '🟢' : '❌',
currentTargetVersion === tanStackReactQueryMajorVersion
? 'The versions are compatible.'
: `Install @tanstack/react-query@${currentTargetVersion} or\nexecute suspensive-react-query switch ${tanStackReactQueryMajorVersion} to match\n@suspensive/react-query version with\n@tanstack/react-query`,
])
table.push([
'You can use',
targetSuspensiveReactQueryAPIs.join('\n'),
'🟢',
'For more detailed information about the provided APIs,\nplease visit the official documentation:\nhttps://suspensive.org/docs/react-query/motivation',
`@tanstack/react-query@${tanStackReactQueryPackageJson.version}`,
isCompatible ? '🟢' : '❌',
isCompatible
? peerDependencyDescription
: `You should npx srq switch ${tanStackReactQueryMajorVersion} to fix this error`,
])

return table.toString()
Expand Down