rwsdk 1.0.0-alpha.9 → 1.0.0-beta.0
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/constants.mjs +1 -2
- package/dist/lib/e2e/browser.d.mts +1 -1
- package/dist/lib/e2e/browser.mjs +3 -4
- package/dist/lib/e2e/dev.mjs +62 -52
- package/dist/lib/e2e/environment.d.mts +2 -6
- package/dist/lib/e2e/environment.mjs +59 -72
- package/dist/lib/e2e/index.d.mts +5 -4
- package/dist/lib/e2e/index.mjs +5 -4
- package/dist/lib/e2e/poll.d.mts +8 -0
- package/dist/lib/e2e/poll.mjs +31 -0
- package/dist/lib/e2e/release.mjs +4 -4
- package/dist/lib/e2e/retry.d.mts +4 -0
- package/dist/lib/e2e/retry.mjs +16 -0
- package/dist/lib/e2e/setup.d.mts +2 -0
- package/dist/lib/e2e/setup.mjs +1 -0
- package/dist/lib/e2e/tarball.d.mts +3 -2
- package/dist/lib/e2e/tarball.mjs +5 -5
- package/dist/lib/e2e/testHarness.d.mts +59 -50
- package/dist/lib/e2e/testHarness.mjs +289 -343
- package/dist/lib/getShortName.mjs +1 -2
- package/dist/lib/getShortName.test.mjs +2 -2
- package/dist/lib/getSrcPaths.js +2 -2
- package/dist/lib/hasPkgScript.test.mjs +2 -2
- package/dist/lib/jsonUtils.test.mjs +2 -2
- package/dist/lib/normalizeModulePath.test.mjs +2 -2
- package/dist/lib/setupEnvFiles.mjs +2 -2
- package/dist/lib/smokeTests/artifacts.mjs +2 -2
- package/dist/lib/smokeTests/browser.d.mts +1 -1
- package/dist/lib/smokeTests/browser.mjs +6 -7
- package/dist/lib/smokeTests/cleanup.mjs +6 -9
- package/dist/lib/smokeTests/codeUpdates.mjs +5 -5
- package/dist/lib/smokeTests/development.mjs +2 -2
- package/dist/lib/smokeTests/environment.d.mts +2 -3
- package/dist/lib/smokeTests/environment.mjs +17 -3
- package/dist/lib/smokeTests/release.d.mts +2 -2
- package/dist/lib/smokeTests/release.mjs +3 -3
- package/dist/lib/smokeTests/reporting.mjs +2 -2
- package/dist/lib/smokeTests/runSmokeTests.mjs +4 -4
- package/dist/lib/smokeTests/utils.mjs +3 -3
- package/dist/lib/testUtils/stubEnvVars.mjs +1 -1
- package/dist/llms/rules/middleware.d.ts +1 -1
- package/dist/llms/rules/middleware.js +4 -4
- package/dist/runtime/client/client.d.ts +2 -2
- package/dist/runtime/client/client.js +2 -2
- package/dist/runtime/client/navigation.test.js +1 -1
- package/dist/runtime/client/types.d.ts +1 -1
- package/dist/runtime/entries/client.d.ts +2 -2
- package/dist/runtime/entries/client.js +2 -2
- package/dist/runtime/entries/router.d.ts +1 -1
- package/dist/runtime/entries/router.js +1 -1
- package/dist/runtime/entries/worker.d.ts +5 -6
- package/dist/runtime/entries/worker.js +5 -6
- package/dist/runtime/imports/worker.js +1 -1
- package/dist/runtime/lib/auth/session.d.ts +2 -2
- package/dist/runtime/lib/auth/session.js +5 -5
- package/dist/runtime/lib/db/DOWorkerDialect.d.ts +1 -1
- package/dist/runtime/lib/db/DOWorkerDialect.js +1 -1
- package/dist/runtime/lib/db/SqliteDurableObject.js +2 -2
- package/dist/runtime/lib/db/index.d.ts +2 -2
- package/dist/runtime/lib/db/index.js +2 -2
- package/dist/runtime/lib/db/migrations.d.ts +1 -1
- package/dist/runtime/lib/db/typeInference/builders/alterTable.d.ts +3 -3
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.d.ts +1 -1
- package/dist/runtime/lib/db/typeInference/builders/createTable.d.ts +2 -2
- package/dist/runtime/lib/db/typeInference/builders/createView.d.ts +1 -1
- package/dist/runtime/lib/db/typeInference/builders/dropTable.d.ts +1 -1
- package/dist/runtime/lib/db/typeInference/builders/dropView.d.ts +1 -1
- package/dist/runtime/lib/db/typeInference/builders/schema.d.ts +3 -3
- package/dist/runtime/lib/db/typeInference/database.d.ts +2 -2
- package/dist/runtime/lib/memoizeOnId.test.js +1 -1
- package/dist/runtime/lib/realtime/client.js +2 -2
- package/dist/runtime/lib/realtime/durableObject.js +1 -1
- package/dist/runtime/lib/realtime/protocol.test.js +1 -1
- package/dist/runtime/lib/realtime/shared.test.js +1 -1
- package/dist/runtime/lib/realtime/validateUpgradeRequest.test.js +1 -1
- package/dist/runtime/lib/realtime/worker.js +2 -2
- package/dist/runtime/lib/router.d.ts +1 -1
- package/dist/runtime/lib/router.test.js +2 -3
- package/dist/runtime/lib/rwContext.d.ts +1 -1
- package/dist/runtime/lib/stitchDocumentAndAppStreams.d.ts +18 -0
- package/dist/runtime/lib/stitchDocumentAndAppStreams.js +143 -0
- package/dist/runtime/lib/turnstile/useTurnstile.js +1 -1
- package/dist/runtime/lib/turnstile/verifyTurnstileToken.test.js +1 -1
- package/dist/runtime/register/worker.d.ts +1 -1
- package/dist/runtime/register/worker.js +34 -22
- package/dist/runtime/render/assembleDocument.d.ts +1 -1
- package/dist/runtime/render/createThenableFromReadableStream.js +1 -1
- package/dist/runtime/render/preloads.d.ts +2 -2
- package/dist/runtime/render/renderDocumentHtmlStream.js +6 -6
- package/dist/runtime/render/renderHtmlStream.d.ts +1 -1
- package/dist/runtime/render/renderToRscStream.d.ts +4 -1
- package/dist/runtime/render/renderToRscStream.js +11 -1
- package/dist/runtime/render/renderToStream.d.ts +1 -1
- package/dist/runtime/render/renderToStream.js +2 -2
- package/dist/runtime/render/stylesheets.d.ts +1 -1
- package/dist/runtime/requestInfo/types.d.ts +0 -2
- package/dist/runtime/requestInfo/worker.d.ts +1 -1
- package/dist/runtime/requestInfo/worker.js +1 -9
- package/dist/runtime/script.js +1 -1
- package/dist/runtime/ssrBridge.d.ts +2 -2
- package/dist/runtime/ssrBridge.js +2 -2
- package/dist/runtime/worker.d.ts +1 -1
- package/dist/runtime/worker.js +3 -11
- package/dist/scripts/addon.d.mts +1 -0
- package/dist/scripts/addon.mjs +70 -0
- package/dist/scripts/debug-sync.mjs +106 -137
- package/dist/scripts/ensure-deploy-env.mjs +6 -6
- package/dist/scripts/migrate-new.mjs +3 -4
- package/dist/scripts/smoke-test.mjs +2 -2
- package/dist/scripts/worker-run.mjs +7 -9
- package/dist/vite/buildApp.mjs +1 -1
- package/dist/vite/checkIsUsingPrisma.test.mjs +1 -1
- package/dist/vite/configPlugin.mjs +33 -6
- package/dist/vite/createDirectiveLookupPlugin.mjs +1 -1
- package/dist/vite/createDirectiveLookupPlugin.test.mjs +2 -2
- package/dist/vite/createViteAwareResolver.d.mts +1 -2
- package/dist/vite/createViteAwareResolver.mjs +1 -1
- package/dist/vite/directiveModulesDevPlugin.mjs +4 -4
- package/dist/vite/directiveModulesDevPlugin.test.mjs +2 -2
- package/dist/vite/directivesPlugin.mjs +3 -3
- package/dist/vite/directivesPlugin.test.mjs +1 -1
- package/dist/vite/ensureAliasArray.test.mjs +1 -1
- package/dist/vite/findSpecifiers.mjs +1 -1
- package/dist/vite/findSpecifiers.test.mjs +2 -2
- package/dist/vite/findSsrSpecifiers.mjs +1 -1
- package/dist/vite/findSsrSpecifiers.test.mjs +1 -1
- package/dist/vite/getViteEsbuild.mjs +1 -1
- package/dist/vite/hasDirective.test.mjs +1 -1
- package/dist/vite/index.d.mts +1 -1
- package/dist/vite/invalidateCacheIfPrismaClientChanged.mjs +2 -2
- package/dist/vite/isJsFile.test.mjs +1 -1
- package/dist/vite/{reactConditionsResolverPlugin.d.mts → knownDepsResolverPlugin.d.mts} +3 -3
- package/dist/vite/{reactConditionsResolverPlugin.mjs → knownDepsResolverPlugin.mjs} +29 -24
- package/dist/vite/linkerPlugin.mjs +2 -2
- package/dist/vite/linkerPlugin.test.mjs +1 -1
- package/dist/vite/miniflareHMRPlugin.mjs +5 -5
- package/dist/vite/miniflareHMRPlugin.test.mjs +1 -1
- package/dist/vite/prismaPlugin.mjs +1 -1
- package/dist/vite/redwoodPlugin.d.mts +2 -0
- package/dist/vite/redwoodPlugin.mjs +36 -17
- package/dist/vite/redwoodPlugin.test.mjs +2 -2
- package/dist/vite/resolveForcedPaths.d.mts +4 -0
- package/dist/vite/resolveForcedPaths.mjs +9 -0
- package/dist/vite/runDirectivesScan.d.mts +2 -1
- package/dist/vite/runDirectivesScan.mjs +53 -17
- package/dist/vite/runDirectivesScan.test.mjs +2 -2
- package/dist/vite/ssrBridgePlugin.mjs +10 -3
- package/dist/vite/transformClientComponents.mjs +8 -6
- package/dist/vite/transformClientComponents.test.mjs +117 -59
- package/dist/vite/transformJsxScriptTagsPlugin.mjs +1 -1
- package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +2 -2
- package/dist/vite/transformServerFunctions.d.mts +1 -1
- package/dist/vite/transformServerFunctions.mjs +5 -5
- package/dist/vite/transformServerFunctions.test.mjs +3 -3
- package/package.json +54 -44
- package/dist/runtime/imports/resolveSSRValue.d.ts +0 -1
- package/dist/runtime/imports/resolveSSRValue.js +0 -8
- package/dist/runtime/lib/injectHtmlAtMarker.d.ts +0 -11
- package/dist/runtime/lib/injectHtmlAtMarker.js +0 -90
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import decompress from "decompress";
|
|
2
|
+
import { findUp } from "find-up";
|
|
3
|
+
import { createWriteStream } from "node:fs";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { Readable } from "node:stream";
|
|
8
|
+
import { pipeline } from "node:stream/promises";
|
|
9
|
+
async function getRwSdkProjectRootDir(cwd) {
|
|
10
|
+
const packageJsonPath = await findUp("package.json", { cwd });
|
|
11
|
+
if (packageJsonPath) {
|
|
12
|
+
return path.dirname(packageJsonPath);
|
|
13
|
+
}
|
|
14
|
+
return cwd;
|
|
15
|
+
}
|
|
16
|
+
export const addon = async () => {
|
|
17
|
+
const addonName = process.argv[2];
|
|
18
|
+
if (!addonName ||
|
|
19
|
+
process.argv.find((arg) => arg === "-h") ||
|
|
20
|
+
process.argv.find((arg) => arg === "--help")) {
|
|
21
|
+
console.error("Please specify the addon name.");
|
|
22
|
+
console.error(`Usage: npx rwsdk addon <addon-name>`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
const projectRootDir = await getRwSdkProjectRootDir(process.cwd());
|
|
27
|
+
const packageJsonPath = path.resolve(projectRootDir, "package.json");
|
|
28
|
+
const packageJsonContent = await fs.readFile(packageJsonPath, "utf-8");
|
|
29
|
+
const { dependencies, devDependencies } = JSON.parse(packageJsonContent);
|
|
30
|
+
let rwsdkVersion = dependencies?.rwsdk || devDependencies?.rwsdk;
|
|
31
|
+
if (rwsdkVersion === "workspace:*") {
|
|
32
|
+
throw new Error('The "rwsdk" dependency is set to "workspace:*". Please use a specific version of the SDK.');
|
|
33
|
+
}
|
|
34
|
+
if (!rwsdkVersion) {
|
|
35
|
+
console.error('Could not find "rwsdk" in your dependencies or devDependencies.');
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const tmpDirPrefix = path.join(os.tmpdir(), `rwsdk-addon-${addonName}-`);
|
|
39
|
+
const tmpDir = await fs.mkdtemp(tmpDirPrefix);
|
|
40
|
+
const downloadUrl = `https://github.com/redwoodjs/sdk/releases/download/${rwsdkVersion}/${addonName}-${rwsdkVersion}.tar.gz`;
|
|
41
|
+
console.log(`Downloading addon "${addonName}" version ${rwsdkVersion}...`);
|
|
42
|
+
const filePath = path.join(os.tmpdir(), `rwsdk-addon-${addonName}-${rwsdkVersion}.tar.gz`);
|
|
43
|
+
const response = await fetch(downloadUrl);
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
console.error(`Error downloading addon: ${response.statusText}`);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
if (!response.body) {
|
|
49
|
+
console.error(`\nError: Failed to download addon "${addonName}". The response contained no data.`);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
await pipeline(Readable.fromWeb(response.body), createWriteStream(filePath));
|
|
53
|
+
await decompress(filePath, tmpDir);
|
|
54
|
+
console.log();
|
|
55
|
+
console.log("Download complete!");
|
|
56
|
+
console.log(`The addon files are located in: ${tmpDir}`);
|
|
57
|
+
console.log();
|
|
58
|
+
console.log("To continue, open the step-by-step instructions:");
|
|
59
|
+
const instructionsPath = path.join(tmpDir, "INSTRUCTIONS.md");
|
|
60
|
+
console.log(`code ${instructionsPath}`);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
console.error(`Could not download addon "${addonName}". Please check the name and try again.`);
|
|
64
|
+
console.error(e.message);
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
|
|
69
|
+
addon();
|
|
70
|
+
}
|
|
@@ -1,32 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
1
|
+
import chokidar from "chokidar";
|
|
3
2
|
import { $ } from "execa";
|
|
4
|
-
import fs from "node:fs/promises";
|
|
5
3
|
import { existsSync } from "node:fs";
|
|
6
|
-
import
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { lock } from "proper-lockfile";
|
|
8
8
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
const getPackageManagerInfo = (targetDir) => {
|
|
10
|
-
if (existsSync(path.join(targetDir, "bun.lock"))) {
|
|
11
|
-
return { name: "bun", lockFile: "bun.lock", command: "add" };
|
|
12
|
-
}
|
|
13
|
-
const pnpmResult = {
|
|
14
|
-
name: "pnpm",
|
|
15
|
-
lockFile: "pnpm-lock.yaml",
|
|
16
|
-
command: "add",
|
|
17
|
-
};
|
|
18
|
-
if (existsSync(path.join(targetDir, "yarn.lock"))) {
|
|
19
|
-
return { name: "yarn", lockFile: "yarn.lock", command: "add" };
|
|
20
|
-
}
|
|
21
|
-
if (existsSync(path.join(targetDir, "pnpm-lock.yaml")) ||
|
|
22
|
-
existsSync(path.join(targetDir, "node_modules", ".pnpm"))) {
|
|
23
|
-
return pnpmResult;
|
|
24
|
-
}
|
|
25
|
-
if (existsSync(path.join(targetDir, "package-lock.json"))) {
|
|
26
|
-
return { name: "npm", lockFile: "package-lock.json", command: "install" };
|
|
27
|
-
}
|
|
28
|
-
return pnpmResult;
|
|
29
|
-
};
|
|
30
9
|
const cleanupViteEntries = async (targetDir) => {
|
|
31
10
|
const nodeModulesDir = path.join(targetDir, "node_modules");
|
|
32
11
|
if (!existsSync(nodeModulesDir)) {
|
|
@@ -58,91 +37,6 @@ const cleanupViteEntries = async (targetDir) => {
|
|
|
58
37
|
console.log(`Failed to cleanup vite cache entries: ${error}`);
|
|
59
38
|
}
|
|
60
39
|
};
|
|
61
|
-
const performFullSync = async (sdkDir, targetDir) => {
|
|
62
|
-
let tarballPath = "";
|
|
63
|
-
let tarballName = "";
|
|
64
|
-
// Clean up vite cache
|
|
65
|
-
await cleanupViteEntries(targetDir);
|
|
66
|
-
try {
|
|
67
|
-
console.log("📦 Packing SDK...");
|
|
68
|
-
const packResult = await $({ cwd: sdkDir }) `npm pack --json`;
|
|
69
|
-
const json = JSON.parse(packResult.stdout || "[]");
|
|
70
|
-
const packInfo = Array.isArray(json) ? json[0] : undefined;
|
|
71
|
-
tarballName = (packInfo && (packInfo.filename || packInfo.name)) || "";
|
|
72
|
-
if (!tarballName) {
|
|
73
|
-
console.error("❌ Failed to get tarball name from npm pack.");
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
tarballPath = path.resolve(sdkDir, tarballName);
|
|
77
|
-
console.log(`💿 Installing ${tarballName} in ${targetDir}...`);
|
|
78
|
-
const pm = getPackageManagerInfo(targetDir);
|
|
79
|
-
const packageJsonPath = path.join(targetDir, "package.json");
|
|
80
|
-
const lockfilePath = path.join(targetDir, pm.lockFile);
|
|
81
|
-
const originalPackageJson = await fs
|
|
82
|
-
.readFile(packageJsonPath, "utf-8")
|
|
83
|
-
.catch(() => null);
|
|
84
|
-
const originalLockfile = await fs
|
|
85
|
-
.readFile(lockfilePath, "utf-8")
|
|
86
|
-
.catch(() => null);
|
|
87
|
-
try {
|
|
88
|
-
// For bun, we need to remove the existing dependency from package.json
|
|
89
|
-
// before adding the tarball to avoid a dependency loop error.
|
|
90
|
-
if (pm.name === "bun" && originalPackageJson) {
|
|
91
|
-
try {
|
|
92
|
-
const targetPackageJson = JSON.parse(originalPackageJson);
|
|
93
|
-
let modified = false;
|
|
94
|
-
if (targetPackageJson.dependencies?.rwsdk) {
|
|
95
|
-
delete targetPackageJson.dependencies.rwsdk;
|
|
96
|
-
modified = true;
|
|
97
|
-
}
|
|
98
|
-
if (targetPackageJson.devDependencies?.rwsdk) {
|
|
99
|
-
delete targetPackageJson.devDependencies.rwsdk;
|
|
100
|
-
modified = true;
|
|
101
|
-
}
|
|
102
|
-
if (modified) {
|
|
103
|
-
console.log("Temporarily removing rwsdk from target package.json to prevent dependency loop with bun.");
|
|
104
|
-
await fs.writeFile(packageJsonPath, JSON.stringify(targetPackageJson, null, 2));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
catch (e) {
|
|
108
|
-
console.warn("Could not modify target package.json, proceeding anyway.");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
const cmd = pm.name;
|
|
112
|
-
const args = [pm.command];
|
|
113
|
-
if (pm.name === "yarn") {
|
|
114
|
-
// For modern yarn, disable PnP to avoid resolution issues with local tarballs
|
|
115
|
-
process.env.YARN_NODE_LINKER = "node-modules";
|
|
116
|
-
args.push(`rwsdk@file:${tarballPath}`);
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
args.push(tarballPath);
|
|
120
|
-
}
|
|
121
|
-
await $(cmd, args, {
|
|
122
|
-
cwd: targetDir,
|
|
123
|
-
stdio: "inherit",
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
finally {
|
|
127
|
-
if (originalPackageJson) {
|
|
128
|
-
console.log("Restoring package.json...");
|
|
129
|
-
await fs.writeFile(packageJsonPath, originalPackageJson);
|
|
130
|
-
}
|
|
131
|
-
if (originalLockfile) {
|
|
132
|
-
console.log(`Restoring ${pm.lockFile}...`);
|
|
133
|
-
await fs.writeFile(lockfilePath, originalLockfile);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
finally {
|
|
138
|
-
if (tarballPath) {
|
|
139
|
-
console.log("Removing tarball...");
|
|
140
|
-
await fs.unlink(tarballPath).catch(() => {
|
|
141
|
-
// ignore if deletion fails
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
40
|
const syncFilesWithRsyncOrFs = async (sdkDir, destDir, filesEntries) => {
|
|
147
41
|
const sources = filesEntries.map((p) => path.join(sdkDir, p));
|
|
148
42
|
// Always include package.json in sync
|
|
@@ -191,45 +85,120 @@ const syncFilesWithRsyncOrFs = async (sdkDir, destDir, filesEntries) => {
|
|
|
191
85
|
}
|
|
192
86
|
}
|
|
193
87
|
};
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
88
|
+
const findUp = async (names, startDir) => {
|
|
89
|
+
let dir = startDir;
|
|
90
|
+
while (dir !== path.dirname(dir)) {
|
|
91
|
+
for (const name of names) {
|
|
92
|
+
const filePath = path.join(dir, name);
|
|
93
|
+
if (existsSync(filePath)) {
|
|
94
|
+
return dir;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
dir = path.dirname(dir);
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
100
|
+
};
|
|
101
|
+
const getMonorepoRoot = async (startDir) => {
|
|
102
|
+
try {
|
|
103
|
+
// `pnpm root` is the most reliable way to find the workspace root node_modules
|
|
104
|
+
const { stdout } = await $({
|
|
105
|
+
cwd: startDir,
|
|
106
|
+
}) `pnpm root`;
|
|
107
|
+
// pnpm root returns the node_modules path, so we go up one level
|
|
108
|
+
return path.resolve(stdout, "..");
|
|
109
|
+
}
|
|
110
|
+
catch (e) {
|
|
111
|
+
console.warn(`Could not determine pnpm root from ${startDir}. Falling back to file search.`);
|
|
112
|
+
const root = await findUp(["pnpm-workspace.yaml"], startDir);
|
|
113
|
+
if (root) {
|
|
114
|
+
return root;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
console.warn("Could not find pnpm monorepo root. Using parent directory of target as fallback.");
|
|
118
|
+
return path.resolve(startDir, "..");
|
|
203
119
|
};
|
|
204
120
|
const areDependenciesEqual = (deps1, deps2) => {
|
|
205
121
|
// Simple string comparison for this use case is sufficient
|
|
206
122
|
return JSON.stringify(deps1 ?? {}) === JSON.stringify(deps2 ?? {});
|
|
207
123
|
};
|
|
124
|
+
const performFullSync = async (sdkDir, targetDir, monorepoRoot) => {
|
|
125
|
+
console.log("📦 Performing full sync with tarball...");
|
|
126
|
+
let tarballPath = "";
|
|
127
|
+
const projectName = path.basename(targetDir);
|
|
128
|
+
const rwsyncDir = path.join(monorepoRoot, "node_modules", `.rwsync_${projectName}`);
|
|
129
|
+
try {
|
|
130
|
+
// 1. Pack the SDK
|
|
131
|
+
const packResult = await $({ cwd: sdkDir }) `npm pack --json`;
|
|
132
|
+
const json = JSON.parse(packResult.stdout || "[]");
|
|
133
|
+
const packInfo = Array.isArray(json) ? json[0] : undefined;
|
|
134
|
+
const tarballName = (packInfo && (packInfo.filename || packInfo.name)) || "";
|
|
135
|
+
if (!tarballName) {
|
|
136
|
+
throw new Error("Failed to get tarball name from npm pack.");
|
|
137
|
+
}
|
|
138
|
+
tarballPath = path.resolve(sdkDir, tarballName);
|
|
139
|
+
// 2. Prepare isolated install directory
|
|
140
|
+
console.log(`Preparing isolated install directory at ${rwsyncDir}`);
|
|
141
|
+
await fs.rm(rwsyncDir, { recursive: true, force: true });
|
|
142
|
+
await fs.mkdir(rwsyncDir, { recursive: true });
|
|
143
|
+
await fs.writeFile(path.join(rwsyncDir, "package.json"), JSON.stringify({ name: `rwsync-env-${projectName}` }, null, 2));
|
|
144
|
+
// 3. Perform isolated install
|
|
145
|
+
console.log(`Installing ${tarballName} in isolation...`);
|
|
146
|
+
await $("pnpm", ["add", tarballPath], {
|
|
147
|
+
cwd: rwsyncDir,
|
|
148
|
+
stdio: "inherit",
|
|
149
|
+
});
|
|
150
|
+
// 4. Create symlink
|
|
151
|
+
const symlinkSource = path.join(rwsyncDir, "node_modules", "rwsdk");
|
|
152
|
+
const symlinkTarget = path.join(targetDir, "node_modules", "rwsdk");
|
|
153
|
+
console.log(`Symlinking ${symlinkTarget} -> ${symlinkSource}`);
|
|
154
|
+
await fs.rm(symlinkTarget, { recursive: true, force: true });
|
|
155
|
+
await fs.mkdir(path.dirname(symlinkTarget), { recursive: true });
|
|
156
|
+
await fs.symlink(symlinkSource, symlinkTarget, "dir");
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
if (tarballPath) {
|
|
160
|
+
console.log("Removing tarball...");
|
|
161
|
+
await fs.unlink(tarballPath).catch(() => { });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
const performFastSync = async (sdkDir, targetDir, monorepoRoot) => {
|
|
166
|
+
console.log("⚡️ Performing fast sync with rsync...");
|
|
167
|
+
const projectName = path.basename(targetDir);
|
|
168
|
+
const rwsyncDir = path.join(monorepoRoot, "node_modules", `.rwsync_${projectName}`);
|
|
169
|
+
const syncDestDir = path.join(rwsyncDir, "node_modules", "rwsdk");
|
|
170
|
+
// Copy directories/files declared in package.json#files (plus package.json)
|
|
171
|
+
const filesToSync = JSON.parse(await fs.readFile(path.join(sdkDir, "package.json"), "utf-8"))
|
|
172
|
+
.files || [];
|
|
173
|
+
await syncFilesWithRsyncOrFs(sdkDir, syncDestDir, filesToSync);
|
|
174
|
+
};
|
|
208
175
|
const performSync = async (sdkDir, targetDir) => {
|
|
209
176
|
console.log("🏗️ Rebuilding SDK...");
|
|
210
177
|
await $ `pnpm build`;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
178
|
+
// Clean up vite cache in the target project
|
|
179
|
+
await cleanupViteEntries(targetDir);
|
|
180
|
+
const monorepoRoot = await getMonorepoRoot(targetDir);
|
|
181
|
+
const projectName = path.basename(targetDir);
|
|
182
|
+
const installedSdkPackageJsonPath = path.join(monorepoRoot, "node_modules", `.rwsync_${projectName}`, "node_modules", "rwsdk", "package.json");
|
|
183
|
+
let needsFullSync = false;
|
|
184
|
+
if (!existsSync(installedSdkPackageJsonPath)) {
|
|
185
|
+
console.log("No previous sync found, performing full sync.");
|
|
186
|
+
needsFullSync = true;
|
|
217
187
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
188
|
+
else {
|
|
189
|
+
const sdkPackageJson = JSON.parse(await fs.readFile(path.join(sdkDir, "package.json"), "utf-8"));
|
|
190
|
+
const installedSdkPackageJson = JSON.parse(await fs.readFile(installedSdkPackageJsonPath, "utf-8"));
|
|
191
|
+
if (!areDependenciesEqual(sdkPackageJson.dependencies, installedSdkPackageJson.dependencies) ||
|
|
192
|
+
!areDependenciesEqual(sdkPackageJson.devDependencies, installedSdkPackageJson.devDependencies)) {
|
|
193
|
+
console.log("Dependency changes detected, performing full sync.");
|
|
194
|
+
needsFullSync = true;
|
|
195
|
+
}
|
|
226
196
|
}
|
|
227
|
-
if (
|
|
228
|
-
|
|
229
|
-
await performFullSync(sdkDir, targetDir);
|
|
197
|
+
if (needsFullSync) {
|
|
198
|
+
await performFullSync(sdkDir, targetDir, monorepoRoot);
|
|
230
199
|
}
|
|
231
200
|
else {
|
|
232
|
-
await performFastSync(sdkDir, targetDir);
|
|
201
|
+
await performFastSync(sdkDir, targetDir, monorepoRoot);
|
|
233
202
|
}
|
|
234
203
|
console.log("✅ Done syncing");
|
|
235
204
|
};
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { $ } from "../lib/$.mjs";
|
|
2
|
-
import { readFile, writeFile } from "fs/promises";
|
|
3
|
-
import { resolve, basename, join } from "path";
|
|
4
1
|
import { randomBytes } from "crypto";
|
|
2
|
+
import { pathExists } from "fs-extra";
|
|
3
|
+
import { readFile, writeFile } from "fs/promises";
|
|
5
4
|
import { glob } from "glob";
|
|
6
5
|
import { parse as parseJsonc } from "jsonc-parser";
|
|
7
|
-
import {
|
|
6
|
+
import { basename, join, resolve } from "path";
|
|
8
7
|
import * as readline from "readline";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { adjectives, animals, uniqueNamesGenerator, } from "unique-names-generator";
|
|
9
|
+
import { $ } from "../lib/$.mjs";
|
|
10
|
+
import { extractAllJson, parseJson } from "../lib/jsonUtils.mjs";
|
|
11
11
|
const promptForDeployment = async () => {
|
|
12
12
|
const rl = readline.createInterface({
|
|
13
13
|
input: process.stdin,
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { mkdirp } from "fs-extra";
|
|
2
|
+
import { readdir, writeFile } from "fs/promises";
|
|
1
3
|
import snakeCase from "lodash/snakeCase.js";
|
|
2
|
-
import { $ } from "../lib/$.mjs";
|
|
3
|
-
import { readdir } from "fs/promises";
|
|
4
4
|
import { resolve } from "path";
|
|
5
|
-
import {
|
|
6
|
-
import { writeFile } from "fs/promises";
|
|
5
|
+
import { $ } from "../lib/$.mjs";
|
|
7
6
|
const getNextMigrationNumber = async () => {
|
|
8
7
|
await mkdirp(resolve(process.cwd(), "./migrations"));
|
|
9
8
|
const files = await readdir(resolve(process.cwd(), "./migrations"));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { fileURLToPath } from "url";
|
|
2
|
-
import { join } from "path";
|
|
3
1
|
import debug from "debug";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
4
|
import { runSmokeTests } from "../lib/smokeTests/runSmokeTests.mjs";
|
|
5
5
|
import { isRunningInCI } from "../lib/smokeTests/utils.mjs";
|
|
6
6
|
// Set up debug logging
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { resolve } from "path";
|
|
3
|
-
import { writeFile } from "fs/promises";
|
|
4
|
-
import { unstable_readConfig } from "wrangler";
|
|
5
|
-
import { createServer as createViteServer } from "vite";
|
|
6
|
-
import tmp from "tmp-promise";
|
|
1
|
+
import { Lang, parse } from "@ast-grep/napi";
|
|
7
2
|
import baseDebug from "debug";
|
|
8
3
|
import enhancedResolve from "enhanced-resolve";
|
|
9
|
-
import { readFile } from "fs/promises";
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
4
|
+
import { readFile, writeFile } from "fs/promises";
|
|
5
|
+
import path, { resolve } from "path";
|
|
6
|
+
import tmp from "tmp-promise";
|
|
7
|
+
import { createServer as createViteServer } from "vite";
|
|
8
|
+
import { unstable_readConfig } from "wrangler";
|
|
12
9
|
import { findWranglerConfig } from "../lib/findWranglerConfig.mjs";
|
|
10
|
+
import { redwood } from "../vite/index.mjs";
|
|
13
11
|
const debug = baseDebug("rwsdk:worker-run");
|
|
14
12
|
export const runWorkerScript = async (relativeScriptPath) => {
|
|
15
13
|
if (!relativeScriptPath) {
|
package/dist/vite/buildApp.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import path, { resolve } from "node:path";
|
|
2
1
|
import enhancedResolve from "enhanced-resolve";
|
|
2
|
+
import path, { resolve } from "node:path";
|
|
3
3
|
import { INTERMEDIATE_SSR_BRIDGE_PATH } from "../lib/constants.mjs";
|
|
4
4
|
import { buildApp } from "./buildApp.mjs";
|
|
5
5
|
import { externalModules } from "./constants.mjs";
|
|
@@ -31,7 +31,17 @@ export const configPlugin = ({ silent, projectRootDir, workerEntryPathname, clie
|
|
|
31
31
|
},
|
|
32
32
|
optimizeDeps: {
|
|
33
33
|
noDiscovery: false,
|
|
34
|
-
include: [
|
|
34
|
+
include: [
|
|
35
|
+
"rwsdk/__ssr_bridge",
|
|
36
|
+
"rwsdk/auth",
|
|
37
|
+
"rwsdk/constants",
|
|
38
|
+
"rwsdk/db",
|
|
39
|
+
"rwsdk/debug",
|
|
40
|
+
"rwsdk/realtime/durableObject",
|
|
41
|
+
"rwsdk/realtime/worker",
|
|
42
|
+
"rwsdk/router",
|
|
43
|
+
"rwsdk/worker",
|
|
44
|
+
],
|
|
35
45
|
exclude: [],
|
|
36
46
|
entries: [workerEntryPathname],
|
|
37
47
|
esbuildOptions: {
|
|
@@ -78,7 +88,13 @@ export const configPlugin = ({ silent, projectRootDir, workerEntryPathname, clie
|
|
|
78
88
|
},
|
|
79
89
|
optimizeDeps: {
|
|
80
90
|
noDiscovery: false,
|
|
81
|
-
include: [
|
|
91
|
+
include: [
|
|
92
|
+
"rwsdk/client",
|
|
93
|
+
"rwsdk/constants",
|
|
94
|
+
"rwsdk/debug",
|
|
95
|
+
"rwsdk/realtime/client",
|
|
96
|
+
"rwsdk/turnstile",
|
|
97
|
+
],
|
|
82
98
|
entries: [],
|
|
83
99
|
esbuildOptions: {
|
|
84
100
|
jsx: "automatic",
|
|
@@ -105,7 +121,18 @@ export const configPlugin = ({ silent, projectRootDir, workerEntryPathname, clie
|
|
|
105
121
|
noDiscovery: false,
|
|
106
122
|
entries: [workerEntryPathname],
|
|
107
123
|
exclude: externalModules,
|
|
108
|
-
include: [
|
|
124
|
+
include: [
|
|
125
|
+
"rwsdk/__ssr",
|
|
126
|
+
"rwsdk/__ssr_bridge",
|
|
127
|
+
"rwsdk/client",
|
|
128
|
+
"rwsdk/constants",
|
|
129
|
+
"rwsdk/debug",
|
|
130
|
+
"rwsdk/realtime/client",
|
|
131
|
+
"rwsdk/router",
|
|
132
|
+
"rwsdk/worker",
|
|
133
|
+
"rwsdk/realtime/durableObject",
|
|
134
|
+
"rwsdk/realtime/worker",
|
|
135
|
+
],
|
|
109
136
|
esbuildOptions: {
|
|
110
137
|
jsx: "automatic",
|
|
111
138
|
jsxImportSource: "react",
|
|
@@ -138,8 +165,8 @@ export const configPlugin = ({ silent, projectRootDir, workerEntryPathname, clie
|
|
|
138
165
|
// original `export` statement from the bundle to prevent syntax
|
|
139
166
|
// errors.
|
|
140
167
|
inlineDynamicImports: true,
|
|
141
|
-
banner: `export const { renderHtmlStream, ssrWebpackRequire, ssrGetModuleExport, createThenableFromReadableStream } = (function() {`,
|
|
142
|
-
footer: `return { renderHtmlStream, ssrWebpackRequire, ssrGetModuleExport, createThenableFromReadableStream };\n})();`,
|
|
168
|
+
banner: `export const { renderHtmlStream, ssrLoadModule, ssrWebpackRequire, ssrGetModuleExport, createThenableFromReadableStream } = (function() {`,
|
|
169
|
+
footer: `return { renderHtmlStream, ssrLoadModule, ssrWebpackRequire, ssrGetModuleExport, createThenableFromReadableStream };\n})();`,
|
|
143
170
|
},
|
|
144
171
|
plugins: [
|
|
145
172
|
{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import debug from "debug";
|
|
1
2
|
import MagicString from "magic-string";
|
|
2
3
|
import path from "path";
|
|
3
|
-
import debug from "debug";
|
|
4
4
|
import { VENDOR_CLIENT_BARREL_EXPORT_PATH, VENDOR_SERVER_BARREL_EXPORT_PATH, } from "../lib/constants.mjs";
|
|
5
5
|
export function generateLookupMap({ files, isDev, kind, exportName, }) {
|
|
6
6
|
const s = new MagicString(`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { describe,
|
|
2
|
-
import { generateLookupMap } from "./createDirectiveLookupPlugin.mjs";
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
3
2
|
import { VENDOR_CLIENT_BARREL_EXPORT_PATH, VENDOR_SERVER_BARREL_EXPORT_PATH, } from "../lib/constants.mjs";
|
|
3
|
+
import { generateLookupMap } from "./createDirectiveLookupPlugin.mjs";
|
|
4
4
|
describe("generateLookupMap", () => {
|
|
5
5
|
const files = new Set([
|
|
6
6
|
"src/app.js",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import resolve, { ResolveOptions } from "enhanced-resolve";
|
|
2
|
-
import { ResolvedConfig } from "vite";
|
|
3
|
-
import { Environment } from "vite";
|
|
2
|
+
import { Environment, ResolvedConfig } from "vite";
|
|
4
3
|
export declare const mapViteResolveToEnhancedResolveOptions: (viteConfig: ResolvedConfig, envName: string) => ResolveOptions;
|
|
5
4
|
export declare const createViteAwareResolver: (viteConfig: ResolvedConfig, environment: Environment) => resolve.ResolveFunctionAsync;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import createDebug from "debug";
|
|
1
2
|
import resolve from "enhanced-resolve";
|
|
2
3
|
import fs from "fs";
|
|
3
4
|
import path from "path";
|
|
4
|
-
import createDebug from "debug";
|
|
5
5
|
import { normalizeModulePath } from "../lib/normalizeModulePath.mjs";
|
|
6
6
|
const debug = createDebug("rwsdk:vite:enhanced-resolve-plugin");
|
|
7
7
|
// Enhanced-resolve plugin that wraps Vite plugin resolution
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
2
2
|
import os from "os";
|
|
3
|
-
import
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { VENDOR_CLIENT_BARREL_EXPORT_PATH, VENDOR_CLIENT_BARREL_PATH, VENDOR_SERVER_BARREL_EXPORT_PATH, VENDOR_SERVER_BARREL_PATH, } from "../lib/constants.mjs";
|
|
4
5
|
import { normalizeModulePath } from "../lib/normalizeModulePath.mjs";
|
|
5
|
-
import { VENDOR_CLIENT_BARREL_PATH, VENDOR_SERVER_BARREL_PATH, VENDOR_CLIENT_BARREL_EXPORT_PATH, VENDOR_SERVER_BARREL_EXPORT_PATH, } from "../lib/constants.mjs";
|
|
6
6
|
import { runDirectivesScan } from "./runDirectivesScan.mjs";
|
|
7
7
|
export const generateVendorBarrelContent = (files, projectRootDir) => {
|
|
8
8
|
const imports = [...files]
|
|
@@ -84,7 +84,7 @@ export const directiveModulesDevPlugin = ({ clientFiles, serverFiles, projectRoo
|
|
|
84
84
|
env.optimizeDeps.include ??= [];
|
|
85
85
|
const entries = (env.optimizeDeps.entries = castArray(env.optimizeDeps.entries ?? []));
|
|
86
86
|
env.optimizeDeps.include.push(VENDOR_CLIENT_BARREL_EXPORT_PATH, VENDOR_SERVER_BARREL_EXPORT_PATH);
|
|
87
|
-
if (envName === "client") {
|
|
87
|
+
if (envName === "client" || envName === "ssr") {
|
|
88
88
|
entries.push(APP_CLIENT_BARREL_PATH);
|
|
89
89
|
}
|
|
90
90
|
else if (envName === "worker") {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { describe,
|
|
2
|
-
import {
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { generateAppBarrelContent, generateVendorBarrelContent, } from "./directiveModulesDevPlugin.mjs";
|
|
3
3
|
describe("directiveModulesDevPlugin helpers", () => {
|
|
4
4
|
const projectRootDir = "/Users/test/project";
|
|
5
5
|
describe("generateVendorBarrelContent", () => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import fs from "node:fs/promises";
|
|
3
1
|
import debug from "debug";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { normalizeModulePath } from "../lib/normalizeModulePath.mjs";
|
|
4
5
|
import { transformClientComponents } from "./transformClientComponents.mjs";
|
|
5
6
|
import { transformServerFunctions } from "./transformServerFunctions.mjs";
|
|
6
|
-
import { normalizeModulePath } from "../lib/normalizeModulePath.mjs";
|
|
7
7
|
const log = debug("rwsdk:vite:rsc-directives-plugin");
|
|
8
8
|
export const getLoader = (filePath) => {
|
|
9
9
|
const ext = path.extname(filePath).slice(1);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe,
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { ensureAliasArray } from "./ensureAliasArray.mjs";
|
|
3
3
|
describe("ensureAliasArray", () => {
|
|
4
4
|
it("should create resolve and alias array if resolve is undefined", () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Lang, Lang as SgLang, parse as sgParse } from "@ast-grep/napi";
|
|
2
2
|
import path from "path";
|
|
3
3
|
// These patterns are used to match import statements in code for SSR transformations.
|
|
4
4
|
export const IMPORT_PATTERNS = [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { describe,
|
|
2
|
-
import {
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { findExports, findImportSpecifiers } from "./findSpecifiers.mjs";
|
|
3
3
|
function dedupeImports(imports) {
|
|
4
4
|
const seen = new Set();
|
|
5
5
|
return imports.filter((imp) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Lang, Lang as SgLang, parse as sgParse } from "@ast-grep/napi";
|
|
2
2
|
import path from "path";
|
|
3
3
|
/**
|
|
4
4
|
* Finds callsites for __vite_ssr_import__ and __vite_ssr_dynamic_import__ with their ranges.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe,
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { findSsrImportCallSites } from "./findSsrSpecifiers.mjs";
|
|
3
3
|
describe("findSsrImportCallSites", () => {
|
|
4
4
|
it("should find __vite_ssr_import__ with double quotes", () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
1
|
import { createRequire } from "node:module";
|
|
2
|
+
import path from "node:path";
|
|
3
3
|
const require = createRequire(import.meta.url);
|
|
4
4
|
export async function getViteEsbuild(projectRootDir) {
|
|
5
5
|
const vitePath = require.resolve("vite/package.json", {
|