Skip to content

Commit fdec58f

Browse files
Plamen5kovpetekanev
authored andcommitted
run npm list --prod command and get all dependency names
1 parent 6b049a8 commit fdec58f

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

lib/tools/node-modules/node-modules-builder.ts

+31-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {sleep} from "../../../lib/common/helpers";
1010
let glob = require("glob");
1111

1212
export class NodeModulesBuilder implements INodeModulesBuilder {
13-
constructor(
13+
constructor(private $childProcess: IChildProcess,
1414
private $fs: IFileSystem,
1515
private $projectData: IProjectData,
1616
private $projectDataService: IProjectDataService,
@@ -133,6 +133,13 @@ export class NodeModulesBuilder implements INodeModulesBuilder {
133133
// Force copying if the destination doesn't exist.
134134
lastModifiedTime = null;
135135
}
136+
137+
//TODO: plamen5kov: WIP
138+
let depJsonStr = this.$childProcess.exec("npm list --prod --json").wait();
139+
let prodDependenciesJson = JSON.parse(depJsonStr);
140+
let productionDepArray = this.getProductionDependencyNames(prodDependenciesJson);
141+
142+
136143
let nodeModules = this.getChangedNodeModules(absoluteOutputPath, platform, lastModifiedTime).wait();
137144

138145
const resolver = new NpmDependencyResolver(this.$projectData.projectDir);
@@ -152,6 +159,29 @@ export class NodeModulesBuilder implements INodeModulesBuilder {
152159
}).future<void>()();
153160
}
154161

162+
private getProductionDependencyNames(inputJson: any): any {
163+
var finalDependencies:any = {};
164+
var queue:any = [];
165+
166+
inputJson.level = 0;
167+
queue.push(inputJson)
168+
169+
while(queue.length > 0) {
170+
var parent = queue.pop();
171+
172+
if(parent.dependencies) {
173+
for(var dep in parent.dependencies) {
174+
var currentDependency = parent.dependencies[dep];
175+
currentDependency.level = parent.level + 1;
176+
queue.push(currentDependency);
177+
finalDependencies[dep] = currentDependency;
178+
}
179+
}
180+
}
181+
182+
return finalDependencies;
183+
}
184+
155185
public cleanNodeModules(absoluteOutputPath: string, platform: string): void {
156186
shelljs.rm("-rf", absoluteOutputPath);
157187
}

0 commit comments

Comments
 (0)