UNPKG

@aws-sdk/util-user-agent-node

Version:

[![NPM version](https://img.shields.io/npm/v/@aws-sdk/util-user-agent-node/latest.svg)](https://www.npmjs.com/package/@aws-sdk/util-user-agent-node) [![NPM downloads](https://img.shields.io/npm/dm/@aws-sdk/util-user-agent-node.svg)](https://www.npmjs.com/

16 lines (15 loc) 528 B
import { normalize, sep } from "node:path"; export const getNodeModulesParentDirs = (dirname) => { const cwd = process.cwd(); if (!dirname) { return [cwd]; } const normalizedPath = normalize(dirname); const parts = normalizedPath.split(sep); const nodeModulesIndex = parts.indexOf("node_modules"); const parentDir = nodeModulesIndex !== -1 ? parts.slice(0, nodeModulesIndex).join(sep) : normalizedPath; if (cwd === parentDir) { return [cwd]; } return [parentDir, cwd]; };