Skip to content

Commit

Permalink
Add missing typescript esm types (#1623)
Browse files Browse the repository at this point in the history
* chore: add writeEsmPackageJson script

* chore: update builds to emit type declaration files

* docs: update changelog
  • Loading branch information
notaphplover authored Nov 12, 2024
1 parent 5b7c8c8 commit 00cb0ba
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 43 additions & 0 deletions scripts/writeEsmPackageJson.mjs
Original file line number Diff line number Diff line change
@@ -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<boolean>}
*/
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);
2 changes: 0 additions & 2 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
],
"extends": "../tsconfig.json",
"compilerOptions": {
"composite": true,
"declaration": true,
"outDir": "../lib",
"rootDir": "."
},
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"allowUnusedLabels": false,
"alwaysStrict": true,
"assumeChangesOnlyAffectDirectDependencies": true,
"declaration": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"exactOptionalPropertyTypes": true,
Expand Down

0 comments on commit 00cb0ba

Please sign in to comment.