fix: handle missing or broken locales main index files #478
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While preparing #477 I encountered the issue, that I renamed the files, but did not fix the imports (as that is supposed to be done by the
generate:locales
script instead.However, the script failed to execute, because it tries to import the locale to read it's title and separator.
$ pnpm run generate:locales > @faker-js/faker@6.0.0-alpha.6 generate:locales ~/git/Faker/faker > esno ./scripts/generateLocales.ts Error: Cannot find module './bicycle' Require stack: - ~/git/Faker/faker/src/locales/en/vehicle/index.ts - ~/git/Faker/faker/src/locales/en/index.ts - ~/git/Faker/faker/scripts/generateLocales.ts at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15) at Function.Module._load (node:internal/modules/cjs/loader:778:27) at Module.require (node:internal/modules/cjs/loader:1005:19) at require (node:internal/modules/cjs/helpers:102:18) at Object.<anonymous> (~/git/Faker/faker/src/locales/en/vehicle/index.ts:6:21) at Module._compile (node:internal/modules/cjs/loader:1101:14) at Module._compile (~/git/Faker/faker/node_modules/.pnpm/esbuild-register@3.3.2_esbuild@0.14.21/node_modules/esbuild-register/dist/node.js:2258:26) at Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Object.newLoader [as .ts] (~/git/Faker/faker/node_modules/.pnpm/esbuild-register@3.3.2_esbuild@0.14.21/node_modules/esbuild-register/dist/node.js:2262:9) at Module.load (node:internal/modules/cjs/loader:981:32) { code: 'MODULE_NOT_FOUND', requireStack: [ '~/git/Faker/faker/src/locales/en/vehicle/index.ts', '~/git/Faker/faker/src/locales/en/index.ts', '~/git/Faker/faker/scripts/generateLocales.ts' ] }
This PR prevents these kind of issues, by adding two fallback layers.
With this new version it is possible to remove or invalidate all
index.ts
files fromsrc/locales
and regenerate them (without the original title though).