@@ -4,11 +4,11 @@ import { path } from "tns-core-modules/file-system";
44
55import { NSFileSystem } from "./file-system/ns-file-system" ;
66
7- const extensionsFallbacks = [
8- [ ".scss" , ".css" ] ,
9- [ ".sass" , ".css" ] ,
10- [ ".less" , ".css" ]
11- ] ;
7+ const sourceExtensionsMap = {
8+ ".scss" : ".css" ,
9+ ".sass" : ".css" ,
10+ ".less" : ".css"
11+ } ;
1212
1313@Injectable ( )
1414export class FileSystemResourceLoader extends ResourceLoader {
@@ -25,20 +25,21 @@ export class FileSystemResourceLoader extends ResourceLoader {
2525 }
2626
2727 resolve ( url : string ) : string {
28- const normalizedUrl = this . resolveRelativeUrls ( url ) ;
29-
30- if ( this . fs . fileExists ( normalizedUrl ) ) {
31- return normalizedUrl ;
28+ const normalizedSourceUrl = this . resolveRelativeUrls ( url ) ;
29+ const normalizedCompiledFileUrl = normalizedSourceUrl . replace ( / \. \w + $ / , ext => sourceExtensionsMap [ ext ] || ext ) ;
30+ if ( normalizedCompiledFileUrl !== normalizedSourceUrl && this . fs . fileExists ( normalizedCompiledFileUrl ) ) {
31+ return normalizedCompiledFileUrl ;
3232 }
33-
34- const { candidates : fallbackCandidates , resource : fallbackResource } =
35- this . fallbackResolve ( normalizedUrl ) ;
36-
37- if ( fallbackResource ) {
38- return fallbackResource ;
33+ if ( this . fs . fileExists ( normalizedSourceUrl ) ) {
34+ return normalizedSourceUrl ;
3935 }
4036
41- throw new Error ( `Could not resolve ${ url } . Looked for: ${ normalizedUrl } , ${ fallbackCandidates } ` ) ;
37+ if ( normalizedCompiledFileUrl === normalizedSourceUrl ) {
38+ throw new Error ( `Could not resolve ${ url } . Looked for: ${ normalizedSourceUrl } .` ) ;
39+ } else {
40+ throw new Error ( `Could not resolve ${ url } .` +
41+ `Looked for: ${ normalizedCompiledFileUrl } , ${ normalizedSourceUrl } .` ) ;
42+ }
4243 }
4344
4445 private resolveRelativeUrls ( url : string ) : string {
@@ -50,23 +51,4 @@ export class FileSystemResourceLoader extends ResourceLoader {
5051 return url ;
5152 }
5253 }
53-
54- private fallbackResolve ( url : string ) :
55- ( { resource : string , candidates : string [ ] } ) {
56-
57- const candidates = extensionsFallbacks
58- . filter ( ( [ extension ] ) => url . endsWith ( extension ) )
59- . map ( ( [ extension , fallback ] ) =>
60- this . replaceExtension ( url , extension , fallback ) ) ;
61-
62- const resource = candidates . find ( candidate => this . fs . fileExists ( candidate ) ) ;
63-
64- return { candidates, resource } ;
65- }
66-
67- private replaceExtension ( fileName : string , oldExtension : string , newExtension : string ) : string {
68- const baseName = fileName . substr ( 0 , fileName . length - oldExtension . length ) ;
69- return baseName + newExtension ;
70- }
7154}
72-
0 commit comments