pax_global_header00006660000000000000000000000064134553423060014517gustar00rootroot0000000000000052 comment=602fb3f95c0c0725471a8fb403c41a2e752c51ba resolve-pkg-2.0.0/000077500000000000000000000000001345534230600137545ustar00rootroot00000000000000resolve-pkg-2.0.0/.editorconfig000066400000000000000000000002571345534230600164350ustar00rootroot00000000000000root = 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 resolve-pkg-2.0.0/.gitattributes000066400000000000000000000000231345534230600166420ustar00rootroot00000000000000* text=auto eol=lf resolve-pkg-2.0.0/.gitignore000066400000000000000000000000271345534230600157430ustar00rootroot00000000000000node_modules yarn.lock resolve-pkg-2.0.0/.npmrc000066400000000000000000000000231345534230600150670ustar00rootroot00000000000000package-lock=false resolve-pkg-2.0.0/.travis.yml000066400000000000000000000000541345534230600160640ustar00rootroot00000000000000language: node_js node_js: - '10' - '8' resolve-pkg-2.0.0/fixtures/000077500000000000000000000000001345534230600156255ustar00rootroot00000000000000resolve-pkg-2.0.0/fixtures/private-module-test/000077500000000000000000000000001345534230600215375ustar00rootroot00000000000000resolve-pkg-2.0.0/fixtures/private-module-test/package.json000066400000000000000000000000771345534230600240310ustar00rootroot00000000000000{ "name": "@someprivate/module-test", "version": "0.0.0" } resolve-pkg-2.0.0/index.d.ts000066400000000000000000000014241345534230600156560ustar00rootroot00000000000000declare namespace resolvePkg { interface Options { /** Directory to resolve from. @default process.cwd() */ readonly cwd?: string; } } /** Resolve the path of a package regardless of it having an entry point. @param moduleId - What you would use in `require()`. @example ``` import resolvePkg = require('resolve-pkg'); // $ npm install --save-dev grunt-svgmin resolvePkg('grunt-svgmin/tasks', {cwd: __dirname}); //=> '/Users/sindresorhus/unicorn/node_modules/grunt-svgmin/tasks' // Fails here as Grunt tasks usually don't have a defined main entry point require.resolve('grunt-svgmin/tasks'); //=> Error: Cannot find module 'grunt-svgmin' ``` */ declare function resolvePkg( moduleId: string, options?: resolvePkg.Options ): string | undefined; export = resolvePkg; resolve-pkg-2.0.0/index.js000066400000000000000000000011401345534230600154150ustar00rootroot00000000000000'use strict'; const path = require('path'); const resolveFrom = require('resolve-from'); module.exports = (moduleId, options = {}) => { const parts = moduleId.replace(/\\/g, '/').split('/'); let packageName = ''; // Handle scoped package name if (parts.length > 0 && parts[0][0] === '@') { packageName += parts.shift() + '/'; } packageName += parts.shift(); const packageJson = path.join(packageName, 'package.json'); const resolved = resolveFrom.silent(options.cwd || process.cwd(), packageJson); if (!resolved) { return; } return path.join(path.dirname(resolved), parts.join('/')); }; resolve-pkg-2.0.0/index.test-d.ts000066400000000000000000000002711345534230600166320ustar00rootroot00000000000000import {expectType} from 'tsd'; import resolvePkg = require('.'); expectType(resolvePkg('hello')); expectType(resolvePkg('hello', {cwd: '.'})); resolve-pkg-2.0.0/license000066400000000000000000000021251345534230600153210ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (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. resolve-pkg-2.0.0/package.json000066400000000000000000000021301345534230600162360ustar00rootroot00000000000000{ "name": "resolve-pkg", "version": "2.0.0", "description": "Resolve the path of a package regardless of it having an entry point", "license": "MIT", "repository": "sindresorhus/resolve-pkg", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=8" }, "scripts": { "pretest": "del node_modules/@someprivate/module-test && make-dir node_modules/@someprivate/module-test && cpy 'fixtures/private-module-test/*' node_modules/@someprivate/module-test/", "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "require", "resolve", "path", "module", "from", "like", "path", "cwd", "current", "working", "directory", "grunt", "main", "entry", "point" ], "dependencies": { "resolve-from": "^5.0.0" }, "devDependencies": { "@someprivate/module-test": "file:./fixtures/private-module-test", "ava": "^1.4.1", "cpy-cli": "^2.0.0", "del-cli": "^1.1.0", "grunt-svgmin": "^6.0.0", "make-dir-cli": "^2.0.0", "tsd": "^0.7.2", "xo": "^0.24.0" } } resolve-pkg-2.0.0/readme.md000066400000000000000000000037121345534230600155360ustar00rootroot00000000000000# resolve-pkg [![Build Status](https://travis-ci.org/sindresorhus/resolve-pkg.svg?branch=master)](https://travis-ci.org/sindresorhus/resolve-pkg) > Resolve the path of a package regardless of it having an entry point Some packages like CLI tools and grunt tasks don't have a entry point, like `"main": "foo.js"` in package.json, resulting in them not being resolvable by `require.resolve()`. Unlike `require.resolve()`, this module also resolves packages without an entry point, returns `undefined` instead of throwing when the module can't be found, and resolves from `process.cwd()` instead `__dirname` by default. ## Install ``` $ npm install resolve-pkg ``` ## Usage ```js const resolvePkg = require('resolve-pkg'); // $ npm install --save-dev grunt-svgmin resolvePkg('grunt-svgmin/tasks', {cwd: __dirname}); //=> '/Users/sindresorhus/unicorn/node_modules/grunt-svgmin/tasks' // Fails here as Grunt tasks usually don't have a defined main entry point require.resolve('grunt-svgmin/tasks'); //=> Error: Cannot find module 'grunt-svgmin' ``` ## API ### resolvePkg(moduleId, [options]) #### moduleId Type: `string` What you would use in `require()`. #### options ##### cwd Type: `string`
Default: `process.cwd()` Directory to resolve from. ## Related - [resolve-cwd](https://github.com/sindresorhus/resolve-cwd) - Resolve the path of a module from the current working directory - [resolve-from](https://github.com/sindresorhus/resolve-from) - Resolve the path of a module from a given path - [resolve-global](https://github.com/sindresorhus/resolve-global) - Resolve the path of a globally installed module - [import-from](https://github.com/sindresorhus/import-from) - Import a module from a given path - [import-cwd](https://github.com/sindresorhus/import-cwd) - Import a module from the current working directory - [import-lazy](https://github.com/sindresorhus/import-lazy) - Import a module lazily ## License MIT © [Sindre Sorhus](https://sindresorhus.com) resolve-pkg-2.0.0/test.js000066400000000000000000000011361345534230600152720ustar00rootroot00000000000000import path from 'path'; import test from 'ava'; import resolvePkg from '.'; test('main', t => { t.is(resolvePkg('nonexistent'), undefined); t.is(resolvePkg('nonexistent/foo'), undefined); t.is(path.relative('.', resolvePkg('grunt-svgmin')), 'node_modules/grunt-svgmin'); t.is(path.relative('.', resolvePkg('grunt-svgmin/tasks')), 'node_modules/grunt-svgmin/tasks'); t.is(path.relative('.', resolvePkg('@someprivate/module-test')), 'node_modules/@someprivate/module-test'); t.is(path.relative('.', resolvePkg('@someprivate/module-test/subdir')), 'node_modules/@someprivate/module-test/subdir'); });