Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Commit

Permalink
feat: detect required devDeps versions
Browse files Browse the repository at this point in the history
The plugin will automatically add devDependencies on postinstall, based
on already used dependencies. More information can be found in the
README
  • Loading branch information
sis0k0 committed Apr 17, 2017
1 parent 7451545 commit 9b102c3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
File renamed without changes.
53 changes: 49 additions & 4 deletions dependencyManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function addDependency(deps, name, version, force) {
}

function getRequiredDeps(packageJson) {
var deps = {
let deps = {
"webpack": "~2.3.3",
"webpack-sources": "~0.2.3",
"copy-webpack-plugin": "~4.0.1",
Expand All @@ -40,15 +40,60 @@ function getRequiredDeps(packageJson) {
};

if (helpers.isAngular({packageJson})) {
deps["@angular/compiler-cli"] = "~4.0.2";
deps["@ngtools/webpack"] = "1.3.0";
deps["typescript"] = "~2.2.2";
const angularDeps = resolveAngularDeps(packageJson.dependencies);
deps = Object.assign(deps, angularDeps);
} else if (helpers.isTypeScript({packageJson})) {
deps["awesome-typescript-loader"] = "~3.1.2";
}

return deps;
}

function resolveAngularDeps(usedDependencies) {
let depsToAdd = {
"@angular/compiler-cli": usedDependencies["@angular/core"],
};
const tnsModulesVersion = getVersionNumber(usedDependencies["tns-core-modules"]);
const angularCoreVersion = getVersionNumber(usedDependencies["@angular/core"]);

if (angularCoreVersion.startsWith("2.")) {
Object.assign(depsToAdd, {
"typescript": "~2.1.6",
"@ngtools/webpack": "1.2.10",
});
} else if (tnsModulesVersion.startsWith("2.")) {
Object.assign(depsToAdd, {
"typescript": "~2.1.6",
"@ngtools/webpack": "1.2.13",
});
} else {
Object.assign(depsToAdd, {
"typescript": "~2.2.2",
"@ngtools/webpack": "1.3.0",
});
}

return depsToAdd;
}

function getVersionWithoutPatch(version) {
if (!version) {
return "";
}

if (version === "next" || version === "latest" || version === "rc") {
return version;
}

version = version.substring(0, version.lastIndexOf("."));

if (version.startsWith("~") || version.startsWith("^")) {
return version.substring(1);
} else {
return version;
}
}

module.exports = {
forceUpdateProjectDeps,
addProjectDeps,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"bin": {
"install-ns-webpack": "./bin/install-ns-webpack",
"remove-ns-webpack": "./bin/remove-ns-webpack",
"update-ns-webpack": "./bin/update-ns-webpack",
"ns-bundle": "./bin/ns-bundle",
"ns-verify-bundle": "./bin/ns-verify-bundle",
"ns-webpack-update": "./bin/ns-webpack-update"
"ns-verify-bundle": "./bin/ns-verify-bundle"
},
"dependencies": {},
"devDependencies": {}
Expand Down

0 comments on commit 9b102c3

Please sign in to comment.