Skip to content

Commit 5098abd

Browse files
committed
refactor: separate module from runtime
BREAKING CHANGE: all imports are now from `typed-vuex` rather than `nuxt-typed-vuex`, which is *exclusively* the module in your `nuxt.config`
1 parent 5ad99db commit 5098abd

File tree

13 files changed

+24
-42
lines changed

13 files changed

+24
-42
lines changed

docs/content/en/getting-started-nuxt.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ position: 2
2727

2828
</d-code-group>
2929

30-
<d-alert type="info">This will also install `typed-vuex` in your project, which is where the store accessor lives. You can import its helper functions from either `nuxt-typed-vuex` or from `typed-vuex`.</d-alert>
30+
<d-alert type="info">This will also install `typed-vuex` in your project, which is where the store accessor lives. All the helper functions are imported from `typed-vuex`.</d-alert>
3131

3232
2. Add module to your `nuxt.config`:
3333

examples/nuxt-ts/store/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getAccessorType, mutationTree, actionTree } from 'nuxt-typed-vuex'
1+
import { getAccessorType, mutationTree, actionTree } from 'typed-vuex'
22

33
import * as submodule from './submodule'
44

examples/nuxt-ts/store/submodule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getterTree, mutationTree, actionTree } from 'nuxt-typed-vuex'
1+
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
22

33
export const state = () => ({
44
firstName: '',

examples/nuxt/store/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getAccessorType, mutationTree, actionTree } from 'nuxt-typed-vuex'
1+
import { getAccessorType, mutationTree, actionTree } from 'typed-vuex'
22
import { Context } from '@nuxt/types'
33

44
import * as submodule from './submodule'

examples/nuxt/store/submodule.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getterTree, mutationTree, actionTree } from 'nuxt-typed-vuex'
1+
import { getterTree, mutationTree, actionTree } from 'typed-vuex'
22

33
export const state = () => ({
44
firstName: '',

packages/nuxt-typed-vuex/package.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@
3333
"dev": "nuxt test/fixture"
3434
},
3535
"dependencies": {
36-
"consola": "^2.15.3",
37-
"normalize-path": "^3.0.0",
38-
"typed-vuex": "0.1.22"
36+
"typed-vuex": "0.1.22",
37+
"upath": "^2.0.1"
3938
},
4039
"devDependencies": {
4140
"@nuxt/test-utils": "^0.2.0",
4241
"@nuxt/types": "^2.15.3",
4342
"@nuxt/typescript-build": "^2.1.0",
44-
"@types/normalize-path": "^3.0.0",
4543
"core-js": "3.9.1",
4644
"nuxt": "^2.15.3",
4745
"ts-loader": "^8.0.18",

packages/nuxt-typed-vuex/src/index.ts

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,29 @@
1-
import type { Module } from '@nuxt/types'
1+
import { join, resolve } from 'upath'
2+
3+
import type { Module, NuxtOptions } from '@nuxt/types'
4+
5+
import { name, version } from '../package.json'
26

37
/**
48
* @private
59
*/
610
const nuxtTypedVuex: Module = async function() {
7-
/* istanbul ignore if */
8-
if (process.client || process.server) return
11+
const nuxtOptions = this.nuxt.options as NuxtOptions
912

10-
const { join, resolve }: typeof import('path') = process.client ? /* istanbul ignore next */ {} : require('path')
11-
const normalize: typeof import('normalize-path') = process.client ? /* istanbul ignore next */ {} : require('normalize-path')
13+
if (!nuxtOptions.store) console.warn('You do not have a store defined.')
1214

13-
if (!this.options.store) console.warn('You do not have a store defined.')
14-
const buildDir = this.options.buildDir || ''
1515
this.addPlugin({
1616
src: resolve(__dirname, '../template/plugin.js'),
1717
fileName: 'nuxt-typed-vuex.js',
1818
options: {
19-
store: normalize(join(buildDir, 'store')),
19+
store: join(nuxtOptions.buildDir, 'store'),
2020
},
2121
})
2222

23-
this.options.build = this.options.build || {}
24-
this.options.build.transpile = /* istanbul ignore next */ this.options.build.transpile || []
25-
this.options.build.transpile.push(/typed-vuex/)
23+
nuxtOptions.build.transpile = /* istanbul ignore next */ nuxtOptions.build.transpile || []
24+
nuxtOptions.build.transpile.push(/typed-vuex/)
2625
}
2726

28-
;(nuxtTypedVuex as any).meta = { name: 'nuxt-typed-vuex' }
29-
30-
export * from 'typed-vuex'
27+
;(nuxtTypedVuex as any).meta = { name, version }
3128

3229
export default nuxtTypedVuex

packages/nuxt-typed-vuex/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
4-
"rootDir": "src",
4+
"rootDir": ".",
55
"outDir": "lib"
66
},
77
"exclude": ["node_modules", "lib", "test"]

packages/typed-vuex/test/fixture/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
getAccessorType,
55
mutationTree,
66
actionTree,
7-
} from 'nuxt-typed-vuex'
7+
} from 'typed-vuex'
88

99
import * as submodule from './submodule'
1010

packages/typed-vuex/test/fixture/submodule.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
getterTree,
3-
mutationTree,
4-
actionTree,
5-
useAccessor,
6-
} from 'nuxt-typed-vuex'
1+
import { getterTree, mutationTree, actionTree, useAccessor } from 'typed-vuex'
72
import { pattern } from '.'
83

94
export const state = () => ({

packages/typed-vuex/test/tsd/accessor.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { DispatchOptions, CommitOptions } from 'vuex'
22
import { expectType, expectError } from 'tsd'
33

4-
import { getAccessorType } from 'nuxt-typed-vuex'
4+
import { getAccessorType } from 'typed-vuex'
55
import { getters, state, actions, mutations } from '../fixture'
66

77
import * as submodule from '../fixture/submodule'

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"compilerOptions": {
33
"strict": true,
44
"sourceMap": true,
5+
"resolveJsonModule": true,
56
"declaration": true,
67
"target": "esnext",
78
"module": "esnext",

yarn.lock

+1-10
Original file line numberDiff line numberDiff line change
@@ -3697,13 +3697,6 @@ __metadata:
36973697
languageName: node
36983698
linkType: hard
36993699

3700-
"@types/normalize-path@npm:^3.0.0":
3701-
version: 3.0.0
3702-
resolution: "@types/normalize-path@npm:3.0.0"
3703-
checksum: 1cff3a34d0c0c37bca26a60e19407783fe85cde0af0ccfe7773001019c6339927460127c043163638d04f54415d165766173d9881ad8e7eb7870e4be2657ee45
3704-
languageName: node
3705-
linkType: hard
3706-
37073700
"@types/optimize-css-assets-webpack-plugin@npm:^5.0.2":
37083701
version: 5.0.2
37093702
resolution: "@types/optimize-css-assets-webpack-plugin@npm:5.0.2"
@@ -12919,14 +12912,12 @@ fsevents@^1.2.7:
1291912912
"@nuxt/test-utils": ^0.2.0
1292012913
"@nuxt/types": ^2.15.3
1292112914
"@nuxt/typescript-build": ^2.1.0
12922-
"@types/normalize-path": ^3.0.0
12923-
consola: ^2.15.3
1292412915
core-js: 3.9.1
12925-
normalize-path: ^3.0.0
1292612916
nuxt: ^2.15.3
1292712917
ts-loader: ^8.0.18
1292812918
tsd: ^0.14.0
1292912919
typed-vuex: 0.1.22
12920+
upath: ^2.0.1
1293012921
peerDependencies:
1293112922
"@nuxt/types": ^2.15.3
1293212923
languageName: unknown

0 commit comments

Comments
 (0)