node-esm-mock 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +5 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -10,6 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { registerHooks } from 'node:module';
11
11
  registerHooks({
12
12
  resolve(specifier, context, nextResolver) {
13
+ var _a, _b;
14
+ // If the parentURL is not a file and contains a query, it means it's a mocked module, so we should ignore the parentURL to avoid issues with resolving the original module.
15
+ if (!((_a = context.parentURL) === null || _a === void 0 ? void 0 : _a.startsWith('file:')) && ((_b = context.parentURL) === null || _b === void 0 ? void 0 : _b.includes('?'))) {
16
+ context.parentURL = undefined;
17
+ }
13
18
  const resolved = nextResolver(specifier, context);
14
19
  const mocksForSpecifier = mocksFor.get(specifier);
15
20
  if (mocksForSpecifier) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-esm-mock",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Mock ES modules in Node.js using registerHooks",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",