Skip to content

Commit f13394f

Browse files
committed
fix: add file context to globalThis
1 parent 5963fb5 commit f13394f

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

packages/instrument-bundler/src/bundle.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import type { BundleOptions } from './schemas.js';
77
import type { BuildOutput } from './types.js';
88

99
const GLOBAL_PROXY_SHIM = `
10-
let __ODC_BUNDLER_ERROR_CONTEXT;
1110
const __createProxy = (name) => {
1211
const formatErrorMessage = (method, propertyName, targetName) => {
13-
const contextName = __ODC_BUNDLER_ERROR_CONTEXT ?? 'UNKNOWN'
14-
return "Cannot " + method + " property '" + propertyName + "' of object '" + targetName + "' in global scope of context '" + contextName + "'"
12+
const contextName = globalThis.__ODC_BUNDLER_ERROR_CONTEXT ?? 'UNKNOWN'
13+
return "Cannot " + method + " property '" + propertyName + "' of object '" + targetName + "' in global scope of file '" + contextName + "'"
1514
}
1615
return new Proxy({ name }, {
1716
get(target, property) {

packages/instrument-bundler/src/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const plugin = (options: { inputs: BundlerInput[] }): Plugin => {
4747
let contents: typeof input.content;
4848
const loader = inferLoader(input.name);
4949
if (loader === 'js' || loader === 'jsx' || loader === 'ts' || loader == 'tsx') {
50-
contents = [`__ODC_BUNDLER_ERROR_CONTEXT = "${input.name}";`, input.content as string].join('\n');
50+
contents = [`globalThis.__ODC_BUNDLER_ERROR_CONTEXT = "${input.name}";`, input.content as string].join('\n');
5151
} else {
5252
contents = input.content;
5353
}

0 commit comments

Comments
 (0)