From 38643b7e90276b5922076f24906d0cc217f0f810 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Mon, 4 Nov 2024 17:27:02 -0500 Subject: [PATCH 1/2] fix patch-package check to be compatible with pnpm --- patches/patch.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/patches/patch.js b/patches/patch.js index c2f5f27a..5e5fe368 100644 --- a/patches/patch.js +++ b/patches/patch.js @@ -4,6 +4,12 @@ * The intention here is to only run `patch-package` during local installation, IE. during * development of the library and not upon installation by the users of the library. */ -if (process.cwd() === process.env.INIT_CWD) { - require("patch-package"); -} +const fs = require('fs'); +const path = require('path'); + +const isInstallingAsDependency = fs.existsSync(path.join(process.cwd(), 'package.json')) && + !fs.existsSync(path.join(process.cwd(), 'src')); + +if (!isInstallingAsDependency) { + require('patch-package'); +} \ No newline at end of file From 708557b31f9bc273ce5e1f498e45466e634bed30 Mon Sep 17 00:00:00 2001 From: Matthew Stern Date: Mon, 4 Nov 2024 17:41:13 -0500 Subject: [PATCH 2/2] refactor patch-package fix to not depend on directory structure --- patches/patch.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/patches/patch.js b/patches/patch.js index 5e5fe368..bbb278d7 100644 --- a/patches/patch.js +++ b/patches/patch.js @@ -4,12 +4,16 @@ * The intention here is to only run `patch-package` during local installation, IE. during * development of the library and not upon installation by the users of the library. */ -const fs = require('fs'); -const path = require('path'); -const isInstallingAsDependency = fs.existsSync(path.join(process.cwd(), 'package.json')) && - !fs.existsSync(path.join(process.cwd(), 'src')); +// Check if the script is running within node_modules +const isInNodeModules = __dirname.includes('node_modules'); -if (!isInstallingAsDependency) { +// Check if the script is running in a workspace (e.g., pnpm, yarn workspaces) +const isInWorkspace = process.env.PWD && process.env.PWD.includes('node_modules'); + +// Determine if we should run patch-package +const shouldRunPatchPackage = !isInNodeModules && !isInWorkspace; + +if (shouldRunPatchPackage) { require('patch-package'); -} \ No newline at end of file +}