From 623b1fe3eec2dc939728f7be4e0d03139e194031 Mon Sep 17 00:00:00 2001 From: Sebastiaan Marynissen Date: Fri, 13 Nov 2020 23:52:32 +0100 Subject: [PATCH 1/5] Add Node.js esm entry point --- package.json | 7 +++++++ src/index.mjs | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/index.mjs diff --git a/package.json b/package.json index 6d9dbe06a..d942e1ccc 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,13 @@ "version": "3.5.1", "description": "state management for Vue.js", "main": "dist/vuex.common.js", + "exports": { + ".": { + "require": "./dist/vuex.common.js", + "import": "./src/index.mjs" + }, + "./": "./" + }, "module": "dist/vuex.esm.js", "unpkg": "dist/vuex.js", "jsdelivr": "dist/vuex.js", diff --git a/src/index.mjs b/src/index.mjs new file mode 100644 index 000000000..18b4018b0 --- /dev/null +++ b/src/index.mjs @@ -0,0 +1,25 @@ +import Vuex from '../dist/vuex.common.js' +const { + Store, + install, + version, + mapState, + mapMutations, + mapGetters, + mapActions, + createNamespacedHelpers, + createLogger +} = Vuex + +export { + Vuex as default, + Store, + install, + version, + mapState, + mapMutations, + mapGetters, + mapActions, + createNamespacedHelpers, + createLogger +} From d70d27a13dd3d2a7555a767d2990c83eafa34986 Mon Sep 17 00:00:00 2001 From: Sebastiaan Marynissen Date: Sat, 14 Nov 2020 00:03:55 +0100 Subject: [PATCH 2/5] Add tests for esm entry point --- package.json | 3 ++- test/esm/esm-import.mjs | 26 ++++++++++++++++++++++++++ test/esm/esm-test.js | 7 +++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/esm/esm-import.mjs create mode 100644 test/esm/esm-test.js diff --git a/package.json b/package.json index d942e1ccc..6b20d5ad9 100644 --- a/package.json +++ b/package.json @@ -28,11 +28,12 @@ "build:main": "node scripts/build-main.js", "build:logger": "node scripts/build-logger.js", "lint": "eslint src test", - "test": "npm run lint && npm run test:types && npm run test:unit && npm run test:ssr && npm run test:e2e", + "test": "npm run lint && npm run test:types && npm run test:unit && npm run test:ssr && npm run test:e2e && npm run test:esm", "test:unit": "jest --testPathIgnorePatterns test/e2e", "test:e2e": "start-server-and-test dev http://localhost:8080 'jest --testPathIgnorePatterns test/unit'", "test:ssr": "cross-env VUE_ENV=server jest --testPathIgnorePatterns test/e2e", "test:types": "tsc -p types/test", + "test:esm": "node test/esm/esm-test.js", "coverage": "jest --testPathIgnorePatterns test/e2e --coverage", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s", "release": "node scripts/release.js", diff --git a/test/esm/esm-import.mjs b/test/esm/esm-import.mjs new file mode 100644 index 000000000..2819a9e53 --- /dev/null +++ b/test/esm/esm-import.mjs @@ -0,0 +1,26 @@ +import assert from 'assert' +import { createRequire } from 'module' +import Vuex, { + Store, + install, + version, + mapState, + mapMutations, + mapGetters, + mapActions, + createNamespacedHelpers, + createLogger +} from 'vuex' + +const require = createRequire(import.meta.url) +const cjs = require('vuex') +assert.equal(Vuex, cjs) +assert.equal(Store, cjs.Store) +assert.equal(install, cjs.install) +assert.equal(version, cjs.version) +assert.equal(mapState, cjs.mapState) +assert.equal(mapMutations, cjs.mapMutations) +assert.equal(mapGetters, cjs.mapGetters) +assert.equal(mapActions, cjs.mapActions) +assert.equal(createNamespacedHelpers, cjs.createNamespacedHelpers) +assert.equal(createLogger, cjs.createLogger) diff --git a/test/esm/esm-test.js b/test/esm/esm-test.js new file mode 100644 index 000000000..a4a19650f --- /dev/null +++ b/test/esm/esm-test.js @@ -0,0 +1,7 @@ +// Only test esm entry points on Node.14 or higher. +const [major] = process.versions.node.split('.') +if (+major >= 14) { + (async function () { + await import('./esm-import.mjs') + })().catch(console.error) +} From 8d0b5006d8954d6e8bf5ed343885468eca067af4 Mon Sep 17 00:00:00 2001 From: Sebastiaan Marynissen Date: Fri, 20 Nov 2020 10:53:49 +0100 Subject: [PATCH 3/5] build: add esm entry point to build --- dist/vuex.mjs | 25 +++++++++++++++++++++++++ package.json | 2 +- scripts/build.js | 12 +++++++++++- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 dist/vuex.mjs diff --git a/dist/vuex.mjs b/dist/vuex.mjs new file mode 100644 index 000000000..18b4018b0 --- /dev/null +++ b/dist/vuex.mjs @@ -0,0 +1,25 @@ +import Vuex from '../dist/vuex.common.js' +const { + Store, + install, + version, + mapState, + mapMutations, + mapGetters, + mapActions, + createNamespacedHelpers, + createLogger +} = Vuex + +export { + Vuex as default, + Store, + install, + version, + mapState, + mapMutations, + mapGetters, + mapActions, + createNamespacedHelpers, + createLogger +} diff --git a/package.json b/package.json index 6b20d5ad9..a1ec03ac6 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "exports": { ".": { "require": "./dist/vuex.common.js", - "import": "./src/index.mjs" + "import": "./dist/vuex.mjs" }, "./": "./" }, diff --git a/scripts/build.js b/scripts/build.js index b77b162af..81e71acb3 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -5,7 +5,10 @@ const { gzipSync } = require('zlib') const { compress } = require('brotli') async function run(config, files) { - await build(config) + await Promise.all([ + build(config), + copy() + ]) checkAllSizes(files) } @@ -13,6 +16,13 @@ async function build(config) { await execa('rollup', ['-c', config], { stdio: 'inherit' }) } +async function copy() { + await fs.copy( + 'src/index.mjs', + 'dist/vuex.mjs' + ) +} + function checkAllSizes(files) { console.log() files.map((f) => checkSize(f)) From f8410df78d6a23bf9783534563cf955d303c274b Mon Sep 17 00:00:00 2001 From: Kia King Ishii Date: Sun, 22 Nov 2020 22:27:05 +0900 Subject: [PATCH 4/5] style: adjust code styles --- scripts/build.js | 10 ++-------- src/index.mjs | 1 + test/esm/esm-import.mjs | 4 ++++ test/esm/esm-test.js | 3 ++- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/build.js b/scripts/build.js index 81e71acb3..cfb554c96 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -5,10 +5,7 @@ const { gzipSync } = require('zlib') const { compress } = require('brotli') async function run(config, files) { - await Promise.all([ - build(config), - copy() - ]) + await Promise.all([build(config), copy()]) checkAllSizes(files) } @@ -17,10 +14,7 @@ async function build(config) { } async function copy() { - await fs.copy( - 'src/index.mjs', - 'dist/vuex.mjs' - ) + await fs.copy('src/index.mjs', 'dist/vuex.mjs') } function checkAllSizes(files) { diff --git a/src/index.mjs b/src/index.mjs index 18b4018b0..2140898f4 100644 --- a/src/index.mjs +++ b/src/index.mjs @@ -1,4 +1,5 @@ import Vuex from '../dist/vuex.common.js' + const { Store, install, diff --git a/test/esm/esm-import.mjs b/test/esm/esm-import.mjs index 2819a9e53..b708c9b77 100644 --- a/test/esm/esm-import.mjs +++ b/test/esm/esm-import.mjs @@ -1,5 +1,7 @@ import assert from 'assert' + import { createRequire } from 'module' + import Vuex, { Store, install, @@ -13,7 +15,9 @@ import Vuex, { } from 'vuex' const require = createRequire(import.meta.url) + const cjs = require('vuex') + assert.equal(Vuex, cjs) assert.equal(Store, cjs.Store) assert.equal(install, cjs.install) diff --git a/test/esm/esm-test.js b/test/esm/esm-test.js index a4a19650f..bd2cd6c11 100644 --- a/test/esm/esm-test.js +++ b/test/esm/esm-test.js @@ -1,5 +1,6 @@ -// Only test esm entry points on Node.14 or higher. +// only test esm entry points on Node.14 or higher const [major] = process.versions.node.split('.') + if (+major >= 14) { (async function () { await import('./esm-import.mjs') From 916f2af28f2856d8ce7baa94c59ed86a7b503e41 Mon Sep 17 00:00:00 2001 From: Kia King Ishii Date: Sun, 22 Nov 2020 22:28:44 +0900 Subject: [PATCH 5/5] chore: remove dist file --- dist/vuex.mjs | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 dist/vuex.mjs diff --git a/dist/vuex.mjs b/dist/vuex.mjs deleted file mode 100644 index 18b4018b0..000000000 --- a/dist/vuex.mjs +++ /dev/null @@ -1,25 +0,0 @@ -import Vuex from '../dist/vuex.common.js' -const { - Store, - install, - version, - mapState, - mapMutations, - mapGetters, - mapActions, - createNamespacedHelpers, - createLogger -} = Vuex - -export { - Vuex as default, - Store, - install, - version, - mapState, - mapMutations, - mapGetters, - mapActions, - createNamespacedHelpers, - createLogger -}