Skip to content

Commit

Permalink
Strip eval calls on edge (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvoytenko authored Mar 27, 2024
1 parent 2f762fa commit 9ba9131
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-shrimps-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vercel/otel": patch
---

Strip eval() calls on Edge
19 changes: 19 additions & 0 deletions packages/otel/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ const externalCjsToEsmPlugin: ExternalPluginFactory = (external) => ({
},
});

// On Edge `eval()` is not allowed. Strip it from the input sources.
const stripEvalEdge: Plugin = {
name: "stripEvalEdge",
setup(builder): void {
builder.onLoad({ filter: /@protobufjs\/inquire\/index\.js/ }, () => {
return {
contents: `
"use strict";
module.exports = inquire;
function inquire(moduleName) {
return null;
}
`,
};
});
},
};

/** Adds support for require, __filename, and __dirname to ESM / Node. */
const esmNodeSupportBanner = {
js: `import { fileURLToPath } from 'url';
Expand Down Expand Up @@ -71,6 +89,7 @@ async function buildAll(): Promise<void> {
external: ["@opentelemetry/api"],
plugins: [
externalCjsToEsmPlugin(["async_hooks", "events", ...peerDependencies]),
stripEvalEdge,
],
}),
]);
Expand Down

0 comments on commit 9ba9131

Please sign in to comment.