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

Commit

Permalink
fix(angular): use hostReplacementPaths function instead of host
Browse files Browse the repository at this point in the history
The new approach fixes the problems with watching platform-specific
files.

depends on #611
fixes #601
  • Loading branch information
sis0k0 committed Jul 18, 2018
1 parent 3a7a6d0 commit 4668a48
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 111 deletions.
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

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"
]
}

0 comments on commit 4668a48

Please sign in to comment.