From c25ae03d0a1e3302ea1ecb6c8f2f43f87ebe0adb Mon Sep 17 00:00:00 2001 From: Thorsten Hochreuter Date: Wed, 10 Apr 2019 16:40:31 +0200 Subject: [PATCH] [FIX] ProjectPreprocessor: Fix dependency resolution NPM dependencies which cannot be configured (via yaml or shim) are considered invalid and should not be part of the final project tree. --- lib/projectPreprocessor.js | 3 +- test/lib/projectPreprocessor.js | 145 ++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 1 deletion(-) diff --git a/lib/projectPreprocessor.js b/lib/projectPreprocessor.js index 708c47ef8..eb561e3e9 100644 --- a/lib/projectPreprocessor.js +++ b/lib/projectPreprocessor.js @@ -79,7 +79,8 @@ class ProjectPreprocessor { if (this.isConfigValid(project)) { await this.applyType(project); queue.push({ - projects: project.dependencies, + // copy array, so that the queue is stable while ignored project dependencies are removed + projects: [...project.dependencies], parent: project, level: level + 1 }); diff --git a/test/lib/projectPreprocessor.js b/test/lib/projectPreprocessor.js index cda2940ed..47103fb54 100644 --- a/test/lib/projectPreprocessor.js +++ b/test/lib/projectPreprocessor.js @@ -9,6 +9,7 @@ const libraryBPath = path.join(__dirname, "..", "fixtures", "collection", "libra // const libraryCPath = path.join(__dirname, "..", "fixtures", "collection", "library.c"); const libraryDPath = path.join(__dirname, "..", "fixtures", "library.d"); const cycleDepsBasePath = path.join(__dirname, "..", "fixtures", "cyclic-deps", "node_modules"); +const pathToInvalidModule = path.join(__dirname, "..", "fixtures", "invalidModule"); test("Project with inline configuration", (t) => { const tree = { @@ -533,9 +534,153 @@ test("Project tree B with inline configs", (t) => { }); }); +test("Project with nested invalid dependencies", (t) => { + return projectPreprocessor.processTree(treeWithInvalidModules).then((parsedTree) => { + t.deepEqual(expectedTreeWithInvalidModules, parsedTree); + }); +}); + /* ========================= */ /* ======= Test data ======= */ +/* === Invalid Modules */ +const treeWithInvalidModules = { + id: "application.a", + path: applicationAPath, + dependencies: [ + // A + { + id: "library.a", + path: libraryAPath, + dependencies: [ + { + // C - invalid - should be missing in preprocessed tree + id: "module.c", + dependencies: [], + path: pathToInvalidModule, + version: "1.0.0" + }, + { + // D - invalid - should be missing in preprocessed tree + id: "module.d", + dependencies: [], + path: pathToInvalidModule, + version: "1.0.0" + } + ], + version: "1.0.0", + specVersion: "1.0", + type: "library", + metadata: {name: "library.a"} + }, + // B + { + id: "library.b", + path: libraryBPath, + dependencies: [ + { + // C - invalid - should be missing in preprocessed tree + id: "module.c", + dependencies: [], + path: pathToInvalidModule, + version: "1.0.0" + }, + { + // D - invalid - should be missing in preprocessed tree + id: "module.d", + dependencies: [], + path: pathToInvalidModule, + version: "1.0.0" + } + ], + version: "1.0.0", + specVersion: "1.0", + type: "library", + metadata: {name: "library.b"} + } + ], + version: "1.0.0", + specVersion: "1.0", + type: "application", + metadata: { + name: "application.a" + } +}; + +const expectedTreeWithInvalidModules = { + "id": "application.a", + "path": applicationAPath, + "dependencies": [{ + "id": "library.a", + "path": libraryAPath, + "dependencies": [], + "version": "1.0.0", + "specVersion": "1.0", + "type": "library", + "metadata": { + "name": "library.a", + "copyright": "Some fancy copyright ${currentYear}" + }, + "kind": "project", + "_level": 1, + "resources": { + "configuration": { + "paths": { + "src": "src", + "test": "test" + } + }, + "pathMappings": { + "/resources/": "src", + "/test-resources/": "test" + } + } + }, { + "id": "library.b", + "path": libraryBPath, + "dependencies": [], + "version": "1.0.0", + "specVersion": "1.0", + "type": "library", + "metadata": { + "name": "library.b", + "copyright": "Some fancy copyright ${currentYear}" + }, + "kind": "project", + "_level": 1, + "resources": { + "configuration": { + "paths": { + "src": "src", + "test": "test" + } + }, + "pathMappings": { + "/resources/": "src", + "/test-resources/": "test" + } + } + }], + "version": "1.0.0", + "specVersion": "1.0", + "type": "application", + "metadata": { + "name": "application.a" + }, + "_level": 0, + "kind": "project", + "resources": { + "configuration": { + "paths": { + "webapp": "webapp" + } + }, + "pathMappings": { + "/": "webapp" + } + } +}; + /* === Tree A === */ const treeAWithInlineConfigs = { id: "application.a",