Skip to content

fix: don't use the globalThis shim when there are no shimmed globals - #517

Merged
dsherret merged 1 commit into
denoland:mainfrom
dsherret:fix_global_this_no_shims
Jul 27, 2026
Merged

fix: don't use the globalThis shim when there are no shimmed globals#517
dsherret merged 1 commit into
denoland:mainfrom
dsherret:fix_global_this_no_shims

Conversation

@dsherret

@dsherret dsherret commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

With shims: {} (or every shim disabled), dnt still rewrote every unresolved globalThis to dntShim.dntGlobalThis and emitted an _dnt.shims.ts into the output, where the proxy merged globalThis with an empty object:

// in
export function isBrowser() {
  return typeof globalThis !== "undefined" && globalThis != null;
}
// out (before)
import * as dntShim from "./_dnt.shims.js";
export function isBrowser() {
    return typeof dntShim.dntGlobalThis !== "undefined" && dntShim.dntGlobalThis != null;
}

There's nothing to merge into globalThis in that case, so the rewrite is skipped when no shim declares any global names. The shim file is only emitted when something imports it, so it now disappears from the output as well.

Behaviour with shims configured is unchanged.

Closes #454

`globalThis` was being rewritten to `dntShim.dntGlobalThis` even when no
shims were configured, which meant an `_dnt.shims.ts` file was emitted
with a proxy that merged `globalThis` with an empty object.
@dsherret
dsherret merged commit b9a4630 into denoland:main Jul 27, 2026
5 checks passed
@dsherret
dsherret deleted the fix_global_this_no_shims branch July 27, 2026 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to disable dntGlobalThis and picocolors

1 participant