diff --git a/nativescript-angular/bin/update-app-ng-deps b/nativescript-angular/bin/update-app-ng-deps old mode 100644 new mode 100755 diff --git a/nativescript-angular/resource-loader.ts b/nativescript-angular/resource-loader.ts index 43a5091bc..f9f5ca9a5 100644 --- a/nativescript-angular/resource-loader.ts +++ b/nativescript-angular/resource-loader.ts @@ -4,11 +4,11 @@ import { path } from "tns-core-modules/file-system"; import { NSFileSystem } from "./file-system/ns-file-system"; -const extensionsFallbacks = [ - [".scss", ".css"], - [".sass", ".css"], - [".less", ".css"] -]; +const sourceExtensionsMap = { + ".scss": ".css", + ".sass": ".css", + ".less": ".css" +}; @Injectable() export class FileSystemResourceLoader extends ResourceLoader { @@ -25,20 +25,21 @@ export class FileSystemResourceLoader extends ResourceLoader { } resolve(url: string): string { - const normalizedUrl = this.resolveRelativeUrls(url); - - if (this.fs.fileExists(normalizedUrl)) { - return normalizedUrl; + const normalizedSourceUrl = this.resolveRelativeUrls(url); + const normalizedCompiledFileUrl = normalizedSourceUrl.replace(/\.\w+$/, ext => sourceExtensionsMap[ext] || ext); + if (normalizedCompiledFileUrl !== normalizedSourceUrl && this.fs.fileExists(normalizedCompiledFileUrl)) { + return normalizedCompiledFileUrl; } - - const { candidates: fallbackCandidates, resource: fallbackResource } = - this.fallbackResolve(normalizedUrl); - - if (fallbackResource) { - return fallbackResource; + if (this.fs.fileExists(normalizedSourceUrl)) { + return normalizedSourceUrl; } - throw new Error(`Could not resolve ${url}. Looked for: ${normalizedUrl}, ${fallbackCandidates}`); + if (normalizedCompiledFileUrl === normalizedSourceUrl) { + throw new Error(`Could not resolve ${url}. Looked for: ${normalizedSourceUrl}.`); + } else { + throw new Error(`Could not resolve ${url}.` + + `Looked for: ${normalizedCompiledFileUrl}, ${normalizedSourceUrl}.`); + } } private resolveRelativeUrls(url: string): string { @@ -50,23 +51,4 @@ export class FileSystemResourceLoader extends ResourceLoader { return url; } } - - private fallbackResolve(url: string): - ({ resource: string, candidates: string[] }) { - - const candidates = extensionsFallbacks - .filter(([extension]) => url.endsWith(extension)) - .map(([extension, fallback]) => - this.replaceExtension(url, extension, fallback)); - - const resource = candidates.find(candidate => this.fs.fileExists(candidate)); - - return { candidates, resource }; - } - - private replaceExtension(fileName: string, oldExtension: string, newExtension: string): string { - const baseName = fileName.substr(0, fileName.length - oldExtension.length); - return baseName + newExtension; - } } -