Skip to content

Commit fbbef7e

Browse files
committed
chore: convert to esm
1 parent 2b2edaa commit fbbef7e

6 files changed

Lines changed: 22 additions & 15 deletions

File tree

.eslintrc.js renamed to .eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { readGitignoreFiles } = require('eslint-gitignore');
55
module.exports = defineConfig({
66
ignorePatterns: [
77
...readGitignoreFiles(),
8-
'.eslintrc.js', // Skip self linting
8+
'.eslintrc.cjs', // Skip self linting
99
],
1010
root: true,
1111
env: {

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@
2828
],
2929
"bugs": "https://github.com/faker-js/faker/issues",
3030
"license": "MIT",
31+
"type": "module",
3132
"main": "dist/cjs/index.js",
32-
"module": "dist/esm/index.mjs",
33+
"module": "dist/esm/index.js",
3334
"types": "index.d.ts",
3435
"typesVersions": {
3536
">=4.0": {
@@ -41,13 +42,15 @@
4142
"exports": {
4243
".": {
4344
"types": "./dist/types/index.d.ts",
45+
"import": "./dist/esm/index.js",
4446
"require": "./dist/cjs/index.js",
45-
"import": "./dist/esm/index.mjs"
47+
"default": "./dist/esm/index.js"
4648
},
4749
"./locale/*": {
4850
"types": "./dist/types/locale/*.d.ts",
51+
"import": "./dist/esm/locale/*.js",
4952
"require": "./dist/cjs/locale/*.js",
50-
"import": "./dist/esm/locale/*.mjs"
53+
"default": "./dist/esm/locale/*.js"
5154
},
5255
"./package.json": "./package.json"
5356
},

scripts/apidoc/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { createHash } from 'node:crypto';
22
import { resolve } from 'node:path';
3+
import { fileURLToPath, URL } from 'node:url';
34
import type { Method } from '../../docs/.vitepress/components/api-docs/method';
45

6+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
7+
58
// Types
69

710
export type Page = { text: string; link: string };

scripts/bundle.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { buildSync } from 'esbuild';
2-
import { globSync } from 'glob';
32
import { allLocales } from '../src';
43

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

76
const target = ['ES2019', 'node14.17'];
87

98
buildSync({
10-
entryPoints: globSync('./src/**/*.ts'),
11-
// We can use the following entry points when esbuild supports cjs+splitting
12-
// entryPoints: [
13-
// './src/index.ts',
14-
// ...Object.keys(locales).map((locale) => `./src/locale/${locale}.ts`),
15-
// ],
9+
entryPoints: [
10+
'./src/index.ts',
11+
...Object.keys(allLocales).map((locale) => `./src/locale/${locale}.ts`),
12+
],
1613
outdir: './dist/cjs',
17-
bundle: false, // Creates 390MiB bundle ...
14+
bundle: true, // Creates 49MiB bundle ...
1815
sourcemap: false,
1916
minify: true,
2017
// splitting: true, // Doesn't work with cjs
@@ -36,5 +33,4 @@ buildSync({
3633
splitting: true,
3734
format: 'esm',
3835
target,
39-
outExtension: { '.js': '.mjs' },
4036
});

scripts/generateLocales.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ import {
2020
writeFileSync,
2121
} from 'node:fs';
2222
import { resolve } from 'node:path';
23+
import { fileURLToPath, URL } from 'node:url';
2324
import type { Options } from 'prettier';
2425
import { format } from 'prettier';
2526
import options from '../.prettierrc.js';
2627
import type { LocaleDefinition, MetadataDefinition } from '../src/definitions';
2728

29+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
30+
2831
// Constants
2932

3033
const pathRoot = resolve(__dirname, '..');
@@ -284,8 +287,7 @@ async function main(): Promise<void> {
284287
const pathMetadata = resolve(pathModules, 'metadata.ts');
285288
let localeTitle = 'No title found';
286289
try {
287-
// eslint-disable-next-line @typescript-eslint/no-var-requires
288-
const metadata: MetadataDefinition = require(pathMetadata).default;
290+
const metadata: MetadataDefinition = (await import(pathMetadata)).default;
289291
const { title } = metadata;
290292
if (!title) {
291293
throw new Error(

test/scripts/apidoc/verify-jsdoc-tags.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
22
import { resolve } from 'node:path';
3+
import { fileURLToPath, URL } from 'node:url';
34
import validator from 'validator';
45
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
56
import { initMarkdownRenderer } from '../../../scripts/apidoc/markdown';
@@ -16,6 +17,8 @@ import {
1617
} from '../../../scripts/apidoc/typedoc';
1718
import { loadProjectModules } from './utils';
1819

20+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
21+
1922
// This test ensures, that every method
2023
// - has working examples
2124
// - running these do not log anything, unless the method is deprecated

0 commit comments

Comments
 (0)