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

feat(react-query): support @tanstack/react-query@4,5 at once automatically (pre exit beta) #950

Merged
merged 8 commits into from
Jun 23, 2024

Conversation

manudeli
Copy link
Member

@manudeli manudeli commented Jun 18, 2024

close #944 related with #36

Copy link

vercel bot commented Jun 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
suspensive.org ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 23, 2024 9:12am
v1.suspensive.org ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 23, 2024 9:12am
visualization.suspensive.org ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 23, 2024 9:12am

Copy link

changeset-bot bot commented Jun 18, 2024

⚠️ No Changeset found

Latest commit: 20119f8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

codspeed-hq bot commented Jun 18, 2024

CodSpeed Performance Report

Merging #950 will create unknown performance changes

Comparing beta (20119f8) with main (26dd707)

Summary

⚠️ No benchmarks were detected in both the base of the PR and the PR.

@manudeli manudeli changed the title chore(changeset): exit beta chore(changeset): pre exit beta Jun 18, 2024
…anstack/react-query@4,5 at once automatically (#946)

related #944, #36 

# Overview

<!--
    A clear and concise description of what this pr is about.
 -->

## PR Checklist

- [x] I did below actions if need

1. I read the [Contributing
Guide](https://github.com/toss/suspensive/blob/main/CONTRIBUTING.md)
2. I added documents and tests.

---------

Co-authored-by: GwanSik Kim <39869096+gwansikk@users.noreply.github.com>
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 beta, this PR will
be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`beta` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `beta`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @suspensive/react-query@2.1.2-beta.0

### Patch Changes

- [#946](#946)
[`2fd8108`](2fd8108)
Thanks [@manudeli](https://github.com/manudeli)! - feat(react-query)
depend on @suspensive/react-query-4,5 to support
@tanstack/react-query@4,5 at once automatically

- Updated dependencies
\[[`2fd8108`](2fd8108)]:
    -   @suspensive/react-query-4@0.0.1-beta.0
    -   @suspensive/react-query-5@0.0.1-beta.0
    -   @suspensive/react@2.1.2-beta.0

## @suspensive/react-query-4@0.0.1-beta.0

### Patch Changes

- [#946](#946)
[`2fd8108`](2fd8108)
Thanks [@manudeli](https://github.com/manudeli)! - feat(react-query)
depend on @suspensive/react-query-4,5 to support
@tanstack/react-query@4,5 at once automatically

-   Updated dependencies \[]:
    -   @suspensive/react@2.1.2-beta.0

## @suspensive/react-query-5@0.0.1-beta.0

### Patch Changes

- [#946](#946)
[`2fd8108`](2fd8108)
Thanks [@manudeli](https://github.com/manudeli)! - feat(react-query)
depend on @suspensive/react-query-4,5 to support
@tanstack/react-query@4,5 at once automatically

-   Updated dependencies \[]:
    -   @suspensive/react@2.1.2-beta.0

## @suspensive/react@2.1.2-beta.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@manudeli manudeli changed the title chore(changeset): pre exit beta feat(react-query): support @tanstack/react-query@4,5 at once (pre exit beta) Jun 19, 2024
@manudeli manudeli changed the title feat(react-query): support @tanstack/react-query@4,5 at once (pre exit beta) feat(react-query): support @tanstack/react-query@4,5 at once automatically (pre exit beta) Jun 19, 2024
# Summary

`@suspensive/react-query` now automatically identifies the installed
version of `@tanstack/react-query` and uses either
`@suspensive/react-query-4` or `@suspensive/react-query-5` accordingly.

# Roadmaps

> This is the list of remaining tasks. It may be added to or revised.

- [x] Core 
- [x] Field Test
- [ ] CLI ⚠️
- [ ] Dependency Log
([comment](#953 (comment)))

# How it works

The mechanism for identifying the version of `@tanstack/react-query` and
selecting the appropriate `@suspensive/react-query-x` to use is similar
to `vue-demi`.

- https://github.com/vueuse/vue-demi

When `@suspsensive/react-query` is added as a dependency, the
`postinstall` script fetches the version of `@tanstack/react-query` and
overlays the build files of `@suspensive/react-query-x` at the entry
point (build root) to ensure the appropriate version is used.

```json
// package.json
// ...
"exports": {
  ".": {
    "import": {
      "types": "./dist/index.d.ts",
      "default": "./dist/index.js"
    },
    "require": {
      "types": "./dist/index.d.cts",
      "default": "./dist/index.cjs"
    }
  },
  "./package.json": "./package.json"
},
// ...
"postinstall": "node -e \"import('./scripts/postinstall.js').catch(e => console.error(e))\""
// ...
```

The `postinstall.js` script is executed during the `postinstall`
process.

```jsx
// script/postinstall.js
import { loadModule, switchVersion } from './utils.js'

const reactQueryPackageJson = loadModule('@tanstack/react-query/package.json')
const version = reactQueryPackageJson?.version

if (!version || typeof version !== 'string') {
  console.warn('@tanstack/react-query is not found.')
} else 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.`)
}
```

This script fetches the installed `@tanstack/react-query/package.json`,
checks the version, and copies the corresponding
`@suspensive/react-query-x` files to the library's root.

```bash
suspensive/packages/react-query/dist
# --- Library entry point
├── index.cjs
├── index.cjs.map
├── index.d.cts
├── index.d.ts
├── index.js
├── index.js.map
# ---
├── v4
# --- Copy files from this folder to the entry point if @tanstack/react-query@4 is detected
|  ├── index.cjs
|  ├── index.cjs.map
|  ├── index.d.cts
|  ├── index.d.ts
|  ├── index.js
|  └── index.js.map
# ---
└── v5
# --- Copy files from this folder to the entry point if @tanstack/react-query@5 is detected
   ├── index.cjs
   ├── index.cjs.map
   ├── index.d.cts
   ├── index.d.ts
   ├── index.js
   └── index.js.map
```

By following this process, `@suspensive/react-query` automatically uses
the appropriate version upon installation.

When added as a dependency, the version switching happens automatically
as shown in the logs below:

```bash
# case1: @tanstack/react-query@4
packages/react-query postinstall$ node -e "import('./scripts/postinstall.js').catch(e => console.error(e))"
│ [@suspensive/react-query] set version to v4
└─ Done in 56ms

# case2: @tanstack/react-query@5
packages/react-query postinstall$ node -e "import('./scripts/postinstall.js').catch(e => console.error(e))"
│ [@suspensive/react-query] set version to v5
└─ Done in 56ms
```

# Field Test

> These tests were conducted in isolated environments using `~.tgz`.
In all environments, `@suspensive/react": "^2.1.2-beta.0` was used
consistently, and versions 4 and 5 of `@tanstack/react-query` were
tested.
> 
- pnpm@9.4.0 ✅
- yarn@v1.22.22 ✅
- yarn berry@4.3.0 (pnp) ✅
- pnpm@9.4.9 (monorepo) ✅

# CLI

In typical environments (single repo), the version switches
automatically. However, for special cases, we have created the
`suspensive-react-query-switch` script, which forces the switching of
`@suspensive/react-query-x`.

```bash
npx suspensive-react-query-switch
[@suspensive/react-query], expecting version "4" or "5""

npx suspensive-react-query-switch 4
[@suspensive/react-query] set version to v4
```

Although it works in most environments, it does not work in the
following case:

- The CLI does not work properly in a monorepo environment. ⚠️
- The CLI does not work properly in a yarn-berry (pnp) environment. ⚠️

---------

Co-authored-by: Jonghyeon Ko <jonghyeon@toss.im>
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 beta, this PR will
be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`beta` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `beta`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @suspensive/react-query@2.1.2-beta.1

### Patch Changes

- [#953](#953)
[`8d8a2d6`](8d8a2d6)
Thanks [@gwansikk](https://github.com/gwansikk)! - feat(react-query):
universal support for TanStack Query 4 and 5

-   Updated dependencies \[]:
    -   @suspensive/react@2.1.2-beta.1
    -   @suspensive/react-query-4@0.0.1-beta.0
    -   @suspensive/react-query-5@0.0.1-beta.0

## @suspensive/react@2.1.2-beta.1

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@codecov-commenter
Copy link

codecov-commenter commented Jun 23, 2024

Codecov Report

Attention: Patch coverage is 0% with 14 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@26dd707). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #950   +/-   ##
=======================================
  Coverage        ?   80.67%           
=======================================
  Files           ?       36           
  Lines           ?      445           
  Branches        ?       98           
=======================================
  Hits            ?      359           
  Misses          ?       77           
  Partials        ?        9           
Components Coverage Δ
@suspensive/react 96.98% <ø> (?)
@suspensive/react-query ∅ <ø> (?)
@suspensive/react-query-4 0.00% <ø> (?)
@suspensive/react-query-5 0.00% <0.00%> (?)
@suspensive/react-await 100.00% <ø> (?)
@suspensive/react-image 23.52% <ø> (?)

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 beta, this PR will
be updated.


# Releases
## @suspensive/react-query@2.2.0

### Minor Changes

- [#953](#953)
[`8d8a2d6`](8d8a2d6)
Thanks [@gwansikk](https://github.com/gwansikk)! - feat(react-query):
universal support for TanStack Query 4 and 5

### Patch Changes

- [#946](#946)
[`2fd8108`](2fd8108)
Thanks [@manudeli](https://github.com/manudeli)! - feat(react-query)
depend on @suspensive/react-query-4,5 to support
@tanstack/react-query@4,5 at once automatically

- Updated dependencies
\[[`2fd8108`](2fd8108)]:
    -   @suspensive/react-query-4@0.0.1
    -   @suspensive/react-query-5@0.0.1
    -   @suspensive/react@2.2.0

## @suspensive/react-query-4@0.0.1

### Patch Changes

- [#946](#946)
[`2fd8108`](2fd8108)
Thanks [@manudeli](https://github.com/manudeli)! - feat(react-query)
depend on @suspensive/react-query-4,5 to support
@tanstack/react-query@4,5 at once automatically

-   Updated dependencies \[]:
    -   @suspensive/react@2.2.0

## @suspensive/react-query-5@0.0.1

### Patch Changes

- [#946](#946)
[`2fd8108`](2fd8108)
Thanks [@manudeli](https://github.com/manudeli)! - feat(react-query)
depend on @suspensive/react-query-4,5 to support
@tanstack/react-query@4,5 at once automatically

-   Updated dependencies \[]:
    -   @suspensive/react@2.2.0

## @suspensive/react@2.2.0

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Support TanStack React Query v5
3 participants