Skip to content

Commit 8c737e3

Browse files
committed
Make esm support optional
1 parent 326beb6 commit 8c737e3

File tree

9 files changed

+47
-2
lines changed

9 files changed

+47
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript",
5+
"tsx": true,
6+
"decorators": true,
7+
"dynamicImport": true
8+
},
9+
"target": "esnext"
10+
},
11+
"module": {
12+
"type": "commonjs",
13+
"lazy": true
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "simple",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "commonjs",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"license": "ISC"
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { utility } from "./utils";
2+
3+
console.log(utility("It worked!"));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
3+
set -ex
4+
5+
$DIR/../../pkg/wds.bin.js $@ $DIR/run.ts | grep "IT WORKED"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const utility = (str: string) => str.toUpperCase();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
esm: false,
3+
};

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)