|
1 | 1 | import {
|
2 | 2 | Compiler,
|
3 | 3 | Injectable,
|
4 |
| - NgModuleFactory, |
5 |
| - NgModuleFactoryLoader, |
| 4 | + Optional, |
6 | 5 | SystemJsNgModuleLoader,
|
7 |
| - Type, |
| 6 | + SystemJsNgModuleLoaderConfig, |
8 | 7 | } from "@angular/core";
|
9 |
| -import { |
10 |
| - path as fileSystemPath, |
11 |
| - knownFolders |
12 |
| -} from "tns-core-modules/file-system"; |
13 |
| - |
14 |
| -const SEPARATOR = "#"; |
15 | 8 |
|
16 | 9 | @Injectable()
|
17 |
| -export class NSModuleFactoryLoader implements NgModuleFactoryLoader { |
18 |
| - private offlineMode: boolean; |
19 |
| - |
| 10 | +export class NSModuleFactoryLoader extends SystemJsNgModuleLoader { |
20 | 11 | constructor(
|
21 |
| - private compiler: Compiler, |
22 |
| - private ngModuleLoader: SystemJsNgModuleLoader, |
| 12 | + compiler: Compiler, |
| 13 | + @Optional() config?: SystemJsNgModuleLoaderConfig |
23 | 14 | ) {
|
24 |
| - this.offlineMode = compiler instanceof Compiler; |
25 |
| - } |
26 |
| - |
27 |
| - load(path: string): Promise<NgModuleFactory<any>> { |
28 |
| - return this.offlineMode ? |
29 |
| - this.ngModuleLoader.load(path) : |
30 |
| - this.loadAndCompile(path); |
31 |
| - } |
32 |
| - |
33 |
| - private loadAndCompile(path: string): Promise<NgModuleFactory<any>> { |
34 |
| - const module = requireModule(path); |
35 |
| - return Promise.resolve(this.compiler.compileModuleAsync(module)); |
36 |
| - } |
37 |
| -} |
38 |
| - |
39 |
| -function requireModule(path: string): Type<any> { |
40 |
| - const {modulePath, exportName} = splitPath(path); |
41 |
| - |
42 |
| - const loadedModule = global.require(modulePath)[exportName]; |
43 |
| - checkNotEmpty(loadedModule, modulePath, exportName); |
44 |
| - |
45 |
| - return loadedModule; |
46 |
| -} |
47 |
| - |
48 |
| -function splitPath(path: string): {modulePath: string, exportName: string} { |
49 |
| - const [relativeModulePath, exportName = "default"] = path.split(SEPARATOR); |
50 |
| - const absoluteModulePath = getAbsolutePath(relativeModulePath); |
51 |
| - |
52 |
| - return {modulePath: absoluteModulePath, exportName}; |
53 |
| -} |
54 |
| - |
55 |
| -function getAbsolutePath(relativePath: string) { |
56 |
| - const projectPath = knownFolders.currentApp().path; |
57 |
| - const absolutePath = fileSystemPath.join(projectPath, relativePath); |
58 |
| - |
59 |
| - return fileSystemPath.normalize(absolutePath); |
60 |
| -} |
61 |
| - |
62 |
| -function checkNotEmpty(value: any, modulePath: string, exportName: string): void { |
63 |
| - if (!value) { |
64 |
| - throw new Error(`Cannot find '${exportName}' in '${modulePath}'`); |
| 15 | + super(compiler, config); |
| 16 | + console.log(`NSModuleFactoryLoader is deprecated! ` + |
| 17 | + `You no longer need to provide it as a module loader.`); |
65 | 18 | }
|
66 | 19 | }
|
0 commit comments