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

Commit e0b85dc

Browse files
committed
fix(angular): use hostReplacementPaths function instead of host
The new approach fixes the problems with watching platform-specific files. depends on #611 fixes #601
1 parent 0c20c34 commit e0b85dc

File tree

9 files changed

+52
-113
lines changed

9 files changed

+52
-113
lines changed

Diff for: .gitignore

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ plugins/WatchStateLoggerPlugin.d.ts
1515
plugins/WatchStateLoggerPlugin.js
1616
plugins/WatchStateLoggerPlugin.js.map
1717

18-
host/platform.d.ts
19-
host/platform.js
20-
host/platform.js.map
18+
host/resolver.d.ts
19+
host/resolver.js
20+
host/resolver.js.map
2121

2222
hooks
2323
.DS_Store

Diff for: .npmignore

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
prepublish
2-
demo
1+
build
2+
demo
3+
4+
*.ts
5+
!*.d.ts
6+

Diff for: demo/AngularApp/webpack.config.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const { join, relative, resolve, sep } = require("path");
33
const webpack = require("webpack");
44
const nsWebpack = require("nativescript-dev-webpack");
55
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
6-
const { PlatformReplacementHost } = require("nativescript-dev-webpack/host/platform");
76
const CleanWebpackPlugin = require("clean-webpack-plugin");
87
const CopyWebpackPlugin = require("copy-webpack-plugin");
98
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
@@ -227,7 +226,7 @@ module.exports = env => {
227226
new NativeScriptWorkerPlugin(),
228227

229228
new AngularCompilerPlugin({
230-
host: platformHost,
229+
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
231230
entryModule: resolve(appPath, "app.module#AppModule"),
232231
tsConfigPath: join(__dirname, "tsconfig.esm.json"),
233232
skipCodeGeneration: !aot,

Diff for: host/platform.ts

-97
This file was deleted.

Diff for: host/resolver.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {
2+
parse,
3+
join,
4+
} from "path";
5+
import { statSync } from "fs";
6+
7+
export function getResolver(platforms: string[]) {
8+
return function(path: string) {
9+
const { dir, name, ext } = parse(path);
10+
11+
for (const platform of platforms) {
12+
const platformFileName = `${name}.${platform}${ext}`;
13+
const platformPath = toSystemPath(join(dir, platformFileName));
14+
15+
try {
16+
const stat = statSync(platformPath);
17+
if (stat && stat.isFile()) {
18+
return platformPath;
19+
}
20+
} catch(_e) {
21+
// continue checking the other platforms
22+
}
23+
}
24+
25+
return path;
26+
}
27+
}
28+
29+
// Convert paths from \c\some\path to c:\some\path
30+
function toSystemPath(path: string) {
31+
if (!process.platform.startsWith("win32")) {
32+
return path;
33+
}
34+
35+
const drive = path.match(/^\\(\w)\\(.*)$/);
36+
return drive ?
37+
`${drive[1]}:\\${drive[2]}`:
38+
path;
39+
}

Diff for: index.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
} = require("./projectHelpers");
1010

1111
Object.assign(exports, require('./plugins'));
12+
Object.assign(exports, require('./host/resolver'));
1213

1314
exports.getAotEntryModule = function (appDirectory) {
1415
verifyEntryModuleDirectory(appDirectory);

Diff for: package.json

-3
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,8 @@
9292
"sass-loader": "~7.0.1"
9393
},
9494
"devDependencies": {
95-
"@angular-devkit/core": "^0.7.0-rc.0",
9695
"@types/node": "^8.0.0",
9796
"conventional-changelog-cli": "^1.3.22",
98-
"rxjs": "^6.2.0",
99-
"source-map-support": "^0.5.0",
10097
"typescript": "~2.7.2"
10198
}
10299
}

Diff for: templates/webpack.angular.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const { join, relative, resolve, sep } = require("path");
33
const webpack = require("webpack");
44
const nsWebpack = require("nativescript-dev-webpack");
55
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
6-
const { PlatformReplacementHost } = require("nativescript-dev-webpack/host/platform");
76
const CleanWebpackPlugin = require("clean-webpack-plugin");
87
const CopyWebpackPlugin = require("copy-webpack-plugin");
98
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
@@ -23,9 +22,6 @@ module.exports = env => {
2322
throw new Error("You need to provide a target platform!");
2423
}
2524

26-
const extensions = ["tns", platform];
27-
const platformHost = new PlatformReplacementHost(extensions);
28-
2925
const projectRoot = __dirname;
3026

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

228224
new AngularCompilerPlugin({
229-
host: platformHost,
225+
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
230226
entryModule: resolve(appPath, "app.module#AppModule"),
231227
tsConfigPath: join(__dirname, "tsconfig.esm.json"),
232228
skipCodeGeneration: !aot,

Diff for: tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"files": [
1111
"plugins/PlatformFSPlugin.ts",
1212
"plugins/WatchStateLoggerPlugin.ts",
13-
"host/platform.ts"
13+
"host/resolver.ts"
1414
]
1515
}

0 commit comments

Comments
 (0)