Skip to content

Commit

Permalink
[FIX] projectPreprocessor: Ignore deduped modules
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Dec 17, 2018
1 parent 2717088 commit 84f7b25
Show file tree
Hide file tree
Showing 2 changed files with 245 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/projectPreprocessor.js
Expand Up @@ -40,7 +40,8 @@ class ProjectPreprocessor {
// by the dependency lookahead
const projectsToProcess = projects.filter((project) => {
if (!project.id) {
throw new Error("Encountered project with missing id");
const parentRefText = parent ? `(child of ${parent.id})` : `(root project)`;
throw new Error(`Encountered project with missing id ${parentRefText}`);
}
if (this.isBeingProcessed(parent, project)) {
return false;
Expand Down Expand Up @@ -155,6 +156,10 @@ class ProjectPreprocessor {

isBeingProcessed(parent, project) { // Check whether a project is currently being or has already been processed
const processedProject = this.processedProjects[project.id];
if (project.deduped) {
// Ignore deduped modules
return true;
}
if (processedProject) {
if (processedProject.ignored) {
log.verbose(`Dependency of project ${parent.id}, "${project.id}" is flagged as ignored.`);
Expand Down
240 changes: 239 additions & 1 deletion test/lib/projectPreprocessor.js
Expand Up @@ -8,6 +8,7 @@ const libraryAPath = path.join(__dirname, "..", "fixtures", "collection", "libra
const libraryBPath = path.join(__dirname, "..", "fixtures", "collection", "library.b");
// 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");

test("Project with inline configuration", (t) => {
const tree = {
Expand Down Expand Up @@ -170,7 +171,7 @@ test("Missing id for root project", (t) => {
dependencies: []
};
return t.throws(projectPreprocessor.processTree(tree),
"Encountered project with missing id", "Rejected with error");
"Encountered project with missing id (root project)", "Rejected with error");
});

test("No type configured for root project", (t) => {
Expand Down Expand Up @@ -525,6 +526,13 @@ test("Project tree B with inline configs", (t) => {
});
});

test("Project tree B with inline configs", (t) => {
// Tree B depends on Library B which has a dependency to Library D
return projectPreprocessor.processTree(treeApplicationCycleA).then((parsedTree) => {
t.deepEqual(parsedTree, expectedTreeApplicationCycleA, "Parsed correctly");
});
});

/* ========================= */
/* ======= Test data ======= */

Expand Down Expand Up @@ -1103,6 +1111,236 @@ const expectedTreeBWithInlineConfigs = {
]
};

const treeApplicationCycleA = {
id: "application.cycle.a",
version: "1.0.0",
specVersion: "0.1",
path: path.join(cycleDepsBasePath, "application.cycle.a"),
type: "application",
metadata: {
name: "application.cycle.a",
},
dependencies: [
{
id: "component.cycle.a",
version: "1.0.0",
specVersion: "0.1",
path: path.join(cycleDepsBasePath, "component.cycle.a"),
type: "library",
metadata: {
name: "component.cycle.a",
},
dependencies: [
{
id: "library.cycle.a",
version: "1.0.0",
specVersion: "0.1",
path: path.join(cycleDepsBasePath, "library.cycle.a"),
type: "library",
metadata: {
name: "library.cycle.a",
},
dependencies: [
{
id: "component.cycle.a",
version: "1.0.0",
specVersion: "0.1",
path: path.join(cycleDepsBasePath, "component.cycle.a"),
type: "library",
metadata: {
name: "component.cycle.a",
},
dependencies: [],
deduped: true
}
]
},
{
id: "library.cycle.b",
version: "1.0.0",
specVersion: "0.1",
path: path.join(cycleDepsBasePath, "library.cycle.b"),
type: "library",
metadata: {
name: "library.cycle.b",
},
dependencies: [
{
id: "component.cycle.a",
version: "1.0.0",
specVersion: "0.1",
path: path.join(cycleDepsBasePath, "component.cycle.a"),
type: "library",
metadata: {
name: "component.cycle.a",
},
dependencies: [],
deduped: true
}
]
},
{
id: "application.cycle.a",
version: "1.0.0",
specVersion: "0.1",
path: path.join(cycleDepsBasePath, "application.cycle.a"),
type: "application",
metadata: {
name: "application.cycle.a",
},
dependencies: [],
deduped: true
}
]
}
]
};

const expectedTreeApplicationCycleA = {
"id": "application.cycle.a",
"version": "1.0.0",
"specVersion": "0.1",
"path": path.join(cycleDepsBasePath, "application.cycle.a"),
"type": "application",
"metadata": {
"name": "application.cycle.a"
},
"dependencies": [
{
"id": "component.cycle.a",
"version": "1.0.0",
"specVersion": "0.1",
"path": path.join(cycleDepsBasePath, "component.cycle.a"),
"type": "library",
"metadata": {
"name": "component.cycle.a",
"copyright": "${copyright}"
},
"dependencies": [
{
"id": "library.cycle.a",
"version": "1.0.0",
"specVersion": "0.1",
"path": path.join(cycleDepsBasePath, "library.cycle.a"),
"type": "library",
"metadata": {
"name": "library.cycle.a",
"copyright": "${copyright}"
},
"dependencies": [
{
"id": "component.cycle.a",
"version": "1.0.0",
"specVersion": "0.1",
"path": path.join(cycleDepsBasePath, "component.cycle.a"),
"type": "library",
"metadata": {
"name": "component.cycle.a"
},
"dependencies": [],
"deduped": true
}
],
"kind": "project",
"_level": 2,
"resources": {
"configuration": {
"paths": {
"src": "src",
"test": "test"
}
},
"pathMappings": {
"/resources/": "src",
"/test-resources/": "test"
}
}
},
{
"id": "library.cycle.b",
"version": "1.0.0",
"specVersion": "0.1",
"path": path.join(cycleDepsBasePath, "library.cycle.b"),
"type": "library",
"metadata": {
"name": "library.cycle.b",
"copyright": "${copyright}"
},
"dependencies": [
{
"id": "component.cycle.a",
"version": "1.0.0",
"specVersion": "0.1",
"path": path.join(cycleDepsBasePath, "component.cycle.a"),
"type": "library",
"metadata": {
"name": "component.cycle.a"
},
"dependencies": [],
"deduped": true
}
],
"kind": "project",
"_level": 2,
"resources": {
"configuration": {
"paths": {
"src": "src",
"test": "test"
}
},
"pathMappings": {
"/resources/": "src",
"/test-resources/": "test"
}
}
},
{
"id": "application.cycle.a",
"version": "1.0.0",
"specVersion": "0.1",
"path": path.join(cycleDepsBasePath, "application.cycle.a"),
"type": "application",
"metadata": {
"name": "application.cycle.a"
},
"dependencies": [],
"deduped": true
}
],
"kind": "project",
"_level": 1,
"resources": {
"configuration": {
"paths": {
"src": "src",
"test": "test"
}
},
"pathMappings": {
"/resources/": "src",
"/test-resources/": "test"
}
}
}
],
"_level": 0,
"kind": "project",
"resources": {
"configuration": {
"paths": {
"webapp": "webapp"
}
},
"pathMappings": {
"/": "webapp"
}
}
};

/* ======= /Test data ======= */
/* ========================= */

test("Application version in package.json data is missing", (t) => {
const tree = {
id: "application.a",
Expand Down

0 comments on commit 84f7b25

Please sign in to comment.