-
Notifications
You must be signed in to change notification settings - Fork 53
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(tsup): update script options #1370
Conversation
🦋 Changeset detectedLatest commit: a743517 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
People can be co-author:
|
Size Change: 0 B Total Size: 64.2 kB ℹ️ View Unchanged
|
CodSpeed Performance ReportMerging #1370 will create unknown performance changesComparing Summary
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1370 +/- ##
==========================================
+ Coverage 71.86% 72.11% +0.24%
==========================================
Files 67 67
Lines 583 581 -2
Branches 129 129
==========================================
Hits 419 419
+ Misses 151 149 -2
Partials 13 13
|
try { | ||
const { version } = getTanStackReactQueryPackageJson() | ||
|
||
if (!version) { | ||
throw new Error() | ||
} | ||
|
||
if (version.startsWith('4.')) { | ||
switchVersion(4) | ||
} else if (version.startsWith('5.')) { | ||
switchVersion(5) | ||
} else { | ||
console.warn('[@suspensive/react-query]', `version v${version} is not supported.`) | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
} catch (error) { | ||
console.error('[@suspensive/react-query]', 'not fond @tanstack/react-query') | ||
process.exit(1) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original code
import { getTanStackReactQueryPackageJson } from './utils/package'
import { switchVersion } from './utils/switchVersion'
const { version } = getTanStackReactQueryPackageJson()
if (version.startsWith('4.')) {
switchVersion(4)
} else if (version.startsWith('5.')) {
switchVersion(5)
} else {
console.warn('[@suspensive/react-query]', `version v${version} is not supported.`)
}
I suggest below code.
try { | |
const { version } = getTanStackReactQueryPackageJson() | |
if (!version) { | |
throw new Error() | |
} | |
if (version.startsWith('4.')) { | |
switchVersion(4) | |
} else if (version.startsWith('5.')) { | |
switchVersion(5) | |
} else { | |
console.warn('[@suspensive/react-query]', `version v${version} is not supported.`) | |
} | |
// eslint-disable-next-line @typescript-eslint/no-unused-vars | |
} catch (error) { | |
console.error('[@suspensive/react-query]', 'not fond @tanstack/react-query') | |
process.exit(1) | |
} | |
const { version } = getTanStackReactQueryPackageJson() | |
if (!version) { | |
throw new Error('[@suspensive/react-query]', 'not found version of @tanstack/react-query') | |
} | |
if (version.startsWith('4.')) { | |
switchVersion(4) | |
} else if (version.startsWith('5.')) { | |
switchVersion(5) | |
} else { | |
console.warn('[@suspensive/react-query]', `version v${version} is not supported.`) | |
} |
if you want use try catch, you could make specific error constructor to specify that caught error is for not found version
try { | |
const { version } = getTanStackReactQueryPackageJson() | |
if (!version) { | |
throw new Error() | |
} | |
if (version.startsWith('4.')) { | |
switchVersion(4) | |
} else if (version.startsWith('5.')) { | |
switchVersion(5) | |
} else { | |
console.warn('[@suspensive/react-query]', `version v${version} is not supported.`) | |
} | |
// eslint-disable-next-line @typescript-eslint/no-unused-vars | |
} catch (error) { | |
console.error('[@suspensive/react-query]', 'not fond @tanstack/react-query') | |
process.exit(1) | |
} | |
class NotFoundVersionError extends Error { | |
message: string = 'Not found version' | |
} | |
try { | |
const { version } = getTanStackReactQueryPackageJson() | |
if (!version) { | |
throw new NotFoundVersionError() | |
} | |
if (version.startsWith('4.')) { | |
switchVersion(4) | |
} else if (version.startsWith('5.')) { | |
switchVersion(5) | |
} else { | |
console.warn('[@suspensive/react-query]', `version v${version} is not supported.`) | |
} | |
// eslint-disable-next-line @typescript-eslint/no-unused-vars | |
} catch (error) { | |
// but in my opinion, this is not good idea | |
if(error instanceof NotFoundVersionError){ // specify error | |
console.error('[@suspensive/react-query]', error.message) | |
} | |
process.exit(1) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention was to simplify the postinstall
script. Ultimately, I designed it so that if an error occurs at runtime (e.g., node ./dist/bin/postinstall.cjs || echo 'please reinstall @suspensive/react-query'
), the error would propagate as intended. The goal was to consistently inform the user of an appropriate solution through a clear message.
Therefore, I believe this file does not cause any inconvenience to the user due to node(runtime) errors, and I will revert it to its previous state (this was my mistake😢).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple than before 👍
@gwansikk Test after new version release please 🙏 I'll release this now |
I'm ready! |
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @suspensive/[email protected] ### Patch Changes - [#1370](#1370) [`390e82d`](390e82d) Thanks [@gwansikk](https://github.com/gwansikk)! - refactor(tsup): update script options ## @suspensive/[email protected] ### Patch Changes - [#1370](#1370) [`390e82d`](390e82d) Thanks [@gwansikk](https://github.com/gwansikk)! - refactor(tsup): update script options - Updated dependencies \[]: - @suspensive/[email protected] - @suspensive/[email protected] - @suspensive/[email protected] ## @suspensive/[email protected] ### Patch Changes - Updated dependencies \[]: - @suspensive/[email protected] ## @suspensive/[email protected] ### Patch Changes - Updated dependencies \[]: - @suspensive/[email protected] ## @suspensive/[email protected] ## @suspensive/[email protected]
Overview
details: #1338 (comment)
PR Checklist