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

Commit 93c5f77

Browse files
authored
fix(angular): use hostReplacementPaths function instead of host (#615)
The new approach fixes the problems with watching platform-specific files. depends on #611 fixes #601
1 parent a8e6ecf commit 93c5f77

File tree

10 files changed

+62
-126
lines changed

10 files changed

+62
-126
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/package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
}
1414
},
1515
"dependencies": {
16-
"@angular/common": "~6.1.0-beta.3",
17-
"@angular/compiler": "~6.1.0-beta.3",
18-
"@angular/core": "~6.1.0-beta.3",
19-
"@angular/forms": "~6.1.0-beta.3",
20-
"@angular/http": "~6.1.0-beta.3",
21-
"@angular/platform-browser": "~6.1.0-beta.3",
22-
"@angular/platform-browser-dynamic": "~6.1.0-beta.3",
23-
"@angular/router": "~6.1.0-beta.3",
16+
"@angular/common": "~6.1.0-rc.0",
17+
"@angular/compiler": "~6.1.0-rc.0",
18+
"@angular/core": "~6.1.0-rc.0",
19+
"@angular/forms": "~6.1.0-rc.0",
20+
"@angular/http": "~6.1.0-rc.0",
21+
"@angular/platform-browser": "~6.1.0-rc.0",
22+
"@angular/platform-browser-dynamic": "~6.1.0-rc.0",
23+
"@angular/router": "~6.1.0-rc.0",
2424
"nativescript-angular": "next",
2525
"nativescript-theme-core": "~1.0.2",
2626
"reflect-metadata": "~0.1.8",
@@ -29,8 +29,8 @@
2929
"zone.js": "^0.8.26"
3030
},
3131
"devDependencies": {
32-
"@angular/compiler-cli": "~6.1.0-beta.3",
33-
"@ngtools/webpack": "6.1.0-rc.0",
32+
"@angular/compiler-cli": "~6.1.0-rc.0",
33+
"@ngtools/webpack": "~6.1.0-rc.3",
3434
"@types/chai": "^4.0.2",
3535
"@types/mocha": "^2.2.41",
3636
"@types/node": "^7.0.5",

Diff for: demo/AngularApp/webpack.config.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");
@@ -24,9 +23,6 @@ module.exports = env => {
2423
throw new Error("You need to provide a target platform!");
2524
}
2625

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

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

229225
new AngularCompilerPlugin({
230-
host: platformHost,
226+
hostReplacementPaths: nsWebpack.getResolver([platform, "tns"]),
231227
entryModule: resolve(appPath, "app.module#AppModule"),
232228
tsConfigPath: join(__dirname, "tsconfig.esm.json"),
233229
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)