Skip to content

Commit 3c1cd8a

Browse files
authored
chore(types): fix TypeScript errors in the esbuild package (#7438)
1 parent 33297e0 commit 3c1cd8a

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

packages/datadog-esbuild/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ function isESMBuild (build) {
6666
}
6767

6868
function getGitMetadata () {
69+
/**
70+
* @type {object}
71+
* @property {string | null} repositoryURL
72+
* @property {string | null} commitSHA
73+
*/
6974
const gitMetadata = {
7075
repositoryURL: null,
7176
commitSHA: null,
@@ -253,7 +258,7 @@ ${build.initialOptions.banner.js}`
253258
}
254259

255260
try {
256-
const packageJson = JSON.parse(fs.readFileSync(pathToPackageJson).toString())
261+
const packageJson = JSON.parse(fs.readFileSync(/** @type {string} */ (pathToPackageJson)).toString())
257262

258263
const isESM = isESMFile(fullPathToModule, pathToPackageJson, packageJson)
259264
if (isESM && !interceptedESMModules.has(fullPathToModule)) {
@@ -403,5 +408,9 @@ function dotFriendlyResolve (path, directory, usesImportStatement) {
403408
if (path.startsWith('file://')) {
404409
path = fileURLToPath(path)
405410
}
406-
return require.resolve(path, { paths: [directory], conditions })
411+
return require.resolve(path, {
412+
paths: [directory],
413+
// @ts-expect-error - Node.js 22+ unofficially supports a conditions option
414+
conditions,
415+
})
407416
}

packages/datadog-esbuild/src/utils.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ function resolve (specifier, context) {
5959
specifier = fileURLToPath(specifier)
6060
}
6161

62-
const resolved = require.resolve(specifier, { conditions, paths: [fileURLToPath(context.parentURL)] })
62+
const resolved = require.resolve(specifier, {
63+
paths: [fileURLToPath(context.parentURL)],
64+
// @ts-expect-error - Node.js 22+ unofficially supports a conditions option
65+
conditions,
66+
})
6367

6468
return {
6569
url: pathToFileURL(resolved),
@@ -79,12 +83,12 @@ function getSource (url, { format }) {
7983
*
8084
* @param {object} moduleData
8185
* @param {string} moduleData.path
82-
* @param {boolean} moduleData.internal
86+
* @param {boolean} [moduleData.internal = false]
8387
* @param {object} moduleData.context
84-
* @param {boolean} moduleData.excludeDefault
88+
* @param {boolean} [moduleData.excludeDefault = false]
8589
* @returns {Promise<Map>}
8690
*/
87-
async function processModule ({ path, internal, context, excludeDefault }) {
91+
async function processModule ({ path, internal = false, context, excludeDefault = false }) {
8892
let exportNames, srcUrl
8993
if (internal) {
9094
// we can not read and parse of internal modules

0 commit comments

Comments
 (0)