From c75ff343ec82af1277fc8d61aea2ed6001a3a1b4 Mon Sep 17 00:00:00 2001 From: Haoqun Jiang Date: Wed, 23 Oct 2024 16:59:01 +0800 Subject: [PATCH] feat: generate .d.ts files on publishing Fixes #24 --- .gitignore | 2 ++ index.js | 1 + package.json | 10 +++++++--- pnpm-lock.yaml | 10 ++++++++++ skip-formatting.js | 2 ++ tsconfig.json | 9 +++++++++ 6 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 3c3629e..3ec4a2e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +index.d.ts +skip-formatting.d.ts diff --git a/index.js b/index.js index 8f78d98..ccca7b6 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,6 @@ const recommendedConfig = require("eslint-plugin-prettier/recommended"); +/** @type {import('eslint').Linter.Config} */ module.exports = { ...recommendedConfig, rules: { diff --git a/package.json b/package.json index e8c16c0..86ce026 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,9 @@ "main": "index.js", "files": [ "index.js", - "skip-formatting.js" + "index.d.ts", + "skip-formatting.js", + "skip-formatting.d.ts" ], "exports": { ".": "./index.js", @@ -38,7 +40,8 @@ }, "devDependencies": { "eslint": "^9.11.0", - "prettier": "^3.3.3" + "prettier": "^3.3.3", + "typescript": "^5.6.3" }, "peerDependencies": { "eslint": ">= 8.21.0", @@ -46,6 +49,7 @@ }, "scripts": { "lint": "eslint . --fix", - "format": "prettier *.{js,md} --write" + "format": "prettier *.{js,md} --write", + "prepublishOnly": "tsc" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 85052c9..821dc22 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -21,6 +21,9 @@ importers: prettier: specifier: ^3.3.3 version: 3.3.3 + typescript: + specifier: ^5.6.3 + version: 5.6.3 packages: @@ -402,6 +405,11 @@ packages: resolution: {integrity: sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==} engines: {node: '>= 0.8.0'} + typescript@5.6.3: + resolution: {integrity: sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==} + engines: {node: '>=14.17'} + hasBin: true + uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} @@ -773,6 +781,8 @@ snapshots: dependencies: prelude-ls: 1.2.1 + typescript@5.6.3: {} + uri-js@4.4.1: dependencies: punycode: 2.3.1 diff --git a/skip-formatting.js b/skip-formatting.js index 3ef197a..24660b8 100644 --- a/skip-formatting.js +++ b/skip-formatting.js @@ -4,6 +4,8 @@ const eslintConfigPrettier = require("eslint-config-prettier"); // Because that would be an overkill: // - since we are not formatting, the plugin isn't needed; // - and without the `prettier/prettier` rule, we don't have to disable the conflicting `arrow-body-style` and `prefer-arrow-callback` rules. + +/** @type {import('eslint').Linter.Config} */ module.exports = { ...eslintConfigPrettier, rules: { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..f5d5a00 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,9 @@ +{ + "include": ["index.js", "skip-formatting.js"], + "compilerOptions": { + "allowJs": true, + "declaration": true, + "emitDeclarationOnly": true, + "skipLibCheck": true + } +}