Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update dependency require-in-the-middle to v7.1.0 for types and named export #3727

Merged
merged 9 commits into from
May 2, 2023
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to experimental packages in this project will be documented

### :bug: (Bug Fix)

* fix(instrumentation): update `require-in-the-middle` to v7.1.0 [#3727](https://github.com/open-telemetry/opentelemetry-js/pull/3727) @trentm
* fix(instrumentation): update `require-in-the-middle` to v7.0.1 [#3743](https://github.com/open-telemetry/opentelemetry-js/pull/3743) @trentm

### :books: (Refine Doc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"url": "https://github.com/open-telemetry/opentelemetry-js/issues"
},
"dependencies": {
"require-in-the-middle": "^7.0.1",
"require-in-the-middle": "^7.1.0",
"semver": "^7.3.2",
"shimmer": "^1.2.1"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* limitations under the License.
*/

import * as RequireInTheMiddle from 'require-in-the-middle';
import type { OnRequireFn } from 'require-in-the-middle';
import { Hook } from 'require-in-the-middle';
import * as path from 'path';
import { ModuleNameTrie, ModuleNameSeparator } from './ModuleNameTrie';

export type Hooked = {
moduleName: string;
onRequire: RequireInTheMiddle.OnRequireFn;
onRequire: OnRequireFn;
};

/**
Expand Down Expand Up @@ -59,7 +60,7 @@ export class RequireInTheMiddleSingleton {
}

private _initialize() {
RequireInTheMiddle(
new Hook(
dyladan marked this conversation as resolved.
Show resolved Hide resolved
// Intercept all `require` calls; we will filter the matching ones below
null,
{ internals: true },
Expand Down Expand Up @@ -88,13 +89,10 @@ export class RequireInTheMiddleSingleton {
* Register a hook with `require-in-the-middle`
*
* @param {string} moduleName Module name
* @param {RequireInTheMiddle.OnRequireFn} onRequire Hook function
* @param {OnRequireFn} onRequire Hook function
* @returns {Hooked} Registered hook
*/
register(
moduleName: string,
onRequire: RequireInTheMiddle.OnRequireFn
): Hooked {
register(moduleName: string, onRequire: OnRequireFn): Hooked {
const hooked = { moduleName, onRequire };
this._moduleNameTrie.insert(hooked);
return hooked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
} from './RequireInTheMiddleSingleton';
import { InstrumentationModuleDefinition } from './types';
import { diag } from '@opentelemetry/api';
import * as RequireInTheMiddle from 'require-in-the-middle';
import type { OnRequireFn } from 'require-in-the-middle';
import { Hook } from 'require-in-the-middle';

/**
* Base abstract class for instrumenting node plugins
Expand All @@ -34,7 +35,7 @@ export abstract class InstrumentationBase<T = any>
implements types.Instrumentation
{
private _modules: InstrumentationModuleDefinition<T>[];
private _hooks: (Hooked | RequireInTheMiddle.Hooked)[] = [];
private _hooks: (Hooked | Hook)[] = [];
private _requireInTheMiddleSingleton: RequireInTheMiddleSingleton =
RequireInTheMiddleSingleton.getInstance();
private _enabled = false;
Expand Down Expand Up @@ -167,11 +168,7 @@ export abstract class InstrumentationBase<T = any>

this._warnOnPreloadedModules();
for (const module of this._modules) {
const onRequire: RequireInTheMiddle.OnRequireFn = (
exports,
name,
baseDir
) => {
const onRequire: OnRequireFn = (exports, name, baseDir) => {
return this._onRequire<typeof exports>(
module as unknown as InstrumentationModuleDefinition<typeof exports>,
exports,
Expand All @@ -181,9 +178,10 @@ export abstract class InstrumentationBase<T = any>
};

// `RequireInTheMiddleSingleton` does not support absolute paths.
// For an absolute paths, we must create a separate instance of `RequireInTheMiddle`.
// For an absolute paths, we must create a separate instance of the
// require-in-the-middle `Hook`.
const hook = path.isAbsolute(module.name)
? RequireInTheMiddle([module.name], { internals: true }, onRequire)
? new Hook([module.name], { internals: true }, onRequire)
dyladan marked this conversation as resolved.
Show resolved Hide resolved
: this._requireInTheMiddleSingleton.register(module.name, onRequire);

this._hooks.push(hook);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as assert from 'assert';
import * as sinon from 'sinon';
import * as path from 'path';
import * as RequireInTheMiddle from 'require-in-the-middle';
import type { OnRequireFn } from 'require-in-the-middle';
import { RequireInTheMiddleSingleton } from '../../src/platform/node/RequireInTheMiddleSingleton';

const requireInTheMiddleSingleton = RequireInTheMiddleSingleton.getInstance();
Expand All @@ -31,7 +31,7 @@ const makeOnRequiresStub = (label: string): sinon.SinonStub =>
exports.__ritmOnRequires ??= [];
exports.__ritmOnRequires.push(label);
return exports;
}) as RequireInTheMiddle.OnRequireFn);
}) as OnRequireFn);

describe('RequireInTheMiddleSingleton', () => {
describe('register', () => {
Expand Down