Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tree-shaking #2790

Merged
merged 9 commits into from
Apr 11, 2024
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@faker-js/faker",
"version": "8.4.1",
"description": "Generate massive amounts of fake contextual data",
"sideEffects": false,
"keywords": [
"faker",
"faker.js",
Expand Down
10 changes: 7 additions & 3 deletions scripts/generate-locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ removeIndexTs(locales);
let localeIndexImports = '';
let localeIndexExportsIndividual = '';
let localeIndexExportsGrouped = '';
let localesIndexExports = '';
let localesIndexImports = '';

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

Expand Down Expand Up @@ -406,7 +406,7 @@ for (const locale of locales) {
localeIndexImports += `import { faker as ${localizedFaker} } from './${locale}';\n`;
localeIndexExportsIndividual += ` ${localizedFaker},\n`;
localeIndexExportsGrouped += ` ${locale}: ${localizedFaker},\n`;
localesIndexExports += `export { default as ${locale} } from './${locale}';\n`;
localesIndexImports += `import { default as ${locale} } from './${locale}';\n`;
localizationLocales += `| \`${locale}\` | ${localeTitle} | \`${localizedFaker}\` |\n`;

// src/locale/<locale>.ts
Expand Down Expand Up @@ -445,7 +445,11 @@ writeFileSync(pathLocaleIndex, localeIndexContent);
let localesIndexContent = `
${autoGeneratedCommentHeader}

${localesIndexExports}
${localesIndexImports}

export { ${locales.join(',')} };

export const allLocales = { ${locales.join(',')} };
`;

localesIndexContent = await formatTypescript(localesIndexContent);
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export {
export * from './locale';
export { fakerEN as faker } from './locale';
export * from './locales';
export * as allLocales from './locales';
export { Aircraft } from './modules/airline';
export type { AircraftType, AirlineModule } from './modules/airline';
export type { AnimalModule } from './modules/animal';
Expand Down
282 changes: 213 additions & 69 deletions src/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,72 +3,216 @@
* Run 'pnpm run generate:locales' to update.
*/

export { default as af_ZA } from './af_ZA';
export { default as ar } from './ar';
export { default as az } from './az';
export { default as base } from './base';
export { default as cs_CZ } from './cs_CZ';
export { default as da } from './da';
export { default as de } from './de';
export { default as de_AT } from './de_AT';
export { default as de_CH } from './de_CH';
export { default as dv } from './dv';
export { default as el } from './el';
export { default as en } from './en';
export { default as en_AU } from './en_AU';
export { default as en_AU_ocker } from './en_AU_ocker';
export { default as en_BORK } from './en_BORK';
export { default as en_CA } from './en_CA';
export { default as en_GB } from './en_GB';
export { default as en_GH } from './en_GH';
export { default as en_HK } from './en_HK';
export { default as en_IE } from './en_IE';
export { default as en_IN } from './en_IN';
export { default as en_NG } from './en_NG';
export { default as en_US } from './en_US';
export { default as en_ZA } from './en_ZA';
export { default as eo } from './eo';
export { default as es } from './es';
export { default as es_MX } from './es_MX';
export { default as fa } from './fa';
export { default as fi } from './fi';
export { default as fr } from './fr';
export { default as fr_BE } from './fr_BE';
export { default as fr_CA } from './fr_CA';
export { default as fr_CH } from './fr_CH';
export { default as fr_LU } from './fr_LU';
export { default as fr_SN } from './fr_SN';
export { default as he } from './he';
export { default as hr } from './hr';
export { default as hu } from './hu';
export { default as hy } from './hy';
export { default as id_ID } from './id_ID';
export { default as it } from './it';
export { default as ja } from './ja';
export { default as ka_GE } from './ka_GE';
export { default as ko } from './ko';
export { default as lv } from './lv';
export { default as mk } from './mk';
export { default as nb_NO } from './nb_NO';
export { default as ne } from './ne';
export { default as nl } from './nl';
export { default as nl_BE } from './nl_BE';
export { default as pl } from './pl';
export { default as pt_BR } from './pt_BR';
export { default as pt_PT } from './pt_PT';
export { default as ro } from './ro';
export { default as ro_MD } from './ro_MD';
export { default as ru } from './ru';
export { default as sk } from './sk';
export { default as sr_RS_latin } from './sr_RS_latin';
export { default as sv } from './sv';
export { default as th } from './th';
export { default as tr } from './tr';
export { default as uk } from './uk';
export { default as ur } from './ur';
export { default as uz_UZ_latin } from './uz_UZ_latin';
export { default as vi } from './vi';
export { default as yo_NG } from './yo_NG';
export { default as zh_CN } from './zh_CN';
export { default as zh_TW } from './zh_TW';
export { default as zu_ZA } from './zu_ZA';
import { default as af_ZA } from './af_ZA';
import { default as ar } from './ar';
import { default as az } from './az';
import { default as base } from './base';
import { default as cs_CZ } from './cs_CZ';
import { default as da } from './da';
import { default as de } from './de';
import { default as de_AT } from './de_AT';
import { default as de_CH } from './de_CH';
import { default as dv } from './dv';
import { default as el } from './el';
import { default as en } from './en';
import { default as en_AU } from './en_AU';
import { default as en_AU_ocker } from './en_AU_ocker';
import { default as en_BORK } from './en_BORK';
import { default as en_CA } from './en_CA';
import { default as en_GB } from './en_GB';
import { default as en_GH } from './en_GH';
import { default as en_HK } from './en_HK';
import { default as en_IE } from './en_IE';
import { default as en_IN } from './en_IN';
import { default as en_NG } from './en_NG';
import { default as en_US } from './en_US';
import { default as en_ZA } from './en_ZA';
import { default as eo } from './eo';
import { default as es } from './es';
import { default as es_MX } from './es_MX';
import { default as fa } from './fa';
import { default as fi } from './fi';
import { default as fr } from './fr';
import { default as fr_BE } from './fr_BE';
import { default as fr_CA } from './fr_CA';
import { default as fr_CH } from './fr_CH';
import { default as fr_LU } from './fr_LU';
import { default as fr_SN } from './fr_SN';
import { default as he } from './he';
import { default as hr } from './hr';
import { default as hu } from './hu';
import { default as hy } from './hy';
import { default as id_ID } from './id_ID';
import { default as it } from './it';
import { default as ja } from './ja';
import { default as ka_GE } from './ka_GE';
import { default as ko } from './ko';
import { default as lv } from './lv';
import { default as mk } from './mk';
import { default as nb_NO } from './nb_NO';
import { default as ne } from './ne';
import { default as nl } from './nl';
import { default as nl_BE } from './nl_BE';
import { default as pl } from './pl';
import { default as pt_BR } from './pt_BR';
import { default as pt_PT } from './pt_PT';
import { default as ro } from './ro';
import { default as ro_MD } from './ro_MD';
import { default as ru } from './ru';
import { default as sk } from './sk';
import { default as sr_RS_latin } from './sr_RS_latin';
import { default as sv } from './sv';
import { default as th } from './th';
import { default as tr } from './tr';
import { default as uk } from './uk';
import { default as ur } from './ur';
import { default as uz_UZ_latin } from './uz_UZ_latin';
import { default as vi } from './vi';
import { default as yo_NG } from './yo_NG';
import { default as zh_CN } from './zh_CN';
import { default as zh_TW } from './zh_TW';
import { default as zu_ZA } from './zu_ZA';

export {
af_ZA,
ar,
az,
base,
cs_CZ,
da,
de,
de_AT,
de_CH,
dv,
el,
en,
en_AU,
en_AU_ocker,
en_BORK,
en_CA,
en_GB,
en_GH,
en_HK,
en_IE,
en_IN,
en_NG,
en_US,
en_ZA,
eo,
es,
es_MX,
fa,
fi,
fr,
fr_BE,
fr_CA,
fr_CH,
fr_LU,
fr_SN,
he,
hr,
hu,
hy,
id_ID,
it,
ja,
ka_GE,
ko,
lv,
mk,
nb_NO,
ne,
nl,
nl_BE,
pl,
pt_BR,
pt_PT,
ro,
ro_MD,
ru,
sk,
sr_RS_latin,
sv,
th,
tr,
uk,
ur,
uz_UZ_latin,
vi,
yo_NG,
zh_CN,
zh_TW,
zu_ZA,
};

export const allLocales = {
af_ZA,
ar,
az,
base,
cs_CZ,
da,
de,
de_AT,
de_CH,
dv,
el,
en,
en_AU,
en_AU_ocker,
en_BORK,
en_CA,
en_GB,
en_GH,
en_HK,
en_IE,
en_IN,
en_NG,
en_US,
en_ZA,
eo,
es,
es_MX,
fa,
fi,
fr,
fr_BE,
fr_CA,
fr_CH,
fr_LU,
fr_SN,
he,
hr,
hu,
hy,
id_ID,
it,
ja,
ka_GE,
ko,
lv,
mk,
nb_NO,
ne,
nl,
nl_BE,
pl,
pt_BR,
pt_PT,
ro,
ro_MD,
ru,
sk,
sr_RS_latin,
sv,
th,
tr,
uk,
ur,
uz_UZ_latin,
vi,
yo_NG,
zh_CN,
zh_TW,
zu_ZA,
};