Skip to content

Commit

Permalink
Fix type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Feb 10, 2024
1 parent 22ab323 commit 8a2e1bd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
30 changes: 29 additions & 1 deletion esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

import esbuild from 'esbuild';
import { readdir, readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

const buildOptionsBase = {
entryPoints: [
Expand All @@ -35,7 +37,7 @@ const buildOptionsBase = {

const formats = ['cjs', 'esm'];

await Promise.resolve(
await Promise.all(
formats.map((format) => {
return esbuild.build({
...buildOptionsBase,
Expand All @@ -46,3 +48,29 @@ await Promise.resolve(
});
}),
);

const cjsDeclarationFiles = async (directoryPath) => {
const entries = await readdir(directoryPath, {
withFileTypes: true,
recursive: true,
});

await Promise.all(
entries
.filter((entry) => {
return entry.isFile() && entry.name.endsWith('.d.ts');
})
.map(async (file) => {
const name = join(file.path, file.name);
const newName = name.slice(0, -2) + 'cts';

const contents = await readFile(name, { encoding: 'utf-8' });
await writeFile(
newName,
contents.replace(/(?<=\.)js(?=['"])/g, 'cjs'),
);
}),
);
};

await cjsDeclarationFiles('dist');
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@exact-realty/rfc8188",
"version": "1.0.3",
"version": "1.0.4",
"description": "An implementation of RFC 8188 (encrypted content-encoding for HTTP)",
"type": "module",
"main": "dist/index.cjs",
Expand All @@ -12,7 +12,7 @@
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
Expand All @@ -22,7 +22,7 @@
"default": "./dist/decrypt.mjs"
},
"require": {
"types": "./dist/exports/decrypt.d.ts",
"types": "./dist/exports/decrypt.d.cts",
"default": "./dist/decrypt.cjs"
}
},
Expand All @@ -32,7 +32,7 @@
"default": "./dist/encodings.mjs"
},
"require": {
"types": "./dist/exports/encodings.d.ts",
"types": "./dist/exports/encodings.d.cts",
"default": "./dist/encodings.cjs"
}
},
Expand All @@ -42,7 +42,7 @@
"default": "./dist/encrypt.mjs"
},
"require": {
"types": "./dist/exports/encrypt.d.ts",
"types": "./dist/exports/encrypt.d.cts",
"default": "./dist/encrypt.cjs"
}
}
Expand Down

0 comments on commit 8a2e1bd

Please sign in to comment.