From ce375a6876f35b545aca70c138ba12640c931c5d Mon Sep 17 00:00:00 2001 From: Dan Onoshko Date: Fri, 5 Aug 2022 05:43:26 +0700 Subject: [PATCH] feat: add ESM support (#10525) * feat: add ESM support * build: rename UMD bundle * chore: edit supbackages description * style: disable es/no-import-meta linter rule * test: dynamic import in cjs module * docs: edit integrations page * docs: review fixes * chore: remove useless regex in webpack config * ci: test size-limit only for ESM bundle --- .eslintignore | 2 +- .eslintrc.yml | 1 + .gitignore | 1 + .size-limit.js => .size-limit.cjs | 16 ++--- auto/auto.d.ts | 4 ++ auto/auto.js | 7 +- auto/auto.mjs | 5 -- auto/auto.mts | 4 -- auto/package.json | 7 +- docs/.vuepress/{config.js => config.cjs} | 6 +- docs/getting-started/integration.md | 21 +++--- docs/scripts/components.js | 2 +- docs/scripts/helpers.js | 2 +- docs/scripts/register.js | 2 +- docs/scripts/utils.js | 2 +- helpers/{helpers.mts => helpers.d.ts} | 0 helpers/helpers.js | 2 +- helpers/helpers.mjs | 1 - helpers/package.json | 9 +-- karma.conf.js => karma.conf.cjs | 14 ++-- package-lock.json | 16 ----- package.json | 24 ++++--- rollup.config.js => rollup.config.cjs | 63 +++--------------- src/core/core.adapters.js | 2 +- src/core/core.controller.js | 8 +-- src/core/core.interaction.js | 4 +- src/core/core.plugins.js | 2 +- src/helpers/helpers.canvas.js | 2 +- src/helpers/helpers.core.js | 2 +- src/helpers/helpers.dom.js | 2 +- src/index.esm.js | 25 ------- src/index.js | 65 ++++++------------- src/index.umd.js | 52 +++++++++++++++ src/plugins/plugin.filler/filler.options.js | 4 +- src/plugins/plugin.legend.js | 2 +- src/plugins/plugin.tooltip.js | 4 +- test/BasicChartWebWorker.js | 2 +- ...tegration-test.js => integration-test.cjs} | 0 test/integration/node/package.json | 8 +-- test/integration/node/test.cjs | 15 +++-- test/integration/node/{test.mjs => test.js} | 0 test/{seed-reporter.js => seed-reporter.cjs} | 0 tsconfig.json | 2 +- types/adapters.d.ts | 2 +- types/animation.d.ts | 2 +- types/helpers/helpers.canvas.d.ts | 2 +- types/helpers/helpers.dom.d.ts | 2 +- types/helpers/helpers.easing.d.ts | 2 +- types/helpers/helpers.options.d.ts | 2 +- types/{index.esm.d.ts => index.d.ts} | 0 types/tests/animation.ts | 2 +- types/tests/autogen.js | 5 +- types/tests/chart_types.ts | 2 +- .../tests/controllers/bubble_chart_options.ts | 2 +- .../tests/controllers/doughnut_meta_total.ts | 2 +- types/tests/controllers/doughnut_offset.ts | 2 +- .../controllers/doughnut_outer_radius.ts | 2 +- .../line_scriptable_parsed_data.ts | 2 +- types/tests/controllers/line_segments.ts | 2 +- types/tests/controllers/line_span_gaps.ts | 2 +- types/tests/controllers/line_styling_array.ts | 2 +- .../radar_dataset_indexable_options.ts | 2 +- types/tests/data_types.ts | 2 +- types/tests/dataset_null_data.ts | 2 +- types/tests/defaults.ts | 2 +- .../elements/scriptable_element_options.ts | 2 +- types/tests/extensions/plugin.ts | 2 +- types/tests/extensions/scale.ts | 4 +- types/tests/interaction.ts | 2 +- types/tests/layout/position.ts | 2 +- types/tests/options.ts | 2 +- types/tests/overrides.ts | 2 +- types/tests/parsed.data.type.ts | 2 +- types/tests/plugins/defaults.ts | 2 +- .../plugin.decimation/decimation_algorithm.ts | 2 +- .../plugins/plugin.filler/fill_target_true.ts | 2 +- .../plugins/plugin.tooltip/chart.tooltip.ts | 2 +- .../plugin.tooltip/tooltip_dataset_type.ts | 2 +- .../plugin.tooltip/tooltip_parsed_data.ts | 2 +- .../tooltip_parsed_data_chart_defaults.ts | 2 +- .../tooltip_scriptable_background_color.ts | 2 +- types/tests/register.ts | 2 +- types/tests/scales/chart_options.ts | 2 +- types/tests/scales/options.ts | 2 +- types/tests/scales/time_string_max.ts | 2 +- types/tests/scriptable.ts | 2 +- types/tests/scriptable_core_chart_options.ts | 2 +- types/tests/test_instance_assignment.ts | 2 +- types/tests/tsconfig.json | 2 +- 89 files changed, 227 insertions(+), 280 deletions(-) rename .size-limit.js => .size-limit.cjs (79%) create mode 100644 auto/auto.d.ts delete mode 100644 auto/auto.mjs delete mode 100644 auto/auto.mts rename docs/.vuepress/{config.js => config.cjs} (98%) rename helpers/{helpers.mts => helpers.d.ts} (100%) delete mode 100644 helpers/helpers.mjs rename karma.conf.js => karma.conf.cjs (93%) rename rollup.config.js => rollup.config.cjs (52%) delete mode 100644 src/index.esm.js create mode 100644 src/index.umd.js rename test/integration/{integration-test.js => integration-test.cjs} (100%) rename test/integration/node/{test.mjs => test.js} (100%) rename test/{seed-reporter.js => seed-reporter.cjs} (100%) rename types/{index.esm.d.ts => index.d.ts} (100%) diff --git a/.eslintignore b/.eslintignore index 5f985010b..a261f2917 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1 @@ -dist/*.js +dist/* diff --git a/.eslintrc.yml b/.eslintrc.yml index 072c9ab2a..781df4c2d 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -28,6 +28,7 @@ rules: no-empty-function: "off" no-use-before-define: ["error", { "functions": false }] # disable everything, except Rest/Spread Properties in ES2018 + es/no-import-meta: "off" es/no-async-iteration: "error" es/no-malformed-template-literals: "error" es/no-regexp-lookbehind-assertions: "error" diff --git a/.gitignore b/.gitignore index 112570e74..a03307d82 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ npm-debug.log* build/ # generated typedocs docs/api +docs/.vuepress/dist # Development .DS_Store diff --git a/.size-limit.js b/.size-limit.cjs similarity index 79% rename from .size-limit.js rename to .size-limit.cjs index 9fbf52b84..e9ea99edd 100644 --- a/.size-limit.js +++ b/.size-limit.cjs @@ -7,46 +7,40 @@ function modifyWebpackConfig(config) { module.exports = [ { path: 'dist/chart.js', - limit: '94.8 KB', - webpack: false, - running: false - }, - { - path: 'dist/chart.esm.js', limit: '75 KB', webpack: false, running: false }, { - path: 'dist/chart.esm.js', + path: 'dist/chart.js', limit: '34 KB', import: '{ Chart }', running: false, modifyWebpackConfig }, { - path: 'dist/chart.esm.js', + path: 'dist/chart.js', limit: '19.5 KB', import: '{ BarController, BubbleController, DoughnutController, LineController, PolarAreaController, PieController, RadarController, ScatterController }', running: false, modifyWebpackConfig }, { - path: 'dist/chart.esm.js', + path: 'dist/chart.js', limit: '14 KB', import: '{ ArcElement, LineElement, PointElement, BarElement }', running: false, modifyWebpackConfig }, { - path: 'dist/chart.esm.js', + path: 'dist/chart.js', limit: '27 KB', import: '{ Decimation, Filler, Legend, SubTitle, Title, Tooltip }', running: false, modifyWebpackConfig }, { - path: 'dist/chart.esm.js', + path: 'dist/chart.js', limit: '22 KB', import: '{ CategoryScale, LinearScale, LogarithmicScale, RadialLinearScale, TimeScale, TimeSeriesScale }', running: false, diff --git a/auto/auto.d.ts b/auto/auto.d.ts new file mode 100644 index 000000000..566f043ac --- /dev/null +++ b/auto/auto.d.ts @@ -0,0 +1,4 @@ +import {Chart} from '../types'; + +export * from '../types'; +export default Chart; diff --git a/auto/auto.js b/auto/auto.js index 235580fef..924a0f900 100644 --- a/auto/auto.js +++ b/auto/auto.js @@ -1 +1,6 @@ -module.exports = require('../dist/chart'); +import {Chart, registerables} from '../dist/chart.js'; + +Chart.register(...registerables); + +export * from '../dist/chart.js'; +export default Chart; diff --git a/auto/auto.mjs b/auto/auto.mjs deleted file mode 100644 index 95d0a9a92..000000000 --- a/auto/auto.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import {Chart, registerables} from '../dist/chart.mjs'; - -Chart.register(...registerables); - -export default Chart; diff --git a/auto/auto.mts b/auto/auto.mts deleted file mode 100644 index f0bc38054..000000000 --- a/auto/auto.mts +++ /dev/null @@ -1,4 +0,0 @@ -import { Chart } from '../types/index.esm'; - -export * from '../types/index.esm'; -export default Chart; diff --git a/auto/package.json b/auto/package.json index 5f89c8f90..b3e1dfbf5 100644 --- a/auto/package.json +++ b/auto/package.json @@ -1,8 +1,9 @@ { "name": "chart.js-auto", "private": true, - "description": "auto registering package", + "description": "Auto registering package. Exists to support bundlers without exports support such as webpack 4.", + "type": "module", "main": "auto.js", - "module": "auto.mjs", - "types": "auto.mts" + "exports": "./auto.js", + "types": "auto.d.ts" } diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.cjs similarity index 98% rename from docs/.vuepress/config.js rename to docs/.vuepress/config.cjs index bff3be11f..4ada9ffd5 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.cjs @@ -33,7 +33,7 @@ module.exports = { [ 'vuepress-plugin-typedoc', { - entryPoints: ['../../types/index.esm.d.ts'], + entryPoints: ['../../types/index.d.ts'], hideInPageTOC: true, tsconfig: 'tsconfig.json', sidebar: { @@ -94,12 +94,10 @@ module.exports = { config.merge({ resolve: { alias: { - 'chart.js': path.resolve(__dirname, '../../dist/chart.mjs'), + 'chart.js': path.resolve(__dirname, '../../dist/chart.js'), } } }) - - config.module.rule('js').test(/\.m?jsx?$/) }, markdown: { extendMarkdown: md => { diff --git a/docs/getting-started/integration.md b/docs/getting-started/integration.md index 79fb100e9..e74aef8a6 100644 --- a/docs/getting-started/integration.md +++ b/docs/getting-started/integration.md @@ -5,19 +5,12 @@ Chart.js can be integrated with plain JavaScript or with different module loader ## Script Tag ```html - + ``` -## Common JS - -```javascript -const Chart = require('chart.js'); -const myChart = new Chart(ctx, {...}); -``` - ## Bundlers (Webpack, Rollup, etc.) Chart.js 3 is tree-shakeable, so it is necessary to import and register the controllers, elements, scales and plugins you are going to use. @@ -96,6 +89,14 @@ And finally there is a separate path to do just the above for you, in one line: import Chart from 'chart.js/auto'; ``` +## CommonJS + +Because Chart.js is an ESM library, in CommonJS modules you should use a dynamic `import`: + +```javascript +const { Chart } = await import('chart.js'); +``` + ### Helper functions If you want to use the helper functions, you will need to import these separately from the helpers package and use them as stand-alone functions. @@ -123,10 +124,10 @@ const chart = new Chart(ctx, { ## Require JS -**Important:** RequireJS [can **not** load CommonJS module as is](https://requirejs.org/docs/commonjs.html#intro), so be sure to require one of the UMD builds instead (i.e. `dist/chart.js`, `dist/chart.min.js`, etc.). +**Important:** RequireJS can load only [AMD modules](https://requirejs.org/docs/whyamd.html), so be sure to require one of the UMD builds instead (i.e. `dist/chart.umd.js`). ```javascript -require(['path/to/chartjs/dist/chart.min.js'], function(Chart){ +require(['path/to/chartjs/dist/chart.umd.js'], function(Chart){ const myChart = new Chart(ctx, {...}); }); ``` diff --git a/docs/scripts/components.js b/docs/scripts/components.js index 9334eb2d7..79f7841f3 100644 --- a/docs/scripts/components.js +++ b/docs/scripts/components.js @@ -1,3 +1,3 @@ // Add Chart components needed in samples here. // Usable through `components[name]`. -export {Tooltip} from '../../dist/chart.mjs'; +export {Tooltip} from '../../dist/chart.js'; diff --git a/docs/scripts/helpers.js b/docs/scripts/helpers.js index 39d60b68b..dc989488c 100644 --- a/docs/scripts/helpers.js +++ b/docs/scripts/helpers.js @@ -1,3 +1,3 @@ // Add helpers needed in samples here. // Usable through `helpers[name]`. -export {color, getHoverColor, easingEffects} from '../../dist/helpers.mjs'; +export {color, getHoverColor, easingEffects} from '../../dist/helpers.js'; diff --git a/docs/scripts/register.js b/docs/scripts/register.js index 675f6443a..e9b6a9f89 100644 --- a/docs/scripts/register.js +++ b/docs/scripts/register.js @@ -1,4 +1,4 @@ -import {Chart, registerables} from '../../dist/chart.mjs'; +import {Chart, registerables} from '../../dist/chart.js'; import Log2Axis from './log2'; import './derived-bubble'; import analyzer from './analyzer'; diff --git a/docs/scripts/utils.js b/docs/scripts/utils.js index eab68e5f0..9cd3cfcf8 100644 --- a/docs/scripts/utils.js +++ b/docs/scripts/utils.js @@ -1,7 +1,7 @@ import colorLib from '@kurkle/color'; import {DateTime} from 'luxon'; import 'chartjs-adapter-luxon'; -import {valueOrDefault} from '../../dist/helpers.mjs'; +import {valueOrDefault} from '../../dist/helpers.js'; // Adapted from http://indiegamr.com/generate-repeatable-random-numbers-in-js/ var _seed = Date.now(); diff --git a/helpers/helpers.mts b/helpers/helpers.d.ts similarity index 100% rename from helpers/helpers.mts rename to helpers/helpers.d.ts diff --git a/helpers/helpers.js b/helpers/helpers.js index a762f589b..451fa58f7 100644 --- a/helpers/helpers.js +++ b/helpers/helpers.js @@ -1 +1 @@ -module.exports = require('..').helpers; +export * from '../dist/helpers.js'; diff --git a/helpers/helpers.mjs b/helpers/helpers.mjs deleted file mode 100644 index ca4eee527..000000000 --- a/helpers/helpers.mjs +++ /dev/null @@ -1 +0,0 @@ -export * from '../dist/helpers.esm'; diff --git a/helpers/package.json b/helpers/package.json index 668b05e70..5e45ceaa6 100644 --- a/helpers/package.json +++ b/helpers/package.json @@ -1,8 +1,9 @@ { "name": "chart.js-helpers", "private": true, - "description": "helper package", + "description": "Helpers package. Exists to support bundlers without exports support such as webpack 4.", + "type": "module", "main": "helpers.js", - "module": "helpers.mjs", - "types": "helpers.mts" -} \ No newline at end of file + "exports": "./helpers.js", + "types": "helpers.d.ts" +} diff --git a/karma.conf.js b/karma.conf.cjs similarity index 93% rename from karma.conf.js rename to karma.conf.cjs index 96cbc0e7a..cde1d4faa 100644 --- a/karma.conf.js +++ b/karma.conf.cjs @@ -1,9 +1,9 @@ -const jasmineSeedReporter = require('./test/seed-reporter'); +const jasmineSeedReporter = require('./test/seed-reporter.cjs'); const commonjs = require('@rollup/plugin-commonjs'); const istanbul = require('rollup-plugin-istanbul'); const json = require('@rollup/plugin-json'); const resolve = require('@rollup/plugin-node-resolve').default; -const builds = require('./rollup.config'); +const builds = require('./rollup.config.cjs'); const yargs = require('yargs'); module.exports = function(karma) { @@ -18,9 +18,13 @@ module.exports = function(karma) { // we will prefer the unminified build which is easier to browse and works // better with source mapping. In other cases, pick the minified build to // make sure that the minification process (terser) doesn't break anything. - const regex = karma.autoWatch ? /chart\.js$/ : /chart\.min\.js$/; + const regex = /chart\.umd\.js$/; const build = builds.filter(v => v.output.file && v.output.file.match(regex))[0]; + if (karma.autoWatch) { + build.plugins.pop(); + } + if (args.coverage) { build.plugins = [ json(), @@ -87,14 +91,14 @@ module.exports = function(karma) { 'node_modules/moment-timezone/builds/moment-timezone-with-data.min.js', {pattern: 'test/index.js', watched: false}, {pattern: 'test/BasicChartWebWorker.js', included: false}, - {pattern: 'src/index.js', watched: false}, + {pattern: 'src/index.umd.js', watched: false}, 'node_modules/chartjs-adapter-moment/dist/chartjs-adapter-moment.js', {pattern: specPattern} ], preprocessors: { 'test/index.js': ['rollup'], - 'src/index.js': ['sources'] + 'src/index.umd.js': ['sources'] }, rollupPreprocessor: { diff --git a/package-lock.json b/package-lock.json index d2af668b5..601e16e38 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,6 @@ "moment-timezone": "^0.5.34", "pixelmatch": "^5.2.1", "rollup": "^2.44.0", - "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-istanbul": "^3.0.0", "rollup-plugin-terser": "^7.0.2", @@ -15700,15 +15699,6 @@ "fsevents": "~2.3.2" } }, - "node_modules/rollup-plugin-analyzer": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-analyzer/-/rollup-plugin-analyzer-4.0.0.tgz", - "integrity": "sha512-LL9GEt3bkXp6Wa19SNR5MWcvHNMvuTFYg+eYBZN2OIFhSWN+pEJUQXEKu5BsOeABob3x9PDaLKW7w5iOJnsESQ==", - "dev": true, - "engines": { - "node": ">=8.0.0" - } - }, "node_modules/rollup-plugin-cleanup": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/rollup-plugin-cleanup/-/rollup-plugin-cleanup-3.2.1.tgz", @@ -32864,12 +32854,6 @@ "fsevents": "~2.3.2" } }, - "rollup-plugin-analyzer": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-analyzer/-/rollup-plugin-analyzer-4.0.0.tgz", - "integrity": "sha512-LL9GEt3bkXp6Wa19SNR5MWcvHNMvuTFYg+eYBZN2OIFhSWN+pEJUQXEKu5BsOeABob3x9PDaLKW7w5iOJnsESQ==", - "dev": true - }, "rollup-plugin-cleanup": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/rollup-plugin-cleanup/-/rollup-plugin-cleanup-3.2.1.tgz", diff --git a/package.json b/package.json index de4354c49..23cea7bca 100644 --- a/package.json +++ b/package.json @@ -4,11 +4,16 @@ "description": "Simple HTML5 charts using the canvas element.", "version": "3.9.0", "license": "MIT", - "jsdelivr": "dist/chart.min.js", - "unpkg": "dist/chart.min.js", + "type": "module", + "jsdelivr": "dist/chart.umd.js", + "unpkg": "dist/chart.umd.js", "main": "dist/chart.js", - "module": "dist/chart.mjs", - "types": "types/index.esm.d.ts", + "exports": { + ".": "./dist/chart.js", + "./auto": "./auto/auto.js", + "./helpers": "./helpers/helpers.js" + }, + "types": "types/index.d.ts", "keywords": [ "canvas", "charts", @@ -33,20 +38,20 @@ "scripts": { "autobuild": "rollup -c -w", "build": "rollup -c", - "dev": "karma start --auto-watch --no-single-run --browsers chrome --grep", - "dev:ff": "karma start --auto-watch --no-single-run --browsers firefox --grep", + "dev": "karma start ./karma.conf.cjs --auto-watch --no-single-run --browsers chrome --grep", + "dev:ff": "karma start ./karma.conf.cjs --auto-watch --no-single-run --browsers firefox --grep", "docs": "npm run build && vuepress build docs --no-cache", "docs:dev": "npm run build && vuepress dev docs --no-cache", "lint-js": "eslint \"src/**/*.js\" \"test/**/*.js\" \"docs/**/*.js\"", "lint-md": "eslint \"**/*.md\"", "lint-tsc": "tsc", - "lint-types": "eslint \"types/**/*.ts\" && node -r esm types/tests/autogen.js && tsc -p types/tests/", + "lint-types": "eslint \"types/**/*.ts\" && npm run build && node types/tests/autogen.js && tsc -p types/tests/", "lint": "concurrently \"npm:lint-*\"", "test-size": "size-limit", "test": "npm run lint && npm run test-ci", "test-ci": "concurrently \"npm:test-ci-*\"", - "test-ci-karma": "cross-env NODE_ENV=test karma start --auto-watch --single-run --coverage --grep", - "test-ci-integration": "mocha --full-trace test/integration/*-test.js" + "test-ci-karma": "cross-env NODE_ENV=test karma start ./karma.conf.cjs --auto-watch --single-run --coverage --grep", + "test-ci-integration": "mocha --full-trace test/integration/*-test.cjs" }, "devDependencies": { "@kurkle/color": "^0.2.1", @@ -94,7 +99,6 @@ "moment-timezone": "^0.5.34", "pixelmatch": "^5.2.1", "rollup": "^2.44.0", - "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-istanbul": "^3.0.0", "rollup-plugin-terser": "^7.0.2", diff --git a/rollup.config.js b/rollup.config.cjs similarity index 52% rename from rollup.config.js rename to rollup.config.cjs index aeda6c0cd..d2ca5d36d 100644 --- a/rollup.config.js +++ b/rollup.config.cjs @@ -1,12 +1,9 @@ -const analyze = require('rollup-plugin-analyzer'); const cleanup = require('rollup-plugin-cleanup'); const json = require('@rollup/plugin-json'); const resolve = require('@rollup/plugin-node-resolve').default; const terser = require('rollup-plugin-terser').terser; const pkg = require('./package.json'); -const input = 'src/index.js'; - const banner = `/*! * Chart.js v${pkg.version} * ${pkg.homepage} @@ -15,30 +12,10 @@ const banner = `/*! */`; module.exports = [ - // UMD builds - // dist/chart.min.js - // dist/chart.js + // UMD build + // dist/chart.umd.js { - input, - plugins: [ - json(), - resolve(), - cleanup({ - comments: ['some', /__PURE__/], - sourcemap: true - }), - analyze({summaryOnly: true}) - ], - output: { - name: 'Chart', - file: 'dist/chart.js', - banner, - format: 'umd', - indent: false, - }, - }, - { - input, + input: 'src/index.umd.js', plugins: [ json(), resolve(), @@ -50,45 +27,20 @@ module.exports = [ ], output: { name: 'Chart', - file: 'dist/chart.min.js', + file: 'dist/chart.umd.js', format: 'umd', indent: false, }, }, // ES6 builds - // dist/chart.mjs + // dist/chart.js // helpers/*.js { input: { - 'dist/chart': 'src/index.esm.js', + 'dist/chart': 'src/index.js', 'dist/helpers': 'src/helpers/index.js' }, - plugins: [ - json(), - resolve(), - cleanup({ - sourcemap: true - }), - ], - output: { - dir: './', - chunkFileNames: 'dist/chunks/[name].mjs', - entryFileNames: '[name].mjs', - banner, - format: 'esm', - indent: false, - }, - }, - - // Legacy ES6 builds for backwards compatibility. Remove for Chart.js 4.0 - // dist/chart.esm.js - // helpers/*.js - { - input: { - 'dist/chart.esm': 'src/index.esm.js', - 'dist/helpers.esm': 'src/helpers/index.js' - }, plugins: [ json(), resolve(), @@ -100,9 +52,10 @@ module.exports = [ output: { dir: './', chunkFileNames: 'dist/chunks/[name].js', + entryFileNames: '[name].js', banner, format: 'esm', indent: false, }, - }, + } ]; diff --git a/src/core/core.adapters.js b/src/core/core.adapters.js index 19eedbc72..0859ea04d 100644 --- a/src/core/core.adapters.js +++ b/src/core/core.adapters.js @@ -5,7 +5,7 @@ */ /** - * @typedef { import("../../types/index.esm").ChartOptions } ChartOptions + * @typedef { import("../../types").ChartOptions } ChartOptions */ /** diff --git a/src/core/core.controller.js b/src/core/core.controller.js index 359240de1..a6953ccb5 100644 --- a/src/core/core.controller.js +++ b/src/core/core.controller.js @@ -14,8 +14,8 @@ import {version} from '../../package.json'; import {debounce} from '../helpers/helpers.extras'; /** - * @typedef { import('../../types/index.esm').ChartEvent } ChartEvent - * @typedef { import("../../types/index.esm").Point } Point + * @typedef { import('../../types').ChartEvent } ChartEvent + * @typedef { import("../../types").Point } Point */ const KNOWN_POSITIONS = ['top', 'bottom', 'left', 'right', 'chartArea']; @@ -1240,10 +1240,10 @@ class Chart { /** * @param {ChartEvent} e - The event - * @param {import('../../types/index.esm').ActiveElement[]} lastActive - Previously active elements + * @param {import('../../types').ActiveElement[]} lastActive - Previously active elements * @param {boolean} inChartArea - Is the envent inside chartArea * @param {boolean} useFinalPosition - Should the evaluation be done with current or final (after animation) element positions - * @returns {import('../../types/index.esm').ActiveElement[]} - The active elements + * @returns {import('../../types').ActiveElement[]} - The active elements * @pravate */ _getActiveElements(e, lastActive, inChartArea, useFinalPosition) { diff --git a/src/core/core.interaction.js b/src/core/core.interaction.js index 5424c862a..776db3288 100644 --- a/src/core/core.interaction.js +++ b/src/core/core.interaction.js @@ -5,10 +5,10 @@ import {_isPointInArea} from '../helpers'; /** * @typedef { import("./core.controller").default } Chart - * @typedef { import("../../types/index.esm").ChartEvent } ChartEvent + * @typedef { import("../../types").ChartEvent } ChartEvent * @typedef {{axis?: string, intersect?: boolean, includeInvisible?: boolean}} InteractionOptions * @typedef {{datasetIndex: number, index: number, element: import("./core.element").default}} InteractionItem - * @typedef { import("../../types/index.esm").Point } Point + * @typedef { import("../../types").Point } Point */ /** diff --git a/src/core/core.plugins.js b/src/core/core.plugins.js index c1693ca12..77aa6fb00 100644 --- a/src/core/core.plugins.js +++ b/src/core/core.plugins.js @@ -3,7 +3,7 @@ import {callback as callCallback, isNullOrUndef, valueOrDefault} from '../helper /** * @typedef { import("./core.controller").default } Chart - * @typedef { import("../../types/index.esm").ChartEvent } ChartEvent + * @typedef { import("../../types").ChartEvent } ChartEvent * @typedef { import("../plugins/plugin.tooltip").default } Tooltip */ diff --git a/src/helpers/helpers.canvas.js b/src/helpers/helpers.canvas.js index 98e6705be..d79f6fb11 100644 --- a/src/helpers/helpers.canvas.js +++ b/src/helpers/helpers.canvas.js @@ -6,7 +6,7 @@ import {PI, TAU, HALF_PI, QUARTER_PI, TWO_THIRDS_PI, RAD_PER_DEG} from './helper * necessary to avoid duplicates with `export * from './helpers`; see * https://github.com/microsoft/TypeScript/issues/46011 * @typedef { import("../core/core.controller").default } canvas.Chart - * @typedef { import("../../types/index.esm").Point } Point + * @typedef { import("../../types").Point } Point */ /** diff --git a/src/helpers/helpers.core.js b/src/helpers/helpers.core.js index ce15bc631..1b1d1ff78 100644 --- a/src/helpers/helpers.core.js +++ b/src/helpers/helpers.core.js @@ -369,7 +369,7 @@ export const setsEqual = (a, b) => { }; /** - * @param {import('../../types/index.esm').ChartEvent} e - The event + * @param {import('../../types').ChartEvent} e - The event * @returns {boolean} * @private */ diff --git a/src/helpers/helpers.dom.js b/src/helpers/helpers.dom.js index c4f54e009..60ffb77d1 100644 --- a/src/helpers/helpers.dom.js +++ b/src/helpers/helpers.dom.js @@ -5,7 +5,7 @@ import {INFINITY} from './helpers.math'; * necessary to avoid duplicates with `export * from './helpers`; see * https://github.com/microsoft/TypeScript/issues/46011 * @typedef { import("../core/core.controller").default } dom.Chart - * @typedef { import('../../types/index.esm').ChartEvent } ChartEvent + * @typedef { import('../../types').ChartEvent } ChartEvent */ /** diff --git a/src/index.esm.js b/src/index.esm.js deleted file mode 100644 index 15865c360..000000000 --- a/src/index.esm.js +++ /dev/null @@ -1,25 +0,0 @@ -export * from './controllers'; -export * from './core'; -export * from './elements'; -export * from './platform'; -export * from './plugins'; -export * from './scales'; - -import * as controllers from './controllers'; -import * as elements from './elements'; -import * as plugins from './plugins'; -import * as scales from './scales'; - -export { - controllers, - elements, - plugins, - scales, -}; - -export const registerables = [ - controllers, - elements, - plugins, - scales, -]; diff --git a/src/index.js b/src/index.js index d3539015b..15865c360 100644 --- a/src/index.js +++ b/src/index.js @@ -1,52 +1,25 @@ -// @ts-nocheck +export * from './controllers'; +export * from './core'; +export * from './elements'; +export * from './platform'; +export * from './plugins'; +export * from './scales'; -/** - * @namespace Chart - */ -import Chart from './core/core.controller'; - -import * as helpers from './helpers/index'; -import _adapters from './core/core.adapters'; -import Animation from './core/core.animation'; -import animator from './core/core.animator'; -import Animations from './core/core.animations'; import * as controllers from './controllers'; -import DatasetController from './core/core.datasetController'; -import Element from './core/core.element'; -import * as elements from './elements/index'; -import Interaction from './core/core.interaction'; -import layouts from './core/core.layouts'; -import * as platforms from './platform/index'; +import * as elements from './elements'; import * as plugins from './plugins'; -import registry from './core/core.registry'; -import Scale from './core/core.scale'; import * as scales from './scales'; -import Ticks from './core/core.ticks'; -// Register built-ins -Chart.register(controllers, scales, elements, plugins); +export { + controllers, + elements, + plugins, + scales, +}; -Chart.helpers = {...helpers}; -Chart._adapters = _adapters; -Chart.Animation = Animation; -Chart.Animations = Animations; -Chart.animator = animator; -Chart.controllers = registry.controllers.items; -Chart.DatasetController = DatasetController; -Chart.Element = Element; -Chart.elements = elements; -Chart.Interaction = Interaction; -Chart.layouts = layouts; -Chart.platforms = platforms; -Chart.Scale = Scale; -Chart.Ticks = Ticks; - -// Compatibility with ESM extensions -Object.assign(Chart, controllers, scales, elements, plugins, platforms); -Chart.Chart = Chart; - -if (typeof window !== 'undefined') { - window.Chart = Chart; -} - -export default Chart; +export const registerables = [ + controllers, + elements, + plugins, + scales, +]; diff --git a/src/index.umd.js b/src/index.umd.js new file mode 100644 index 000000000..d3539015b --- /dev/null +++ b/src/index.umd.js @@ -0,0 +1,52 @@ +// @ts-nocheck + +/** + * @namespace Chart + */ +import Chart from './core/core.controller'; + +import * as helpers from './helpers/index'; +import _adapters from './core/core.adapters'; +import Animation from './core/core.animation'; +import animator from './core/core.animator'; +import Animations from './core/core.animations'; +import * as controllers from './controllers'; +import DatasetController from './core/core.datasetController'; +import Element from './core/core.element'; +import * as elements from './elements/index'; +import Interaction from './core/core.interaction'; +import layouts from './core/core.layouts'; +import * as platforms from './platform/index'; +import * as plugins from './plugins'; +import registry from './core/core.registry'; +import Scale from './core/core.scale'; +import * as scales from './scales'; +import Ticks from './core/core.ticks'; + +// Register built-ins +Chart.register(controllers, scales, elements, plugins); + +Chart.helpers = {...helpers}; +Chart._adapters = _adapters; +Chart.Animation = Animation; +Chart.Animations = Animations; +Chart.animator = animator; +Chart.controllers = registry.controllers.items; +Chart.DatasetController = DatasetController; +Chart.Element = Element; +Chart.elements = elements; +Chart.Interaction = Interaction; +Chart.layouts = layouts; +Chart.platforms = platforms; +Chart.Scale = Scale; +Chart.Ticks = Ticks; + +// Compatibility with ESM extensions +Object.assign(Chart, controllers, scales, elements, plugins, platforms); +Chart.Chart = Chart; + +if (typeof window !== 'undefined') { + window.Chart = Chart; +} + +export default Chart; diff --git a/src/plugins/plugin.filler/filler.options.js b/src/plugins/plugin.filler/filler.options.js index bc22cec88..70b740d77 100644 --- a/src/plugins/plugin.filler/filler.options.js +++ b/src/plugins/plugin.filler/filler.options.js @@ -3,8 +3,8 @@ import {isObject, isFinite, valueOrDefault} from '../../helpers/helpers.core'; /** * @typedef { import('../../core/core.scale').default } Scale * @typedef { import('../../elements/element.line').default } LineElement - * @typedef { import('../../../types/index.esm').FillTarget } FillTarget - * @typedef { import('../../../types/index.esm').ComplexFillTarget } ComplexFillTarget + * @typedef { import('../../../types').FillTarget } FillTarget + * @typedef { import('../../../types').ComplexFillTarget } ComplexFillTarget */ export function _resolveTarget(sources, index, propagate) { diff --git a/src/plugins/plugin.legend.js b/src/plugins/plugin.legend.js index 936111d84..c4d7564a5 100644 --- a/src/plugins/plugin.legend.js +++ b/src/plugins/plugin.legend.js @@ -10,7 +10,7 @@ import { import {_toLeftRightCenter, _alignStartEnd, _textX} from '../helpers/helpers.extras'; import {toTRBLCorners} from '../helpers/helpers.options'; /** - * @typedef { import("../../types/index.esm").ChartEvent } ChartEvent + * @typedef { import("../../types").ChartEvent } ChartEvent */ const getBoxSize = (labelOpts, fontSize) => { diff --git a/src/plugins/plugin.tooltip.js b/src/plugins/plugin.tooltip.js index bc1689848..77d40be55 100644 --- a/src/plugins/plugin.tooltip.js +++ b/src/plugins/plugin.tooltip.js @@ -9,8 +9,8 @@ import {createContext, drawPoint} from '../helpers'; /** * @typedef { import("../platform/platform.base").Chart } Chart - * @typedef { import("../../types/index.esm").ChartEvent } ChartEvent - * @typedef { import("../../types/index.esm").ActiveElement } ActiveElement + * @typedef { import("../../types").ChartEvent } ChartEvent + * @typedef { import("../../types").ActiveElement } ActiveElement */ const positioners = { diff --git a/test/BasicChartWebWorker.js b/test/BasicChartWebWorker.js index ca267713e..900084ffe 100644 --- a/test/BasicChartWebWorker.js +++ b/test/BasicChartWebWorker.js @@ -6,7 +6,7 @@ // Sends messages with data of types: { type: 'success' } | { type: 'error', errorMessage: string } // eslint-disable-next-line no-undef -importScripts('../src/chart.js'); +importScripts('../src/chart.umd.js'); onmessage = function(event) { try { diff --git a/test/integration/integration-test.js b/test/integration/integration-test.cjs similarity index 100% rename from test/integration/integration-test.js rename to test/integration/integration-test.cjs diff --git a/test/integration/node/package.json b/test/integration/node/package.json index 6754a4f3b..5be41d8d7 100644 --- a/test/integration/node/package.json +++ b/test/integration/node/package.json @@ -1,11 +1,11 @@ { "private": true, "description": "chart.js should work in Node", + "type": "module", "scripts": { - "test": "npm run test-cjs", - "test-cjs": "node test.cjs", - "test-mjs": "node test.mjs", - "TODO": "test-mjs should be enambled for chart.js v4" + "test": "npm run test-mjs && npm run test-cjs", + "test-mjs": "node test.js", + "test-cjs": "node test.cjs" }, "dependencies": { "chart.js": "file:../package.tgz" diff --git a/test/integration/node/test.cjs b/test/integration/node/test.cjs index 2c5219c70..94f86f221 100644 --- a/test/integration/node/test.cjs +++ b/test/integration/node/test.cjs @@ -1,7 +1,10 @@ -const Chart = require('chart.js'); -const valueOrDefault = Chart.helpers.valueOrDefault; - -Chart.register({ - id: 'TEST_PLUGIN', - dummyValue: valueOrDefault(0, 1) +/* 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) + }); }); diff --git a/test/integration/node/test.mjs b/test/integration/node/test.js similarity index 100% rename from test/integration/node/test.mjs rename to test/integration/node/test.js diff --git a/test/seed-reporter.js b/test/seed-reporter.cjs similarity index 100% rename from test/seed-reporter.js rename to test/seed-reporter.cjs diff --git a/tsconfig.json b/tsconfig.json index bff8bcec7..9a2e9d66b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,7 @@ }, "typedocOptions": { "name": "Chart.js", - "entryPoints": ["types/index.esm.d.ts"], + "entryPoints": ["types/index.d.ts"], "readme": "none", "excludeExternals": true, "includeVersion": true, diff --git a/types/adapters.d.ts b/types/adapters.d.ts index cae40966b..7e3e63c8e 100644 --- a/types/adapters.d.ts +++ b/types/adapters.d.ts @@ -1,4 +1,4 @@ -import type { ChartOptions } from './index.esm'; +import type { ChartOptions } from '.'; export type TimeUnit = 'millisecond' | 'second' | 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'; diff --git a/types/animation.d.ts b/types/animation.d.ts index b83204124..0aece8eae 100644 --- a/types/animation.d.ts +++ b/types/animation.d.ts @@ -1,4 +1,4 @@ -import { Chart } from './index.esm'; +import { Chart } from '.'; import { AnyObject } from './basic'; export class Animation { diff --git a/types/helpers/helpers.canvas.d.ts b/types/helpers/helpers.canvas.d.ts index e6961af93..4adb7ee63 100644 --- a/types/helpers/helpers.canvas.d.ts +++ b/types/helpers/helpers.canvas.d.ts @@ -1,4 +1,4 @@ -import { PointStyle } from '../index.esm'; +import { PointStyle } from '..'; import { Color } from '../color'; import { ChartArea, RoundedRect } from '../geometric'; import { CanvasFontSpec } from './helpers.options'; diff --git a/types/helpers/helpers.dom.d.ts b/types/helpers/helpers.dom.d.ts index 738643140..a595b6b5b 100644 --- a/types/helpers/helpers.dom.d.ts +++ b/types/helpers/helpers.dom.d.ts @@ -1,4 +1,4 @@ -import { ChartEvent } from '../index.esm'; +import { ChartEvent } from '..'; export function getMaximumSize(node: HTMLElement, width?: number, height?: number, aspectRatio?: number): { width: number, height: number }; export function getRelativePosition( diff --git a/types/helpers/helpers.easing.d.ts b/types/helpers/helpers.easing.d.ts index b86d6532a..682a5d05a 100644 --- a/types/helpers/helpers.easing.d.ts +++ b/types/helpers/helpers.easing.d.ts @@ -1,4 +1,4 @@ -import { EasingFunction } from '../index.esm'; +import { EasingFunction } from '..'; export type EasingFunctionSignature = (t: number) => number; diff --git a/types/helpers/helpers.options.d.ts b/types/helpers/helpers.options.d.ts index 0bd783fa9..b622e71e8 100644 --- a/types/helpers/helpers.options.d.ts +++ b/types/helpers/helpers.options.d.ts @@ -1,5 +1,5 @@ import { TRBL, TRBLCorners } from '../geometric'; -import { FontSpec } from '../index.esm'; +import { FontSpec } from '..'; export interface CanvasFontSpec extends FontSpec { string: string; diff --git a/types/index.esm.d.ts b/types/index.d.ts similarity index 100% rename from types/index.esm.d.ts rename to types/index.d.ts diff --git a/types/tests/animation.ts b/types/tests/animation.ts index bc9ff433e..6e38e68ea 100644 --- a/types/tests/animation.ts +++ b/types/tests/animation.ts @@ -1,4 +1,4 @@ -import { Chart } from '../index.esm'; +import { Chart } from '..'; const chart = new Chart('id', { type: 'bar', diff --git a/types/tests/autogen.js b/types/tests/autogen.js index 6b3770444..584a33636 100644 --- a/types/tests/autogen.js +++ b/types/tests/autogen.js @@ -1,6 +1,9 @@ import * as fs from 'fs'; import * as path from 'path'; -import * as helpers from '../../src/helpers/index.js'; +import { fileURLToPath } from 'url'; +import * as helpers from '../../dist/helpers.js'; + +const __dirname = fileURLToPath(new URL('.', import.meta.url)); let fd; diff --git a/types/tests/chart_types.ts b/types/tests/chart_types.ts index f05bda4da..32831901e 100644 --- a/types/tests/chart_types.ts +++ b/types/tests/chart_types.ts @@ -1,4 +1,4 @@ -import { Chart } from '../index.esm'; +import { Chart } from '..'; const chart = new Chart('chart', { type: 'bar', diff --git a/types/tests/controllers/bubble_chart_options.ts b/types/tests/controllers/bubble_chart_options.ts index e036037e6..5924dd5f9 100644 --- a/types/tests/controllers/bubble_chart_options.ts +++ b/types/tests/controllers/bubble_chart_options.ts @@ -1,4 +1,4 @@ -import { Chart, ChartOptions } from '../../index.esm'; +import { Chart, ChartOptions } from '../..'; const chart = new Chart('test', { type: 'bubble', diff --git a/types/tests/controllers/doughnut_meta_total.ts b/types/tests/controllers/doughnut_meta_total.ts index da94fa0d8..76eb6eb6f 100644 --- a/types/tests/controllers/doughnut_meta_total.ts +++ b/types/tests/controllers/doughnut_meta_total.ts @@ -1,4 +1,4 @@ -import { Chart, ChartMeta, Element } from '../../index.esm'; +import { Chart, ChartMeta, Element } from '../..'; const chart = new Chart('id', { type: 'doughnut', diff --git a/types/tests/controllers/doughnut_offset.ts b/types/tests/controllers/doughnut_offset.ts index 58f7546bd..cf2d06943 100644 --- a/types/tests/controllers/doughnut_offset.ts +++ b/types/tests/controllers/doughnut_offset.ts @@ -1,4 +1,4 @@ -import { Chart, ChartMeta, Element } from '../../index.esm'; +import { Chart, ChartMeta, Element } from '../..'; const chart = new Chart('id', { type: 'doughnut', diff --git a/types/tests/controllers/doughnut_outer_radius.ts b/types/tests/controllers/doughnut_outer_radius.ts index e1074f39c..e72d309c2 100644 --- a/types/tests/controllers/doughnut_outer_radius.ts +++ b/types/tests/controllers/doughnut_outer_radius.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../index.esm'; +import { Chart } from '../..'; const chart = new Chart('id', { type: 'doughnut', diff --git a/types/tests/controllers/line_scriptable_parsed_data.ts b/types/tests/controllers/line_scriptable_parsed_data.ts index da88d0ec2..7a726da37 100644 --- a/types/tests/controllers/line_scriptable_parsed_data.ts +++ b/types/tests/controllers/line_scriptable_parsed_data.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../index.esm'; +import { Chart } from '../..'; const chart = new Chart('id', { type: 'line', diff --git a/types/tests/controllers/line_segments.ts b/types/tests/controllers/line_segments.ts index 9e99e3d21..5d07063a9 100644 --- a/types/tests/controllers/line_segments.ts +++ b/types/tests/controllers/line_segments.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../index.esm'; +import { Chart } from '../..'; const chart = new Chart('id', { type: 'line', diff --git a/types/tests/controllers/line_span_gaps.ts b/types/tests/controllers/line_span_gaps.ts index 040c9a99c..0025641bd 100644 --- a/types/tests/controllers/line_span_gaps.ts +++ b/types/tests/controllers/line_span_gaps.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../index.esm'; +import { Chart } from '../..'; const chart = new Chart('id', { type: 'line', diff --git a/types/tests/controllers/line_styling_array.ts b/types/tests/controllers/line_styling_array.ts index 3b6c6733c..daf2b7be7 100644 --- a/types/tests/controllers/line_styling_array.ts +++ b/types/tests/controllers/line_styling_array.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../index.esm'; +import { Chart } from '../..'; const chart = new Chart('id', { type: 'line', diff --git a/types/tests/controllers/radar_dataset_indexable_options.ts b/types/tests/controllers/radar_dataset_indexable_options.ts index 0c66f23f6..7ef753619 100644 --- a/types/tests/controllers/radar_dataset_indexable_options.ts +++ b/types/tests/controllers/radar_dataset_indexable_options.ts @@ -1,4 +1,4 @@ -import { Chart, ChartOptions } from '../../index.esm'; +import { Chart, ChartOptions } from '../..'; const chart = new Chart('test', { type: 'radar', diff --git a/types/tests/data_types.ts b/types/tests/data_types.ts index 1740d8e66..0e6a2d87f 100644 --- a/types/tests/data_types.ts +++ b/types/tests/data_types.ts @@ -1,4 +1,4 @@ -import { Chart } from '../index.esm'; +import { Chart } from '..'; const chart = new Chart('chart', { type: 'bar', diff --git a/types/tests/dataset_null_data.ts b/types/tests/dataset_null_data.ts index ae13c6a21..bb86a0aae 100644 --- a/types/tests/dataset_null_data.ts +++ b/types/tests/dataset_null_data.ts @@ -1,4 +1,4 @@ -import { ChartDataset } from '../index.esm'; +import { ChartDataset } from '..'; const dataset: ChartDataset = { data: [10, null, 20], diff --git a/types/tests/defaults.ts b/types/tests/defaults.ts index a3e8e96f5..c4c591000 100644 --- a/types/tests/defaults.ts +++ b/types/tests/defaults.ts @@ -1,4 +1,4 @@ -import { Chart } from '../index.esm'; +import { Chart } from '..'; Chart.defaults.scales.time.time.minUnit = 'day'; diff --git a/types/tests/elements/scriptable_element_options.ts b/types/tests/elements/scriptable_element_options.ts index c81892d79..791684c64 100644 --- a/types/tests/elements/scriptable_element_options.ts +++ b/types/tests/elements/scriptable_element_options.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../index.esm'; +import { Chart } from '../..'; const chart = new Chart('id', { type: 'line', diff --git a/types/tests/extensions/plugin.ts b/types/tests/extensions/plugin.ts index fcb0bd0e9..b0a89c5b0 100644 --- a/types/tests/extensions/plugin.ts +++ b/types/tests/extensions/plugin.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../index.esm'; +import { Chart } from '../..'; Chart.register({ id: 'my-plugin', diff --git a/types/tests/extensions/scale.ts b/types/tests/extensions/scale.ts index fdf1c89e4..0b6a10dcc 100644 --- a/types/tests/extensions/scale.ts +++ b/types/tests/extensions/scale.ts @@ -1,5 +1,5 @@ import { AnyObject } from '../../basic'; -import { CartesianScaleOptions, Chart, Scale } from '../../index.esm'; +import { CartesianScaleOptions, Chart, Scale } from '../..'; export type TestScaleOptions = CartesianScaleOptions & { testOption?: boolean @@ -17,7 +17,7 @@ export class TestScale extends Sc } } -declare module '../../index.esm' { +declare module '../..' { interface CartesianScaleTypeRegistry { test: { options: TestScaleOptions diff --git a/types/tests/interaction.ts b/types/tests/interaction.ts index e5df1da19..3450bbfe0 100644 --- a/types/tests/interaction.ts +++ b/types/tests/interaction.ts @@ -1,6 +1,6 @@ import { Chart, ChartData, ChartConfiguration, Element -} from '../index.esm'; +} from '..'; const data: ChartData<'line'> = { datasets: [] }; const chartItem = 'item'; diff --git a/types/tests/layout/position.ts b/types/tests/layout/position.ts index 87f249e27..544ed4f3e 100644 --- a/types/tests/layout/position.ts +++ b/types/tests/layout/position.ts @@ -1,4 +1,4 @@ -import { LayoutPosition } from '../../index.esm'; +import { LayoutPosition } from '../..'; const left: LayoutPosition = 'left'; const right: LayoutPosition = 'right'; diff --git a/types/tests/options.ts b/types/tests/options.ts index 0aab0f0f7..2ec8b895c 100644 --- a/types/tests/options.ts +++ b/types/tests/options.ts @@ -1,4 +1,4 @@ -import { Chart } from '../index.esm'; +import { Chart } from '..'; const chart = new Chart('test', { type: 'bar', diff --git a/types/tests/overrides.ts b/types/tests/overrides.ts index 8c2e02d6c..1e184e561 100644 --- a/types/tests/overrides.ts +++ b/types/tests/overrides.ts @@ -1,4 +1,4 @@ -import { Chart } from '../index.esm'; +import { Chart } from '..'; Chart.overrides.bar.scales.x.type = 'time'; diff --git a/types/tests/parsed.data.type.ts b/types/tests/parsed.data.type.ts index c5476eaae..54b207a4b 100644 --- a/types/tests/parsed.data.type.ts +++ b/types/tests/parsed.data.type.ts @@ -1,4 +1,4 @@ -import { ParsedDataType } from '../index.esm'; +import { ParsedDataType } from '..'; interface test { pie: ParsedDataType<'pie'>, diff --git a/types/tests/plugins/defaults.ts b/types/tests/plugins/defaults.ts index ec54b34ff..9ca1edea6 100644 --- a/types/tests/plugins/defaults.ts +++ b/types/tests/plugins/defaults.ts @@ -1,4 +1,4 @@ -import { defaults } from '../../index.esm'; +import { defaults } from '../..'; // https://github.com/chartjs/Chart.js/issues/8711 const original = defaults.plugins.legend.labels.generateLabels; diff --git a/types/tests/plugins/plugin.decimation/decimation_algorithm.ts b/types/tests/plugins/plugin.decimation/decimation_algorithm.ts index 978764bde..a6659bac7 100644 --- a/types/tests/plugins/plugin.decimation/decimation_algorithm.ts +++ b/types/tests/plugins/plugin.decimation/decimation_algorithm.ts @@ -1,4 +1,4 @@ -import { Chart, DecimationAlgorithm } from '../../../index.esm'; +import { Chart, DecimationAlgorithm } from '../../..'; const chart = new Chart('id', { type: 'bubble', diff --git a/types/tests/plugins/plugin.filler/fill_target_true.ts b/types/tests/plugins/plugin.filler/fill_target_true.ts index d9dc21061..3768ddeda 100644 --- a/types/tests/plugins/plugin.filler/fill_target_true.ts +++ b/types/tests/plugins/plugin.filler/fill_target_true.ts @@ -1,4 +1,4 @@ -import { ChartDataset } from '../../../index.esm'; +import { ChartDataset } from '../../..'; const dataset: ChartDataset = { data: [], diff --git a/types/tests/plugins/plugin.tooltip/chart.tooltip.ts b/types/tests/plugins/plugin.tooltip/chart.tooltip.ts index 66c824412..56b37f295 100644 --- a/types/tests/plugins/plugin.tooltip/chart.tooltip.ts +++ b/types/tests/plugins/plugin.tooltip/chart.tooltip.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../../index.esm'; +import { Chart } from '../../..'; const chart = new Chart('id', { type: 'line', diff --git a/types/tests/plugins/plugin.tooltip/tooltip_dataset_type.ts b/types/tests/plugins/plugin.tooltip/tooltip_dataset_type.ts index 989a7cc45..343828d8d 100644 --- a/types/tests/plugins/plugin.tooltip/tooltip_dataset_type.ts +++ b/types/tests/plugins/plugin.tooltip/tooltip_dataset_type.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../../index.esm'; +import { Chart } from '../../..'; const chart = new Chart('id', { type: 'line', diff --git a/types/tests/plugins/plugin.tooltip/tooltip_parsed_data.ts b/types/tests/plugins/plugin.tooltip/tooltip_parsed_data.ts index 93b7a9004..d7fb45959 100644 --- a/types/tests/plugins/plugin.tooltip/tooltip_parsed_data.ts +++ b/types/tests/plugins/plugin.tooltip/tooltip_parsed_data.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../../index.esm'; +import { Chart } from '../../..'; const chart = new Chart('id', { type: 'bar', diff --git a/types/tests/plugins/plugin.tooltip/tooltip_parsed_data_chart_defaults.ts b/types/tests/plugins/plugin.tooltip/tooltip_parsed_data_chart_defaults.ts index 694943e60..d1488b681 100644 --- a/types/tests/plugins/plugin.tooltip/tooltip_parsed_data_chart_defaults.ts +++ b/types/tests/plugins/plugin.tooltip/tooltip_parsed_data_chart_defaults.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../../index.esm'; +import { Chart } from '../../..'; Chart.overrides.bubble.plugins.tooltip.callbacks.label = (item) => { const { x, y, _custom: r } = item.parsed; diff --git a/types/tests/plugins/plugin.tooltip/tooltip_scriptable_background_color.ts b/types/tests/plugins/plugin.tooltip/tooltip_scriptable_background_color.ts index a55d44547..36c54d7e0 100644 --- a/types/tests/plugins/plugin.tooltip/tooltip_scriptable_background_color.ts +++ b/types/tests/plugins/plugin.tooltip/tooltip_scriptable_background_color.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../../index.esm'; +import { Chart } from '../../..'; const chart = new Chart('id', { type: 'bar', diff --git a/types/tests/register.ts b/types/tests/register.ts index 7256ef8b3..49979d7a8 100644 --- a/types/tests/register.ts +++ b/types/tests/register.ts @@ -24,7 +24,7 @@ import { Title, SubTitle, Tooltip -} from '../index.esm'; +} from '..'; Chart.register( ArcElement, diff --git a/types/tests/scales/chart_options.ts b/types/tests/scales/chart_options.ts index a0b02d79a..c097601a9 100644 --- a/types/tests/scales/chart_options.ts +++ b/types/tests/scales/chart_options.ts @@ -1,4 +1,4 @@ -import { ChartOptions } from '../../index.esm'; +import { ChartOptions } from '../..'; const chartOptions: ChartOptions<'line'> = { scales: { diff --git a/types/tests/scales/options.ts b/types/tests/scales/options.ts index cc1dc9015..a521f0150 100644 --- a/types/tests/scales/options.ts +++ b/types/tests/scales/options.ts @@ -1,4 +1,4 @@ -import { Chart, ScaleOptions } from '../../index.esm'; +import { Chart, ScaleOptions } from '../..'; const chart = new Chart('test', { type: 'bar', diff --git a/types/tests/scales/time_string_max.ts b/types/tests/scales/time_string_max.ts index 530b1c548..9c1c38bf4 100644 --- a/types/tests/scales/time_string_max.ts +++ b/types/tests/scales/time_string_max.ts @@ -1,4 +1,4 @@ -import { Chart } from '../../index.esm'; +import { Chart } from '../..'; const chart = new Chart('id', { type: 'line', diff --git a/types/tests/scriptable.ts b/types/tests/scriptable.ts index db72edb21..bf9cec805 100644 --- a/types/tests/scriptable.ts +++ b/types/tests/scriptable.ts @@ -1,4 +1,4 @@ -import { ChartType, Scriptable, ScriptableContext } from '../index.esm'; +import { ChartType, Scriptable, ScriptableContext } from '..'; interface test { pie?: Scriptable>, diff --git a/types/tests/scriptable_core_chart_options.ts b/types/tests/scriptable_core_chart_options.ts index 2c81f592e..3e2115f65 100644 --- a/types/tests/scriptable_core_chart_options.ts +++ b/types/tests/scriptable_core_chart_options.ts @@ -1,4 +1,4 @@ -import { ChartConfiguration } from '../index.esm'; +import { ChartConfiguration } from '..'; const getConfig = (): ChartConfiguration<'bar'> => { return { diff --git a/types/tests/test_instance_assignment.ts b/types/tests/test_instance_assignment.ts index 044f53f7c..ea3951d2e 100644 --- a/types/tests/test_instance_assignment.ts +++ b/types/tests/test_instance_assignment.ts @@ -1,4 +1,4 @@ -import { Chart } from '../index.esm'; +import { Chart } from '..'; const chart = new Chart('id', { type: 'scatter', diff --git a/types/tests/tsconfig.json b/types/tests/tsconfig.json index 9bbed3c55..a8494a0a8 100644 --- a/types/tests/tsconfig.json +++ b/types/tests/tsconfig.json @@ -8,6 +8,6 @@ }, "include": [ "./**/*.ts", - "../index.esm.d.ts" + "../index.d.ts" ] }