@instana/core
Advanced tools
Comparing version 2.6.1 to 2.6.2
@@ -6,2 +6,10 @@ # Change Log | ||
## 2.6.2 (2022-08-17) | ||
**Note:** Version bump only for package @instana/core | ||
## [2.6.1](https://github.com/instana/nodejs/compare/v2.6.0...v2.6.1) (2022-08-09) | ||
@@ -8,0 +16,0 @@ |
{ | ||
"name": "@instana/core", | ||
"version": "2.6.1", | ||
"version": "2.6.2", | ||
"description": "Core library for Instana's Node.js packages", | ||
@@ -139,3 +139,3 @@ "main": "src/index.js", | ||
}, | ||
"gitHead": "6910adcc568af60c1f648abc816daff8ff0bccdb" | ||
"gitHead": "14403f521e832904e6aff83f873ef90a2f8ded51" | ||
} |
@@ -33,3 +33,3 @@ /* | ||
* Looks for the app's main package.json file, parses it and returns the parsed content. The search is started at | ||
* path.dirname(process.mainModule.filename). | ||
* path.dirname(require.main.filename). | ||
* | ||
@@ -47,3 +47,3 @@ * In case the search is successful, the result will be cached for consecutive invocations. | ||
* Looks for the app's main package.json file, parses it and returns the parsed content. If the given directory is null | ||
* or undefined, the search will start at path.dirname(process.mainModule.filename). | ||
* or undefined, the search will start at path.dirname(require.main.filename). | ||
* | ||
@@ -88,3 +88,3 @@ * In case the search is successful, the result will be cached for consecutive invocations. | ||
/** | ||
* Looks for path of the app's main package.json file, starting the search at path.dirname(process.mainModule.filename). | ||
* Looks for path of the app's main package.json file, starting the search at path.dirname(require.main.filename). | ||
* | ||
@@ -102,3 +102,3 @@ * In case the search is successful, the result will be cached for consecutive invocations. | ||
* Looks for path of the app's main package.json file, starting the search at the given directory. If the given | ||
* directory is null or undefined, the search will start at path.dirname(process.mainModule.filename). | ||
* directory is null or undefined, the search will start at path.dirname(require.main.filename). | ||
* | ||
@@ -120,14 +120,40 @@ * In case the search is successful, the result will be cached for consecutive invocations. | ||
// No explicit starting directory for searching for the main package.json has been provided, use the Node.js | ||
// process' main module as the starting point. | ||
const mainModule = process.mainModule; | ||
// "require.main" module as the starting point. | ||
// NOTE: "require.main" is undefined when the Instana collector is required inside a | ||
// preloaded module using "--require". "process.mainModule" is not, but it is deprecated and should | ||
// no longer been used. | ||
let mainModule = require.main; | ||
if (!mainModule) { | ||
// This happens | ||
// a) when the Node CLI is evaluating an expression, or | ||
// b) when the REPL is used, or | ||
// c) when we have been pre-required with the --require/-r command line flag | ||
// In particular for case (c) we want to try again later. This is handled in the individual metrics that rely on | ||
// evaluating the package.json file. | ||
return process.nextTick(cb); | ||
// b) when the REPL is used | ||
// c) when we have been pre-required with the --require/-r command line flag. | ||
// | ||
// In particular for case (c) we can try again later and wait for the main module to be loaded. | ||
// But usually that is not necessary because the initialisation of the collector takes longer than | ||
// Node.js having not loaded the main module. Still, it is "ok" to keep the retry mechanismn inside | ||
// the individual metrics (e.g. name.js) just for safety. | ||
// | ||
// But when the application is using ES modules and they require the Instana collector | ||
// with "--require file.cjs", neither `require.main` nor the deprecated `process.mainModule` | ||
// will have a value, because ES modules use `import.meta` and soon `import.main`. | ||
// See https://github.com/nodejs/modules/issues/274 | ||
// eslint-disable-next-line max-len | ||
// See https://github.com/nodejs/node/blob/472edc775d683aed2d9ed39ca7cf381f3e7e3ce2/lib/internal/modules/run_main.js#L79 | ||
// Node.js is using `process.argv[1]` internally as main file path. | ||
// Check whether a module was preloaded and use process.argv[1] as filename. | ||
// @ts-ignore | ||
if (process._preload_modules && process._preload_modules.length > 0) { | ||
// @ts-ignore | ||
mainModule = { | ||
filename: process.argv[1] | ||
}; | ||
} else { | ||
return process.nextTick(cb); | ||
} | ||
} | ||
startDirectory = path.dirname(mainModule.filename); | ||
@@ -237,3 +263,3 @@ } | ||
const mainModule = process.mainModule; | ||
const mainModule = require.main; | ||
if (!mainModule) { | ||
@@ -240,0 +266,0 @@ return process.nextTick(cb); |
635301
17400