Skip to content

Commit

Permalink
treat pnpm and yarn workspace equally
Browse files Browse the repository at this point in the history
  • Loading branch information
mmews committed Jan 4, 2024
1 parent 14274af commit 097255a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -583,9 +583,9 @@ private void applyN4JSDefaults(ProjectDescriptionBuilder target, String defaultP
private void setSourceContainer(ProjectDescriptionBuilder target, String path, boolean replace) {
// if no source containers are defined (no matter what type),
// then add a default source container of type "source" with path "."
// EXCEPT target represents a yarn workspace root
// EXCEPT target represents a workspace root

if (!target.isYarnWorkspaceRoot()) {
if (!target.isWorkspaceRoot()) {
List<SourceContainerDescription> sourceContainers = target.getSourceContainers();
SourceContainerDescription sourceContainerOfTypeSource = null;
for (SourceContainerDescription sourceContainer : sourceContainers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,13 @@ public boolean hasN4JSNature() {
return n4jsNature;
}

/**
* True iff the project represented by this project description is the root of either a yarn or pnpm workspace.
*/
public boolean isWorkspaceRoot() {
return isYarnWorkspaceRoot() || isPnpmWorkspaceRoot();
}

/**
* Tells whether the project represented by this project description is the root of a yarn workspace. This flag will
* be {@code true} iff the package.json contains yarn's top-level property "workspaces", no matter the value (i.e.
Expand Down Expand Up @@ -485,6 +492,7 @@ protected int computeHashCode() {
esm,
moduleProperty,
n4jsNature,
pnpmWorkspaceRoot,
yarnWorkspaceRoot,
isGeneratorEnabledSourceMaps,
isGeneratorEnabledDts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ public ProjectDescriptionBuilder setN4JSNature(boolean n4jsNature) {
return this;
}

public boolean isWorkspaceRoot() {
return isYarnWorkspaceRoot() || isPnpmWorkspaceRoot();
}

public boolean isPnpmWorkspaceRoot() {
return pnpmWorkspaceRoot;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private List<String> getWorkspacesOfYarnWorkspaceProject(File yarnProjectFolder,
.loadProjectDescriptionAtLocation(location, null);
return pd;
});
final List<String> workspaces = (prjDescr != null && prjDescr.isYarnWorkspaceRoot())
final List<String> workspaces = (prjDescr != null && prjDescr.isWorkspaceRoot())
? prjDescr.getWorkspaces()
: null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public N4JSPackageName getN4JSPackageName() {

/** Tells whether this project is a yarn workspace project. */
public boolean isWorkspaceProject() {
return projectDescription.isYarnWorkspaceRoot()
return projectDescription.isWorkspaceRoot()
&& projectDescription.getWorkspaces() != null
&& !projectDescription.getWorkspaces().isEmpty();
}
Expand Down

0 comments on commit 097255a

Please sign in to comment.