From 1931e24a04cdad7713cef317bdd0b510e0dd418b Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 26 Oct 2023 12:50:25 -0700 Subject: [PATCH 1/8] fix(shared): Remove "module" from package.json --- packages/shared/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/shared/package.json b/packages/shared/package.json index 11a2a911c85..37403836305 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -7,7 +7,6 @@ "dist" ], "main": "./dist/index.js", - "module": "./dist/index.mjs", "exports": { ".": { "import": { From c42797600f6630245ccb344f4c698903505407b9 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 26 Oct 2023 13:17:45 -0700 Subject: [PATCH 2/8] chore(repo): Add subpath workaround script --- scripts/subpath-workaround.mjs | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/subpath-workaround.mjs diff --git a/scripts/subpath-workaround.mjs b/scripts/subpath-workaround.mjs new file mode 100644 index 00000000000..c2287258743 --- /dev/null +++ b/scripts/subpath-workaround.mjs @@ -0,0 +1,40 @@ +#!/usr/bin/env zx + +import 'zx/globals'; + +import fs from 'fs'; + +const loadJSON = (path) => JSON.parse(fs.readFileSync(new URL(path, import.meta.url))); +const writeJSON = (path, contents) => fs.writeFileSync(new URL(path, import.meta.url), JSON.stringify(contents, null, 2)); + +const pkgName = argv._[0] +console.log(`Loading package.json for ${pkgName}`) +const pkgFile = loadJSON(`../packages/${pkgName}/package.json`) +const subpathHelperFile = await import(`../packages/${pkgName}/subpaths.mjs`) + +const pkgJsonPlaceholder = (name) => ({ + main: `../dist/${name}.js` +}) +const pkgJsonBarrelPlaceholder = (name) => ({ + main: `../dist/${name}/index.js` +}) + +// Add all subpaths to the "files" property on package.json + +pkgFile.files = [...pkgFile.files, ...subpathHelperFile.subpathNames, ...subpathHelperFile.subpathFoldersBarrel] + +console.log(`Found ${subpathHelperFile.subpathNames.length} subpaths and ${subpathHelperFile.subpathFoldersBarrel.length} subpath barrels`) + +// Create directories for each subpath name using the pkgJsonPlaceholder +subpathHelperFile.subpathNames.forEach((name) => { + fs.mkdirSync(new URL(`../packages/${pkgName}/${name}`, import.meta.url)) + 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)) + writeJSON(`../packages/${pkgName}/${name}/package.json`, pkgJsonBarrelPlaceholder(name)) +}) + +console.log('Successfully created subpath directories and package.json file override') \ No newline at end of file From efefbff8c727dce27e4c4d25f45fd230ae64cbc7 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 26 Oct 2023 13:17:56 -0700 Subject: [PATCH 3/8] chore(shared): Add script to shared --- packages/shared/.gitignore | 19 +++++++++++++++++++ packages/shared/package.json | 1 + packages/shared/subpaths.mjs | 27 +++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 packages/shared/.gitignore create mode 100644 packages/shared/subpaths.mjs diff --git a/packages/shared/.gitignore b/packages/shared/.gitignore new file mode 100644 index 00000000000..45af1b0ba8a --- /dev/null +++ b/packages/shared/.gitignore @@ -0,0 +1,19 @@ +browser +callWithRetry +color +cookie +date +deprecated +error +file +globs +handleValueOrFn +isomorphicAtob +keys +loadScript +localStorageBroadcastChannel +poller +proxy +underscore +url +react \ No newline at end of file diff --git a/packages/shared/package.json b/packages/shared/package.json index 37403836305..72df1b66f5b 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -44,6 +44,7 @@ "dev": "tsup --watch", "dev:publish": "npm run dev -- --env.publish", "publish:local": "npx yalc push --replace --sig", + "prepublishOnly": "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..e49cb50976b --- /dev/null +++ b/packages/shared/subpaths.mjs @@ -0,0 +1,27 @@ +// 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' +] \ No newline at end of file From ccbedab3df10bd582aa8e54082eca27fb7d3a2f2 Mon Sep 17 00:00:00 2001 From: Lennart Date: Thu, 26 Oct 2023 13:36:40 -0700 Subject: [PATCH 4/8] Create wise-houses-shop.md --- .changeset/wise-houses-shop.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/wise-houses-shop.md diff --git a/.changeset/wise-houses-shop.md b/.changeset/wise-houses-shop.md new file mode 100644 index 00000000000..29508244603 --- /dev/null +++ b/.changeset/wise-houses-shop.md @@ -0,0 +1,5 @@ +--- +"@clerk/shared": patch +--- + +TODO From da6ed2dd317f347e9c9f95ffe2a455c1c40b72f3 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 26 Oct 2023 13:48:45 -0700 Subject: [PATCH 5/8] chore(*): Fix stuff --- packages/shared/package.json | 2 +- packages/shared/subpaths.mjs | 6 ++-- scripts/subpath-workaround.mjs | 53 ++++++++++++++++++---------------- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/packages/shared/package.json b/packages/shared/package.json index 72df1b66f5b..ce76bcf815f 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -44,7 +44,7 @@ "dev": "tsup --watch", "dev:publish": "npm run dev -- --env.publish", "publish:local": "npx yalc push --replace --sig", - "prepublishOnly": "node ../../scripts/subpath-workaround.mjs shared", + "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 index e49cb50976b..6a1c22d8ec1 100644 --- a/packages/shared/subpaths.mjs +++ b/packages/shared/subpaths.mjs @@ -20,8 +20,6 @@ export const subpathNames = [ 'proxy', 'underscore', 'url', -] +]; -export const subpathFoldersBarrel = [ - 'react' -] \ No newline at end of file +export const subpathFoldersBarrel = ['react']; diff --git a/scripts/subpath-workaround.mjs b/scripts/subpath-workaround.mjs index c2287258743..3511c018e69 100644 --- a/scripts/subpath-workaround.mjs +++ b/scripts/subpath-workaround.mjs @@ -4,37 +4,40 @@ import 'zx/globals'; import fs from 'fs'; -const loadJSON = (path) => JSON.parse(fs.readFileSync(new URL(path, import.meta.url))); -const writeJSON = (path, contents) => fs.writeFileSync(new URL(path, import.meta.url), JSON.stringify(contents, null, 2)); - -const pkgName = argv._[0] -console.log(`Loading package.json for ${pkgName}`) -const pkgFile = loadJSON(`../packages/${pkgName}/package.json`) -const subpathHelperFile = await import(`../packages/${pkgName}/subpaths.mjs`) - -const pkgJsonPlaceholder = (name) => ({ - main: `../dist/${name}.js` -}) -const pkgJsonBarrelPlaceholder = (name) => ({ - main: `../dist/${name}/index.js` -}) +const loadJSON = path => JSON.parse(fs.readFileSync(new URL(path, import.meta.url))); +const writeJSON = (path, contents) => + fs.writeFileSync(new URL(path, import.meta.url), JSON.stringify(contents, null, 2)); + +const pkgName = argv._[0]; +console.log(`Loading package.json for ${pkgName}`); +const pkgFile = loadJSON(`../packages/${pkgName}/package.json`); +const subpathHelperFile = await import(`../packages/${pkgName}/subpaths.mjs`); + +const pkgJsonPlaceholder = name => ({ + main: `../dist/${name}.js`, +}); +const pkgJsonBarrelPlaceholder = name => ({ + main: `../dist/${name}/index.js`, +}); // Add all subpaths to the "files" property on package.json -pkgFile.files = [...pkgFile.files, ...subpathHelperFile.subpathNames, ...subpathHelperFile.subpathFoldersBarrel] +pkgFile.files = [...pkgFile.files, ...subpathHelperFile.subpathNames, ...subpathHelperFile.subpathFoldersBarrel]; -console.log(`Found ${subpathHelperFile.subpathNames.length} subpaths and ${subpathHelperFile.subpathFoldersBarrel.length} subpath barrels`) +console.log( + `Found ${subpathHelperFile.subpathNames.length} subpaths and ${subpathHelperFile.subpathFoldersBarrel.length} subpath barrels`, +); // Create directories for each subpath name using the pkgJsonPlaceholder -subpathHelperFile.subpathNames.forEach((name) => { - fs.mkdirSync(new URL(`../packages/${pkgName}/${name}`, import.meta.url)) - writeJSON(`../packages/${pkgName}/${name}/package.json`, pkgJsonPlaceholder(name)) -}) +subpathHelperFile.subpathNames.forEach(name => { + fs.mkdirSync(new URL(`../packages/${pkgName}/${name}`, import.meta.url)); + 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)) - writeJSON(`../packages/${pkgName}/${name}/package.json`, pkgJsonBarrelPlaceholder(name)) -}) +subpathHelperFile.subpathFoldersBarrel.forEach(name => { + fs.mkdirSync(new URL(`../packages/${pkgName}/${name}`, import.meta.url)); + writeJSON(`../packages/${pkgName}/${name}/package.json`, pkgJsonBarrelPlaceholder(name)); +}); -console.log('Successfully created subpath directories and package.json file override') \ No newline at end of file +console.log('Successfully created subpath directories and package.json file override'); From d7e7883c5f4ad4f0908a87b1e3c7e82f07669cb5 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 26 Oct 2023 14:17:53 -0700 Subject: [PATCH 6/8] chore(repo): Improve script --- scripts/subpath-workaround.mjs | 67 +++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/scripts/subpath-workaround.mjs b/scripts/subpath-workaround.mjs index 3511c018e69..943b8632d76 100644 --- a/scripts/subpath-workaround.mjs +++ b/scripts/subpath-workaround.mjs @@ -8,11 +8,6 @@ const loadJSON = path => JSON.parse(fs.readFileSync(new URL(path, import.meta.ur const writeJSON = (path, contents) => fs.writeFileSync(new URL(path, import.meta.url), JSON.stringify(contents, null, 2)); -const pkgName = argv._[0]; -console.log(`Loading package.json for ${pkgName}`); -const pkgFile = loadJSON(`../packages/${pkgName}/package.json`); -const subpathHelperFile = await import(`../packages/${pkgName}/subpaths.mjs`); - const pkgJsonPlaceholder = name => ({ main: `../dist/${name}.js`, }); @@ -20,24 +15,44 @@ const pkgJsonBarrelPlaceholder = name => ({ main: `../dist/${name}/index.js`, }); -// Add all subpaths to the "files" property on package.json - -pkgFile.files = [...pkgFile.files, ...subpathHelperFile.subpathNames, ...subpathHelperFile.subpathFoldersBarrel]; - -console.log( - `Found ${subpathHelperFile.subpathNames.length} subpaths and ${subpathHelperFile.subpathFoldersBarrel.length} subpath barrels`, -); - -// Create directories for each subpath name using the pkgJsonPlaceholder -subpathHelperFile.subpathNames.forEach(name => { - fs.mkdirSync(new URL(`../packages/${pkgName}/${name}`, import.meta.url)); - 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)); - writeJSON(`../packages/${pkgName}/${name}/package.json`, pkgJsonBarrelPlaceholder(name)); -}); - -console.log('Successfully created subpath directories and package.json file override'); +async function run() { + const pkgName = argv._[0]; + console.log(`Loading package.json for ${pkgName}`); + const pkgFile = loadJSON(`../packages/${pkgName}/package.json`); + const subpathHelperFile = await import(`../packages/${pkgName}/subpaths.mjs`); + + console.log( + `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)); + + if (subpathsAlreadyAdded) { + return console.log(`Subpaths already added to ${pkgName} package.json. Exiting early`); + } + + + // 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)); + 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)); + writeJSON(`../packages/${pkgName}/${name}/package.json`, pkgJsonBarrelPlaceholder(name)); + }); + + console.log('Successfully created subpath directories with placeholder files'); +} + +await run() From b5242aad12f82782a65a9a2ce5b8eae7a9ebbc53 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 26 Oct 2023 14:18:13 -0700 Subject: [PATCH 7/8] chore(repo): Scripting --- scripts/subpath-workaround.mjs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/scripts/subpath-workaround.mjs b/scripts/subpath-workaround.mjs index 943b8632d76..8c3c507256a 100644 --- a/scripts/subpath-workaround.mjs +++ b/scripts/subpath-workaround.mjs @@ -20,39 +20,38 @@ async function run() { console.log(`Loading package.json for ${pkgName}`); const pkgFile = loadJSON(`../packages/${pkgName}/package.json`); const subpathHelperFile = await import(`../packages/${pkgName}/subpaths.mjs`); - + console.log( `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)); - + if (subpathsAlreadyAdded) { return console.log(`Subpaths already added to ${pkgName} package.json. Exiting early`); } - // 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`) - + + 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)); 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)); writeJSON(`../packages/${pkgName}/${name}/package.json`, pkgJsonBarrelPlaceholder(name)); }); - + console.log('Successfully created subpath directories with placeholder files'); } -await run() +await run(); From 5b6ea233a085699e16dcc9930c7c865052554a4a Mon Sep 17 00:00:00 2001 From: Lennart Date: Thu, 26 Oct 2023 15:04:55 -0700 Subject: [PATCH 8/8] Update wise-houses-shop.md --- .changeset/wise-houses-shop.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/wise-houses-shop.md b/.changeset/wise-houses-shop.md index 29508244603..f9844cabd2f 100644 --- a/.changeset/wise-houses-shop.md +++ b/.changeset/wise-houses-shop.md @@ -2,4 +2,4 @@ "@clerk/shared": patch --- -TODO +Improve compatibility with Expo