-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 8, return
undefined
instead of null
, add TypeScri…
…pt definition (#7)
- Loading branch information
1 parent
4974b04
commit 0a350ed
Showing
12 changed files
with
117 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
language: node_js | ||
node_js: | ||
- '6' | ||
- '4' | ||
- '10' | ||
- '8' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
declare 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {expectType} from 'tsd'; | ||
import resolvePkg = require('.'); | ||
|
||
expectType<string | undefined>(resolvePkg('hello')); | ||
expectType<string | undefined>(resolvePkg('hello', {cwd: '.'})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,9 @@ | ||
The MIT License (MIT) | ||
MIT License | ||
|
||
Copyright (c) Sindre Sorhus <[email protected]> (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: | ||
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 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. | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,53 @@ | ||
{ | ||
"name": "resolve-pkg", | ||
"version": "1.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": "[email protected]", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"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": { | ||
"@someprivate/module-test": "file:./fixtures/private-module-test", | ||
"ava": "*", | ||
"grunt-svgmin": "^4.0.0", | ||
"xo": "*" | ||
} | ||
"name": "resolve-pkg", | ||
"version": "1.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": "[email protected]", | ||
"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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import path from 'path'; | ||
import test from 'ava'; | ||
import m from './'; | ||
import resolvePkg 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'); | ||
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'); | ||
}); |