mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 11:01:21 +08:00
Prefer registered modules in builder and component-builder.
Avoid breakage in bundled scenarios.
This commit is contained in:
@ -60,6 +60,7 @@ function parseInternal(value: string, context: any, uri?: string): ComponentModu
|
|||||||
function loadCustomComponent(componentPath: string, componentName?: string, attributes?: Object, context?: Object, parentPage?: Page): ComponentModule {
|
function loadCustomComponent(componentPath: string, componentName?: string, attributes?: Object, context?: Object, parentPage?: Page): ComponentModule {
|
||||||
var result: ComponentModule;
|
var result: ComponentModule;
|
||||||
componentPath = componentPath.replace("~/", "");
|
componentPath = componentPath.replace("~/", "");
|
||||||
|
const moduleName = componentPath + "/" + componentName;
|
||||||
|
|
||||||
var fullComponentPathFilePathWithoutExt = componentPath;
|
var fullComponentPathFilePathWithoutExt = componentPath;
|
||||||
|
|
||||||
@ -74,10 +75,15 @@ function loadCustomComponent(componentPath: string, componentName?: string, attr
|
|||||||
var jsFilePath = resolveFileName(fullComponentPathFilePathWithoutExt, "js");
|
var jsFilePath = resolveFileName(fullComponentPathFilePathWithoutExt, "js");
|
||||||
|
|
||||||
var subExports = context;
|
var subExports = context;
|
||||||
|
if (global.moduleExists(moduleName)) {
|
||||||
|
// Component has registered code module.
|
||||||
|
subExports = global.loadModule(moduleName);
|
||||||
|
} else {
|
||||||
if (jsFilePath) {
|
if (jsFilePath) {
|
||||||
// Custom components with XML and code
|
// Component has code file.
|
||||||
subExports = global.loadModule(jsFilePath)
|
subExports = global.loadModule(jsFilePath)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
result = loadInternal(xmlFilePath, subExports);
|
result = loadInternal(xmlFilePath, subExports);
|
||||||
|
|
||||||
|
@ -50,18 +50,26 @@ export function getComponentModule(elementName: string, namespace: string, attri
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (isString(namespace)) {
|
if (isString(namespace)) {
|
||||||
|
if (global.moduleExists(namespace)) {
|
||||||
|
moduleId = namespace;
|
||||||
|
} else {
|
||||||
var pathInsideTNSModules = path.join(knownFolders.currentApp().path, "tns_modules", namespace);
|
var pathInsideTNSModules = path.join(knownFolders.currentApp().path, "tns_modules", namespace);
|
||||||
|
|
||||||
if (Folder.exists(pathInsideTNSModules)) {
|
try {
|
||||||
|
// module inside tns_modules
|
||||||
|
instanceModule = require(pathInsideTNSModules);
|
||||||
moduleId = pathInsideTNSModules;
|
moduleId = pathInsideTNSModules;
|
||||||
} else {
|
} catch (e) {
|
||||||
// We expect module at root level in the app.
|
// module at root level in the app.
|
||||||
moduleId = path.join(knownFolders.currentApp().path, namespace);
|
moduleId = path.join(knownFolders.currentApp().path, namespace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!instanceModule) {
|
||||||
// Require module by module id.
|
// Require module by module id.
|
||||||
instanceModule = global.loadModule(moduleId);
|
instanceModule = global.loadModule(moduleId);
|
||||||
|
}
|
||||||
|
|
||||||
// Get the component type from module.
|
// Get the component type from module.
|
||||||
var instanceType = instanceModule[elementName] || Object;
|
var instanceType = instanceModule[elementName] || Object;
|
||||||
|
Reference in New Issue
Block a user