Skip to content

Commit 57c1c81

Browse files
committed
Second attempt at reworking TypeScript .d.ts handling
1 parent 02be20a commit 57c1c81

File tree

4 files changed

+10
-49
lines changed

4 files changed

+10
-49
lines changed

karma.conf.cjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ module.exports = async function(karma) {
1818
const regex = karma.autoWatch ? /chartjs-plugin-annotation\.cjs$/ : /chartjs-plugin-annotation\.min\.js$/;
1919
const build = builds.filter(v => v.output.file && v.output.file.match(regex))[0];
2020

21+
// Even if using the unminified build, use UMD format with default exports, so
22+
// we can access it as a global variable.
23+
build.output.format = 'umd';
24+
delete build.output.exports;
25+
2126
if (env === 'test') {
2227
build.plugins = [
2328
json(),

package-lock.json

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

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"type": "module",
99
"main": "dist/chartjs-plugin-annotation.cjs",
1010
"module": "dist/chartjs-plugin-annotation.esm.js",
11-
"types": "dist/chartjs-plugin-annotation.d.cts",
11+
"types": "dist/chartjs-plugin-annotation.d.ts",
1212
"jsdelivr": "dist/chartjs-plugin-annotation.min.js",
1313
"unpkg": "dist/chartjs-plugin-annotation.min.js",
1414
"exports": {
@@ -54,7 +54,6 @@
5454
"devDependencies": {
5555
"@rollup/plugin-json": "^6.0.0",
5656
"@rollup/plugin-node-resolve": "^15.0.1",
57-
"@rollup/plugin-replace": "^6.0.2",
5857
"@rollup/plugin-terser": "^0.4.0",
5958
"@simonbrunel/vuepress-plugin-versions": "^0.2.0",
6059
"@typescript-eslint/eslint-plugin": "^5.51.0",

rollup.config.js

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import resolve from '@rollup/plugin-node-resolve';
2-
import replace from '@rollup/plugin-replace';
32
import terser from '@rollup/plugin-terser';
43
import json from '@rollup/plugin-json';
54
import {readFileSync} from 'fs';
@@ -39,7 +38,8 @@ export default [
3938
banner,
4039
format: 'umd',
4140
indent: false,
42-
globals
41+
globals,
42+
exports: 'named'
4343
},
4444
external
4545
},
@@ -84,22 +84,12 @@ export default [
8484
{
8585
input: './types/index.d.ts',
8686
output: [{file: exp.import.types, format: 'es'}],
87-
plugins: [dts()],
87+
plugins: [dts()]
8888
},
8989
// .d.cts
9090
{
9191
input: './types/index.d.ts',
9292
output: [{file: exp.require.types, format: 'cjs'}],
93-
plugins: [
94-
replace({
95-
preventAssignment: true,
96-
values: {
97-
'// declare namespace Annotation {': 'declare namespace Annotation {',
98-
'// } // declare namespace Annotation': '} // declare namespace Annotation',
99-
'export default Annotation': 'export = Annotation',
100-
}
101-
}),
102-
dts(),
103-
],
93+
plugins: [dts()]
10494
},
10595
];

0 commit comments

Comments
 (0)