mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-26 23:39:13 +00:00
2dbfd85506
* ci(linter): add renovate/no-sync-io rule Flags calls to a fixed list of Node.js sync I/O APIs (readFileSync, writeFileSync, mkdirSync, rmSync, readdirSync, statSync, existsSync, copyFileSync, execSync, spawnSync, execFileSync) in tools/** and **/*.spec.ts only; production lib code is not targeted. Set to "warn" instead of "error": the repo has 40 pre-existing violations, exceeding the agreed fix threshold of 30, so violations are left in place for follow-up rather than mass-fixed here. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * ci(linter): enforce renovate/no-sync-io at error Promote the rule from warn to error now that the codebase has been migrated off synchronous I/O in tools/ and spec files. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * refactor(tools): migrate synchronous fs calls to async equivalents Replace *Sync fs calls with their async/promise-based counterparts in tools/ scripts (generate-imports, check runner, utils, cwdchanged hook) now that renovate/no-sync-io is enforced at error there. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * test: migrate synchronous fs calls in specs to async equivalents Replace *Sync fs calls (readdirSync, writeFileSync, existsSync, etc.) with their async/promise-based counterparts across affected spec files, making the enclosing it()/module-scope initializers async as needed, to satisfy renovate/no-sync-io now enforced at error. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * ci(linter): replace custom no-sync-io rule with built-in node/no-sync The oxc built-in covers a superset of the custom fixed-name list. Migrate the additionally flagged sites: async glob in test-shards, async execa in prepare-deps, promisified gzip/generateKeyPair in rpm/hex specs, and rename the misleading execSync mock alias (it mocks the async rawExec). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
99 lines
2.1 KiB
TypeScript
99 lines
2.1 KiB
TypeScript
import fs from 'fs-extra';
|
|
import { SemVer } from 'semver';
|
|
import { logger } from '../../lib/logger/index.ts';
|
|
|
|
export const newFiles = new Set();
|
|
|
|
/**
|
|
* Get environment variable or empty string.
|
|
* Used for easy mocking.
|
|
* @param {string} key variable name
|
|
* @returns {string}
|
|
*/
|
|
export function getEnv(key: string): string {
|
|
return process.env[key] ?? '';
|
|
}
|
|
|
|
/**
|
|
* Find all module directories.
|
|
* @param {string} dirname dir to search in
|
|
* @returns {Promise<string[]>}
|
|
*/
|
|
export async function findModules(dirname: string): Promise<string[]> {
|
|
const dirents = await fs.readdir(dirname, { withFileTypes: true });
|
|
return dirents
|
|
.filter((dirent) => dirent.isDirectory())
|
|
.map((dirent) => dirent.name)
|
|
.filter((name) => !name.startsWith('__'))
|
|
.sort();
|
|
}
|
|
|
|
/**
|
|
* @param {string} input
|
|
* @returns {string}
|
|
*/
|
|
export function camelCase(input: string): string {
|
|
return input
|
|
.replace(/(?:^\w|[A-Z]|\b\w)/g, (char, index) =>
|
|
index === 0 ? char.toLowerCase() : char.toUpperCase(),
|
|
)
|
|
.replace(/-/g, '');
|
|
}
|
|
|
|
/**
|
|
* @param {string } file
|
|
* @param {string} code
|
|
* @returns {Promise<void>}
|
|
*/
|
|
export async function updateFile(file: string, code: string): Promise<void> {
|
|
const oldCode = (await fs.pathExists(file))
|
|
? await fs.readFile(file, 'utf8')
|
|
: null;
|
|
if (code !== oldCode) {
|
|
if (!code) {
|
|
logger.error({ file }, 'Missing content');
|
|
}
|
|
await fs.outputFile(file, code ?? '', { encoding: 'utf8' });
|
|
}
|
|
newFiles.add(file);
|
|
}
|
|
|
|
/**
|
|
* @param {string } file
|
|
* @returns {Promise<string | null>}
|
|
*/
|
|
export async function readFile(file: string): Promise<string> {
|
|
if (await fs.pathExists(file)) {
|
|
return fs.readFile(file, 'utf8');
|
|
}
|
|
return '';
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param val
|
|
*/
|
|
export function parsePositiveInt(val: string | undefined): number {
|
|
if (!val) {
|
|
return 0;
|
|
}
|
|
const r = Number.parseInt(val, 10);
|
|
if (!Number.isFinite(r) || r < 0) {
|
|
throw new Error(`Invalid number: ${val}`);
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param val
|
|
*/
|
|
export function parseVersion(val: string | undefined): SemVer | undefined {
|
|
if (!val) {
|
|
return undefined;
|
|
}
|
|
// can throw
|
|
return new SemVer(val);
|
|
}
|