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

Commit dc6210d

Browse files
chore: fix liveSync of html files in Angular apps (#845)
In case you change `.html` file in Angular application, during `tns run <platform> --bundle`, the application will be restarted and an error will be shown. This happens as in some cases, the `getCompiledFile` method from Angular compiler does not throw an error when it is unable to find a file, but instead it returns an object with empty outputText and array of errors (errorDependencies). Fix the liveSync in these cases by checking the result of the Angular compiler and fallback to non-platform specific file in the mentioned case.
1 parent e1e9463 commit dc6210d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

plugins/NativeScriptAngularCompilerPlugin.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function getAngularCompilerPlugin(platform: string): any {
66
// This is the bridge between the @ngtols/webpack loader and the AngularCompilerPlugin plugin itself:
77
// https://github.com/angular/angular-cli/blob/bf52b26219ffc16bed2dd55716e21773b415fd2a/packages/ngtools/webpack/src/loader.ts#L49
88
// The problem is that the loader does not call the `hostReplacementPaths` method when asking for the compiledFile.
9-
// By overriding this method, we work around this issue and support platform specific files from the loader
9+
// By overriding this method, we work around this issue and support platform specific files from the loader
1010
// that are not compiled by the AngularCompilerPlugin plugin. e.g. main.ts is the webpack entry point and
1111
// it's loaded by the @ngtools/webpack loader but its not compiled by the plugin because the TypeScript Compiler
1212
// knowns only about main.android.ts and main.ios.ts (main.ts is not imported/required anywhere in the app).
@@ -15,7 +15,12 @@ export function getAngularCompilerPlugin(platform: string): any {
1515
if (platform) {
1616
const parsed = parse(file);
1717
const platformFile = join(parsed.dir, `${parsed.name}.${platform}${parsed.ext}`);
18-
return super.getCompiledFile(platformFile);
18+
const result = super.getCompiledFile(platformFile);
19+
// In case there's some issue with the generation, getCompilePath may fail or
20+
// produce a result with empty outputText and errorDependencies array populated with files.
21+
if (result && result.outputText) {
22+
return result;
23+
}
1924
}
2025
}
2126
catch (e) { }

0 commit comments

Comments
 (0)