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

fix: add missing tsconfig paths when the app is using only scoped core modules and Angular #1108

Merged
merged 1 commit into from
Jan 6, 2020
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
47 changes: 41 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}/*`
});
}

Expand Down Expand Up @@ -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];
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-dev-webpack",
"version": "1.4.0",
"version": "1.4.1",
"main": "index",
"description": "",
"homepage": "http://www.telerik.com",
Expand Down