pax_global_header00006660000000000000000000000064127522244670014525gustar00rootroot0000000000000052 comment=7545c5b0b7f55a1bfffea4a57e3671d771372025 get-caller-file-1.0.2/000077500000000000000000000000001275222446700144615ustar00rootroot00000000000000get-caller-file-1.0.2/.gitignore000066400000000000000000000000161275222446700164460ustar00rootroot00000000000000node_modules/ get-caller-file-1.0.2/.travis.yml000066400000000000000000000005341275222446700165740ustar00rootroot00000000000000sudo: false language: node_js node_js: - "0.10" - "0.12" - "4.2" - "5" - node os: - linux script: npm test before_install: - curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash - npm config set spin false install: - node --version - npm --version - git --version - npm install --no-optional get-caller-file-1.0.2/README.md000066400000000000000000000004741275222446700157450ustar00rootroot00000000000000# get-caller-file [![Build Status](https://travis-ci.org/ember-cli/ember-cli.svg?branch=master)](https://travis-ci.org/ember-cli/ember-cli) [![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) get-caller-file-1.0.2/appveyor.yml000066400000000000000000000014651275222446700170570ustar00rootroot00000000000000# http://www.appveyor.com/docs/appveyor-yml # Fix line endings in Windows. (runs before repo cloning) init: - git config --global core.autocrlf true # Test against these versions of Node.js. environment: matrix: - nodejs_version: "0.12" - nodejs_version: "4.2" - nodejs_version: "5.0" # Install scripts. (runs after repo cloning) install: - git rev-parse HEAD # Get the latest stable version of Node 0.STABLE.latest - ps: Install-Product node $env:nodejs_version # Typical npm stuff. - md C:\nc - npm config set cache C:\nc - npm version - npm install # Post-install test scripts. test_script: # Output useful info for debugging. - npm version - cmd: npm test # Don't actually build. build: off # Set build version format here instead of in the admin panel. version: "{build}" get-caller-file-1.0.2/fixtures/000077500000000000000000000000001275222446700163325ustar00rootroot00000000000000get-caller-file-1.0.2/fixtures/bar.js000066400000000000000000000001371275222446700174350ustar00rootroot00000000000000'use strict'; var foo = require('./foo.js'); module.exports = function() { return foo(); }; get-caller-file-1.0.2/fixtures/foo.js000066400000000000000000000001561275222446700174550ustar00rootroot00000000000000'use strict'; var getCallerFile = require('../'); module.exports = function() { return getCallerFile(); }; get-caller-file-1.0.2/index.js000066400000000000000000000013251275222446700161270ustar00rootroot00000000000000'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; }; get-caller-file-1.0.2/package.json000066400000000000000000000012431275222446700167470ustar00rootroot00000000000000{ "name": "get-caller-file", "version": "1.0.2", "description": "", "main": "index.js", "directories": { "test": "tests" }, "files": [ "index.js" ], "scripts": { "test": "mocha test", "test:debug": "mocha test" }, "repository": { "type": "git", "url": "git+https://github.com/stefanpenner/get-caller-file.git" }, "author": "Stefan Penner", "license": "ISC", "bugs": { "url": "https://github.com/stefanpenner/get-caller-file/issues" }, "homepage": "https://github.com/stefanpenner/get-caller-file#readme", "devDependencies": { "chai": "^3.4.1", "ensure-posix-path": "^1.0.1", "mocha": "^2.3.4" } } get-caller-file-1.0.2/test.js000066400000000000000000000013101275222446700157710ustar00rootroot00000000000000'use strict'; var getCallerFile = require('./'); var expect = require('chai').expect; var foo = require('./fixtures/foo'); var bar = require('./fixtures/bar'); var ensurePosix = require('ensure-posix-path'); describe('getCallerFile', function() { it('gets current caller file', function() { expect(ensurePosix(getCallerFile())).to.eql(ensurePosix(__dirname + '/node_modules/mocha/lib/runnable.js')); }); it('gets current file, as it is the caller', function() { expect(ensurePosix(foo())).to.eql(ensurePosix(__dirname + '/test.js')); }); it('gets another file, as it is the caller', function() { expect(ensurePosix(bar())).to.eql(ensurePosix(__dirname + '/fixtures/bar.js')); }); });