Skip to content

Commit df8475d

Browse files
committed
TS: emit type declarations for .ts files with external exports, and publish them under dist/types
This change makes it possible to easily expose types from internal .ts files. This is achieved by adding a TS compilation step which generates .d.ts files from .ts ones. Additionally, a copying step is needed for existing .d.ts files, which are not automatically moved to the outDir by tsc. The dist types will still only include those exported by the index files. Other tried approaches (to e.g. avoid the manual copying step) that were not viable: - generating a single .d.ts bundle is not supported by tsc, and other tools/plugins are either deprecated or (in the case of `rollup-plugin-dts`) failed to process our source code due to unsupported JS syntax - relying on the `rollup-typescript` plugin to emit declarations felt overly messy to configure and potentially unreliable as it generated declarations for .js files as well - renaming existing .d.ts to .ts (alongside .js ones) is not an option since it results in an empty output for the corresponding modules on Rollup compilation, as the .js source files are ignored.
1 parent 6a67a8a commit df8475d

File tree

4 files changed

+333
-93
lines changed

4 files changed

+333
-93
lines changed

package-lock.json

Lines changed: 226 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,28 @@
2121
},
2222
"exports": {
2323
".": {
24-
"types": "./openpgp.d.ts",
24+
"types": "./dist/types/index.d.ts",
2525
"browser": "./dist/openpgp.min.mjs",
2626
"import": "./dist/node/openpgp.mjs",
2727
"require": "./dist/node/openpgp.min.cjs"
2828
},
2929
"./lightweight": {
30-
"types": "./openpgp.d.ts",
30+
"types": "./dist/types/index.d.ts",
3131
"browser": "./dist/lightweight/openpgp.min.mjs"
3232
}
3333
},
34-
"types": "openpgp.d.ts",
34+
"types": "dist/types/index.d.ts",
3535
"type": "module",
3636
"directories": {
3737
"lib": "src"
3838
},
3939
"files": [
4040
"dist/",
41-
"lightweight/",
42-
"openpgp.d.ts",
43-
"**/*.d.ts"
41+
"lightweight/"
4442
],
4543
"scripts": {
46-
"build": "rollup --config",
44+
"build": "rollup --config && npm run build-types",
45+
"build-types": "rm -rf dist/types && tsc --project tsconfig.dist.json && cpy 'src/**/*.d.ts' dist/types",
4746
"build-test": "npm run build -- --config-build-only=test",
4847
"prepare": "npm run build",
4948
"test": "mocha --timeout 120000 test/unittests.js",
@@ -93,6 +92,7 @@
9392
"c8": "^10.1.3",
9493
"chai": "^4.5.0",
9594
"chai-as-promised": "^7.1.2",
95+
"cpy-cli": "^6.0.0",
9696
"eckey-utils": "^0.7.14",
9797
"eslint": "^8.57.1",
9898
"eslint-config-airbnb": "^19.0.4",
@@ -109,9 +109,9 @@
109109
"sinon": "^20.0.0",
110110
"ts-node": "^10.9.2",
111111
"tslib": "^2.8.1",
112-
"web-streams-polyfill": "^4.1.0",
113112
"tsx": "^4.20.5",
114-
"typescript": "^5.9.2"
113+
"typescript": "^5.9.2",
114+
"web-streams-polyfill": "^4.1.0"
115115
},
116116
"overrides": {
117117
"@web/dev-server-core": "npm:@openpgp/wtr-dev-server-core@0.7.3-patch.1",

0 commit comments

Comments
 (0)