]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
feat: typescript node next support (#10661)
authorDan Onoshko <danon0404@gmail.com>
Wed, 14 Sep 2022 10:44:57 +0000 (17:44 +0700)
committerGitHub <noreply@github.com>
Wed, 14 Sep 2022 10:44:57 +0000 (06:44 -0400)
12 files changed:
auto/auto.d.ts
helpers/helpers.d.ts
package.json
pnpm-lock.yaml
rollup.config.js
test/integration/typescript-node-next/package.json [new file with mode: 0644]
test/integration/typescript-node-next/src/index.ts [new file with mode: 0644]
test/integration/typescript-node-next/tsconfig.json [new file with mode: 0644]
test/integration/typescript-node/package.json [new file with mode: 0644]
test/integration/typescript-node/src/index.ts [new file with mode: 0644]
test/integration/typescript-node/tsconfig.json [new file with mode: 0644]
types/tests/autogen.js

index 487acb610fabd72f13d83262154d396be07337e7..fb1263ae5c9987c38407184688af5a1e5ed2ac02 100644 (file)
@@ -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;
index 587d0fd55616e8d6db147b607814c664d7e346c0..451fa58f7396f4777c448905884eff155cc84c96 100644 (file)
@@ -1 +1 @@
-export * from '../dist/helpers/types';
+export * from '../dist/helpers.js';
index e3ae7fd11a0f4df51e867ad0c78f41143c23acdd..0f4414b8dca24859cdfd8946cbc33a5f0e477979 100644 (file)
     "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": [
     "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",
         "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",
             "html-entities": "1.4.0"
         },
         "peerDependencyRules": {
-            "ignoreMissing": ["chart.js"]
+            "ignoreMissing": [
+                "chart.js"
+            ]
         }
     }
 }
index 0748a78359120cb26e41adf2cc65dd92b3348587..60fa8c7db20a7144bca10e93c7423c27188bd911 100644 (file)
@@ -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:
index b6ab1e82697ca92eb156ce417c0e91cebf1fab48..c45e09455c67428ef2286680e0e3a290b32fc3be 100644 (file)
@@ -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 (file)
index 0000000..814afb7
--- /dev/null
@@ -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 (file)
index 0000000..4b2ba1a
--- /dev/null
@@ -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);
diff --git a/test/integration/typescript-node-next/tsconfig.json b/test/integration/typescript-node-next/tsconfig.json
new file mode 100644 (file)
index 0000000..3a894d5
--- /dev/null
@@ -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 (file)
index 0000000..49143cb
--- /dev/null
@@ -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 (file)
index 0000000..4b2ba1a
--- /dev/null
@@ -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);
diff --git a/test/integration/typescript-node/tsconfig.json b/test/integration/typescript-node/tsconfig.json
new file mode 100644 (file)
index 0000000..9a26a3d
--- /dev/null
@@ -0,0 +1,10 @@
+{
+  "compilerOptions": {
+    "moduleResolution": "Node",
+    "noEmit": true,
+    "lib": ["es2018", "DOM"]
+  },
+  "include": [
+    "./src/**/*.ts",
+  ]
+}
index 9d17efcb0f0adc90c455202e919ec004d59275d2..e347983413626f8dc9e53cb034334626da34c87e 100644 (file)
@@ -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)) {