From 0fa824718a18caea384af56b3ff4fa9549159bdf Mon Sep 17 00:00:00 2001 From: syimyuzya Date: Sun, 28 Jul 2024 21:57:16 +0800 Subject: [PATCH] feat: bundle .d.ts (again) Bundled as `index.d.ts` as before --- .gitignore | 2 +- package-lock.json | 34 ++++++++++++++++++++++++++++++++++ package.json | 5 +++-- rollup.config.mjs | 41 ++++++++++++++++++++++++++--------------- tsconfig.json | 1 - tsconfig.test.json | 1 - 6 files changed, 64 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index bcdbe7e..ce80f0c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ yarn.lock /index.js /index.js.map -/types +/index.d.ts /docs diff --git a/package-lock.json b/package-lock.json index d677d37..0186b84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,7 @@ "open-cli": "^8.0.0", "prettier": "^3.3.2", "rollup": "^4.18.0", + "rollup-plugin-dts": "^6.1.1", "ts-node": "^10.9.2", "tslib": "^2.6.3", "typedoc": "^0.26.3", @@ -6264,6 +6265,16 @@ "dev": true, "license": "MIT" }, + "node_modules/magic-string": { + "version": "0.30.10", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.10.tgz", + "integrity": "sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.4.15" + } + }, "node_modules/make-dir": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", @@ -8237,6 +8248,29 @@ "fsevents": "~2.3.2" } }, + "node_modules/rollup-plugin-dts": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/rollup-plugin-dts/-/rollup-plugin-dts-6.1.1.tgz", + "integrity": "sha512-aSHRcJ6KG2IHIioYlvAOcEq6U99sVtqDDKVhnwt70rW6tsz3tv5OSjEiWcgzfsHdLyGXZ/3b/7b/+Za3Y6r1XA==", + "dev": true, + "license": "LGPL-3.0-only", + "dependencies": { + "magic-string": "^0.30.10" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/Swatinem" + }, + "optionalDependencies": { + "@babel/code-frame": "^7.24.2" + }, + "peerDependencies": { + "rollup": "^3.29.4 || ^4", + "typescript": "^4.5 || ^5.0" + } + }, "node_modules/run-applescript": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-7.0.0.tgz", diff --git a/package.json b/package.json index e361788..5791998 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.15.0-alpha.1", "description": "A JavaScript library for the Qieyun phonological system", "main": "index.js", - "types": "types/index.d.ts", + "types": "index.d.ts", "scripts": { "build": "run-p build:*", "build:rollup": "rollup -c", @@ -68,6 +68,7 @@ "open-cli": "^8.0.0", "prettier": "^3.3.2", "rollup": "^4.18.0", + "rollup-plugin-dts": "^6.1.1", "ts-node": "^10.9.2", "tslib": "^2.6.3", "typedoc": "^0.26.3", @@ -77,7 +78,7 @@ "files": [ "index.js", "index.js.map", - "types", + "index.d.ts", "LICENSE", "README.md" ], diff --git a/rollup.config.mjs b/rollup.config.mjs index 8c40084..909441f 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,20 +1,31 @@ // @ts-check import typescript from '@rollup/plugin-typescript'; +import dts from 'rollup-plugin-dts'; -export default { - input: 'src/index.ts', - output: { - file: 'index.js', - format: 'umd', - sourcemap: true, - name: 'Qieyun', - exports: 'named', +export default [ + { + input: 'src/index.ts', + output: { + file: 'index.js', + format: 'umd', + sourcemap: true, + name: 'Qieyun', + exports: 'named', + }, + plugins: [ + typescript({ + // NOTE Apparently needed with `"incremental": true` in tsconfig + outputToFilesystem: false, + }), + ], }, - plugins: [ - typescript({ - // XXX Apparently needed with `"incremental": true` in tsconfig - outputToFilesystem: false, - }), - ], -}; + { + input: 'build/esnext/index.d.ts', + output: { + file: 'index.d.ts', + format: 'es', + }, + plugins: [dts()], + }, +]; diff --git a/tsconfig.json b/tsconfig.json index 1a8647d..c9cc96a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,6 @@ "moduleResolution": "node", "module": "esnext", "declaration": true, - "declarationDir": "types", "inlineSourceMap": true, "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */, "resolveJsonModule": true /* Include modules imported with .json extension. */, diff --git a/tsconfig.test.json b/tsconfig.test.json index 47e218c..c1f064c 100644 --- a/tsconfig.test.json +++ b/tsconfig.test.json @@ -4,7 +4,6 @@ "outDir": "build/test", "module": "commonjs", "declaration": false, - "declarationDir": null, "types": ["node"] }, "exclude": []