/
githubmirror
/
DefinitelyTyped
Обзор
Документация
Войти
/
githubmirror
/
DefinitelyTyped
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
scripts/clean-node-modules.js
44 строки
1 KB
Jake Bailey
Update to pnpm 10 (#74562)
20 фев 2026, 22:21
Не верифицирован
20 фев 2026, 22:21
df699c6
Код
Авторство
О чём код?
import fs from "node:fs"; import path from "node:path"; import url from "node:url"; const __filename = url.fileURLToPath(new URL(import.meta.url)); const __dirname = path.dirname(__filename); const repoRoot = path.resolve(__dirname, ".."); /** * @param {string} p * @returns {Iterable<string>} */ function* iterateNodeModules(p) { const dirents = fs.readdirSync(p, { withFileTypes: true }); for (const dirent of dirents) { if (dirent.isDirectory()) { const subDir = path.join(p, dirent.name); if (dirent.name == "node_modules") { yield subDir; continue; } yield* iterateNodeModules(subDir); } } } /** * @param {string} p */ function rimraf(p) { // The rimraf package uses maxRetries=10 on Windows, but Node's fs.rm does not have that special case. return fs.rmSync(p, { recursive: true, force: true, maxRetries: process.platform === "win32" ? 10 : 0 }); } for (const nodeModules of iterateNodeModules(repoRoot)) { console.log(path.relative(repoRoot, nodeModules)); rimraf(nodeModules); const lockfile = path.join(path.dirname(nodeModules), "pnpm-lock.yaml"); if (fs.existsSync(lockfile)) { console.log(path.relative(repoRoot, lockfile)); fs.unlinkSync(lockfile); } }