Skip to content

IITM does not hook an indirect import of the "main" file, differing from RITM #239

@trentm

Description

@trentm

The problem

This works:

Hook(['ioredis'], (exports, name, baseDir) => {
  console.log('HIT: name=%s', name)  // matched, name=="ioredis"
})
await import('ioredis')

but IITM does not match when the module "main" file is deep-imported:

Hook(['ioredis'], (exports, name, baseDir) => {
  console.log('HIT: name=%s', name)  // Note: IITM does not match here
})
await import('ioredis/built/index.js')  // deep import of the module "main" file

This does work with RITM.

RITM does extra work (using require.resolve(moduleName)) to realize that the loaded filename/URL (e.g. "/Users/trentm/my-app/node_modules/ioredis/built/index.js" in this case) file is the package "main" file, and then returns the module name rather than the internal file path.

Fixing it?

I don't know how IITM could fix this.

RITM is using require.resolve(modName).
For IITM to do the equivalent, it would have to use import.meta.resolve(modName). However, IIUC, that can only be used in an ESM module and all the IITM code here is CommonJS at this point.

There is an argument to be made that perhaps this need not be changed to match RITM, because:

Granted that means changing instrumentations... and coping with the IITM/RITM difference, or perhaps getting RITM to add that 4th modPath arg I mentioned in #238

Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions