revert: prettier change

This commit is contained in:
Igor Randjelovic
2023-05-12 21:06:29 +02:00
parent 4c2ab53773
commit d2a502e2f3
49 changed files with 1074 additions and 4240 deletions

View File

@ -11,10 +11,7 @@ export type ModuleListProvider = () => string[];
export class ModuleNameResolver {
private _cache = {};
constructor(
private context: PlatformContext,
private moduleListProvider: ModuleListProvider = global.getRegisteredModules
) {
constructor(private context: PlatformContext, private moduleListProvider: ModuleListProvider = global.getRegisteredModules) {
Application.on('livesync', (args) => clearCache());
Application.on('orientationChanged', (args) => {
resolverInstance = undefined;
@ -30,10 +27,7 @@ export class ModuleNameResolver {
}
if (Trace.isEnabled()) {
Trace.write(
`path: '${path}' with ext: '${ext}' resolved: '${result}'`,
Trace.categories.ModuleNameResolver
);
Trace.write(`path: '${path}' with ext: '${ext}' resolved: '${result}'`, Trace.categories.ModuleNameResolver);
}
return result;
@ -57,9 +51,7 @@ export class ModuleNameResolver {
}
private getCandidates(path: string, ext: string): Array<string> {
const candidates = this.moduleListProvider().filter(
(moduleName) => moduleName.startsWith(path) && (!ext || moduleName.endsWith(ext))
);
const candidates = this.moduleListProvider().filter((moduleName) => moduleName.startsWith(path) && (!ext || moduleName.endsWith(ext)));
return candidates;
}
@ -85,10 +77,7 @@ export function resolveModuleName(path: string, ext: string): string {
}
function resolveModuleSnapshot(path, ext) {
Trace.write(
`Resolving module in SNAPSHOT context - path: '${path}' with ext: '${ext}'`,
Trace.categories.ModuleNameResolver
);
Trace.write(`Resolving module in SNAPSHOT context - path: '${path}' with ext: '${ext}'`, Trace.categories.ModuleNameResolver);
// Platform module when in snapshot. So resolve modules with default android phone.
// NB: The only module name that should ever be resolved while in snapshot is app.css, because it is

View File

@ -14,27 +14,19 @@ function register(name: string, loader: (name?: string) => void) {
if (name.startsWith('tns_modules')) {
const nonTnsModulesName = name.substr('tns_modules'.length + 1);
if (Trace.isEnabled()) {
Trace.write(
`[Compat] Register module: ${nonTnsModulesName}`,
Trace.categories.ModuleNameResolver
);
Trace.write(`[Compat] Register module: ${nonTnsModulesName}`, Trace.categories.ModuleNameResolver);
}
global.registerModule(nonTnsModulesName, loader);
}
}
function processFile(file: fs.File) {
const filePathRelativeToApp = file.path.substr(
fs.knownFolders.currentApp().path.length + 1
);
const filePathRelativeToApp = file.path.substr(fs.knownFolders.currentApp().path.length + 1);
const loadContent = () => file.readTextSync();
switch (file.extension.toLocaleLowerCase()) {
case '.js': {
const noExtPath = filePathRelativeToApp.substr(
0,
filePathRelativeToApp.length - '.js'.length
);
const noExtPath = filePathRelativeToApp.substr(0, filePathRelativeToApp.length - '.js'.length);
register(filePathRelativeToApp, function () {
return global.require(file.path);
@ -57,10 +49,7 @@ function processFile(file: fs.File) {
if (file.name === 'package.json') {
const json = global.require(file.path);
if (json.main) {
const name = filePathRelativeToApp.substr(
0,
filePathRelativeToApp.length - 'package.json'.length - 1
);
const name = filePathRelativeToApp.substr(0, filePathRelativeToApp.length - 'package.json'.length - 1);
const requirePath = fs.path.join(file.parent.path, json.main);
register(name, () => global.require(requirePath));
@ -79,10 +68,7 @@ function processFolder(path: string): boolean {
cache.add(path);
if (Trace.isEnabled()) {
Trace.write(
`[Compat] Processing folder: ${path}`,
Trace.categories.ModuleNameResolver
);
Trace.write(`[Compat] Processing folder: ${path}`, Trace.categories.ModuleNameResolver);
}
let folderEmpty = true;
@ -134,22 +120,14 @@ export function registerModulesFromFileSystem(moduleName: string) {
}
// moduleName is a folder in tns_modules ex. "nativescript-ui-chart"
const tnsModulesPath = fs.path.join(
fs.knownFolders.currentApp().path,
'tns_modules',
moduleName
);
const tnsModulesPath = fs.path.join(fs.knownFolders.currentApp().path, 'tns_modules', moduleName);
if (fs.Folder.exists(tnsModulesPath)) {
processFolder(tnsModulesPath);
}
// moduleName a file in tns_modules/plugin. Avoid traversing the whole tns_modules folder if parentName is empty
if (parentName) {
const tnsParentFolderPath = fs.path.join(
fs.knownFolders.currentApp().path,
'tns_modules',
parentName
);
const tnsParentFolderPath = fs.path.join(fs.knownFolders.currentApp().path, 'tns_modules', parentName);
if (fs.Folder.exists(tnsParentFolderPath)) {
processFolder(tnsParentFolderPath);
}