From 87ec15705a89bd9d08d087fae5ca65a6d8cc9efe Mon Sep 17 00:00:00 2001 From: DimitarTachev Date: Mon, 6 Jan 2020 15:17:48 +0200 Subject: [PATCH] fix: add missing tsconfig paths when the app is using only scoped modules and angular The AngularCompilerPlugin is using these paths for resolving the Webpack modules similar to the alias in the other flavours. --- index.js | 47 +++++++++++++++++++++++++++++++++++++++++------ package.json | 2 +- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 9036ae0c..05b13ab1 100644 --- a/index.js +++ b/index.js @@ -11,18 +11,42 @@ Object.assign(exports, require("./plugins")); Object.assign(exports, require("./host/resolver")); exports.processTsPathsForScopedModules = function ({ compilerOptions }) { - return replacePathInCompilerOptions({ + const tnsModulesOldPackage = "tns-core-modules"; + const tnsModulesNewPackage = "@nativescript/core"; + replacePathInCompilerOptions({ compilerOptions, - targetPath: "tns-core-modules", - replacementPath: "@nativescript/core" + targetPath: tnsModulesOldPackage, + replacementPath: tnsModulesNewPackage + }); + ensurePathInCompilerOptions({ + compilerOptions, + sourcePath: tnsModulesOldPackage, + destinationPath: `./node_modules/${tnsModulesNewPackage}` + }); + ensurePathInCompilerOptions({ + compilerOptions, + sourcePath: `${tnsModulesOldPackage}/*`, + destinationPath: `./node_modules/${tnsModulesNewPackage}/*` }); } exports.processTsPathsForScopedAngular = function ({ compilerOptions }) { - return replacePathInCompilerOptions({ + const nsAngularOldPackage = "nativescript-angular"; + const nsAngularNewPackage = "@nativescript/angular"; + replacePathInCompilerOptions({ + compilerOptions, + targetPath: nsAngularOldPackage, + replacementPath: nsAngularNewPackage + }); + ensurePathInCompilerOptions({ + compilerOptions, + sourcePath: nsAngularOldPackage, + destinationPath: `./node_modules/${nsAngularNewPackage}` + }); + ensurePathInCompilerOptions({ compilerOptions, - targetPath: "nativescript-angular", - replacementPath: "@nativescript/angular" + sourcePath: `${nsAngularOldPackage}/*`, + destinationPath: `./node_modules/${nsAngularNewPackage}/*` }); } @@ -215,4 +239,15 @@ function replacePathInCompilerOptions({ compilerOptions, targetPath, replacement } } } +} + +function ensurePathInCompilerOptions({ compilerOptions, sourcePath, destinationPath }) { + const paths = (compilerOptions && compilerOptions.paths) || {}; + if (paths[sourcePath]) { + if (Array.isArray(paths[sourcePath]) && paths[sourcePath].indexOf(destinationPath) === -1) { + paths[sourcePath].push(destinationPath); + } + } else { + paths[sourcePath] = [destinationPath]; + } } \ No newline at end of file diff --git a/package.json b/package.json index 1046ba2a..c4491a95 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nativescript-dev-webpack", - "version": "1.4.0", + "version": "1.4.1", "main": "index", "description": "", "homepage": "http://www.telerik.com",