Skip to content

Commit

Permalink
fix: Allow React to be detected in NPM Workspaces (PlasmoHQ#864)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
deavial and louisgv authored Jan 29, 2024
1 parent 1cb290e commit f9e9c01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cli/plasmo/src/features/manifest-factory/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ export abstract class PlasmoManifest<T extends ExtensionManifest = any> {

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() {
Expand Down
4 changes: 3 additions & 1 deletion core/parcel-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default new Runtime({
.getConfigFrom<{
dependencies: Record<string, string>
devDependencies: Record<string, string>
peerDependencies: Record<string, string>
}>(
join(process.env.PLASMO_PROJECT_DIR, "lab"), // parcel only look up
["package.json"],
Expand All @@ -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
Expand Down

0 comments on commit f9e9c01

Please sign in to comment.