Skip to content

Commit

Permalink
Upgrade
Browse files Browse the repository at this point in the history
* Updated dependencies
* Fixed CJS types
* Defined a new getter to get build result `text`
  • Loading branch information
corrideat committed Feb 23, 2024
1 parent 50ea22e commit 244de8f
Show file tree
Hide file tree
Showing 4 changed files with 338 additions and 686 deletions.
28 changes: 28 additions & 0 deletions 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';

await esbuild.build({
entryPoints: ['./src/index.ts'],
Expand Down Expand Up @@ -44,3 +46,29 @@ await esbuild.build({
'.js': '.mjs',
},
});

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');
Loading

0 comments on commit 244de8f

Please sign in to comment.