diff --git a/README.md b/README.md index 83b0168..ada9c33 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,9 @@ npm install vue-deprecate ``` ## Setup + +### Default setup + ```js import Vue from 'vue'; import VueDeprecate from 'vue-deprecate'; @@ -16,6 +19,23 @@ import VueDeprecate from 'vue-deprecate'; Vue.use(VueDeprecate); ``` + +### Nuxt.js setup + +Create file `plugins/vue-deprecate.js`: +```js +import Vue from 'vue' +import VueDeprecate from 'vue-deprecate'; + +Vue.use(VueDeprecate); +``` +Then add the file path inside the `plugins` key of `nuxt.config.js`: +```js +export default { + plugins: ['@/plugins/vue-deprecate.js'] +} +``` + ## Usage Deprecate component: @@ -66,6 +86,19 @@ Deprecate property: }; ``` +### Usage with property decorators (like vue-property-decorator/nuxt-property-decorator) + +```js +import { Vue, Component } from 'nuxt-property-decorator' + +@Component({ + deprecated: true, +}) +export default class Test extends Vue { +} +``` + + ## Features You can: diff --git a/package.json b/package.json index 2ea1383..548991f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-deprecate", - "version": "0.3.0", + "version": "0.3.2", "author": "fringers", "scripts": { "build": "vue-cli-service build --target lib src/deprecate.ts --mode production", diff --git a/src/deprecate.ts b/src/deprecate.ts index 93b656c..1bdbe5f 100644 --- a/src/deprecate.ts +++ b/src/deprecate.ts @@ -14,7 +14,7 @@ const VueDeprecate: PluginObject = { install: function (vue: typeof Vue, options: VueDeprecateOptions = defaultOptions) { vue.mixin({ created: function () { - if (process.env.NODE_ENV === 'production' && options && !options.enabledOnProduction) { + if (!vue.config.devtools && options && !options.enabledOnProduction) { return; } diff --git a/tests/unit/components.spec.ts b/tests/unit/components.spec.ts index 0038ce0..d1fff51 100644 --- a/tests/unit/components.spec.ts +++ b/tests/unit/components.spec.ts @@ -9,6 +9,7 @@ describe('Components', () => { const localVue = createLocalVue() localVue.use(VueDeprecate); + localVue.config.devtools = true; shallowMount(component, { localVue, diff --git a/tests/unit/options.spec.ts b/tests/unit/options.spec.ts index 5c95caa..225d3db 100644 --- a/tests/unit/options.spec.ts +++ b/tests/unit/options.spec.ts @@ -13,11 +13,12 @@ describe('Options', () => { }; // TODO: fix types - function mountWithPluginSpy(component: any, options?: any) { + function mountWithPluginSpy(component: any, options?: any, devtools: boolean = true) { const installSpy = jest.spyOn(VueDeprecate, 'install'); const localVue = createLocalVue() localVue.use(VueDeprecate, options); + localVue.config.devtools = devtools; shallowMount(component, { localVue, @@ -30,18 +31,6 @@ describe('Options', () => { } describe('enabledOnProduction', () => { - const OLD_ENV = process.env; - - beforeEach(() => { - jest.resetModules(); - process.env = { ...OLD_ENV }; - delete process.env.NODE_ENV; - }); - - afterEach(() => { - process.env = OLD_ENV; - }); - it('log warnings if no options and not production', () => { const warnMock = jest.fn(); console.warn = warnMock; @@ -88,8 +77,7 @@ describe('Options', () => { const warnMock = jest.fn(); console.warn = warnMock; - process.env.NODE_ENV = 'production'; - mountWithPluginSpy(deprecatedComponent); + mountWithPluginSpy(deprecatedComponent, undefined, false); expect(warnMock).not.toHaveBeenCalled(); }); @@ -98,10 +86,12 @@ describe('Options', () => { const warnMock = jest.fn(); console.warn = warnMock; - process.env.NODE_ENV = 'production'; - mountWithPluginSpy(deprecatedComponent, { - someProp: 'value', - }); + mountWithPluginSpy(deprecatedComponent, + { + someProp: 'value', + }, + false + ); expect(warnMock).not.toHaveBeenCalled(); }); @@ -110,10 +100,12 @@ describe('Options', () => { const warnMock = jest.fn(); console.warn = warnMock; - process.env.NODE_ENV = 'production'; - mountWithPluginSpy(deprecatedComponent, { - enabledOnProduction: true, - }); + mountWithPluginSpy(deprecatedComponent, + { + enabledOnProduction: true, + }, + false + ); expect(warnMock).toHaveBeenCalledTimes(2); }); @@ -122,10 +114,12 @@ describe('Options', () => { const warnMock = jest.fn(); console.warn = warnMock; - process.env.NODE_ENV = 'production'; - mountWithPluginSpy(deprecatedComponent, { - enabledOnProduction: false, - }); + mountWithPluginSpy(deprecatedComponent, + { + enabledOnProduction: false, + }, + false + ); expect(warnMock).not.toHaveBeenCalled(); }); diff --git a/tests/unit/props.spec.ts b/tests/unit/props.spec.ts index b6c14f4..a4855c2 100644 --- a/tests/unit/props.spec.ts +++ b/tests/unit/props.spec.ts @@ -10,6 +10,7 @@ describe('Props', () => { const localVue = createLocalVue() localVue.use(VueDeprecate); + localVue.config.devtools = true; shallowMount(component, { localVue,