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

refactor: stop adding TS as dependency #406

Merged
merged 3 commits into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,3 @@ $ tns run ios --bundle

For details, see the [NativeScript docs](http://docs.nativescript.org/angular/best-practices/bundling-with-webpack.html).

# Note about dependencies.

The `nativescript-dev-webpack` plugin adds a few devDependencies to the project. Make sure to run either `npm install` or `yarn` after installing the plugin.
The versions of the newly added packages depend on the versions of some of your already added packages. More specifically - `tns-core-modules` and all packages from the `@angular` scope. Since version 0.4.0, nativescript-dev-webpack will automatically add the correct development dependencies, based on what you already have installed.
You can force update your `package.json` using the `update-ns-webpack` script which you can find in `PROJECT_DIR/node_modules/.bin`.
If the bundling process fails, please make sure you have the correct versions of the packages.

| Main packages versions | Plugins versions
| --- | ---
| `tns-core-modules`: **^3.0.0** <br> `@angular/`: **^4.0.0** | `nativescript-angular`: **^3.0.0** <br> `@ngtools/webpack`: **^1.3.0** <br> `typescript`: **^2.2.0**
| `tns-core-modules`: **^2.5.0** <br> `@angular/`: **^4.0.0** | `nativescript-angular`: **^1.5.1** <br> `@ngtools/webpack`: **1.2.13** <br> `typescript`: **2.1.6**
| `tns-core-modules`: **^2.5.0** <br> `@angular/`: **^2.4.0** | `nativescript-angular`: **^1.4.1** <br> ``@ngtools/webpack``: **1.2.10** <br> `typescript`: **2.1.6**

P.S. Also please make sure you are using the same version of all `@angular/` packages, including the devDependency of `@angular/compiler-cli`.
55 changes: 4 additions & 51 deletions dependencyManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ function getRequiredDeps(packageJson) {
};

if (isAngular({packageJson})) {
const angularDeps = resolveAngularDeps(packageJson.dependencies);
Object.assign(deps, angularDeps);
Object.assign(deps, {
"@angular/compiler-cli": packageJson.dependencies["@angular/core"],
"@ngtools/webpack": "~1.9.4",
});
} else if (isTypeScript({packageJson})) {
Object.assign(deps, { "awesome-typescript-loader": "~3.1.3" });
}
Expand All @@ -84,55 +86,6 @@ function getRequiredDeps(packageJson) {
return deps;
}

function resolveAngularDeps(usedDependencies) {
const depsToAdd = {
"@angular/compiler-cli": usedDependencies["@angular/core"],
};
const tnsModulesVersion = getVersionWithoutPatch(usedDependencies["tns-core-modules"]);
const angularCoreVersion = getVersionWithoutPatch(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 if (angularCoreVersion.startsWith("5.0")) {
Object.assign(depsToAdd, {
"typescript": "~2.4.2",
"@ngtools/webpack": "~1.8.2",
});
} else {
Object.assign(depsToAdd, {
"typescript": "~2.4.2",
"@ngtools/webpack": "~1.9.1",
});
}

return depsToAdd;
}

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

const prereleaseVersions = Object.freeze(["next", "latest", "rc"]);
if (prereleaseVersions.includes(fullVersion)) {
return fullVersion;
}

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

return version.startsWith("~") || version.startsWith("^") ?
version.substring(1) :
version;
}

function showHelperMessages({ newDepsAdded, hasOldDeps }) {
console.info(USAGE_MESSAGE);

Expand Down