Skip to content

Commit

Permalink
Distribute types as is (#8720)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
joshkel committed Mar 25, 2021
1 parent 9293dda commit 3671c01
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 74 deletions.
2 changes: 1 addition & 1 deletion MAINTAINING.md
Expand Up @@ -13,7 +13,7 @@ Chart.js relies on [Travis CI](https://travis-ci.org/) to automate the library [
Creation of this tag triggers a new build:

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

Finally, [cdnjs](https://cdnjs.com/libraries/Chart.js) is automatically updated from the npm release.
Expand Down
34 changes: 0 additions & 34 deletions package-lock.json

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

7 changes: 3 additions & 4 deletions package.json
Expand Up @@ -8,7 +8,7 @@
"unpkg": "dist/chart.min.js",
"main": "dist/chart.js",
"module": "dist/chart.esm.js",
"types": "dist/chart.esm.d.ts",
"types": "types/chart.esm.d.ts",
"keywords": [
"canvas",
"charts",
Expand All @@ -28,9 +28,9 @@
"auto/**/*.js",
"auto/**/*.d.ts",
"dist/*.js",
"dist/*.d.ts",
"dist/chunks/*.js",
"dist/chunks/*.d.ts",
"types/*.d.ts",
"types/helpers/*.d.ts",
"helpers/**/*.js",
"helpers/**/*.d.ts"
],
Expand Down Expand Up @@ -84,7 +84,6 @@
"rollup": "^2.41.4",
"rollup-plugin-analyzer": "^4.0.0",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-dts": "^3.0.1",
"rollup-plugin-istanbul": "^3.0.0",
"rollup-plugin-terser": "^7.0.2",
"typedoc": "^0.20.32",
Expand Down
21 changes: 0 additions & 21 deletions rollup.config.js
@@ -1,6 +1,5 @@
const analyze = require('rollup-plugin-analyzer');
const cleanup = require('rollup-plugin-cleanup');
const dts = require('rollup-plugin-dts').default;
const json = require('@rollup/plugin-json');
const resolve = require('@rollup/plugin-node-resolve').default;
const terser = require('rollup-plugin-terser').terser;
Expand All @@ -11,10 +10,6 @@ const inputESM = {
'dist/chart.esm': 'src/index.esm.js',
'dist/helpers.esm': 'src/helpers/index.js'
};
const inputESMTypings = {
'dist/chart.esm': 'types/index.esm.d.ts',
'dist/helpers.esm': 'types/helpers/index.d.ts'
};

const banner = `/*!
* Chart.js v${pkg.version}
Expand Down Expand Up @@ -84,20 +79,4 @@ module.exports = [
indent: false,
},
},
// ES6 Typings builds
// dist/chart.esm.d.ts
// helpers/*.d.ts
{
input: inputESMTypings,
plugins: [
dts()
],
output: {
dir: './',
chunkFileNames: 'dist/chunks/[name].ts',
banner,
format: 'esm',
indent: false,
},
}
];
14 changes: 0 additions & 14 deletions types/index.esm.d.ts
@@ -1,17 +1,3 @@
/**
* Top-level type definitions. These are processed by Rollup and rollup-plugin-dts
* to make a combined .d.ts file under dist; that way, all of the type definitions
* appear directly within the "chart.js" module; that matches the layout of the
* distributed chart.esm.js bundle and means that users of Chart.js can easily use
* module augmentation to extend Chart.js's types and plugins within their own
* code, like so:
*
* @example
* declare module "chart.js" {
* // Add types here
* }
*/

import { DeepPartial, DistributiveArray, UnionToIntersection } from './utils';

import { TimeUnit } from './adapters';
Expand Down

0 comments on commit 3671c01

Please sign in to comment.