Skip to content

Commit 3671c01

Browse files
authored
Distribute types as is (#8720)
I had initially seen some oddities around type augmentation for type definitions in subdirectories of `types`, and using Rollup seemed to help with that. However, now that all of Chart.js's main types are directly under `types`, there seems to be no need for this. This simplifies the build process, since it no longer needs to use rollup-plugin-dts. It also improves some third-party tools. For example, I'm in the habit of using WebStorm's "Go To Declaration or Usages" hotkey with third-party TypeScript definitions as a quick way of getting more information about an API. With the Rollup-generate types, that works poorly; WebStorm goes to the imported-and-re-exported symbol within the barely-readable machine-generated dist/chart.esm.d.ts file, and I have to navigate two more hops to find the actual definitions.
1 parent 9293dda commit 3671c01

File tree

5 files changed

+4
-74
lines changed

5 files changed

+4
-74
lines changed

MAINTAINING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Chart.js relies on [Travis CI](https://travis-ci.org/) to automate the library [
1313
Creation of this tag triggers a new build:
1414

1515
* `Chart.js.zip` package is generated, containing dist files and examples
16-
* `dist/*.js` and `Chart.js.zip` are attached to the GitHub release (downloads)
16+
* `dist/*.js`, `types/*.ts`, and `Chart.js.zip` are attached to the GitHub release (downloads)
1717
* A new npm package is published on [npmjs](https://www.npmjs.com/package/chart.js)
1818

1919
Finally, [cdnjs](https://cdnjs.com/libraries/Chart.js) is automatically updated from the npm release.

package-lock.json

Lines changed: 0 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"unpkg": "dist/chart.min.js",
99
"main": "dist/chart.js",
1010
"module": "dist/chart.esm.js",
11-
"types": "dist/chart.esm.d.ts",
11+
"types": "types/chart.esm.d.ts",
1212
"keywords": [
1313
"canvas",
1414
"charts",
@@ -28,9 +28,9 @@
2828
"auto/**/*.js",
2929
"auto/**/*.d.ts",
3030
"dist/*.js",
31-
"dist/*.d.ts",
3231
"dist/chunks/*.js",
33-
"dist/chunks/*.d.ts",
32+
"types/*.d.ts",
33+
"types/helpers/*.d.ts",
3434
"helpers/**/*.js",
3535
"helpers/**/*.d.ts"
3636
],
@@ -84,7 +84,6 @@
8484
"rollup": "^2.41.4",
8585
"rollup-plugin-analyzer": "^4.0.0",
8686
"rollup-plugin-cleanup": "^3.2.1",
87-
"rollup-plugin-dts": "^3.0.1",
8887
"rollup-plugin-istanbul": "^3.0.0",
8988
"rollup-plugin-terser": "^7.0.2",
9089
"typedoc": "^0.20.32",

rollup.config.js

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const analyze = require('rollup-plugin-analyzer');
22
const cleanup = require('rollup-plugin-cleanup');
3-
const dts = require('rollup-plugin-dts').default;
43
const json = require('@rollup/plugin-json');
54
const resolve = require('@rollup/plugin-node-resolve').default;
65
const terser = require('rollup-plugin-terser').terser;
@@ -11,10 +10,6 @@ const inputESM = {
1110
'dist/chart.esm': 'src/index.esm.js',
1211
'dist/helpers.esm': 'src/helpers/index.js'
1312
};
14-
const inputESMTypings = {
15-
'dist/chart.esm': 'types/index.esm.d.ts',
16-
'dist/helpers.esm': 'types/helpers/index.d.ts'
17-
};
1813

1914
const banner = `/*!
2015
* Chart.js v${pkg.version}
@@ -84,20 +79,4 @@ module.exports = [
8479
indent: false,
8580
},
8681
},
87-
// ES6 Typings builds
88-
// dist/chart.esm.d.ts
89-
// helpers/*.d.ts
90-
{
91-
input: inputESMTypings,
92-
plugins: [
93-
dts()
94-
],
95-
output: {
96-
dir: './',
97-
chunkFileNames: 'dist/chunks/[name].ts',
98-
banner,
99-
format: 'esm',
100-
indent: false,
101-
},
102-
}
10382
];

types/index.esm.d.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
1-
/**
2-
* Top-level type definitions. These are processed by Rollup and rollup-plugin-dts
3-
* to make a combined .d.ts file under dist; that way, all of the type definitions
4-
* appear directly within the "chart.js" module; that matches the layout of the
5-
* distributed chart.esm.js bundle and means that users of Chart.js can easily use
6-
* module augmentation to extend Chart.js's types and plugins within their own
7-
* code, like so:
8-
*
9-
* @example
10-
* declare module "chart.js" {
11-
* // Add types here
12-
* }
13-
*/
14-
151
import { DeepPartial, DistributiveArray, UnionToIntersection } from './utils';
162

173
import { TimeUnit } from './adapters';

0 commit comments

Comments
 (0)