Skip to content

Commit

Permalink
feat: restore commonjs bundle (#10984)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreen committed Dec 15, 2022
1 parent 185bb97 commit 35fd620
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 12 deletions.
6 changes: 6 additions & 0 deletions auto/auto.cjs
@@ -0,0 +1,6 @@
const exports = require('../dist/chart.cjs');
const {Chart, registerables} = exports;

Chart.register(...registerables);

module.exports = Object.assign(Chart, exports);
1 change: 1 addition & 0 deletions helpers/helpers.cjs
@@ -0,0 +1 @@
module.exports = require('../dist/helpers.cjs');
9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -15,15 +15,18 @@
"exports": {
".": {
"types": "./dist/types.d.ts",
"import": "./dist/chart.js"
"import": "./dist/chart.js",
"require": "./dist/chart.cjs"
},
"./auto": {
"types": "./auto/auto.d.ts",
"import": "./auto/auto.js"
"import": "./auto/auto.js",
"require": "./auto/auto.cjs"
},
"./helpers": {
"types": "./helpers/helpers.d.ts",
"import": "./helpers/helpers.js"
"import": "./helpers/helpers.js",
"require": "./helpers/helpers.cjs"
}
},
"types": "./dist/types.d.ts",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions rollup.config.js
Expand Up @@ -77,5 +77,26 @@ export default [
indent: false,
sourcemap: true,
},
},

// CommonJS builds
// dist/chart.js
// helpers/*.js
{
input: {
'dist/chart': 'src/index.ts',
'dist/helpers': 'src/helpers/index.ts'
},
plugins: plugins(),
external: _ => (/node_modules/).test(_),
output: {
dir: './',
chunkFileNames: 'dist/chunks/[name].cjs',
entryFileNames: '[name].cjs',
banner,
format: 'commonjs',
indent: false,
sourcemap: true,
},
}
];
10 changes: 10 additions & 0 deletions test/integration/node-commonjs/package.json
@@ -0,0 +1,10 @@
{
"private": true,
"description": "chart.js should work in Node",
"scripts": {
"test": "node test.js"
},
"dependencies": {
"chart.js": "workspace:*"
}
}
7 changes: 7 additions & 0 deletions test/integration/node-commonjs/test.js
@@ -0,0 +1,7 @@
const {Chart} = require('chart.js');
const {valueOrDefault} = require('chart.js/helpers');

Chart.register({
id: 'TEST_PLUGIN',
dummyValue: valueOrDefault(0, 1)
});
15 changes: 6 additions & 9 deletions test/integration/node/test.cjs
@@ -1,10 +1,7 @@
/* eslint-disable es/no-dynamic-import */
Promise.all([
import('chart.js'),
import('chart.js/helpers')
]).then(([{Chart}, {valueOrDefault}]) => {
Chart.register({
id: 'TEST_PLUGIN',
dummyValue: valueOrDefault(0, 1)
});
const {Chart} = require('chart.js');
const {valueOrDefault} = require('chart.js/helpers');

Chart.register({
id: 'TEST_PLUGIN',
dummyValue: valueOrDefault(0, 1)
});

0 comments on commit 35fd620

Please sign in to comment.