Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -225,13 +226,20 @@ 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",
setup: build => {
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);
});
},
Expand Down
3 changes: 1 addition & 2 deletions src/typescript/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
Debug,
LogLevel,
} from "./_namespaces/ts";
import * as ts from "./_namespaces/ts";

// enable deprecation logging
declare const console: any;
Expand All @@ -23,4 +22,4 @@ if (typeof console !== "undefined") {
};
}

export = ts;
export * from "./_namespaces/ts";