From cc824ca52260f643b56e2cb21308611906c3aff0 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Fri, 23 Feb 2024 14:30:04 +0200 Subject: [PATCH 1/4] Set default workspaceName to "default" --- lib/graph/graph.js | 21 +++++++++------------ test/lib/graph/graph.js | 10 +++++----- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/graph/graph.js b/lib/graph/graph.js index 892c84068..1e305714f 100644 --- a/lib/graph/graph.js +++ b/lib/graph/graph.js @@ -29,8 +29,8 @@ const log = getLogger("generateProjectGraph"); * @param {string} [options.versionOverride] Framework version to use instead of the one defined in the root project * @param {string} [options.resolveFrameworkDependencies=true] * Whether framework dependencies should be added to the graph - * @param {string} [options.workspaceName] - * Name of the workspace configuration that should be used if any is provided + * @param {string} [options.workspaceName=default] + * Name of the workspace configuration that should be used. "default" if not provided. * @param {module:@ui5/project/ui5Framework/maven/CacheMode} [options.cacheMode] * Cache mode to use when consuming SNAPSHOT versions of a framework * @param {string} [options.workspaceConfigPath=ui5-workspace.yaml] @@ -43,7 +43,7 @@ const log = getLogger("generateProjectGraph"); export async function graphFromPackageDependencies({ cwd, rootConfiguration, rootConfigPath, versionOverride, cacheMode, resolveFrameworkDependencies = true, - workspaceName /* TODO 4.0: default workspaceName to "default" ? */, + workspaceName="default", workspaceConfiguration, workspaceConfigPath = "ui5-workspace.yaml" }) { log.verbose(`Creating project graph using npm provider...`); @@ -54,15 +54,12 @@ export async function graphFromPackageDependencies({ cwd = cwd ? path.resolve(cwd) : process.cwd(); rootConfigPath = utils.resolveConfigPath(cwd, rootConfigPath); - let workspace; - if (workspaceName || workspaceConfiguration) { - workspace = await createWorkspace({ - cwd, - name: workspaceName, - configObject: workspaceConfiguration, - configPath: workspaceConfigPath - }); - } + const workspace = await createWorkspace({ + cwd, + name: workspaceName, + configObject: workspaceConfiguration, + configPath: workspaceConfigPath, + }); const provider = new NpmProvider({ cwd, diff --git a/test/lib/graph/graph.js b/test/lib/graph/graph.js index c11bfbc88..7f393007c 100644 --- a/test/lib/graph/graph.js +++ b/test/lib/graph/graph.js @@ -63,7 +63,7 @@ test.serial("graphFromPackageDependencies", async (t) => { t.is(res, "graph"); - t.is(createWorkspaceStub.callCount, 0, "createWorkspace did not get called"); + t.is(createWorkspaceStub.callCount, 1, "createWorkspace did not get called"); t.is(npmProviderConstructorStub.callCount, 1, "NPM provider constructor got called once"); t.deepEqual(npmProviderConstructorStub.getCall(0).args[0], { cwd: path.join(__dirname, "..", "..", "..", "cwd"), @@ -74,15 +74,15 @@ test.serial("graphFromPackageDependencies", async (t) => { t.is(projectGraphBuilderStub.callCount, 1, "projectGraphBuilder got called once"); t.true(projectGraphBuilderStub.getCall(0).args[0] instanceof MockNpmProvider, "projectGraphBuilder got called with correct provider instance"); - t.is(projectGraphBuilderStub.getCall(0).args[1], undefined, - "projectGraphBuilder got called with an empty workspace"); + t.is(projectGraphBuilderStub.getCall(0).args[1], "workspace", + "projectGraphBuilder got called with \"default\" workspace"); t.is(enrichProjectGraphStub.callCount, 1, "enrichProjectGraph got called once"); t.is(enrichProjectGraphStub.getCall(0).args[0], "graph", "enrichProjectGraph got called with graph"); t.deepEqual(enrichProjectGraphStub.getCall(0).args[1], { versionOverride: "versionOverride", - workspace: undefined, + workspace: "workspace", cacheMode: "Off" }, "enrichProjectGraph got called with correct options"); }); @@ -156,7 +156,7 @@ test.serial("graphFromPackageDependencies with workspace object", async (t) => { t.deepEqual(createWorkspaceStub.getCall(0).args[0], { cwd: path.join(__dirname, "..", "..", "..", "cwd"), configPath: "ui5-workspace.yaml", - name: undefined, + name: "default", configObject: "workspaceConfiguration" }, "createWorkspace called with correct parameters"); }); From 7da1ec863bc67578dbf60e5925495c2ff7055be8 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Fri, 23 Feb 2024 15:42:33 +0200 Subject: [PATCH 2/4] Update lib/graph/graph.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matthias Oßwald --- lib/graph/graph.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/graph/graph.js b/lib/graph/graph.js index 1e305714f..866c943a2 100644 --- a/lib/graph/graph.js +++ b/lib/graph/graph.js @@ -29,7 +29,7 @@ const log = getLogger("generateProjectGraph"); * @param {string} [options.versionOverride] Framework version to use instead of the one defined in the root project * @param {string} [options.resolveFrameworkDependencies=true] * Whether framework dependencies should be added to the graph - * @param {string} [options.workspaceName=default] + * @param {string|null} [options.workspaceName=default] * Name of the workspace configuration that should be used. "default" if not provided. * @param {module:@ui5/project/ui5Framework/maven/CacheMode} [options.cacheMode] * Cache mode to use when consuming SNAPSHOT versions of a framework From 950056b06497c29f5ade9033fce97c5b5b3d1fea Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Fri, 23 Feb 2024 15:46:56 +0200 Subject: [PATCH 3/4] Allow null values for workspaceName --- lib/graph/graph.js | 15 +++++++++------ test/lib/graph/graph.js | 16 +++++++++------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/lib/graph/graph.js b/lib/graph/graph.js index 866c943a2..1f77bbb58 100644 --- a/lib/graph/graph.js +++ b/lib/graph/graph.js @@ -54,12 +54,15 @@ export async function graphFromPackageDependencies({ cwd = cwd ? path.resolve(cwd) : process.cwd(); rootConfigPath = utils.resolveConfigPath(cwd, rootConfigPath); - const workspace = await createWorkspace({ - cwd, - name: workspaceName, - configObject: workspaceConfiguration, - configPath: workspaceConfigPath, - }); + let workspace; + if (workspaceName || workspaceConfiguration) { + workspace = await createWorkspace({ + cwd, + name: workspaceName, + configObject: workspaceConfiguration, + configPath: workspaceConfigPath + }); + } const provider = new NpmProvider({ cwd, diff --git a/test/lib/graph/graph.js b/test/lib/graph/graph.js index 7f393007c..7b1ec419e 100644 --- a/test/lib/graph/graph.js +++ b/test/lib/graph/graph.js @@ -58,12 +58,13 @@ test.serial("graphFromPackageDependencies", async (t) => { rootConfiguration: "rootConfiguration", rootConfigPath: "/rootConfigPath", versionOverride: "versionOverride", - cacheMode: CacheMode.Off + cacheMode: CacheMode.Off, + workspaceName: null }); t.is(res, "graph"); - t.is(createWorkspaceStub.callCount, 1, "createWorkspace did not get called"); + t.is(createWorkspaceStub.callCount, 0, "createWorkspace did not get called"); t.is(npmProviderConstructorStub.callCount, 1, "NPM provider constructor got called once"); t.deepEqual(npmProviderConstructorStub.getCall(0).args[0], { cwd: path.join(__dirname, "..", "..", "..", "cwd"), @@ -74,15 +75,15 @@ test.serial("graphFromPackageDependencies", async (t) => { t.is(projectGraphBuilderStub.callCount, 1, "projectGraphBuilder got called once"); t.true(projectGraphBuilderStub.getCall(0).args[0] instanceof MockNpmProvider, "projectGraphBuilder got called with correct provider instance"); - t.is(projectGraphBuilderStub.getCall(0).args[1], "workspace", - "projectGraphBuilder got called with \"default\" workspace"); + t.is(projectGraphBuilderStub.getCall(0).args[1], undefined, + "projectGraphBuilder got called with an empty workspace"); t.is(enrichProjectGraphStub.callCount, 1, "enrichProjectGraph got called once"); t.is(enrichProjectGraphStub.getCall(0).args[0], "graph", "enrichProjectGraph got called with graph"); t.deepEqual(enrichProjectGraphStub.getCall(0).args[1], { versionOverride: "versionOverride", - workspace: "workspace", + workspace: undefined, cacheMode: "Off" }, "enrichProjectGraph got called with correct options"); }); @@ -147,7 +148,8 @@ test.serial("graphFromPackageDependencies with workspace object", async (t) => { rootConfiguration: "rootConfiguration", rootConfigPath: "/rootConfigPath", versionOverride: "versionOverride", - workspaceConfiguration: "workspaceConfiguration" + workspaceConfiguration: "workspaceConfiguration", + workspaceName: null }); t.is(res, "graph"); @@ -156,7 +158,7 @@ test.serial("graphFromPackageDependencies with workspace object", async (t) => { t.deepEqual(createWorkspaceStub.getCall(0).args[0], { cwd: path.join(__dirname, "..", "..", "..", "cwd"), configPath: "ui5-workspace.yaml", - name: "default", + name: null, configObject: "workspaceConfiguration" }, "createWorkspace called with correct parameters"); }); From 95a392012eeb32591db2f41adac837d55e2ed042 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Mon, 26 Feb 2024 14:31:39 +0200 Subject: [PATCH 4/4] Provide tests for "default" workspace name --- test/lib/graph/graph.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/lib/graph/graph.js b/test/lib/graph/graph.js index 7b1ec419e..4cc4c1386 100644 --- a/test/lib/graph/graph.js +++ b/test/lib/graph/graph.js @@ -283,6 +283,24 @@ test.serial("graphFromPackageDependencies: Do not resolve framework dependencies t.is(enrichProjectGraphStub.callCount, 0, "enrichProjectGraph did not get called"); }); +test.serial("graphFromPackageDependencies: Default workspace name", async (t) => { + const {createWorkspaceStub} = t.context; + const {graphFromPackageDependencies} = t.context.graph; + + const res = await graphFromPackageDependencies({ + cwd: "cwd", + rootConfiguration: "rootConfiguration", + rootConfigPath: "/rootConfigPath", + versionOverride: "versionOverride", + resolveFrameworkDependencies: false + }); + + t.is(res, "graph"); + t.true(createWorkspaceStub.calledOnce, "createWorkspace is called"); + t.is(createWorkspaceStub.getCall(0).args[0].name, "default", + "createWorkspace is called with 'default' workspace"); +}); + test.serial("graphFromStaticFile", async (t) => { const { dependencyTreeProviderStub,