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

fix(angular): use hostReplacementPaths function instead of host #615

Merged
merged 5 commits into from
Jul 19, 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
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ plugins/WatchStateLoggerPlugin.d.ts
plugins/WatchStateLoggerPlugin.js
plugins/WatchStateLoggerPlugin.js.map

host/platform.d.ts
host/platform.js
host/platform.js.map
host/resolver.d.ts
host/resolver.js
host/resolver.js.map

hooks
.DS_Store
8 changes: 6 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
prepublish
demo
build
demo

*.ts
!*.d.ts

20 changes: 10 additions & 10 deletions demo/AngularApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
}
},
"dependencies": {
"@angular/common": "~6.1.0-beta.3",
"@angular/compiler": "~6.1.0-beta.3",
"@angular/core": "~6.1.0-beta.3",
"@angular/forms": "~6.1.0-beta.3",
"@angular/http": "~6.1.0-beta.3",
"@angular/platform-browser": "~6.1.0-beta.3",
"@angular/platform-browser-dynamic": "~6.1.0-beta.3",
"@angular/router": "~6.1.0-beta.3",
"@angular/common": "~6.1.0-rc.0",
"@angular/compiler": "~6.1.0-rc.0",
"@angular/core": "~6.1.0-rc.0",
"@angular/forms": "~6.1.0-rc.0",
"@angular/http": "~6.1.0-rc.0",
"@angular/platform-browser": "~6.1.0-rc.0",
"@angular/platform-browser-dynamic": "~6.1.0-rc.0",
"@angular/router": "~6.1.0-rc.0",
"nativescript-angular": "next",
"nativescript-theme-core": "~1.0.2",
"reflect-metadata": "~0.1.8",
Expand All @@ -29,8 +29,8 @@
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "~6.1.0-beta.3",
"@ngtools/webpack": "6.1.0-rc.0",
"@angular/compiler-cli": "~6.1.0-rc.0",
"@ngtools/webpack": "~6.1.0-rc.3",
"@types/chai": "^4.0.2",
"@types/mocha": "^2.2.41",
"@types/node": "^7.0.5",
Expand Down
6 changes: 1 addition & 5 deletions demo/AngularApp/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { join, relative, resolve, sep } = require("path");
const webpack = require("webpack");
const nsWebpack = require("nativescript-dev-webpack");
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
const { PlatformReplacementHost } = require("nativescript-dev-webpack/host/platform");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
Expand All @@ -24,9 +23,6 @@ module.exports = env => {
throw new Error("You need to provide a target platform!");
}

const extensions = ["tns", platform];
const platformHost = new PlatformReplacementHost(extensions);

const projectRoot = __dirname;

// Default destination inside platforms/<platform>/...
Expand Down Expand Up @@ -227,7 +223,7 @@ module.exports = env => {
new NativeScriptWorkerPlugin(),

new AngularCompilerPlugin({
host: platformHost,
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
entryModule: resolve(appPath, "app.module#AppModule"),
tsConfigPath: join(__dirname, "tsconfig.esm.json"),
skipCodeGeneration: !aot,
Expand Down
97 changes: 0 additions & 97 deletions host/platform.ts

This file was deleted.

39 changes: 39 additions & 0 deletions host/resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
parse,
join,
} from "path";
import { statSync } from "fs";

export function getResolver(platforms: string[]) {
return function(path: string) {
const { dir, name, ext } = parse(path);

for (const platform of platforms) {
const platformFileName = `${name}.${platform}${ext}`;
const platformPath = toSystemPath(join(dir, platformFileName));

try {
const stat = statSync(platformPath);
if (stat && stat.isFile()) {
return platformPath;
}
} catch(_e) {
// continue checking the other platforms
}
}

return path;
}
}

// Convert paths from \c\some\path to c:\some\path
function toSystemPath(path: string) {
if (!process.platform.startsWith("win32")) {
return path;
}

const drive = path.match(/^\\(\w)\\(.*)$/);
return drive ?
`${drive[1]}:\\${drive[2]}`:
path;
}
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
} = require("./projectHelpers");

Object.assign(exports, require('./plugins'));
Object.assign(exports, require('./host/resolver'));

exports.getAotEntryModule = function (appDirectory) {
verifyEntryModuleDirectory(appDirectory);
Expand Down
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@
"sass-loader": "~7.0.1"
},
"devDependencies": {
"@angular-devkit/core": "^0.7.0-rc.0",
"@types/node": "^8.0.0",
"conventional-changelog-cli": "^1.3.22",
"rxjs": "^6.2.0",
"source-map-support": "^0.5.0",
"typescript": "~2.7.2"
}
}
6 changes: 1 addition & 5 deletions templates/webpack.angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { join, relative, resolve, sep } = require("path");
const webpack = require("webpack");
const nsWebpack = require("nativescript-dev-webpack");
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
const { PlatformReplacementHost } = require("nativescript-dev-webpack/host/platform");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
Expand All @@ -23,9 +22,6 @@ module.exports = env => {
throw new Error("You need to provide a target platform!");
}

const extensions = ["tns", platform];
const platformHost = new PlatformReplacementHost(extensions);

const projectRoot = __dirname;

// Default destination inside platforms/<platform>/...
Expand Down Expand Up @@ -226,7 +222,7 @@ module.exports = env => {
new NativeScriptWorkerPlugin(),

new AngularCompilerPlugin({
host: platformHost,
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
entryModule: resolve(appPath, "app.module#AppModule"),
tsConfigPath: join(__dirname, "tsconfig.esm.json"),
skipCodeGeneration: !aot,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"files": [
"plugins/PlatformFSPlugin.ts",
"plugins/WatchStateLoggerPlugin.ts",
"host/platform.ts"
"host/resolver.ts"
]
}