Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid "Cannot redefine property" errors when multiple dependencies ha… #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions magic-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

/** begin setting magic properties into global (required for other functions) */
if (!global.hasOwnProperty('__stack'))
Object.defineProperty(global, '__stack', {
get: function(){
var orig = Error.prepareStackTrace;
Expand All @@ -17,13 +18,15 @@ Object.defineProperty(global, '__stack', {
});

/** returns line number when placing this in your code: __line */
if (!global.hasOwnProperty('__line'))
Object.defineProperty(global, '__line', {
get: function(){
return __stack[1].getLineNumber();
}
});

/** return filename (without directory path or file extension) when placing this in your code: __file */
if (!global.hasOwnProperty('__file'))
Object.defineProperty(global, '__file', {
get: function(){
var file_pieces = __stack[1].getFileName().split(/[\\\/]/).slice(-1)[0].split('.');
Expand All @@ -32,6 +35,7 @@ Object.defineProperty(global, '__file', {
});

/** return file extension (without preceding period) when placing this in your code: __ext */
if (!global.hasOwnProperty('__ext'))
Object.defineProperty(global, '__ext', {
get: function(){
return __stack[1].getFileName().split('.').slice(-1)[0];
Expand All @@ -42,20 +46,23 @@ Object.defineProperty(global, '__ext', {
* return current function
* @source https://gist.github.com/lordvlad/ec81834ddff73aaa1ab0
*/
if (!global.hasOwnProperty('__func'))
Object.defineProperty(global, '__func', {
get: function(){
return arguments.callee.caller && arguments.callee.caller.name || '(anonymous)';
}
});

/** return base path of project */
if (!global.hasOwnProperty('__base'))
Object.defineProperty(global, '__base', {
get: function(){
return process.cwd();
}
});

/** returns filename, a colon, and line number when placing this in your code: __fili */
if (!global.hasOwnProperty('__fili'))
Object.defineProperty(global, '__fili', {
get: function(){
filid = ':'
Expand Down