Skip to content

Commit

Permalink
Add native support for Windows 🎉
Browse files Browse the repository at this point in the history
As of cloudflare/workerd#452, `workerd` supports Windows' natively.
This change upgrades `workerd`, then removes the WSL and Docker
runtime shells.
  • Loading branch information
mrbbot committed Apr 5, 2023
1 parent dae7719 commit 3b851a8
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 344 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest] # `windows-latest` not yet supported
os: [ubuntu-latest, windows-latest]
node: [16.13.0, latest]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

Expand Down
109 changes: 66 additions & 43 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/tre/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"source-map-support": "0.5.21",
"stoppable": "^1.1.0",
"undici": "^5.13.0",
"workerd": "^1.20230221.0",
"workerd": "^1.20230404.0",
"ws": "^8.11.0",
"youch": "^3.2.2",
"zod": "^3.20.6"
Expand Down
20 changes: 8 additions & 12 deletions packages/tre/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ import {
import {
Config,
Runtime,
RuntimeConstructor,
RuntimeOptions,
Service,
Socket,
Worker_Binding,
Worker_Module,
getSupportedRuntime,
serializeConfig,
} from "./runtime";
import {
Expand Down Expand Up @@ -214,12 +212,18 @@ const restrictedWebSocketUpgradeHeaders = [

async function writeResponse(response: Response, res: http.ServerResponse) {
const headers = Object.fromEntries(response.headers);
// process.stdout.write(`${response.status} ${response.statusText}\n`);
// for (const [key, value] of response.headers) {
// process.stdout.write(`${key}: ${value}\n`);
// }
res.writeHead(response.status, response.statusText, headers);
if (response.body) {
for await (const chunk of response.body) {
// if (chunk) process.stdout.write(chunk);
if (chunk) res.write(chunk);
}
}
// process.stdout.write("\n");
res.end();
}

Expand All @@ -232,7 +236,6 @@ export class Miniflare {
#log: Log;
readonly #clock: Clock;

readonly #runtimeConstructor: RuntimeConstructor;
#runtime?: Runtime;
#removeRuntimeExitHook?: () => void;
#runtimeEntryURL?: URL;
Expand Down Expand Up @@ -286,12 +289,6 @@ export class Miniflare {
this.#clock = this.#sharedOpts.core.clock ?? defaultClock;
this.#initPlugins();

// Get supported shell for executing runtime binary
// TODO: allow this to be configured if necessary
this.#runtimeConstructor = getSupportedRuntime();
const desc = this.#runtimeConstructor.description;
this.#log.debug(`Running workerd ${desc}...`);

this.#liveReloadServer = new WebSocketServer({ noServer: true });
this.#webSocketServer = new WebSocketServer({
noServer: true,
Expand Down Expand Up @@ -386,12 +383,11 @@ export class Miniflare {
inspectorPort: this.#sharedOpts.core.inspectorPort,
verbose: this.#sharedOpts.core.verbose,
};
this.#runtime = new this.#runtimeConstructor(opts);
this.#runtime = new Runtime(opts);
this.#removeRuntimeExitHook = exitHook(() => void this.#runtime?.dispose());

const accessibleHost =
this.#runtime.accessibleHostOverride ??
(host === "*" || host === "0.0.0.0" ? "127.0.0.1" : host);
host === "*" || host === "0.0.0.0" ? "127.0.0.1" : host;
this.#runtimeEntryURL = new URL(`http://${accessibleHost}:${entryPort}`);

const config = await this.#assembleConfig();
Expand Down
3 changes: 2 additions & 1 deletion packages/tre/src/plugins/shared/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ export const DEFAULT_PERSIST_ROOT = ".mf";
export const PARAM_FILE_UNSANITISE = "unsanitise";

export function maybeParseURL(url: Persistence): URL | undefined {
if (typeof url !== "string" || path.isAbsolute(url)) return;
try {
if (typeof url === "string") return new URL(url);
return new URL(url);
} catch {}
}

Expand Down
Loading

0 comments on commit 3b851a8

Please sign in to comment.