From 0a865f21f7b8ecfbf811fe3ab9aeb0844ee23b80 Mon Sep 17 00:00:00 2001 From: Lennart Date: Tue, 31 Oct 2023 07:49:53 +0100 Subject: [PATCH] fix(shared): Remove "sideEffects" and fix postbuild script (#1974) * fix(clerk-expo,shared): Bundle shared in expo * Revert "fix(clerk-expo,shared): Bundle shared in expo" This reverts commit c1e02797f2c3892a50f5158dd92aabc01f848838. * fix(shared): Add files key and fix script * chore(repo): Linting * fix(shared): Add package.json to exports (cherry picked from commit a68eb3083ff68459cd33098e2df190a5ba26c841) --- .changeset/fair-cameras-boil.md | 5 +++++ packages/shared/package.json | 25 ++++++++++++++++++++++--- scripts/subpath-workaround.mjs | 25 ++++++++++++------------- 3 files changed, 39 insertions(+), 16 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 eea3ba840a8..366fa071f82 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -2,9 +2,27 @@ "name": "@clerk/shared", "version": "1.0.1", "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": { @@ -37,7 +55,8 @@ "types": "./dist/react/index.d.ts", "default": "./dist/react/index.js" } - } + }, + "./package.json": "./package.json" }, "scripts": { "build": "tsup", diff --git a/scripts/subpath-workaround.mjs b/scripts/subpath-workaround.mjs index 8c3c507256a..790e2805ca3 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)); });