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

fix: avoid npm bug when resolving optional deps #2841

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ A few notes about the project and possible questions:
npm install pinia
```

If you are using Vue <2.7, make sure to install latest `@vue/composition-api`:

```bash
npm install pinia @vue/composition-api
```

## Usage

### Install the plugin
Expand Down
6 changes: 1 addition & 5 deletions packages/pinia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,12 @@
"vue-demi": "^0.14.10"
},
"peerDependencies": {
"@vue/composition-api": "^1.4.0",
"typescript": ">=4.4.4",
"vue": "^2.6.14 || ^3.5.11"
"vue": "^2.7.0 || ^3.5.11"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
},
"@vue/composition-api": {
"optional": true
}
},
"repository": {
Expand Down
10 changes: 2 additions & 8 deletions packages/pinia/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ function mergeReactiveObjects<
const skipHydrateSymbol = __DEV__
? Symbol('pinia:skipHydration')
: /* istanbul ignore next */ Symbol()
const skipHydrateMap = /*#__PURE__*/ new WeakMap<any, any>()

/**
* Tells Pinia to skip the hydration process of a given object. This is useful in setup stores (only) when you return a
Expand All @@ -127,10 +126,7 @@ const skipHydrateMap = /*#__PURE__*/ new WeakMap<any, any>()
* @returns obj
*/
export function skipHydrate<T = any>(obj: T): T {
return isVue2
? // in @vue/composition-api, the refs are sealed so defineProperty doesn't work...
/* istanbul ignore next */ skipHydrateMap.set(obj, 1) && obj
: Object.defineProperty(obj, skipHydrateSymbol, {})
return Object.defineProperty(obj, skipHydrateSymbol, {})
}

/**
Expand All @@ -140,9 +136,7 @@ export function skipHydrate<T = any>(obj: T): T {
* @returns true if `obj` should be hydrated
*/
export function shouldHydrate(obj: any) {
return isVue2
? /* istanbul ignore next */ !skipHydrateMap.has(obj)
: !isPlainObject(obj) || !obj.hasOwnProperty(skipHydrateSymbol)
return !isPlainObject(obj) || !obj.hasOwnProperty(skipHydrateSymbol)
}

const { assign } = Object
Expand Down
6 changes: 2 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ function createConfig(buildName, output, plugins = []) {
output.globals = {
'vue-demi': 'VueDemi',
vue: 'Vue',
'@vue/composition-api': 'vueCompositionApi',
}

const isProductionBuild = /\.prod\.[cm]?js$/.test(output.file)
Expand Down Expand Up @@ -127,7 +126,7 @@ function createConfig(buildName, output, plugins = []) {
// during a single build.
hasTSChecked = true

const external = ['vue-demi', 'vue', '@vue/composition-api']
const external = ['vue-demi', 'vue']
if (
!isGlobalBuild &&
// pinia.prod.cjs should not require `@vue/devtools-api` (like Vue)
Expand Down