]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
feat: restore commonjs bundle (#10984)
authorDan Onoshko <danon0404@gmail.com>
Thu, 15 Dec 2022 23:11:11 +0000 (03:11 +0400)
committerGitHub <noreply@github.com>
Thu, 15 Dec 2022 23:11:11 +0000 (01:11 +0200)
auto/auto.cjs [new file with mode: 0644]
helpers/helpers.cjs [new file with mode: 0644]
package.json
pnpm-lock.yaml
rollup.config.js
test/integration/node-commonjs/package.json [new file with mode: 0644]
test/integration/node-commonjs/test.js [new file with mode: 0644]
test/integration/node/test.cjs

diff --git a/auto/auto.cjs b/auto/auto.cjs
new file mode 100644 (file)
index 0000000..4a4590a
--- /dev/null
@@ -0,0 +1,6 @@
+const exports = require('../dist/chart.cjs');
+const {Chart, registerables} = exports;
+
+Chart.register(...registerables);
+
+module.exports = Object.assign(Chart, exports);
diff --git a/helpers/helpers.cjs b/helpers/helpers.cjs
new file mode 100644 (file)
index 0000000..d476848
--- /dev/null
@@ -0,0 +1 @@
+module.exports = require('../dist/helpers.cjs');
index 4c5ccae6f9651c4718ab1342e03977330033b619..cac1fb077aa7ca37197851ddc8a1f8b8df33a12e 100644 (file)
     "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",
index 1f461b883af17943dc5e7a19e9e8b6da04a07b1e..65dae2628722bf008d664b4f3570d5c5198a5572 100644 (file)
@@ -152,6 +152,12 @@ importers:
     dependencies:
       chart.js: link:../../..
 
+  test/integration/node-commonjs:
+    specifiers:
+      chart.js: workspace:*
+    dependencies:
+      chart.js: link:../../..
+
   test/integration/react-browser:
     specifiers:
       '@babel/core': ^7.0.0
index d3e6fc54c0f196aae8fd643eec50cc26dfb9e359..c6a77531048fc70821d060ce21cfbffecf602680 100644 (file)
@@ -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,
+    },
   }
 ];
diff --git a/test/integration/node-commonjs/package.json b/test/integration/node-commonjs/package.json
new file mode 100644 (file)
index 0000000..19c9b2c
--- /dev/null
@@ -0,0 +1,10 @@
+{
+  "private": true,
+  "description": "chart.js should work in Node",
+  "scripts": {
+    "test": "node test.js"
+  },
+  "dependencies": {
+    "chart.js": "workspace:*"
+  }
+}
diff --git a/test/integration/node-commonjs/test.js b/test/integration/node-commonjs/test.js
new file mode 100644 (file)
index 0000000..1d43d2d
--- /dev/null
@@ -0,0 +1,7 @@
+const {Chart} = require('chart.js');
+const {valueOrDefault} = require('chart.js/helpers');
+
+Chart.register({
+  id: 'TEST_PLUGIN',
+  dummyValue: valueOrDefault(0, 1)
+});
index 94f86f2214faf3ea98a1350bcb7595102592e603..1d43d2d239b07eed5d951ffbcb2a1c6580573094 100644 (file)
@@ -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)
 });