rwsdk 0.1.17 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/dist/lib/compileTsModule.d.mts +0 -1
- package/dist/lib/compileTsModule.mjs +0 -27
- package/dist/runtime/entries/navigation.d.ts +0 -1
- package/dist/runtime/entries/navigation.js +0 -1
- package/dist/runtime/lib/db/typeInference/builders/table.d.ts +0 -10
- package/dist/runtime/lib/db/typeInference/builders/table.js +0 -1
- package/dist/runtime/render/injectRSCPayload.d.ts +0 -3
- package/dist/runtime/render/injectRSCPayload.js +0 -79
- package/dist/scripts/build-vendor-bundles.d.mts +0 -1
- package/dist/scripts/build-vendor-bundles.mjs +0 -92
- package/dist/vite/aliasByEnvPlugin.d.mts +0 -2
- package/dist/vite/aliasByEnvPlugin.mjs +0 -11
- package/dist/vite/asyncSetupPlugin.d.mts +0 -6
- package/dist/vite/asyncSetupPlugin.mjs +0 -23
- package/dist/vite/copyPrismaWasmPlugin.d.mts +0 -4
- package/dist/vite/copyPrismaWasmPlugin.mjs +0 -32
- package/dist/vite/customReactBuildPlugin.d.mts +0 -4
- package/dist/vite/customReactBuildPlugin.mjs +0 -61
- package/dist/vite/injectHmrPreambleJsxPlugin.d.mts +0 -2
- package/dist/vite/injectHmrPreambleJsxPlugin.mjs +0 -22
- package/dist/vite/miniflarePlugin.d.mts +0 -9
- package/dist/vite/miniflarePlugin.mjs +0 -135
- package/dist/vite/requestUtils.d.mts +0 -6
- package/dist/vite/requestUtils.mjs +0 -35
- package/dist/vite/setupEnvFiles.d.mts +0 -4
- package/dist/vite/setupEnvFiles.mjs +0 -31
- package/dist/vite/useClientPlugin.d.mts +0 -8
- package/dist/vite/useClientPlugin.mjs +0 -295
- package/dist/vite/useClientPlugin.test.d.mts +0 -1
- package/dist/vite/useClientPlugin.test.mjs +0 -1204
- package/dist/worker/__ssr_bridge.js +0 -8947
- package/dist/worker/__ssr_bridge.js.map +0 -1
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const compileTsModule: (tsCode: string) => string;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import path from "path";
|
|
3
|
-
export const compileTsModule = (tsCode) => {
|
|
4
|
-
const tsConfigPath = "./tsconfig.json";
|
|
5
|
-
// Find the nearest tsconfig.json
|
|
6
|
-
const configPath = ts.findConfigFile(path.dirname(tsConfigPath), ts.sys.fileExists, path.basename(tsConfigPath));
|
|
7
|
-
if (!configPath) {
|
|
8
|
-
throw new Error(`Could not find a valid tsconfig.json at path: ${tsConfigPath}`);
|
|
9
|
-
}
|
|
10
|
-
// Read and parse tsconfig.json
|
|
11
|
-
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
12
|
-
if (configFile.error) {
|
|
13
|
-
throw new Error(`Error reading tsconfig.json: ${ts.formatDiagnostic(configFile.error, ts.createCompilerHost({}))}`);
|
|
14
|
-
}
|
|
15
|
-
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configPath));
|
|
16
|
-
const compilerOptions = parsedConfig.options;
|
|
17
|
-
// Transpile the TypeScript code using the compiler options
|
|
18
|
-
const output = ts.transpileModule(tsCode, {
|
|
19
|
-
compilerOptions,
|
|
20
|
-
reportDiagnostics: true,
|
|
21
|
-
});
|
|
22
|
-
if (output.diagnostics && output.diagnostics.length) {
|
|
23
|
-
const diagnosticMessages = output.diagnostics.map((diagnostic) => ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
24
|
-
throw new Error(`TypeScript Compilation Errors:\n${diagnosticMessages.join("\n")}`);
|
|
25
|
-
}
|
|
26
|
-
return output.outputText; // Compiled JavaScript code
|
|
27
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../clientNavigation";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "../clientNavigation";
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { SqlToTsType, ExecutedBuilder, Prettify } from "../utils";
|
|
2
|
-
import { ColumnDefinitionBuilder } from "./columnDefinition";
|
|
3
|
-
export interface TableBuilder<TName extends string, TSchema extends Record<string, any> = {}> {
|
|
4
|
-
readonly __tableName: TName;
|
|
5
|
-
readonly __schema: TSchema;
|
|
6
|
-
addColumn<K extends string, T extends string>(name: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>>): TableBuilder<TName, Prettify<TSchema & Record<K, SqlToTsType<T>>>>;
|
|
7
|
-
temporary(): this;
|
|
8
|
-
ifNotExists(): this;
|
|
9
|
-
execute(): Promise<ExecutedBuilder<this>>;
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// port(justinvdm, 10 Mar 2025): This is a modified version of https://github.com/devongovett/rsc-html-stream/blob/main/server.js
|
|
2
|
-
// Modification: We needed to add a nonce attribute to the script tag for CSP
|
|
3
|
-
const encoder = new TextEncoder();
|
|
4
|
-
const trailer = "</body></html>";
|
|
5
|
-
export function injectRSCPayload(rscStream, { nonce }) {
|
|
6
|
-
let decoder = new TextDecoder();
|
|
7
|
-
let resolveFlightDataPromise;
|
|
8
|
-
let flightDataPromise = new Promise((resolve) => (resolveFlightDataPromise = resolve));
|
|
9
|
-
let startedRSC = false;
|
|
10
|
-
// Buffer all HTML chunks enqueued during the current tick of the event loop (roughly)
|
|
11
|
-
// and write them to the output stream all at once. This ensures that we don't generate
|
|
12
|
-
// invalid HTML by injecting RSC in between two partial chunks of HTML.
|
|
13
|
-
let buffered = [];
|
|
14
|
-
let timeout = null;
|
|
15
|
-
function flushBufferedChunks(controller) {
|
|
16
|
-
for (let chunk of buffered) {
|
|
17
|
-
let buf = decoder.decode(chunk);
|
|
18
|
-
if (buf.endsWith(trailer)) {
|
|
19
|
-
buf = buf.slice(0, -trailer.length);
|
|
20
|
-
}
|
|
21
|
-
controller.enqueue(encoder.encode(buf));
|
|
22
|
-
}
|
|
23
|
-
buffered.length = 0;
|
|
24
|
-
timeout = null;
|
|
25
|
-
}
|
|
26
|
-
return new TransformStream({
|
|
27
|
-
transform(chunk, controller) {
|
|
28
|
-
buffered.push(chunk);
|
|
29
|
-
if (timeout) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
timeout = setTimeout(async () => {
|
|
33
|
-
flushBufferedChunks(controller);
|
|
34
|
-
if (!startedRSC) {
|
|
35
|
-
startedRSC = true;
|
|
36
|
-
writeRSCStream(rscStream, controller, { nonce })
|
|
37
|
-
.catch((err) => controller.error(err))
|
|
38
|
-
.then(resolveFlightDataPromise);
|
|
39
|
-
}
|
|
40
|
-
}, 0);
|
|
41
|
-
},
|
|
42
|
-
async flush(controller) {
|
|
43
|
-
await flightDataPromise;
|
|
44
|
-
if (timeout) {
|
|
45
|
-
clearTimeout(timeout);
|
|
46
|
-
flushBufferedChunks(controller);
|
|
47
|
-
}
|
|
48
|
-
controller.enqueue(encoder.encode("</body></html>"));
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
async function writeRSCStream(rscStream, controller, { nonce }) {
|
|
53
|
-
let decoder = new TextDecoder("utf-8", { fatal: true });
|
|
54
|
-
for await (let chunk of rscStream) {
|
|
55
|
-
// Try decoding the chunk to send as a string.
|
|
56
|
-
// If that fails (e.g. binary data that is invalid unicode), write as base64.
|
|
57
|
-
try {
|
|
58
|
-
writeChunk(JSON.stringify(decoder.decode(chunk, { stream: true })), controller, { nonce });
|
|
59
|
-
}
|
|
60
|
-
catch (err) {
|
|
61
|
-
let base64 = JSON.stringify(btoa(String.fromCodePoint(...chunk)));
|
|
62
|
-
writeChunk(`Uint8Array.from(atob(${base64}), m => m.codePointAt(0))`, controller, { nonce });
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
let remaining = decoder.decode();
|
|
66
|
-
if (remaining.length) {
|
|
67
|
-
writeChunk(JSON.stringify(remaining), controller, { nonce });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
function writeChunk(chunk, controller, { nonce }) {
|
|
71
|
-
controller.enqueue(encoder.encode(`<script nonce="${nonce}">${escapeScript(`(self.__FLIGHT_DATA||=[]).push(${chunk})`)}</script>`));
|
|
72
|
-
}
|
|
73
|
-
// Escape closing script tags and HTML comments in JS content.
|
|
74
|
-
// https://www.w3.org/TR/html52/semantics-scripting.html#restrictions-for-contents-of-script-elements
|
|
75
|
-
// Avoid replacing </script with <\/script as it would break the following valid JS: 0</script/ (i.e. regexp literal).
|
|
76
|
-
// Instead, escape the s character.
|
|
77
|
-
function escapeScript(script) {
|
|
78
|
-
return script.replace(/<!--/g, "<\\!--").replace(/<\/(script)/gi, "</\\$1");
|
|
79
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const buildVendorBundles: () => Promise<void>;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { resolve } from "node:path";
|
|
2
|
-
import { build, mergeConfig } from "vite";
|
|
3
|
-
import { $ } from "../lib/$.mjs";
|
|
4
|
-
import { VENDOR_DIST_DIR, VENDOR_SRC_DIR } from "../lib/constants.mjs";
|
|
5
|
-
import { unlink } from "fs/promises";
|
|
6
|
-
import { pathExists } from "fs-extra";
|
|
7
|
-
const createConfig = (mode) => ({
|
|
8
|
-
mode,
|
|
9
|
-
plugins: [],
|
|
10
|
-
logLevel: process.env.VERBOSE ? "info" : "error",
|
|
11
|
-
build: {
|
|
12
|
-
emptyOutDir: false,
|
|
13
|
-
sourcemap: true,
|
|
14
|
-
minify: mode === "production",
|
|
15
|
-
},
|
|
16
|
-
define: {
|
|
17
|
-
"process.env.NODE_ENV": JSON.stringify(mode),
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
const configs = {
|
|
21
|
-
// Build react internals with server conditions
|
|
22
|
-
reactServerInternals: (mode) => mergeConfig(createConfig(mode), {
|
|
23
|
-
build: {
|
|
24
|
-
outDir: VENDOR_DIST_DIR,
|
|
25
|
-
lib: {
|
|
26
|
-
entry: resolve(VENDOR_SRC_DIR, "react-server-internals.js"),
|
|
27
|
-
name: "react-server-internals",
|
|
28
|
-
formats: ["es"],
|
|
29
|
-
fileName: () => `react-server-internals.${mode}.js`,
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
resolve: {
|
|
33
|
-
conditions: ["react-server"],
|
|
34
|
-
},
|
|
35
|
-
}),
|
|
36
|
-
// Build custom React implementation (for both development and production)
|
|
37
|
-
react: (mode) => mergeConfig(createConfig(mode), {
|
|
38
|
-
build: {
|
|
39
|
-
outDir: VENDOR_DIST_DIR,
|
|
40
|
-
lib: {
|
|
41
|
-
entry: resolve(VENDOR_SRC_DIR, "react.js"),
|
|
42
|
-
name: "react",
|
|
43
|
-
formats: ["es"],
|
|
44
|
-
fileName: () => `react.${mode}.js`,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
resolve: {
|
|
48
|
-
alias: {
|
|
49
|
-
"react-server-internals": resolve(VENDOR_DIST_DIR, `react-server-internals.${mode}.js`),
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
}),
|
|
53
|
-
};
|
|
54
|
-
export const buildVendorBundles = async () => {
|
|
55
|
-
console.log("Cleaning vendor directory...");
|
|
56
|
-
await $ `pnpm clean:vendor`;
|
|
57
|
-
// Build for both development and production modes
|
|
58
|
-
const modes = ["development", "production"];
|
|
59
|
-
// Build the temporary server internals files first
|
|
60
|
-
console.log("Building react-server-internals...");
|
|
61
|
-
for (const mode of modes) {
|
|
62
|
-
await build(configs.reactServerInternals(mode));
|
|
63
|
-
}
|
|
64
|
-
// Build React using the server internals
|
|
65
|
-
console.log("Building React custom builds...");
|
|
66
|
-
for (const mode of modes) {
|
|
67
|
-
await build(configs.react(mode));
|
|
68
|
-
}
|
|
69
|
-
// Clean up temporary server internals files
|
|
70
|
-
console.log("Cleaning up temporary server internals files...");
|
|
71
|
-
for (const mode of modes) {
|
|
72
|
-
const serverInternalsFile = resolve(VENDOR_DIST_DIR, `react-server-internals.${mode}.js`);
|
|
73
|
-
const serverInternalsMapFile = `${serverInternalsFile}.map`;
|
|
74
|
-
try {
|
|
75
|
-
// Delete the server internals JavaScript file
|
|
76
|
-
if (await pathExists(serverInternalsFile)) {
|
|
77
|
-
await unlink(serverInternalsFile);
|
|
78
|
-
}
|
|
79
|
-
// Delete the source map file if it exists
|
|
80
|
-
if (await pathExists(serverInternalsMapFile)) {
|
|
81
|
-
await unlink(serverInternalsMapFile);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
console.warn(`Warning: Failed to delete ${serverInternalsFile}`, error);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
console.log("Done building vendor bundles");
|
|
89
|
-
};
|
|
90
|
-
if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
|
|
91
|
-
buildVendorBundles();
|
|
92
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const aliasByEnvPlugin = (aliasesByEnv) => ({
|
|
2
|
-
name: "rw-sdk-env-alias",
|
|
3
|
-
enforce: "pre",
|
|
4
|
-
resolveId(id, importer) {
|
|
5
|
-
const aliases = aliasesByEnv[this.environment.name] ?? {};
|
|
6
|
-
const alias = aliases[id];
|
|
7
|
-
if (alias) {
|
|
8
|
-
return alias;
|
|
9
|
-
}
|
|
10
|
-
},
|
|
11
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export const asyncSetupPlugin = ({ setup, }) => {
|
|
2
|
-
let taskPromise = Promise.resolve(null);
|
|
3
|
-
return [
|
|
4
|
-
{
|
|
5
|
-
name: "rw-sdk-async-setup:serve",
|
|
6
|
-
apply: "serve",
|
|
7
|
-
configureServer(server) {
|
|
8
|
-
taskPromise = setup({ command: "serve" });
|
|
9
|
-
server.middlewares.use(async (_req, _res, next) => {
|
|
10
|
-
await taskPromise;
|
|
11
|
-
next();
|
|
12
|
-
});
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
name: "rw-sdk-async-setup:build",
|
|
17
|
-
apply: "build",
|
|
18
|
-
async buildStart() {
|
|
19
|
-
await setup({ command: "build" });
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
];
|
|
23
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { copy, pathExists } from "fs-extra";
|
|
2
|
-
import { resolve } from "node:path";
|
|
3
|
-
import MagicString from "magic-string";
|
|
4
|
-
import path from "path";
|
|
5
|
-
export const copyPrismaWasmPlugin = ({ rootDir, }) => ({
|
|
6
|
-
name: "rwsdk:copy-prisma-wasm",
|
|
7
|
-
enforce: "post",
|
|
8
|
-
apply: "build",
|
|
9
|
-
async writeBundle() {
|
|
10
|
-
const wasmFilePath = resolve(rootDir, "node_modules/.prisma/client/query_engine_bg.wasm");
|
|
11
|
-
const fileName = path.basename(wasmFilePath);
|
|
12
|
-
const outputPath = path.resolve(rootDir, "dist", "worker", fileName);
|
|
13
|
-
if (await pathExists(wasmFilePath)) {
|
|
14
|
-
await copy(wasmFilePath, outputPath);
|
|
15
|
-
console.log(`✅ Copied ${fileName} from ${wasmFilePath} to ${outputPath}`);
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
renderChunk(code) {
|
|
19
|
-
if (!code.includes(".wasm")) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const s = new MagicString(code);
|
|
23
|
-
s.replace(/import\(["'](.+?\.wasm)["']\)/g, (_, filePath) => {
|
|
24
|
-
const fileName = path.basename(filePath);
|
|
25
|
-
return `import("./${fileName}")`;
|
|
26
|
-
});
|
|
27
|
-
return {
|
|
28
|
-
code: s.toString(),
|
|
29
|
-
map: s.generateMap(),
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
});
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { resolve } from "path";
|
|
2
|
-
import { mkdirp, copy } from "fs-extra";
|
|
3
|
-
import { VENDOR_DIST_DIR } from "../lib/constants.mjs";
|
|
4
|
-
const copyReactFiles = async (viteDistDir) => {
|
|
5
|
-
await mkdirp(viteDistDir);
|
|
6
|
-
await copy(resolve(VENDOR_DIST_DIR, "react.js"), resolve(viteDistDir, "react.js"));
|
|
7
|
-
await copy(resolve(VENDOR_DIST_DIR, "react.js.map"), resolve(viteDistDir, "react.js.map"));
|
|
8
|
-
await copy(resolve(VENDOR_DIST_DIR, "react-dom-server-edge.js"), resolve(viteDistDir, "react-dom-server-edge.js"));
|
|
9
|
-
await copy(resolve(VENDOR_DIST_DIR, "react-dom-server-edge.js.map"), resolve(viteDistDir, "react-dom-server-edge.js.map"));
|
|
10
|
-
};
|
|
11
|
-
export const customReactBuildPlugin = async ({ projectRootDir, }) => {
|
|
12
|
-
const viteDistDir = resolve(projectRootDir, "node_modules", ".vite_@redwoodjs/sdk");
|
|
13
|
-
await copyReactFiles(viteDistDir);
|
|
14
|
-
return {
|
|
15
|
-
name: "custom-react-build-plugin",
|
|
16
|
-
enforce: "pre",
|
|
17
|
-
applyToEnvironment: (environment) => {
|
|
18
|
-
return environment.name === "worker";
|
|
19
|
-
},
|
|
20
|
-
async configureServer() {
|
|
21
|
-
await mkdirp(viteDistDir);
|
|
22
|
-
await copy(resolve(VENDOR_DIST_DIR, "react.js"), resolve(viteDistDir, "react.js"));
|
|
23
|
-
await copy(resolve(VENDOR_DIST_DIR, "react.js.map"), resolve(viteDistDir, "react.js.map"));
|
|
24
|
-
await copy(resolve(VENDOR_DIST_DIR, "react-dom-server-edge.js"), resolve(viteDistDir, "react-dom-server-edge.js"));
|
|
25
|
-
await copy(resolve(VENDOR_DIST_DIR, "react-dom-server-edge.js.map"), resolve(viteDistDir, "react-dom-server-edge.js.map"));
|
|
26
|
-
},
|
|
27
|
-
resolveId(id) {
|
|
28
|
-
if (id === "react") {
|
|
29
|
-
return resolve(viteDistDir, "react.js");
|
|
30
|
-
}
|
|
31
|
-
if (id === "react-dom/server.edge" || id === "react-dom/server") {
|
|
32
|
-
return resolve(viteDistDir, "react-dom-server-edge.js");
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
config: () => ({
|
|
36
|
-
environments: {
|
|
37
|
-
worker: {
|
|
38
|
-
optimizeDeps: {
|
|
39
|
-
esbuildOptions: {
|
|
40
|
-
plugins: [
|
|
41
|
-
{
|
|
42
|
-
name: "rewrite-react-imports",
|
|
43
|
-
setup(build) {
|
|
44
|
-
build.onResolve({ filter: /^react$/ }, (args) => {
|
|
45
|
-
return { path: resolve(viteDistDir, "react.js") };
|
|
46
|
-
});
|
|
47
|
-
build.onResolve({ filter: /^react-dom\/server\.edge$/ }, (args) => {
|
|
48
|
-
return {
|
|
49
|
-
path: resolve(viteDistDir, "react-dom-server-edge.js"),
|
|
50
|
-
};
|
|
51
|
-
});
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
}),
|
|
60
|
-
};
|
|
61
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import MagicString from "magic-string";
|
|
2
|
-
export const injectHmrPreambleJsxPlugin = () => ({
|
|
3
|
-
name: "rw-sdk-inject-hmr-preamble",
|
|
4
|
-
apply: "serve",
|
|
5
|
-
async transform(code, id) {
|
|
6
|
-
const htmlHeadRE = /jsxDEV\("html",[^]*?jsxDEV\("head",[^]*?\[(.*?)\]/s;
|
|
7
|
-
const match = code.match(htmlHeadRE);
|
|
8
|
-
if (!match) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const s = new MagicString(code);
|
|
12
|
-
const headContentStart = match.index + match[0].lastIndexOf("[");
|
|
13
|
-
s.appendLeft(headContentStart + 1, `jsxDEV("script", {
|
|
14
|
-
type: "module",
|
|
15
|
-
src: "/__vite_preamble__",
|
|
16
|
-
}),`);
|
|
17
|
-
return {
|
|
18
|
-
code: s.toString(),
|
|
19
|
-
map: s.generateMap(),
|
|
20
|
-
};
|
|
21
|
-
},
|
|
22
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Plugin } from "vite";
|
|
2
|
-
import { cloudflare } from "@cloudflare/vite-plugin";
|
|
3
|
-
type BasePluginOptions = Parameters<typeof cloudflare>[0];
|
|
4
|
-
type MiniflarePluginOptions = BasePluginOptions & {};
|
|
5
|
-
export declare const miniflarePlugin: (givenOptions: MiniflarePluginOptions & {
|
|
6
|
-
rootDir: string;
|
|
7
|
-
workerEntryPathname: string;
|
|
8
|
-
}) => (Plugin | Plugin[])[];
|
|
9
|
-
export {};
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { cloudflare } from "@cloudflare/vite-plugin";
|
|
2
|
-
import { resolve } from "node:path";
|
|
3
|
-
import colors from "picocolors";
|
|
4
|
-
import { readFile } from "node:fs/promises";
|
|
5
|
-
import { getShortName } from "../lib/getShortName.mjs";
|
|
6
|
-
import { pathExists } from "fs-extra";
|
|
7
|
-
const hasEntryAsAncestor = (module, entryFile, seen = new Set()) => {
|
|
8
|
-
// Prevent infinite recursion
|
|
9
|
-
if (seen.has(module))
|
|
10
|
-
return false;
|
|
11
|
-
seen.add(module);
|
|
12
|
-
// Check direct importers
|
|
13
|
-
for (const importer of module.importers) {
|
|
14
|
-
if (importer.file === entryFile)
|
|
15
|
-
return true;
|
|
16
|
-
// Recursively check importers
|
|
17
|
-
if (hasEntryAsAncestor(importer, entryFile, seen))
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
return false;
|
|
21
|
-
};
|
|
22
|
-
// Cache for "use client" status results
|
|
23
|
-
const useClientCache = new Map();
|
|
24
|
-
// Function to invalidate cache for a file
|
|
25
|
-
const invalidateUseClientCache = (file) => {
|
|
26
|
-
useClientCache.delete(file);
|
|
27
|
-
};
|
|
28
|
-
const isUseClientModule = async (ctx, file, seen = new Set()) => {
|
|
29
|
-
// Prevent infinite recursion
|
|
30
|
-
if (seen.has(file))
|
|
31
|
-
return false;
|
|
32
|
-
seen.add(file);
|
|
33
|
-
try {
|
|
34
|
-
// Check cache first
|
|
35
|
-
if (useClientCache.has(file)) {
|
|
36
|
-
return useClientCache.get(file);
|
|
37
|
-
}
|
|
38
|
-
// Read and check the file
|
|
39
|
-
const content = (await pathExists(file))
|
|
40
|
-
? await readFile(file, "utf-8")
|
|
41
|
-
: "";
|
|
42
|
-
const hasUseClient = content.includes("'use client'") || content.includes('"use client"');
|
|
43
|
-
if (hasUseClient) {
|
|
44
|
-
useClientCache.set(file, true);
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
// Get the module from the module graph to find importers
|
|
48
|
-
const module = ctx.server.moduleGraph.getModuleById(file);
|
|
49
|
-
if (!module) {
|
|
50
|
-
useClientCache.set(file, false);
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
// Check all importers recursively
|
|
54
|
-
for (const importer of module.importers) {
|
|
55
|
-
if (await isUseClientModule(ctx, importer.url, seen)) {
|
|
56
|
-
useClientCache.set(file, true);
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
useClientCache.set(file, false);
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
catch (error) {
|
|
64
|
-
useClientCache.set(file, false);
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
export const miniflarePlugin = (givenOptions) => [
|
|
69
|
-
cloudflare(givenOptions),
|
|
70
|
-
{
|
|
71
|
-
name: "rwsdk:miniflare-hmr",
|
|
72
|
-
async hotUpdate(ctx) {
|
|
73
|
-
const environment = givenOptions.viteEnvironment?.name ?? "worker";
|
|
74
|
-
const entry = givenOptions.workerEntryPathname;
|
|
75
|
-
if (!["client", environment].includes(this.environment.name)) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
// todo(justinvdm, 12 Dec 2024): Skip client references
|
|
79
|
-
const modules = Array.from(ctx.server.environments[environment].moduleGraph.getModulesByFile(ctx.file) ?? []);
|
|
80
|
-
const isWorkerUpdate = ctx.file === entry ||
|
|
81
|
-
modules.some((module) => hasEntryAsAncestor(module, entry));
|
|
82
|
-
// The worker doesnt need an update
|
|
83
|
-
// => Short circuit HMR
|
|
84
|
-
if (!isWorkerUpdate) {
|
|
85
|
-
return [];
|
|
86
|
-
}
|
|
87
|
-
// The worker needs an update, but this is the client environment
|
|
88
|
-
// => Notify for HMR update of any css files imported by in worker, that are also in the client module graph
|
|
89
|
-
// Why: There may have been changes to css classes referenced, which might css modules to change
|
|
90
|
-
if (this.environment.name === "client") {
|
|
91
|
-
const cssModules = [];
|
|
92
|
-
for (const [_, module] of ctx.server.environments[environment]
|
|
93
|
-
.moduleGraph.idToModuleMap) {
|
|
94
|
-
// todo(justinvdm, 13 Dec 2024): We check+update _all_ css files in worker module graph,
|
|
95
|
-
// but it could just be a subset of css files that are actually affected, depending
|
|
96
|
-
// on the importers and imports of the changed file. We should be smarter about this.
|
|
97
|
-
if (module.file && module.file.endsWith(".css")) {
|
|
98
|
-
const clientModules = ctx.server.environments.client.moduleGraph.getModulesByFile(module.file);
|
|
99
|
-
if (clientModules) {
|
|
100
|
-
cssModules.push(...clientModules.values());
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
invalidateUseClientCache(ctx.file);
|
|
105
|
-
return (await isUseClientModule(ctx, ctx.file))
|
|
106
|
-
? [...ctx.modules, ...cssModules]
|
|
107
|
-
: cssModules;
|
|
108
|
-
}
|
|
109
|
-
// The worker needs an update, and the hot check is for the worker environment
|
|
110
|
-
// => Notify for custom RSC-based HMR update, then short circuit HMR
|
|
111
|
-
if (isWorkerUpdate && this.environment.name === environment) {
|
|
112
|
-
const shortName = getShortName(ctx.file, ctx.server.config.root);
|
|
113
|
-
this.environment.logger.info(`${colors.green(`worker update`)} ${colors.dim(shortName)}`, {
|
|
114
|
-
clear: true,
|
|
115
|
-
timestamp: true,
|
|
116
|
-
});
|
|
117
|
-
const m = ctx.server.environments.client.moduleGraph
|
|
118
|
-
.getModulesByFile(resolve(givenOptions.rootDir, "src", "app", "style.css"))
|
|
119
|
-
?.values()
|
|
120
|
-
.next().value;
|
|
121
|
-
if (m) {
|
|
122
|
-
ctx.server.environments.client.moduleGraph.invalidateModule(m, new Set(), ctx.timestamp, true);
|
|
123
|
-
}
|
|
124
|
-
ctx.server.environments.client.hot.send({
|
|
125
|
-
type: "custom",
|
|
126
|
-
event: "rsc:update",
|
|
127
|
-
data: {
|
|
128
|
-
file: ctx.file,
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
return [];
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
];
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Miniflare, type RequestInit } from "miniflare";
|
|
2
|
-
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
3
|
-
type MiniflareResponse = Awaited<ReturnType<typeof Miniflare.prototype.dispatchFetch>>;
|
|
4
|
-
export declare const nodeToWebRequest: (req: IncomingMessage) => Request & RequestInit;
|
|
5
|
-
export declare const webToNodeResponse: (webResponse: Response | MiniflareResponse, nodeResponse: ServerResponse) => Promise<void>;
|
|
6
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export const nodeToWebRequest = (req) => {
|
|
2
|
-
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
3
|
-
return new Request(url.href, {
|
|
4
|
-
method: req.method,
|
|
5
|
-
headers: req.headers,
|
|
6
|
-
body: req.method !== "GET" && req.method !== "HEAD"
|
|
7
|
-
? req
|
|
8
|
-
: undefined,
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
duplex: "half",
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
export const webToNodeResponse = async (webResponse, nodeResponse) => {
|
|
14
|
-
// Copy status and headers
|
|
15
|
-
nodeResponse.statusCode = webResponse.status;
|
|
16
|
-
webResponse.headers.forEach((value, key) => {
|
|
17
|
-
nodeResponse.setHeader(key, value);
|
|
18
|
-
});
|
|
19
|
-
// Stream the response
|
|
20
|
-
if (webResponse.body) {
|
|
21
|
-
const reader = webResponse.body.getReader();
|
|
22
|
-
try {
|
|
23
|
-
while (true) {
|
|
24
|
-
const { done, value } = await reader.read();
|
|
25
|
-
if (done)
|
|
26
|
-
break;
|
|
27
|
-
nodeResponse.write(value);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
finally {
|
|
31
|
-
reader.releaseLock();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
nodeResponse.end();
|
|
35
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { resolve } from "node:path";
|
|
2
|
-
import { symlink, copyFile } from "node:fs/promises";
|
|
3
|
-
import { pathExists } from "fs-extra";
|
|
4
|
-
export async function setupEnvFiles({ rootDir, }) {
|
|
5
|
-
const envPath = resolve(rootDir, ".env");
|
|
6
|
-
const devVarsPath = resolve(rootDir, ".dev.vars");
|
|
7
|
-
const envExamplePath = resolve(rootDir, ".env.example");
|
|
8
|
-
const envExists = await pathExists(envPath);
|
|
9
|
-
const devVarsExists = await pathExists(devVarsPath);
|
|
10
|
-
const envExampleExists = await pathExists(envExamplePath);
|
|
11
|
-
// If .env.example exists but .env doesn't, copy from example to .env
|
|
12
|
-
if (!envExists && !devVarsExists && envExampleExists) {
|
|
13
|
-
try {
|
|
14
|
-
await copyFile(envExamplePath, envPath);
|
|
15
|
-
console.log("Created .env file from .env.example");
|
|
16
|
-
}
|
|
17
|
-
catch (error) {
|
|
18
|
-
console.warn("Failed to copy .env.example to .env:", error);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
// Create symlink from .env to .dev.vars if needed
|
|
22
|
-
if ((await pathExists(envPath)) && !devVarsExists) {
|
|
23
|
-
try {
|
|
24
|
-
await symlink(envPath, devVarsPath);
|
|
25
|
-
console.log("Created symlink from .env to .dev.vars");
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
console.warn("Failed to create symlink from .env to .dev.vars:", error);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|