From: Dan Onoshko Date: Wed, 14 Sep 2022 10:44:57 +0000 (+0700) Subject: feat: typescript node next support (#10661) X-Git-Tag: v4.0.0~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=47cb9e1f76c76a0563bd9aec6aa787c713f690fa;p=thirdparty%2FChart.js.git feat: typescript node next support (#10661) --- diff --git a/auto/auto.d.ts b/auto/auto.d.ts index 487acb610..fb1263ae5 100644 --- a/auto/auto.d.ts +++ b/auto/auto.d.ts @@ -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; diff --git a/helpers/helpers.d.ts b/helpers/helpers.d.ts index 587d0fd55..451fa58f7 100644 --- a/helpers/helpers.d.ts +++ b/helpers/helpers.d.ts @@ -1 +1 @@ -export * from '../dist/helpers/types'; +export * from '../dist/helpers.js'; diff --git a/package.json b/package.json index e3ae7fd11..0f4414b8d 100644 --- a/package.json +++ b/package.json @@ -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": [ @@ -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", @@ -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", @@ -116,7 +124,9 @@ "html-entities": "1.4.0" }, "peerDependencyRules": { - "ignoreMissing": ["chart.js"] + "ignoreMissing": [ + "chart.js" + ] } } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0748a7835..60fa8c7db 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -49,6 +49,7 @@ importers: 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 @@ -98,6 +99,7 @@ importers: pixelmatch: 5.3.0 rollup: 2.77.2 rollup-plugin-cleanup: 3.2.1_rollup@2.77.2 + rollup-plugin-dts: 4.2.2_oo3i3f3qmqiztdz5qgxrrjmd5e rollup-plugin-istanbul: 3.0.0_rollup@2.77.2 rollup-plugin-swc3: 0.3.0_niznp7c4dpiumotw6saahmrjuy rollup-plugin-terser: 7.0.2_rollup@2.77.2 @@ -179,6 +181,28 @@ importers: typescript: 4.7.4 web-vitals: 2.1.4 + test/integration/typescript-node: + specifiers: + chart.js: workspace:* + ts-expect: ^1.3.0 + typescript: ^4.7.4 + dependencies: + chart.js: link:../../.. + typescript: 4.7.4 + devDependencies: + ts-expect: 1.3.0 + + test/integration/typescript-node-next: + specifiers: + chart.js: workspace:* + ts-expect: ^1.3.0 + typescript: ^4.7.4 + dependencies: + chart.js: link:../../.. + typescript: 4.7.4 + devDependencies: + ts-expect: 1.3.0 + packages: /@ampproject/remapping/2.2.0: @@ -10646,6 +10670,13 @@ packages: dependencies: sourcemap-codec: 1.4.8 + /magic-string/0.26.3: + resolution: {integrity: sha512-u1Po0NDyFcwdg2nzHT88wSK0+Rih0N1M+Ph1Sp08k8yvFFU3KR72wryS7e1qMPJypt99WB7fIFVCA92mQrMjrg==} + engines: {node: '>=12'} + dependencies: + sourcemap-codec: 1.4.8 + dev: true + /make-dir/2.1.0: resolution: {integrity: sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==} engines: {node: '>=6'} @@ -13803,6 +13834,20 @@ packages: rollup-pluginutils: 2.8.2 dev: true + /rollup-plugin-dts/4.2.2_oo3i3f3qmqiztdz5qgxrrjmd5e: + resolution: {integrity: sha512-A3g6Rogyko/PXeKoUlkjxkP++8UDVpgA7C+Tdl77Xj4fgEaIjPSnxRmR53EzvoYy97VMVwLAOcWJudaVAuxneQ==} + engines: {node: '>=v12.22.11'} + peerDependencies: + rollup: ^2.55 + typescript: ^4.1 + dependencies: + magic-string: 0.26.3 + rollup: 2.77.2 + typescript: 4.7.4 + optionalDependencies: + '@babel/code-frame': 7.18.6 + dev: true + /rollup-plugin-istanbul/3.0.0_rollup@2.77.2: resolution: {integrity: sha512-z8kD2A57qTcxgqjbJ8cZBBE/IGYk+iJtE42sCaZjrSe/uBEUq5jJYvQwquJ+Acfko1LMYww4EJfeMJmc0GttpQ==} peerDependencies: @@ -15235,6 +15280,10 @@ packages: resolution: {integrity: sha512-c3zayb8/kWWpycWYg87P71E1S1ZL6b6IJxfb5fvsUgsf0S2MVGaDhDXXjDMpdCpfWXqptc+4mXwmiy1ypXqRAA==} dev: false + /ts-expect/1.3.0: + resolution: {integrity: sha512-e4g0EJtAjk64xgnFPD6kTBUtpnMVzDrMb12N1YZV0VvSlhnVT3SGxiYTLdGy8Q5cYHOIC/FAHmZ10eGrAguicQ==} + dev: true + /tsconfig-paths/3.14.1: resolution: {integrity: sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ==} dependencies: diff --git a/rollup.config.js b/rollup.config.js index b6ab1e826..c45e09455 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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')); @@ -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' + } } ]; diff --git a/test/integration/typescript-node-next/package.json b/test/integration/typescript-node-next/package.json new file mode 100644 index 000000000..814afb7ac --- /dev/null +++ b/test/integration/typescript-node-next/package.json @@ -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" + } +} diff --git a/test/integration/typescript-node-next/src/index.ts b/test/integration/typescript-node-next/src/index.ts new file mode 100644 index 000000000..4b2ba1aa0 --- /dev/null +++ b/test/integration/typescript-node-next/src/index.ts @@ -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>(false); +expectType>(false); +expectType>(false); diff --git a/test/integration/typescript-node-next/tsconfig.json b/test/integration/typescript-node-next/tsconfig.json new file mode 100644 index 000000000..3a894d573 --- /dev/null +++ b/test/integration/typescript-node-next/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "moduleResolution": "NodeNext", + "noEmit": true, + "lib": ["es2018", "DOM"] + }, + "include": [ + "./src/**/*.ts", + ] +} diff --git a/test/integration/typescript-node/package.json b/test/integration/typescript-node/package.json new file mode 100644 index 000000000..49143cb10 --- /dev/null +++ b/test/integration/typescript-node/package.json @@ -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" + } +} diff --git a/test/integration/typescript-node/src/index.ts b/test/integration/typescript-node/src/index.ts new file mode 100644 index 000000000..4b2ba1aa0 --- /dev/null +++ b/test/integration/typescript-node/src/index.ts @@ -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>(false); +expectType>(false); +expectType>(false); diff --git a/test/integration/typescript-node/tsconfig.json b/test/integration/typescript-node/tsconfig.json new file mode 100644 index 000000000..9a26a3d9d --- /dev/null +++ b/test/integration/typescript-node/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "moduleResolution": "Node", + "noEmit": true, + "lib": ["es2018", "DOM"] + }, + "include": [ + "./src/**/*.ts", + ] +} diff --git a/types/tests/autogen.js b/types/tests/autogen.js index 9d17efcb0..e34798341 100644 --- a/types/tests/autogen.js +++ b/types/tests/autogen.js @@ -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)) {