Skip to content

Commit

Permalink
Fix CommonJS file content
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore committed May 4, 2023
1 parent fca9909 commit 7a9f716
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tools/rename-ext.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'node:path';
import fs from 'node:fs';
import fs from 'node:fs/promises';
import { globby } from 'globby';
import * as url from 'node:url';

Expand All @@ -13,13 +13,17 @@ const paths: string[] = await globby([
'packages/**/dist/cjs/**/*.mjs',
'!**/node_modules',
]);

paths.forEach(async (pathname: string) => {
const fileContent = await fs.readFile(pathname, 'utf-8');
await fs.writeFile(pathname, fileContent.replace(/\.mjs/g, '.js'));

const newPath = path.format({
...path.parse(pathname),
base: '',
ext: '.js',
});

console.log(`Renaming ${pathname} to ${newPath}...`);
await fs.promises.rename(pathname, newPath);
await fs.rename(pathname, newPath);
});

0 comments on commit 7a9f716

Please sign in to comment.