diff --git a/Herebyfile.mjs b/Herebyfile.mjs index cd8b6a5145d7a..9530963d6ab57 100644 --- a/Herebyfile.mjs +++ b/Herebyfile.mjs @@ -2,6 +2,7 @@ import { CancelToken, } from "@esfx/canceltoken"; +import assert from "assert"; import chalk from "chalk"; import chokidar from "chokidar"; import esbuild from "esbuild"; @@ -225,6 +226,10 @@ function createBundler(entrypoint, outfile, taskOptions = {}) { const fakeName = "Q".repeat(require.length); const fakeNameRegExp = new RegExp(fakeName, "g"); options.define = { [require]: fakeName }; + + const toCommonJsRegExp = /var __toCommonJS .*/; + const toCommonJsRegExpReplacement = "var __toCommonJS = (mod) => (__copyProps, mod);"; + options.plugins = [ { name: "fix-require", @@ -232,6 +237,9 @@ function createBundler(entrypoint, outfile, taskOptions = {}) { build.onEnd(async () => { let contents = await fs.promises.readFile(outfile, "utf-8"); contents = contents.replace(fakeNameRegExp, require); + const toCommonJsMatch = contents.match(toCommonJsRegExp); + assert(toCommonJsMatch); + contents = contents.replace(toCommonJsRegExp, toCommonJsRegExpReplacement + ";".repeat(toCommonJsMatch[0].length - toCommonJsRegExpReplacement.length)); await fs.promises.writeFile(outfile, contents); }); }, diff --git a/src/typescript/typescript.ts b/src/typescript/typescript.ts index 83f991b83fad2..0df80b850032d 100644 --- a/src/typescript/typescript.ts +++ b/src/typescript/typescript.ts @@ -2,7 +2,6 @@ import { Debug, LogLevel, } from "./_namespaces/ts"; -import * as ts from "./_namespaces/ts"; // enable deprecation logging declare const console: any; @@ -23,4 +22,4 @@ if (typeof console !== "undefined") { }; } -export = ts; +export * from "./_namespaces/ts";