Skip to content

Commit

Permalink
Make esm support optional
Browse files Browse the repository at this point in the history
  • Loading branch information
airhorns committed Nov 15, 2024
1 parent 326beb6 commit 6f56cf7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface RunOptions {
export interface ProjectConfig {
ignore: string[];
swc?: SwcConfig;
esm?: boolean;
extensions: string[];
cacheDir: string;
}
2 changes: 2 additions & 0 deletions src/Supervisor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ChildProcess, StdioOptions } from "child_process";
import { spawn } from "child_process";
import { EventEmitter, once } from "events";
import { defaultTo } from "lodash";
import { setTimeout } from "timers/promises";
import type { RunOptions } from "./Options.js";
import type { Project } from "./Project.js";
Expand Down Expand Up @@ -66,6 +67,7 @@ export class Supervisor extends EventEmitter {
...process.env,
WDS_SOCKET_PATH: this.socketPath,
WDS_EXTENSIONS: this.project.config.extensions.join(","),
WDS_ESM_ENABLED: defaultTo(this.project.config.esm, true) ? "true" : "false",
},
stdio: stdio,
detached: true,
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/child-process-register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ process.setSourceMapsEnabled(true);
// register the CJS hook to intercept require calls the old way
import "./child-process-cjs-hook.cjs";

// register the ESM loader the new way
register("./child-process-esm-loader.js", import.meta.url);
if (process.env.WDS_ESM_ENABLED === "true") {
// register the ESM loader the new way
register("./child-process-esm-loader.js", import.meta.url);
}

0 comments on commit 6f56cf7

Please sign in to comment.