pax_global_header00006660000000000000000000000064151034330330014505gustar00rootroot0000000000000052 comment=a9236d35b77d34d22a33e5efeec823ff305e5e3c read-package-up-12.0.0/000077500000000000000000000000001510343303300145135ustar00rootroot00000000000000read-package-up-12.0.0/.editorconfig000066400000000000000000000002571510343303300171740ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 read-package-up-12.0.0/.gitattributes000066400000000000000000000000231510343303300174010ustar00rootroot00000000000000* text=auto eol=lf read-package-up-12.0.0/.github/000077500000000000000000000000001510343303300160535ustar00rootroot00000000000000read-package-up-12.0.0/.github/security.md000066400000000000000000000002631510343303300202450ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. read-package-up-12.0.0/.github/workflows/000077500000000000000000000000001510343303300201105ustar00rootroot00000000000000read-package-up-12.0.0/.github/workflows/main.yml000066400000000000000000000006451510343303300215640ustar00rootroot00000000000000name: CI on: - push - pull_request jobs: test: name: Node.js ${{ matrix.node-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 24 - 20 steps: - uses: actions/checkout@v5 - uses: actions/setup-node@v6 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test read-package-up-12.0.0/.gitignore000066400000000000000000000000271510343303300165020ustar00rootroot00000000000000node_modules yarn.lock read-package-up-12.0.0/.npmrc000066400000000000000000000000231510343303300156260ustar00rootroot00000000000000package-lock=false read-package-up-12.0.0/fixture/000077500000000000000000000000001510343303300162015ustar00rootroot00000000000000read-package-up-12.0.0/fixture/.gitkeep000066400000000000000000000000001510343303300176200ustar00rootroot00000000000000read-package-up-12.0.0/index.d.ts000066400000000000000000000034511510343303300164170ustar00rootroot00000000000000import {type Except} from 'type-fest'; import { readPackage, readPackageSync, type Options as ReadPackageOptions, type NormalizeOptions as ReadPackageNormalizeOptions, type PackageJson, type NormalizedPackageJson, } from 'read-pkg'; export type Options = { /** The directory to start looking for a package.json file. @default process.cwd() */ cwd?: URL | string; } & Except; export type NormalizeOptions = { /** The directory to start looking for a package.json file. @default process.cwd() */ cwd?: URL | string; } & Except; export type ReadResult = { packageJson: PackageJson; path: string; }; export type NormalizedReadResult = { packageJson: NormalizedPackageJson; path: string; }; /** Read the closest `package.json` file. @example ``` import {readPackageUp} from 'read-package-up'; console.log(await readPackageUp()); // { // packageJson: { // name: 'awesome-package', // version: '1.0.0', // … // }, // path: '/Users/sindresorhus/dev/awesome-package/package.json' // } ``` */ export function readPackageUp(options?: NormalizeOptions): Promise; export function readPackageUp(options: Options): Promise; /** Synchronously read the closest `package.json` file. @example ``` import {readPackageUpSync} from 'read-package-up'; console.log(readPackageUpSync()); // { // packageJson: { // name: 'awesome-package', // version: '1.0.0', // … // }, // path: '/Users/sindresorhus/dev/awesome-package/package.json' // } ``` */ export function readPackageUpSync(options?: NormalizeOptions): NormalizedReadResult | undefined; export function readPackageUpSync(options: Options): ReadResult | undefined; export {PackageJson, NormalizedPackageJson} from 'read-pkg'; read-package-up-12.0.0/index.js000066400000000000000000000011621510343303300161600ustar00rootroot00000000000000import path from 'node:path'; import {findUp, findUpSync} from 'find-up-simple'; import {readPackage, readPackageSync} from 'read-pkg'; export async function readPackageUp(options) { const filePath = await findUp('package.json', options); if (!filePath) { return; } return { packageJson: await readPackage({...options, cwd: path.dirname(filePath)}), path: filePath, }; } export function readPackageUpSync(options) { const filePath = findUpSync('package.json', options); if (!filePath) { return; } return { packageJson: readPackageSync({...options, cwd: path.dirname(filePath)}), path: filePath, }; } read-package-up-12.0.0/license000066400000000000000000000021351510343303300160610ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. read-package-up-12.0.0/package.json000066400000000000000000000020121510343303300167740ustar00rootroot00000000000000{ "name": "read-package-up", "version": "12.0.0", "description": "Read the closest package.json file", "license": "MIT", "repository": "sindresorhus/read-package-up", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "type": "module", "exports": { "types": "./index.d.ts", "default": "./index.js" }, "sideEffects": false, "engines": { "node": ">=20" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "json", "read", "parse", "file", "fs", "graceful", "load", "package", "find", "up", "find-up", "findup", "look-up", "look", "search", "match", "resolve", "parent", "parents", "folder", "directory", "walk", "walking", "path" ], "dependencies": { "find-up-simple": "^1.0.1", "read-pkg": "^10.0.0", "type-fest": "^5.2.0" }, "devDependencies": { "ava": "^6.4.1", "xo": "^1.2.3" } } read-package-up-12.0.0/readme.md000066400000000000000000000030611510343303300162720ustar00rootroot00000000000000# read-package-up > Read the closest package.json file ## Why - [Finds the closest package.json](https://github.com/sindresorhus/find-up) - [Throws more helpful JSON errors](https://github.com/sindresorhus/parse-json) - [Normalizes the data](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) ## Install ```sh npm install read-package-up ``` ## Usage ```js import {readPackageUp} from 'read-package-up'; console.log(await readPackageUp()); /* { packageJson: { name: 'awesome-package', version: '1.0.0', … }, path: '/Users/sindresorhus/dev/awesome-package/package.json' } */ ``` ## API ### readPackageUp(options?) Returns a `Promise`, or `Promise` if no `package.json` was found. ### readPackageUpSync(options?) Returns the result object, or `undefined` if no `package.json` was found. #### options Type: `object` ##### cwd Type: `URL | string`\ Default: `process.cwd()` The directory to start looking for a package.json file. ##### normalize Type: `boolean`\ Default: `true` [Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data. ## Related - [read-pkg](https://github.com/sindresorhus/read-pkg) - Read a package.json file - [package-up](https://github.com/sindresorhus/package-up) - Find the closest package.json file - [find-up](https://github.com/sindresorhus/find-up) - Find a file by walking up parent directories - [package-config](https://github.com/sindresorhus/package-config) - Get namespaced config from the closest package.json read-package-up-12.0.0/test.js000066400000000000000000000014171510343303300160330ustar00rootroot00000000000000import path from 'node:path'; import test from 'ava'; import {readPackageUp, readPackageUpSync} from './index.js'; const cwd = 'fixture'; const packagePath = path.resolve('.', 'package.json'); test('async', async t => { const result = await readPackageUp({cwd}); t.is(result.packageJson.name, 'read-package-up'); t.is(result.path, packagePath); t.deepEqual( await readPackageUp({cwd: new URL(cwd, import.meta.url)}), result, ); t.is(await readPackageUp({cwd: '/'}), undefined); }); test('sync', t => { const result = readPackageUpSync({cwd}); t.is(result.packageJson.name, 'read-package-up'); t.is(result.path, packagePath); t.deepEqual( readPackageUpSync({cwd: new URL(cwd, import.meta.url)}), result, ); t.is(readPackageUpSync({cwd: '/'}), undefined); });