mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
* build: add oxfmt for code formatting and import sorting
Adds oxfmt as a devDependency alongside oxlint and wires it into the
lint pipeline. The .oxfmtrc.json config matches Electron's current JS
style (single quotes, semicolons, 2-space indent, trailing commas off,
printWidth 100) and configures sortImports with custom groups that
mirror the import/order pathGroups previously enforced by ESLint:
@electron/internal, @electron/*, and {electron,electron/**} each get
their own ordered group ahead of external modules.
- `yarn lint:fmt` runs `oxfmt --check` over JS/TS sources and is
chained into `yarn lint` so CI enforces it automatically.
- `yarn format` runs `oxfmt --write` for local fix-up.
- lint-staged invokes `oxfmt --write` on staged .js/.ts/.mjs/.cjs
files before oxlint, so formatting is applied at commit time.
The next commit applies the formatter to the existing codebase so the
check actually passes.
* chore: apply oxfmt formatting to JS and TS sources
Runs `yarn format` across lib/, spec/, script/, build/, default_app/,
and npm/ to bring the codebase in line with the .oxfmtrc.json settings
added in the previous commit. This is a pure formatting pass: import
statements are sorted into the groups defined by the config, method
chains longer than printWidth are broken, single-quoted strings
containing apostrophes are switched to double quotes, and a handful of
single-statement `if` bodies are re-wrapped and get braces added by
`oxlint --fix` to satisfy the `curly: multi-line` rule.
No behavior changes.
102 lines
2.6 KiB
JavaScript
102 lines
2.6 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { valid, coerce, inc } from 'semver';
|
|
|
|
import { parseArgs } from 'node:util';
|
|
|
|
import { getElectronVersion } from '../lib/get-version';
|
|
import { VersionBumpType } from './types';
|
|
import { isNightly, isAlpha, isBeta, nextNightly, nextAlpha, nextBeta, isStable } from './version-utils';
|
|
|
|
// run the script
|
|
async function main() {
|
|
const {
|
|
values: { bump, dryRun, help }
|
|
} = parseArgs({
|
|
options: {
|
|
bump: {
|
|
type: 'string'
|
|
},
|
|
dryRun: {
|
|
type: 'boolean'
|
|
},
|
|
help: {
|
|
type: 'boolean'
|
|
}
|
|
}
|
|
});
|
|
|
|
if (!bump || help) {
|
|
console.log(`
|
|
Bump release version number. Possible arguments:\n
|
|
--bump=patch to increment patch version\n
|
|
--version={version} to set version number directly\n
|
|
--dryRun to print the next version without updating files
|
|
Note that you can use both --bump and --stable simultaneously.
|
|
`);
|
|
if (!bump) process.exit(0);
|
|
else process.exit(1);
|
|
}
|
|
|
|
const currentVersion = getElectronVersion();
|
|
const version = await nextVersion(bump as VersionBumpType, currentVersion);
|
|
|
|
// print would-be new version and exit early
|
|
if (dryRun) {
|
|
console.log(`new version number would be: ${version}\n`);
|
|
return 0;
|
|
}
|
|
|
|
console.log(`Bumped to version: ${version}`);
|
|
}
|
|
|
|
// get next version for release based on [nightly, alpha, beta, stable]
|
|
export async function nextVersion(bumpType: VersionBumpType, version: string) {
|
|
if (isNightly(version) || isAlpha(version) || isBeta(version)) {
|
|
switch (bumpType) {
|
|
case 'nightly':
|
|
version = await nextNightly(version);
|
|
break;
|
|
case 'alpha':
|
|
version = await nextAlpha(version);
|
|
break;
|
|
case 'beta':
|
|
version = await nextBeta(version);
|
|
break;
|
|
case 'stable':
|
|
version = valid(coerce(version))!;
|
|
break;
|
|
default:
|
|
throw new Error('Invalid bump type.');
|
|
}
|
|
} else if (isStable(version)) {
|
|
switch (bumpType) {
|
|
case 'nightly':
|
|
version = await nextNightly(version);
|
|
break;
|
|
case 'alpha':
|
|
throw new Error('Cannot bump to alpha from stable.');
|
|
case 'beta':
|
|
throw new Error('Cannot bump to beta from stable.');
|
|
case 'minor':
|
|
version = inc(version, 'minor')!;
|
|
break;
|
|
case 'stable':
|
|
version = inc(version, 'patch')!;
|
|
break;
|
|
default:
|
|
throw new Error('Invalid bump type.');
|
|
}
|
|
} else {
|
|
throw new Error(`Invalid current version: ${version}`);
|
|
}
|
|
return version;
|
|
}
|
|
|
|
if (require.main === module) {
|
|
main().catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|
|
}
|