MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / registerModuleById

Function registerModuleById

packages/core/globals/index.ts:116–159  ·  view source on GitHub ↗
(moduleId: string)

Source from the content-addressed store, hash-verified

114 };
115
116 const registerModuleById = (moduleId: string) => {
117 const extDotIndex = moduleId.lastIndexOf('.');
118 const base = moduleId.substring(0, extDotIndex);
119 const originalExt = moduleId.substring(extDotIndex);
120 const registerExt = extensionMap[originalExt] || defaultExtensionMap[originalExt] || originalExt;
121
122 // We prefer source files for webpack scenarios before compilation leftovers,
123 // e. g. if we get a .js and .ts for the same module, the .js is probably the compiled version of the .ts file,
124 // so we register the .ts with higher priority, similar is the case with us preferring the .scss to .css
125 const isSourceFile = originalExt !== registerExt;
126 const registerName = base + registerExt;
127
128 if (registerName.startsWith('./') && registerName.endsWith('.js')) {
129 const jsNickNames = [
130 // This is extremely short version like "main-page" that was promoted to be used with global.registerModule("module-name", loaderFunc);
131 registerName.substring(2, registerName.length - 3),
132 // This is for supporting module names like "./main/main-page"
133 registerName.substring(0, registerName.length - 3),
134 // This is for supporting module names like "main/main-page.js"
135 registerName.substring(2),
136 ];
137
138 jsNickNames.forEach((jsNickName) => {
139 if (isSourceFile || !global.moduleExists(jsNickName)) {
140 registerWithName(jsNickName, moduleId);
141 }
142 });
143 } else if (registerName.startsWith('./')) {
144 const moduleNickNames = [
145 // This is for supporting module names like "main/main-page.xml"
146 registerName.substring(2),
147 ];
148
149 moduleNickNames.forEach((moduleNickName) => {
150 if (!global.moduleExists(moduleNickName)) {
151 registerWithName(moduleNickName, moduleId);
152 }
153 });
154 }
155
156 if (isSourceFile || !global.moduleExists(registerName)) {
157 registerWithName(registerName, moduleId);
158 }
159 };
160
161 context.keys().forEach(registerModuleById);
162};

Callers

nothing calls this directly

Calls 3

registerWithNameFunction · 0.85
lastIndexOfMethod · 0.80
forEachMethod · 0.80

Tested by

no test coverage detected