From 7fd4ae4e8c487759d675af5947d1b55fbd0b3391 Mon Sep 17 00:00:00 2001 From: Dan Onoshko Date: Mon, 5 Dec 2022 21:09:22 +0400 Subject: [PATCH] feat: upgrade Chart.js to v4 (#960) Chart.js v4 support BREAKING CHANGE: package now is ESM-only, no CommonJS support --- .eslintrc.js => .eslintrc.cjs | 2 +- .size-limit.json | 11 -------- .storybook/manager.js | 2 +- .storybook/package.json | 3 +++ package.json | 11 +++++--- rollup.config.js | 32 +++++++++++++++++++++++ rollup.config.mjs | 45 -------------------------------- sandboxes/bar/package.json | 5 ++-- sandboxes/bar/src/App.vue | 2 +- sandboxes/bubble/package.json | 5 ++-- sandboxes/bubble/src/App.vue | 2 +- sandboxes/custom/package.json | 5 ++-- sandboxes/custom/src/App.vue | 4 +-- sandboxes/doughnut/package.json | 5 ++-- sandboxes/doughnut/src/App.vue | 2 +- sandboxes/line/package.json | 5 ++-- sandboxes/line/src/App.vue | 2 +- sandboxes/pie/package.json | 5 ++-- sandboxes/pie/src/App.vue | 2 +- sandboxes/polar-area/src/App.vue | 2 +- sandboxes/radar/package.json | 5 ++-- sandboxes/radar/src/App.vue | 2 +- sandboxes/reactive/package.json | 5 ++-- sandboxes/reactive/src/App.vue | 2 +- sandboxes/scatter/package.json | 5 ++-- sandboxes/scatter/src/App.vue | 2 +- src/chart.ts | 7 ++--- src/index.ts | 6 ++--- src/props.ts | 6 ++--- src/typedCharts.ts | 6 ++--- src/types.ts | 2 ++ stories/bar.stories.ts | 4 +-- stories/bubble.stories.ts | 4 +-- stories/custom.stories.ts | 4 +-- stories/doughnut.stories.ts | 4 +-- stories/line.stories.ts | 4 +-- stories/pie.stories.ts | 4 +-- stories/polarArea.stories.ts | 4 +-- stories/radar.stories.ts | 4 +-- stories/reactive.stories.ts | 4 +-- stories/scatter.stories.ts | 4 +-- test/Bar.spec.ts | 4 +-- test/Bubble.spec.ts | 4 +-- test/Doughnut.spec.ts | 4 +-- test/Line.spec.ts | 4 +-- test/Pie.spec.ts | 4 +-- test/PolarArea.spec.ts | 4 +-- test/Radar.spec.ts | 4 +-- test/Scatter.spec.ts | 4 +-- test/types.test-d.ts | 4 +-- tsconfig.json | 7 ++--- 51 files changed, 139 insertions(+), 144 deletions(-) rename .eslintrc.js => .eslintrc.cjs (98%) create mode 100644 .storybook/package.json create mode 100644 rollup.config.js delete mode 100644 rollup.config.mjs diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 98% rename from .eslintrc.js rename to .eslintrc.cjs index 69d9d53d..934c8dad 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -31,5 +31,5 @@ module.exports = { } } ], - ignorePatterns: ['dist/**/*', 'node_modules/**/*', 'rollup.config.mjs'] + ignorePatterns: ['dist/**/*', 'node_modules/**/*', 'rollup.config.js'] } diff --git a/.size-limit.json b/.size-limit.json index dd0eb0b3..5261dc91 100644 --- a/.size-limit.json +++ b/.size-limit.json @@ -1,15 +1,4 @@ [ - { - "path": "dist/index.cjs", - "limit": "1.75 KB", - "webpack": false, - "running": false - }, - { - "path": "dist/index.cjs", - "limit": "1 KB", - "import": "{ Bar }" - }, { "path": "dist/index.js", "limit": "1.7 KB", diff --git a/.storybook/manager.js b/.storybook/manager.js index da7d4c1a..7f903a97 100644 --- a/.storybook/manager.js +++ b/.storybook/manager.js @@ -1,6 +1,6 @@ import { addons } from '@storybook/addons' -import { theme } from './theme' +import { theme } from './theme.js' addons.setConfig({ theme, diff --git a/.storybook/package.json b/.storybook/package.json new file mode 100644 index 00000000..5bbefffb --- /dev/null +++ b/.storybook/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/package.json b/package.json index df8dd9d6..3347037e 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name": "vue-chartjs", + "type": "module", "version": "4.1.2", "description": "Vue.js wrapper for chart.js for creating beautiful charts.", "author": "Jakub Juszczak ", @@ -37,11 +38,13 @@ "Charts" ], "sideEffects": false, - "main": "./src/index.ts", "types": "./dist/index.d.ts", + "exports": "./src/index.ts", "publishConfig": { - "main": "./dist/index.cjs", - "module": "./dist/index.js", + "exports": { + "import": "./dist/index.js", + "types": "./dist/index.d.ts" + }, "directory": "package" }, "files": [ @@ -68,7 +71,7 @@ "updateGitHooks": "simple-git-hooks" }, "peerDependencies": { - "chart.js": "^3.7.0", + "chart.js": "^4.0.0", "vue": "^3.0.0-0 || ^2.6.0" }, "devDependencies": { diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 00000000..d2d47531 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,32 @@ +import { swc } from 'rollup-plugin-swc3' +import { nodeResolve } from '@rollup/plugin-node-resolve' +import pkg from './package.json' assert { type: 'json' } + +const extensions = ['.js', '.ts'] +const external = _ => /node_modules/.test(_) && !/@swc\/helpers/.test(_) +const plugins = targets => [ + nodeResolve({ + extensions + }), + swc({ + tsconfig: false, + env: { + targets + }, + module: { + type: 'es6' + }, + sourceMaps: true + }) +] + +export default { + input: pkg.exports, + plugins: plugins('defaults and supports es6-module'), + external, + output: { + format: 'es', + file: pkg.publishConfig.exports.import, + sourcemap: true + } +} diff --git a/rollup.config.mjs b/rollup.config.mjs deleted file mode 100644 index 0b5b60ff..00000000 --- a/rollup.config.mjs +++ /dev/null @@ -1,45 +0,0 @@ -import { swc } from 'rollup-plugin-swc3' -import { nodeResolve } from '@rollup/plugin-node-resolve' -import pkg from './package.json' assert { type: 'json' } - -const extensions = ['.js', '.ts'] -const external = _ => /node_modules/.test(_) && !/@swc\/helpers/.test(_) -const plugins = (targets) => [ - nodeResolve({ - extensions - }), - swc({ - tsconfig: false, - env: { - targets - }, - module: { - type: 'es6' - }, - sourceMaps: true - }) -] - -export default [ - { - input: pkg.main, - plugins: plugins('defaults, not ie 11, not ie_mob 11'), - external, - output: { - format: 'cjs', - file: pkg.publishConfig.main, - exports: 'named', - sourcemap: true - } - }, - { - input: pkg.main, - plugins: plugins('defaults and supports es6-module'), - external, - output: { - format: 'es', - file: pkg.publishConfig.module, - sourcemap: true - } - } -] diff --git a/sandboxes/bar/package.json b/sandboxes/bar/package.json index 17f5a5dc..df369262 100644 --- a/sandboxes/bar/package.json +++ b/sandboxes/bar/package.json @@ -1,11 +1,12 @@ { + "type": "module", "scripts": { "start": "vite" }, "dependencies": { - "chart.js": "^3.8.0", + "chart.js": "^4.0.0", "vue": "^3.2.31", - "vue-chartjs": "^4.0.0" + "vue-chartjs": "^5.0.0" }, "devDependencies": { "@vitejs/plugin-vue": "^3.0.1", diff --git a/sandboxes/bar/src/App.vue b/sandboxes/bar/src/App.vue index 2cf53cdd..239a3ca0 100644 --- a/sandboxes/bar/src/App.vue +++ b/sandboxes/bar/src/App.vue @@ -13,7 +13,7 @@ import { LinearScale } from 'chart.js' import { Bar } from 'vue-chartjs' -import * as chartConfig from './chartConfig' +import * as chartConfig from './chartConfig.js' ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend) diff --git a/sandboxes/bubble/package.json b/sandboxes/bubble/package.json index 17f5a5dc..df369262 100644 --- a/sandboxes/bubble/package.json +++ b/sandboxes/bubble/package.json @@ -1,11 +1,12 @@ { + "type": "module", "scripts": { "start": "vite" }, "dependencies": { - "chart.js": "^3.8.0", + "chart.js": "^4.0.0", "vue": "^3.2.31", - "vue-chartjs": "^4.0.0" + "vue-chartjs": "^5.0.0" }, "devDependencies": { "@vitejs/plugin-vue": "^3.0.1", diff --git a/sandboxes/bubble/src/App.vue b/sandboxes/bubble/src/App.vue index 50693f1b..787e5d86 100644 --- a/sandboxes/bubble/src/App.vue +++ b/sandboxes/bubble/src/App.vue @@ -11,7 +11,7 @@ import { LinearScale } from 'chart.js' import { Bubble } from 'vue-chartjs' -import * as chartConfig from './chartConfig' +import * as chartConfig from './chartConfig.js' ChartJS.register(LinearScale, PointElement, Tooltip, Legend) diff --git a/sandboxes/custom/package.json b/sandboxes/custom/package.json index 17f5a5dc..df369262 100644 --- a/sandboxes/custom/package.json +++ b/sandboxes/custom/package.json @@ -1,11 +1,12 @@ { + "type": "module", "scripts": { "start": "vite" }, "dependencies": { - "chart.js": "^3.8.0", + "chart.js": "^4.0.0", "vue": "^3.2.31", - "vue-chartjs": "^4.0.0" + "vue-chartjs": "^5.0.0" }, "devDependencies": { "@vitejs/plugin-vue": "^3.0.1", diff --git a/sandboxes/custom/src/App.vue b/sandboxes/custom/src/App.vue index a9007583..9ba2accc 100644 --- a/sandboxes/custom/src/App.vue +++ b/sandboxes/custom/src/App.vue @@ -13,8 +13,8 @@ import { Tooltip, Legend } from 'chart.js' -import LineWithLineChart from './components/LineWithLineChart' -import * as chartConfig from './chartConfig' +import LineWithLineChart from './components/LineWithLineChart.js' +import * as chartConfig from './chartConfig.js' ChartJS.register( CategoryScale, diff --git a/sandboxes/doughnut/package.json b/sandboxes/doughnut/package.json index 17f5a5dc..df369262 100644 --- a/sandboxes/doughnut/package.json +++ b/sandboxes/doughnut/package.json @@ -1,11 +1,12 @@ { + "type": "module", "scripts": { "start": "vite" }, "dependencies": { - "chart.js": "^3.8.0", + "chart.js": "^4.0.0", "vue": "^3.2.31", - "vue-chartjs": "^4.0.0" + "vue-chartjs": "^5.0.0" }, "devDependencies": { "@vitejs/plugin-vue": "^3.0.1", diff --git a/sandboxes/doughnut/src/App.vue b/sandboxes/doughnut/src/App.vue index 085fb258..cfe2fca1 100644 --- a/sandboxes/doughnut/src/App.vue +++ b/sandboxes/doughnut/src/App.vue @@ -5,7 +5,7 @@