@contrast/agentify
Advanced tools
Comparing version 1.21.0 to 1.22.0
@@ -81,3 +81,3 @@ /* | ||
let unwritten = functionHooks.contextualizeFunction(code); | ||
unwritten = rewriter.unwrite(unwritten); | ||
unwritten = rewriter.unwriteSync(unwritten); | ||
unwritten = unwritten.replace(METHOD_CONTEXT, ''); | ||
@@ -84,0 +84,0 @@ unwritten = unwritten.replace(FUNCTION_CONTEXT, ''); |
@@ -16,7 +16,12 @@ /* | ||
import { Installable } from '@contrast/common'; | ||
import { Config } from '@contrast/config'; | ||
import { Installable } from '@contrast/common'; | ||
import { Core as _Core } from '@contrast/core'; | ||
import { Logger } from '@contrast/logger'; | ||
import { Rewriter } from '@contrast/rewriter'; | ||
import RequireHook from '@contrast/require-hook'; | ||
import { Patcher } from '@contrast/patcher'; | ||
import { Scopes } from '@contrast/scopes'; | ||
import { Deadzones } from '@contrast/deadzones'; | ||
import { ReporterBus } from '@contrast/reporter'; | ||
@@ -26,8 +31,18 @@ declare module 'module' { | ||
/** | ||
* @see https://github.com/nodejs/node/blob/main/lib/internal/modules/cjs/loader.js | ||
* @param content The source code of the module | ||
* @param filename The file path of the module | ||
*/ | ||
_compile(content: string, filename: string); | ||
static _extensions: { | ||
/** | ||
* @see https://github.com/nodejs/node/blob/main/lib/internal/modules/cjs/loader.js | ||
* @param content The source code of the module | ||
* @param module The module to compile | ||
* @param filename The file path of the module | ||
*/ | ||
_compile(content: string, filename: string); | ||
['.js'](module: import('module'), filename: string); | ||
}; | ||
} | ||
export = Module; | ||
@@ -41,9 +56,13 @@ } | ||
// TODO: this is now much larger with all of the existing core deps | ||
export interface Core { | ||
readonly config: Config; | ||
readonly depHooks: RequireHook; | ||
readonly logger: Logger; | ||
readonly rewriter: Rewriter; | ||
readonly threadInfo: any; | ||
export interface Core extends _Core { | ||
config: Config; | ||
logger: Logger; | ||
depHooks: RequireHook; | ||
patcher: Patcher | ||
rewriter: Rewriter; | ||
scopes: Scopes; | ||
deadzones: Deadzones; | ||
reporter: ReporterBus; | ||
instrumentation: any; | ||
metrics: any; | ||
} | ||
@@ -56,11 +75,11 @@ | ||
export interface PreRunMain { | ||
(core: any): Installable | void | Promise<Installable | void>; | ||
(core: Core): Installable | void | Promise<Installable | void>; | ||
} | ||
export interface Agentify { | ||
(preRunMain: PreRunMain, opts?: AgentifyOptions): any; | ||
(preRunMain: PreRunMain, opts?: AgentifyOptions): Installable | void; | ||
} | ||
declare function init(core: any): Agentify; | ||
declare function init(core: Partial<Core>): Agentify; | ||
export = init; |
@@ -58,2 +58,4 @@ /* | ||
module.exports = function init(core = {}) { | ||
core.startTime = process.hrtime.bigint(); | ||
let _callback; | ||
@@ -60,0 +62,0 @@ let _opts; |
@@ -19,3 +19,3 @@ /* | ||
const Module = require('module'); | ||
const Module = require('node:module'); | ||
@@ -29,2 +29,3 @@ /** | ||
module.exports = function init(core) { | ||
const js = Module._extensions['.js']; | ||
const { _compile } = Module.prototype; | ||
@@ -34,3 +35,3 @@ | ||
install() { | ||
if (!core.config.agent.node.enable_rewrite) return; | ||
if (!core.config.agent.node.rewrite.enable) return; | ||
@@ -43,3 +44,3 @@ /** | ||
Module.prototype._compile = function (content, filename) { | ||
let result; | ||
/** @type {import('@contrast/rewriter').RewriteOpts} */ | ||
const options = { | ||
@@ -50,8 +51,15 @@ filename, | ||
wrap: true, | ||
trim: false, | ||
}; | ||
const { code } = core.rewriter.rewrite(content, options); | ||
const result = core.rewriter.rewriteSync(content, options); | ||
try { | ||
result = _compile.call(this, code, filename); | ||
const compiled = Reflect.apply(_compile, this, [result.code, filename]); | ||
if (core.config.agent.node.rewrite.cache.enable) { | ||
core.rewriter.cache.write(filename, result); | ||
} | ||
return compiled; | ||
} catch (err) { | ||
@@ -63,6 +71,23 @@ core.logger.warn( | ||
); | ||
result = _compile.call(this, content, filename); | ||
return Reflect.apply(_compile, this, [content, filename]); | ||
} | ||
}; | ||
return result; | ||
/** | ||
* @see https://github.com/nodejs/node/blob/main/lib/internal/modules/cjs/loader.js | ||
* @param {Module} module The module to compile | ||
* @param {string} filename The file path of the module | ||
*/ | ||
Module._extensions['.js'] = function (module, filename) { | ||
if (!core.config.agent.node.rewrite.cache.enable) { | ||
return Reflect.apply(js, this, [module, filename]); | ||
} | ||
const cached = core.rewriter.cache.readSync(filename); | ||
// If cached, short circuit the _extensions method and go straight to compile. | ||
return cached | ||
? Reflect.apply(_compile, module, [cached, filename]) | ||
: Reflect.apply(js, this, [module, filename]); | ||
}; | ||
@@ -73,2 +98,3 @@ }, | ||
Module.prototype._compile = _compile; | ||
Module._extensions['.js'] = js; | ||
} | ||
@@ -75,0 +101,0 @@ }; |
{ | ||
"name": "@contrast/agentify", | ||
"version": "1.21.0", | ||
"version": "1.22.0", | ||
"description": "Configures Contrast agent services and instrumentation within an application", | ||
@@ -25,11 +25,11 @@ "license": "SEE LICENSE IN LICENSE", | ||
"@contrast/dep-hooks": "1.3.1", | ||
"@contrast/esm-hooks": "2.3.0", | ||
"@contrast/esm-hooks": "2.4.0", | ||
"@contrast/instrumentation": "1.6.0", | ||
"@contrast/logger": "1.8.0", | ||
"@contrast/metrics": "1.5.0", | ||
"@contrast/metrics": "1.6.0", | ||
"@contrast/patcher": "1.7.1", | ||
"@contrast/reporter": "1.25.0", | ||
"@contrast/rewriter": "1.4.2", | ||
"@contrast/reporter": "1.25.1", | ||
"@contrast/rewriter": "1.5.0", | ||
"@contrast/scopes": "1.4.0" | ||
} | ||
} |
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
23505
565
5
+ Added@contrast/esm-hooks@2.4.0(transitive)
+ Added@contrast/metrics@1.6.0(transitive)
+ Added@contrast/reporter@1.25.1(transitive)
+ Added@contrast/rewriter@1.5.0(transitive)
- Removed@contrast/esm-hooks@2.3.0(transitive)
- Removed@contrast/metrics@1.5.0(transitive)
- Removed@contrast/reporter@1.25.0(transitive)
- Removed@contrast/rewriter@1.4.2(transitive)
Updated@contrast/esm-hooks@2.4.0
Updated@contrast/metrics@1.6.0
Updated@contrast/reporter@1.25.1
Updated@contrast/rewriter@1.5.0