From 00cb0ba3cf841c5d794e4b949e2671697a21a221 Mon Sep 17 00:00:00 2001 From: notaphplover Date: Tue, 12 Nov 2024 12:54:57 +0100 Subject: [PATCH] Add missing typescript esm types (#1623) * chore: add writeEsmPackageJson script * chore: update builds to emit type declaration files * docs: update changelog --- CHANGELOG.md | 1 + package.json | 2 +- scripts/writeEsmPackageJson.mjs | 43 +++++++++++++++++++++++++++++++++ src/tsconfig.json | 2 -- tsconfig.json | 1 + 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100755 scripts/writeEsmPackageJson.mjs diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d645c09d..294bdd719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed ### Fixed +- Updated ESM build with missing types. ## [6.1.2] diff --git a/package.json b/package.json index 66e706c6a..701fc1c3d 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "scripts": { "build": "npm run build:lib && npm run build:amd && npm run build:es && npm run build:es6", "build:amd": "tsc -p src/tsconfig-amd.json", - "build:es": "tsc -p src/tsconfig-es.json", + "build:es": "tsc -p src/tsconfig-es.json && node ./scripts/writeEsmPackageJson.mjs ./es", "build:es6": "tsc -p src/tsconfig-es6.json", "build:lib": "tsc -p src/tsconfig.json", "clean": "rimraf amd es es6 lib", diff --git a/scripts/writeEsmPackageJson.mjs b/scripts/writeEsmPackageJson.mjs new file mode 100755 index 000000000..2941aab5e --- /dev/null +++ b/scripts/writeEsmPackageJson.mjs @@ -0,0 +1,43 @@ +#!/usr/bin/env node + +import fs from 'node:fs/promises'; +import { argv } from 'node:process'; +import path from 'node:path'; +import { writeFile } from 'node:fs/promises'; + +/** + * @param {string} path + * @returns {Promise} + */ +async function pathExists(path) { + try { + await fs.access(path); + return true; + } catch (_err) { + return false; + } +} + +const directory = argv[2]; + +if (directory === undefined) { + throw new Error('Expected a path'); +} + +const directoryExists = await pathExists(directory); + +if (!directoryExists) { + throw new Error(`Path ${directory} not found`); +} + +const filePath = path.join(directory, 'package.json'); + +const packageJsonFileContent = JSON.stringify( + { + type: 'module', + }, + undefined, + 2, +); + +await writeFile(filePath, packageJsonFileContent); diff --git a/src/tsconfig.json b/src/tsconfig.json index 7e0412d29..af9997ca3 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -4,8 +4,6 @@ ], "extends": "../tsconfig.json", "compilerOptions": { - "composite": true, - "declaration": true, "outDir": "../lib", "rootDir": "." }, diff --git a/tsconfig.json b/tsconfig.json index f148d6b99..91359d106 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "allowUnusedLabels": false, "alwaysStrict": true, "assumeChangesOnlyAffectDirectDependencies": true, + "declaration": true, "emitDecoratorMetadata": true, "esModuleInterop": true, "exactOptionalPropertyTypes": true,