tools: update ESLint to 5.12.0

Update ESLint to 5.12.0.

PR-URL: https://github.com/nodejs/node/pull/25347
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
This commit is contained in:
cjihrig 2019-01-04 16:11:19 -05:00
parent 076d8b9f9d
commit ec5884a94f
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
37 changed files with 480 additions and 281 deletions

View File

@ -18,7 +18,7 @@ const fs = require("fs"),
pathIsInside = require("path-is-inside"), pathIsInside = require("path-is-inside"),
stripComments = require("strip-json-comments"), stripComments = require("strip-json-comments"),
stringify = require("json-stable-stringify-without-jsonify"), stringify = require("json-stable-stringify-without-jsonify"),
requireUncached = require("require-uncached"); importFresh = require("import-fresh");
const debug = require("debug")("eslint:config-file"); const debug = require("debug")("eslint:config-file");
@ -156,7 +156,7 @@ function loadLegacyConfigFile(filePath) {
function loadJSConfigFile(filePath) { function loadJSConfigFile(filePath) {
debug(`Loading JS config file: ${filePath}`); debug(`Loading JS config file: ${filePath}`);
try { try {
return requireUncached(filePath); return importFresh(filePath);
} catch (e) { } catch (e) {
debug(`Error reading JavaScript file: ${filePath}`); debug(`Error reading JavaScript file: ${filePath}`);
e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`; e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;

View File

@ -29,8 +29,8 @@ module.exports = {
], ],
messages: { messages: {
missing: "Requires a space {{location}} '{{token}}'", missing: "Requires a space {{location}} '{{token}}'.",
extra: "Unexpected space(s) {{location}} '{{token}}'" extra: "Unexpected space(s) {{location}} '{{token}}'."
} }
}, },

View File

@ -137,8 +137,8 @@ module.exports = {
], ],
messages: { messages: {
unexpectedLowercaseComment: "Comments should not begin with a lowercase character", unexpectedLowercaseComment: "Comments should not begin with a lowercase character.",
unexpectedUppercaseComment: "Comments should not begin with an uppercase character" unexpectedUppercaseComment: "Comments should not begin with an uppercase character."
} }
}, },

View File

@ -92,10 +92,10 @@ module.exports = {
}, },
messages: { messages: {
matchProperty: "Function name `{{funcName}}` should match property name `{{name}}`", matchProperty: "Function name `{{funcName}}` should match property name `{{name}}`.",
matchVariable: "Function name `{{funcName}}` should match variable name `{{name}}`", matchVariable: "Function name `{{funcName}}` should match variable name `{{name}}`.",
notMatchProperty: "Function name `{{funcName}}` should not match property name `{{name}}`", notMatchProperty: "Function name `{{funcName}}` should not match property name `{{name}}`.",
notMatchVariable: "Function name `{{funcName}}` should not match variable name `{{name}}`" notMatchVariable: "Function name `{{funcName}}` should not match variable name `{{name}}`."
} }
}, },

View File

@ -32,7 +32,7 @@ module.exports = {
], ],
messages: { messages: {
maximumExceeded: "Number of classes per file must not exceed {{ max }}" maximumExceeded: "Number of classes per file must not exceed {{ max }}."
} }
}, },
create(context) { create(context) {

View File

@ -107,6 +107,14 @@ module.exports = {
break; break;
// EXCLUDES: e.g. (foo ? a : b).c = bar;
case "ConditionalExpression":
if (parent.test === node) {
return false;
}
break;
// no default // no default
} }

View File

@ -226,8 +226,8 @@ module.exports = {
fixable: "code", fixable: "code",
messages: { messages: {
useSpreadMessage: "Use an object spread instead of `Object.assign` eg: `{ ...foo }`", useSpreadMessage: "Use an object spread instead of `Object.assign` eg: `{ ...foo }`.",
useLiteralMessage: "Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`" useLiteralMessage: "Use an object literal instead of `Object.assign`. eg: `{ foo: bar }`."
} }
}, },

View File

@ -36,6 +36,9 @@ module.exports = {
minItems: 4, minItems: 4,
maxItems: 4 maxItems: 4
}, },
ignoreDeclarationSort: {
type: "boolean"
},
ignoreMemberSort: { ignoreMemberSort: {
type: "boolean" type: "boolean"
} }
@ -51,6 +54,7 @@ module.exports = {
const configuration = context.options[0] || {}, const configuration = context.options[0] || {},
ignoreCase = configuration.ignoreCase || false, ignoreCase = configuration.ignoreCase || false,
ignoreDeclarationSort = configuration.ignoreDeclarationSort || false,
ignoreMemberSort = configuration.ignoreMemberSort || false, ignoreMemberSort = configuration.ignoreMemberSort || false,
memberSyntaxSortOrder = configuration.memberSyntaxSortOrder || ["none", "all", "multiple", "single"], memberSyntaxSortOrder = configuration.memberSyntaxSortOrder || ["none", "all", "multiple", "single"],
sourceCode = context.getSourceCode(); sourceCode = context.getSourceCode();
@ -105,6 +109,7 @@ module.exports = {
return { return {
ImportDeclaration(node) { ImportDeclaration(node) {
if (!ignoreDeclarationSort) {
if (previousDeclaration) { if (previousDeclaration) {
const currentMemberSyntaxGroupIndex = getMemberParameterGroupIndex(node), const currentMemberSyntaxGroupIndex = getMemberParameterGroupIndex(node),
previousMemberSyntaxGroupIndex = getMemberParameterGroupIndex(previousDeclaration); previousMemberSyntaxGroupIndex = getMemberParameterGroupIndex(previousDeclaration);
@ -145,6 +150,9 @@ module.exports = {
} }
} }
previousDeclaration = node;
}
if (!ignoreMemberSort) { if (!ignoreMemberSort) {
const importSpecifiers = node.specifiers.filter(specifier => specifier.type === "ImportSpecifier"); const importSpecifiers = node.specifiers.filter(specifier => specifier.type === "ImportSpecifier");
const getSortableName = ignoreCase ? specifier => specifier.local.name.toLowerCase() : specifier => specifier.local.name; const getSortableName = ignoreCase ? specifier => specifier.local.name.toLowerCase() : specifier => specifier.local.name;
@ -191,8 +199,6 @@ module.exports = {
}); });
} }
} }
previousDeclaration = node;
} }
}; };
} }

View File

@ -19,6 +19,7 @@ declare namespace acorn {
allowReserved?: boolean allowReserved?: boolean
allowReturnOutsideFunction?: boolean allowReturnOutsideFunction?: boolean
allowImportExportEverywhere?: boolean allowImportExportEverywhere?: boolean
allowAwaitOutsideFunction?: boolean
allowHashBang?: boolean allowHashBang?: boolean
locations?: boolean locations?: boolean
onToken?: ((token: Token) => any) | Token[] onToken?: ((token: Token) => any) | Token[]
@ -42,7 +43,7 @@ declare namespace acorn {
getToken(): Token getToken(): Token
[Symbol.iterator](): Iterator<Token> [Symbol.iterator](): Iterator<Token>
} }
static extend(...plugins: (typeof Parser)[]): typeof Parser static extend(...plugins: ((BaseParser: typeof Parser) => typeof Parser)[]): typeof Parser
} }
interface Position { line: number; column: number; offset: number } interface Position { line: number; column: number; offset: number }

View File

@ -325,7 +325,7 @@ var defaultOptions = {
sourceType: "script", sourceType: "script",
// `onInsertedSemicolon` can be a callback that will be called // `onInsertedSemicolon` can be a callback that will be called
// when a semicolon is automatically inserted. It will be passed // when a semicolon is automatically inserted. It will be passed
// th position of the comma as an offset, and if `locations` is // the position of the comma as an offset, and if `locations` is
// enabled, it is given the location as a `{line, column}` object // enabled, it is given the location as a `{line, column}` object
// as second argument. // as second argument.
onInsertedSemicolon: null, onInsertedSemicolon: null,
@ -755,7 +755,8 @@ pp$1.isLet = function() {
skipWhiteSpace.lastIndex = this.pos; skipWhiteSpace.lastIndex = this.pos;
var skip = skipWhiteSpace.exec(this.input); var skip = skipWhiteSpace.exec(this.input);
var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next); var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
if (nextCh === 91 || nextCh === 123) { return true } // '{' and '[' if (nextCh === 123 && !lineBreak.test(this.input.slice(this.end, next)) // '{'
|| nextCh === 91) { return true } // '['
if (isIdentifierStart(nextCh, true)) { if (isIdentifierStart(nextCh, true)) {
var pos = next + 1; var pos = next + 1;
while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; } while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
@ -1645,7 +1646,7 @@ pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
break break
case "ParenthesizedExpression": case "ParenthesizedExpression":
this.toAssignable(node.expression, isBinding); this.toAssignable(node.expression, isBinding, refDestructuringErrors);
break break
case "MemberExpression": case "MemberExpression":
@ -5275,7 +5276,7 @@ pp$8.readWord = function() {
// //
// [walk]: util/walk.js // [walk]: util/walk.js
var version = "6.0.4"; var version = "6.0.5";
// The main exported interface (under `self.acorn` when in the // The main exported interface (under `self.acorn` when in the
// browser) is a `parse` function that takes a code string and // browser) is a `parse` function that takes a code string and

File diff suppressed because one or more lines are too long

View File

@ -319,7 +319,7 @@ var defaultOptions = {
sourceType: "script", sourceType: "script",
// `onInsertedSemicolon` can be a callback that will be called // `onInsertedSemicolon` can be a callback that will be called
// when a semicolon is automatically inserted. It will be passed // when a semicolon is automatically inserted. It will be passed
// th position of the comma as an offset, and if `locations` is // the position of the comma as an offset, and if `locations` is
// enabled, it is given the location as a `{line, column}` object // enabled, it is given the location as a `{line, column}` object
// as second argument. // as second argument.
onInsertedSemicolon: null, onInsertedSemicolon: null,
@ -749,7 +749,8 @@ pp$1.isLet = function() {
skipWhiteSpace.lastIndex = this.pos; skipWhiteSpace.lastIndex = this.pos;
var skip = skipWhiteSpace.exec(this.input); var skip = skipWhiteSpace.exec(this.input);
var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next); var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
if (nextCh === 91 || nextCh === 123) { return true } // '{' and '[' if (nextCh === 123 && !lineBreak.test(this.input.slice(this.end, next)) // '{'
|| nextCh === 91) { return true } // '['
if (isIdentifierStart(nextCh, true)) { if (isIdentifierStart(nextCh, true)) {
var pos = next + 1; var pos = next + 1;
while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; } while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
@ -1639,7 +1640,7 @@ pp$2.toAssignable = function(node, isBinding, refDestructuringErrors) {
break break
case "ParenthesizedExpression": case "ParenthesizedExpression":
this.toAssignable(node.expression, isBinding); this.toAssignable(node.expression, isBinding, refDestructuringErrors);
break break
case "MemberExpression": case "MemberExpression":
@ -5269,7 +5270,7 @@ pp$8.readWord = function() {
// //
// [walk]: util/walk.js // [walk]: util/walk.js
var version = "6.0.4"; var version = "6.0.5";
// The main exported interface (under `self.acorn` when in the // The main exported interface (under `self.acorn` when in the
// browser) is a `parse` function that takes a code string and // browser) is a `parse` function that takes a code string and

File diff suppressed because one or more lines are too long

View File

@ -39,5 +39,5 @@
"scripts": { "scripts": {
"prepare": "cd ..; npm run build:main && npm run build:bin" "prepare": "cd ..; npm run build:main && npm run build:bin"
}, },
"version": "6.0.4" "version": "6.0.5"
} }

View File

@ -1,6 +0,0 @@
'use strict';
var callsites = require('callsites');
module.exports = function () {
return callsites()[2].getFileName();
};

View File

@ -1,36 +0,0 @@
# caller-path [![Build Status](https://travis-ci.org/sindresorhus/caller-path.svg?branch=master)](https://travis-ci.org/sindresorhus/caller-path)
> Get the path of the caller module
You can't use [`module.parent`](http://nodejs.org/api/modules.html#modules_module_parent) as modules are cached and it will return the first caller module, not necessarily the current one.
## Install
```
$ npm install --save caller-path
```
## Usage
```js
// foo.js
var callerPath = require('caller-path');
module.exports = function () {
console.log(callerPath());
//=> /Users/sindresorhus/dev/unicorn/bar.js
}
```
```js
// bar.js
var foo = require('./foo');
foo();
```
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)

View File

@ -0,0 +1,73 @@
export interface CallSite {
/**
* Returns the value of `this`.
*/
getThis(): unknown | undefined;
/**
* Returns the type of `this` as a string. This is the name of the function stored in the constructor field of `this`, if available, otherwise the object's `[[Class]]` internal property.
*/
getTypeName(): string | null;
/**
* Returns the current function.
*/
getFunction(): Function | undefined;
/**
* Returns the name of the current function, typically its `name` property. If a name property is not available an attempt will be made to try to infer a name from the function's context.
*/
getFunctionName(): string | null;
/**
* Returns the name of the property of `this` or one of its prototypes that holds the current function.
*/
getMethodName(): string | undefined;
/**
* Returns the name of the script if this function was defined in a script.
*/
getFileName(): string | null;
/**
* Returns the current line number if this function was defined in a script.
*/
getLineNumber(): number | null;
/**
* Returns the current column number if this function was defined in a script.
*/
getColumnNumber(): number | null;
/**
* Returns a string representing the location where `eval` was called if this function was created using a call to `eval`.
*/
getEvalOrigin(): string | undefined;
/**
* Returns `true` if this is a top-level invocation, that is, if it's a global object.
*/
isToplevel(): boolean;
/**
* Returns `true` if this call takes place in code defined by a call to `eval`.
*/
isEval(): boolean;
/**
* Returns `true` if this call is in native V8 code.
*/
isNative(): boolean;
/**
* Returns `true` if this is a constructor call.
*/
isConstructor(): boolean;
}
/**
* Get callsites from the V8 stack trace API.
*
* @returns An array of `CallSite` objects.
*/
export default function callsites(): CallSite[];

View File

@ -1,8 +1,12 @@
'use strict'; 'use strict';
module.exports = function () {
var _ = Error.prepareStackTrace; const callsites = () => {
Error.prepareStackTrace = function (_, stack) { return stack }; const _prepareStackTrace = Error.prepareStackTrace;
var stack = new Error().stack.slice(1); Error.prepareStackTrace = (_, stack) => stack;
Error.prepareStackTrace = _; const stack = new Error().stack.slice(1);
Error.prepareStackTrace = _prepareStackTrace;
return stack; return stack;
}; };
module.exports = callsites;
module.exports.default = callsites;

View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.

View File

@ -2,7 +2,7 @@
"author": { "author": {
"name": "Sindre Sorhus", "name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com", "email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com" "url": "sindresorhus.com"
}, },
"bugs": { "bugs": {
"url": "https://github.com/sindresorhus/callsites/issues" "url": "https://github.com/sindresorhus/callsites/issues"
@ -11,20 +11,23 @@
"deprecated": false, "deprecated": false,
"description": "Get callsites from the V8 stack trace API", "description": "Get callsites from the V8 stack trace API",
"devDependencies": { "devDependencies": {
"mocha": "*" "ava": "^0.25.0",
"tsd-check": "^0.2.1",
"xo": "^0.23.0"
}, },
"engines": { "engines": {
"node": ">=0.10.0" "node": ">=6"
}, },
"files": [ "files": [
"index.js" "index.js",
"index.d.ts"
], ],
"homepage": "https://github.com/sindresorhus/callsites#readme", "homepage": "https://github.com/sindresorhus/callsites#readme",
"keywords": [ "keywords": [
"callsites",
"callsite",
"v8",
"stacktrace", "stacktrace",
"v8",
"callsite",
"callsites",
"stack", "stack",
"trace", "trace",
"function", "function",
@ -39,7 +42,7 @@
"url": "git+https://github.com/sindresorhus/callsites.git" "url": "git+https://github.com/sindresorhus/callsites.git"
}, },
"scripts": { "scripts": {
"test": "mocha" "test": "xo && ava && tsd-check"
}, },
"version": "0.2.0" "version": "3.0.0"
} }

View File

@ -1,47 +1,48 @@
# callsites [![Build Status](https://travis-ci.org/sindresorhus/callsites.svg?branch=master)](https://travis-ci.org/sindresorhus/callsites) # callsites [![Build Status](https://travis-ci.org/sindresorhus/callsites.svg?branch=master)](https://travis-ci.org/sindresorhus/callsites)
> Get callsites from the [V8 stack trace API](https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi) > Get callsites from the [V8 stack trace API](https://v8.dev/docs/stack-trace-api)
## Install ## Install
```sh ```
$ npm install --save callsites $ npm install callsites
``` ```
## Usage ## Usage
```js ```js
var callsites = require('callsites'); const callsites = require('callsites');
function unicorn() { function unicorn() {
console.log(callsites()[0].getFileName()); console.log(callsites()[0].getFileName());
//=> /Users/sindresorhus/dev/callsites/test.js //=> '/Users/sindresorhus/dev/callsites/test.js'
} }
unicorn(); unicorn();
``` ```
## API ## API
Returns an array of callsite objects with the following methods: Returns an array of callsite objects with the following methods:
- `getThis`: returns the value of this - `getThis`: returns the value of `this`.
- `getTypeName`: returns the type of this as a string. This is the name of the function stored in the constructor field of this, if available, otherwise the object's [[Class]] internal property. - `getTypeName`: returns the type of `this` as a string. This is the name of the function stored in the constructor field of `this`, if available, otherwise the object's `[[Class]]` internal property.
- `getFunction`: returns the current function - `getFunction`: returns the current function.
- `getFunctionName`: returns the name of the current function, typically its name property. If a name property is not available an attempt will be made to try to infer a name from the function's context. - `getFunctionName`: returns the name of the current function, typically its `name` property. If a name property is not available an attempt will be made to try to infer a name from the function's context.
- `getMethodName`: returns the name of the property of this or one of its prototypes that holds the current function - `getMethodName`: returns the name of the property of `this` or one of its prototypes that holds the current function.
- `getFileName`: if this function was defined in a script returns the name of the script - `getFileName`: if this function was defined in a script returns the name of the script.
- `getLineNumber`: if this function was defined in a script returns the current line number - `getLineNumber`: if this function was defined in a script returns the current line number.
- `getColumnNumber`: if this function was defined in a script returns the current column number - `getColumnNumber`: if this function was defined in a script returns the current column number
- `getEvalOrigin`: if this function was created using a call to eval returns a CallSite object representing the location where eval was called - `getEvalOrigin`: if this function was created using a call to `eval` returns a string representing the location where `eval` was called.
- `isToplevel`: is this a toplevel invocation, that is, is this the global object? - `isToplevel`: is this a top-level invocation, that is, is this the global object?
- `isEval`: does this call take place in code defined by a call to eval? - `isEval`: does this call take place in code defined by a call to `eval`?
- `isNative`: is this call in native V8 code? - `isNative`: is this call in native V8 code?
- `isConstructor`: is this a constructor call? - `isConstructor`: is this a constructor call?
## License ## License
MIT © [Sindre Sorhus](http://sindresorhus.com) MIT © [Sindre Sorhus](https://sindresorhus.com)

View File

@ -1,18 +1,18 @@
'use strict'; 'use strict';
var path = require('path'); const path = require('path');
var resolveFrom = require('resolve-from'); const resolveFrom = require('resolve-from');
var callerPath = require('caller-path'); const parentModule = require('parent-module');
module.exports = function (moduleId) { module.exports = moduleId => {
if (typeof moduleId !== 'string') { if (typeof moduleId !== 'string') {
throw new TypeError('Expected a string'); throw new TypeError('Expected a string');
} }
var filePath = resolveFrom(path.dirname(callerPath()), moduleId); const filePath = resolveFrom(path.dirname(parentModule(__filename)), moduleId);
// delete itself from module parent // Delete itself from module parent
if (require.cache[filePath] && require.cache[filePath].parent) { if (require.cache[filePath] && require.cache[filePath].parent) {
var i = require.cache[filePath].parent.children.length; let i = require.cache[filePath].parent.children.length;
while (i--) { while (i--) {
if (require.cache[filePath].parent.children[i].id === filePath) { if (require.cache[filePath].parent.children[i].id === filePath) {
@ -21,9 +21,9 @@ module.exports = function (moduleId) {
} }
} }
// delete module from cache // Delete module from cache
delete require.cache[filePath]; delete require.cache[filePath];
// return fresh module // Return fresh module
return require(filePath); return require(filePath);
}; };

View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.

View File

@ -5,27 +5,27 @@
"url": "sindresorhus.com" "url": "sindresorhus.com"
}, },
"bugs": { "bugs": {
"url": "https://github.com/sindresorhus/require-uncached/issues" "url": "https://github.com/sindresorhus/import-fresh/issues"
}, },
"bundleDependencies": false, "bundleDependencies": false,
"dependencies": { "dependencies": {
"caller-path": "^0.1.0", "parent-module": "^1.0.0",
"resolve-from": "^1.0.0" "resolve-from": "^4.0.0"
}, },
"deprecated": false, "deprecated": false,
"description": "Require a module bypassing the cache", "description": "Import a module while bypassing the cache",
"devDependencies": { "devDependencies": {
"ava": "*", "ava": "^1.0.1",
"heapdump": "^0.3.7", "heapdump": "^0.3.12",
"xo": "^0.16.0" "xo": "^0.23.0"
}, },
"engines": { "engines": {
"node": ">=0.10.0" "node": ">=6"
}, },
"files": [ "files": [
"index.js" "index.js"
], ],
"homepage": "https://github.com/sindresorhus/require-uncached#readme", "homepage": "https://github.com/sindresorhus/import-fresh#readme",
"keywords": [ "keywords": [
"require", "require",
"cache", "cache",
@ -36,19 +36,14 @@
"bypass" "bypass"
], ],
"license": "MIT", "license": "MIT",
"name": "require-uncached", "name": "import-fresh",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/sindresorhus/require-uncached.git" "url": "git+https://github.com/sindresorhus/import-fresh.git"
}, },
"scripts": { "scripts": {
"heapdump": "node heapdump.js", "heapdump": "node heapdump.js",
"test": "xo && ava" "test": "xo && ava"
}, },
"version": "1.0.3", "version": "3.0.0"
"xo": {
"rules": {
"import/no-dynamic-require": "off"
}
}
} }

View File

@ -0,0 +1,50 @@
# import-fresh [![Build Status](https://travis-ci.org/sindresorhus/import-fresh.svg?branch=master)](https://travis-ci.org/sindresorhus/import-fresh)
> Import a module while bypassing the [cache](https://nodejs.org/api/modules.html#modules_caching)
Useful for testing purposes when you need to freshly import a module.
## Install
```
$ npm install import-fresh
```
## Usage
```js
// foo.js
let i = 0;
module.exports = () => ++i;
```
```js
const importFresh = require('import-fresh');
require('./foo')();
//=> 1
require('./foo')();
//=> 2
importFresh('./foo')();
//=> 1
importFresh('./foo')();
//=> 1
```
## Related
- [clear-module](https://github.com/sindresorhus/clear-module) - Clear a module from the import cache
- [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 modules lazily
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

View File

@ -0,0 +1,33 @@
'use strict';
const callsites = require('callsites');
module.exports = filepath => {
const stacks = callsites();
if (!filepath) {
return stacks[2].getFileName();
}
let seenVal = false;
// Skip the first stack as it's this function
stacks.shift();
for (const stack of stacks) {
const parentFilepath = stack.getFileName();
if (parentFilepath === filepath) {
seenVal = true;
continue;
}
// Skip native modules
if (parentFilepath === 'module.js') {
continue;
}
if (seenVal && parentFilepath !== filepath) {
return parentFilepath;
}
}
};

View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.

View File

@ -2,33 +2,38 @@
"author": { "author": {
"name": "Sindre Sorhus", "name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com", "email": "sindresorhus@gmail.com",
"url": "http://sindresorhus.com" "url": "sindresorhus.com"
}, },
"bugs": { "bugs": {
"url": "https://github.com/sindresorhus/caller-path/issues" "url": "https://github.com/sindresorhus/parent-module/issues"
}, },
"bundleDependencies": false, "bundleDependencies": false,
"dependencies": { "dependencies": {
"callsites": "^0.2.0" "callsites": "^3.0.0"
}, },
"deprecated": false, "deprecated": false,
"description": "Get the path of the caller module", "description": "Get the path of the parent module",
"devDependencies": { "devDependencies": {
"mocha": "*" "ava": "^1.0.1",
"execa": "^1.0.0",
"xo": "^0.23.0"
}, },
"engines": { "engines": {
"node": ">=0.10.0" "node": ">=6"
}, },
"files": [ "files": [
"index.js" "index.js"
], ],
"homepage": "https://github.com/sindresorhus/caller-path#readme", "homepage": "https://github.com/sindresorhus/parent-module#readme",
"keywords": [ "keywords": [
"parent",
"module",
"package",
"pkg",
"caller", "caller",
"calling", "calling",
"module", "module",
"path", "path",
"parent",
"callsites", "callsites",
"callsite", "callsite",
"stacktrace", "stacktrace",
@ -38,13 +43,13 @@
"file" "file"
], ],
"license": "MIT", "license": "MIT",
"name": "caller-path", "name": "parent-module",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/sindresorhus/caller-path.git" "url": "git+https://github.com/sindresorhus/parent-module.git"
}, },
"scripts": { "scripts": {
"test": "mocha" "test": "xo && ava"
}, },
"version": "0.1.0" "version": "1.0.0"
} }

View File

@ -0,0 +1,66 @@
# parent-module [![Build Status](https://travis-ci.org/sindresorhus/parent-module.svg?branch=master)](https://travis-ci.org/sindresorhus/parent-module)
> Get the path of the parent module
Node.js exposes `module.parent`, but it only gives you the first cached parent, which is not necessarily the actual parent.
## Install
```
$ npm install --save parent-module
```
## Usage
```js
// bar.js
const parentModule = require('parent-module');
module.exports = () => {
console.log(parentModule());
//=> '/Users/sindresorhus/dev/unicorn/foo.js'
}
```
```js
// foo.js
const bar = require('./bar');
bar();
```
## API
### parentModule([filepath])
By default, it will return the path of the immediate parent.
#### filepath
Type: `string`<br>
Default: [`__filename`](https://nodejs.org/api/globals.html#globals_filename)
Filepath of the module of which to get the parent path.
Useful if you want it to work [multiple module levels down](https://github.com/sindresorhus/parent-module/tree/master/fixtures/filepath).
## Tip
Combine it with [`read-pkg-up`](https://github.com/sindresorhus/read-pkg-up) to read the package.json of the parent module.
```js
const path = require('path');
const readPkgUp = require('read-pkg-up');
const parentModule = require('parent-module');
console.log(readPkgUp.sync({cwd: path.dirname(parentModule())}).pkg);
//=> {name: 'chalk', version: '1.0.0', ...}
```
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

View File

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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.

View File

@ -1,47 +0,0 @@
# require-uncached [![Build Status](https://travis-ci.org/sindresorhus/require-uncached.svg?branch=master)](https://travis-ci.org/sindresorhus/require-uncached)
> Require a module bypassing the [cache](https://nodejs.org/api/modules.html#modules_caching)
Useful for testing purposes when you need to freshly require a module.
## Install
```
$ npm install --save require-uncached
```
## Usage
```js
// foo.js
let i = 0;
module.exports = () => ++i;
```
```js
const requireUncached = require('require-uncached');
require('./foo')();
//=> 1
require('./foo')();
//=> 2
requireUncached('./foo')();
//=> 1
requireUncached('./foo')();
//=> 1
```
## Related
- [clear-require](https://github.com/sindresorhus/clear-require) - Clear a module from the require cache
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

View File

@ -1,19 +1,47 @@
'use strict'; 'use strict';
var path = require('path'); const path = require('path');
var Module = require('module'); const Module = require('module');
const fs = require('fs');
module.exports = function (fromDir, moduleId) { const resolveFrom = (fromDir, moduleId, silent) => {
if (typeof fromDir !== 'string' || typeof moduleId !== 'string') { if (typeof fromDir !== 'string') {
throw new TypeError('Expected `fromDir` and `moduleId` to be a string'); throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDir}\``);
} }
if (typeof moduleId !== 'string') {
throw new TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof moduleId}\``);
}
try {
fromDir = fs.realpathSync(fromDir);
} catch (err) {
if (err.code === 'ENOENT') {
fromDir = path.resolve(fromDir); fromDir = path.resolve(fromDir);
} else if (silent) {
return null;
} else {
throw err;
}
}
var fromFile = path.join(fromDir, 'noop.js'); const fromFile = path.join(fromDir, 'noop.js');
return Module._resolveFilename(moduleId, { const resolveFileName = () => Module._resolveFilename(moduleId, {
id: fromFile, id: fromFile,
filename: fromFile, filename: fromFile,
paths: Module._nodeModulePaths(fromDir) paths: Module._nodeModulePaths(fromDir)
}); });
if (silent) {
try {
return resolveFileName();
} catch (err) {
return null;
}
}
return resolveFileName();
}; };
module.exports = (fromDir, moduleId) => resolveFrom(fromDir, moduleId);
module.exports.silent = (fromDir, moduleId) => resolveFrom(fromDir, moduleId, true);

View File

@ -1,21 +1,9 @@
The MIT License (MIT) MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com) Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
Permission is hereby granted, free of charge, to any person obtaining a copy 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:
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 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 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.
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.

View File

@ -9,13 +9,13 @@
}, },
"bundleDependencies": false, "bundleDependencies": false,
"deprecated": false, "deprecated": false,
"description": "Resolve the path of a module like require.resolve() but from a given path", "description": "Resolve the path of a module like `require.resolve()` but from a given path",
"devDependencies": { "devDependencies": {
"ava": "*", "ava": "*",
"xo": "*" "xo": "*"
}, },
"engines": { "engines": {
"node": ">=0.10.0" "node": ">=4"
}, },
"files": [ "files": [
"index.js" "index.js"
@ -28,7 +28,7 @@
"module", "module",
"from", "from",
"like", "like",
"path" "import"
], ],
"license": "MIT", "license": "MIT",
"name": "resolve-from", "name": "resolve-from",
@ -39,5 +39,5 @@
"scripts": { "scripts": {
"test": "xo && ava" "test": "xo && ava"
}, },
"version": "1.0.1" "version": "4.0.0"
} }

View File

@ -1,12 +1,12 @@
# resolve-from [![Build Status](https://travis-ci.org/sindresorhus/resolve-from.svg?branch=master)](https://travis-ci.org/sindresorhus/resolve-from) # resolve-from [![Build Status](https://travis-ci.org/sindresorhus/resolve-from.svg?branch=master)](https://travis-ci.org/sindresorhus/resolve-from)
> Resolve the path of a module like [`require.resolve()`](http://nodejs.org/api/globals.html#globals_require_resolve) but from a given path > Resolve the path of a module like [`require.resolve()`](https://nodejs.org/api/globals.html#globals_require_resolve) but from a given path
## Install ## Install
``` ```
$ npm install --save resolve-from $ npm install resolve-from
``` ```
@ -15,7 +15,7 @@ $ npm install --save resolve-from
```js ```js
const resolveFrom = require('resolve-from'); const resolveFrom = require('resolve-from');
// there's a file at `./foo/bar.js` // There is a file at `./foo/bar.js`
resolveFrom('foo', './bar'); resolveFrom('foo', './bar');
//=> '/Users/sindresorhus/dev/test/foo/bar.js' //=> '/Users/sindresorhus/dev/test/foo/bar.js'
@ -26,11 +26,17 @@ resolveFrom('foo', './bar');
### resolveFrom(fromDir, moduleId) ### resolveFrom(fromDir, moduleId)
Like `require()`, throws when the module can't be found.
### resolveFrom.silent(fromDir, moduleId)
Returns `null` instead of throwing when the module can't be found.
#### fromDir #### fromDir
Type: `string` Type: `string`
The directory to resolve from. Directory to resolve from.
#### moduleId #### moduleId
@ -41,7 +47,7 @@ What you would use in `require()`.
## Tip ## Tip
Create a partial using a bound function if you want to require from the same `fromDir` multiple times: Create a partial using a bound function if you want to resolve from the same `fromDir` multiple times:
```js ```js
const resolveFromFoo = resolveFrom.bind(null, 'foo'); const resolveFromFoo = resolveFrom.bind(null, 'foo');
@ -51,6 +57,16 @@ resolveFromFoo('./baz');
``` ```
## Related
- [resolve-cwd](https://github.com/sindresorhus/resolve-cwd) - Resolve the path of a module from the current working directory
- [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
- [resolve-pkg](https://github.com/sindresorhus/resolve-pkg) - Resolve the path of a package regardless of it having an entry point
- [import-lazy](https://github.com/sindresorhus/import-lazy) - Import a module lazily
- [resolve-global](https://github.com/sindresorhus/resolve-global) - Resolve the path of a globally installed module
## License ## License
MIT © [Sindre Sorhus](http://sindresorhus.com) MIT © [Sindre Sorhus](https://sindresorhus.com)

View File

@ -12,13 +12,13 @@
}, },
"bundleDependencies": false, "bundleDependencies": false,
"dependencies": { "dependencies": {
"glob": "^7.0.5" "glob": "^7.1.3"
}, },
"deprecated": false, "deprecated": false,
"description": "A deep deletion module for node (like `rm -rf`)", "description": "A deep deletion module for node (like `rm -rf`)",
"devDependencies": { "devDependencies": {
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"tap": "^10.1.2" "tap": "^12.1.1"
}, },
"files": [ "files": [
"LICENSE", "LICENSE",
@ -35,7 +35,10 @@
"url": "git://github.com/isaacs/rimraf.git" "url": "git://github.com/isaacs/rimraf.git"
}, },
"scripts": { "scripts": {
"postpublish": "git push origin --all; git push origin --tags",
"postversion": "npm publish",
"preversion": "npm test",
"test": "tap test/*.js" "test": "tap test/*.js"
}, },
"version": "2.6.2" "version": "2.6.3"
} }

View File

@ -29,6 +29,7 @@
"glob": "^7.1.2", "glob": "^7.1.2",
"globals": "^11.7.0", "globals": "^11.7.0",
"ignore": "^4.0.6", "ignore": "^4.0.6",
"import-fresh": "^3.0.0",
"imurmurhash": "^0.1.4", "imurmurhash": "^0.1.4",
"inquirer": "^6.1.0", "inquirer": "^6.1.0",
"js-yaml": "^3.12.0", "js-yaml": "^3.12.0",
@ -43,7 +44,6 @@
"pluralize": "^7.0.0", "pluralize": "^7.0.0",
"progress": "^2.0.0", "progress": "^2.0.0",
"regexpp": "^2.0.1", "regexpp": "^2.0.1",
"require-uncached": "^1.0.3",
"semver": "^5.5.1", "semver": "^5.5.1",
"strip-ansi": "^4.0.0", "strip-ansi": "^4.0.0",
"strip-json-comments": "^2.0.1", "strip-json-comments": "^2.0.1",
@ -65,7 +65,7 @@
"coveralls": "^3.0.1", "coveralls": "^3.0.1",
"dateformat": "^3.0.3", "dateformat": "^3.0.3",
"ejs": "^2.6.1", "ejs": "^2.6.1",
"eslint-plugin-eslint-plugin": "^1.4.1", "eslint-plugin-eslint-plugin": "^2.0.1",
"eslint-plugin-node": "^8.0.0", "eslint-plugin-node": "^8.0.0",
"eslint-plugin-rulesdir": "^0.1.0", "eslint-plugin-rulesdir": "^0.1.0",
"eslint-release": "^1.2.0", "eslint-release": "^1.2.0",
@ -76,17 +76,17 @@
"jsdoc": "^3.5.5", "jsdoc": "^3.5.5",
"karma": "^3.0.0", "karma": "^3.0.0",
"karma-babel-preprocessor": "^7.0.0", "karma-babel-preprocessor": "^7.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0", "karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.3", "karma-mocha-reporter": "^2.2.3",
"karma-phantomjs-launcher": "^1.0.4",
"leche": "^2.2.3", "leche": "^2.2.3",
"load-perf": "^0.2.0", "load-perf": "^0.2.0",
"markdownlint": "^0.11.0", "markdownlint": "^0.11.0",
"mocha": "^5.0.5", "mocha": "^5.0.5",
"mock-fs": "^4.6.0", "mock-fs": "^4.6.0",
"npm-license": "^0.3.3", "npm-license": "^0.3.3",
"phantomjs-prebuilt": "^2.1.16",
"proxyquire": "^2.0.1", "proxyquire": "^2.0.1",
"puppeteer": "^1.9.0",
"shelljs": "^0.8.2", "shelljs": "^0.8.2",
"sinon": "^3.3.0", "sinon": "^3.3.0",
"temp": "^0.8.3", "temp": "^0.8.3",
@ -134,5 +134,5 @@
"publish-release": "node Makefile.js publishRelease", "publish-release": "node Makefile.js publishRelease",
"test": "node Makefile.js test" "test": "node Makefile.js test"
}, },
"version": "5.11.1" "version": "5.12.0"
} }