From 6f56cf7b2f55989383aec8bc97841a52687ad680 Mon Sep 17 00:00:00 2001 From: Harry Brundage Date: Fri, 15 Nov 2024 10:11:34 -0500 Subject: [PATCH] Make esm support optional --- src/Options.ts | 1 + src/Supervisor.ts | 2 ++ src/hooks/child-process-register.ts | 6 ++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Options.ts b/src/Options.ts index 9343a9b..3e97f39 100644 --- a/src/Options.ts +++ b/src/Options.ts @@ -11,6 +11,7 @@ export interface RunOptions { export interface ProjectConfig { ignore: string[]; swc?: SwcConfig; + esm?: boolean; extensions: string[]; cacheDir: string; } diff --git a/src/Supervisor.ts b/src/Supervisor.ts index 3ba897b..9518d62 100644 --- a/src/Supervisor.ts +++ b/src/Supervisor.ts @@ -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"; @@ -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, diff --git a/src/hooks/child-process-register.ts b/src/hooks/child-process-register.ts index 9ecf175..3fb3bc6 100644 --- a/src/hooks/child-process-register.ts +++ b/src/hooks/child-process-register.ts @@ -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); +}