mirror of
https://github.com/pnpm/pnpm.git
synced 2026-03-24 01:51:41 -04:00
refactor: remove path-exists from tests
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
"is-subdir": "catalog:",
|
||||
"load-json-file": "catalog:",
|
||||
"normalize-path": "catalog:",
|
||||
"path-exists": "catalog:",
|
||||
"write-json-file": "catalog:"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -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<string, string>),
|
||||
_test: 'jest',
|
||||
|
||||
@@ -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:*"
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
"@types/semver": "catalog:",
|
||||
"@types/sinon": "catalog:",
|
||||
"execa": "catalog:",
|
||||
"path-exists": "catalog:",
|
||||
"sinon": "catalog:",
|
||||
"write-yaml-file": "catalog:"
|
||||
},
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -65,7 +65,6 @@
|
||||
"didyoumean2": "catalog:",
|
||||
"execa": "catalog:",
|
||||
"p-limit": "catalog:",
|
||||
"path-exists": "catalog:",
|
||||
"path-name": "catalog:",
|
||||
"ramda": "catalog:",
|
||||
"realpath-missing": "catalog:",
|
||||
|
||||
@@ -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) : {}),
|
||||
|
||||
@@ -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<string | undefined> {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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:"
|
||||
|
||||
@@ -58,7 +58,6 @@
|
||||
"@types/ramda": "catalog:",
|
||||
"@types/semver": "catalog:",
|
||||
"cmd-extension": "catalog:",
|
||||
"path-exists": "catalog:",
|
||||
"tempy": "catalog:"
|
||||
},
|
||||
"funding": "https://opencollective.com/pnpm",
|
||||
|
||||
@@ -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:",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
33
pnpm-lock.yaml
generated
33
pnpm-lock.yaml
generated
@@ -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
|
||||
|
||||
@@ -99,7 +99,6 @@
|
||||
"normalize-newline": "catalog:",
|
||||
"p-any": "catalog:",
|
||||
"p-defer": "catalog:",
|
||||
"path-exists": "catalog:",
|
||||
"path-name": "catalog:",
|
||||
"pidtree": "catalog:",
|
||||
"ps-list": "catalog:",
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
"cross-spawn": "catalog:",
|
||||
"is-windows": "catalog:",
|
||||
"load-json-file": "catalog:",
|
||||
"path-exists": "catalog:",
|
||||
"tar": "catalog:",
|
||||
"write-yaml-file": "catalog:"
|
||||
},
|
||||
|
||||
@@ -66,7 +66,6 @@
|
||||
"@types/semver": "catalog:",
|
||||
"@types/ssri": "catalog:",
|
||||
"nock": "catalog:",
|
||||
"path-exists": "catalog:",
|
||||
"tempy": "catalog:"
|
||||
},
|
||||
"funding": "https://opencollective.com/pnpm",
|
||||
|
||||
@@ -41,7 +41,6 @@
|
||||
"@types/ssri": "catalog:",
|
||||
"@zkochan/rimraf": "catalog:",
|
||||
"execa": "catalog:",
|
||||
"path-exists": "catalog:",
|
||||
"ssri": "catalog:",
|
||||
"tempy": "catalog:"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user