mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Prefer registered modules in builder and component-builder.
Avoid breakage in bundled scenarios.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import {Page} from "ui/page";
|
||||
import {View, isEventOrGesture} from "ui/core/view";
|
||||
import {ComponentModule} from "ui/builder/component-builder";
|
||||
import {File, Folder, path, knownFolders} from "file-system";
|
||||
import {File, path, knownFolders} from "file-system";
|
||||
import {getBindingOptions, bindingConstants} from "./binding-builder";
|
||||
import * as debugModule from "utils/debug";
|
||||
import * as platformModule from "platform";
|
||||
@@ -50,18 +50,26 @@ export function getComponentModule(elementName: string, namespace: string, attri
|
||||
|
||||
try {
|
||||
if (isString(namespace)) {
|
||||
var pathInsideTNSModules = path.join(knownFolders.currentApp().path, "tns_modules", namespace);
|
||||
|
||||
if (Folder.exists(pathInsideTNSModules)) {
|
||||
moduleId = pathInsideTNSModules;
|
||||
if (global.moduleExists(namespace)) {
|
||||
moduleId = namespace;
|
||||
} else {
|
||||
// We expect module at root level in the app.
|
||||
moduleId = path.join(knownFolders.currentApp().path, namespace);
|
||||
var pathInsideTNSModules = path.join(knownFolders.currentApp().path, "tns_modules", namespace);
|
||||
|
||||
try {
|
||||
// module inside tns_modules
|
||||
instanceModule = require(pathInsideTNSModules);
|
||||
moduleId = pathInsideTNSModules;
|
||||
} catch (e) {
|
||||
// module at root level in the app.
|
||||
moduleId = path.join(knownFolders.currentApp().path, namespace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Require module by module id.
|
||||
instanceModule = global.loadModule(moduleId);
|
||||
if (!instanceModule) {
|
||||
// Require module by module id.
|
||||
instanceModule = global.loadModule(moduleId);
|
||||
}
|
||||
|
||||
// Get the component type from module.
|
||||
var instanceType = instanceModule[elementName] || Object;
|
||||
|
||||
Reference in New Issue
Block a user