Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 13 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/build-info/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@bugsnag/js": "^8.0.0",
"@iarna/toml": "^2.2.5",
"dot-prop": "^9.0.0",
"find-up": "^7.0.0",
"empathic": "^2.0.0",
"minimatch": "^9.0.0",
"read-pkg": "^9.0.0",
"semver": "^7.3.8",
Expand Down
24 changes: 19 additions & 5 deletions packages/build-info/src/node/file-system.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { promises as fs } from 'fs'
import { promises as fs, existsSync } from 'fs'
import { basename, dirname, isAbsolute, join, relative, resolve } from 'path'

import { findUp, findUpMultiple } from 'find-up'
import { any as findUpAny, up as findUp } from 'empathic/find'
import { up as walkUp } from 'empathic/walk'

import { DirType, Environment, FileSystem, findUpOptions } from '../file-system.js'

Expand Down Expand Up @@ -68,12 +69,25 @@ export class NodeFS extends FileSystem {
}

/** Node implementation of finding a file or directory by walking up parent directories. */
findUp(name: string | readonly string[], options: findUpOptions = {}): Promise<string | undefined> {
return findUp(name, options)
findUp(name: string | string[], options: findUpOptions = {}): Promise<string | undefined> {
if (typeof name === 'string') {
return Promise.resolve(findUp(name, options))
}
return Promise.resolve(findUpAny(name, options))
}

/** Node implementation of finding files or directories by walking up parent directories. */
findUpMultiple(name: string | readonly string[], options: findUpOptions = {}): Promise<string[]> {
return findUpMultiple(name, options)
const results: string[] = []
const normalisedNames = typeof name === 'string' ? [name] : name
for (const dir of walkUp(options.cwd ?? '.', options)) {
for (const potentialName of normalisedNames) {
const filePath = join(dir, potentialName)
if (existsSync(filePath)) {
results.push(filePath)
}
}
}
return Promise.resolve(results)
}
}
2 changes: 1 addition & 1 deletion packages/build-info/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default defineConfig({
setupFiles: ['tests/test-setup.ts'],
deps: {
// this is to work inside memfs as well
inline: ['find-up', 'locate-path'],
inline: ['empathic', 'locate-path'],
},
},
})
1 change: 0 additions & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
"p-locate": "^6.0.0",
"p-map": "^7.0.0",
"p-reduce": "^3.0.0",
"package-directory": "^8.0.0",
"path-exists": "^5.0.0",
"path-type": "^6.0.0",
"pretty-ms": "^9.0.0",
Expand Down
7 changes: 5 additions & 2 deletions packages/build/src/install/local.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { packageDirectory } from 'package-directory'
import { dirname } from 'path'

import { up as packagePath } from 'empathic/package'

import { logInstallLocalPluginsDeps } from '../log/messages/install.js'

Expand Down Expand Up @@ -57,6 +59,7 @@ const hasPackageDir = function ({ packageDir }) {

// We only install dependencies of local plugins that have their own `package.json`
const removeMainRoot = async function (localPluginsOptions, buildDir) {
const mainPackageDir = await packageDirectory({ cwd: buildDir })
const mainPackagePath = packagePath({ cwd: buildDir })
const mainPackageDir = mainPackagePath ? dirname(mainPackagePath) : undefined
return localPluginsOptions.filter(({ packageDir }) => packageDir !== mainPackageDir)
}
2 changes: 1 addition & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
"cron-parser": "^4.1.0",
"deepmerge": "^4.2.2",
"dot-prop": "^9.0.0",
"empathic": "^2.0.0",
"execa": "^8.0.0",
"fast-safe-stringify": "^2.0.7",
"figures": "^6.0.0",
"filter-obj": "^6.0.0",
"find-up": "^7.0.0",
"indent-string": "^5.0.0",
"is-plain-obj": "^4.0.0",
"map-obj": "^5.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/config/src/options/repository_root.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dirname } from 'path'

import { findUp } from 'find-up'
import { dir as findUp } from 'empathic/find'

// Find out repository root among (in priority order):
// - `repositoryRoot` option
Expand All @@ -11,7 +11,7 @@ export const getRepositoryRoot = async function ({ repositoryRoot, cwd }) {
return repositoryRoot
}

const repositoryRootA = await findUp('.git', { cwd, type: 'directory' })
const repositoryRootA = findUp('.git', { cwd })

if (repositoryRootA === undefined) {
return cwd
Expand Down
2 changes: 1 addition & 1 deletion packages/config/src/path.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { existsSync } from 'fs'
import { join, resolve } from 'path'

import { findUp } from 'find-up'
import { file as findUp } from 'empathic/find'
import pLocate from 'p-locate'

const FILENAME = 'netlify.toml'
Expand Down
6 changes: 3 additions & 3 deletions packages/edge-bundler/node/npm_dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { fileURLToPath, pathToFileURL } from 'url'

import { resolve, ParsedImportMap } from '@import-maps/resolve'
import { build } from 'esbuild'
import { findUp } from 'find-up'
import { up as findUp } from 'empathic/find'
import { parseImports } from 'parse-imports'
import tmp from 'tmp-promise'

Expand Down Expand Up @@ -40,7 +40,7 @@ const getTypePathFromTypesPackage = async (
packageName: string,
packageJsonPath: string,
): Promise<string | undefined> => {
const typesPackagePath = await findUp(`node_modules/${getTypesPackageName(packageName)}/package.json`, {
const typesPackagePath = findUp(`node_modules/${getTypesPackageName(packageName)}/package.json`, {
cwd: packageJsonPath,
})
if (!typesPackagePath) {
Expand Down Expand Up @@ -81,7 +81,7 @@ function packageName(specifier: string) {

const safelyDetectTypes = async (pkg: string, basePath: string): Promise<string | undefined> => {
try {
const json = await findUp(`node_modules/${packageName(pkg)}/package.json`, {
const json = findUp(`node_modules/${packageName(pkg)}/package.json`, {
cwd: basePath,
})
if (json) {
Expand Down
14 changes: 4 additions & 10 deletions packages/edge-bundler/node/package_json.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { readFileSync } from 'fs'
import { join } from 'path'
import { dirname, join } from 'path'
import { fileURLToPath } from 'url'

import { findUpSync, pathExistsSync } from 'find-up'
import { file as findUp } from 'empathic/find'

const getPackagePath = () => {
const packagePath = findUpSync(
(directory: string) => {
if (pathExistsSync(join(directory, 'package.json'))) {
return directory
}
},
{ cwd: fileURLToPath(import.meta.url), type: 'directory' },
)
const packageJsonPath = findUp('package.json', { cwd: dirname(fileURLToPath(import.meta.url)) })
const packagePath = packageJsonPath ? dirname(packageJsonPath) : undefined

// We should never get here, but let's show a somewhat useful error message.
if (packagePath === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion packages/edge-bundler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@
"ajv-errors": "^3.0.0",
"better-ajv-errors": "^1.2.0",
"common-path-prefix": "^3.0.0",
"empathic": "^2.0.0",
"env-paths": "^3.0.0",
"esbuild": "0.25.6",
"execa": "^8.0.0",
"find-up": "^7.0.0",
"get-package-name": "^2.2.0",
"get-port": "^7.0.0",
"is-path-inside": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/zip-it-and-ship-it/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
"es-module-lexer": "^1.0.0",
"esbuild": "0.25.6",
"execa": "^8.0.0",
"empathic": "^2.0.0",
"fast-glob": "^3.3.3",
"filter-obj": "^6.0.0",
"find-up": "^7.0.0",
"is-builtin-module": "^3.1.0",
"is-path-inside": "^4.0.0",
"junk": "^4.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createRequire } from 'module'
import { version as nodeVersion } from 'process'

import { findUp } from 'find-up'
import { up as walkUp } from 'empathic/walk'
import { pathExists } from 'path-exists'
// @ts-expect-error doesnt export async
import { async as asyncResolve } from 'resolve'
Expand Down Expand Up @@ -94,7 +94,12 @@ const resolvePathFollowSymlinks = function (path: string, baseDirs: string[]) {
// unlikely, and we don't have any better alternative.
const resolvePackageFallback = async function (moduleName: string, baseDirs: string[], error: Error) {
const mainFilePath = resolvePathFollowSymlinks(moduleName, baseDirs)
const packagePath = await findUp(isPackageDir.bind(null, moduleName), { cwd: mainFilePath, type: 'directory' })
let packagePath
for (const dir of walkUp(mainFilePath)) {
if (await isPackageDir(moduleName, dir)) {
packagePath = dir
}
}

if (packagePath === undefined) {
throw error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { promises as fs } from 'fs'
import { basename, join } from 'path'

import { findUp, findUpStop, pathExists } from 'find-up'
import { up as walkUp } from 'empathic/walk'

export interface PackageJson {
name?: string
Expand All @@ -23,21 +23,26 @@ export interface PackageJsonFile {
}

export const getClosestPackageJson = async (resolveDir: string, boundary?: string): Promise<PackageJsonFile | null> => {
const packageJsonPath = await findUp(
async (directory) => {
// We stop traversing if we're about to leave the boundaries of any
// node_modules directory.
if (basename(directory) === 'node_modules') {
return findUpStop
let packageJsonPath

for (const directory of walkUp(resolveDir, { last: boundary })) {
// We stop traversing if we're about to leave the boundaries of any
// node_modules directory.
if (basename(directory) === 'node_modules') {
break
}

const path = join(directory, 'package.json')
try {
const stats = await fs.stat(path)
if (stats.isFile()) {
packageJsonPath = path
break
}

const path = join(directory, 'package.json')
const hasPackageJson = await pathExists(path)

return hasPackageJson ? path : undefined
},
{ cwd: resolveDir, stopAt: boundary },
)
} catch {
// do nothing, continue searching
}
}

if (packageJsonPath === undefined) {
return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join, relative } from 'path'

import { findUp } from 'find-up'
import { dir as findUp } from 'empathic/find'

const AUTO_PLUGINS_DIR = '.netlify/plugins/'

Expand All @@ -21,5 +21,7 @@ export const createAliases = (
})
}

export const getPluginsModulesPath = (srcDir: string): Promise<string | undefined> =>
findUp(`${AUTO_PLUGINS_DIR}node_modules`, { cwd: srcDir, type: 'directory' })
export const getPluginsModulesPath = (srcDir: string): Promise<string | undefined> => {
const result = findUp(`${AUTO_PLUGINS_DIR}node_modules`, { cwd: srcDir })
return Promise.resolve(result)
}
Loading