From df83685c8eab00b1cf3f8b29449f1a1a38fe2377 Mon Sep 17 00:00:00 2001 From: Max Liashuk Date: Tue, 19 Jan 2021 00:15:55 +0200 Subject: [PATCH] feat: dedicated entrypoint for the decorator BREAKING CHANGE: `Socket` decorates is no longer exported out of the root entry point of `vue-socket.io-extended`, use the separate entrypoint instead: ```diff - import { Socket } from 'vue-socket.io-extended' + import Socket from 'vue-socket.io-extended/decorator' ``` --- package.json | 10 ++++- scripts/rollup-build.js | 44 ++++++++++++------- .../{index.esm.spec.js => index.spec.js} | 6 +-- src/__tests__/index.umd.spec.js | 19 -------- src/index.esm.js | 7 --- src/index.js | 3 ++ src/index.umd.js | 8 ---- 7 files changed, 41 insertions(+), 56 deletions(-) rename src/__tests__/{index.esm.spec.js => index.spec.js} (66%) delete mode 100644 src/__tests__/index.umd.spec.js delete mode 100644 src/index.esm.js create mode 100644 src/index.js delete mode 100644 src/index.umd.js diff --git a/package.json b/package.json index 7c76cda6..95822d2b 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,13 @@ "description": "Socket.io bindings for Vue.js and Vuex (inspired by Vue-Socket.io)", "main": "dist/vue-socket.io-ext.min.js", "module": "dist/vue-socket.io-ext.esm.js", + "exports": { + ".": { + "import": "./dist/vue-socket.io-ext.esm.js", + "default": "./dist/vue-socket.io-ext.min.js" + }, + "./decorator/": "./dist/vue-socket.io-ext.decorator.esm.js" + }, "scripts": { "test": "jest", "lint": "eslint scripts src", @@ -17,8 +24,7 @@ }, "files": [ "dist/", - "types/index.d.ts", - "types/vue.d.ts" + "types/" ], "typings": "types/index.d.ts", "keywords": [ diff --git a/scripts/rollup-build.js b/scripts/rollup-build.js index c4d3b7a6..584a22b4 100644 --- a/scripts/rollup-build.js +++ b/scripts/rollup-build.js @@ -1,19 +1,19 @@ /* eslint-disable import/no-extraneous-dependencies */ import nodeResolve from 'rollup-plugin-node-resolve'; import babel from 'rollup-plugin-babel'; -import { terser } from 'rollup-plugin-terser'; +import { terser } from 'rollup-plugin-terser'; // uglifyjs alternative import commonjs from 'rollup-plugin-commonjs'; import filesize from 'rollup-plugin-filesize'; export default [ { - input: 'src/index.esm.js', - external: ['vue', 'vue-class-component'], + input: 'src/index.js', + external: ['vue'], plugins: [ nodeResolve(), commonjs(), babel(), - terser(), // uglifyjs alternative + terser(), filesize(), ], output: { @@ -22,22 +22,36 @@ export default [ }, }, { - input: 'src/index.umd.js', - external: ['vue', 'vue-class-component'], + input: 'src/index.js', + external: ['vue'], plugins: [ nodeResolve(), commonjs(), babel(), - terser(), // uglifyjs alternative + terser(), filesize(), ], - output: - { - format: 'umd', - name: 'VueSocketIOExt', - exports: 'named', - globals: { vue: 'Vue' }, - file: 'dist/vue-socket.io-ext.min.js', - }, + output: { + format: 'umd', + name: 'VueSocketIOExt', + exports: 'named', + globals: { vue: 'Vue' }, + file: 'dist/vue-socket.io-ext.min.js', + }, + }, + { + input: 'src/decorator.js', + external: ['vue-class-component'], + plugins: [ + nodeResolve(), + commonjs(), + babel(), + terser(), + filesize(), + ], + output: { + format: 'esm', + file: 'dist/vue-socket.io-ext.decorator.esm.js', + }, }, ]; diff --git a/src/__tests__/index.esm.spec.js b/src/__tests__/index.spec.js similarity index 66% rename from src/__tests__/index.esm.spec.js rename to src/__tests__/index.spec.js index d87022fc..efeee942 100644 --- a/src/__tests__/index.esm.spec.js +++ b/src/__tests__/index.spec.js @@ -1,4 +1,4 @@ -import VueSocketIoExt, { Socket } from '../index.esm'; +import VueSocketIoExt from '../index'; it('default export should be a vue plugin', () => { expect(VueSocketIoExt).toMatchObject({ @@ -11,7 +11,3 @@ it('default export should have `defaults` options exported', () => { defaults: expect.any(Object), }); }); - -it('named export `Socket` exists', () => { - expect(Socket).toEqual(expect.any(Function)); -}); diff --git a/src/__tests__/index.umd.spec.js b/src/__tests__/index.umd.spec.js deleted file mode 100644 index 79cc3d2f..00000000 --- a/src/__tests__/index.umd.spec.js +++ /dev/null @@ -1,19 +0,0 @@ -const VueSocketIoExt = require('../index.umd'); - -it('should be a vue plugin (is an object with `install` method)', () => { - expect(VueSocketIoExt).toMatchObject({ - install: expect.any(Function), - }); -}); - -it('should have `Socket` decorator exported', () => { - expect(VueSocketIoExt).toMatchObject({ - Socket: expect.any(Function), - }); -}); - -it('should have `defaults` options exported', () => { - expect(VueSocketIoExt).toMatchObject({ - defaults: expect.any(Object), - }); -}); diff --git a/src/index.esm.js b/src/index.esm.js deleted file mode 100644 index d7b90be4..00000000 --- a/src/index.esm.js +++ /dev/null @@ -1,7 +0,0 @@ -import Socket from './decorator'; -import * as plugin from './plugin'; - -export { - Socket, - plugin as default, -}; diff --git a/src/index.js b/src/index.js new file mode 100644 index 00000000..dae05332 --- /dev/null +++ b/src/index.js @@ -0,0 +1,3 @@ +import * as plugin from './plugin'; + +export default plugin; diff --git a/src/index.umd.js b/src/index.umd.js deleted file mode 100644 index ccd9de07..00000000 --- a/src/index.umd.js +++ /dev/null @@ -1,8 +0,0 @@ -import Socket from './decorator'; -import { install, defaults } from './plugin'; - -export { - Socket, - defaults, - install, -};