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. It also `Cherry`picks #509, to allow Miniflare
development on Windows too.
  • Loading branch information
mrbbot committed Apr 5, 2023
1 parent dae7719 commit cccd3da
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 351 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
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.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
"dev": "node scripts/build.mjs watch",
"helpers:scaffold": "node scripts/scaffold.mjs",
"helpers:version": "node scripts/version.mjs",
"lint": "eslint 'packages/*/{src,test}/**/*.ts' 'scripts/**/*.{js,mjs}' 'types/**/*.ts'",
"lint": "eslint \"packages/*/{src,test}/**/*.ts\" \"scripts/**/*.{js,mjs}\" \"types/**/*.ts\"",
"lint:fix": "npm run lint -- --fix",
"prepublishOnly": "npm run lint && npm run clean && npm run build && npm run types:bundle && npm run test",
"test": "npm run build && ava && rimraf ./.tmp",
"types:build": "tsc",
"___$comment:types:bundle": "api-extractor doesn't know to load index.ts instead of index.d.ts when resolving imported types",
"types:bundle": "cp node_modules/@cloudflare/workers-types/experimental/index.ts node_modules/@cloudflare/workers-types/experimental/index.d.ts && npm run types:build && node scripts/types.mjs"
"types:bundle": "node scripts/copy.mjs node_modules/@cloudflare/workers-types/experimental/index.ts node_modules/@cloudflare/workers-types/experimental/index.d.ts && npm run types:build && node scripts/types.mjs"
},
"devDependencies": {
"@ava/get-port": "^2.0.0",
Expand Down
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
14 changes: 2 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 @@ -232,7 +230,6 @@ export class Miniflare {
#log: Log;
readonly #clock: Clock;

readonly #runtimeConstructor: RuntimeConstructor;
#runtime?: Runtime;
#removeRuntimeExitHook?: () => void;
#runtimeEntryURL?: URL;
Expand Down Expand Up @@ -286,12 +283,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 +377,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 cccd3da

Please sign in to comment.