From c1e02797f2c3892a50f5158dd92aabc01f848838 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 30 Oct 2023 15:14:26 +0100 Subject: [PATCH 1/5] fix(clerk-expo,shared): Bundle shared in expo --- .changeset/bright-pugs-leave.md | 5 +++++ .changeset/fair-cameras-boil.md | 5 +++++ packages/expo/package.json | 2 +- packages/expo/tsup.config.ts | 2 +- packages/shared/package.json | 2 -- packages/shared/subpaths.mjs | 25 ------------------------- 6 files changed, 12 insertions(+), 29 deletions(-) create mode 100644 .changeset/bright-pugs-leave.md create mode 100644 .changeset/fair-cameras-boil.md delete mode 100644 packages/shared/subpaths.mjs diff --git a/.changeset/bright-pugs-leave.md b/.changeset/bright-pugs-leave.md new file mode 100644 index 00000000000..e2a4b5388ae --- /dev/null +++ b/.changeset/bright-pugs-leave.md @@ -0,0 +1,5 @@ +--- +'@clerk/clerk-expo': patch +--- + +Bundle `@clerk/shared/deprecated` into the package to workaround package export map issues diff --git a/.changeset/fair-cameras-boil.md b/.changeset/fair-cameras-boil.md new file mode 100644 index 00000000000..b99365b9f49 --- /dev/null +++ b/.changeset/fair-cameras-boil.md @@ -0,0 +1,5 @@ +--- +'@clerk/shared': patch +--- + +Remove `"sideEffects": "false"` since the package has side-effects diff --git a/packages/expo/package.json b/packages/expo/package.json index 1ea8cc5d00a..894eb06a046 100644 --- a/packages/expo/package.json +++ b/packages/expo/package.json @@ -32,11 +32,11 @@ "dependencies": { "@clerk/clerk-js": "4.63.0", "@clerk/clerk-react": "4.27.0", - "@clerk/shared": "1.0.0", "base-64": "1.0.0", "react-native-url-polyfill": "2.0.0" }, "devDependencies": { + "@clerk/shared": "1.0.0", "@clerk/types": "^3.57.0", "@types/base-64": "^1.0.0", "@types/node": "^16.11.55", diff --git a/packages/expo/tsup.config.ts b/packages/expo/tsup.config.ts index 7dae145a8a0..050ef3647af 100644 --- a/packages/expo/tsup.config.ts +++ b/packages/expo/tsup.config.ts @@ -13,7 +13,7 @@ export default defineConfig(overrideOptions => { format: 'cjs', outDir: './dist', entry: ['./src/**/*.{ts,tsx,js,jsx}'], - bundle: false, + bundle: true, clean: true, minify: false, sourcemap: true, diff --git a/packages/shared/package.json b/packages/shared/package.json index ce76bcf815f..2d1e6a94ae1 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -2,7 +2,6 @@ "name": "@clerk/shared", "version": "1.0.0", "description": "Internal package utils used by the Clerk SDKs", - "sideEffects": false, "files": [ "dist" ], @@ -44,7 +43,6 @@ "dev": "tsup --watch", "dev:publish": "npm run dev -- --env.publish", "publish:local": "npx yalc push --replace --sig", - "postbuild": "node ../../scripts/subpath-workaround.mjs shared", "clean": "rimraf ./dist", "lint": "eslint src/", "lint:publint": "publint", diff --git a/packages/shared/subpaths.mjs b/packages/shared/subpaths.mjs deleted file mode 100644 index 6a1c22d8ec1..00000000000 --- a/packages/shared/subpaths.mjs +++ /dev/null @@ -1,25 +0,0 @@ -// This file is a helper for the "subpath-workaround.mjs" script -// We have to polyfill our "exports" subpaths :cry: - -export const subpathNames = [ - 'browser', - 'callWithRetry', - 'color', - 'cookie', - 'date', - 'deprecated', - 'error', - 'file', - 'globs', - 'handleValueOrFn', - 'isomorphicAtob', - 'keys', - 'loadScript', - 'localStorageBroadcastChannel', - 'poller', - 'proxy', - 'underscore', - 'url', -]; - -export const subpathFoldersBarrel = ['react']; From 140fc81cb56f5a7f6e86a1c14b2bca68a533cec2 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 30 Oct 2023 15:28:18 +0100 Subject: [PATCH 2/5] Revert "fix(clerk-expo,shared): Bundle shared in expo" This reverts commit c1e02797f2c3892a50f5158dd92aabc01f848838. --- .changeset/bright-pugs-leave.md | 5 ----- .changeset/fair-cameras-boil.md | 5 ----- packages/expo/package.json | 2 +- packages/expo/tsup.config.ts | 2 +- packages/shared/package.json | 2 ++ packages/shared/subpaths.mjs | 25 +++++++++++++++++++++++++ 6 files changed, 29 insertions(+), 12 deletions(-) delete mode 100644 .changeset/bright-pugs-leave.md delete mode 100644 .changeset/fair-cameras-boil.md create mode 100644 packages/shared/subpaths.mjs diff --git a/.changeset/bright-pugs-leave.md b/.changeset/bright-pugs-leave.md deleted file mode 100644 index e2a4b5388ae..00000000000 --- a/.changeset/bright-pugs-leave.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@clerk/clerk-expo': patch ---- - -Bundle `@clerk/shared/deprecated` into the package to workaround package export map issues diff --git a/.changeset/fair-cameras-boil.md b/.changeset/fair-cameras-boil.md deleted file mode 100644 index b99365b9f49..00000000000 --- a/.changeset/fair-cameras-boil.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@clerk/shared': patch ---- - -Remove `"sideEffects": "false"` since the package has side-effects diff --git a/packages/expo/package.json b/packages/expo/package.json index 894eb06a046..1ea8cc5d00a 100644 --- a/packages/expo/package.json +++ b/packages/expo/package.json @@ -32,11 +32,11 @@ "dependencies": { "@clerk/clerk-js": "4.63.0", "@clerk/clerk-react": "4.27.0", + "@clerk/shared": "1.0.0", "base-64": "1.0.0", "react-native-url-polyfill": "2.0.0" }, "devDependencies": { - "@clerk/shared": "1.0.0", "@clerk/types": "^3.57.0", "@types/base-64": "^1.0.0", "@types/node": "^16.11.55", diff --git a/packages/expo/tsup.config.ts b/packages/expo/tsup.config.ts index 050ef3647af..7dae145a8a0 100644 --- a/packages/expo/tsup.config.ts +++ b/packages/expo/tsup.config.ts @@ -13,7 +13,7 @@ export default defineConfig(overrideOptions => { format: 'cjs', outDir: './dist', entry: ['./src/**/*.{ts,tsx,js,jsx}'], - bundle: true, + bundle: false, clean: true, minify: false, sourcemap: true, diff --git a/packages/shared/package.json b/packages/shared/package.json index 2d1e6a94ae1..ce76bcf815f 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -2,6 +2,7 @@ "name": "@clerk/shared", "version": "1.0.0", "description": "Internal package utils used by the Clerk SDKs", + "sideEffects": false, "files": [ "dist" ], @@ -43,6 +44,7 @@ "dev": "tsup --watch", "dev:publish": "npm run dev -- --env.publish", "publish:local": "npx yalc push --replace --sig", + "postbuild": "node ../../scripts/subpath-workaround.mjs shared", "clean": "rimraf ./dist", "lint": "eslint src/", "lint:publint": "publint", diff --git a/packages/shared/subpaths.mjs b/packages/shared/subpaths.mjs new file mode 100644 index 00000000000..6a1c22d8ec1 --- /dev/null +++ b/packages/shared/subpaths.mjs @@ -0,0 +1,25 @@ +// This file is a helper for the "subpath-workaround.mjs" script +// We have to polyfill our "exports" subpaths :cry: + +export const subpathNames = [ + 'browser', + 'callWithRetry', + 'color', + 'cookie', + 'date', + 'deprecated', + 'error', + 'file', + 'globs', + 'handleValueOrFn', + 'isomorphicAtob', + 'keys', + 'loadScript', + 'localStorageBroadcastChannel', + 'poller', + 'proxy', + 'underscore', + 'url', +]; + +export const subpathFoldersBarrel = ['react']; From 3629b5dcc497bce712a5fe2cb9e14db0a53e918d Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 30 Oct 2023 15:39:21 +0100 Subject: [PATCH 3/5] fix(shared): Add files key and fix script --- .changeset/fair-cameras-boil.md | 5 +++++ packages/shared/package.json | 22 ++++++++++++++++++++-- scripts/subpath-workaround.mjs | 25 ++++++++++++------------- 3 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 .changeset/fair-cameras-boil.md diff --git a/.changeset/fair-cameras-boil.md b/.changeset/fair-cameras-boil.md new file mode 100644 index 00000000000..23fa2a1286d --- /dev/null +++ b/.changeset/fair-cameras-boil.md @@ -0,0 +1,5 @@ +--- +'@clerk/shared': patch +--- + +Remove `"sideEffects": "false"` since the package has side-effects \ No newline at end of file diff --git a/packages/shared/package.json b/packages/shared/package.json index ce76bcf815f..4e47dec8bb7 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -2,9 +2,27 @@ "name": "@clerk/shared", "version": "1.0.0", "description": "Internal package utils used by the Clerk SDKs", - "sideEffects": false, "files": [ - "dist" + "dist", + "browser", + "callWithRetry", + "color", + "cookie", + "date", + "deprecated", + "error", + "file", + "globs", + "handleValueOrFn", + "isomorphicAtob", + "keys", + "loadScript", + "localStorageBroadcastChannel", + "poller", + "proxy", + "underscore", + "url", + "react" ], "main": "./dist/index.js", "exports": { diff --git a/scripts/subpath-workaround.mjs b/scripts/subpath-workaround.mjs index 8c3c507256a..bdf98aeb948 100644 --- a/scripts/subpath-workaround.mjs +++ b/scripts/subpath-workaround.mjs @@ -25,29 +25,28 @@ async function run() { `Found ${subpathHelperFile.subpathNames.length} subpaths and ${subpathHelperFile.subpathFoldersBarrel.length} subpath barrels`, ); - // Check if pkgFile.files already contains the subpaths. This means that the script has already been run and we should exit early - const subpathsAlreadyAdded = subpathHelperFile.subpathNames.some(name => pkgFile.files.includes(name)); + const allFilesNames = [...subpathHelperFile.subpathNames, ...subpathHelperFile.subpathFoldersBarrel, 'dist'] + const hasAllSubpathsInFiles = pkgFile.files.every(name => allFilesNames.includes(name)); - if (subpathsAlreadyAdded) { - return console.log(`Subpaths already added to ${pkgName} package.json. Exiting early`); + if (!hasAllSubpathsInFiles) { + throw new Error('Not all subpaths from the package.json "files" array are in the subpaths.mjs') } - // Add all subpaths to the "files" property on package.json - pkgFile.files = [...pkgFile.files, ...subpathHelperFile.subpathNames, ...subpathHelperFile.subpathFoldersBarrel]; - - writeJSON(`../packages/${pkgName}/package.json`, pkgFile); - - console.log(`Overwrote package.json for ${pkgName} with subpaths`); - // Create directories for each subpath name using the pkgJsonPlaceholder subpathHelperFile.subpathNames.forEach(name => { - fs.mkdirSync(new URL(`../packages/${pkgName}/${name}`, import.meta.url)); + const dir = new URL(`../packages/${pkgName}/${name}`, import.meta.url) + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } writeJSON(`../packages/${pkgName}/${name}/package.json`, pkgJsonPlaceholder(name)); }); // Create directories for each subpath barrel file using the pkgJsonBarrelPlaceholder subpathHelperFile.subpathFoldersBarrel.forEach(name => { - fs.mkdirSync(new URL(`../packages/${pkgName}/${name}`, import.meta.url)); + const dir = new URL(`../packages/${pkgName}/${name}`, import.meta.url) + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir); + } writeJSON(`../packages/${pkgName}/${name}/package.json`, pkgJsonBarrelPlaceholder(name)); }); From e938dd0cd4bf875094edcfbbad5475b1399b5bdd Mon Sep 17 00:00:00 2001 From: LekoArts Date: Mon, 30 Oct 2023 15:43:36 +0100 Subject: [PATCH 4/5] chore(repo): Linting --- scripts/subpath-workaround.mjs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/subpath-workaround.mjs b/scripts/subpath-workaround.mjs index bdf98aeb948..790e2805ca3 100644 --- a/scripts/subpath-workaround.mjs +++ b/scripts/subpath-workaround.mjs @@ -25,16 +25,16 @@ async function run() { `Found ${subpathHelperFile.subpathNames.length} subpaths and ${subpathHelperFile.subpathFoldersBarrel.length} subpath barrels`, ); - const allFilesNames = [...subpathHelperFile.subpathNames, ...subpathHelperFile.subpathFoldersBarrel, 'dist'] + const allFilesNames = [...subpathHelperFile.subpathNames, ...subpathHelperFile.subpathFoldersBarrel, 'dist']; const hasAllSubpathsInFiles = pkgFile.files.every(name => allFilesNames.includes(name)); if (!hasAllSubpathsInFiles) { - throw new Error('Not all subpaths from the package.json "files" array are in the subpaths.mjs') + throw new Error('Not all subpaths from the package.json "files" array are in the subpaths.mjs'); } // Create directories for each subpath name using the pkgJsonPlaceholder subpathHelperFile.subpathNames.forEach(name => { - const dir = new URL(`../packages/${pkgName}/${name}`, import.meta.url) + const dir = new URL(`../packages/${pkgName}/${name}`, import.meta.url); if (!fs.existsSync(dir)) { fs.mkdirSync(dir); } @@ -43,7 +43,7 @@ async function run() { // Create directories for each subpath barrel file using the pkgJsonBarrelPlaceholder subpathHelperFile.subpathFoldersBarrel.forEach(name => { - const dir = new URL(`../packages/${pkgName}/${name}`, import.meta.url) + const dir = new URL(`../packages/${pkgName}/${name}`, import.meta.url); if (!fs.existsSync(dir)) { fs.mkdirSync(dir); } From 81a51e7c02e0f1163132cc7c44ed9e6025fe918d Mon Sep 17 00:00:00 2001 From: LekoArts Date: Tue, 31 Oct 2023 07:36:49 +0100 Subject: [PATCH 5/5] fix(shared): Add package.json to exports --- packages/shared/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/shared/package.json b/packages/shared/package.json index 4e47dec8bb7..317bb725315 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -55,7 +55,8 @@ "types": "./dist/react/index.d.ts", "default": "./dist/react/index.js" } - } + }, + "./package.json": "./package.json" }, "scripts": { "build": "tsup",