diff --git a/LICENSE-3rdparty.csv b/LICENSE-3rdparty.csv index f36fac2da6c..0ce2aba174a 100644 --- a/LICENSE-3rdparty.csv +++ b/LICENSE-3rdparty.csv @@ -29,6 +29,7 @@ require,retry,MIT,Copyright 2011 Tim Koschützki Felix Geisendörfer require,rfdc,MIT,Copyright 2019 David Mark Clements require,semver,ISC,Copyright Isaac Z. Schlueter and Contributors require,shell-quote,mit,Copyright (c) 2013 James Halliday +dev,@apollo/server,MIT,Copyright (c) 2016-2020 Apollo Graph, Inc. (Formerly Meteor Development Group, Inc.) dev,@types/node,MIT,Copyright Authors dev,autocannon,MIT,Copyright 2016 Matteo Collina dev,aws-sdk,Apache 2.0,Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. diff --git a/integration-tests/esbuild/basic-test.js b/integration-tests/esbuild/basic-test.js index dc41b4efa53..5e95234eddf 100755 --- a/integration-tests/esbuild/basic-test.js +++ b/integration-tests/esbuild/basic-test.js @@ -6,6 +6,7 @@ const assert = require('assert') const express = require('express') const http = require('http') require('knex') // has dead code paths for multiple instrumented packages +require('@apollo/server') const app = express() const PORT = 31415 diff --git a/integration-tests/esbuild/package.json b/integration-tests/esbuild/package.json index cc027c59bcf..63e8caa8372 100644 --- a/integration-tests/esbuild/package.json +++ b/integration-tests/esbuild/package.json @@ -18,6 +18,7 @@ "author": "Thomas Hunter II ", "license": "ISC", "dependencies": { + "@apollo/server": "^4.11.0", "aws-sdk": "^2.1446.0", "axios": "^1.6.7", "esbuild": "0.16.12", diff --git a/package.json b/package.json index bf2be1343cd..f2795ada2db 100644 --- a/package.json +++ b/package.json @@ -108,6 +108,7 @@ "tlhunter-sorted-set": "^0.1.0" }, "devDependencies": { + "@apollo/server": "^4.11.0", "@types/node": "^16.18.103", "autocannon": "^4.5.2", "aws-sdk": "^2.1446.0", diff --git a/packages/datadog-esbuild/index.js b/packages/datadog-esbuild/index.js index ce263799023..4a69cf32ebc 100644 --- a/packages/datadog-esbuild/index.js +++ b/packages/datadog-esbuild/index.js @@ -96,7 +96,9 @@ module.exports.setup = function (build) { let pathToPackageJson try { - pathToPackageJson = require.resolve(`${extracted.pkg}/package.json`, { paths: [args.resolveDir] }) + // we can't use require.resolve('pkg/package.json') as ESM modules don't make the file available + pathToPackageJson = require.resolve(`${extracted.pkg}`, { paths: [args.resolveDir] }) + pathToPackageJson = extractPackageAndModulePath(pathToPackageJson).pkgJson } catch (err) { if (err.code === 'MODULE_NOT_FOUND') { if (!internal) { @@ -111,7 +113,7 @@ module.exports.setup = function (build) { } } - const packageJson = require(pathToPackageJson) + const packageJson = JSON.parse(fs.readFileSync(pathToPackageJson).toString()) if (DEBUG) console.log(`RESOLVE: ${args.path}@${packageJson.version}`) diff --git a/packages/datadog-instrumentations/src/utils/src/extract-package-and-module-path.js b/packages/datadog-instrumentations/src/utils/src/extract-package-and-module-path.js index 176c3c618ff..7a48565e379 100644 --- a/packages/datadog-instrumentations/src/utils/src/extract-package-and-module-path.js +++ b/packages/datadog-instrumentations/src/utils/src/extract-package-and-module-path.js @@ -6,7 +6,7 @@ const NM = 'node_modules/' * For a given full path to a module, * return the package name it belongs to and the local path to the module * input: '/foo/node_modules/@co/stuff/foo/bar/baz.js' - * output: { pkg: '@co/stuff', path: 'foo/bar/baz.js' } + * output: { pkg: '@co/stuff', path: 'foo/bar/baz.js', pkgJson: '/foo/node_modules/@co/stuff/package.json' } */ module.exports = function extractPackageAndModulePath (fullPath) { const nm = fullPath.lastIndexOf(NM) @@ -17,17 +17,20 @@ module.exports = function extractPackageAndModulePath (fullPath) { const subPath = fullPath.substring(nm + NM.length) const firstSlash = subPath.indexOf('/') + const firstPath = fullPath.substring(fullPath[0], nm + NM.length) + if (subPath[0] === '@') { const secondSlash = subPath.substring(firstSlash + 1).indexOf('/') - return { pkg: subPath.substring(0, firstSlash + 1 + secondSlash), - path: subPath.substring(firstSlash + 1 + secondSlash + 1) + path: subPath.substring(firstSlash + 1 + secondSlash + 1), + pkgJson: firstPath + subPath.substring(0, firstSlash + 1 + secondSlash) + '/package.json' } } return { pkg: subPath.substring(0, firstSlash), - path: subPath.substring(firstSlash + 1) + path: subPath.substring(firstSlash + 1), + pkgJson: firstPath + subPath.substring(0, firstSlash) + '/package.json' } }