Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: feat: implement esm compatibility (#4) #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const clientPlugin = function ({

let watchers: Record<string, any> = {};

const microbundle = require("microbundle");
const microbundle = (await import("microbundle")).default;

const startBundlers = async function () {
const assetsJsonPath = path.resolve(absDist, "clientAssets.json");
Expand Down Expand Up @@ -164,7 +164,7 @@ export const clientPlugin = function ({
}

if (watch) {
const chokidar = require("chokidar");
const chokidar = (await import("chokidar")).default;
chokidar.watch(absSrc).on("all", startBundlers);
}

Expand Down
10 changes: 8 additions & 2 deletions lib/devSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import url from "url";
import { Ctx, useCtx } from "./ctx";
import { copy, emptyDir } from "fs-extra";
import path from "path";
import { fileURLToPath } from "url";

const integrateClientJs = async function (ctx: Ctx) {
const publicFolder = "sosseDevSocketClient";

if (!globalThis.sosseDevClientCopied) {
const dirName =
typeof __dirname !== "undefined"
? __dirname
: path.dirname(fileURLToPath(import.meta.url));

const clientJsPath = path.resolve(
__dirname,
dirName,
"..",
"dev-socket-client",
"dist"
Expand Down Expand Up @@ -53,7 +59,7 @@ export const devSocket = async function ({
return;
}

const WebSocket = require("ws");
const WebSocket = (await import("ws")).default;

const ctx = useCtx();

Expand Down
4 changes: 2 additions & 2 deletions lib/hsr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const hsr = async function ({
let listen;
clearModule.all();

const { setCtx, unsetCtx } = require("sosse");
const { setCtx, unsetCtx } = await import("sosse");

setCtx(ctx);

Expand Down Expand Up @@ -118,7 +118,7 @@ export const hsr = async function ({
}
}, wait);

const chokidar = require("chokidar");
const chokidar = (await import("chokidar")).default;

const watcher = chokidar.watch(absWatch, {
ignored: absExclude,
Expand Down