Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[expo-cli] Added profiling #3217

Merged
merged 2 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions packages/expo-cli/src/commands/utils/typescript/resolveModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Glob } from 'glob';
import * as path from 'path';
import resolveFrom from 'resolve-from';

import Log from '../../../log';

async function fileExistsAsync(file: string): Promise<boolean> {
return (await stat(file).catch(() => null))?.isFile() ?? false;
}
Expand All @@ -17,14 +19,20 @@ const requiredPackages = [

export const baseTSConfigName = 'expo/tsconfig.base';

export function queryFirstProjectTypeScriptFileAsync(projectRoot: string): Promise<null | string> {
// Bail out as soon as a single match is found.
return new Promise((resolve, reject) => {
export async function queryFirstProjectTypeScriptFileAsync(
projectRoot: string
): Promise<null | string> {
Log.time('queryFirstProjectTypeScriptFileAsync');
const results = await new Promise<null | string>((resolve, reject) => {
const mg = new Glob(
'**/*.{ts,tsx}',
'**/*.@(ts|tsx)',
{
cwd: projectRoot,
ignore: ['**/@(Carthage|Pods|node_modules)/**', '**/*.d.ts', '/{ios,android}/**'],
ignore: [
'**/@(Carthage|Pods|node_modules)/**',
'**/*.d.ts',
'@(ios|android|web|web-build|dist)/**',
],
},
(error, matches) => {
if (error) {
Expand All @@ -39,6 +47,9 @@ export function queryFirstProjectTypeScriptFileAsync(projectRoot: string): Promi
resolve(matched);
});
});
Log.timeEnd('queryFirstProjectTypeScriptFileAsync');
// Bail out as soon as a single match is found.
return results;
}

export function resolveBaseTSConfig(projectRoot: string): string | null {
Expand Down
12 changes: 12 additions & 0 deletions packages/expo-cli/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ import terminalLink from 'terminal-link';

type Color = (...text: string[]) => string;

const isProfiling = boolish('EXPO_PROFILE', false);

// eslint-disable-next-line no-console
const consoleTime: (label?: string) => void = isProfiling ? console.time : () => {};
// eslint-disable-next-line no-console
const consoleTimeEnd: (label?: string) => void = isProfiling ? console.timeEnd : () => {};

export default class Log {
public static readonly chalk = chalk;
public static readonly terminalLink = terminalLink;
public static readonly isDebug = boolish('EXPO_DEBUG', false);
public static readonly isProfiling = isProfiling;

public static log(...args: any[]) {
Log.respectProgressBars(() => {
Expand All @@ -23,6 +31,10 @@ export default class Log {
});
}

public static time = consoleTime;

public static timeEnd = consoleTimeEnd;

public static newLine() {
Log.respectProgressBars(() => {
Log.consoleLog();
Expand Down