Skip to content

Commit

Permalink
[tools] add and hook up lint setup, remove module-scripts (expo#16974)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simek authored Apr 11, 2022
1 parent 3600f66 commit a272999
Show file tree
Hide file tree
Showing 93 changed files with 1,017 additions and 3,606 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/expotools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ jobs:
- name: 🛠 Compile TypeScript sources
run: yarn tsc
working-directory: tools
- name: 🚨 Lint TypeScript sources
run: yarn lint --max-warnings 0
working-directory: tools
13 changes: 11 additions & 2 deletions tools/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
// @generated by expo-module-scripts
module.exports = require('expo-module-scripts/eslintrc.base.js');
module.exports = {
root: true,
extends: ['universe/node'],
plugins: ['lodash'],
rules: {
'lodash/import-scope': [2, 'method'],
// note(simek): I'm not brave enough to touch the RegExps I did not write,
// if you are, feel free to remove line below and fix the reported issues
'no-useless-escape': 0
},
};
9 changes: 6 additions & 3 deletions tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"watch": "tsc --watch",
"clean": "rm -rf build cache",
"et": "bin/expotools.js",
"postinstall": "expo-module configure"
"lint": "eslint ./src"
},
"bin": {
"et": "bin/expotools.js",
Expand Down Expand Up @@ -96,14 +96,17 @@
"@types/klaw-sync": "^6.0.1",
"@types/node": "^14.18.12",
"@types/node-fetch": "^2.6.1",
"@types/request-promise-native": "^1.0.18",
"@types/semver": "^7.3.9",
"@types/server-destroy": "^1.0.1",
"@types/source-map-support": "^0.5.4",
"@types/uuid": "^3.4.4",
"@types/ws": "^7.4.7",
"babel-preset-expo": "^9.0.2",
"expo-module-scripts": "^2.0.0",
"prettier": "^2.3.1",
"eslint": "^8.12.0",
"eslint-config-universe": "11.0.0-beta.0",
"eslint-plugin-lodash": "^7.4.0",
"prettier": "^2.6.2",
"typescript": "~4.4.4"
}
}
4 changes: 2 additions & 2 deletions tools/src/Changelogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class Changelog {
try {
const markdown = await fs.readFile(this.filePath, 'utf8');
this.tokens = Markdown.lexify(markdown);
} catch (error) {
} catch {
this.tokens = [];
}
}
Expand Down Expand Up @@ -545,7 +545,7 @@ export class MemChangelog extends Changelog {
if (!this.tokens) {
try {
this.tokens = Markdown.lexify(this.content);
} catch (error) {
} catch {
this.tokens = [];
}
}
Expand Down
1 change: 1 addition & 0 deletions tools/src/CocoaPods.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { StdioOptions } from 'child_process';

import { spawnAsync, spawnJSONCommandAsync } from './Utils';

/**
Expand Down
2 changes: 1 addition & 1 deletion tools/src/Codegen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import spawnAsync from '@expo/spawn-async';
import fs from 'fs-extra';
import path from 'path';
import spawnAsync from '@expo/spawn-async';

export interface ReactNativeCodegenParameters {
// path to `react-native` package
Expand Down
2 changes: 1 addition & 1 deletion tools/src/ExpoCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export async function runExpoCliAsync(
args: string[] = [],
options: Options = {}
): Promise<void> {
let configArgs = options.root ? ['--config', path.resolve(options.root, 'app.json')] : [];
const configArgs = options.root ? ['--config', path.resolve(options.root, 'app.json')] : [];

// Don't handle SIGINT/SIGTERM in this process...defer to expo-cli
process.on('SIGINT', () => {});
Expand Down
2 changes: 1 addition & 1 deletion tools/src/FirebaseTestLab.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import spawnAsync from '@expo/spawn-async';
import path from 'path';

import { getExpoRepositoryRootDir } from './Directories';

Expand Down
2 changes: 1 addition & 1 deletion tools/src/Formatter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import chalk from 'chalk';
import path from 'path';
import terminalLink from 'terminal-link';

import { GitLog, GitFileLog } from './Git';
Expand Down
4 changes: 2 additions & 2 deletions tools/src/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fs from 'fs-extra';
import parseDiff from 'parse-diff';
import { join, relative } from 'path';

import { spawnAsync, SpawnResult, SpawnOptions } from './Utils';
import { EXPO_DIR } from './Constants';
import { spawnAsync, SpawnResult, SpawnOptions } from './Utils';

export type GitPullOptions = {
rebase?: boolean;
Expand Down Expand Up @@ -97,7 +97,7 @@ export class GitDirectory {
try {
await this.runAsync(args, options);
return true;
} catch (error) {
} catch {
return false;
}
}
Expand Down
11 changes: 6 additions & 5 deletions tools/src/GitHubActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ const octokit = new Octokit({
const owner = 'expo';
const repo = 'expo';

export type Workflow = RestEndpointMethodTypes['actions']['listRepoWorkflows']['response']['data']['workflows'][0] & {
slug: string;
baseSlug: string;
inputs?: Record<string, string>;
};
export type Workflow =
RestEndpointMethodTypes['actions']['listRepoWorkflows']['response']['data']['workflows'][0] & {
slug: string;
baseSlug: string;
inputs?: Record<string, string>;
};

export type WorkflowDispatchEventInputs = Record<string, string>;

Expand Down
30 changes: 15 additions & 15 deletions tools/src/HashDirectory.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import globby from 'globby';
import path from 'path';
import spawnAsync from '@expo/spawn-async';
import fs from 'fs';
import _ from 'lodash';
import globby from 'globby';
import hashFiles from 'hash-files';
import spawnAsync from '@expo/spawn-async';
import trim from 'lodash/trim';
import path from 'path';

import * as Directories from './Directories';

export async function getListOfFilesAsync(directory: string): Promise<string[]> {
let expoGitignore = fs.readFileSync(
const expoGitignore = fs.readFileSync(
path.join(Directories.getExpoRepositoryRootDir(), '.gitignore'),
'utf8'
);
let directoryGitignore = '';
try {
directoryGitignore = fs.readFileSync(path.join(directory, '.gitignore'), 'utf8');
} catch (e) {
} catch {
// Don't worry if we can't find this gitignore
}
let gitignoreLines = [...expoGitignore.split('\n'), ...directoryGitignore.split('\n')].filter(
const gitignoreLines = [...expoGitignore.split('\n'), ...directoryGitignore.split('\n')].filter(
(line) => {
return _.trim(line).length > 0 && !_.trim(line).startsWith('#');
return trim(line).length > 0 && !trim(line).startsWith('#');
}
);

let gitignoreGlobPatterns: string[] = [];
const gitignoreGlobPatterns: string[] = [];

gitignoreLines.forEach((line) => {
// Probably doesn't cover every gitignore possiblity but works better than the gitignore-to-glob
Expand All @@ -46,7 +46,7 @@ export async function getListOfFilesAsync(directory: string): Promise<string[]>
gitignoreGlobPatterns.push(firstCharacter + '/**' + line + '/**');
});

let files = await globby(['**', ...gitignoreGlobPatterns], {
const files = await globby(['**', ...gitignoreGlobPatterns], {
cwd: directory,
});
return files.map((file) => path.resolve(directory, file));
Expand All @@ -65,8 +65,8 @@ export async function hashFilesAsync(options: { [key: string]: any }): Promise<s
}

export async function hashDirectoryAsync(directory: string): Promise<string> {
let files = await getListOfFilesAsync(directory);
let hash = await hashFilesAsync({
const files = await getListOfFilesAsync(directory);
const hash = await hashFilesAsync({
files,
noGlob: true,
});
Expand All @@ -76,15 +76,15 @@ export async function hashDirectoryAsync(directory: string): Promise<string> {

export async function hashDirectoryWithVersionsAsync(directory: string): Promise<string> {
// Add Node and Yarn versions to the hash
let yarnVersion = (await spawnAsync('yarn', ['--version'])).stdout;
let metadataFilename = path.join(directory, 'HASH_DIRECTORY_METADATA');
const yarnVersion = (await spawnAsync('yarn', ['--version'])).stdout;
const metadataFilename = path.join(directory, 'HASH_DIRECTORY_METADATA');
fs.writeFileSync(
metadataFilename,
`NODE_VERSION=${process.version}
YARN_VERSION=${yarnVersion}`
);

let hash = await hashDirectoryAsync(directory);
const hash = await hashDirectoryAsync(directory);

fs.unlinkSync(metadataFilename);
return hash;
Expand Down
8 changes: 4 additions & 4 deletions tools/src/IOSSimulator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import spawnAsync from '@expo/spawn-async';
import { spawn } from 'child_process';
import { Transform, TransformCallback, TransformOptions } from 'stream';
import spawnAsync from '@expo/spawn-async';

/**
* Starts an arbitrary iOS simulator so that simctl can reference a "booted" simulator.
Expand All @@ -23,7 +23,7 @@ export async function installSimulatorAppAsync(
try {
await spawnAsync('xcrun', ['simctl', 'install', simulatorId, archivePath]);
} catch (e) {
let error = new Error(e.stderr);
const error = new Error(e.stderr);
(error as any).status = e.status;
throw error;
}
Expand All @@ -36,7 +36,7 @@ export async function launchSimulatorAppAsync(
try {
await spawnAsync('xcrun', ['simctl', 'launch', simulatorId, bundleIdentifier]);
} catch (e) {
let error = new Error(e.stderr);
const error = new Error(e.stderr);
(error as any).status = e.status;
throw error;
}
Expand Down Expand Up @@ -72,7 +72,7 @@ export class IOSLogStream extends Transform {
let entry;
try {
entry = JSON.parse(data.toString('utf8'));
} catch (e) {}
} catch {}

if (entry?.eventMessage) {
this.push(entry);
Expand Down
14 changes: 7 additions & 7 deletions tools/src/IOSSimulatorTestSuite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export async function runTestSuiteOnIOSSimulatorAsync(simulatorId, archivePath,
console.log(`Installing test-suite on the simulator`);
await IOSSimulator.installSimulatorAppAsync(simulatorId, path.resolve(archivePath));
console.log(`Streaming logs from the simulator`);
let resultsPromise = _streamSimulatorLogsAsync(simulatorId);
const resultsPromise = _streamSimulatorLogsAsync(simulatorId);
console.log(`Launching the test-suite app and waiting for tests to complete`);
await IOSSimulator.launchSimulatorAppAsync(simulatorId, TEST_SUITE_BUNDLE_ID);

let results = await resultsPromise;
const results = await resultsPromise;
if (results.failed === 0) {
console.log(`😊 All tests passed`);
} else {
Expand All @@ -45,11 +45,11 @@ export async function runTestSuiteOnIOSSimulatorAsync(simulatorId, archivePath,

function _streamSimulatorLogsAsync(simulatorId: string): Promise<TestSuiteResults> {
return new Promise((resolve, reject) => {
let logProcess = IOSSimulator.getSimulatorLogProcess(
const logProcess = IOSSimulator.getSimulatorLogProcess(
simulatorId,
'(subsystem == "host.exp.Exponent") && (category == "test")'
);
let logStream = new IOSSimulator.IOSLogStream();
const logStream = new IOSSimulator.IOSLogStream();
logProcess.stdout.pipe(logStream);

logStream.on('data', (entry) => {
Expand All @@ -63,8 +63,8 @@ function _streamSimulatorLogsAsync(simulatorId: string): Promise<TestSuiteResult
try {
logStream.removeAllListeners('data');

let resultsJson = entry.eventMessage.substring(TEST_SUITE_END_SENTINEL.length).trim();
let results = JSON.parse(resultsJson);
const resultsJson = entry.eventMessage.substring(TEST_SUITE_END_SENTINEL.length).trim();
const results = JSON.parse(resultsJson);
resolve(results);
} catch (e) {
reject(e);
Expand All @@ -77,7 +77,7 @@ function _streamSimulatorLogsAsync(simulatorId: string): Promise<TestSuiteResult
}

function _writeJUnitReport(results: TestSuiteResults, reportPath: string): void {
let builder = JUnitReportBuilder.newBuilder();
const builder = JUnitReportBuilder.newBuilder();
// let suite = builder.testSuite().name('Test Suite');

// TODO: parse the results
Expand Down
2 changes: 1 addition & 1 deletion tools/src/Markdown.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unescape } from 'lodash';
import unescape from 'lodash/unescape';
import marked from 'marked';

export enum TokenType {
Expand Down
4 changes: 2 additions & 2 deletions tools/src/Npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function getPackageViewAsync(
version ? `${packageName}@${version}` : packageName,
'--json',
]);
} catch (error) {
} catch {
return null;
}
}
Expand Down Expand Up @@ -101,7 +101,7 @@ export async function whoamiAsync(): Promise<string | null> {
try {
const { stdout } = await spawnAsync('npm', ['whoami']);
return stdout.trim();
} catch (e) {
} catch {
return null;
}
}
2 changes: 1 addition & 1 deletion tools/src/Packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ function readExpoModuleConfigJson(dir: string) {
const unimoduleJsonPath = path.join(dir, 'unimodule.json');
try {
return require(expoModuleConfigJsonExists ? expoModuleConfigJsonPath : unimoduleJsonPath);
} catch (error) {
} catch {
return null;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tools/src/ProjectVersions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'path';
import JsonFile from '@expo/json-file';
import fs from 'fs-extra';
import path from 'path';
import plist from 'plist';
import semver from 'semver';
import JsonFile from '@expo/json-file';

import { EXPO_DIR, ANDROID_DIR, PACKAGES_DIR } from './Constants';

Expand Down
Loading

0 comments on commit a272999

Please sign in to comment.