From 9f5b8d3a110aeb8c7118e8138212f7465b3cf0e9 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Fri, 28 Apr 2023 13:21:04 +0300 Subject: [PATCH 1/7] [FIX] Resolve properly depenency name aliases --- lib/graph/providers/NodePackageDependencies.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/graph/providers/NodePackageDependencies.js b/lib/graph/providers/NodePackageDependencies.js index ecf79c5ef..e3c523b11 100644 --- a/lib/graph/providers/NodePackageDependencies.js +++ b/lib/graph/providers/NodePackageDependencies.js @@ -64,7 +64,7 @@ class NodePackageDependencies { } return Promise.all(node._dependencies.map(async ({name, optional}) => { const modulePath = await this._resolveModulePath(node.path, name, workspace); - return this._getNode(modulePath, optional); + return this._getNode(modulePath, optional, name); })); } @@ -99,7 +99,7 @@ class NodePackageDependencies { } } - async _getNode(modulePath, optional) { + async _getNode(modulePath, optional, nameAlias) { log.verbose(`Reading package.json in directory ${modulePath}...`); const packageJson = await readPackage({ cwd: modulePath, @@ -107,7 +107,7 @@ class NodePackageDependencies { }); return { - id: packageJson.name, + id: nameAlias || packageJson.name, version: packageJson.version, path: modulePath, optional, From c0dcbe9815d7c8bbc4c22f4294b5099b45264ca5 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Tue, 2 May 2023 09:14:41 +0300 Subject: [PATCH 2/7] Add aliased app --- .../main/src/library/d/.library | 11 ++++++++++ .../main/src/library/d/some.js | 4 ++++ .../main/test/library/d/Test.html | 0 .../node_modules/library.d.alias/package.json | 9 ++++++++ .../node_modules/library.d.alias/ui5.yaml | 10 +++++++++ .../application.a.aliases/package.json | 12 +++++++++++ test/fixtures/application.a.aliases/ui5.yaml | 5 +++++ .../application.a.aliases/webapp/index.html | 9 ++++++++ .../webapp/manifest.json | 13 ++++++++++++ .../application.a.aliases/webapp/test.js | 5 +++++ .../NodePackageDependencies.integration.js | 21 +++++++++++++++++++ 11 files changed, 99 insertions(+) create mode 100644 test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/.library create mode 100644 test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/some.js create mode 100644 test/fixtures/application.a.aliases/node_modules/library.d.alias/main/test/library/d/Test.html create mode 100644 test/fixtures/application.a.aliases/node_modules/library.d.alias/package.json create mode 100644 test/fixtures/application.a.aliases/node_modules/library.d.alias/ui5.yaml create mode 100644 test/fixtures/application.a.aliases/package.json create mode 100644 test/fixtures/application.a.aliases/ui5.yaml create mode 100644 test/fixtures/application.a.aliases/webapp/index.html create mode 100644 test/fixtures/application.a.aliases/webapp/manifest.json create mode 100644 test/fixtures/application.a.aliases/webapp/test.js diff --git a/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/.library b/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/.library new file mode 100644 index 000000000..53c2d14c9 --- /dev/null +++ b/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/.library @@ -0,0 +1,11 @@ + + + + library.d + SAP SE + Some fancy copyright + ${version} + + Library D + + diff --git a/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/some.js b/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/some.js new file mode 100644 index 000000000..81e734360 --- /dev/null +++ b/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/some.js @@ -0,0 +1,4 @@ +/*! + * ${copyright} + */ +console.log('HelloWorld'); \ No newline at end of file diff --git a/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/test/library/d/Test.html b/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/test/library/d/Test.html new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/application.a.aliases/node_modules/library.d.alias/package.json b/test/fixtures/application.a.aliases/node_modules/library.d.alias/package.json new file mode 100644 index 000000000..90c75040a --- /dev/null +++ b/test/fixtures/application.a.aliases/node_modules/library.d.alias/package.json @@ -0,0 +1,9 @@ +{ + "name": "library.d", + "version": "1.0.0", + "description": "Simple SAPUI5 based library", + "dependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + } +} diff --git a/test/fixtures/application.a.aliases/node_modules/library.d.alias/ui5.yaml b/test/fixtures/application.a.aliases/node_modules/library.d.alias/ui5.yaml new file mode 100644 index 000000000..a47c1f64c --- /dev/null +++ b/test/fixtures/application.a.aliases/node_modules/library.d.alias/ui5.yaml @@ -0,0 +1,10 @@ +--- +specVersion: "2.3" +type: library +metadata: + name: library.d +resources: + configuration: + paths: + src: main/src + test: main/test diff --git a/test/fixtures/application.a.aliases/package.json b/test/fixtures/application.a.aliases/package.json new file mode 100644 index 000000000..db8c8f76a --- /dev/null +++ b/test/fixtures/application.a.aliases/package.json @@ -0,0 +1,12 @@ +{ + "name": "application.a.aliases", + "version": "1.0.0", + "description": "Simple SAPUI5 based application", + "main": "index.html", + "dependencies": { + "library.d.alias": "file:../library.d" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + } +} diff --git a/test/fixtures/application.a.aliases/ui5.yaml b/test/fixtures/application.a.aliases/ui5.yaml new file mode 100644 index 000000000..746eb39be --- /dev/null +++ b/test/fixtures/application.a.aliases/ui5.yaml @@ -0,0 +1,5 @@ +--- +specVersion: "2.3" +type: application +metadata: + name: application.a.aliases diff --git a/test/fixtures/application.a.aliases/webapp/index.html b/test/fixtures/application.a.aliases/webapp/index.html new file mode 100644 index 000000000..77b0207cc --- /dev/null +++ b/test/fixtures/application.a.aliases/webapp/index.html @@ -0,0 +1,9 @@ + + + + Application A + + + + + \ No newline at end of file diff --git a/test/fixtures/application.a.aliases/webapp/manifest.json b/test/fixtures/application.a.aliases/webapp/manifest.json new file mode 100644 index 000000000..781945df9 --- /dev/null +++ b/test/fixtures/application.a.aliases/webapp/manifest.json @@ -0,0 +1,13 @@ +{ + "_version": "1.1.0", + "sap.app": { + "_version": "1.1.0", + "id": "id1", + "type": "application", + "applicationVersion": { + "version": "1.2.2" + }, + "embeds": ["embedded"], + "title": "{{title}}" + } +} \ No newline at end of file diff --git a/test/fixtures/application.a.aliases/webapp/test.js b/test/fixtures/application.a.aliases/webapp/test.js new file mode 100644 index 000000000..a3df410c3 --- /dev/null +++ b/test/fixtures/application.a.aliases/webapp/test.js @@ -0,0 +1,5 @@ +function test(paramA) { + var variableA = paramA; + console.log(variableA); +} +test(); diff --git a/test/lib/graph/providers/NodePackageDependencies.integration.js b/test/lib/graph/providers/NodePackageDependencies.integration.js index 842442cb1..dd12522d3 100644 --- a/test/lib/graph/providers/NodePackageDependencies.integration.js +++ b/test/lib/graph/providers/NodePackageDependencies.integration.js @@ -6,6 +6,7 @@ import sinonGlobal from "sinon"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const applicationAPath = path.join(__dirname, "..", "..", "..", "fixtures", "application.a"); +const applicationAAliasesPath = path.join(__dirname, "..", "..", "..", "fixtures", "application.a.aliases"); const applicationCPath = path.join(__dirname, "..", "..", "..", "fixtures", "application.c"); const applicationC2Path = path.join(__dirname, "..", "..", "..", "fixtures", "application.c2"); const applicationC3Path = path.join(__dirname, "..", "..", "..", "fixtures", "application.c3"); @@ -14,6 +15,7 @@ const applicationFPath = path.join(__dirname, "..", "..", "..", "fixtures", "app const applicationGPath = path.join(__dirname, "..", "..", "..", "fixtures", "application.g"); const errApplicationAPath = path.join(__dirname, "..", "..", "..", "fixtures", "err.application.a"); const cycleDepsBasePath = path.join(__dirname, "..", "..", "..", "fixtures", "cyclic-deps", "node_modules"); +const libraryDPath = path.join(__dirname, "..", "..", "..", "fixtures", "library.d"); const libraryDOverridePath = path.join(__dirname, "..", "..", "..", "fixtures", "library.d-adtl-deps"); import projectGraphBuilder from "../../../../lib/graph/projectGraphBuilder.js"; @@ -68,6 +70,25 @@ test("AppA: project with collection dependency", async (t) => { ]); }); +test.only("AppA: project with an alias dependency", async (t) => { + const workspace = { + getName: () => "workspace name", + getModuleByNodeId: t.context.sinon.stub().resolves(undefined).onFirstCall().resolves({ + // This version of library.d has an additional dependency to library.f, + // which in turn has a dependency to library.g + getPath: () => libraryDPath, + getVersion: () => "1.0.0", + }) + }; + const npmProvider = new NodePackageDependenciesProvider({ + cwd: applicationAAliasesPath + }); + await testGraphCreationDfs(t, npmProvider, [ + "library.d.alias", + "application.a.aliases", + ], workspace); +}); + test("AppA: project with workspace overrides", async (t) => { const workspace = { getName: () => "workspace name", From e948306323553444b0b9313013c32aba22da7b45 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Tue, 2 May 2023 09:56:08 +0300 Subject: [PATCH 3/7] Add "external" module to the test and provide shim config --- .../lib/extensionModule.js | 2 ++ .../extension.a.esm.alias/package.json | 5 +++++ .../main/src/library/d/.library | 11 ---------- .../main/src/library/d/some.js | 4 ---- .../main/test/library/d/Test.html | 0 .../node_modules/library.d.alias/package.json | 9 --------- .../node_modules/library.d.alias/ui5.yaml | 10 ---------- .../application.a.aliases/package.json | 2 +- test/fixtures/application.a.aliases/ui5.yaml | 20 ++++++++++++++++++- .../NodePackageDependencies.integration.js | 7 +++---- 10 files changed, 30 insertions(+), 40 deletions(-) create mode 100644 test/fixtures/application.a.aliases/node_modules/extension.a.esm.alias/lib/extensionModule.js create mode 100644 test/fixtures/application.a.aliases/node_modules/extension.a.esm.alias/package.json delete mode 100644 test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/.library delete mode 100644 test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/some.js delete mode 100644 test/fixtures/application.a.aliases/node_modules/library.d.alias/main/test/library/d/Test.html delete mode 100644 test/fixtures/application.a.aliases/node_modules/library.d.alias/package.json delete mode 100644 test/fixtures/application.a.aliases/node_modules/library.d.alias/ui5.yaml diff --git a/test/fixtures/application.a.aliases/node_modules/extension.a.esm.alias/lib/extensionModule.js b/test/fixtures/application.a.aliases/node_modules/extension.a.esm.alias/lib/extensionModule.js new file mode 100644 index 000000000..c7a5c0758 --- /dev/null +++ b/test/fixtures/application.a.aliases/node_modules/extension.a.esm.alias/lib/extensionModule.js @@ -0,0 +1,2 @@ +export default () => "extension module"; +export function determineRequiredDependencies () { return "required dependencies function" }; diff --git a/test/fixtures/application.a.aliases/node_modules/extension.a.esm.alias/package.json b/test/fixtures/application.a.aliases/node_modules/extension.a.esm.alias/package.json new file mode 100644 index 000000000..97c63b166 --- /dev/null +++ b/test/fixtures/application.a.aliases/node_modules/extension.a.esm.alias/package.json @@ -0,0 +1,5 @@ +{ + "name": "extension.a", + "type": "module", + "version": "1.0.0" +} diff --git a/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/.library b/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/.library deleted file mode 100644 index 53c2d14c9..000000000 --- a/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/.library +++ /dev/null @@ -1,11 +0,0 @@ - - - - library.d - SAP SE - Some fancy copyright - ${version} - - Library D - - diff --git a/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/some.js b/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/some.js deleted file mode 100644 index 81e734360..000000000 --- a/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/src/library/d/some.js +++ /dev/null @@ -1,4 +0,0 @@ -/*! - * ${copyright} - */ -console.log('HelloWorld'); \ No newline at end of file diff --git a/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/test/library/d/Test.html b/test/fixtures/application.a.aliases/node_modules/library.d.alias/main/test/library/d/Test.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/fixtures/application.a.aliases/node_modules/library.d.alias/package.json b/test/fixtures/application.a.aliases/node_modules/library.d.alias/package.json deleted file mode 100644 index 90c75040a..000000000 --- a/test/fixtures/application.a.aliases/node_modules/library.d.alias/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "library.d", - "version": "1.0.0", - "description": "Simple SAPUI5 based library", - "dependencies": {}, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - } -} diff --git a/test/fixtures/application.a.aliases/node_modules/library.d.alias/ui5.yaml b/test/fixtures/application.a.aliases/node_modules/library.d.alias/ui5.yaml deleted file mode 100644 index a47c1f64c..000000000 --- a/test/fixtures/application.a.aliases/node_modules/library.d.alias/ui5.yaml +++ /dev/null @@ -1,10 +0,0 @@ ---- -specVersion: "2.3" -type: library -metadata: - name: library.d -resources: - configuration: - paths: - src: main/src - test: main/test diff --git a/test/fixtures/application.a.aliases/package.json b/test/fixtures/application.a.aliases/package.json index db8c8f76a..b15c70dfe 100644 --- a/test/fixtures/application.a.aliases/package.json +++ b/test/fixtures/application.a.aliases/package.json @@ -4,7 +4,7 @@ "description": "Simple SAPUI5 based application", "main": "index.html", "dependencies": { - "library.d.alias": "file:../library.d" + "extension.a.esm.alias": "file:../extension.a.esm" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/test/fixtures/application.a.aliases/ui5.yaml b/test/fixtures/application.a.aliases/ui5.yaml index 746eb39be..bdc9a31f8 100644 --- a/test/fixtures/application.a.aliases/ui5.yaml +++ b/test/fixtures/application.a.aliases/ui5.yaml @@ -1,5 +1,23 @@ --- -specVersion: "2.3" +specVersion: "3.0" type: application metadata: name: application.a.aliases + +--- # Everything below this line could also be put into the ui5.yaml of a standalone extension module +specVersion: "3.0" +kind: extension +type: project-shim +metadata: + name: my.application.thirdparty +shims: + configurations: + extension.a.esm.alias: # name as defined in package.json + specVersion: "3.0" + type: module # Use module type + metadata: + name: extension.a.esm.alias + resources: + configuration: + paths: + /resources/my/application/thirdparty/: "" # map root directory of lodash module diff --git a/test/lib/graph/providers/NodePackageDependencies.integration.js b/test/lib/graph/providers/NodePackageDependencies.integration.js index dd12522d3..b1a6c1b22 100644 --- a/test/lib/graph/providers/NodePackageDependencies.integration.js +++ b/test/lib/graph/providers/NodePackageDependencies.integration.js @@ -15,7 +15,6 @@ const applicationFPath = path.join(__dirname, "..", "..", "..", "fixtures", "app const applicationGPath = path.join(__dirname, "..", "..", "..", "fixtures", "application.g"); const errApplicationAPath = path.join(__dirname, "..", "..", "..", "fixtures", "err.application.a"); const cycleDepsBasePath = path.join(__dirname, "..", "..", "..", "fixtures", "cyclic-deps", "node_modules"); -const libraryDPath = path.join(__dirname, "..", "..", "..", "fixtures", "library.d"); const libraryDOverridePath = path.join(__dirname, "..", "..", "..", "fixtures", "library.d-adtl-deps"); import projectGraphBuilder from "../../../../lib/graph/projectGraphBuilder.js"; @@ -70,13 +69,13 @@ test("AppA: project with collection dependency", async (t) => { ]); }); -test.only("AppA: project with an alias dependency", async (t) => { +test("AppA: project with an alias dependency", async (t) => { const workspace = { getName: () => "workspace name", getModuleByNodeId: t.context.sinon.stub().resolves(undefined).onFirstCall().resolves({ // This version of library.d has an additional dependency to library.f, // which in turn has a dependency to library.g - getPath: () => libraryDPath, + getPath: () => path.join(applicationAAliasesPath, "node_modules", "extension.a.esm.alias"), getVersion: () => "1.0.0", }) }; @@ -84,7 +83,7 @@ test.only("AppA: project with an alias dependency", async (t) => { cwd: applicationAAliasesPath }); await testGraphCreationDfs(t, npmProvider, [ - "library.d.alias", + "extension.a.esm.alias", "application.a.aliases", ], workspace); }); From 446d7dcbb5f82e8469c4665ebdaf23148199d5cf Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Tue, 2 May 2023 11:40:34 +0300 Subject: [PATCH 4/7] Fix comments --- test/fixtures/application.a.aliases/webapp/index.html | 2 +- test/fixtures/application.a.aliases/webapp/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/fixtures/application.a.aliases/webapp/index.html b/test/fixtures/application.a.aliases/webapp/index.html index 77b0207cc..1b8755901 100644 --- a/test/fixtures/application.a.aliases/webapp/index.html +++ b/test/fixtures/application.a.aliases/webapp/index.html @@ -6,4 +6,4 @@ - \ No newline at end of file + diff --git a/test/fixtures/application.a.aliases/webapp/manifest.json b/test/fixtures/application.a.aliases/webapp/manifest.json index 781945df9..d33902df7 100644 --- a/test/fixtures/application.a.aliases/webapp/manifest.json +++ b/test/fixtures/application.a.aliases/webapp/manifest.json @@ -10,4 +10,4 @@ "embeds": ["embedded"], "title": "{{title}}" } -} \ No newline at end of file +} From febc68adade2da0a8cab86591ad355c9e9523d6e Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Thu, 4 May 2023 09:37:47 +0300 Subject: [PATCH 5/7] Add correct descriptions and JSDoc --- lib/graph/providers/NodePackageDependencies.js | 10 ++++++++++ .../providers/NodePackageDependencies.integration.js | 2 -- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/graph/providers/NodePackageDependencies.js b/lib/graph/providers/NodePackageDependencies.js index e3c523b11..10a9fe86f 100644 --- a/lib/graph/providers/NodePackageDependencies.js +++ b/lib/graph/providers/NodePackageDependencies.js @@ -99,6 +99,16 @@ class NodePackageDependencies { } } + /** + * Resolves a Node module by reading its package.json + * + * @param {string} modulePath Path to the module. + * @param {boolean} optional Whether this dependency is optional. + * @param {string} nameAlias The name of the module. It's usually the same as the name definfed + * in package.json and could easily be skipped. Useful when defining dependency as an alias: + * https://github.com/npm/rfcs/blob/main/implemented/0001-package-aliases.md + * @returns Promise + */ async _getNode(modulePath, optional, nameAlias) { log.verbose(`Reading package.json in directory ${modulePath}...`); const packageJson = await readPackage({ diff --git a/test/lib/graph/providers/NodePackageDependencies.integration.js b/test/lib/graph/providers/NodePackageDependencies.integration.js index b1a6c1b22..19657aa41 100644 --- a/test/lib/graph/providers/NodePackageDependencies.integration.js +++ b/test/lib/graph/providers/NodePackageDependencies.integration.js @@ -73,8 +73,6 @@ test("AppA: project with an alias dependency", async (t) => { const workspace = { getName: () => "workspace name", getModuleByNodeId: t.context.sinon.stub().resolves(undefined).onFirstCall().resolves({ - // This version of library.d has an additional dependency to library.f, - // which in turn has a dependency to library.g getPath: () => path.join(applicationAAliasesPath, "node_modules", "extension.a.esm.alias"), getVersion: () => "1.0.0", }) From c65bb1e976eb9b62e9d82f1ee7cf0fc1fe289f04 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Thu, 4 May 2023 09:43:14 +0300 Subject: [PATCH 6/7] Fix JSDoc formatting --- lib/graph/providers/NodePackageDependencies.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/graph/providers/NodePackageDependencies.js b/lib/graph/providers/NodePackageDependencies.js index 10a9fe86f..ca1ff90ed 100644 --- a/lib/graph/providers/NodePackageDependencies.js +++ b/lib/graph/providers/NodePackageDependencies.js @@ -106,8 +106,8 @@ class NodePackageDependencies { * @param {boolean} optional Whether this dependency is optional. * @param {string} nameAlias The name of the module. It's usually the same as the name definfed * in package.json and could easily be skipped. Useful when defining dependency as an alias: - * https://github.com/npm/rfcs/blob/main/implemented/0001-package-aliases.md - * @returns Promise + * {@link https://github.com/npm/rfcs/blob/main/implemented/0001-package-aliases.md} + * @returns {Promise} */ async _getNode(modulePath, optional, nameAlias) { log.verbose(`Reading package.json in directory ${modulePath}...`); From 53edb4682362f244092848136ee12db09397c0d1 Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Thu, 4 May 2023 09:44:00 +0300 Subject: [PATCH 7/7] nameAlias as optional parameter --- lib/graph/providers/NodePackageDependencies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/graph/providers/NodePackageDependencies.js b/lib/graph/providers/NodePackageDependencies.js index ca1ff90ed..ada50f406 100644 --- a/lib/graph/providers/NodePackageDependencies.js +++ b/lib/graph/providers/NodePackageDependencies.js @@ -104,7 +104,7 @@ class NodePackageDependencies { * * @param {string} modulePath Path to the module. * @param {boolean} optional Whether this dependency is optional. - * @param {string} nameAlias The name of the module. It's usually the same as the name definfed + * @param {string} [nameAlias] The name of the module. It's usually the same as the name definfed * in package.json and could easily be skipped. Useful when defining dependency as an alias: * {@link https://github.com/npm/rfcs/blob/main/implemented/0001-package-aliases.md} * @returns {Promise}