Skip to content
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
27 changes: 0 additions & 27 deletions .eslintrc.cjs

This file was deleted.

2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Source code and markdown files should always use LF as line ending.
*.css text eol=lf
*.html text eol=lf
*.js text eol=lf
*.json text eol=lf
*.md text eol=lf
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn lint-staged
9 changes: 9 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"$schema": "./node_modules/oxfmt/configuration_schema.json",
"trailingComma": "all",
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"sortPackageJson": false,
"ignorePatterns": [".yarn/releases/*", "*.md", "*.yml", "*.yaml"]
}
10 changes: 10 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"plugins": ["eslint", "typescript", "unicorn", "oxc", "import"],
"categories": {
"correctness": "warn"
},
"options": {
"typeAware": true
}
}
10 changes: 0 additions & 10 deletions .prettierrc.js

This file was deleted.

32 changes: 18 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@
"build": "tsc -b",
"docs": "api-extractor run --local",
"docs:ci": "api-extractor run",
"lint": "yarn lint:eslint && yarn lint:prettier",
"lint:fix": "yarn lint:eslint:fix && yarn lint:prettier:fix",
"lint:eslint": "eslint \"./src/**/*.ts\" \"./tests/**/*.ts\"",
"lint:eslint:fix": "eslint --fix \"./src/**/*.ts\" \"./tests/**/*.ts\"",
"lint:prettier": "prettier --check package.json src/**/*.ts tests/**/*.ts",
"lint:prettier:fix": "prettier --write package.json src/**/*.ts tests/**/*.ts",
"lint": "oxfmt --check . && oxlint",
"lint:fix": "oxfmt --write . && oxlint --fix",
"prepare": "husky",
"prepack": "yarn build",
"start": "node dist/cli.js",
"test": "vitest run",
Expand All @@ -51,16 +48,14 @@
"@types/graceful-fs": "^4.1.9",
"@types/node": "~22.10.7",
"@types/semver": "^7.5.6",
"@typescript-eslint/eslint-plugin": "^8.32.1",
"@typescript-eslint/parser": "^8.32.1",
"@vitest/coverage-v8": "^4.1.2",
"eslint": "^8.57.1",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-prettier": "^5.2.1",
"husky": "^9.0.0",
"lint-staged": "^16.0.0",
"nock": "^14.0.1",
"prettier": "^3.4.2",
"typescript": "^5.8.3",
"oxfmt": "^0.44.0",
"oxlint": "^1.59.0",
"oxlint-tsgolint": "^0.20.0",
"typescript": "^6.0.2",
"vitest": "^4.1.2"
},
"engines": {
Expand All @@ -69,5 +64,14 @@
"resolutions": {
"fsevents": "npm:@electron/fsevents@2.3.3-fork"
},
"lint-staged": {
"*.{js,ts}": [
"oxfmt --write",
"oxlint --fix"
],
"*.{json,css,html}": [
"oxfmt --write"
]
},
"packageManager": "yarn@4.10.3+sha512.c38cafb5c7bb273f3926d04e55e1d8c9dfa7d9c3ea1f36a4868fa028b9e5f72298f0b7f401ad5eb921749eb012eb1c3bb74bf7503df3ee43fd600d14a018266f"
}
5 changes: 1 addition & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import { fileURLToPath } from 'node:url';

import { runFromCommandLine } from './command-line.js';

if (
(await fs.promises.realpath(process.argv[1])) ===
fileURLToPath(import.meta.url)
) {
if ((await fs.promises.realpath(process.argv[1])) === fileURLToPath(import.meta.url)) {
void runFromCommandLine(process.argv.slice(2));
}
10 changes: 2 additions & 8 deletions src/command-line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ export async function runFromCommandLine(argv: string[]): Promise<void> {
} else if (param === 'test' || param === 'start' || param === 'run') {
d('it is test');
cmd = 'test';
} else if (
param === 'test:msix' ||
param === 'start:msix' ||
param === 'run:msix'
) {
} else if (param === 'test:msix' || param === 'start:msix' || param === 'run:msix') {
cmd = 'test';
runWithIdentity = true;
} else if (versions.isVersion(param)) {
Expand All @@ -50,9 +46,7 @@ export async function runFromCommandLine(argv: string[]): Promise<void> {
d(inspect({ cmd, fiddle, versions }));

if (!cmd) {
console.error(
"Command-line parameters must include one of ['bisect', 'test', 'start']",
);
console.error("Command-line parameters must include one of ['bisect', 'test', 'start']");
process.exit(1);
}

Expand Down
12 changes: 3 additions & 9 deletions src/fiddle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,8 @@ export class FiddleFactory {
[...map.entries()].map(([filename, content]) => {
const filePath = path.resolve(folder, filename);
const relative = path.relative(folder, filePath);
if (
!relative ||
relative.startsWith('..') ||
path.isAbsolute(relative)
) {
throw new Error(
`Refusing to write file outside of fiddle: "${filename}"`,
);
if (!relative || relative.startsWith('..') || path.isAbsolute(relative)) {
throw new Error(`Refusing to write file outside of fiddle: "${filename}"`);
}
return util.promisify(fs.writeFile)(filePath, content, 'utf8');
}),
Expand All @@ -129,7 +123,7 @@ export class FiddleFactory {
fiddle = await this.fromFolder(src);
} else if (/^[0-9A-Fa-f]{32}$/.test(src)) {
fiddle = await this.fromGist(src);
} else if (/^https:/.test(src) || /\.git$/.test(src)) {
} else if (src.startsWith('https:') || src.endsWith('.git')) {
fiddle = await this.fromRepo(src);
} else {
return;
Expand Down
15 changes: 2 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,8 @@ import {
Mirrors,
ProgressObject,
} from './installer.js';
import {
Fiddle,
FiddleFactory,
FiddleSource,
FiddleFactoryCreateOptions,
} from './fiddle.js';
import {
BisectResult,
Runner,
RunnerOptions,
RunnerSpawnOptions,
TestResult,
} from './runner.js';
import { Fiddle, FiddleFactory, FiddleSource, FiddleFactoryCreateOptions } from './fiddle.js';
import { BisectResult, Runner, RunnerOptions, RunnerSpawnOptions, TestResult } from './runner.js';
import {
BaseVersions,
ElectronVersions,
Expand Down
40 changes: 8 additions & 32 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ export class Installer extends EventEmitter {
this.setState(match[1], InstallState.downloaded);
} else {
// Case when the download path already has the unzipped electron version
const versionFile = path.join(
this.paths.electronDownloads,
file,
'version',
);
const versionFile = path.join(this.paths.electronDownloads, file, 'version');

if (fs.existsSync(versionFile)) {
const version = fs.readFileSync(versionFile, 'utf8').trim();
Expand Down Expand Up @@ -182,10 +178,7 @@ export class Installer extends EventEmitter {
func(path);
return true;
} catch (error) {
console.warn(
`Installer: failed to run ${func.name} for ${version}, but failed`,
error,
);
console.warn(`Installer: failed to run ${func.name} for ${version}, but failed`, error);
if (counter < 4) {
console.log(`Installer: Trying again to run ${func.name}`);
await rerunner(path, func, counter + 1);
Expand All @@ -206,10 +199,7 @@ export class Installer extends EventEmitter {
}
};
// get the zip path
const zipPath = path.join(
this.paths.electronDownloads,
getZipName(version),
);
const zipPath = path.join(this.paths.electronDownloads, getZipName(version));
// Or, maybe the version was already installed and kept in file system
const preInstalledPath = path.join(this.paths.electronDownloads, version);

Expand All @@ -218,10 +208,7 @@ export class Installer extends EventEmitter {

// maybe uninstall it
if (this.installedVersion === version) {
isBinaryDeleted = await rerunner(
this.paths.electronInstall,
binaryCleaner,
);
isBinaryDeleted = await rerunner(this.paths.electronInstall, binaryCleaner);
} else {
// If the current version binary doesn't exists
isBinaryDeleted = true;
Expand All @@ -241,10 +228,7 @@ export class Installer extends EventEmitter {
if (state === InstallState.installed) return version;
}

private async download(
version: string,
opts?: Partial<InstallerParams>,
): Promise<string> {
private async download(version: string, opts?: Partial<InstallerParams>): Promise<string> {
let pctDone = 0;
const getProgressCallback = (progress: ProgressObject) => {
if (opts?.progressCallback) {
Expand Down Expand Up @@ -338,20 +322,15 @@ export class Installer extends EventEmitter {
let promise = promises.get(version);
if (promise) return promise;

promise = this.ensureDownloadedImpl(version, opts).finally(() =>
promises.delete(version),
);
promise = this.ensureDownloadedImpl(version, opts).finally(() => promises.delete(version));
promises.set(version, promise);
return promise;
}

/** keep a track of all currently installing versions */
private installing = new Set<string>();

public async install(
version: string,
opts?: Partial<InstallerParams>,
): Promise<string> {
public async install(version: string, opts?: Partial<InstallerParams>): Promise<string> {
const d = debug(`fiddle-core:Installer:${version}:install`);
const { electronInstall } = this.paths;
const isVersionInstalling = this.installing.has(version);
Expand All @@ -369,10 +348,7 @@ export class Installer extends EventEmitter {
if (installedVersion === version) {
d(`already installed`);
} else {
const { path: source, alreadyExtracted } = await this.ensureDownloaded(
version,
opts,
);
const { path: source, alreadyExtracted } = await this.ensureDownloaded(version, opts);

// An unzipped version already exists at `electronDownload` path
if (alreadyExtracted) {
Expand Down
35 changes: 9 additions & 26 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@
versions?: Versions;
} = {},
): Promise<Runner> {
const paths = Object.freeze({ ...DefaultPaths, ...(opts.paths || {}) });
const paths = Object.freeze({ ...DefaultPaths, ...opts.paths });
const installer = opts.installer || new Installer(paths);
const versions =
opts.versions || (await ElectronVersions.create({ paths }));
const versions = opts.versions || (await ElectronVersions.create({ paths }));
const factory = opts.fiddleFactory || new FiddleFactory(paths.fiddles);
return new Runner(installer, versions, factory);
}
Expand All @@ -97,8 +96,7 @@
if (fs.existsSync(name)) return name;
} catch {
// if it's a version, install it
if (this.versions.isVersion(electron))
return await this.installer.install(electron);
if (this.versions.isVersion(electron)) return await this.installer.install(electron);
}
throw new Error(`Unrecognized electron name: "${electron}"`);
}
Expand Down Expand Up @@ -129,10 +127,7 @@
].join('\n');

/** If headless specified on *nix, try to run with xvfb-run */
private static headless(
exec: string,
args: string[],
): { exec: string; args: string[] } {
private static headless(exec: string, args: string[]): { exec: string; args: string[] } {
if (process.platform !== 'darwin' && process.platform !== 'win32') {
// try to get a free server number
args.unshift('--auto-servernum', exec);
Expand All @@ -159,9 +154,7 @@
// set up the electron binary and the fiddle
const electronExec = await this.getExec(version);
let exec =
process.platform === 'win32' && opts.runWithIdentity
? MSIX_EXEC_ALIAS
: electronExec;
process.platform === 'win32' && opts.runWithIdentity ? MSIX_EXEC_ALIAS : electronExec;
let args = [...(opts.args || []), fiddle.mainPath];
if (opts.headless) ({ exec, args } = Runner.headless(exec, args));

Expand Down Expand Up @@ -213,8 +206,7 @@
opts: RunnerSpawnOptions = DefaultRunnerOpts,
): Promise<TestResult> {
if (process.platform === 'win32' && opts.runWithIdentity) {
const electronVersion =
version instanceof SemVer ? version.version : version;
const electronVersion = version instanceof SemVer ? version.version : version;
const electronExec = await this.getExec(electronVersion);
const electronDir = path.dirname(electronExec);
await registerElectronIdentity(electronVersion, electronDir);
Expand Down Expand Up @@ -275,7 +267,7 @@
let right = RIGHT_POS;
let result: TestResult | undefined = undefined;
const testOrder: (number | undefined)[] = [];
const results = new Array<TestResult>(versions.length);

Check warning on line 270 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Test (22.12.x, ubuntu-24.04-arm)

eslint-plugin-unicorn(no-new-array)

Do not use `new Array(singleArgument)`.

Check warning on line 270 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Test (22.12.x, macos-latest)

eslint-plugin-unicorn(no-new-array)

Do not use `new Array(singleArgument)`.

Check warning on line 270 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Test (22.12.x, ubuntu-latest)

eslint-plugin-unicorn(no-new-array)

Do not use `new Array(singleArgument)`.

Check warning on line 270 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Test (22.12.x, windows-11-arm)

eslint-plugin-unicorn(no-new-array)

Do not use `new Array(singleArgument)`.

Check warning on line 270 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Test (22.12.x, windows-latest)

eslint-plugin-unicorn(no-new-array)

Do not use `new Array(singleArgument)`.
while (left + 1 < right) {
const mid = Math.round(left + (right - left) / 2);
const ver = versions[mid];
Expand Down Expand Up @@ -313,18 +305,12 @@
versions.forEach((ver, i) => {
const n = testOrder.indexOf(i);
if (n === -1) return;
log(
displayIndex(i),
Runner.displayResult(results[i]),
ver,
`(test #${n + 1})`,
);
log(displayIndex(i), Runner.displayResult(results[i]), ver, `(test #${n + 1})`);
});

log('\n🏁 Done bisecting');
const success =
results[left].status === 'test_passed' &&
results[right].status === 'test_failed';
results[left].status === 'test_passed' && results[right].status === 'test_failed';
if (success) {
const good = versions[left].version;
const bad = versions[right].version;
Expand All @@ -343,10 +329,7 @@
};
} else {
// FIXME: log some failure
if (
result?.status === 'test_error' ||
result?.status === 'system_error'
) {
if (result?.status === 'test_error' || result?.status === 'system_error') {
return { status: result.status };
}

Expand Down
Loading
Loading