@contrast/esm-hooks 2.19.1 → 2.19.2
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.
- package/lib/hooks.mjs +32 -17
- package/package.json +2 -2
package/lib/hooks.mjs
CHANGED
|
@@ -152,25 +152,40 @@ async function load(url, context, nextLoad) {
|
|
|
152
152
|
};
|
|
153
153
|
|
|
154
154
|
const { source } = await nextLoad(url, context);
|
|
155
|
-
const rewriteResult = await loaderAgent.rewriter.rewrite(
|
|
156
|
-
Buffer.isBuffer(source) ? BufferPrototypeToString.call(source) : source.toString(),
|
|
157
|
-
rewriteOptions
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
if (process.env.CSI_EXPOSE_CORE) {
|
|
161
|
-
// only do this in testing scenarios (todo: compose this functionality into test agents instead)
|
|
162
|
-
loaderAgent.esmHooks.portClient.sendStatus('rewriting file during ESM load hook', rewriteOptions);
|
|
163
|
-
}
|
|
164
155
|
|
|
165
|
-
|
|
166
|
-
await loaderAgent.rewriter.
|
|
167
|
-
|
|
156
|
+
try {
|
|
157
|
+
const rewriteResult = await loaderAgent.rewriter.rewrite(
|
|
158
|
+
Buffer.isBuffer(source) ? BufferPrototypeToString.call(source) : source.toString(),
|
|
159
|
+
rewriteOptions
|
|
160
|
+
);
|
|
168
161
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
162
|
+
if (process.env.CSI_EXPOSE_CORE) {
|
|
163
|
+
// only do this in testing scenarios (todo: compose this functionality into test agents instead)
|
|
164
|
+
loaderAgent.esmHooks.portClient.sendStatus('rewriting file during ESM load hook', rewriteOptions);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (loaderAgent.config.agent.node.rewrite.cache.enable) {
|
|
168
|
+
await loaderAgent.rewriter.cache.write(filename, rewriteResult);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
source: rewriteResult.code,
|
|
173
|
+
format: 'module',
|
|
174
|
+
shortCircuit: true,
|
|
175
|
+
};
|
|
176
|
+
} catch (err) {
|
|
177
|
+
loaderAgent.logger.warn(
|
|
178
|
+
{ err },
|
|
179
|
+
'Failed to rewrite code for %s, continuing with original code.',
|
|
180
|
+
filename,
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
source,
|
|
185
|
+
format: 'module',
|
|
186
|
+
shortCircuit: true,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
174
189
|
}
|
|
175
190
|
|
|
176
191
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/esm-hooks",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Support for loading and instrumenting ECMAScript modules",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|
|
@@ -24,6 +24,6 @@
|
|
|
24
24
|
"@contrast/core": "1.45.1",
|
|
25
25
|
"@contrast/find-package-json": "^1.1.0",
|
|
26
26
|
"@contrast/logger": "1.18.1",
|
|
27
|
-
"@contrast/rewriter": "1.21.
|
|
27
|
+
"@contrast/rewriter": "1.21.2"
|
|
28
28
|
}
|
|
29
29
|
}
|