Skip to content

Commit a7de0ab

Browse files
authored
Merge branch 'next' into refactor/location/decouple-direction-data-index-from-representation-value
2 parents 4ed9ee3 + 03b965a commit a7de0ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2811
-2737
lines changed

docs/.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ const config: UserConfig<DefaultTheme.Config> = {
243243
text: 'Roadmap',
244244
link: '/about/roadmap/',
245245
items: [
246+
{
247+
text: 'v9 - Tree-Shakeable Module-Functions',
248+
link: '/about/roadmap/v9',
249+
},
246250
{ text: 'v8 - Make Faker Handier', link: '/about/roadmap/v8' },
247251
{
248252
text: 'v7 - Cleanup & Improvements',

docs/about/roadmap/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Click on the specific versions for more details.
99

1010
## Upcoming Versions
1111

12+
- [v9 - Tree Shaking](v9.md)
13+
14+
## Current Versions
15+
1216
- [v8 - Make Faker Handier](v8.html)
1317

1418
## Previous Versions

docs/about/roadmap/v8.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,3 @@ Finish the module shuffling.
2626
Split the Faker class into smaller units so you don't have ship an entire locale if you only generate some strings and numbers.
2727

2828
[v8.1 Tasks](https://github.com/faker-js/faker/milestone/11)
29-
30-
## v8.x - Tree-Shakeable Module-Functions
31-
32-
Refactor modules to be tree shakeable.
33-
Potentially allowing individual Faker methods to be called by themselves.
34-
35-
[v8.x Tasks](https://github.com/faker-js/faker/milestone/12)

docs/about/roadmap/v9.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## v9.0 - Tree-Shakeable Module-Functions
2+
3+
Fix the issue of Faker not being tree shakeable.
4+
Potentially allowing individual Faker methods to be called by themselves.
5+
6+
[v9.0 Tasks](https://github.com/faker-js/faker/milestone/12)

docs/guide/localization.md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,6 @@ For example, you can import the German locale:
1414
You can also build your own Faker instances, with custom locales/overwrites.
1515
:::
1616

17-
## Individual localized packages
18-
19-
Currently, the imports from the main package have a [bug](https://github.com/faker-js/faker/issues/1791) and always cause the entire Faker lib to be imported.
20-
This might result in loading around 5 MB of data into memory and slow down startup times.
21-
22-
_But we got your back!_
23-
When encountering such a problem in a test or production environment, you can use the individual localized packages.
24-
25-
```ts
26-
import { faker } from '@faker-js/faker/locale/de';
27-
```
28-
29-
This will then just load the German locales with additional English locales as fallback. The fallback is required due to not all locales containing data for all features. If you encounter a missing locale entry in your selected language, feel free to open a Pull Request fixing that issue.
30-
31-
::: info Info
32-
The English locales are around 600 KB in size.
33-
All locales together are around 5 MB in size.
34-
:::
35-
36-
::: tip Note
37-
Some locales have limited coverage and rely more heavily on the English locale as the source for features they currently do not have.
38-
However, in most cases, using a specific locale will be beneficial in the long term as specifying a locale reduces the time necessary for startup, which has a compounding effect on testing frameworks that reload the imports every execution.
39-
:::
40-
4117
## Custom locales and fallbacks
4218

4319
If our built-in faker instances don't satisfy your needs, you can build your own:
@@ -152,6 +128,11 @@ The `Locale` (data) and `Faker` columns refer to the respective `import` names:
152128
import { de, fakerDE } from '@faker-js/faker';
153129
```
154130

131+
::: tip Note
132+
Some locales have limited coverage and rely more heavily on the English locale as the source for features they currently do not have.
133+
However, in most cases, using a specific locale will be beneficial in the long term as specifying a locale reduces the time necessary for startup, which has a compounding effect on testing frameworks that reload the imports every execution.
134+
:::
135+
155136
## Locale codes
156137

157138
Locales are named in a systematic way. The first two characters are a lowercase language code following the [ISO 639-1 standard](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) for example `ar` for Arabic or `en` for English.

docs/guide/upgrading_v9/2789.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### Remove deprecated locale aliases
2+
3+
Addendum for #2787
4+
5+
Remove deprecated locale aliases
6+
7+
| old | replacement |
8+
| ------------------------------------------------------- | ----------------------------------------------------- |
9+
| `import { faker } from '@faker-js/faker/locale/global'` | `import { faker } from '@faker-js/faker/locale/base'` |

docs/guide/upgrading_v9/2790.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### Fix Tree Shaking
2+
3+
Prior to this version, users had to resort to workarounds by importing specific faker instances from dedicated paths to overcome tree shaking issues.
4+
5+
```ts
6+
import { faker } from '@faker-js/faker/locale/de';
7+
```
8+
9+
With the implementation of this fix, such workarounds should no longer be necessary.
10+
That means that you should be able to import different localized faker instances from the root of your package.
11+
12+
```ts
13+
import { fakerDE, fakerES, fakerFR } from '@faker-js/faker';
14+
```
15+
16+
The dedicated import paths will still stay for now, to allow a gradual migration for our users.
17+
18+
While the implementation of this change does not constitute as breaking according to semantic versioning guidelines, it does impact the behavior of users bundlers.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "@faker-js/faker",
33
"version": "8.4.1",
44
"description": "Generate massive amounts of fake contextual data",
5+
"sideEffects": false,
56
"keywords": [
67
"faker",
78
"faker.js",

scripts/generate-locales.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ async function normalizeLocaleFile(filePath: string, definitionKey: string) {
308308
const legacyDefinitions = ['app', 'cell_phone', 'team'];
309309
const definitionsToSkip = [
310310
'airline',
311-
'animal',
312311
'color',
313312
'commerce',
314313
'company',
@@ -375,7 +374,7 @@ removeIndexTs(locales);
375374
let localeIndexImports = '';
376375
let localeIndexExportsIndividual = '';
377376
let localeIndexExportsGrouped = '';
378-
let localesIndexExports = '';
377+
let localesIndexImports = '';
379378

380379
let localizationLocales = '| Locale | Name | Faker |\n| :--- | :--- | :--- |\n';
381380

@@ -406,7 +405,7 @@ for (const locale of locales) {
406405
localeIndexImports += `import { faker as ${localizedFaker} } from './${locale}';\n`;
407406
localeIndexExportsIndividual += ` ${localizedFaker},\n`;
408407
localeIndexExportsGrouped += ` ${locale}: ${localizedFaker},\n`;
409-
localesIndexExports += `export { default as ${locale} } from './${locale}';\n`;
408+
localesIndexImports += `import { default as ${locale} } from './${locale}';\n`;
410409
localizationLocales += `| \`${locale}\` | ${localeTitle} | \`${localizedFaker}\` |\n`;
411410

412411
// src/locale/<locale>.ts
@@ -445,7 +444,11 @@ writeFileSync(pathLocaleIndex, localeIndexContent);
445444
let localesIndexContent = `
446445
${autoGeneratedCommentHeader}
447446
448-
${localesIndexExports}
447+
${localesIndexImports}
448+
449+
export { ${locales.join(',')} };
450+
451+
export const allLocales = { ${locales.join(',')} };
449452
`;
450453

451454
localesIndexContent = await formatTypescript(localesIndexContent);

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export {
3636
export * from './locale';
3737
export { fakerEN as faker } from './locale';
3838
export * from './locales';
39-
export * as allLocales from './locales';
4039
export { Aircraft } from './modules/airline';
4140
export type { AircraftType, AirlineModule } from './modules/airline';
4241
export type { AnimalModule } from './modules/animal';

src/locale/global.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/locales/en/animal/bear.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export default [
2-
'Giant panda',
3-
'Spectacled bear',
4-
'Sun bear',
5-
'Sloth bear',
62
'American black bear',
73
'Asian black bear',
84
'Brown bear',
5+
'Giant panda',
96
'Polar bear',
7+
'Sloth bear',
8+
'Spectacled bear',
9+
'Sun bear',
1010
];

0 commit comments

Comments
 (0)