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

refactor(vite-node-miniflare): remove vite-node #161

Merged
merged 83 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
696621a
fix(vite-node-miniflare): use `ssr.optimizeDeps` for vite-node
hi-ogawa Jan 9, 2024
39cddc4
Merge branch 'main' into fix-vite-node-ssr-optimizeDeps
hi-ogawa Jan 9, 2024
f916f85
fix: optimizeDeps.exclude for node deps
hi-ogawa Jan 9, 2024
21b2889
fix: resolve.conditions browser for react-dom/server
hi-ogawa Jan 9, 2024
4129b00
chore: comment
hi-ogawa Jan 9, 2024
2a5b25a
chore: direct import "react-dom/server.browser"
hi-ogawa Jan 9, 2024
8b74dd4
fix: fix pre-bundle externalization + fix "require" esbuild banner
hi-ogawa Jan 9, 2024
46bfac3
chore: remove optimizeDeps.force for debuggin
hi-ogawa Jan 9, 2024
8bd55cd
chore: comment
hi-ogawa Jan 9, 2024
9b70f49
chore: comment
hi-ogawa Jan 9, 2024
8f56565
chore: comment
hi-ogawa Jan 9, 2024
fc2d72b
chore: "serve" only
hi-ogawa Jan 10, 2024
190305e
chore: comment
hi-ogawa Jan 10, 2024
6128685
chore: remove redundant noDiscovery
hi-ogawa Jan 10, 2024
6e7cdeb
Merge branch 'main' into fix-vite-node-ssr-optimizeDeps
hi-ogawa Jan 12, 2024
c415228
chore(deps): vite 5.1.0-beta.0
hi-ogawa Jan 16, 2024
c337335
Merge remote-tracking branch 'origin/fix-vite-node-ssr-optimizeDeps' …
hi-ogawa Jan 16, 2024
d79805e
Merge branch 'main' into fix-vite-node-ssr-optimizeDeps
hi-ogawa Jan 16, 2024
4781972
feat: move config to plugin
hi-ogawa Jan 16, 2024
b4477d3
chore: more examples
hi-ogawa Jan 16, 2024
808ee5c
chore: more
hi-ogawa Jan 16, 2024
0fe2858
chore: remove unused
hi-ogawa Jan 16, 2024
5484643
chore: cleanup react-dom import
hi-ogawa Jan 16, 2024
599be33
chore: use sapphi-red's prebuilt vite
hi-ogawa Jan 21, 2024
385dc74
wip: simple integration without hmr/invalidation
hi-ogawa Jan 21, 2024
6337df8
fix: disable installSourcemapsSupport
hi-ogawa Jan 21, 2024
bf9efdf
fix: tweak optimizeDeps for remix dep cjs
hi-ogawa Jan 21, 2024
62a70c4
chore: lint
hi-ogawa Jan 21, 2024
8b45d0f
chore: comment
hi-ogawa Jan 21, 2024
cc0aee8
chore: manual invalidation
hi-ogawa Jan 21, 2024
9fd7a29
test: xfail sourcemap
hi-ogawa Jan 21, 2024
2dd0ecf
feat: handle HMRPayload on client
hi-ogawa Jan 21, 2024
e5eb876
chore: todo
hi-ogawa Jan 21, 2024
da12968
wip: fix stack trace
hi-ogawa Jan 21, 2024
a6d4c76
wip: try newAsyncFunction
hi-ogawa Jan 21, 2024
e5a2219
chore: comment
hi-ogawa Jan 21, 2024
2dcd233
chore: comment
hi-ogawa Jan 21, 2024
dfe98ac
chore: update build
hi-ogawa Jan 24, 2024
930f20f
wip: prepareStackTrace
hi-ogawa Jan 24, 2024
83a36ce
wip: struggle
hi-ogawa Jan 24, 2024
fa739bc
fix: fix source map by two empty lines
hi-ogawa Jan 24, 2024
2f6337f
chore: remove local build
hi-ogawa Jan 24, 2024
ace8ef1
chore: lint
hi-ogawa Jan 24, 2024
b4938df
chore: remove unused
hi-ogawa Jan 24, 2024
9bf1c7d
chore: comment
hi-ogawa Jan 24, 2024
596b232
chore: prebuilt vite
hi-ogawa Jan 26, 2024
45c5f4c
chore: use custom fetchModule to avoid two empty lines injection
hi-ogawa Jan 26, 2024
748f523
Merge branch 'main' into fix-vite-node-ssr-optimizeDeps
hi-ogawa Jan 29, 2024
b4a8f10
Merge branch 'fix-vite-node-ssr-optimizeDeps' into refactor-vite-runtime
hi-ogawa Jan 29, 2024
9702304
chore: update vite
hi-ogawa Jan 30, 2024
24f47ac
chore: update vite
hi-ogawa Jan 30, 2024
38ee21b
chore: remove unused
hi-ogawa Jan 30, 2024
9b40a28
fix: back to `moduleCache.invalidateDepTree` without SSR HMR
hi-ogawa Jan 31, 2024
95d6705
feat: optional ssr hmr (disabled by default)
hi-ogawa Jan 31, 2024
c97a158
chore: log
hi-ogawa Jan 31, 2024
8b32d19
chore: comment
hi-ogawa Jan 31, 2024
4bfa4c9
chore: remove vite-node
hi-ogawa Jan 31, 2024
c686d3a
chore: remove polyfill
hi-ogawa Jan 31, 2024
322c69e
refactor: obtain HMRHandler from onUpdate callback
hi-ogawa Feb 1, 2024
fda6e52
chore: typing
hi-ogawa Feb 1, 2024
ec4a93f
chore: vite beta
hi-ogawa Feb 2, 2024
37e8fbc
Merge branch 'main' into fix-vite-node-ssr-optimizeDeps
hi-ogawa Feb 9, 2024
c5c5f62
chore: remove unused
hi-ogawa Feb 9, 2024
eee7c16
chore: remove deprecated `optimizeDeps.disabled`
hi-ogawa Feb 9, 2024
e4dc5a2
Merge branch 'main' into fix-vite-node-ssr-optimizeDeps
hi-ogawa Feb 9, 2024
4ffec98
Merge branch 'fix-vite-node-ssr-optimizeDeps' into refactor-vite-runtime
hi-ogawa Feb 9, 2024
8889857
chore: comment
hi-ogawa Feb 9, 2024
e165313
chore: comment
hi-ogawa Feb 9, 2024
2ad4f3c
chore: type
hi-ogawa Feb 9, 2024
64b6ba9
chore: comment
hi-ogawa Feb 9, 2024
68412a2
Merge branch 'main' into refactor-vite-runtime
hi-ogawa Feb 9, 2024
545011f
Merge branch 'main' into refactor-vite-runtime
hi-ogawa Feb 9, 2024
acc386e
Merge branch 'refactor-vite-runtime' into refactor-remove-vite-node
hi-ogawa Feb 9, 2024
d5994a8
chore: minor
hi-ogawa Feb 9, 2024
be96520
chore: readme
hi-ogawa Feb 9, 2024
f7e7f7c
chore: fix merge
hi-ogawa Feb 9, 2024
31259d6
chore: readme
hi-ogawa Feb 9, 2024
e15f264
chore: readme
hi-ogawa Feb 9, 2024
2a93fff
chore: remove unused wrapper
hi-ogawa Feb 9, 2024
c0d7539
chore: tweak build
hi-ogawa Feb 9, 2024
37ce787
Revert "chore: tweak build"
hi-ogawa Feb 9, 2024
855c0c4
refactor: tweak build 2
hi-ogawa Feb 9, 2024
d6193d4
chore: cleanup
hi-ogawa Feb 9, 2024
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
9 changes: 4 additions & 5 deletions packages/vite-node-miniflare/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# vite-node-miniflare

> [!note]
> now it uses `ViteRuntime` introduced by https://github.com/vitejs/vite/pull/12165 instead of `vite-node`

Running [`vite-node`](https://github.com/vitest-dev/vitest/tree/main/packages/vite-node) on [`miniflare`](https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare).

See https://github.com/dario-piotrowicz/vite-workerd-ssr-request-handler-experimentation/pull/1 for the motivation.
Expand All @@ -23,11 +26,7 @@ import { defineConfig } from "vite";
import { vitePluginViteNodeMiniflare } from "@hiogawa/vite-node-miniflare";

export default defineConfig({
appType: "custom",
ssr: {
noExternal: true,
},
plugins: [vitePluginViteNodeMiniflare({ entry: "./worker-entry.ts" })],
plugins: [vitePluginViteNodeMiniflare({ entry: "/worker-entry.ts" })],
});

//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { h, renderToString } from "@hiogawa/tiny-react";
import type { ViteNodeMiniflareClient } from "@hiogawa/vite-node-miniflare/client/vite-node";
import type { ViteNodeMiniflareClient } from "@hiogawa/vite-node-miniflare";
import { App } from "./app";

export default {
Expand Down
3 changes: 1 addition & 2 deletions packages/vite-node-miniflare/examples/basic/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export default defineConfig({
plugins: [
vitePluginViteNodeMiniflare({
debug: true,
// TODO: must be a relative url for invalidation to work?
entry: "./src/worker-entry.ts",
entry: "/src/worker-entry.ts",
miniflareOptions(options) {
options.log = new Log();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
globPageRoutesServer,
handleReactRouterServer,
} from "@hiogawa/vite-glob-routes/dist/react-router/server";
import type { ViteNodeMiniflareClient } from "@hiogawa/vite-node-miniflare/client/vite-node";
import type { ViteNodeMiniflareClient } from "@hiogawa/vite-node-miniflare";
import React from "react";
import { renderToString } from "react-dom/server";
import {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default defineConfig({
globRoutesPlugin({ root: "/src/routes" }),
vitePluginViteNodeMiniflare({
debug: true,
entry: "./src/server/worker-entry-wrapper.ts",
entry: "/src/server/worker-entry.ts",
miniflareOptions(options) {
options.log = new Log();
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ViteNodeMiniflareClient } from "@hiogawa/vite-node-miniflare/client/vite-node";
import type { ViteNodeMiniflareClient } from "@hiogawa/vite-node-miniflare";
import ReactDomServer from "react-dom/server";
import { App } from "./app";

Expand Down
2 changes: 1 addition & 1 deletion packages/vite-node-miniflare/examples/react/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default defineConfig({
plugins: [
vitePluginViteNodeMiniflare({
debug: true,
entry: "./src/worker-entry.tsx",
entry: "/src/worker-entry.tsx",
miniflareOptions(options) {
options.log = new Log();
},
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion packages/vite-node-miniflare/examples/remix/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default defineConfig({
plugins: [
vitePluginViteNodeMiniflare({
debug: true,
entry: "./app/worker-entry-wrapper.ts",
entry: "/app/worker-entry.ts",
miniflareOptions(options) {
options.log = new Log();
// @ts-ignore why type error?
Expand Down
14 changes: 2 additions & 12 deletions packages/vite-node-miniflare/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hiogawa/vite-node-miniflare",
"version": "0.0.0-pre.12",
"version": "0.0.0-pre.13",
"homepage": "https://github.com/hi-ogawa/vite-plugins/tree/main/packages/vite-node-miniflare",
"repository": {
"type": "git",
Expand All @@ -13,14 +13,6 @@
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./client/worker-entry": {
"types": "./dist/client/worker-entry.d.ts",
"default": "./dist/client/worker-entry.js"
},
"./client/vite-node": {
"types": "./dist/client/vite-node.d.ts",
"default": "./dist/client/vite-node.js"
}
},
"main": "./dist/index.js",
Expand All @@ -37,13 +29,11 @@
"@hattip/adapter-node": "^0.0.34",
"@hattip/compose": "^0.0.34",
"esbuild": "^0.18.6",
"miniflare": "^3.20231030.3",
"vite-node": "^1.0.4"
"miniflare": "^3.20231030.3"
},
"devDependencies": {
"@hiogawa/tiny-rpc": "^0.2.3-pre.11",
"@hiogawa/utils": "1.6.1-pre.10",
"pathe": "^1.1.1",
"vite": "^5.1.0"
},
"peerDependencies": {
Expand Down

This file was deleted.

17 changes: 0 additions & 17 deletions packages/vite-node-miniflare/src/client/polyfills/debug.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/vite-node-miniflare/src/client/polyfills/node-fs.ts

This file was deleted.

This file was deleted.

This file was deleted.

20 changes: 0 additions & 20 deletions packages/vite-node-miniflare/src/client/polyfills/node-url.ts

This file was deleted.

20 changes: 0 additions & 20 deletions packages/vite-node-miniflare/src/client/polyfills/node-vm.ts

This file was deleted.

10 changes: 0 additions & 10 deletions packages/vite-node-miniflare/src/client/polyfills/usage-checker.ts

This file was deleted.

64 changes: 4 additions & 60 deletions packages/vite-node-miniflare/src/client/vite-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,22 @@ import {
httpClientAdapter,
proxyTinyRpc,
} from "@hiogawa/tiny-rpc";
import { tinyassert } from "@hiogawa/utils";
import type { HMRPayload } from "vite";
import type { ViteNodeRunnerOptions } from "vite-node";
import { ViteNodeRunner } from "vite-node/client";
import { installSourcemapsSupport } from "vite-node/source-map";
import { ViteRuntime } from "vite/runtime";
import type { ViteNodeRpc } from "..";
import { __setDebug } from "./polyfills/debug";
import { __setUnsafeEval } from "./polyfills/node-vm";
import type { ViteNodeRpc } from "../server/vite-node";

export interface ViteNodeMiniflareClient {
rpc: TinyRpcProxy<ViteNodeRpc>;
runner: ViteNodeRunner;
runtime: ViteRuntime;
runtimeHMRHandler: (payload: HMRPayload) => void;
}

export function createViteNodeClient(options: {
unsafeEval: any;
serverRpcUrl: string;
runnerOptions: Omit<ViteNodeRunnerOptions, "fetchModule" | "resolveId">;
root: string;
debug: boolean;
}): ViteNodeMiniflareClient {
__setUnsafeEval(options.unsafeEval);
__setDebug(options.debug);

const rpc = proxyTinyRpc<ViteNodeRpc>({
adapter: httpClientAdapter({ url: options.serverRpcUrl }),
});
Expand All @@ -37,7 +27,7 @@ export function createViteNodeClient(options: {

const runtime = new ViteRuntime(
{
root: options.runnerOptions.root,
root: options.root,
fetchModule(id, importer) {
return rpc.ssrFetchModule(id, importer);
},
Expand Down Expand Up @@ -80,51 +70,5 @@ export function createViteNodeClient(options: {
}
);

const runner = new ViteNodeRunner({
...options.runnerOptions,
fetchModule(id) {
return rpc.fetchModule(id);
},
resolveId(id, importer) {
return rpc.resolveId(id, importer);
},
});

// Since Vitest's getSourceMap/extractSourceMap relies on `Buffer.from(mapString, 'base64').toString('utf-8')`,
// we inject minimal Buffer polyfill temporary during this function.
// https://github.com/vitest-dev/vitest/blob/8dabef860a3f51f5a4c4debc10faa1837fdcdd71/packages/vite-node/src/source-map.ts#L57-L62
// prettier-ignore
0 && installSourcemapsSupport({
getSourceMap: (source) => {
const teardown = setupBufferPolyfill();
try {
return runner.moduleCache.getSourceMap(source);
} finally {
teardown();
}
},
});

return { rpc, runner, runtime, runtimeHMRHandler };
}

function setupBufferPolyfill() {
const prev = globalThis.Buffer;
globalThis.Buffer = BufferPolyfill as any;
return () => {
globalThis.Buffer = prev;
};
return { rpc, runtime, runtimeHMRHandler };
}

const BufferPolyfill = {
from: (s: unknown, encoding: unknown) => {
tinyassert(typeof s === "string");
tinyassert(encoding === "base64");
return {
toString: (encoding: unknown) => {
tinyassert(encoding === "utf-8");
return atob(s);
},
};
},
};
Loading
Loading