Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
* Updated dependencies
* Added esbuild 20.x a supported version
* Switched to ESM
  • Loading branch information
corrideat committed Feb 23, 2024
1 parent b0c2bf6 commit 023c243
Show file tree
Hide file tree
Showing 8 changed files with 1,127 additions and 1,977 deletions.
59 changes: 0 additions & 59 deletions .eslintrc.js

This file was deleted.

23 changes: 0 additions & 23 deletions .prettierrc.js

This file was deleted.

35 changes: 33 additions & 2 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 All @@ -25,7 +27,10 @@ await esbuild.build({
format: 'cjs',
entryNames: '[name]',
platform: 'node',
external: ['sharp'],
external: ['esbuild'],
outExtension: {
'.js': '.cjs',
},
});

await esbuild.build({
Expand All @@ -36,8 +41,34 @@ await esbuild.build({
format: 'esm',
entryNames: '[name]',
platform: 'node',
external: ['sharp'],
external: ['esbuild'],
outExtension: {
'.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 023c243

Please sign in to comment.