Skip to content

Commit 160960b

Browse files
authored
feat!: esm only (#3540)
1 parent 4e422f7 commit 160960b

File tree

6 files changed

+14
-18
lines changed

6 files changed

+14
-18
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This is a shorthand for running the following scripts in order:
2323
- `pnpm run format` - runs [prettify](https://github.com/prettier/prettier) to format code
2424
- `pnpm run lint` - runs [ESLint](https://github.com/eslint/eslint) to enforce project code standards
2525
- `pnpm run build:clean` - removes artifacts from previous builds
26-
- `pnpm run build:code` - builds the code, both CommonJS and ESM versions
26+
- `pnpm run build:code` - builds the code
2727
- `pnpm run test:update-snapshots` - runs all tests, and updates any snapshots if needed
2828
- `pnpm run ts-check` - checks that there are no TypeScript errors in any files
2929

docs/contributing/submit-a-pull-request.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ It is a shorthand for running the following scripts in order:
4545
- `pnpm run format` - runs [prettier](https://github.com/prettier/prettier) to format code
4646
- `pnpm run lint` - runs [ESLint](https://github.com/eslint/eslint) to enforce project code standards
4747
- `pnpm run build:clean` - removes artifacts from previous builds
48-
- `pnpm run build:code` - builds the code, both CommonJS and ESM versions
48+
- `pnpm run build:code` - builds the code
4949
- `pnpm run test:update-snapshots` - runs all tests with [vitest](https://github.com/vitest-dev/vitest), and updates any snapshots if needed
5050
- `pnpm run ts-check` - checks that there are no TypeScript errors in any files
5151

docs/guide/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ This documentation only covers the JavaScript implementation of Faker.
1515

1616
## Environments
1717

18-
You can run Faker in the browser, or in Node.js. Faker v9.0 requires Node.js version 18 or above. Both ESM and CommonJS imports are available.
18+
You can run Faker in the browser, or in Node.js. Faker v10.0 requires Node.js version 20 or above.
19+
20+
::: tip Note
21+
When using CJS, you need to use at least Node.js v20.19. See https://nodejs.org/api/modules.html#loading-ecmascript-modules-using-require
22+
:::
1923

2024
## Installation
2125

package.json

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,28 +67,20 @@
6767
"type": "module",
6868
"exports": {
6969
".": {
70-
"require": {
71-
"types": "./dist/index.d.cts",
72-
"default": "./dist/index.cjs"
73-
},
7470
"default": {
7571
"types": "./dist/index.d.ts",
7672
"default": "./dist/index.js"
7773
}
7874
},
7975
"./locale/*": {
80-
"require": {
81-
"types": "./dist/locale/*.d.cts",
82-
"default": "./dist/locale/*.cjs"
83-
},
8476
"default": {
8577
"types": "./dist/locale/*.d.ts",
8678
"default": "./dist/locale/*.js"
8779
}
8880
},
8981
"./package.json": "./package.json"
9082
},
91-
"main": "dist/index.cjs",
83+
"main": "dist/index.js",
9284
"module": "dist/index.js",
9385
"types": "dist/index.d.ts",
9486
"typesVersions": {
@@ -145,8 +137,8 @@
145137
},
146138
"packageManager": "[email protected]",
147139
"engines": {
148-
"node": ">=18.0.0",
149-
"npm": ">=9.0.0"
140+
"node": ">=20.19",
141+
"npm": ">=10"
150142
},
151143
"pnpm": {
152144
"ignoredBuiltDependencies": [

test/require.spec.cts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { describe, expect, it, vi } = await import('vitest');
2-
const { allLocales, SimpleFaker } = require('../dist/index.cjs');
2+
const { allLocales, SimpleFaker } = require('../dist/index.js');
33

44
describe('require (cjs)', () => {
55
describe.each(
@@ -9,7 +9,7 @@ describe('require (cjs)', () => {
99
)
1010
)('locale imports', (locale) => {
1111
it(`should be possible to directly require('@faker-js/faker/locale/${locale}')`, () => {
12-
const { faker } = require(`../dist/locale/${locale}.cjs`);
12+
const { faker } = require(`../dist/locale/${locale}.js`);
1313

1414
expect(faker).toBeDefined();
1515
expect(faker.string.alpha()).toBeTypeOf('string');

tsup.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export default defineConfig({
88
],
99
outDir: 'dist',
1010
clean: true,
11-
format: ['esm', 'cjs'],
12-
target: ['es2022', 'node18'],
11+
format: 'esm',
12+
target: ['es2023', 'node20.11'],
1313
dts: true,
1414
minify: true,
1515
sourcemap: false,

0 commit comments

Comments
 (0)