Skip to content

Commit

Permalink
Read UNEXPECTED_FULL_TRACE and UNEXPECTED_DEPTH in deno if the script…
Browse files Browse the repository at this point in the history
… has access to environment variables
  • Loading branch information
papandreou committed Aug 4, 2019
1 parent f067a86 commit 3cfca74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
9 changes: 7 additions & 2 deletions lib/defaultDepth.js
@@ -1,3 +1,5 @@
const utils = require('./utils');

let defaultDepth = 3;
const matchDepthParameter =
typeof window !== 'undefined' &&
Expand All @@ -6,7 +8,10 @@ const matchDepthParameter =

if (matchDepthParameter) {
defaultDepth = parseInt(matchDepthParameter[1], 10);
} else if (typeof process !== 'undefined' && process.env.UNEXPECTED_DEPTH) {
defaultDepth = parseInt(process.env.UNEXPECTED_DEPTH, 10);
} else {
const defaultDepthFromEnv = utils.getEnv('UNEXPECTED_DEPTH');
if (defaultDepthFromEnv) {
defaultDepth = parseInt(defaultDepthFromEnv, 10);
}
}
module.exports = defaultDepth;
8 changes: 3 additions & 5 deletions lib/useFullStackTrace.js
@@ -1,16 +1,14 @@
const Promise = require('unexpected-bluebird');
const utils = require('./utils');

let useFullStackTrace = false;
if (typeof window !== 'undefined' && typeof window.location !== 'undefined') {
useFullStackTrace = !!window.location.search.match(
/[?&]full-trace=true(?:$|&)/
);
}

if (
typeof process !== 'undefined' &&
process.env &&
process.env.UNEXPECTED_FULL_TRACE
) {
if (utils.getEnv('UNEXPECTED_FULL_TRACE')) {
Promise.longStackTraces();
useFullStackTrace = true;
}
Expand Down
10 changes: 10 additions & 0 deletions lib/utils.js
@@ -1,4 +1,6 @@
/* eslint-disable no-proto */
/* global Deno */

const canSetPrototype =
Object.setPrototypeOf || { __proto__: [] } instanceof Array;
const greedyIntervalPacker = require('greedy-interval-packer');
Expand Down Expand Up @@ -358,5 +360,13 @@ const utils = (module.exports = {
} else {
return subject.substring(contextLength, subject.length);
}
},

getEnv(varName) {
if (typeof Deno === 'object' && Deno.permissions().env) {
return Deno.env()[varName];
} else if (typeof process === 'object' && process.env) {
return process.env[varName];
}
}
});

0 comments on commit 3cfca74

Please sign in to comment.