Skip to content

Commit

Permalink
fix(shared-metrics): removed recursive-copy dependency (#1265)
Browse files Browse the repository at this point in the history
- refs INSTA-12493  
- resolves the following warning:  
  "npm WARN deprecated [email protected]: This module is unsupported and has memory leaks. Avoid using it. Consider using lru-cache for a more robust and tested solution for coalescing async requests by key value."
  • Loading branch information
aryamohanan authored Aug 16, 2024
1 parent e2ac2ad commit 63e67f1
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 30 deletions.
78 changes: 68 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/shared-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@
"@instana/core": "3.15.0",
"detect-libc": "^2.0.2",
"event-loop-lag": "^1.4.0",
"recursive-copy": "^2.0.13",
"fs-extra": "^11.2.0",
"semver": "^7.5.4",
"tar": "^6.2.1"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/tar": "^6.1.6"
},
"optionalDependencies": {
Expand Down
33 changes: 14 additions & 19 deletions packages/shared-metrics/src/util/nativeModuleRetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ const { logger: Logger, uninstrumentedFs: fs } = require('@instana/core');
let logger = Logger.getLogger('shared-metrics/native-module-retry');

const EventEmitter = require('events');
const copy = require('recursive-copy');
const os = require('os');
const tar = require('tar');
const path = require('path');
const detectLibc = require('detect-libc');
const fse = require('fs-extra');

/**
* @typedef {Object} InstanaSharedMetricsOptions
Expand Down Expand Up @@ -183,23 +183,14 @@ function copyPrecompiled(opts, loaderEmitter, callback) {
.then(() => {
// See below for the reason why we append 'precompiled' to the path.
const targetDir = path.join(opts.nativeModulePath, 'precompiled');
const sourceDir = path.join(os.tmpdir(), opts.nativeModuleName);
logger.debug(
`Copying the precompiled build for ${opts.nativeModuleName} ${label} from ${sourceDir} to ${targetDir}.`
);

// @ts-ignore
copy(
path.join(os.tmpdir(), opts.nativeModuleName),
targetDir,
{
overwrite: true,
dot: true
},
// @ts-ignore
cpErr => {
if (cpErr) {
logger.warn(`Copying the precompiled build for ${opts.nativeModuleName} ${label} failed.`, cpErr);
callback(false);
return;
}

fse
.copy(sourceDir, targetDir)
.then(() => {
// We have unpacked and copied the correct precompiled native addon. The next attempt to require the
// dependency should work.
//
Expand All @@ -211,10 +202,14 @@ function copyPrecompiled(opts, loaderEmitter, callback) {
// it will remember and not try to load anything from that path again (a `false` will be
// put into the cache for that cache key). Instead, we force a new path, by adding precompiled
// to the module path and use the absolute path to the module to load it.
logger.debug(`Successfully copied the precompiled build for ${opts.nativeModuleName} ${label}.`);
opts.loadFrom = targetDir;
callback(true);
}
);
})
.catch(error => {
logger.warn(`Copying the precompiled build for ${opts.nativeModuleName} ${label} failed.`, error);
callback(false);
});
})
.catch(tarErr => {
logger.warn(`Unpacking the precompiled build for ${opts.nativeModuleName} ${label} failed.`, tarErr);
Expand Down

0 comments on commit 63e67f1

Please sign in to comment.