Skip to content

Commit 192a3d0

Browse files
committed
fix: deprecate NSModuleFactoryLoader in favor of the built-in
SystemJsModuleLoader related to NativeScript/NativeScript@011be36 Deprecated code: NSModuleFactoryLoader is no longer needed for {N} apps. Before: ``` // app.module.ts @NgModule({ providers: [ { provide: NgModuleFactoryLoader, useClass: NSModuleFactoryLoader } // ... ], // ... }) class AppModule { } ``` After: ``` // app.module.ts @NgModule({ providers: [ // ... ], // ... }) class AppModule { } ```
1 parent c8a3683 commit 192a3d0

File tree

1 file changed

+8
-55
lines changed

1 file changed

+8
-55
lines changed
+8-55
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,19 @@
11
import {
22
Compiler,
33
Injectable,
4-
NgModuleFactory,
5-
NgModuleFactoryLoader,
4+
Optional,
65
SystemJsNgModuleLoader,
7-
Type,
6+
SystemJsNgModuleLoaderConfig,
87
} from "@angular/core";
9-
import {
10-
path as fileSystemPath,
11-
knownFolders
12-
} from "tns-core-modules/file-system";
13-
14-
const SEPARATOR = "#";
158

169
@Injectable()
17-
export class NSModuleFactoryLoader implements NgModuleFactoryLoader {
18-
private offlineMode: boolean;
19-
10+
export class NSModuleFactoryLoader extends SystemJsNgModuleLoader {
2011
constructor(
21-
private compiler: Compiler,
22-
private ngModuleLoader: SystemJsNgModuleLoader,
12+
compiler: Compiler,
13+
@Optional() config?: SystemJsNgModuleLoaderConfig
2314
) {
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.`);
6518
}
6619
}

0 commit comments

Comments
 (0)