Skip to content

Commit

Permalink
chore: removed <20 to test out versioned tests on node 20
Browse files Browse the repository at this point in the history
  • Loading branch information
bizob2828 committed Aug 14, 2023
1 parent 2b10589 commit 67f2140
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 60 deletions.
1 change: 1 addition & 0 deletions bin/run-versioned-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ if [ ! -z "$JOBS" ];
then
JOBS_ARGS="--jobs $JOBS"
fi
export NR_LOADER=./esm-loader.mjs

if [[ "${NPM7}" = 1 ]];
then
Expand Down
36 changes: 0 additions & 36 deletions lib/esm-shim.mjs

This file was deleted.

3 changes: 3 additions & 0 deletions lib/instrumentation/grpc-js/nr-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ module.exports = [
{
type: 'generic',
moduleName: '@grpc/grpc-js/build/src/resolving-call',
isEsm: true,
onRequire: grpc.wrapStartResolve
},
{
type: 'generic',
moduleName: '@grpc/grpc-js/build/src/call-stream',
isEsm: true,
onRequire: grpc.wrapStartCall
},
{
type: 'web-framework',
moduleName: '@grpc/grpc-js/build/src/server',
isEsm: true,
onRequire: grpc.wrapServer
}
]
37 changes: 20 additions & 17 deletions lib/shimmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ const shimmer = (module.exports = {
registerCoreInstrumentation(agent) {
// Instrument global.
const globalShim = new shims.Shim(agent, 'globals', 'globals')
applyDebugState(globalShim, global)
applyDebugState(globalShim, global, false)
const globalsFilepath = path.join(__dirname, 'instrumentation', 'core', 'globals.js')
_firstPartyInstrumentation(agent, globalsFilepath, globalShim, global, 'globals')

Expand All @@ -340,7 +340,7 @@ const shimmer = (module.exports = {
}

const shim = shims.createShimFromType(core.type, agent, mojule, mojule)
applyDebugState(shim, core)
applyDebugState(shim, core, false)
_firstPartyInstrumentation(agent, filePath, shim, uninstrumented, mojule)
}
},
Expand All @@ -355,9 +355,7 @@ const shimmer = (module.exports = {
return _postLoad(agent, exports, name, basedir)
})
this._iitm = new IitmHook(pkgsToHook, function onESMHook(exports, name, basedir) {
// TOOD: if this is ESM it needs to be the export, otherwise it needs to be the
// default of the export
return _postLoad(agent, exports, name, basedir)
return _postLoad(agent, exports, name, basedir, true)
})
},
removeHooks() {
Expand Down Expand Up @@ -460,16 +458,18 @@ const shimmer = (module.exports = {
}
})

function applyDebugState(shim, nodule) {
function applyDebugState(shim, nodule, inEsm) {
if (shimmer.debug) {
shim.enableDebug()
instrumented.push(shim)
instrumented.push({
[symbols.unwrap]: function unwrapNodule() {
delete nodule[symbols.shim]
}
})
// nodule[symbols.shim] = shim
if (!inEsm) {
instrumented.push({
[symbols.unwrap]: function unwrapNodule() {
delete nodule[symbols.shim]
}
})
nodule[symbols.shim] = shim
}
}
}

Expand All @@ -482,8 +482,9 @@ function applyDebugState(shim, nodule) {
* @param nodule
* @param moduleName
* @param resolvedName
* @param esmResolver
*/
function instrumentPostLoad(agent, nodule, moduleName, resolvedName) {
function instrumentPostLoad(agent, nodule, moduleName, resolvedName, esmResolver) {
const instrumentations = shimmer.registeredInstrumentations[moduleName]
instrumentations.forEach((instrumentation) => {
if (
Expand All @@ -497,6 +498,8 @@ function instrumentPostLoad(agent, nodule, moduleName, resolvedName) {
return
}

const resolvedNodule = instrumentation.isEsm || !esmResolver ? nodule : nodule.default

const shim = shims.createShimFromType(
instrumentation.type,
agent,
Expand All @@ -505,7 +508,7 @@ function instrumentPostLoad(agent, nodule, moduleName, resolvedName) {
instrumentation.shimName
)

applyDebugState(shim, nodule)
applyDebugState(shim, resolvedNodule, esmResolver)
trackInstrumentationUsage(
agent,
shim,
Expand All @@ -522,7 +525,7 @@ function instrumentPostLoad(agent, nodule, moduleName, resolvedName) {
}

try {
if (instrumentation.onRequire(shim, nodule, moduleName) !== false) {
if (instrumentation.onRequire(shim, resolvedNodule, moduleName) !== false) {
nodule = shim.getExport(nodule)
instrumentation[symbols.instrumented] = true
}
Expand Down Expand Up @@ -570,7 +573,7 @@ function _firstPartyInstrumentation(agent, fileName, shim, nodule, moduleName) {
}
}

function _postLoad(agent, nodule, name, resolvedName) {
function _postLoad(agent, nodule, name, resolvedName, esmResolver) {
const instrumentation = shimmer.getInstrumentationNameFromModuleName(name)
const registeredInstrumentation = shimmer.registeredInstrumentations[instrumentation]
const hasPostLoadInstrumentation =
Expand All @@ -581,7 +584,7 @@ function _postLoad(agent, nodule, name, resolvedName) {
// Check if this is a known instrumentation and then run it.
if (hasPostLoadInstrumentation) {
logger.trace('Instrumenting %s with onRequire (module loaded) hook.', name)
return instrumentPostLoad(agent, nodule, instrumentation, resolvedName)
return instrumentPostLoad(agent, nodule, instrumentation, resolvedName, esmResolver)
}

return nodule
Expand Down
2 changes: 1 addition & 1 deletion test/versioned/esm-package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"tests": [
{
"engines": {
"node": ">=16.12.0 <20"
"node": ">=16.12.0"
},
"dependencies": {
"parse-json": "6.0.2"
Expand Down
1 change: 1 addition & 0 deletions test/versioned/esm-package/parse-json.tap.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import parseJsonInstrumentation from './parse-json-instrumentation.mjs'
shimmer.registerInstrumentation({
moduleName: 'parse-json',
type: 'generic',
isEsm: true,
onRequire: parseJsonInstrumentation
})

Expand Down
2 changes: 1 addition & 1 deletion test/versioned/express-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"tests": [
{
"engines": {
"node": ">=16.12.0 <20"
"node": ">=16.12.0"
},
"dependencies": {
"express": ">=4.6.0",
Expand Down
2 changes: 1 addition & 1 deletion test/versioned/grpc-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"tests": [
{
"engines": {
"node": ">=16.12.0 <20"
"node": ">=16.12.0"
},
"dependencies": {
"@grpc/grpc-js": ">=1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion test/versioned/mongodb-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"tests": [
{
"engines": {
"node": ">=16.12.0 <20"
"node": ">=16.12.0"
},
"dependencies": {
"mongodb": ">=2.1 < 4.0.0 || >= 4.1.4 < 5"
Expand Down
4 changes: 2 additions & 2 deletions test/versioned/pg-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"tests": [
{
"engines": {
"node": ">=16.12.0 <20"
"node": ">=16.12.0"
},
"dependencies": {
"pg": ">=8.2 <8.8",
Expand All @@ -20,7 +20,7 @@
},
{
"engines": {
"node": ">=16.12.0 <20"
"node": ">=16.12.0"
},
"dependencies": {
"pg": ">=8.8",
Expand Down
2 changes: 1 addition & 1 deletion third_party_manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lastUpdated": "Fri Aug 11 2023 16:32:55 GMT-0400 (Eastern Daylight Time)",
"lastUpdated": "Mon Aug 14 2023 12:54:19 GMT-0400 (Eastern Daylight Time)",
"projectName": "New Relic Node Agent",
"projectUrl": "https://github.com/newrelic/node-newrelic",
"includeOptDeps": true,
Expand Down

0 comments on commit 67f2140

Please sign in to comment.