Skip to content

Commit 83eb8e1

Browse files
committed
Make esm support optional
1 parent 326beb6 commit 83eb8e1

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/Options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface RunOptions {
1111
export interface ProjectConfig {
1212
ignore: string[];
1313
swc?: SwcConfig;
14+
esm?: boolean;
1415
extensions: string[];
1516
cacheDir: string;
1617
}

src/Supervisor.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ChildProcess, StdioOptions } from "child_process";
22
import { spawn } from "child_process";
33
import { EventEmitter, once } from "events";
4+
import _ from "lodash";
45
import { setTimeout } from "timers/promises";
56
import type { RunOptions } from "./Options.js";
67
import type { Project } from "./Project.js";
@@ -66,6 +67,7 @@ export class Supervisor extends EventEmitter {
6667
...process.env,
6768
WDS_SOCKET_PATH: this.socketPath,
6869
WDS_EXTENSIONS: this.project.config.extensions.join(","),
70+
WDS_ESM_ENABLED: _.defaultTo(this.project.config.esm, true) ? "true" : "false",
6971
},
7072
stdio: stdio,
7173
detached: true,

src/hooks/child-process-register.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Entrypoint file passed as --import to all child processes started by wds
33
*/
44
import { register } from "node:module";
5+
import { debugLog } from "../SyncWorker.cjs";
56

67
if (!register) {
78
throw new Error(
@@ -15,5 +16,8 @@ process.setSourceMapsEnabled(true);
1516
// register the CJS hook to intercept require calls the old way
1617
import "./child-process-cjs-hook.cjs";
1718

18-
// register the ESM loader the new way
19-
register("./child-process-esm-loader.js", import.meta.url);
19+
if (process.env.WDS_ESM_ENABLED === "true") {
20+
debugLog?.("registering wds ESM loader");
21+
// register the ESM loader the new way
22+
register("./child-process-esm-loader.js", import.meta.url);
23+
}

0 commit comments

Comments
 (0)