/
githubmirror
/
lerna
Обзор
Документация
Войти
/
githubmirror
/
lerna
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
libs/commands/version/src/lib/git-add.ts
85 строк
3 KB
AI-JamesHenry
feat!: support node ^22.13.0 || ^24.0.0 || ^26.0.0, ship lerna as ESM-only (#4390)
14 июл 2026, 11:38
Не верифицирован
14 июл 2026, 11:38
a148ba2
Код
Авторство
О чём код?
import { log } from "@lerna/core"; import { readJsonFile, workspaceRoot } from "@nx/devkit"; import fs from "fs"; import { createRequire } from "node:module"; import path from "path"; import { slash } from "@lerna/core"; import * as childProcess from "@lerna/child-process"; import type { LernaOptions } from "@lerna/child-process"; const require = createRequire(import.meta.url); let resolvedPrettier: any; function resolvePrettier() { if (!resolvedPrettier) { try { // If the workspace has prettier (explicitly) installed, apply it to the updated files const packageJson = readJsonFile(path.join(workspaceRoot, "package.json")); const hasPrettier = packageJson.devDependencies?.prettier || packageJson.dependencies?.prettier; if (!hasPrettier) { return; } resolvedPrettier = require("prettier"); } catch { return; } } return resolvedPrettier; } async function maybeFormatFile(filePath: any) { const prettier = resolvePrettier(); if (!prettier) { return; } const config = await resolvedPrettier.resolveConfig(filePath); const ignorePath = path.join(workspaceRoot, ".prettierignore"); const fullFilePath = path.join(workspaceRoot, filePath); const fileInfo = await resolvedPrettier.getFileInfo(fullFilePath, { ignorePath, resolveConfig: false }); if (fileInfo.ignored) { log.silly("version", `Skipped applying prettier to ignored file: ${filePath}`); return; } try { const input = fs.readFileSync(fullFilePath, "utf8"); fs.writeFileSync( fullFilePath, await resolvedPrettier.format(input, { ...config, filepath: fullFilePath }), "utf8" ); log.silly("version", `Successfully applied prettier to updated file: ${filePath}`); } catch { log.silly("version", `Failed to apply prettier to updated file: ${filePath}`); } } export async function gitAdd( changedFiles: string[], gitOpts: { granularPathspec?: boolean }, execOpts: LernaOptions ) { let files: string | string[] = []; for (const file of changedFiles) { const filePath = slash(path.relative(execOpts.cwd as string, path.resolve(execOpts.cwd as string, file))); await maybeFormatFile(filePath); if (gitOpts.granularPathspec) { files.push(filePath); } } // granular pathspecs should be relative to the git root, but that isn't necessarily where lerna lives if (!gitOpts.granularPathspec) { files = "."; } // TODO: refactor based on TS feedback // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore log.silly("gitAdd", files); return childProcess.exec("git", ["add", "--", ...files], execOpts); }