rwsdk 0.1.17 ā 0.1.18-test.20250716133535
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/dist/lib/smokeTests/release.mjs +46 -17
- package/package.json +10 -9
- package/LICENSE.md +0 -21
- 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
|
@@ -285,23 +285,52 @@ export async function runRelease(cwd, projectDir, resourceUniqueKey) {
|
|
|
285
285
|
console.error(`Warning: Could not update wrangler.jsonc: ${error}`);
|
|
286
286
|
}
|
|
287
287
|
}
|
|
288
|
-
// Run release command with our interactive $expect utility
|
|
289
|
-
log("Running release command with interactive prompts");
|
|
290
|
-
const
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
288
|
+
// Run release command with our interactive $expect utility and retry logic
|
|
289
|
+
log("Running release command with interactive prompts and retries");
|
|
290
|
+
const MAX_RETRIES = 3;
|
|
291
|
+
let lastError = null;
|
|
292
|
+
let result = null;
|
|
293
|
+
for (let i = 0; i < MAX_RETRIES; i++) {
|
|
294
|
+
try {
|
|
295
|
+
console.log(`\nš Deploying worker to Cloudflare (Attempt ${i + 1}/${MAX_RETRIES})...`);
|
|
296
|
+
result = await $expect("npm run release", [
|
|
297
|
+
{
|
|
298
|
+
// Make the pattern more flexible to account for potential whitespace differences
|
|
299
|
+
expect: /Do you want to proceed with deployment\?\s*\(y\/N\)/i,
|
|
300
|
+
send: "y\r",
|
|
301
|
+
},
|
|
302
|
+
], {
|
|
303
|
+
reject: false, // Add reject: false to prevent uncaught promise rejections
|
|
304
|
+
env: {
|
|
305
|
+
RWSDK_RENAME_WORKER: "1",
|
|
306
|
+
RWSDK_RENAME_DB: "1",
|
|
307
|
+
...process.env,
|
|
308
|
+
},
|
|
309
|
+
cwd,
|
|
310
|
+
});
|
|
311
|
+
// Check exit code to ensure command succeeded
|
|
312
|
+
if (result.code === 0) {
|
|
313
|
+
log(`Release command succeeded on attempt ${i + 1}`);
|
|
314
|
+
lastError = null; // Clear last error on success
|
|
315
|
+
break; // Exit the loop on success
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
throw new Error(`Release command failed with exit code ${result.code}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
lastError = error;
|
|
323
|
+
log(`Attempt ${i + 1} failed: ${lastError.message}`);
|
|
324
|
+
if (i < MAX_RETRIES - 1) {
|
|
325
|
+
console.log(` Waiting 5 seconds before retrying...`);
|
|
326
|
+
await setTimeout(5000);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (lastError || !result) {
|
|
331
|
+
log("ERROR: Release command failed after all retries.");
|
|
332
|
+
throw lastError || new Error("Release command failed after all retries.");
|
|
333
|
+
}
|
|
305
334
|
// Check exit code to ensure command succeeded
|
|
306
335
|
if (result.code !== 0) {
|
|
307
336
|
// Add more contextual information about the error
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rwsdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18-test.20250716133535",
|
|
4
4
|
"description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
"./dist",
|
|
13
13
|
"./bin"
|
|
14
14
|
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc --build --clean && tsc",
|
|
17
|
+
"release": "./scripts/release.sh",
|
|
18
|
+
"test": "vitest --run",
|
|
19
|
+
"debug:sync": "tsx ./src/scripts/debug-sync.mts",
|
|
20
|
+
"smoke-test": "tsx ./src/scripts/smoke-test.mts"
|
|
21
|
+
},
|
|
15
22
|
"exports": {
|
|
16
23
|
"./vite": {
|
|
17
24
|
"default": "./dist/vite/index.mjs",
|
|
@@ -152,6 +159,7 @@
|
|
|
152
159
|
"peerDependencies": {
|
|
153
160
|
"vite": "^6.2.6"
|
|
154
161
|
},
|
|
162
|
+
"packageManager": "pnpm@9.14.4+sha512.c8180b3fbe4e4bca02c94234717896b5529740a6cbadf19fa78254270403ea2f27d4e1d46a08a0f56c89b63dc8ebfd3ee53326da720273794e6200fcf0d184ab",
|
|
155
163
|
"devDependencies": {
|
|
156
164
|
"@types/debug": "^4.1.12",
|
|
157
165
|
"@types/lodash": "^4.17.16",
|
|
@@ -161,12 +169,5 @@
|
|
|
161
169
|
"tsx": "^4.19.4",
|
|
162
170
|
"typescript": "^5.8.3",
|
|
163
171
|
"vitest": "^3.1.1"
|
|
164
|
-
},
|
|
165
|
-
"scripts": {
|
|
166
|
-
"build": "tsc --build --clean && tsc",
|
|
167
|
-
"release": "./scripts/release.sh",
|
|
168
|
-
"test": "vitest --run",
|
|
169
|
-
"debug:sync": "tsx ./src/scripts/debug-sync.mts",
|
|
170
|
-
"smoke-test": "tsx ./src/scripts/smoke-test.mts"
|
|
171
172
|
}
|
|
172
|
-
}
|
|
173
|
+
}
|
package/LICENSE.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 RedwoodJS Inc
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -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 {};
|