Skip to content

Commit

Permalink
build: add redirect aliases for cjs (faker-js#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 authored and demipel8 committed Mar 11, 2022
1 parent 95b3e4d commit 825e225
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ versions.json
/docs/.vitepress/dist
/docs/api/typedoc.json
/lib
/locale

# Faker
TAGS
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"CHANGELOG.md",
"CHANGELOG_old.md",
"dist",
"locale",
"tsconfig.json"
],
"scripts": {
Expand Down
16 changes: 16 additions & 0 deletions scripts/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import { buildSync } from 'esbuild';
import { sync as globSync } from 'glob';
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
import locales from '../src/locales';

console.log('Building dist for node (cjs)...');

// Generate entry-points for cjs compatibility
const localeDir = 'locale';
if (existsSync(localeDir)) {
rmSync(localeDir, { recursive: true, force: true });
}
mkdirSync(localeDir);
for (const locale of Object.keys(locales)) {
writeFileSync(
`${localeDir}/${locale}.js`,
`module.exports = require('../dist/cjs/locale/${locale}');\n`,
{ encoding: 'utf8' }
);
}

buildSync({
entryPoints: globSync('./src/**/*.ts'),
// We can use the following entry points when esbuild supports cjs+splitting
Expand Down

0 comments on commit 825e225

Please sign in to comment.