rwsdk 0.1.16 → 0.1.17-test.20250715200658
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/$.d.mts +8 -0
- package/dist/lib/$.mjs +5 -0
- package/dist/lib/constants.d.mts +4 -0
- package/dist/lib/constants.mjs +6 -0
- package/dist/lib/findWranglerConfig.d.mts +1 -0
- package/dist/lib/findWranglerConfig.mjs +12 -0
- package/dist/lib/getShortName.d.mts +1 -0
- package/dist/lib/getShortName.mjs +2 -0
- package/dist/lib/getSrcPaths.d.ts +15 -0
- package/dist/lib/getSrcPaths.js +80 -0
- package/dist/lib/hasPkgScript.d.mts +1 -0
- package/dist/lib/hasPkgScript.mjs +9 -0
- package/dist/lib/jsonUtils.d.mts +28 -0
- package/dist/lib/jsonUtils.mjs +167 -0
- package/dist/lib/setupEnvFiles.d.mts +4 -0
- package/dist/lib/setupEnvFiles.mjs +31 -0
- package/dist/lib/smokeTests/artifacts.d.mts +10 -0
- package/dist/lib/smokeTests/artifacts.mjs +164 -0
- package/dist/lib/smokeTests/browser.d.mts +48 -0
- package/dist/lib/smokeTests/browser.mjs +1041 -0
- package/dist/lib/smokeTests/cleanup.d.mts +5 -0
- package/dist/lib/smokeTests/cleanup.mjs +214 -0
- package/dist/lib/smokeTests/codeUpdates.d.mts +8 -0
- package/dist/lib/smokeTests/codeUpdates.mjs +229 -0
- package/dist/lib/smokeTests/constants.d.mts +5 -0
- package/dist/lib/smokeTests/constants.mjs +10 -0
- package/dist/lib/smokeTests/development.d.mts +11 -0
- package/dist/lib/smokeTests/development.mjs +209 -0
- package/dist/lib/smokeTests/environment.d.mts +14 -0
- package/dist/lib/smokeTests/environment.mjs +163 -0
- package/dist/lib/smokeTests/release.d.mts +61 -0
- package/dist/lib/smokeTests/release.mjs +526 -0
- package/dist/lib/smokeTests/reporting.d.mts +13 -0
- package/dist/lib/smokeTests/reporting.mjs +355 -0
- package/dist/lib/smokeTests/runSmokeTests.d.mts +5 -0
- package/dist/lib/smokeTests/runSmokeTests.mjs +144 -0
- package/dist/lib/smokeTests/state.d.mts +48 -0
- package/dist/lib/smokeTests/state.mjs +57 -0
- package/dist/lib/smokeTests/templates/SmokeTest.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/SmokeTest.template.js +81 -0
- package/dist/lib/smokeTests/templates/SmokeTestClient.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/SmokeTestClient.template.js +159 -0
- package/dist/lib/smokeTests/templates/smokeTestFunctions.template.d.ts +1 -0
- package/dist/lib/smokeTests/templates/smokeTestFunctions.template.js +19 -0
- package/dist/lib/smokeTests/types.d.mts +75 -0
- package/dist/lib/smokeTests/utils.d.mts +15 -0
- package/dist/lib/smokeTests/utils.mjs +147 -0
- package/dist/llms/index.d.ts +3 -0
- package/dist/llms/index.js +35 -0
- package/dist/llms/rules/interruptors.d.ts +1 -0
- package/dist/llms/rules/interruptors.js +243 -0
- package/dist/llms/rules/middleware.d.ts +1 -0
- package/dist/llms/rules/middleware.js +71 -0
- package/dist/llms/rules/react.d.ts +1 -0
- package/dist/llms/rules/react.js +106 -0
- package/dist/llms/rules/request-response.d.ts +1 -0
- package/dist/llms/rules/request-response.js +209 -0
- package/dist/runtime/client.d.ts +17 -0
- package/dist/runtime/client.js +74 -0
- package/dist/runtime/clientNavigation.d.ts +4 -0
- package/dist/runtime/clientNavigation.js +53 -0
- package/dist/runtime/clientNavigation.test.d.ts +1 -0
- package/dist/runtime/clientNavigation.test.js +55 -0
- package/dist/runtime/constants.d.ts +1 -0
- package/dist/runtime/constants.js +1 -0
- package/dist/runtime/entries/auth.d.ts +1 -0
- package/dist/runtime/entries/auth.js +1 -0
- package/dist/runtime/entries/client.d.ts +4 -0
- package/dist/runtime/entries/client.js +4 -0
- package/dist/runtime/entries/clientSSR.d.ts +1 -0
- package/dist/runtime/entries/clientSSR.js +1 -0
- package/dist/runtime/entries/no-react-server.d.ts +0 -0
- package/dist/runtime/entries/no-react-server.js +2 -0
- package/dist/runtime/entries/react-server-only.d.ts +0 -0
- package/dist/runtime/entries/react-server-only.js +2 -0
- package/dist/runtime/entries/router.d.ts +2 -0
- package/dist/runtime/entries/router.js +2 -0
- package/dist/runtime/entries/ssr.d.ts +1 -0
- package/dist/runtime/entries/ssr.js +1 -0
- package/dist/runtime/entries/worker.d.ts +9 -0
- package/dist/runtime/entries/worker.js +9 -0
- package/dist/runtime/error.d.ts +6 -0
- package/dist/runtime/error.js +8 -0
- package/dist/runtime/imports/ClientOnly.d.ts +3 -0
- package/dist/runtime/imports/ClientOnly.js +8 -0
- package/dist/runtime/imports/client.d.ts +4 -0
- package/dist/runtime/imports/client.js +33 -0
- package/dist/runtime/imports/ssr.d.ts +5 -0
- package/dist/runtime/imports/ssr.js +20 -0
- package/dist/runtime/imports/worker.d.ts +5 -0
- package/dist/runtime/imports/worker.js +22 -0
- package/dist/runtime/lib/auth/index.d.ts +1 -0
- package/dist/runtime/lib/auth/index.js +1 -0
- package/dist/runtime/lib/auth/session.d.ts +50 -0
- package/dist/runtime/lib/auth/session.js +148 -0
- package/dist/runtime/lib/db/DOWorkerDialect.d.ts +29 -0
- package/dist/runtime/lib/db/DOWorkerDialect.js +66 -0
- package/dist/runtime/lib/db/SqliteDurableObject.d.ts +14 -0
- package/dist/runtime/lib/db/SqliteDurableObject.js +42 -0
- package/dist/runtime/lib/db/createDb.d.ts +2 -0
- package/dist/runtime/lib/db/createDb.js +33 -0
- package/dist/runtime/lib/db/index.d.ts +4 -0
- package/dist/runtime/lib/db/index.js +3 -0
- package/dist/runtime/lib/db/migrations.d.ts +23 -0
- package/dist/runtime/lib/db/migrations.js +34 -0
- package/dist/runtime/lib/db/typeInference/assert.d.ts +2 -0
- package/dist/runtime/lib/db/typeInference/assert.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/alterColumn.d.ts +27 -0
- package/dist/runtime/lib/db/typeInference/builders/alterColumn.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.d.ts +53 -0
- package/dist/runtime/lib/db/typeInference/builders/alterTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.d.ts +26 -0
- package/dist/runtime/lib/db/typeInference/builders/columnDefinition.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/createTable.d.ts +49 -0
- package/dist/runtime/lib/db/typeInference/builders/createTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/createView.d.ts +17 -0
- package/dist/runtime/lib/db/typeInference/builders/createView.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/dropTable.d.ts +11 -0
- package/dist/runtime/lib/db/typeInference/builders/dropTable.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/dropView.d.ts +12 -0
- package/dist/runtime/lib/db/typeInference/builders/dropView.js +1 -0
- package/dist/runtime/lib/db/typeInference/builders/schema.d.ts +24 -0
- package/dist/runtime/lib/db/typeInference/builders/schema.js +1 -0
- package/dist/runtime/lib/db/typeInference/database.d.ts +27 -0
- package/dist/runtime/lib/db/typeInference/database.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/alterTable.typetest.js +360 -0
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/createTable.typetest.js +33 -0
- package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/dropTable.typetest.js +143 -0
- package/dist/runtime/lib/db/typeInference/typetests/print.d.ts +3 -0
- package/dist/runtime/lib/db/typeInference/typetests/print.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.d.ts +2 -0
- package/dist/runtime/lib/db/typeInference/typetests/testUtils.js +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.d.ts +1 -0
- package/dist/runtime/lib/db/typeInference/typetests/typeInference.typetest.js +17 -0
- package/dist/runtime/lib/db/typeInference/utils.d.ts +82 -0
- package/dist/runtime/lib/db/typeInference/utils.js +2 -0
- package/dist/runtime/lib/debug.d.ts +2 -0
- package/dist/runtime/lib/debug.js +36 -0
- package/dist/runtime/lib/links.d.ts +14 -0
- package/dist/runtime/lib/links.js +38 -0
- package/dist/runtime/lib/realtime/client.d.ts +7 -0
- package/dist/runtime/lib/realtime/client.js +166 -0
- package/dist/runtime/lib/realtime/constants.d.ts +1 -0
- package/dist/runtime/lib/realtime/constants.js +1 -0
- package/dist/runtime/lib/realtime/durableObject.d.ts +29 -0
- package/dist/runtime/lib/realtime/durableObject.js +187 -0
- package/dist/runtime/lib/realtime/renderRealtimeClients.d.ts +7 -0
- package/dist/runtime/lib/realtime/renderRealtimeClients.js +6 -0
- package/dist/runtime/lib/realtime/shared.d.ts +10 -0
- package/dist/runtime/lib/realtime/shared.js +10 -0
- package/dist/runtime/lib/realtime/validateUpgradeRequest.d.ts +6 -0
- package/dist/runtime/lib/realtime/validateUpgradeRequest.js +29 -0
- package/dist/runtime/lib/realtime/worker.d.ts +3 -0
- package/dist/runtime/lib/realtime/worker.js +16 -0
- package/dist/runtime/lib/router.d.ts +56 -0
- package/dist/runtime/lib/router.js +210 -0
- package/dist/runtime/lib/router.test.d.ts +1 -0
- package/dist/runtime/lib/router.test.js +58 -0
- package/dist/runtime/lib/streams/consumeEventStream.d.ts +4 -0
- package/dist/runtime/lib/streams/consumeEventStream.js +13 -0
- package/dist/runtime/lib/turnstile/TurnstileScript.d.ts +1 -0
- package/dist/runtime/lib/turnstile/TurnstileScript.js +2 -0
- package/dist/runtime/lib/turnstile/turnstile.d.ts +3 -0
- package/dist/runtime/lib/turnstile/turnstile.js +3 -0
- package/dist/runtime/lib/turnstile/useTurnstile.d.ts +4 -0
- package/dist/runtime/lib/turnstile/useTurnstile.js +23 -0
- package/dist/runtime/lib/turnstile/verifyTurnstileToken.d.ts +4 -0
- package/dist/runtime/lib/turnstile/verifyTurnstileToken.js +15 -0
- package/dist/runtime/lib/utils.d.ts +1 -0
- package/dist/runtime/lib/utils.js +1 -0
- package/dist/runtime/register/client.d.ts +1 -0
- package/dist/runtime/register/client.js +5 -0
- package/dist/runtime/register/ssr.d.ts +3 -0
- package/dist/runtime/register/ssr.js +26 -0
- package/dist/runtime/register/worker.d.ts +4 -0
- package/dist/runtime/register/worker.js +42 -0
- package/dist/runtime/render/createClientManifest.d.ts +1 -0
- package/dist/runtime/render/createClientManifest.js +7 -0
- package/dist/runtime/render/createModuleMap.d.ts +1 -0
- package/dist/runtime/render/createModuleMap.js +13 -0
- package/dist/runtime/render/renderRscThenableToHtmlStream.d.ts +9 -0
- package/dist/runtime/render/renderRscThenableToHtmlStream.js +49 -0
- package/dist/runtime/render/renderToRscStream.d.ts +5 -0
- package/dist/runtime/render/renderToRscStream.js +46 -0
- package/dist/runtime/render/renderToStream.d.ts +9 -0
- package/dist/runtime/render/renderToStream.js +27 -0
- package/dist/runtime/render/renderToString.d.ts +7 -0
- package/dist/runtime/render/renderToString.js +26 -0
- package/dist/runtime/render/transformRscToHtmlStream.d.ts +8 -0
- package/dist/runtime/render/transformRscToHtmlStream.js +19 -0
- package/dist/runtime/requestInfo/types.d.ts +11 -0
- package/dist/runtime/requestInfo/types.js +1 -0
- package/dist/runtime/requestInfo/worker.d.ts +5 -0
- package/dist/runtime/requestInfo/worker.js +33 -0
- package/dist/runtime/script.d.ts +5 -0
- package/dist/runtime/script.js +8 -0
- package/dist/runtime/ssrBridge.d.ts +2 -0
- package/dist/runtime/ssrBridge.js +11 -0
- package/dist/runtime/worker.d.ts +18 -0
- package/dist/runtime/worker.js +173 -0
- package/dist/scripts/__sdk.d.mts +1 -0
- package/dist/scripts/__sdk.mjs +14 -0
- package/dist/scripts/debug-sync.d.mts +6 -0
- package/dist/scripts/debug-sync.mjs +224 -0
- package/dist/scripts/dev-init.d.mts +1 -0
- package/dist/scripts/dev-init.mjs +25 -0
- package/dist/scripts/ensure-deploy-env.d.mts +1 -0
- package/dist/scripts/ensure-deploy-env.mjs +271 -0
- package/dist/scripts/ensure-env.d.mts +1 -0
- package/dist/scripts/ensure-env.mjs +9 -0
- package/dist/scripts/migrate-new.d.mts +1 -0
- package/dist/scripts/migrate-new.mjs +51 -0
- package/dist/scripts/smoke-test.d.mts +1 -0
- package/dist/scripts/smoke-test.mjs +166 -0
- package/dist/scripts/worker-run.d.mts +1 -0
- package/dist/scripts/worker-run.mjs +82 -0
- package/dist/vite/checkIsUsingPrisma.d.mts +6 -0
- package/dist/vite/checkIsUsingPrisma.mjs +18 -0
- package/dist/vite/configPlugin.d.mts +9 -0
- package/dist/vite/configPlugin.mjs +169 -0
- package/dist/vite/createDirectiveLookupPlugin.d.mts +21 -0
- package/dist/vite/createDirectiveLookupPlugin.mjs +231 -0
- package/dist/vite/devServerTimingPlugin.d.mts +2 -0
- package/dist/vite/devServerTimingPlugin.mjs +24 -0
- package/dist/vite/directivesPlugin.d.mts +6 -0
- package/dist/vite/directivesPlugin.mjs +200 -0
- package/dist/vite/ensureAliasArray.d.mts +2 -0
- package/dist/vite/ensureAliasArray.mjs +17 -0
- package/dist/vite/findSpecifiers.d.mts +31 -0
- package/dist/vite/findSpecifiers.mjs +230 -0
- package/dist/vite/findSsrSpecifiers.d.mts +11 -0
- package/dist/vite/findSsrSpecifiers.mjs +67 -0
- package/dist/vite/hasDirective.d.mts +7 -0
- package/dist/vite/hasDirective.mjs +54 -0
- package/dist/vite/hasOwnCloudflareVitePlugin.d.mts +3 -0
- package/dist/vite/hasOwnCloudflareVitePlugin.mjs +14 -0
- package/dist/vite/index.d.mts +1 -0
- package/dist/vite/index.mjs +1 -0
- package/dist/vite/injectVitePreamblePlugin.d.mts +4 -0
- package/dist/vite/injectVitePreamblePlugin.mjs +23 -0
- package/dist/vite/invalidateCacheIfPrismaClientChanged.d.mts +3 -0
- package/dist/vite/invalidateCacheIfPrismaClientChanged.mjs +27 -0
- package/dist/vite/invalidateModule.d.mts +6 -0
- package/dist/vite/invalidateModule.mjs +30 -0
- package/dist/vite/miniflareHMRPlugin.d.mts +10 -0
- package/dist/vite/miniflareHMRPlugin.mjs +209 -0
- package/dist/vite/moveStaticAssetsPlugin.d.mts +4 -0
- package/dist/vite/moveStaticAssetsPlugin.mjs +12 -0
- package/dist/vite/normalizeModulePath.d.mts +1 -0
- package/dist/vite/normalizeModulePath.mjs +13 -0
- package/dist/vite/prismaPlugin.d.mts +4 -0
- package/dist/vite/prismaPlugin.mjs +43 -0
- package/dist/vite/reactConditionsResolverPlugin.d.mts +16 -0
- package/dist/vite/reactConditionsResolverPlugin.mjs +179 -0
- package/dist/vite/redwoodPlugin.d.mts +12 -0
- package/dist/vite/redwoodPlugin.mjs +105 -0
- package/dist/vite/ssrBridgePlugin.d.mts +7 -0
- package/dist/vite/ssrBridgePlugin.mjs +137 -0
- package/dist/vite/transformClientComponents.d.mts +12 -0
- package/dist/vite/transformClientComponents.mjs +116 -0
- package/dist/vite/transformClientComponents.test.d.mts +1 -0
- package/dist/vite/transformClientComponents.test.mjs +264 -0
- package/dist/vite/transformJsxScriptTagsPlugin.d.mts +8 -0
- package/dist/vite/transformJsxScriptTagsPlugin.mjs +315 -0
- package/dist/vite/transformJsxScriptTagsPlugin.test.d.mts +1 -0
- package/dist/vite/transformJsxScriptTagsPlugin.test.mjs +334 -0
- package/dist/vite/transformServerFunctions.d.mts +16 -0
- package/dist/vite/transformServerFunctions.mjs +296 -0
- package/dist/vite/transformServerFunctions.test.d.mts +1 -0
- package/dist/vite/transformServerFunctions.test.mjs +124 -0
- package/dist/vite/useClientLookupPlugin.d.mts +5 -0
- package/dist/vite/useClientLookupPlugin.mjs +15 -0
- package/dist/vite/useServerLookupPlugin.d.mts +5 -0
- package/dist/vite/useServerLookupPlugin.mjs +15 -0
- package/dist/vite/useServerPlugin.d.mts +1 -0
- package/dist/vite/useServerPlugin.mjs +1 -0
- package/dist/vite/virtualPlugin.d.mts +2 -0
- package/dist/vite/virtualPlugin.mjs +18 -0
- package/dist/vite/vitePreamblePlugin.d.mts +1 -0
- package/dist/vite/vitePreamblePlugin.mjs +11 -0
- package/package.json +1 -1
- package/dist/runtime/lib/db/typeInference/builders/table.d.ts +0 -10
- package/dist/vite/invalidateClientModule.d.mts +0 -2
- package/dist/vite/invalidateClientModule.mjs +0 -8
- package/dist/vite/invalidateModule copy.d.mts +0 -2
- package/dist/vite/invalidateModule copy.mjs +0 -14
- package/dist/vite/invalidateSSRModule.d.mts +0 -2
- package/dist/vite/invalidateSSRModule.mjs +0 -7
- package/dist/vite/mode.d.mts +0 -5
- package/dist/vite/mode.mjs +0 -25
- package/dist/vite/modePlugin.d.mts +0 -2
- package/dist/vite/modePlugin.mjs +0 -10
- /package/dist/{runtime/lib/db/typeInference/builders/table.js → lib/smokeTests/types.mjs} +0 -0
- /package/dist/vite/{isJsFile.d.ts → isJsFile.d.mts} +0 -0
- /package/dist/vite/{isJsFile.js → isJsFile.mjs} +0 -0
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { $ } from "../lib/$.mjs";
|
|
2
|
+
import { readFile, writeFile } from "fs/promises";
|
|
3
|
+
import { resolve, basename, join } from "path";
|
|
4
|
+
import { randomBytes } from "crypto";
|
|
5
|
+
import { glob } from "glob";
|
|
6
|
+
import { parse as parseJsonc } from "jsonc-parser";
|
|
7
|
+
import { uniqueNamesGenerator, adjectives, animals, } from "unique-names-generator";
|
|
8
|
+
import * as readline from "readline";
|
|
9
|
+
import { pathExists } from "fs-extra";
|
|
10
|
+
import { parseJson, extractAllJson } from "../lib/jsonUtils.mjs";
|
|
11
|
+
const promptForDeployment = async () => {
|
|
12
|
+
const rl = readline.createInterface({
|
|
13
|
+
input: process.stdin,
|
|
14
|
+
output: process.stdout,
|
|
15
|
+
});
|
|
16
|
+
return new Promise((resolve) => {
|
|
17
|
+
// Handle Ctrl+C (SIGINT)
|
|
18
|
+
rl.on('SIGINT', () => {
|
|
19
|
+
rl.close();
|
|
20
|
+
console.log('\nDeployment cancelled.');
|
|
21
|
+
process.exit(1);
|
|
22
|
+
});
|
|
23
|
+
rl.question("Do you want to proceed with deployment? (y/N): ", (answer) => {
|
|
24
|
+
rl.close();
|
|
25
|
+
resolve(answer.toLowerCase() === "y");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
const generateSecretKey = () => {
|
|
30
|
+
return randomBytes(32).toString("base64");
|
|
31
|
+
};
|
|
32
|
+
const hasWebAuthn = async () => {
|
|
33
|
+
const files = await glob("src/**/*.{ts,tsx}", { ignore: "node_modules/**" });
|
|
34
|
+
for (const file of files) {
|
|
35
|
+
const content = await readFile(file, "utf-8");
|
|
36
|
+
if (content.includes("WEBAUTHN")) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
};
|
|
42
|
+
const hasD1Database = async () => {
|
|
43
|
+
const files = await glob("src/**/*.{ts,tsx}", { ignore: "node_modules/**" });
|
|
44
|
+
for (const file of files) {
|
|
45
|
+
const content = await readFile(file, "utf-8");
|
|
46
|
+
if (content.includes("env.DB")) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
};
|
|
52
|
+
const hasAuthUsage = async () => {
|
|
53
|
+
const files = await glob("src/**/*.{ts,tsx}", { ignore: "node_modules/**" });
|
|
54
|
+
for (const file of files) {
|
|
55
|
+
const content = await readFile(file, "utf-8");
|
|
56
|
+
if (content.includes("rwsdk/auth")) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
export const ensureDeployEnv = async () => {
|
|
63
|
+
const shouldDeploy = await promptForDeployment();
|
|
64
|
+
if (!shouldDeploy) {
|
|
65
|
+
console.log("Deployment cancelled.");
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
console.log("Ensuring deployment environment is ready...");
|
|
69
|
+
const pkg = JSON.parse(await readFile(resolve(process.cwd(), "package.json"), "utf-8"));
|
|
70
|
+
// Read wrangler config
|
|
71
|
+
const wranglerPath = resolve(process.cwd(), "wrangler.jsonc");
|
|
72
|
+
const wranglerConfig = parseJsonc(await readFile(wranglerPath, "utf-8"));
|
|
73
|
+
// Update wrangler name if needed
|
|
74
|
+
if (wranglerConfig.name === "__change_me__" ||
|
|
75
|
+
process.env.RWSDK_RENAME_WORKER === "1") {
|
|
76
|
+
const dirName = basename(process.cwd());
|
|
77
|
+
wranglerConfig.name = dirName;
|
|
78
|
+
console.log(`Set wrangler name to ${dirName}`);
|
|
79
|
+
await writeFile(wranglerPath, JSON.stringify(wranglerConfig, null, 2));
|
|
80
|
+
console.log("Updated wrangler.jsonc configuration");
|
|
81
|
+
}
|
|
82
|
+
if (process.env.CLOUDFLARE_ACCOUNT_ID == null ||
|
|
83
|
+
process.env.CLOUDFLARE_API_TOKEN == null) {
|
|
84
|
+
// Trigger account selection prompt if needed
|
|
85
|
+
console.log("Checking Cloudflare account setup...");
|
|
86
|
+
const accountCachePath = join(process.cwd(), "node_modules/.cache/wrangler/wrangler-account.json");
|
|
87
|
+
// todo(justinvdm): this is a hack to force the account selection prompt,
|
|
88
|
+
// we need to find a better way
|
|
89
|
+
if (!(await pathExists(accountCachePath))) {
|
|
90
|
+
await $({ stdio: "inherit" }) `npx wrangler d1 list --json`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Create a no-op secret to ensure worker exists
|
|
94
|
+
console.log(`Ensuring worker ${wranglerConfig.name} exists...`);
|
|
95
|
+
await $({ stdio: "pipe" }) `echo "true"`
|
|
96
|
+
.pipe `npx wrangler secret put TMP_WORKER_CREATED`;
|
|
97
|
+
// Check D1 database setup
|
|
98
|
+
const needsDatabase = await hasD1Database();
|
|
99
|
+
if (!needsDatabase) {
|
|
100
|
+
console.log("Skipping D1 setup - no env.DB usage detected in codebase");
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
console.log("Found env.DB usage, checking D1 database setup...");
|
|
104
|
+
try {
|
|
105
|
+
const existingDb = wranglerConfig.d1_databases?.find((db) => db.binding === "DB");
|
|
106
|
+
if (existingDb &&
|
|
107
|
+
existingDb.database_id !== "__change_me__" &&
|
|
108
|
+
process.env.RWSDK_RENAME_DB !== "1") {
|
|
109
|
+
console.log("D1 database already configured in wrangler.jsonc, skipping creation");
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
const suffix = uniqueNamesGenerator({
|
|
113
|
+
dictionaries: [adjectives, animals],
|
|
114
|
+
separator: "-",
|
|
115
|
+
length: 2,
|
|
116
|
+
style: "lowerCase",
|
|
117
|
+
});
|
|
118
|
+
const dbName = `${wranglerConfig.name}-${suffix}`;
|
|
119
|
+
try {
|
|
120
|
+
// Create the database with real-time output so the user can see progress
|
|
121
|
+
console.log(`Creating D1 database: ${dbName}...`);
|
|
122
|
+
const createResult = await $({
|
|
123
|
+
stdio: "pipe",
|
|
124
|
+
}) `npx wrangler d1 create ${dbName}`;
|
|
125
|
+
// Log the result to the console
|
|
126
|
+
console.log(createResult.stdout);
|
|
127
|
+
// Parse all JSON objects from the output
|
|
128
|
+
const allJsonObjects = extractAllJson(createResult.stdout);
|
|
129
|
+
// First look for object with uuid directly
|
|
130
|
+
let dbInfo = { uuid: undefined, name: undefined };
|
|
131
|
+
for (const obj of allJsonObjects) {
|
|
132
|
+
if (obj && obj.uuid) {
|
|
133
|
+
dbInfo = obj;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// If not found, look for the d1_databases structure
|
|
138
|
+
if (!dbInfo.uuid) {
|
|
139
|
+
for (const obj of allJsonObjects) {
|
|
140
|
+
if (obj && obj.d1_databases && Array.isArray(obj.d1_databases)) {
|
|
141
|
+
const dbConfig = obj.d1_databases.find((db) => db.binding === "DB" || db.database_name === dbName);
|
|
142
|
+
if (dbConfig && dbConfig.database_id) {
|
|
143
|
+
dbInfo.uuid = dbConfig.database_id;
|
|
144
|
+
dbInfo.name = dbConfig.database_name || dbName;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (!dbInfo.uuid) {
|
|
151
|
+
throw new Error("Failed to extract database ID from wrangler output");
|
|
152
|
+
}
|
|
153
|
+
// Update wrangler config with database info, preserving other databases
|
|
154
|
+
const existingDatabases = wranglerConfig.d1_databases || [];
|
|
155
|
+
wranglerConfig.d1_databases = [
|
|
156
|
+
...existingDatabases.filter((db) => db.binding !== "DB"),
|
|
157
|
+
{
|
|
158
|
+
binding: "DB",
|
|
159
|
+
database_name: dbName,
|
|
160
|
+
database_id: dbInfo.uuid,
|
|
161
|
+
},
|
|
162
|
+
];
|
|
163
|
+
await writeFile(wranglerPath, JSON.stringify(wranglerConfig, null, 2));
|
|
164
|
+
console.log("Updated wrangler.jsonc configuration");
|
|
165
|
+
console.log(`D1 database configured: ${dbName} with ID: ${dbInfo.uuid}`);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
console.error("Failed to create D1 database:", error instanceof Error ? error.message : String(error));
|
|
169
|
+
console.error("Please create it manually:");
|
|
170
|
+
console.error("1. Run: npx wrangler d1 create <your-db-name>");
|
|
171
|
+
console.error("2. Update wrangler.jsonc with the database details");
|
|
172
|
+
process.exit(1);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.error("Failed to create D1 database. Please create it manually:");
|
|
178
|
+
console.error("1. Run: npx wrangler d1 create <your-db-name>");
|
|
179
|
+
console.error("2. Update wrangler.jsonc with the database details");
|
|
180
|
+
process.exit(1);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Check AUTH_SECRET_KEY setup
|
|
184
|
+
if (!(await hasAuthUsage())) {
|
|
185
|
+
console.log("Skipping AUTH_SECRET_KEY setup - no auth usage detected in codebase");
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
console.log("Found auth usage, checking secret setup...");
|
|
189
|
+
try {
|
|
190
|
+
// Get list of all secrets
|
|
191
|
+
const secretsResult = await $ `npx wrangler secret list --format=json`;
|
|
192
|
+
const existingSecrets = parseJson(secretsResult.stdout, []).map((secret) => secret.name);
|
|
193
|
+
// Check if AUTH_SECRET_KEY already exists
|
|
194
|
+
if (existingSecrets.includes("AUTH_SECRET_KEY")) {
|
|
195
|
+
console.log("AUTH_SECRET_KEY secret already exists in Cloudflare, skipping");
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
// Secret doesn't exist, create it
|
|
199
|
+
const secretKey = generateSecretKey();
|
|
200
|
+
// Use the same pattern as TMP_WORKER_CREATED for consistency
|
|
201
|
+
await $({ stdio: "pipe" }) `echo "${secretKey}"`
|
|
202
|
+
.pipe `npx wrangler secret put AUTH_SECRET_KEY`;
|
|
203
|
+
console.log("Set AUTH_SECRET_KEY secret");
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
console.error("Failed to set up AUTH_SECRET_KEY. Please configure it manually:");
|
|
208
|
+
console.error("1. Generate a secret key: node -e \"console.log(require('crypto').randomBytes(32).toString('base64'))\"");
|
|
209
|
+
console.error("2. Set the secret: npx wrangler secret put AUTH_SECRET_KEY");
|
|
210
|
+
process.exit(1);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Check WebAuthn setup
|
|
214
|
+
const needsWebAuthn = await hasWebAuthn();
|
|
215
|
+
if (!needsWebAuthn) {
|
|
216
|
+
console.log("Skipping WebAuthn setup - no WEBAUTHN usage detected in codebase");
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
console.log("Found WEBAUTHN usage, checking WebAuthn setup...");
|
|
220
|
+
try {
|
|
221
|
+
wranglerConfig.vars = wranglerConfig.vars || {};
|
|
222
|
+
if (wranglerConfig.vars.WEBAUTHN_APP_NAME === wranglerConfig.name) {
|
|
223
|
+
console.log(`WEBAUTHN_APP_NAME already set to "${wranglerConfig.name}" in wrangler.jsonc`);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
wranglerConfig.vars.WEBAUTHN_APP_NAME = wranglerConfig.name;
|
|
227
|
+
await writeFile(wranglerPath, JSON.stringify(wranglerConfig, null, 2));
|
|
228
|
+
console.log("Updated wrangler.jsonc configuration");
|
|
229
|
+
console.log(`Set WEBAUTHN_APP_NAME to ${wranglerConfig.name}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
catch (error) {
|
|
233
|
+
console.error("Failed to set up WebAuthn. Please configure it manually:");
|
|
234
|
+
console.error("Add to wrangler.jsonc vars:");
|
|
235
|
+
console.error(` "vars": { "WEBAUTHN_APP_NAME": "${wranglerConfig.name}" }`);
|
|
236
|
+
process.exit(1);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (pkg.scripts?.["migrate:prd"]) {
|
|
240
|
+
console.log("Checking migration status...");
|
|
241
|
+
try {
|
|
242
|
+
// Get the database name from wrangler config
|
|
243
|
+
const dbConfig = wranglerConfig.d1_databases?.find((db) => db.binding === "DB");
|
|
244
|
+
if (!dbConfig) {
|
|
245
|
+
throw new Error("No D1 database configuration found in wrangler.jsonc");
|
|
246
|
+
}
|
|
247
|
+
// Check remote migrations status
|
|
248
|
+
const migrationStatus = await $ `npx wrangler d1 migrations list ${dbConfig.database_name} --remote`;
|
|
249
|
+
// If stdout includes "No migrations found", this is a fresh database
|
|
250
|
+
if (migrationStatus.stdout?.includes("No migrations present")) {
|
|
251
|
+
console.log("No migrations found.");
|
|
252
|
+
}
|
|
253
|
+
else if (migrationStatus.stdout?.includes("Migrations to be applied")) {
|
|
254
|
+
await $({ stdio: "inherit" }) `npm run migrate:prd`;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
console.log("Migrations are up to date.");
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
console.error("\n❌ Error checking migration status:");
|
|
262
|
+
console.error(error);
|
|
263
|
+
process.exit(1);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
console.log("\nDeployment initialization complete!");
|
|
267
|
+
process.exit(0);
|
|
268
|
+
};
|
|
269
|
+
if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
|
|
270
|
+
ensureDeployEnv();
|
|
271
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ensureEnv: () => Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const migrateNew: (name: string, skipApply?: boolean) => Promise<void>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import snakeCase from "lodash/snakeCase.js";
|
|
2
|
+
import { $ } from "../lib/$.mjs";
|
|
3
|
+
import { readdir } from "fs/promises";
|
|
4
|
+
import { resolve } from "path";
|
|
5
|
+
import { mkdirp } from "fs-extra";
|
|
6
|
+
import { writeFile } from "fs/promises";
|
|
7
|
+
const getNextMigrationNumber = async () => {
|
|
8
|
+
await mkdirp(resolve(process.cwd(), "./migrations"));
|
|
9
|
+
const files = await readdir(resolve(process.cwd(), "./migrations"));
|
|
10
|
+
const numbers = files
|
|
11
|
+
.map((file) => parseInt(file.split("_")[0]))
|
|
12
|
+
.filter((num) => !isNaN(num));
|
|
13
|
+
const lastNumber = Math.max(0, ...numbers);
|
|
14
|
+
return String(lastNumber + 1).padStart(4, "0");
|
|
15
|
+
};
|
|
16
|
+
export const migrateNew = async (name, skipApply = false) => {
|
|
17
|
+
if (!name) {
|
|
18
|
+
console.log("Usage: npm run migrate:new <migration-name> [--no-apply]");
|
|
19
|
+
console.log("Example: npm run migrate:new add a user");
|
|
20
|
+
process.exit(1);
|
|
21
|
+
}
|
|
22
|
+
const nextNum = await getNextMigrationNumber();
|
|
23
|
+
const filepath = `./migrations/${nextNum}_${snakeCase(name.toLowerCase())}.sql`;
|
|
24
|
+
const raw = await $ `npx prisma migrate diff --from-local-d1 --to-schema-datamodel ./prisma/schema.prisma --script`;
|
|
25
|
+
const cleaned = raw.stdout
|
|
26
|
+
?.split("\n")
|
|
27
|
+
.filter((line) => !line.includes("_cf_METADATA") && !line.includes("_cf_metadata"))
|
|
28
|
+
.join("\n");
|
|
29
|
+
if (!cleaned) {
|
|
30
|
+
console.error("No changes to apply");
|
|
31
|
+
process.exitCode = 1;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await writeFile(filepath, cleaned);
|
|
35
|
+
console.log("Generated migration:", filepath);
|
|
36
|
+
if (!skipApply) {
|
|
37
|
+
console.log("Applying migration in development...");
|
|
38
|
+
await $ `npm run migrate:dev`;
|
|
39
|
+
console.log("Generating Prisma Client");
|
|
40
|
+
await $ `npx prisma generate`;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
|
|
44
|
+
const args = process.argv.slice(2);
|
|
45
|
+
// Separate flags from other arguments
|
|
46
|
+
const flags = new Set(args.filter((arg) => arg.startsWith("--")));
|
|
47
|
+
const nonFlags = args.filter((arg) => !arg.startsWith("--"));
|
|
48
|
+
const skipApply = flags.has("--no-apply");
|
|
49
|
+
const name = nonFlags.join("_").toLocaleLowerCase();
|
|
50
|
+
migrateNew(name, skipApply);
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { fileURLToPath } from "url";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import debug from "debug";
|
|
4
|
+
import { runSmokeTests } from "../lib/smokeTests/runSmokeTests.mjs";
|
|
5
|
+
import { isRunningInCI } from "../lib/smokeTests/utils.mjs";
|
|
6
|
+
// Set up debug logging
|
|
7
|
+
if (!process.env.DEBUG) {
|
|
8
|
+
debug.enable("rwsdk:smoke");
|
|
9
|
+
}
|
|
10
|
+
const log = debug("rwsdk:smoke");
|
|
11
|
+
// Run the smoke test if this file is executed directly
|
|
12
|
+
if (fileURLToPath(import.meta.url) === process.argv[1]) {
|
|
13
|
+
// Parse command line arguments
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
log("Command line arguments: %O", args);
|
|
16
|
+
// Check for CI flag first
|
|
17
|
+
const ciFlag = args.includes("--ci");
|
|
18
|
+
// Set initial default values (sync will be determined below)
|
|
19
|
+
const options = {
|
|
20
|
+
customPath: "/", // Default path
|
|
21
|
+
skipDev: false,
|
|
22
|
+
skipRelease: false,
|
|
23
|
+
skipClient: false,
|
|
24
|
+
projectDir: undefined,
|
|
25
|
+
artifactDir: join(process.cwd(), ".artifacts"), // Default to .artifacts in current directory
|
|
26
|
+
keep: isRunningInCI(ciFlag), // Default to true in CI environments
|
|
27
|
+
headless: true,
|
|
28
|
+
ci: ciFlag,
|
|
29
|
+
bail: false, // Default to false - continue tests even if some fail
|
|
30
|
+
copyProject: false, // Default to false - don't copy project to artifacts
|
|
31
|
+
realtime: false, // Default to false - don't just test realtime
|
|
32
|
+
skipHmr: false, // Default to false - run HMR tests
|
|
33
|
+
// sync: will be set below
|
|
34
|
+
};
|
|
35
|
+
// Log if we're in CI
|
|
36
|
+
if (isRunningInCI(ciFlag)) {
|
|
37
|
+
log("Running in CI environment, keeping test directory by default");
|
|
38
|
+
}
|
|
39
|
+
// Track if user explicitly set sync or no-sync
|
|
40
|
+
let syncExplicit = undefined;
|
|
41
|
+
// Process arguments in order
|
|
42
|
+
for (let i = 0; i < args.length; i++) {
|
|
43
|
+
const arg = args[i];
|
|
44
|
+
if (arg === "--skip-dev") {
|
|
45
|
+
options.skipDev = true;
|
|
46
|
+
}
|
|
47
|
+
else if (arg === "--skip-release") {
|
|
48
|
+
options.skipRelease = true;
|
|
49
|
+
}
|
|
50
|
+
else if (arg === "--skip-client") {
|
|
51
|
+
options.skipClient = true;
|
|
52
|
+
}
|
|
53
|
+
else if (arg === "--skip-hmr") {
|
|
54
|
+
options.skipHmr = true;
|
|
55
|
+
}
|
|
56
|
+
else if (arg === "--keep") {
|
|
57
|
+
options.keep = true;
|
|
58
|
+
}
|
|
59
|
+
else if (arg === "--no-headless") {
|
|
60
|
+
options.headless = false;
|
|
61
|
+
}
|
|
62
|
+
else if (arg === "--copy-project") {
|
|
63
|
+
options.copyProject = true;
|
|
64
|
+
}
|
|
65
|
+
else if (arg === "--no-sync") {
|
|
66
|
+
syncExplicit = false;
|
|
67
|
+
}
|
|
68
|
+
else if (arg === "--sync") {
|
|
69
|
+
syncExplicit = true;
|
|
70
|
+
}
|
|
71
|
+
else if (arg === "--ci") {
|
|
72
|
+
// Already handled above, just skip
|
|
73
|
+
}
|
|
74
|
+
else if (arg === "--bail") {
|
|
75
|
+
options.bail = true;
|
|
76
|
+
}
|
|
77
|
+
else if (arg === "--realtime") {
|
|
78
|
+
options.realtime = true;
|
|
79
|
+
}
|
|
80
|
+
else if (arg === "--help" || arg === "-h") {
|
|
81
|
+
// Display help text
|
|
82
|
+
console.log(`
|
|
83
|
+
Smoke Test Usage:
|
|
84
|
+
node smoke-test.mjs [options]
|
|
85
|
+
|
|
86
|
+
Options:
|
|
87
|
+
--url=PATH Custom URL path to test (e.g., "/login")
|
|
88
|
+
--skip-dev Skip testing the local development server
|
|
89
|
+
--skip-release Skip testing the release/production deployment
|
|
90
|
+
--skip-client Skip client-side tests, only run server-side checks
|
|
91
|
+
--skip-hmr Skip hot module replacement (HMR) tests
|
|
92
|
+
--path=PATH Project directory to test
|
|
93
|
+
--artifact-dir=DIR Directory to store test artifacts (default: .artifacts)
|
|
94
|
+
--keep Keep temporary test directory after tests complete
|
|
95
|
+
--no-headless Run browser tests with GUI (not headless)
|
|
96
|
+
--sync Force syncing SDK code to test project
|
|
97
|
+
--no-sync Disable syncing SDK code to test project
|
|
98
|
+
--ci Run in CI mode (keeps temp dirs, sets headless)
|
|
99
|
+
--bail Stop on first test failure
|
|
100
|
+
--copy-project Copy the project to the artifacts directory
|
|
101
|
+
--realtime Only run realtime smoke tests, skip initial tests
|
|
102
|
+
--help Show this help message
|
|
103
|
+
`);
|
|
104
|
+
process.exit(0);
|
|
105
|
+
}
|
|
106
|
+
else if (arg.startsWith("--path=")) {
|
|
107
|
+
options.projectDir = arg.substring(7);
|
|
108
|
+
}
|
|
109
|
+
else if (arg.startsWith("--artifact-dir=")) {
|
|
110
|
+
options.artifactDir = arg.substring(15);
|
|
111
|
+
}
|
|
112
|
+
else if (arg.startsWith("--url=")) {
|
|
113
|
+
options.customPath = arg.substring(6);
|
|
114
|
+
}
|
|
115
|
+
else if (!arg.startsWith("--")) {
|
|
116
|
+
// For backwards compatibility, any non-flag argument is treated as the custom path
|
|
117
|
+
console.log(`Setting URL path to "${arg}" (use --url= format in the future)`);
|
|
118
|
+
options.customPath = arg;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
// Throw error for unknown options instead of just warning
|
|
122
|
+
log("Unknown option: %s", arg);
|
|
123
|
+
throw new Error(`Unknown option: ${arg}. Use --help to see available options.`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Async IIFE to determine sync default and run main
|
|
127
|
+
(async () => {
|
|
128
|
+
if (syncExplicit !== undefined) {
|
|
129
|
+
options.sync = syncExplicit;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
// Determine default for sync: true if cwd has package.json with name 'rwsdk', otherwise false
|
|
133
|
+
let syncDefault = false;
|
|
134
|
+
const pkgPath = join(process.cwd(), "package.json");
|
|
135
|
+
log(`[sync default] Checking for package.json at: %s`, pkgPath);
|
|
136
|
+
try {
|
|
137
|
+
const pkgRaw = await import("fs/promises").then((fs) => fs.readFile(pkgPath, "utf8"));
|
|
138
|
+
log(`[sync default] Read package.json: %s`, pkgRaw);
|
|
139
|
+
const pkg = JSON.parse(pkgRaw);
|
|
140
|
+
if (pkg && pkg.name === "rwsdk") {
|
|
141
|
+
log(`[sync default] package.json name is 'rwsdk', setting syncDefault = true`);
|
|
142
|
+
syncDefault = true;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
log(`[sync default] package.json name is not 'rwsdk', setting syncDefault = false`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
log(`[sync default] Could not read package.json or parse name: %O`, e);
|
|
150
|
+
log(`[sync default] Defaulting syncDefault = false`);
|
|
151
|
+
}
|
|
152
|
+
log(`[sync default] Final syncDefault value: %s`, syncDefault);
|
|
153
|
+
options.sync = syncDefault;
|
|
154
|
+
}
|
|
155
|
+
log("Parsed options: %O", options);
|
|
156
|
+
// Run the smoke tests with the parsed options
|
|
157
|
+
try {
|
|
158
|
+
await runSmokeTests(options);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
log("Error running smoke tests: %O", error);
|
|
162
|
+
console.error(`Error running smoke tests: ${error instanceof Error ? error.message : String(error)}`);
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
})();
|
|
166
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const runWorkerScript: (relativeScriptPath: string) => Promise<never>;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { resolve } from "path";
|
|
2
|
+
import { writeFile } from "fs/promises";
|
|
3
|
+
import { unstable_readConfig } from "wrangler";
|
|
4
|
+
import { createServer as createViteServer } from "vite";
|
|
5
|
+
import tmp from "tmp-promise";
|
|
6
|
+
import baseDebug from "debug";
|
|
7
|
+
import { redwood } from "../vite/index.mjs";
|
|
8
|
+
import { findWranglerConfig } from "../lib/findWranglerConfig.mjs";
|
|
9
|
+
const debug = baseDebug("rwsdk:worker-run");
|
|
10
|
+
export const runWorkerScript = async (relativeScriptPath) => {
|
|
11
|
+
if (!relativeScriptPath) {
|
|
12
|
+
console.error("Error: Script path is required");
|
|
13
|
+
console.log("\nUsage:");
|
|
14
|
+
console.log(" npm run worker:run <script-path>");
|
|
15
|
+
console.log("\nExample:");
|
|
16
|
+
console.log(" npm run worker:run src/scripts/seed.ts\n");
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
const scriptPath = resolve(process.cwd(), relativeScriptPath);
|
|
20
|
+
debug("Running worker script: %s", scriptPath);
|
|
21
|
+
const workerConfigPath = await findWranglerConfig(process.cwd());
|
|
22
|
+
debug("Using wrangler config: %s", workerConfigPath);
|
|
23
|
+
const workerConfig = unstable_readConfig({
|
|
24
|
+
config: workerConfigPath,
|
|
25
|
+
});
|
|
26
|
+
const tmpWorkerPath = await tmp.file({
|
|
27
|
+
postfix: ".json",
|
|
28
|
+
});
|
|
29
|
+
const scriptWorkerConfig = {
|
|
30
|
+
...workerConfig,
|
|
31
|
+
configPath: tmpWorkerPath.path,
|
|
32
|
+
userConfigPath: tmpWorkerPath.path,
|
|
33
|
+
main: scriptPath,
|
|
34
|
+
};
|
|
35
|
+
try {
|
|
36
|
+
await writeFile(tmpWorkerPath.path, JSON.stringify(scriptWorkerConfig, null, 2));
|
|
37
|
+
debug("Worker config written to: %s", tmpWorkerPath.path);
|
|
38
|
+
process.env.RWSDK_WORKER_RUN = "1";
|
|
39
|
+
const server = await createViteServer({
|
|
40
|
+
configFile: false,
|
|
41
|
+
plugins: [
|
|
42
|
+
redwood({
|
|
43
|
+
configPath: tmpWorkerPath.path,
|
|
44
|
+
includeCloudflarePlugin: true,
|
|
45
|
+
entry: {
|
|
46
|
+
worker: scriptPath,
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
],
|
|
50
|
+
server: {
|
|
51
|
+
port: 0,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
debug("Vite server created");
|
|
55
|
+
try {
|
|
56
|
+
await server.listen();
|
|
57
|
+
const address = server.httpServer?.address();
|
|
58
|
+
debug("Server listening on address: %o", address);
|
|
59
|
+
if (!address || typeof address === "string") {
|
|
60
|
+
throw new Error("Dev server address is invalid");
|
|
61
|
+
}
|
|
62
|
+
debug("Fetching worker...");
|
|
63
|
+
await fetch(`http://localhost:${address.port}/`);
|
|
64
|
+
debug("Worker fetched successfully");
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
debug("Closing server...");
|
|
68
|
+
await server.close();
|
|
69
|
+
debug("Server closed");
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
debug("Closing inspector servers...");
|
|
74
|
+
await tmpWorkerPath.cleanup();
|
|
75
|
+
debug("Temporary files cleaned up");
|
|
76
|
+
}
|
|
77
|
+
// todo(justinvdm, 01 Apr 2025): Investigate what handles are remaining open
|
|
78
|
+
process.exit(0);
|
|
79
|
+
};
|
|
80
|
+
if (import.meta.url === new URL(process.argv[1], import.meta.url).href) {
|
|
81
|
+
runWorkerScript(process.argv[2]);
|
|
82
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import enhancedResolve from "enhanced-resolve";
|
|
2
|
+
const isUsingPrisma = ({ projectRootDir }) => {
|
|
3
|
+
try {
|
|
4
|
+
const prismaClientPath = enhancedResolve.sync(projectRootDir, "@prisma/client");
|
|
5
|
+
if (!prismaClientPath) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export const checkPrismaStatus = ({ projectRootDir, }) => {
|
|
15
|
+
return {
|
|
16
|
+
isUsingPrisma: isUsingPrisma({ projectRootDir }),
|
|
17
|
+
};
|
|
18
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
export declare const cloudflareBuiltInModules: string[];
|
|
3
|
+
export declare const externalModules: string[];
|
|
4
|
+
export declare const configPlugin: ({ silent, projectRootDir, clientEntryPathnames, workerEntryPathname, }: {
|
|
5
|
+
silent: boolean;
|
|
6
|
+
projectRootDir: string;
|
|
7
|
+
clientEntryPathnames: string[];
|
|
8
|
+
workerEntryPathname: string;
|
|
9
|
+
}) => Plugin;
|