From a2e9bdcc028c729dc22fc9518650a34747fbeb8f Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Mon, 8 Jul 2024 17:09:58 +0200 Subject: [PATCH] refactor: remove path-exists from tests --- .meta-updater/package.json | 1 - .meta-updater/src/index.ts | 7 ++-- __utils__/assert-store/package.json | 3 +- exec/plugin-commands-rebuild/package.json | 1 - exec/plugin-commands-rebuild/test/index.ts | 19 +++++------ .../package.json | 1 - .../src/exec.ts | 4 +-- .../src/existsInDir.ts | 6 ++-- .../plugin-commands-script-runners/src/run.ts | 3 +- .../src/runRecursive.ts | 4 +-- fs/indexed-pkg-importer/package.json | 1 - pkg-manager/link-bins/package.json | 1 - .../plugin-commands-installation/package.json | 1 - .../src/import/index.ts | 8 ++--- pnpm-lock.yaml | 33 ------------------- pnpm/package.json | 1 - pnpm/test/server.ts | 14 ++++---- .../plugin-commands-publishing/package.json | 1 - resolving/npm-resolver/package.json | 1 - store/plugin-commands-store/package.json | 1 - 20 files changed, 32 insertions(+), 79 deletions(-) diff --git a/.meta-updater/package.json b/.meta-updater/package.json index 5c03d7720d..fcad5804bb 100644 --- a/.meta-updater/package.json +++ b/.meta-updater/package.json @@ -13,7 +13,6 @@ "is-subdir": "catalog:", "load-json-file": "catalog:", "normalize-path": "catalog:", - "path-exists": "catalog:", "write-json-file": "catalog:" }, "devDependencies": { diff --git a/.meta-updater/src/index.ts b/.meta-updater/src/index.ts index ca5e20e3c4..36ba08a7d6 100644 --- a/.meta-updater/src/index.ts +++ b/.meta-updater/src/index.ts @@ -6,7 +6,6 @@ import { createUpdateOptions, type FormatPluginFnOptions } from '@pnpm/meta-upda import isSubdir from 'is-subdir' import loadJsonFile from 'load-json-file' import normalizePath from 'normalize-path' -import exists from 'path-exists' import writeJsonFile from 'write-json-file' const NEXT_TAG = 'next-9' @@ -119,7 +118,7 @@ async function updateTSConfig ( if (!spec.startsWith('link:') || spec.length === 5) continue const relativePath = spec.slice(5) const linkedPkgDir = path.join(dir, relativePath) - if (!await exists(path.join(linkedPkgDir, 'tsconfig.json'))) continue + if (!fs.existsSync(path.join(linkedPkgDir, 'tsconfig.json'))) continue if (!isSubdir(context.workspaceDir, linkedPkgDir)) continue if ( depName === '@pnpm/package-store' && ( @@ -138,7 +137,7 @@ async function updateTSConfig ( async function writeTestTsconfig () { const testDir = path.join(dir, 'test') - if (!await exists(testDir)) { + if (!fs.existsSync(testDir)) { return } @@ -258,7 +257,7 @@ async function updateManifest (workspaceDir: string, manifest: ProjectManifest, break } default: - if (await exists(path.join(dir, 'test'))) { + if (fs.existsSync(path.join(dir, 'test'))) { scripts = { ...(manifest.scripts as Record), _test: 'jest', diff --git a/__utils__/assert-store/package.json b/__utils__/assert-store/package.json index 6d6ad866da..ba41842d66 100644 --- a/__utils__/assert-store/package.json +++ b/__utils__/assert-store/package.json @@ -41,8 +41,7 @@ }, "dependencies": { "@pnpm/registry-mock": "catalog:", - "@pnpm/store.cafs": "workspace:*", - "path-exists": "catalog:" + "@pnpm/store.cafs": "workspace:*" }, "devDependencies": { "@pnpm/assert-store": "workspace:*" diff --git a/exec/plugin-commands-rebuild/package.json b/exec/plugin-commands-rebuild/package.json index de1b852442..b9f94d9ab2 100644 --- a/exec/plugin-commands-rebuild/package.json +++ b/exec/plugin-commands-rebuild/package.json @@ -42,7 +42,6 @@ "@types/semver": "catalog:", "@types/sinon": "catalog:", "execa": "catalog:", - "path-exists": "catalog:", "sinon": "catalog:", "write-yaml-file": "catalog:" }, diff --git a/exec/plugin-commands-rebuild/test/index.ts b/exec/plugin-commands-rebuild/test/index.ts index 4e6b3e2465..616659955b 100644 --- a/exec/plugin-commands-rebuild/test/index.ts +++ b/exec/plugin-commands-rebuild/test/index.ts @@ -10,7 +10,6 @@ import { getIntegrity, REGISTRY_MOCK_PORT } from '@pnpm/registry-mock' import { fixtures } from '@pnpm/test-fixtures' import execa from 'execa' import loadJsonFile from 'load-json-file' -import exists from 'path-exists' import sinon from 'sinon' import { DEFAULT_OPTS } from './utils' @@ -56,8 +55,8 @@ test('rebuilds dependencies', async () => { expect(modules!.pendingBuilds.length).toBe(0) { - expect(await exists('node_modules/@pnpm.e2e/pre-and-postinstall-scripts-example/generated-by-prepare.js')).toBeFalsy() - expect(await exists('node_modules/@pnpm.e2e/pre-and-postinstall-scripts-example/generated-by-preinstall.js')).toBeTruthy() + expect(fs.existsSync('node_modules/@pnpm.e2e/pre-and-postinstall-scripts-example/generated-by-prepare.js')).toBeFalsy() + expect(fs.existsSync('node_modules/@pnpm.e2e/pre-and-postinstall-scripts-example/generated-by-preinstall.js')).toBeTruthy() const generatedByPreinstall = project.requireModule('@pnpm.e2e/pre-and-postinstall-scripts-example/generated-by-preinstall') expect(typeof generatedByPreinstall).toBe('function') @@ -319,12 +318,12 @@ test('rebuild links bins', async () => { '--ignore-scripts', ]) - expect(await exists(path.resolve('node_modules/.bin/cmd1'))).toBeFalsy() - expect(await exists(path.resolve('node_modules/.bin/cmd2'))).toBeFalsy() + expect(fs.existsSync(path.resolve('node_modules/.bin/cmd1'))).toBeFalsy() + expect(fs.existsSync(path.resolve('node_modules/.bin/cmd2'))).toBeFalsy() - expect(await exists(path.resolve('node_modules/@pnpm.e2e/has-generated-bins-as-dep/package.json'))).toBeTruthy() - expect(await exists(path.resolve('node_modules/@pnpm.e2e/has-generated-bins-as-dep/node_modules/.bin/cmd1'))).toBeFalsy() - expect(await exists(path.resolve('node_modules/@pnpm.e2e/has-generated-bins-as-dep/node_modules/.bin/cmd2'))).toBeFalsy() + expect(fs.existsSync(path.resolve('node_modules/@pnpm.e2e/has-generated-bins-as-dep/package.json'))).toBeTruthy() + expect(fs.existsSync(path.resolve('node_modules/@pnpm.e2e/has-generated-bins-as-dep/node_modules/.bin/cmd1'))).toBeFalsy() + expect(fs.existsSync(path.resolve('node_modules/@pnpm.e2e/has-generated-bins-as-dep/node_modules/.bin/cmd2'))).toBeFalsy() const modules = project.readModulesManifest() await rebuild.handler({ @@ -407,12 +406,12 @@ test('never build neverBuiltDependencies', async () => { ) expect( - await exists( + fs.existsSync( 'node_modules/@pnpm.e2e/pre-and-postinstall-scripts-example/generated-by-prepare.js' ) ).toBeFalsy() expect( - await exists( + fs.existsSync( 'node_modules/@pnpm.e2e/pre-and-postinstall-scripts-example/generated-by-preinstall.js' ) ).toBeTruthy() diff --git a/exec/plugin-commands-script-runners/package.json b/exec/plugin-commands-script-runners/package.json index 672438d840..1efa4e8b66 100644 --- a/exec/plugin-commands-script-runners/package.json +++ b/exec/plugin-commands-script-runners/package.json @@ -65,7 +65,6 @@ "didyoumean2": "catalog:", "execa": "catalog:", "p-limit": "catalog:", - "path-exists": "catalog:", "path-name": "catalog:", "ramda": "catalog:", "realpath-missing": "catalog:", diff --git a/exec/plugin-commands-script-runners/src/exec.ts b/exec/plugin-commands-script-runners/src/exec.ts index 1eaf7fd3e0..177f9cc2f3 100644 --- a/exec/plugin-commands-script-runners/src/exec.ts +++ b/exec/plugin-commands-script-runners/src/exec.ts @@ -180,7 +180,7 @@ export async function handler ( const result = createEmptyRecursiveSummary(chunks) const existsPnp = existsInDir.bind(null, '.pnp.cjs') - const workspacePnpPath = opts.workspaceDir && await existsPnp(opts.workspaceDir) + const workspacePnpPath = opts.workspaceDir && existsPnp(opts.workspaceDir) let exitCode = 0 const prependPaths = [ @@ -195,7 +195,7 @@ export async function handler ( result[prefix].status = 'running' const startTime = process.hrtime() try { - const pnpPath = workspacePnpPath ?? await existsPnp(prefix) + const pnpPath = workspacePnpPath ?? existsPnp(prefix) const extraEnv = { ...opts.extraEnv, ...(pnpPath ? makeNodeRequireOption(pnpPath) : {}), diff --git a/exec/plugin-commands-script-runners/src/existsInDir.ts b/exec/plugin-commands-script-runners/src/existsInDir.ts index 673ca5d10b..e0a4cf82f4 100644 --- a/exec/plugin-commands-script-runners/src/existsInDir.ts +++ b/exec/plugin-commands-script-runners/src/existsInDir.ts @@ -1,8 +1,8 @@ +import fs from 'fs' import path from 'path' -import exists from 'path-exists' -export async function existsInDir (entityName: string, dir: string): Promise { +export function existsInDir (entityName: string, dir: string): string | undefined { const entityPath = path.join(dir, entityName) - if (await exists(entityPath)) return entityPath + if (fs.existsSync(entityPath)) return entityPath return undefined } diff --git a/exec/plugin-commands-script-runners/src/run.ts b/exec/plugin-commands-script-runners/src/run.ts index dd29e16caf..86f3acb05f 100644 --- a/exec/plugin-commands-script-runners/src/run.ts +++ b/exec/plugin-commands-script-runners/src/run.ts @@ -251,8 +251,7 @@ so you may run "pnpm -w run ${scriptName}"`, unsafePerm: true, // when running scripts explicitly, assume that they're trusted. } const existsPnp = existsInDir.bind(null, '.pnp.cjs') - const pnpPath = (opts.workspaceDir && await existsPnp(opts.workspaceDir)) ?? - await existsPnp(dir) + const pnpPath = (opts.workspaceDir && existsPnp(opts.workspaceDir)) ?? existsPnp(dir) if (pnpPath) { lifecycleOpts.extraEnv = { ...lifecycleOpts.extraEnv, diff --git a/exec/plugin-commands-script-runners/src/runRecursive.ts b/exec/plugin-commands-script-runners/src/runRecursive.ts index 5cc1bc475c..4ecff83024 100644 --- a/exec/plugin-commands-script-runners/src/runRecursive.ts +++ b/exec/plugin-commands-script-runners/src/runRecursive.ts @@ -67,7 +67,7 @@ export async function runRecursive ( ? 'inherit' : 'pipe' const existsPnp = existsInDir.bind(null, '.pnp.cjs') - const workspacePnpPath = opts.workspaceDir && await existsPnp(opts.workspaceDir) + const workspacePnpPath = opts.workspaceDir && existsPnp(opts.workspaceDir) const requiredScripts = opts.rootProjectManifest?.pnpm?.requiredScripts ?? [] if (requiredScripts.includes(scriptName)) { @@ -121,7 +121,7 @@ export async function runRecursive ( stdio, unsafePerm: true, // when running scripts explicitly, assume that they're trusted. } - const pnpPath = workspacePnpPath ?? await existsPnp(prefix) + const pnpPath = workspacePnpPath ?? existsPnp(prefix) if (pnpPath) { lifecycleOpts.extraEnv = { ...lifecycleOpts.extraEnv, diff --git a/fs/indexed-pkg-importer/package.json b/fs/indexed-pkg-importer/package.json index ac7650082e..b37ef6198f 100644 --- a/fs/indexed-pkg-importer/package.json +++ b/fs/indexed-pkg-importer/package.json @@ -23,7 +23,6 @@ "fs-extra": "catalog:", "make-empty-dir": "catalog:", "p-limit": "catalog:", - "path-exists": "catalog:", "path-temp": "catalog:", "rename-overwrite": "catalog:", "sanitize-filename": "catalog:" diff --git a/pkg-manager/link-bins/package.json b/pkg-manager/link-bins/package.json index 2fe25f0513..dff02285fa 100644 --- a/pkg-manager/link-bins/package.json +++ b/pkg-manager/link-bins/package.json @@ -58,7 +58,6 @@ "@types/ramda": "catalog:", "@types/semver": "catalog:", "cmd-extension": "catalog:", - "path-exists": "catalog:", "tempy": "catalog:" }, "funding": "https://opencollective.com/pnpm", diff --git a/pkg-manager/plugin-commands-installation/package.json b/pkg-manager/plugin-commands-installation/package.json index 082047e891..13218c4dcd 100644 --- a/pkg-manager/plugin-commands-installation/package.json +++ b/pkg-manager/plugin-commands-installation/package.json @@ -100,7 +100,6 @@ "p-filter": "catalog:", "p-limit": "catalog:", "path-absolute": "catalog:", - "path-exists": "catalog:", "ramda": "catalog:", "render-help": "catalog:", "version-selector-type": "catalog:", diff --git a/pkg-manager/plugin-commands-installation/src/import/index.ts b/pkg-manager/plugin-commands-installation/src/import/index.ts index 4eec703a14..3f405b9885 100644 --- a/pkg-manager/plugin-commands-installation/src/import/index.ts +++ b/pkg-manager/plugin-commands-installation/src/import/index.ts @@ -1,3 +1,4 @@ +import fs from 'fs' import path from 'path' import { docsUrl } from '@pnpm/cli-utils' import { WANTED_LOCKFILE } from '@pnpm/constants' @@ -21,7 +22,6 @@ import renderHelp from 'render-help' import { parse as parseYarnLock, type LockFileObject } from '@yarnpkg/lockfile' import * as yarnCore from '@yarnpkg/core' import { parseSyml } from '@yarnpkg/parsers' -import exists from 'path-exists' import { recursive } from '../recursive' import { yarnLockFileKeyNormalizer } from './yarnUtil' @@ -113,12 +113,12 @@ export async function handler ( await rimraf(path.join(opts.dir, WANTED_LOCKFILE)) const versionsByPackageNames = {} let preferredVersions = {} - if (await exists(path.join(opts.dir, 'yarn.lock'))) { + if (fs.existsSync(path.join(opts.dir, 'yarn.lock'))) { const yarnPackageLockFile = await readYarnLockFile(opts.dir) getAllVersionsFromYarnLockFile(yarnPackageLockFile, versionsByPackageNames) } else if ( - await exists(path.join(opts.dir, 'package-lock.json')) || - await exists(path.join(opts.dir, 'npm-shrinkwrap.json')) + fs.existsSync(path.join(opts.dir, 'package-lock.json')) || + fs.existsSync(path.join(opts.dir, 'npm-shrinkwrap.json')) ) { const npmPackageLock = await readNpmLockfile(opts.dir) if (npmPackageLock.lockfileVersion < 3) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2adf430a44..f296c475eb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -791,9 +791,6 @@ importers: normalize-path: specifier: 'catalog:' version: 3.0.0 - path-exists: - specifier: 'catalog:' - version: 4.0.0 write-json-file: specifier: 'catalog:' version: 4.3.0 @@ -862,9 +859,6 @@ importers: '@pnpm/store.cafs': specifier: workspace:* version: link:../../store/cafs - path-exists: - specifier: 'catalog:' - version: 4.0.0 devDependencies: '@pnpm/assert-store': specifier: workspace:* @@ -2046,9 +2040,6 @@ importers: execa: specifier: 'catalog:' version: safe-execa@0.1.2 - path-exists: - specifier: 'catalog:' - version: 4.0.0 sinon: specifier: 'catalog:' version: 16.1.3 @@ -2124,9 +2115,6 @@ importers: p-limit: specifier: 'catalog:' version: 3.1.0 - path-exists: - specifier: 'catalog:' - version: 4.0.0 path-name: specifier: 'catalog:' version: 1.0.0 @@ -2515,9 +2503,6 @@ importers: p-limit: specifier: 'catalog:' version: 3.1.0 - path-exists: - specifier: 'catalog:' - version: 4.0.0 path-temp: specifier: 'catalog:' version: 2.1.0 @@ -4442,9 +4427,6 @@ importers: cmd-extension: specifier: 'catalog:' version: 1.0.2 - path-exists: - specifier: 'catalog:' - version: 4.0.0 tempy: specifier: 'catalog:' version: 1.0.1 @@ -4791,9 +4773,6 @@ importers: path-absolute: specifier: 'catalog:' version: 1.0.1 - path-exists: - specifier: 'catalog:' - version: 4.0.0 ramda: specifier: 'catalog:' version: '@pnpm/ramda@0.28.1' @@ -5514,9 +5493,6 @@ importers: p-defer: specifier: 'catalog:' version: 3.0.0 - path-exists: - specifier: 'catalog:' - version: 4.0.0 path-name: specifier: 'catalog:' version: 1.0.0 @@ -5829,9 +5805,6 @@ importers: load-json-file: specifier: 'catalog:' version: 6.2.0 - path-exists: - specifier: 'catalog:' - version: 4.0.0 tar: specifier: 'catalog:' version: 6.2.1 @@ -6037,9 +6010,6 @@ importers: nock: specifier: 'catalog:' version: 13.3.4 - path-exists: - specifier: 'catalog:' - version: 4.0.0 tempy: specifier: 'catalog:' version: 1.0.1 @@ -6876,9 +6846,6 @@ importers: execa: specifier: 'catalog:' version: safe-execa@0.1.2 - path-exists: - specifier: 'catalog:' - version: 4.0.0 ssri: specifier: 'catalog:' version: 10.0.5 diff --git a/pnpm/package.json b/pnpm/package.json index e209175a3b..8c9f081f31 100644 --- a/pnpm/package.json +++ b/pnpm/package.json @@ -99,7 +99,6 @@ "normalize-newline": "catalog:", "p-any": "catalog:", "p-defer": "catalog:", - "path-exists": "catalog:", "path-name": "catalog:", "pidtree": "catalog:", "ps-list": "catalog:", diff --git a/pnpm/test/server.ts b/pnpm/test/server.ts index 7c5934f92f..d2a5ba186a 100644 --- a/pnpm/test/server.ts +++ b/pnpm/test/server.ts @@ -1,3 +1,4 @@ +import fs from 'fs' import { type ChildProcess } from 'child_process' import { type Readable } from 'stream' import { promisify } from 'util' @@ -12,7 +13,6 @@ import isWindows from 'is-windows' import killcb from 'tree-kill' import writeJsonFile from 'write-json-file' import pAny from 'p-any' -import pathExists from 'path-exists' import { execPnpm, execPnpmSync, @@ -51,7 +51,7 @@ function prepareServerTest (serverStartArgs?: readonly string[]): TestSetup { async function onTestEnd () { await expect(execPnpm(['server', 'stop'])).resolves.not.toThrow() - await expect(pathExists(serverJsonPath)).resolves.toBeFalsy() + expect(fs.existsSync(serverJsonPath)).toBeFalsy() } return { @@ -165,7 +165,7 @@ skipOnWindows('uploading cache can be disabled without breaking install', async const storePath = project.getStorePath() const engine = `${process.platform}-${process.arch}-node-${process.version.split('.')[0]}` const cacheDir = path.join(storePath, `localhost+${REGISTRY_MOCK_PORT}/diskusage/1.1.3/side_effects/${engine}/package`) - await expect(pathExists(cacheDir)).resolves.toBeFalsy() + expect(fs.existsSync(cacheDir)).toBeFalsy() }) skipOnWindows('installation using store server started in the background', async () => { @@ -185,7 +185,7 @@ skipOnWindows('installation using store server started in the background', async await expect(execPnpm(['uninstall', 'is-positive'])).resolves.not.toThrow() } finally { await expect(execPnpm(['server', 'stop'])).resolves.not.toThrow() - await expect(pathExists(serverJsonPath)).resolves.toBeFalsy() + expect(fs.existsSync(serverJsonPath)).toBeFalsy() } }) @@ -206,7 +206,7 @@ skipOnWindows('store server started in the background should use store location await expect(execPnpm(['remove', 'is-positive', '--store-dir', '../store2'])).resolves.not.toThrow() } finally { await expect(execPnpm(['server', 'stop', '--store-dir', '../store2'])).resolves.not.toThrow() - await expect(pathExists(serverJsonPath)).resolves.toBeFalsy() + expect(fs.existsSync(serverJsonPath)).toBeFalsy() } }) @@ -311,7 +311,7 @@ skipOnWindows('parallel server starts against the same store should result in on timeoutMillis: 60000, })).resolves.not.toThrow() const serverJsonPath = path.resolve('..', 'store/v3/server/server.json') - await expect(pathExists(serverJsonPath)).resolves.toBeFalsy() + expect(fs.existsSync(serverJsonPath)).toBeFalsy() }) skipOnWindows('installation without store server running in the background', async () => { @@ -320,7 +320,7 @@ skipOnWindows('installation without store server running in the background', asy await expect(execPnpm(['install', 'is-positive@1.0.0', '--no-use-store-server'])).resolves.not.toThrow() const serverJsonPath = path.resolve('..', 'store/v3/server/server.json') - await expect(pathExists(serverJsonPath)).resolves.toBeFalsy() + expect(fs.existsSync(serverJsonPath)).toBeFalsy() expect(project.requireModule('is-positive')).toBeTruthy() }) diff --git a/releasing/plugin-commands-publishing/package.json b/releasing/plugin-commands-publishing/package.json index 0759a2dcb0..18a74551cf 100644 --- a/releasing/plugin-commands-publishing/package.json +++ b/releasing/plugin-commands-publishing/package.json @@ -49,7 +49,6 @@ "cross-spawn": "catalog:", "is-windows": "catalog:", "load-json-file": "catalog:", - "path-exists": "catalog:", "tar": "catalog:", "write-yaml-file": "catalog:" }, diff --git a/resolving/npm-resolver/package.json b/resolving/npm-resolver/package.json index ef7a9c2c59..9bdac513cb 100644 --- a/resolving/npm-resolver/package.json +++ b/resolving/npm-resolver/package.json @@ -66,7 +66,6 @@ "@types/semver": "catalog:", "@types/ssri": "catalog:", "nock": "catalog:", - "path-exists": "catalog:", "tempy": "catalog:" }, "funding": "https://opencollective.com/pnpm", diff --git a/store/plugin-commands-store/package.json b/store/plugin-commands-store/package.json index 08e102b4c6..97f1e07cff 100644 --- a/store/plugin-commands-store/package.json +++ b/store/plugin-commands-store/package.json @@ -41,7 +41,6 @@ "@types/ssri": "catalog:", "@zkochan/rimraf": "catalog:", "execa": "catalog:", - "path-exists": "catalog:", "ssri": "catalog:", "tempy": "catalog:" },