pax_global_header00006660000000000000000000000064127511732460014522gustar00rootroot0000000000000052 comment=b3fbd48c0c59696a71b420ce41779e59e5872b6b resolve-pkg-0.2.0/000077500000000000000000000000001275117324600137575ustar00rootroot00000000000000resolve-pkg-0.2.0/.editorconfig000066400000000000000000000002761275117324600164410ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,*.yml}] indent_style = space indent_size = 2 resolve-pkg-0.2.0/.gitattributes000066400000000000000000000000141275117324600166450ustar00rootroot00000000000000* text=auto resolve-pkg-0.2.0/.gitignore000066400000000000000000000000151275117324600157430ustar00rootroot00000000000000node_modules resolve-pkg-0.2.0/.travis.yml000066400000000000000000000001011275117324600160600ustar00rootroot00000000000000language: node_js node_js: - '6' - '4' - '0.12' - '0.10' resolve-pkg-0.2.0/fixtures/000077500000000000000000000000001275117324600156305ustar00rootroot00000000000000resolve-pkg-0.2.0/fixtures/private-module-test/000077500000000000000000000000001275117324600215425ustar00rootroot00000000000000resolve-pkg-0.2.0/fixtures/private-module-test/package.json000066400000000000000000000000771275117324600240340ustar00rootroot00000000000000{ "name": "@someprivate/module-test", "version": "0.0.0" } resolve-pkg-0.2.0/index.js000066400000000000000000000011121275117324600154170ustar00rootroot00000000000000'use strict'; var path = require('path'); var resolveFrom = require('resolve-from'); module.exports = function (moduleId, opts) { opts = opts || {}; var parts = moduleId.replace(/\\/g, '/').split('/'); var packageName = ''; // handle scoped package name if (parts.length > 0 && parts[0][0] === '@') { packageName += parts.shift() + '/'; } packageName += parts.shift(); var pkg = path.join(packageName, 'package.json'); var resolved = resolveFrom(opts.cwd || '.', pkg); if (!resolved) { return null; } return path.join(path.dirname(resolved), parts.join('/')); }; resolve-pkg-0.2.0/license000066400000000000000000000021371275117324600153270ustar00rootroot00000000000000The MIT License (MIT) 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-0.2.0/package.json000066400000000000000000000015511275117324600162470ustar00rootroot00000000000000{ "name": "resolve-pkg", "version": "0.2.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": ">=0.10.0" }, "scripts": { "test": "xo && ava" }, "files": [ "index.js" ], "keywords": [ "require", "resolve", "path", "module", "from", "like", "path", "cwd", "current", "working", "directory", "grunt", "main", "entry", "point" ], "dependencies": { "resolve-from": "^2.0.0" }, "devDependencies": { "ava": "*", "grunt-svgmin": "3.3.0", "xo": "*", "@someprivate/module-test": "file:./fixtures/private-module-test" } } resolve-pkg-0.2.0/readme.md000066400000000000000000000035101275117324600155350ustar00rootroot00000000000000# 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 `null` instead of throwing when the module can't be found, and resolves from `process.cwd()` instead `__dirname` by default. ## Install ``` $ npm install --save 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: `boolean`
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 - [req-from](https://github.com/sindresorhus/req-from) - Require a module from a given path - [req-cwd](https://github.com/sindresorhus/req-cwd) - Require a module from the current working directory - [lazy-req](https://github.com/sindresorhus/lazy-req) - Require modules lazily ## License MIT © [Sindre Sorhus](https://sindresorhus.com) resolve-pkg-0.2.0/test.js000066400000000000000000000010161275117324600152720ustar00rootroot00000000000000import path from 'path'; import test from 'ava'; import m from './'; test(t => { t.is(m('nonexistent'), null); t.is(m('nonexistent/foo'), null); t.is(path.relative('.', m('grunt-svgmin')), 'node_modules/grunt-svgmin'); t.is(path.relative('.', m('grunt-svgmin/tasks')), 'node_modules/grunt-svgmin/tasks'); t.is(path.relative('.', m('@someprivate/module-test')), 'node_modules/@someprivate/module-test'); t.is(path.relative('.', m('@someprivate/module-test/subdir')), 'node_modules/@someprivate/module-test/subdir'); });