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

Commit

Permalink
[expo-cli] Added profiling (#3217)
Browse files Browse the repository at this point in the history
* Improve TS globs

* Added profiling
  • Loading branch information
EvanBacon authored Feb 12, 2021
1 parent d70a7a8 commit 5a32e00
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
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

0 comments on commit 5a32e00

Please sign in to comment.