Skip to content

Commit

Permalink
feat: typescript node next support (#10661)
Browse files Browse the repository at this point in the history
  • Loading branch information
dangreen authored Sep 14, 2022
1 parent cc65c2b commit 47cb9e1
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 12 deletions.
4 changes: 2 additions & 2 deletions auto/auto.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Chart} from '../dist/types';
import {Chart} from '../dist/types.js';

export * from '../dist/types';
export * from '../dist/types.js';
export default Chart;
2 changes: 1 addition & 1 deletion helpers/helpers.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from '../dist/helpers/types';
export * from '../dist/helpers.js';
26 changes: 18 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@
"unpkg": "./dist/chart.umd.js",
"main": "./dist/chart.js",
"exports": {
".": "./dist/chart.js",
"./auto": "./auto/auto.js",
"./helpers": "./helpers/helpers.js"
".": {
"import": "./dist/chart.js",
"types": "./dist/types.d.ts"
},
"./auto": {
"import": "./auto/auto.js",
"types": "./auto/auto.d.ts"
},
"./helpers": {
"import": "./helpers/helpers.js",
"types": "./helpers/helpers.d.ts"
}
},
"types": "./dist/types.d.ts",
"keywords": [
Expand All @@ -36,20 +45,18 @@
"files": [
"auto/**",
"dist/**",
"types/**",
"helpers/**"
],
"scripts": {
"autobuild": "rollup -c -w",
"emitDeclarations": "tsc --emitDeclarationOnly",
"build": "rollup -c && npm run emitDeclarations",
"build": "tsc --noEmit && rollup -c",
"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": "pnpm run build && pnpm --filter \"./docs/**\" build",
"docs:dev": "pnpm run build && pnpm --filter \"./docs/**\" dev",
"lint-js": "eslint \"src/**/*.{js,ts}\" \"test/**/*.js\" \"docs/**/*.js\"",
"lint-md": "eslint \"**/*.md\"",
"lint-types": "eslint \"types/**/*.ts\" && pnpm run build && node types/tests/autogen.js && tsc -p types/tests/",
"lint-types": "eslint \"types/**/*.ts\" && pnpm build && node types/tests/autogen.js && tsc -p types/tests/",
"lint": "concurrently \"pnpm:lint-*\"",
"test-size": "size-limit",
"test": "pnpm lint && pnpm test-ci",
Expand Down Expand Up @@ -100,6 +107,7 @@
"pixelmatch": "^5.3.0",
"rollup": "^2.77.2",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-dts": "^4.2.2",
"rollup-plugin-istanbul": "^3.0.0",
"rollup-plugin-swc3": "^0.3.0",
"rollup-plugin-terser": "^7.0.2",
Expand All @@ -116,7 +124,9 @@
"html-entities": "1.4.0"
},
"peerDependencyRules": {
"ignoreMissing": ["chart.js"]
"ignoreMissing": [
"chart.js"
]
}
}
}
49 changes: 49 additions & 0 deletions pnpm-lock.yaml

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

18 changes: 18 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import {swc} from 'rollup-plugin-swc3';
import {terser} from 'rollup-plugin-terser';
import dts from 'rollup-plugin-dts';
import {readFileSync} from 'fs';

const {version, homepage} = JSON.parse(readFileSync('./package.json'));
Expand Down Expand Up @@ -76,5 +77,22 @@ export default [
indent: false,
sourcemap: true,
},
},

// Types
// dist/types.d.ts
// dist/helpers.d.ts
{
input: {
'dist/types': 'src/types.ts',
'dist/helpers': 'src/helpers/types.ts'
},
plugins: [dts()],
output: {
dir: './',
chunkFileNames: 'dist/chunks/[name].d.ts',
entryFileNames: '[name].d.ts',
format: 'es'
}
}
];
15 changes: 15 additions & 0 deletions test/integration/typescript-node-next/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"private": true,
"type": "module",
"description": "chart.js should work in node next typescript project",
"dependencies": {
"chart.js": "workspace:*",
"typescript": "^4.7.4"
},
"scripts": {
"test": "tsc"
},
"devDependencies": {
"ts-expect": "^1.3.0"
}
}
9 changes: 9 additions & 0 deletions test/integration/typescript-node-next/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable @typescript-eslint/no-explicit-any, no-console */
import {Chart} from 'chart.js';
import AutoChart from 'chart.js/auto';
import {debounce} from 'chart.js/helpers';
import {TypeOf, expectType} from 'ts-expect';

expectType<TypeOf<typeof Chart.register, any>>(false);
expectType<TypeOf<typeof AutoChart.register, any>>(false);
expectType<TypeOf<typeof debounce, any>>(false);
10 changes: 10 additions & 0 deletions test/integration/typescript-node-next/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"moduleResolution": "NodeNext",
"noEmit": true,
"lib": ["es2018", "DOM"]
},
"include": [
"./src/**/*.ts",
]
}
15 changes: 15 additions & 0 deletions test/integration/typescript-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"private": true,
"type": "module",
"description": "chart.js should work in node typescript project",
"dependencies": {
"chart.js": "workspace:*",
"typescript": "^4.7.4"
},
"scripts": {
"test": "tsc"
},
"devDependencies": {
"ts-expect": "^1.3.0"
}
}
9 changes: 9 additions & 0 deletions test/integration/typescript-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* eslint-disable @typescript-eslint/no-explicit-any, no-console */
import {Chart} from 'chart.js';
import AutoChart from 'chart.js/auto';
import {debounce} from 'chart.js/helpers';
import {TypeOf, expectType} from 'ts-expect';

expectType<TypeOf<typeof Chart.register, any>>(false);
expectType<TypeOf<typeof AutoChart.register, any>>(false);
expectType<TypeOf<typeof debounce, any>>(false);
10 changes: 10 additions & 0 deletions test/integration/typescript-node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"moduleResolution": "Node",
"noEmit": true,
"lib": ["es2018", "DOM"]
},
"include": [
"./src/**/*.ts",
]
}
2 changes: 1 addition & 1 deletion types/tests/autogen.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let fd;
try {
const fn = path.resolve(__dirname, 'autogen_helpers.ts');
fd = fs.openSync(fn, 'w+');
fs.writeSync(fd, 'import * as helpers from \'../../src/helpers/types\';\n\n');
fs.writeSync(fd, 'import * as helpers from \'../../dist/helpers\';\n\n');

fs.writeSync(fd, 'const testKeys: unknown[] = [];\n');
for (const key of Object.keys(helpers)) {
Expand Down

0 comments on commit 47cb9e1

Please sign in to comment.