mirror of
https://github.com/ProtonMail/openpgpjs.git
synced 2026-01-11 19:26:27 +00:00
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.
This commit is contained in:
parent
e4c754f144
commit
b7fc9a76cb
5 changed files with 258 additions and 15 deletions
226
package-lock.json
generated
226
package-lock.json
generated
|
|
@ -39,6 +39,7 @@
|
|||
"c8": "^10.1.3",
|
||||
"chai": "^4.5.0",
|
||||
"chai-as-promised": "^7.1.2",
|
||||
"cpy-cli": "^6.0.0",
|
||||
"eckey-utils": "^0.7.14",
|
||||
"eslint": "^8.57.1",
|
||||
"eslint-config-airbnb": "^19.0.4",
|
||||
|
|
@ -1687,6 +1688,19 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@sindresorhus/merge-streams": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@sindresorhus/merge-streams/-/merge-streams-2.3.0.tgz",
|
||||
"integrity": "sha512-LtoMMhxAlorcGhmFYI+LhPgbPZCkgP6ra1YL604EeF6U98pLlQ3iWIGMdWSC+vWmPBWBNgmDBAhnAobLROJmwg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/@sinonjs/commons": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz",
|
||||
|
|
@ -4513,6 +4527,52 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/copy-file": {
|
||||
"version": "11.1.0",
|
||||
"resolved": "https://registry.npmjs.org/copy-file/-/copy-file-11.1.0.tgz",
|
||||
"integrity": "sha512-X8XDzyvYaA6msMyAM575CUoygY5b44QzLcGRKsK3MFmXcOvQa518dNPLsKYwkYsn72g3EiW+LE0ytd/FlqWmyw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"graceful-fs": "^4.2.11",
|
||||
"p-event": "^6.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/copy-file/node_modules/p-event": {
|
||||
"version": "6.0.1",
|
||||
"resolved": "https://registry.npmjs.org/p-event/-/p-event-6.0.1.tgz",
|
||||
"integrity": "sha512-Q6Bekk5wpzW5qIyUP4gdMEujObYstZl6DMMOSenwBvV0BlE5LkDwkjs5yHbZmdCEq2o4RJx4tE1vwxFVf2FG1w==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"p-timeout": "^6.1.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.17"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/copy-file/node_modules/p-timeout": {
|
||||
"version": "6.1.4",
|
||||
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-6.1.4.tgz",
|
||||
"integrity": "sha512-MyIV3ZA/PmyBN/ud8vV9XzwTrNtR4jFrObymZYnZqMmW0zA8Z17vnT0rBgFE/TlohB+YCHqXMgZzb3Csp49vqg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=14.16"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/core-util-is": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||
|
|
@ -4520,6 +4580,104 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/cpy": {
|
||||
"version": "12.0.1",
|
||||
"resolved": "https://registry.npmjs.org/cpy/-/cpy-12.0.1.tgz",
|
||||
"integrity": "sha512-hCnNla4AB27lUncMuO7KFjge0u0C5R74iKMBOajKOMB9ONGXcIek314ZTpxg16BuNYRTjPz7UW3tPXgJVLxUww==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"copy-file": "^11.1.0",
|
||||
"globby": "^14.1.0",
|
||||
"junk": "^4.0.1",
|
||||
"micromatch": "^4.0.8",
|
||||
"p-filter": "^4.1.0",
|
||||
"p-map": "^7.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/cpy-cli": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/cpy-cli/-/cpy-cli-6.0.0.tgz",
|
||||
"integrity": "sha512-q7GUqTDnRymCbScJ4Ph1IUM86wWdKG8JbgrvKLgvvehH4wrbRcVN+jRwOTlxJdwm7ykdXMKSp6IESksFeHa0eA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cpy": "^12.0.0",
|
||||
"meow": "^13.2.0"
|
||||
},
|
||||
"bin": {
|
||||
"cpy": "cli.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/cpy/node_modules/globby": {
|
||||
"version": "14.1.0",
|
||||
"resolved": "https://registry.npmjs.org/globby/-/globby-14.1.0.tgz",
|
||||
"integrity": "sha512-0Ia46fDOaT7k4og1PDW4YbodWWr3scS2vAr2lTbsplOt2WkKp0vQbkI9wKis/T5LV/dqPjO3bpS/z6GTJB82LA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@sindresorhus/merge-streams": "^2.1.0",
|
||||
"fast-glob": "^3.3.3",
|
||||
"ignore": "^7.0.3",
|
||||
"path-type": "^6.0.0",
|
||||
"slash": "^5.1.0",
|
||||
"unicorn-magic": "^0.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/cpy/node_modules/ignore": {
|
||||
"version": "7.0.5",
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.5.tgz",
|
||||
"integrity": "sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
}
|
||||
},
|
||||
"node_modules/cpy/node_modules/path-type": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/path-type/-/path-type-6.0.0.tgz",
|
||||
"integrity": "sha512-Vj7sf++t5pBD637NSfkxpHSMfWaeig5+DKWLhcqIYx6mWQz5hdJTGDVMQiJcw1ZYkhs7AazKDGpRVji1LJCZUQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/cpy/node_modules/slash": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/slash/-/slash-5.1.0.tgz",
|
||||
"integrity": "sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=14.16"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/crc-32": {
|
||||
"version": "1.2.2",
|
||||
"resolved": "https://registry.npmjs.org/crc-32/-/crc-32-1.2.2.tgz",
|
||||
|
|
@ -8246,6 +8404,19 @@
|
|||
"safe-buffer": "~5.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/junk": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/junk/-/junk-4.0.1.tgz",
|
||||
"integrity": "sha512-Qush0uP+G8ZScpGMZvHUiRfI0YBWuB3gVBYlI0v0vvOJt5FLicco+IkP0a50LqTTQhmts/m6tP5SWE+USyIvcQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=12.20"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/keygrip": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/keygrip/-/keygrip-1.1.0.tgz",
|
||||
|
|
@ -8827,6 +8998,19 @@
|
|||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/meow": {
|
||||
"version": "13.2.0",
|
||||
"resolved": "https://registry.npmjs.org/meow/-/meow-13.2.0.tgz",
|
||||
"integrity": "sha512-pxQJQzB6djGPXh08dacEloMFopsOqGVRKFPYvPOt9XDZ1HasbgDZA74CJGreSU4G3Ak7EFJGoiH2auq+yXISgA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/merge-stream": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
|
||||
|
|
@ -9469,6 +9653,22 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/p-filter": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/p-filter/-/p-filter-4.1.0.tgz",
|
||||
"integrity": "sha512-37/tPdZ3oJwHaS3gNJdenCDB3Tz26i9sjhnguBtvN0vYlRIiDNnvTWkuh+0hETV9rLPdJ3rlL3yVOYPIAnM8rw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"p-map": "^7.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/p-finally": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
|
||||
|
|
@ -9511,6 +9711,19 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/p-map": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npmjs.org/p-map/-/p-map-7.0.3.tgz",
|
||||
"integrity": "sha512-VkndIv2fIB99swvQoA65bm+fsmt6UNdGeIB0oxBs+WhAhdh08QA04JXpI7rbB9r08/nkbysKoya9rtDERYOYMA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/p-timeout": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
|
||||
|
|
@ -12257,6 +12470,19 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/unicorn-magic": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.3.0.tgz",
|
||||
"integrity": "sha512-+QBBXBCvifc56fsbuxZQ6Sic3wqqc3WWaqxs58gvJrcOuN83HGTCwz3oS5phzU9LthRNE9VrJCFCLUgHeeFnfA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/unpipe": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
|
||||
|
|
|
|||
20
package.json
20
package.json
|
|
@ -21,33 +21,32 @@
|
|||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./openpgp.d.ts",
|
||||
"types": "./dist/types/index.d.ts",
|
||||
"browser": "./dist/openpgp.min.mjs",
|
||||
"import": "./dist/node/openpgp.mjs",
|
||||
"require": "./dist/node/openpgp.min.cjs"
|
||||
},
|
||||
"./lightweight": {
|
||||
"types": "./openpgp.d.ts",
|
||||
"types": "./dist/types/index.d.ts",
|
||||
"browser": "./dist/lightweight/openpgp.min.mjs"
|
||||
}
|
||||
},
|
||||
"types": "openpgp.d.ts",
|
||||
"types": "dist/types/index.d.ts",
|
||||
"type": "module",
|
||||
"directories": {
|
||||
"lib": "src"
|
||||
},
|
||||
"files": [
|
||||
"dist/",
|
||||
"lightweight/",
|
||||
"openpgp.d.ts",
|
||||
"**/*.d.ts"
|
||||
"lightweight/"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rollup --config",
|
||||
"build-types": "rm -rf dist/types && tsc --project tsconfig.dist.json && cpy 'src/**/*.d.ts' dist/types",
|
||||
"build-test": "npm run build -- --config-build-only=test",
|
||||
"prepare": "npm run build",
|
||||
"prepare": "npm run build && npm run build-types",
|
||||
"test": "mocha --timeout 120000 test/unittests.js",
|
||||
"test-type-definitions": "tsc --project test/typescript/tsconfig.test.json && tsx test/typescript/definitions.ts",
|
||||
"test-type-definitions": "npm run build-types && tsc --project test/typescript/tsconfig.test.json && tsx test/typescript/definitions.ts",
|
||||
"benchmark-time": "node test/benchmarks/time.js",
|
||||
"benchmark-memory-usage": "node test/benchmarks/memory_usage.js",
|
||||
"prebrowsertest": "npm run build-test",
|
||||
|
|
@ -93,6 +92,7 @@
|
|||
"c8": "^10.1.3",
|
||||
"chai": "^4.5.0",
|
||||
"chai-as-promised": "^7.1.2",
|
||||
"cpy-cli": "^6.0.0",
|
||||
"eckey-utils": "^0.7.14",
|
||||
"eslint": "^8.57.1",
|
||||
"eslint-config-airbnb": "^19.0.4",
|
||||
|
|
@ -109,9 +109,9 @@
|
|||
"sinon": "^20.0.0",
|
||||
"ts-node": "^10.9.2",
|
||||
"tslib": "^2.8.1",
|
||||
"web-streams-polyfill": "^4.1.0",
|
||||
"tsx": "^4.20.5",
|
||||
"typescript": "^5.9.2"
|
||||
"typescript": "^5.9.2",
|
||||
"web-streams-polyfill": "^4.1.0"
|
||||
},
|
||||
"overrides": {
|
||||
"@web/dev-server-core": "npm:@openpgp/wtr-dev-server-core@0.7.3-patch.1",
|
||||
|
|
|
|||
|
|
@ -80,7 +80,8 @@ const nodeBuild = {
|
|||
exportConditions: ['node'] // needed for resolution of noble-curves import of '@noble/crypto' in Node 18
|
||||
}),
|
||||
typescript({
|
||||
compilerOptions: { outDir: './dist/node' } // temporary output location, needed to avoid js files being overwritten under `src`
|
||||
compilerOptions: { outDir: './dist/node' }, // temporary output location, needed to avoid js files being overwritten under `src`
|
||||
rootDir: 'src' // ignore .ts files outside of src folder
|
||||
}),
|
||||
commonjs(),
|
||||
replace({
|
||||
|
|
@ -104,7 +105,8 @@ const fullBrowserBuild = {
|
|||
browser: true
|
||||
}),
|
||||
typescript({
|
||||
compilerOptions: { outDir: './dist' } // temporary output location, needed to avoid js files being overwritten under `src`
|
||||
compilerOptions: { outDir: './dist' }, // temporary output location, needed to avoid js files being overwritten under `src`
|
||||
rootDir: 'src' // ignore .ts files outside of src folder
|
||||
}),
|
||||
commonjs({
|
||||
ignore: nodeBuiltinModules.concat(nodeDependencies)
|
||||
|
|
@ -131,7 +133,8 @@ const lightweightBrowserBuild = {
|
|||
browser: true
|
||||
}),
|
||||
typescript({
|
||||
compilerOptions: { outDir: './dist/lightweight' }
|
||||
compilerOptions: { outDir: './dist/lightweight' },
|
||||
rootDir: 'src' // ignore .ts files outside of src folder
|
||||
}),
|
||||
commonjs({
|
||||
ignore: nodeBuiltinModules.concat(nodeDependencies)
|
||||
|
|
|
|||
6
openpgp.d.ts → src/index.d.ts
vendored
6
openpgp.d.ts → src/index.d.ts
vendored
|
|
@ -10,8 +10,10 @@
|
|||
*/
|
||||
|
||||
import type { WebStream as GenericWebStream, NodeWebStream as GenericNodeWebStream } from '@openpgp/web-stream-tools';
|
||||
import enums from './src/enums';
|
||||
import config, { type Config, type PartialConfig } from './src/config';
|
||||
import enums from './enums';
|
||||
import config, { type Config, type PartialConfig } from './config';
|
||||
|
||||
export { GrammarError } from './packet/grammar';
|
||||
|
||||
export { enums, config, Config, PartialConfig };
|
||||
|
||||
12
tsconfig.dist.json
Normal file
12
tsconfig.dist.json
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// tsconfig taking care of generating declaration files to be released
|
||||
// under 'dist/types'
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"emitDeclarationOnly": true,
|
||||
"declarationDir": "./dist/types",
|
||||
"rootDir": "src"
|
||||
},
|
||||
"files": ["src/index.d.ts"]
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue