-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate module from runtime (#219)
* refactor: separate nuxt 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` **Migration path**: Search/replace through your project `nuxt-typed-vuex` for `typed-vuex`, with the sole exception of your `nuxt.config.js`. 😊
- Loading branch information
Showing
17 changed files
with
42 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,29 @@ | ||
import type { Module } from '@nuxt/types' | ||
import { join, resolve } from 'upath' | ||
|
||
import type { Module, NuxtOptions } from '@nuxt/types' | ||
|
||
import { name, version } from '../package.json' | ||
|
||
/** | ||
* @private | ||
*/ | ||
const nuxtTypedVuex: Module = async function() { | ||
/* istanbul ignore if */ | ||
if (process.client || process.server) return | ||
const nuxtTypedVuex: Module = function nuxtTypedVuex() { | ||
const nuxtOptions = this.nuxt.options as NuxtOptions | ||
|
||
const { join, resolve }: typeof import('path') = process.client ? /* istanbul ignore next */ {} : require('path') | ||
const normalize: typeof import('normalize-path') = process.client ? /* istanbul ignore next */ {} : require('normalize-path') | ||
if (!nuxtOptions.store) console.warn('You do not have a store defined.') | ||
|
||
if (!this.options.store) console.warn('You do not have a store defined.') | ||
const buildDir = this.options.buildDir || '' | ||
this.addPlugin({ | ||
src: resolve(__dirname, '../template/plugin.js'), | ||
fileName: 'nuxt-typed-vuex.js', | ||
options: { | ||
store: normalize(join(buildDir, 'store')), | ||
store: join(nuxtOptions.buildDir, 'store'), | ||
}, | ||
}) | ||
|
||
this.options.build = this.options.build || {} | ||
this.options.build.transpile = /* istanbul ignore next */ this.options.build.transpile || [] | ||
this.options.build.transpile.push(/typed-vuex/) | ||
nuxtOptions.build.transpile = /* istanbul ignore next */ nuxtOptions.build.transpile || [] | ||
nuxtOptions.build.transpile.push(/typed-vuex/) | ||
} | ||
|
||
;(nuxtTypedVuex as any).meta = { name: 'nuxt-typed-vuex' } | ||
|
||
export * from 'typed-vuex' | ||
;(nuxtTypedVuex as any).meta = { name, version } | ||
|
||
export default nuxtTypedVuex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,21 @@ | ||
import nuxtModule from '../src' | ||
import path from 'path' | ||
|
||
import { setupTest, expectModuleToBeCalledWith } from '@nuxt/test-utils' | ||
|
||
describe('nuxt module', () => { | ||
setupTest({ | ||
testDir: __dirname, | ||
}) | ||
it('exists', () => { | ||
expect(nuxtModule).toBeDefined() | ||
}) | ||
it('warns without store defined', () => { | ||
// @ts-ignore | ||
global.console = { warn: jest.fn() } | ||
const addPlugin = jest.fn() | ||
nuxtModule.call({ | ||
options: {}, | ||
addPlugin, | ||
}) | ||
|
||
expect(console.warn).toBeCalled() | ||
}) | ||
it('adds plugin', () => { | ||
const addPlugin = jest.fn() | ||
nuxtModule.call({ | ||
expectModuleToBeCalledWith('addPlugin', { | ||
src: expect.stringContaining('template/plugin.js'), | ||
fileName: 'nuxt-typed-vuex.js', | ||
options: { | ||
store: {}, | ||
store: expect.stringContaining('store'), | ||
}, | ||
addPlugin, | ||
}) | ||
expect(addPlugin).toHaveBeenCalled() | ||
expect(addPlugin.mock.calls[0][0].options.store).toBeDefined() | ||
expect(path.resolve(addPlugin.mock.calls[0][0].src)).toBeDefined() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b8d556b
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.
Successfully deployed to the following URLs: