Skip to content

Commit

Permalink
feat(localizations): Allow usage of subpath exports
Browse files Browse the repository at this point in the history
The addition of `.gitignore` and `subpaths.mjs` is used to support
Expo framework. This fix is also used in `@clerk/shared` package.

original PR: #2046

Co-authored-by: Andrew <[email protected]>
  • Loading branch information
dimkl and MonsterDeveloper committed Nov 29, 2023
1 parent d48d1aa commit 5e8714c
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 10 deletions.
14 changes: 14 additions & 0 deletions .changeset/selfish-trains-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@clerk/localizations': patch
---

The package now allows for [subpath exports](https://nodejs.org/api/packages.html#subpath-exports).

```diff
- import { frFR } from "@clerk/localizations"
+ import { frFR } from "@clerk/localizations/fr-FR"
```

This should help with tree-shaking by helping the bundler to include only specific localization.

This is a non-breaking change-previous imports from "@clerk/localizations" are still working as expected.
2 changes: 2 additions & 0 deletions packages/localizations/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*/
!/src/
53 changes: 51 additions & 2 deletions packages/localizations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,63 @@
"license": "MIT",
"author": "Clerk",
"sideEffects": false,
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
},
"./*": {
"import": {
"types": "./dist/*.d.mts",
"default": "./dist/*.mjs"
},
"require": {
"types": "./dist/*.d.ts",
"default": "./dist/*.js"
}
},
"./package.json": "./package.json"
},
"main": "./dist/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
"dist",
"ar-SA",
"cs-CZ",
"da-DK",
"de-DE",
"el-GR",
"en-US",
"es-ES",
"fr-FR",
"he-IL",
"it-IT",
"ja-JP",
"ko-KR",
"nb-NO",
"nl-NL",
"pl-PL",
"pt-BR",
"pt-PT",
"ro-RO",
"ru-RU",
"sk-SK",
"sv-SE",
"tr-TR",
"uk-UA",
"vi-VN",
"zh-CN",
"zh-TW"
],
"scripts": {
"build": "tsup --env.NODE_ENV production",
"postbuild": "node ../../scripts/subpath-workaround.mjs localizations",
"clean": "rimraf ./dist",
"dev": "tsup --watch",
"lint": "eslint src/"
Expand Down
35 changes: 35 additions & 0 deletions packages/localizations/subpaths.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// This file is a helper for the "subpath-workaround.mjs" script
// We have to polyfill our "exports" subpaths :cry:

export const subpathNames = [
'ar-SA',
'cs-CZ',
'da-DK',
'de-DE',
'el-GR',
'en-US',
'es-ES',
'fr-FR',
'he-IL',
'it-IT',
'ja-JP',
'ko-KR',
'nb-NO',
'nl-NL',
'pl-PL',
'pt-BR',
'pt-PT',
'ro-RO',
'ru-RU',
'sk-SK',
'sv-SE',
'tr-TR',
'uk-UA',
'vi-VN',
'zh-CN',
'zh-TW',
];

export const subpathFoldersBarrel = [];

export const ignoredFolders = [];
15 changes: 8 additions & 7 deletions packages/localizations/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { defineConfig } from 'tsup';

export default defineConfig(() => {
export default defineConfig(_overrideOptions => {
const uiRetheme = process.env.CLERK_RETHEME === '1' || process.env.CLERK_RETHEME === 'true';

return {
entry: {
index: uiRetheme ? 'src/index.retheme.ts' : 'src/index.ts',
},
minify: false,
entry: uiRetheme
? ['src', '!src/index.ts', '!src/en-US.ts']
: ['src', '!src/index.retheme.ts', '!src/en-US.retheme.ts'],
format: ['cjs', 'esm'],
bundle: true,
clean: true,
minify: false,
sourcemap: true,
format: ['cjs', 'esm'],
legacyOutput: true,
dts: true,
splitting: false,
};
});
2 changes: 2 additions & 0 deletions packages/shared/subpaths.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ export const subpathNames = [
];

export const subpathFoldersBarrel = ['react'];

export const ignoredFolders = ['scripts'];
2 changes: 1 addition & 1 deletion scripts/subpath-workaround.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ async function run() {
const allFilesNames = [
...subpathHelperFile.subpathNames,
...subpathHelperFile.subpathFoldersBarrel,
...subpathHelperFile.ignoredFolders,
'dist',
'scripts',
];
const hasAllSubpathsInFiles = pkgFile.files.every(name => allFilesNames.includes(name));

Expand Down

0 comments on commit 5e8714c

Please sign in to comment.