@contrast/agentify
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -18,3 +18,3 @@ /* | ||
module.exports = function(core) { | ||
module.exports = function (core) { | ||
const { logger, patcher } = core; | ||
@@ -32,4 +32,2 @@ | ||
const contrastMethods = { | ||
// TODO: Assess will require add'l methods | ||
// TODO: ESM will require add'l methods | ||
api: { | ||
@@ -39,7 +37,9 @@ eval(v) { | ||
}, | ||
plus(left, right) { | ||
// Binary Operators | ||
add(left, right) { | ||
const ret = getOrig(left) + getOrig(right); | ||
return ret; | ||
}, | ||
doubleEqual(left, right) { | ||
eqEq(left, right) { | ||
left = getOrig(left); | ||
@@ -50,15 +50,15 @@ right = getOrig(right); | ||
}, | ||
notTripleEqual(left, right) { | ||
eqEqEq(left, right) { | ||
left = getOrig(left); | ||
right = getOrig(right); | ||
return left !== right; | ||
return left === right; | ||
}, | ||
tripleEqual(left, right) { | ||
notEqEq(left, right) { | ||
left = getOrig(left); | ||
right = getOrig(right); | ||
return left === right; | ||
return left !== right; | ||
}, | ||
notDoubleEqual(left, right) { | ||
notEq(left, right) { | ||
left = getOrig(left); | ||
@@ -69,8 +69,10 @@ right = getOrig(right); | ||
}, | ||
// Computed Properties | ||
// Used to force a copy of handle: | ||
// https://stackoverflow.com/a/31733628 | ||
// This is a workaround for CONTRAST-30333, in which something we | ||
// suspect is a v8 bug means that handle will otherwise be clobbered | ||
// and if it was externalized, we will lose the data associated with it | ||
forceCopy(handle) { | ||
// Used to force a copy of handle: | ||
// https://stackoverflow.com/a/31733628 | ||
// This is a workaround for CONTRAST-30333, in which something we | ||
// suspect is a v8 bug means that handle will otherwise be clobbered | ||
// and if it was externalized, we will lose the data associated with it | ||
if (typeof handle === 'string') { | ||
@@ -81,21 +83,72 @@ handle = toUntrackedString(handle); | ||
}, | ||
cast: function __cast(val) { | ||
// Switch Case | ||
cast(val) { | ||
return getOrig(val); | ||
}, | ||
tag: function __contrastTag(strings) { | ||
// XXX implemented in lib/assess/propagators/templates.js | ||
/** | ||
* Tagged Templates | ||
* The first argument received by the tag function is an array of strings. | ||
* For any template literal, its length is equal to the number of | ||
* substitutions (occurrences of ${...}) plus one, and is therefore always | ||
* non-empty. | ||
* see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates | ||
* @param {string[]} strings length n+1 | ||
* @param {string[]} args length n | ||
* @returns {string} | ||
*/ | ||
tag(strings, ...args) { | ||
const [first, ...rest] = strings; | ||
return rest.reduce( | ||
(result, str, i) => result.concat(args[i], str), | ||
first, | ||
); | ||
}, | ||
// Import Statements | ||
importDefault(...args) { | ||
// noop | ||
}, | ||
importStarAs(...args) { | ||
// noop | ||
}, | ||
importNamed(...args) { | ||
// noop | ||
}, | ||
// Injections | ||
Function: core.patcher.patch(global.Function, { | ||
name: 'global.Function', | ||
patchType: 'rewrite-injection' | ||
patchType: 'rewrite-injection', | ||
}), | ||
JSON: core.patcher.patch(global.JSON, { | ||
name: 'global.JSON', | ||
patchType: 'rewrite-injection', | ||
}), | ||
Number: core.patcher.patch(global.Number, { | ||
name: 'global.Number', | ||
patchType: 'rewrite-injection', | ||
}), | ||
Object: core.patcher.patch(global.Object, { | ||
name: 'global.Object', | ||
patchType: 'rewrite-injection', | ||
}), | ||
String: core.patcher.patch(global.String, { | ||
name: 'global.String', | ||
patchType: 'rewrite-injection', | ||
}), | ||
}, | ||
installed: false, | ||
getGlobal() { | ||
return global; | ||
} | ||
}, | ||
}; | ||
contrastMethods.install = function() { | ||
contrastMethods.install = function () { | ||
if (contrastMethods.installed) { | ||
@@ -111,3 +164,3 @@ return; | ||
configurable: false, | ||
value: contrastMethods.api | ||
value: contrastMethods.api, | ||
}); | ||
@@ -118,7 +171,7 @@ contrastMethods.installed = true; | ||
// controlled, but still we should have the defensive code. | ||
logger.error({ err }, 'Unable to install global.ContrastMethods'); | ||
logger.error({ err }, 'Unable to inject global.ContrastMethods'); | ||
} | ||
}; | ||
return core.contrastMethods = contrastMethods; | ||
return (core.contrastMethods = contrastMethods); | ||
}; |
@@ -84,3 +84,3 @@ /* | ||
unwritten = unwritten.replace(FUNCTION_CONTEXT, ''); | ||
unwritten = unwritten.replace(/;$/, ''); // removes trailing semicolon | ||
unwritten = unwritten.replace(/;\s*$/, ''); // removes trailing semicolon/whitespace | ||
return unwritten; | ||
@@ -87,0 +87,0 @@ } catch (err) { |
@@ -34,3 +34,4 @@ /* | ||
'depHooks', | ||
'enhancedLibraryUsage', | ||
'routeCoverage', | ||
'libraryAnalysis', | ||
'rewriteHooks', | ||
@@ -110,3 +111,3 @@ 'functionHooks' | ||
self.logEffectiveConfig(); | ||
self.logDiagnosticFiles(); | ||
return self.runMain.apply(this, args); | ||
@@ -140,25 +141,29 @@ }; | ||
logEffectiveConfig() { | ||
const { config, getEffectiveConfig } = this.core; | ||
logDiagnosticFiles() { | ||
const { config, getEffectiveConfig, getSystemInfo } = this.core; | ||
if (config._flat['agent.diagnostics.enable'] !== false) { | ||
const content = JSON.stringify(getEffectiveConfig(), null, 2).concat('\n\n'); | ||
if (config.agent.diagnostics.enable !== false) { | ||
const effectiveConfig = JSON.stringify(getEffectiveConfig(), null, 2).concat('\n\n'); | ||
const systemInfo = JSON.stringify(getSystemInfo(), null, 2).concat('\n\n'); | ||
if (config._flat['agent.diagnostics.quiet'] !== true) { | ||
fs.writeFileSync(1, content, 'utf8'); | ||
if (!config.agent.diagnostics.quiet) { | ||
fs.writeFileSync(1, effectiveConfig, 'utf8'); | ||
fs.writeFileSync(1, systemInfo, 'utf8'); | ||
} | ||
let outputDir = config._flat['agent.diagnostics.report_path']; | ||
let outputDir = config.agent.diagnostics.report_path; | ||
if (!outputDir && config.agent.logger.path) { | ||
outputDir = path.join(config.agent.logger.path, '../contrast_effective_config.json'); | ||
outputDir = path.join(config.agent.logger.path, '..'); | ||
} | ||
try { | ||
fs.writeFileSync(outputDir, content, 'utf-8'); | ||
fs.writeFileSync(path.join(outputDir, 'contrast_effective_config.json'), effectiveConfig, 'utf-8'); | ||
fs.writeFileSync(path.join(outputDir, 'contrast_system_info.json'), systemInfo, 'utf-8'); | ||
} catch (err) { | ||
outputDir = path.join(process.cwd(), 'contrast_effective_config.json'); | ||
outputDir = path.join(process.cwd()); | ||
try { | ||
fs.writeFileSync(outputDir, content, 'utf-8'); | ||
fs.writeFileSync(path.join(outputDir, 'contrast_effective_config.json'), effectiveConfig, 'utf-8'); | ||
fs.writeFileSync(path.join(outputDir, 'contrast_system_info.json'), systemInfo, 'utf-8'); | ||
} catch (err) { | ||
fs.writeFileSync(1, `Couldn't create effective config file: ${err}`, 'utf-8'); | ||
fs.writeFileSync(1, `Couldn't create the diagnostic files: ${err}`, 'utf-8'); | ||
} | ||
@@ -165,0 +170,0 @@ } |
@@ -30,3 +30,8 @@ /* | ||
let compiled; | ||
const { code } = deps.rewriter.rewrite(content, { filename, inject: true, wrap: true }); | ||
const { code } = deps.rewriter.rewrite(content, { | ||
filename, | ||
isModule: false, | ||
inject: true, | ||
wrap: true, | ||
}); | ||
@@ -33,0 +38,0 @@ try { |
{ | ||
"name": "@contrast/agentify", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Configures Contrast agent services and instrumentation within an application", | ||
@@ -5,0 +5,0 @@ "license": "SEE LICENSE IN LICENSE", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20793
566