diff options
Diffstat (limited to 'node_modules/get-caller-file')
-rw-r--r-- | node_modules/get-caller-file/README.md | 37 | ||||
-rw-r--r-- | node_modules/get-caller-file/index.d.ts | 2 | ||||
-rw-r--r-- | node_modules/get-caller-file/index.js | 32 | ||||
-rw-r--r-- | node_modules/get-caller-file/index.js.map | 1 | ||||
-rw-r--r-- | node_modules/get-caller-file/package.json | 38 |
5 files changed, 82 insertions, 28 deletions
diff --git a/node_modules/get-caller-file/README.md b/node_modules/get-caller-file/README.md index 194492736..a7d8c0797 100644 --- a/node_modules/get-caller-file/README.md +++ b/node_modules/get-caller-file/README.md @@ -2,3 +2,40 @@ [![Build Status](https://travis-ci.org/stefanpenner/get-caller-file.svg?branch=master)](https://travis-ci.org/stefanpenner/get-caller-file) [![Build status](https://ci.appveyor.com/api/projects/status/ol2q94g1932cy14a/branch/master?svg=true)](https://ci.appveyor.com/project/embercli/get-caller-file/branch/master) + +This is a utility, which allows a function to figure out from which file it was invoked. It does so by inspecting v8's stack trace at the time it is invoked. + +Inspired by http://stackoverflow.com/questions/13227489 + +*note: this relies on Node/V8 specific APIs, as such other runtimes may not work* + +## Installation + +```bash +yarn add get-caller-file +``` + +## Usage + +Given: + +```js +// ./foo.js +const getCallerFile = require('get-caller-file'); + +module.exports = function() { + return getCallerFile(); // figures out who called it +}; +``` + +```js +// index.js +const foo = require('./foo'); + +foo() // => /full/path/to/this/file/index.js +``` + + +## Options: + +* `getCallerFile(position = 2)`: where position is stack frame whos fileName we want. diff --git a/node_modules/get-caller-file/index.d.ts b/node_modules/get-caller-file/index.d.ts new file mode 100644 index 000000000..babed696a --- /dev/null +++ b/node_modules/get-caller-file/index.d.ts @@ -0,0 +1,2 @@ +declare const _default: (position?: number) => any; +export = _default; diff --git a/node_modules/get-caller-file/index.js b/node_modules/get-caller-file/index.js index 03e7dfc39..57304f803 100644 --- a/node_modules/get-caller-file/index.js +++ b/node_modules/get-caller-file/index.js @@ -1,20 +1,22 @@ -'use strict'; - +"use strict"; // Call this function in a another function to find out the file from // which that function was called from. (Inspects the v8 stack trace) // // Inspired by http://stackoverflow.com/questions/13227489 - -module.exports = function getCallerFile(_position) { - var oldPrepareStackTrace = Error.prepareStackTrace; - Error.prepareStackTrace = function(err, stack) { return stack; }; - var stack = new Error().stack; - Error.prepareStackTrace = oldPrepareStackTrace; - - var position = _position ? _position : 2; - - // stack[0] holds this file - // stack[1] holds where this function was called - // stack[2] holds the file we're interested in - return stack[position] ? stack[position].getFileName() : undefined; +module.exports = function getCallerFile(position) { + if (position === void 0) { position = 2; } + if (position >= Error.stackTraceLimit) { + throw new TypeError('getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: `' + position + '` and Error.stackTraceLimit was: `' + Error.stackTraceLimit + '`'); + } + var oldPrepareStackTrace = Error.prepareStackTrace; + Error.prepareStackTrace = function (_, stack) { return stack; }; + var stack = new Error().stack; + Error.prepareStackTrace = oldPrepareStackTrace; + if (stack !== null && typeof stack === 'object') { + // stack[0] holds this file + // stack[1] holds where this function was called + // stack[2] holds the file we're interested in + return stack[position] ? stack[position].getFileName() : undefined; + } }; +//# sourceMappingURL=index.js.map
\ No newline at end of file diff --git a/node_modules/get-caller-file/index.js.map b/node_modules/get-caller-file/index.js.map new file mode 100644 index 000000000..89c655c06 --- /dev/null +++ b/node_modules/get-caller-file/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,qEAAqE;AACrE,EAAE;AACF,0DAA0D;AAE1D,iBAAS,SAAS,aAAa,CAAC,QAAY;IAAZ,yBAAA,EAAA,YAAY;IAC1C,IAAI,QAAQ,IAAI,KAAK,CAAC,eAAe,EAAE;QACrC,MAAM,IAAI,SAAS,CAAC,kGAAkG,GAAG,QAAQ,GAAG,oCAAoC,GAAG,KAAK,CAAC,eAAe,GAAG,GAAG,CAAC,CAAC;KACzM;IAED,IAAM,oBAAoB,GAAG,KAAK,CAAC,iBAAiB,CAAC;IACrD,KAAK,CAAC,iBAAiB,GAAG,UAAC,CAAC,EAAE,KAAK,IAAM,OAAA,KAAK,EAAL,CAAK,CAAC;IAC/C,IAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,KAAK,CAAC;IAChC,KAAK,CAAC,iBAAiB,GAAG,oBAAoB,CAAC;IAG/C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC/C,2BAA2B;QAC3B,gDAAgD;QAChD,8CAA8C;QAC9C,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAE,KAAK,CAAC,QAAQ,CAAS,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;KAC7E;AACH,CAAC,CAAC"}
\ No newline at end of file diff --git a/node_modules/get-caller-file/package.json b/node_modules/get-caller-file/package.json index e853deec1..f2079d6cb 100644 --- a/node_modules/get-caller-file/package.json +++ b/node_modules/get-caller-file/package.json @@ -1,27 +1,28 @@ { - "_from": "get-caller-file@^1.0.1", - "_id": "get-caller-file@1.0.3", + "_from": "get-caller-file@^2.0.1", + "_id": "get-caller-file@2.0.5", "_inBundle": false, - "_integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==", + "_integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "_location": "/get-caller-file", "_phantomChildren": {}, "_requested": { "type": "range", "registry": true, - "raw": "get-caller-file@^1.0.1", + "raw": "get-caller-file@^2.0.1", "name": "get-caller-file", "escapedName": "get-caller-file", - "rawSpec": "^1.0.1", + "rawSpec": "^2.0.1", "saveSpec": null, - "fetchSpec": "^1.0.1" + "fetchSpec": "^2.0.1" }, "_requiredBy": [ + "/nyc/yargs", "/yargs" ], - "_resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", - "_shasum": "f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a", - "_spec": "get-caller-file@^1.0.1", - "_where": "/Users/mperrotte/npminc/cli/node_modules/yargs", + "_resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "_shasum": "4f94412a82db32f36e3b0b9741f8a97feb031f7e", + "_spec": "get-caller-file@^2.0.1", + "_where": "/Users/isaacs/dev/npm/cli/node_modules/yargs", "author": { "name": "Stefan Penner" }, @@ -32,15 +33,25 @@ "deprecated": false, "description": "[![Build Status](https://travis-ci.org/stefanpenner/get-caller-file.svg?branch=master)](https://travis-ci.org/stefanpenner/get-caller-file) [![Build status](https://ci.appveyor.com/api/projects/status/ol2q94g1932cy14a/branch/master?svg=true)](https://ci.appveyor.com/project/embercli/get-caller-file/branch/master)", "devDependencies": { + "@types/chai": "^4.1.7", + "@types/ensure-posix-path": "^1.0.0", + "@types/mocha": "^5.2.6", + "@types/node": "^11.10.5", "chai": "^4.1.2", "ensure-posix-path": "^1.0.1", - "mocha": "^5.2.0" + "mocha": "^5.2.0", + "typescript": "^3.3.3333" }, "directories": { "test": "tests" }, + "engines": { + "node": "6.* || 8.* || >= 10.*" + }, "files": [ - "index.js" + "index.js", + "index.js.map", + "index.d.ts" ], "homepage": "https://github.com/stefanpenner/get-caller-file#readme", "license": "ISC", @@ -51,8 +62,9 @@ "url": "git+https://github.com/stefanpenner/get-caller-file.git" }, "scripts": { + "prepare": "tsc", "test": "mocha test", "test:debug": "mocha test" }, - "version": "1.0.3" + "version": "2.0.5" } |