From 097255a28b069729bceed793a5161719ec0b8644 Mon Sep 17 00:00:00 2001 From: mmews Date: Thu, 4 Jan 2024 11:52:46 +0100 Subject: [PATCH] treat pnpm and yarn workspace equally --- .../org/eclipse/n4js/packagejson/PackageJsonHelper.java | 4 ++-- .../projectDescription/ProjectDescription.java | 8 ++++++++ .../projectDescription/ProjectDescriptionBuilder.java | 4 ++++ .../eclipse/n4js/utils/NodeModulesDiscoveryHelper.java | 2 +- .../src/org/eclipse/n4js/workspace/N4JSProjectConfig.java | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/packagejson/PackageJsonHelper.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/packagejson/PackageJsonHelper.java index c90bdf0e86..0d77fe4ec5 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/packagejson/PackageJsonHelper.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/packagejson/PackageJsonHelper.java @@ -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 sourceContainers = target.getSourceContainers(); SourceContainerDescription sourceContainerOfTypeSource = null; for (SourceContainerDescription sourceContainer : sourceContainers) { diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/packagejson/projectDescription/ProjectDescription.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/packagejson/projectDescription/ProjectDescription.java index 51f985fac1..cc9b986e7c 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/packagejson/projectDescription/ProjectDescription.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/packagejson/projectDescription/ProjectDescription.java @@ -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. @@ -485,6 +492,7 @@ protected int computeHashCode() { esm, moduleProperty, n4jsNature, + pnpmWorkspaceRoot, yarnWorkspaceRoot, isGeneratorEnabledSourceMaps, isGeneratorEnabledDts, diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/packagejson/projectDescription/ProjectDescriptionBuilder.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/packagejson/projectDescription/ProjectDescriptionBuilder.java index 876188db42..bfaec8c668 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/packagejson/projectDescription/ProjectDescriptionBuilder.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/packagejson/projectDescription/ProjectDescriptionBuilder.java @@ -379,6 +379,10 @@ public ProjectDescriptionBuilder setN4JSNature(boolean n4jsNature) { return this; } + public boolean isWorkspaceRoot() { + return isYarnWorkspaceRoot() || isPnpmWorkspaceRoot(); + } + public boolean isPnpmWorkspaceRoot() { return pnpmWorkspaceRoot; } diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/utils/NodeModulesDiscoveryHelper.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/utils/NodeModulesDiscoveryHelper.java index 86f9e40c8c..932e7d535a 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/utils/NodeModulesDiscoveryHelper.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/utils/NodeModulesDiscoveryHelper.java @@ -276,7 +276,7 @@ private List getWorkspacesOfYarnWorkspaceProject(File yarnProjectFolder, .loadProjectDescriptionAtLocation(location, null); return pd; }); - final List workspaces = (prjDescr != null && prjDescr.isYarnWorkspaceRoot()) + final List workspaces = (prjDescr != null && prjDescr.isWorkspaceRoot()) ? prjDescr.getWorkspaces() : null; diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/workspace/N4JSProjectConfig.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/workspace/N4JSProjectConfig.java index 634b6de895..ef392268dc 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/workspace/N4JSProjectConfig.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/workspace/N4JSProjectConfig.java @@ -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(); }