From bc84a98ec62c6c3af21a585e3f9c0edc3a62fdda Mon Sep 17 00:00:00 2001 From: Dan Onoshko Date: Fri, 16 Dec 2022 16:53:27 +0400 Subject: [PATCH] fix: hotfix chart.js/auto for commonjs (#10992) * fix: hotfix chart.js/auto for commonjs * fix: add auto.cjs to side effects --- auto/auto.cjs | 6 +++--- package.json | 1 + test/integration/node-commonjs/package.json | 4 +++- test/integration/node-commonjs/test-auto.js | 7 +++++++ 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 test/integration/node-commonjs/test-auto.js diff --git a/auto/auto.cjs b/auto/auto.cjs index 4a4590a4b0f..62e08b16dfc 100644 --- a/auto/auto.cjs +++ b/auto/auto.cjs @@ -1,6 +1,6 @@ -const exports = require('../dist/chart.cjs'); -const {Chart, registerables} = exports; +const chartjs = require('../dist/chart.cjs'); +const {Chart, registerables} = chartjs; Chart.register(...registerables); -module.exports = Object.assign(Chart, exports); +module.exports = Object.assign(Chart, chartjs); diff --git a/package.json b/package.json index cac1fb077aa..3b990e8f808 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "type": "module", "sideEffects": [ "./auto/auto.js", + "./auto/auto.cjs", "./dist/chart.umd.js" ], "jsdelivr": "./dist/chart.umd.js", diff --git a/test/integration/node-commonjs/package.json b/test/integration/node-commonjs/package.json index 19c9b2c0ccc..b2a0e280434 100644 --- a/test/integration/node-commonjs/package.json +++ b/test/integration/node-commonjs/package.json @@ -2,7 +2,9 @@ "private": true, "description": "chart.js should work in Node", "scripts": { - "test": "node test.js" + "test": "npm run test-index && npm run test-auto", + "test-index": "node test.js", + "test-auto": "node test-auto.js" }, "dependencies": { "chart.js": "workspace:*" diff --git a/test/integration/node-commonjs/test-auto.js b/test/integration/node-commonjs/test-auto.js new file mode 100644 index 00000000000..a0a58ff619e --- /dev/null +++ b/test/integration/node-commonjs/test-auto.js @@ -0,0 +1,7 @@ +const Chart = require('chart.js/auto'); +const {valueOrDefault} = require('chart.js/helpers'); + +Chart.register({ + id: 'TEST_PLUGIN', + dummyValue: valueOrDefault(0, 1) +});