Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to eslint unicorn 54 #2154

Merged
merged 1 commit into from
Jul 6, 2024
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
9 changes: 6 additions & 3 deletions bin/browsertime.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import get from 'lodash.get';
import set from 'lodash.set';
import intel from 'intel';
import { existsSync, mkdirSync } from 'node:fs';
import { resolve, relative } from 'node:path';
import path from 'node:path';
import { Engine } from '../lib/core/engine/index.js';
import {
findAndParseScripts,
Expand All @@ -25,7 +25,7 @@ async function parseUserScripts(scripts) {
if (!Array.isArray(scripts)) scripts = [scripts];
const results = {};
for (const script of scripts) {
const code = await findAndParseScripts(resolve(script), 'custom');
const code = await findAndParseScripts(path.resolve(script), 'custom');
merge(results, code);
}
return results;
Expand Down Expand Up @@ -125,7 +125,10 @@ async function run(urls, options) {

await Promise.all(saveOperations);

const resultDirectory = relative(process.cwd(), storageManager.directory);
const resultDirectory = path.relative(
process.cwd(),
storageManager.directory
);

// check for errors
// If we have set the exit code in scripts, respect that
Expand Down
6 changes: 3 additions & 3 deletions lib/android/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { promisify } from 'node:util';
import { mkdir as _mkdir, createWriteStream } from 'node:fs';
import { join } from 'node:path';
import path from 'node:path';
import { EOL as endOfLine } from 'node:os';
import { execa } from 'execa';
import intel from 'intel';
Expand Down Expand Up @@ -105,7 +105,7 @@ export class Android {

for (const file of files) {
const fullSourcePath = `${sourcePath}/${file.name}`;
const fullDestinationPath = join(destinationPath, file.name);
const fullDestinationPath = path.join(destinationPath, file.name);

if (file.isFile()) {
await this._downloadFile(fullSourcePath, fullDestinationPath);
Expand Down Expand Up @@ -475,7 +475,7 @@ export class Android {

async getUsbPowerUsageProfile(index, url, result, options, storageManager) {
let profileData = await usbPowerProfiler.profileFromData();
let destinationFilename = join(
let destinationFilename = path.join(
await pathToFolder(url, options),
`powerProfile-${index}.json`
);
Expand Down
10 changes: 5 additions & 5 deletions lib/chrome/webdriver/chromium.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { promisify } from 'node:util';
import { unlink as _unlink, rm as _rm } from 'node:fs';
import { join } from 'node:path';
import path from 'node:path';
import { logging } from 'selenium-webdriver';
import intel from 'intel';
import usbPowerProfiler from 'usb-power-profiling/usb-power-profiling.js';
Expand Down Expand Up @@ -261,12 +261,12 @@ export class Chromium {

if (this.chrome.collectNetLog && !this.chrome.android) {
await this.storageManager.createSubDataDir(
join(pathToFolder(result.url, this.options))
path.join(pathToFolder(result.url, this.options))
);

await this.storageManager.gzip(
`${this.baseDir}/chromeNetlog.json`,
join(
path.join(
this.baseDir,
pathToFolder(result.url, this.options),
`chromeNetlog-${index}.json.gz`
Expand Down Expand Up @@ -350,13 +350,13 @@ export class Chromium {

if (this.chrome.collectNetLog && this.chrome.android) {
// THIS needs to be unique per page
const filename = join(
const filename = path.join(
this.baseDir,
pathToFolder(result.url, this.options),
`chromeNetlog-${index}.json`
);

const gzFilename = join(
const gzFilename = path.join(
this.baseDir,
pathToFolder(result.url, this.options),
`chromeNetlog-${index}.json.gz`
Expand Down
4 changes: 2 additions & 2 deletions lib/core/engine/collector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from 'node:path';
import path from 'node:path';
import { createRequire } from 'node:module';
import get from 'lodash.get';
import intel from 'intel';
Expand Down Expand Up @@ -482,7 +482,7 @@ export class Collector {
for (let filename of Object.keys(data.extraJson)) {
extraWork.push(
this.storageManager.writeJson(
join(pathToFolder(url, this.options), filename),
path.join(pathToFolder(url, this.options), filename),
data.extraJson[filename],
true
)
Expand Down
4 changes: 2 additions & 2 deletions lib/core/engine/command/measure.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from 'node:path';
import path from 'node:path';
import intel from 'intel';
import get from 'lodash.get';
import merge from 'lodash.merge';
Expand Down Expand Up @@ -429,7 +429,7 @@ export class Measure {

// We have the URL, create the data dir
await this.storageManager.createSubDataDir(
join(pathToFolder(url, this.options))
path.join(pathToFolder(url, this.options))
);
await this._stopVideo(url);

Expand Down
4 changes: 2 additions & 2 deletions lib/core/engine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export class Engine {
}
}

return Promise.all([this.myXVFB.start()]);
return this.myXVFB.start();
}

async runByScript(
Expand Down Expand Up @@ -518,6 +518,6 @@ export class Engine {
await this.gnirehtet.stop();
}

return Promise.all([this.myXVFB.stop()]);
return this.myXVFB.stop();
}
}
17 changes: 12 additions & 5 deletions lib/firefox/geckoProfiler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from 'node:path';
import path from 'node:path';
import get from 'lodash.get';
import intel from 'intel';
import { geckoProfilerDefaults } from './settings/geckoProfilerDefaults.js';
Expand Down Expand Up @@ -156,9 +156,12 @@ export class GeckoProfiler {
const options = this.options;

let profileDir = await storageManager.createSubDataDir(
join(pathToFolder(url, options))
path.join(pathToFolder(url, options))
);
let destinationFilename = path.join(
profileDir,
`geckoProfile-${index}.json`
);
let destinationFilename = join(profileDir, `geckoProfile-${index}.json`);

let deviceProfileFilename = destinationFilename;
if (isAndroidConfigured(options)) {
Expand Down Expand Up @@ -214,7 +217,7 @@ export class GeckoProfiler {
const profile = JSON.parse(
await storageManager.readData(
`geckoProfile-${index}.json`,
join(pathToFolder(url, options))
path.join(pathToFolder(url, options))
)
);
let power = 0;
Expand All @@ -237,7 +240,11 @@ export class GeckoProfiler {
? `geckoProfile-${index}-extra.json.gz`
: `geckoProfile-${index}.json.gz`;
await timeout(
storageManager.gzip(destinationFilename, join(profileDir, name), true),
storageManager.gzip(
destinationFilename,
path.join(profileDir, name),
true
),
300_000, // 5 minutes
'Could not gzip the profile.'
);
Expand Down
6 changes: 3 additions & 3 deletions lib/firefox/webdriver/firefox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { rename as _rename } from 'node:fs';
import { promisify } from 'node:util';
import { join } from 'node:path';
import path from 'node:path';
import intel from 'intel';
import get from 'lodash.get';
import usbPowerProfiler from 'usb-power-profiling/usb-power-profiling.js';
Expand Down Expand Up @@ -312,7 +312,7 @@ export class Firefox {
for (const file of files) {
await rename(
`${this.baseDir}/${file}`,
join(
path.join(
this.baseDir,
pathToFolder(result.url, this.options),
`${file}-${index}.txt`
Expand Down Expand Up @@ -358,7 +358,7 @@ export class Firefox {
geckoProfile.meta.visualMetrics = result.visualMetrics;

await this.storageManager.writeJson(
join(profileSubdir, `geckoProfile-${index}.json`),
path.join(profileSubdir, `geckoProfile-${index}.json`),
geckoProfile,
true
);
Expand Down
8 changes: 4 additions & 4 deletions lib/screenshot/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from 'node:path';
import path from 'node:path';
import merge from 'lodash.merge';
import intel from 'intel';
import { screenshotDefaults } from './defaults.js';
Expand Down Expand Up @@ -36,7 +36,7 @@ export class ScreenshotManager {
data,
url,
this.storageManager,
join(SCREENSHOT_DIR, `${index}`),
path.join(SCREENSHOT_DIR, `${index}`),
this.options
);
this.savedScreenshots.push(
Expand All @@ -50,7 +50,7 @@ export class ScreenshotManager {
url,
this.storageManager,
this.config,
join(SCREENSHOT_DIR, `${index}`),
path.join(SCREENSHOT_DIR, `${index}`),
this.options
);
this.savedScreenshots.push(
Expand All @@ -63,7 +63,7 @@ export class ScreenshotManager {
url,
this.storageManager,
this.config,
join(SCREENSHOT_DIR, `${index}`),
path.join(SCREENSHOT_DIR, `${index}`),
this.options
);
this.savedScreenshots.push(
Expand Down
13 changes: 8 additions & 5 deletions lib/support/engineUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve, dirname, join } from 'node:path';
import path from 'node:path';
import { promisify } from 'node:util';
import {
writeFile as _writeFile,
Expand Down Expand Up @@ -32,7 +32,7 @@ async function loadFile(script, options, throwError) {
script.endsWith('.mjs') ||
script.endsWith('.cjs')
) {
let myFunction = await import(pathToFileURL(resolve(script)));
let myFunction = await import(pathToFileURL(path.resolve(script)));
return myFunction.default ?? myFunction;
} else {
// Hack a way! Try to add a package.json file in the same folder as the
Expand All @@ -43,7 +43,10 @@ async function loadFile(script, options, throwError) {
);
let createdPackageJson = false;
try {
const packageJson = join(dirname(resolve(script)), 'package.json');
const packageJson = path.join(
path.dirname(path.resolve(script)),
'package.json'
);
try {
await writeFile(packageJson, '{}');
createdPackageJson = true;
Expand All @@ -53,7 +56,7 @@ async function loadFile(script, options, throwError) {
script
);
}
const myFunction = await import(resolve(script));
const myFunction = await import(path.resolve(script));

try {
if (createdPackageJson) {
Expand Down Expand Up @@ -89,7 +92,7 @@ export async function loadPrePostScripts(scripts, options) {

export async function loadPageCompleteScript(script) {
if (script && script.endsWith('js')) {
return readFile(resolve(script), 'utf8');
return readFile(path.resolve(script), 'utf8');
}
return script;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/support/fileUtil.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from 'node:path';
import path from 'node:path';
import { promisify } from 'node:util';
import {
readdir as _readdir,
Expand Down Expand Up @@ -50,7 +50,7 @@ export async function removeDirAndFiles(dirName) {
await Promise.all(
files.map(async file => {
try {
const p = join(dir, file);
const p = path.join(dir, file);
const stat = await lstat(p);
await (stat.isDirectory() ? removeDir(p) : unlink(p));
} catch (error) {
Expand All @@ -68,7 +68,7 @@ export async function removeDirAndFiles(dirName) {
export async function removeByType(dir, type) {
const fileNames = await readdir(dir);
const filePaths = fileNames
.map(fileName => join(dir, fileName))
.map(fileName => path.join(dir, fileName))
.filter(element => onlyFiles(element))
.filter(onlyWithExtension('.' + type));

Expand Down
4 changes: 2 additions & 2 deletions lib/support/filters.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { promisify } from 'node:util';
import { stat as _stat } from 'node:fs';
import { extname } from 'node:path';
import path from 'node:path';
const stat = promisify(_stat);

/**
* Filters to use with Array.prototype.filter, e.g. ['/a/path', '/another/path'].filter(onlyFiles)
*/
export function onlyWithExtension(extension) {
return filepath => extname(filepath) === extension;
return filepath => path.extname(filepath) === extension;
}
export async function onlyFiles(filepath) {
const stats = await stat(filepath);
Expand Down
8 changes: 4 additions & 4 deletions lib/support/images/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from 'node:path';
import path from 'node:path';
import { pathToFolder } from '../pathToFolder.js';

export async function savePngWithoutResize(
Expand All @@ -12,7 +12,7 @@ export async function savePngWithoutResize(
return storageManager.writeData(
`${name}.png`,
data,
join(pathToFolder(url, options), dir)
path.join(pathToFolder(url, options), dir)
);
}
export async function savePng(
Expand Down Expand Up @@ -41,7 +41,7 @@ export async function savePng(
return storageManager.writeData(
`${name}.png`,
buffer,
join(pathToFolder(url, options), dir)
path.join(pathToFolder(url, options), dir)
);
}
}
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function saveJpg(
return storageManager.writeData(
`${name}.jpg`,
buffer,
join(pathToFolder(url, options), dir)
path.join(pathToFolder(url, options), dir)
);
}
}
Loading
Loading