@contrast/esm-hooks 2.6.1 → 2.6.3

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/lib/hooks.mjs +16 -5
  2. package/package.json +3 -3
package/lib/hooks.mjs CHANGED
@@ -122,10 +122,21 @@ async function load(url, context, nextLoad) {
122
122
  }
123
123
 
124
124
  if (loaderAgent.config.agent.node.rewrite.cache.enable) {
125
- const cached = await loaderAgent.rewriter.cache.find(filename);
126
-
127
- if (cached) {
128
- return nextLoad(pathToFileURL(cached).href, context);
125
+ const cachedURL = await loaderAgent.rewriter.cache.find(filename);
126
+ if (cachedURL) {
127
+ // allow other load hooks to run
128
+ const loadResult = await nextLoad(pathToFileURL(cachedURL).href, context);
129
+ // use original url so that import.meta.url and import.meta.resolve work as expected
130
+ loadResult.responseURL = url;
131
+
132
+ if (process.env.CSI_EXPOSE_CORE) {
133
+ // only do this in testing scenarios
134
+ loaderAgent.esmHooks.portClient.sendStatus('rewritten file loaded from cache', {
135
+ cachedURL,
136
+ responseURL: loadResult.responseURL,
137
+ });
138
+ }
139
+ return loadResult;
129
140
  }
130
141
  }
131
142
 
@@ -150,7 +161,7 @@ async function load(url, context, nextLoad) {
150
161
  }
151
162
 
152
163
  if (loaderAgent.config.agent.node.rewrite.cache.enable) {
153
- loaderAgent.rewriter.cache.write(filename, rewriteResult);
164
+ await loaderAgent.rewriter.cache.write(filename, rewriteResult);
154
165
  }
155
166
 
156
167
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/esm-hooks",
3
- "version": "2.6.1",
3
+ "version": "2.6.3",
4
4
  "type": "module",
5
5
  "description": "Support for loading and instrumenting ECMAScript modules",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -19,8 +19,8 @@
19
19
  "test": "../scripts/test.sh"
20
20
  },
21
21
  "dependencies": {
22
- "@contrast/common": "1.21.1",
23
- "@contrast/core": "1.32.1",
22
+ "@contrast/common": "1.21.3",
23
+ "@contrast/core": "1.32.3",
24
24
  "@contrast/find-package-json": "^1.0.0"
25
25
  }
26
26
  }