🤖 Pick PR #58895 (Fix global when typescript.js loade...) into release-5.5 (#58896)

Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
This commit is contained in:
TypeScript Bot 2024-06-17 17:08:13 -07:00 committed by GitHub
parent 45b1e3c254
commit 02132e5b81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View File

@ -216,7 +216,7 @@ function createBundler(entrypoint, outfile, taskOptions = {}) {
// Monaco bundles us as ESM by wrapping our code with something that defines module.exports
// but then does not use it, instead using the `ts` variable. Ensure that if we think we're CJS
// that we still set `ts` to the module.exports object.
options.footer = { js: `})(typeof module !== "undefined" && module.exports ? module : { exports: ts });\nif (typeof module !== "undefined" && module.exports) { ts = module.exports; }` };
options.footer = { js: `})({ get exports() { return ts; }, set exports(v) { ts = v; if (typeof module !== "undefined" && module.exports) { module.exports = v; } } })` };
// esbuild converts calls to "require" to "__require"; this function
// calls the real require if it exists, or throws if it does not (rather than

View File

@ -29,6 +29,7 @@ for (const browserType of browsers) {
await page.setContent(`
<html>
<script>${readFileSync(join("built", "local", "typescript.js"), "utf8")}</script>
<script>if (typeof ts.version !== "string") throw new Error("ts.version not set")</script>
</html>
`);