From f9e9c0149b4370acc7218f99f904e4a4faab1202 Mon Sep 17 00:00:00 2001 From: Deavial Date: Mon, 29 Jan 2024 16:31:21 -0600 Subject: [PATCH] fix: Allow React to be detected in NPM Workspaces (#864) * Allow React to be detected in mono repo projects React is detected by looking for a react devDependency or dependency. NPM Workspaces (mono repos) do not define these in the project package.json. The mono repo will fail if they are defined. The mono repo root has the dependencies listed. When looking for React in this type of environment, the peerDependencies should be inspected instead. * fix for react not loading --------- Co-authored-by: L <6723574+louisgv@users.noreply.github.com> --- cli/plasmo/src/features/manifest-factory/base.ts | 4 +++- core/parcel-runtime/src/index.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cli/plasmo/src/features/manifest-factory/base.ts b/cli/plasmo/src/features/manifest-factory/base.ts index 872df5dc2..abc2390f7 100644 --- a/cli/plasmo/src/features/manifest-factory/base.ts +++ b/cli/plasmo/src/features/manifest-factory/base.ts @@ -176,7 +176,9 @@ export abstract class PlasmoManifest { get dependencies() { ok(this.packageData) - return this.packageData.dependencies + // to support npm workspaces (mono repos) we need to fallback to + // peerDependencies because dependencies will never exist + return this.packageData.dependencies ?? this.packageData.peerDependencies } get devDependencies() { diff --git a/core/parcel-runtime/src/index.ts b/core/parcel-runtime/src/index.ts index 9e8a4437f..2f1c980b3 100644 --- a/core/parcel-runtime/src/index.ts +++ b/core/parcel-runtime/src/index.ts @@ -27,6 +27,7 @@ export default new Runtime({ .getConfigFrom<{ dependencies: Record devDependencies: Record + peerDependencies: Record }>( join(process.env.PLASMO_PROJECT_DIR, "lab"), // parcel only look up ["package.json"], @@ -36,7 +37,8 @@ export default new Runtime({ ) .then((cfg) => cfg?.contents) - const hasReact = !!pkg?.dependencies?.react || !!pkg?.devDependencies?.react + // npm workspaces mono repo's do not have dependencies or devDependencies (they are defined in a parent directory), fallback to peerDependencies + const hasReact = !!pkg?.dependencies?.react || !!pkg?.devDependencies?.react || !!pkg?.peerDependencies?.react return { hasReact