Skip to content

Commit

Permalink
fix(shared): Remove "sideEffects" and fix postbuild script (#1974) (#…
Browse files Browse the repository at this point in the history
…1983)

* fix(clerk-expo,shared): Bundle shared in expo

* Revert "fix(clerk-expo,shared): Bundle shared in expo"

This reverts commit c1e0279.

* fix(shared): Add files key and fix script

* chore(repo): Linting

* fix(shared): Add package.json to exports

(cherry picked from commit a68eb30)

Co-authored-by: Lennart <lekoarts@gmail.com>
  • Loading branch information
clerk-cookie and LekoArts authored Oct 31, 2023
1 parent 1a95065 commit a8d7a68
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-cameras-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/shared': patch
---

Remove `"sideEffects": "false"` since the package has side-effects
25 changes: 22 additions & 3 deletions packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -37,7 +55,8 @@
"types": "./dist/react/index.d.ts",
"default": "./dist/react/index.js"
}
}
},
"./package.json": "./package.json"
},
"scripts": {
"build": "tsup",
Expand Down
25 changes: 12 additions & 13 deletions scripts/subpath-workaround.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});

Expand Down

0 comments on commit a8d7a68

Please sign in to comment.