Skip to content

Commit

Permalink
Upgrade tachometer to ES modules, and update dependencies (#239)
Browse files Browse the repository at this point in the history
- Updates to ES modules, so Node 12 is now required.
- Updates all dependencies.
- Updates import styles for ESM.
  • Loading branch information
aomarks authored Jul 15, 2022
1 parent ef7c3f1 commit e6c340a
Show file tree
Hide file tree
Showing 40 changed files with 1,271 additions and 1,146 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
project adheres to [Semantic Versioning](http://semver.org/).

<!-- ## Unreleased -->
## Unreleased

- [**BREAKING**] Tachometer is now an ES module binary, so it requires Node 12
or higher.
- Upgraded dependencies and removed unnecessary ones.

## [0.6.0] 2022-07-01

Expand Down
4 changes: 2 additions & 2 deletions bin/tach.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

// eslint-disable-next-line @typescript-eslint/no-var-requires
require('../lib/cli.js').main(process.argv);
import {main} from '../lib/cli.js';
main(process.argv);
2,036 changes: 1,061 additions & 975 deletions package-lock.json

Large diffs are not rendered by default.

30 changes: 14 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"directories": {
"lib": "lib"
},
"type": "module",
"bin": {
"tach": "bin/tach.js",
"tachometer": "bin/tach.js"
Expand Down Expand Up @@ -37,16 +38,13 @@
"chromedriver"
],
"dependencies": {
"@types/command-line-usage": "^5.0.1",
"@types/selenium-webdriver": "^4.0.11",
"@types/table": "^6.0.0",
"ansi-escape-sequences": "^6.0.1",
"command-line-args": "^5.0.2",
"command-line-usage": "^6.1.0",
"csv-stringify": "^5.3.0",
"csv-stringify": "^6.2.0",
"fs-extra": "^10.0.0",
"get-stream": "^6.0.0",
"got": "^11.5.0",
"got": "^12.1.0",
"jsonschema": "^1.4.0",
"jsonwebtoken": "^8.5.1",
"jstat": "^1.9.2",
Expand All @@ -57,26 +55,25 @@
"koa-send": "^5.0.0",
"koa-static": "^5.0.0",
"pkg-install": "^1.0.0",
"pkg-up": "^3.1.0",
"pkg-up": "^4.0.0",
"progress": "^2.0.3",
"sanitize-filename": "^1.6.3",
"selenium-webdriver": "^4.0.0-alpha.8",
"semver": "^7.1.1",
"source-map-support": "^0.5.16",
"strip-ansi": "^6.0.0",
"strip-ansi": "^7.0.1",
"systeminformation": "^5.3.3",
"table": "^6.0.7",
"ua-parser-js": "^0.7.19"
"ua-parser-js": "^1.0.2"
},
"devDependencies": {
"@types/ansi-escape-sequences": "^4.0.0",
"@types/babel__generator": "^7.6.1",
"@types/chai": "^4.2.4",
"@types/chai-as-promised": "^7.1.2",
"@types/command-line-args": "^5.0.0",
"@types/csv-stringify": "^3.1.0",
"@types/command-line-usage": "^5.0.1",
"@types/fs-extra": "^9.0.1",
"@types/get-stream": "^3.0.2",
"@types/got": "^9.6.8",
"@types/jsonwebtoken": "^8.3.5",
"@types/koa": "^2.0.51",
Expand All @@ -88,20 +85,21 @@
"@types/node-fetch": "^2.5.3",
"@types/progress": "^2.0.3",
"@types/rimraf": "^3.0.0",
"@types/selenium-webdriver": "^4.0.11",
"@types/semver": "^7.3.1",
"@types/source-map-support": "^0.5.4",
"@types/ua-parser-js": "^0.7.32",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"eslint": "^7.32.0",
"eslint": "^8.19.0",
"eslint-plugin-no-only-tests": "^2.6.0",
"mocha": "^9.1.1",
"node-fetch": "^2.6.0",
"mocha": "^10.0.0",
"node-fetch": "^3.2.8",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
"typescript": "^4.0.2",
"typescript-json-schema": "^0.51.0"
"typescript-json-schema": "^0.54.0"
}
}
12 changes: 6 additions & 6 deletions src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/

import * as webdriver from 'selenium-webdriver';
import * as chrome from 'selenium-webdriver/chrome';
import * as edge from 'selenium-webdriver/edge';
import * as firefox from 'selenium-webdriver/firefox';
import * as chrome from 'selenium-webdriver/chrome.js';
import * as edge from 'selenium-webdriver/edge.js';
import * as firefox from 'selenium-webdriver/firefox.js';

import {installOnDemand} from './install';
import {isHttpUrl} from './util';
import {installOnDemand} from './install.js';
import {isHttpUrl} from './util.js';

/** Tachometer browser names. Often but not always equal to WebDriver's. */
export type BrowserName = 'chrome' | 'firefox' | 'safari' | 'edge' | 'ie';
Expand Down Expand Up @@ -181,7 +181,7 @@ export async function makeDriver(

if (webdriverModuleName != null) {
await installOnDemand(webdriverModuleName);
require(webdriverModuleName);
await import(webdriverModuleName);
}

const builder = new webdriver.Builder();
Expand Down
23 changes: 13 additions & 10 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@ sourceMapSupport.install();

import * as path from 'path';
import ansi from 'ansi-escape-sequences';
import * as semver from 'semver';
import semver from 'semver';

import commandLineUsage from 'command-line-usage';

import {optDefs, parseFlags} from './flags';
import {BenchmarkSpec} from './types';
import {makeConfig} from './config';
import {Server} from './server';
import {ResultStatsWithDifferences} from './stats';
import {optDefs, parseFlags} from './flags.js';
import {BenchmarkSpec} from './types.js';
import {makeConfig} from './config.js';
import {Server} from './server.js';
import {ResultStatsWithDifferences} from './stats.js';
import {
prepareVersionDirectory,
makeServerPlans,
installGitDependency,
} from './versions';
import {manualMode} from './manual';
import {Runner} from './runner';
import {runNpm} from './util';
} from './versions.js';
import {manualMode} from './manual.js';
import {Runner} from './runner.js';
import {runNpm} from './util.js';

import {createRequire} from 'module';
const require = createRequire(import.meta.url);

const installedVersion = (): string =>
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down
20 changes: 10 additions & 10 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

import * as fsExtra from 'fs-extra';
import fsExtra from 'fs-extra';
import * as path from 'path';

import {fcpBrowsers} from './browser';
import {parseConfigFile, writeBackSchemaIfNeeded} from './configfile';
import * as defaults from './defaults';
import {Opts} from './flags';
import {CheckConfig, parseGithubCheckFlag} from './github';
import {specsFromOpts} from './specs';
import {AutoSampleConditions} from './stats';
import {BenchmarkSpec} from './types';
import {fileKind} from './util';
import {fcpBrowsers} from './browser.js';
import {parseConfigFile, writeBackSchemaIfNeeded} from './configfile.js';
import * as defaults from './defaults.js';
import {Opts} from './flags.js';
import {CheckConfig, parseGithubCheckFlag} from './github.js';
import {specsFromOpts} from './specs.js';
import {AutoSampleConditions} from './stats.js';
import {BenchmarkSpec} from './types.js';
import {fileKind} from './util.js';

/**
* Validated and fully specified configuration.
Expand Down
16 changes: 9 additions & 7 deletions src/configfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

import * as fsExtra from 'fs-extra';
import fsExtra from 'fs-extra';
import * as jsonschema from 'jsonschema';
import * as path from 'path';
import sanitizeFileName from 'sanitize-filename';
import {createRequire} from 'module';
const require = createRequire(import.meta.url);

import {
BrowserConfig,
BrowserName,
parseBrowserConfigString,
validateBrowserConfig,
} from './browser';
import {Config, parseAutoSampleConditions, urlFromLocalPath} from './config';
import * as defaults from './defaults';
import {makeUniqueSpecLabelFn} from './format';
} from './browser.js';
import {Config, parseAutoSampleConditions, urlFromLocalPath} from './config.js';
import * as defaults from './defaults.js';
import {makeUniqueSpecLabelFn} from './format.js';
import {
BenchmarkSpec,
ExtendedPackageDependencyMap,
Measurement,
measurements,
} from './types';
import {isHttpUrl} from './util';
} from './types.js';
import {isHttpUrl} from './util.js';

/**
* Expected format of the top-level JSON config file. Note this interface is
Expand Down
4 changes: 2 additions & 2 deletions src/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

import csvStringify from 'csv-stringify/lib/sync';
import {stringify as csvStringify} from 'csv-stringify/sync';

import {ResultStatsWithDifferences} from './stats';
import {ResultStatsWithDifferences} from './stats.js';

const precision = 5;

Expand Down
4 changes: 2 additions & 2 deletions src/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*/

import * as path from 'path';
import {BrowserName} from './browser';
import {LocalUrl, Measurement, RemoteUrl} from './types';
import {BrowserName} from './browser.js';
import {LocalUrl, Measurement, RemoteUrl} from './types.js';

export const windowWidth = 1024;
export const windowHeight = 768;
Expand Down
10 changes: 5 additions & 5 deletions src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import * as os from 'os';
import * as path from 'path';

import {supportedBrowsers} from './browser';
import * as defaults from './defaults';
import {CommandLineMeasurements, measurements} from './types';
import {supportedBrowsers} from './browser.js';
import * as defaults from './defaults.js';
import {CommandLineMeasurements, measurements} from './types.js';

import commandLineArgs = require('command-line-args');
import commandLineUsage = require('command-line-usage');
import commandLineArgs from 'command-line-args';
import commandLineUsage from 'command-line-usage';

export const defaultInstallDir = path.join(
os.tmpdir(),
Expand Down
9 changes: 4 additions & 5 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

import stripAnsi = require('strip-ansi');
import stripAnsi from 'strip-ansi';
import * as table from 'table';
import {UAParser} from 'ua-parser-js';

import ansi = require('ansi-escape-sequences');
import ansi from 'ansi-escape-sequences';

import {
Difference,
ConfidenceInterval,
ResultStats,
ResultStatsWithDifferences,
} from './stats';
import {BenchmarkSpec, BenchmarkResult} from './types';
} from './stats.js';
import {BenchmarkSpec, BenchmarkResult} from './types.js';

export const spinner = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'].map(
(frame) => ansi.format(`[blue]{${frame}}`)
Expand Down
7 changes: 5 additions & 2 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import {promisify} from 'util';
import {promises as fs} from 'fs';
import path from 'path';
import {install} from 'pkg-install';
import pkgUp from 'pkg-up';
import {pkgUp} from 'pkg-up';

const execPromise = promisify(exec);

import * as url from 'url';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

export type OnDemandDependencies = Map<string, string>;

/**
Expand All @@ -38,7 +41,7 @@ export interface ContainsOnDemandDependencies {
installsOnDemand?: string[];
}

export const getPackageJSONPath = async (): Promise<string | null> => {
export const getPackageJSONPath = async (): Promise<string | undefined> => {
// NOTE: This used to search starting with module.path, but module.path was
// not added until Node.js v11. In order to preserve Node.js v10 compatibility
// we use __dirname instead, which should be mostly the same thing (docs are
Expand Down
8 changes: 4 additions & 4 deletions src/json-output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import * as systeminformation from 'systeminformation';

import {BrowserConfig} from './browser';
import {measurementName} from './measure';
import {ResultStatsWithDifferences} from './stats';
import {BenchmarkResult, Measurement} from './types';
import {BrowserConfig} from './browser.js';
import {measurementName} from './measure.js';
import {ResultStatsWithDifferences} from './stats.js';
import {BenchmarkResult, Measurement} from './types.js';

export interface JsonOutputFile {
benchmarks: Benchmark[];
Expand Down
11 changes: 5 additions & 6 deletions src/manual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

import ansi = require('ansi-escape-sequences');

import {Server} from './server';
import {Config} from './config';
import {specUrl} from './specs';
import {BenchmarkSpec} from './types';
import ansi from 'ansi-escape-sequences';
import {Server} from './server.js';
import {Config} from './config.js';
import {specUrl} from './specs.js';
import {BenchmarkSpec} from './types.js';

/**
* Let the user run benchmarks manually. This process will not exit until
Expand Down
6 changes: 3 additions & 3 deletions src/measure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import * as webdriver from 'selenium-webdriver';

import {Server} from './server';
import {Measurement, PerformanceEntryMeasurement} from './types';
import {throwUnreachable} from './util';
import {Server} from './server.js';
import {Measurement, PerformanceEntryMeasurement} from './types.js';
import {throwUnreachable} from './util.js';

/**
* Try to take a measurement in milliseconds from the given browser. Returns
Expand Down
Loading

0 comments on commit e6c340a

Please sign in to comment.