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,209 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import colors from "picocolors";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import debug from "debug";
|
|
5
|
+
import { VIRTUAL_SSR_PREFIX } from "./ssrBridgePlugin.mjs";
|
|
6
|
+
import { normalizeModulePath } from "./normalizeModulePath.mjs";
|
|
7
|
+
import { hasDirective as sourceHasDirective } from "./hasDirective.mjs";
|
|
8
|
+
import { isJsFile } from "./isJsFile.mjs";
|
|
9
|
+
import { invalidateModule } from "./invalidateModule.mjs";
|
|
10
|
+
import { getShortName } from "../lib/getShortName.mjs";
|
|
11
|
+
const log = debug("rwsdk:vite:hmr-plugin");
|
|
12
|
+
const hasDirective = async (filepath, directive) => {
|
|
13
|
+
if (!isJsFile(filepath)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const content = await readFile(filepath, "utf-8");
|
|
17
|
+
return sourceHasDirective(content, directive);
|
|
18
|
+
};
|
|
19
|
+
const hasEntryAsAncestor = (module, entryFile, seen = new Set()) => {
|
|
20
|
+
// Prevent infinite recursion
|
|
21
|
+
if (seen.has(module)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
seen.add(module);
|
|
25
|
+
// Check direct importers
|
|
26
|
+
for (const importer of module.importers) {
|
|
27
|
+
if (importer.file === entryFile)
|
|
28
|
+
return true;
|
|
29
|
+
// Recursively check importers
|
|
30
|
+
if (hasEntryAsAncestor(importer, entryFile, seen))
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
35
|
+
const isInUseClientGraph = ({ file, clientFiles, server, }) => {
|
|
36
|
+
const id = normalizeModulePath(server.config.root, file);
|
|
37
|
+
if (clientFiles.has(id)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
const modules = server.environments.client.moduleGraph.getModulesByFile(file);
|
|
41
|
+
if (!modules) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
for (const m of modules) {
|
|
45
|
+
for (const importer of m.importers) {
|
|
46
|
+
if (importer.file &&
|
|
47
|
+
isInUseClientGraph({ file: importer.file, clientFiles, server })) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
};
|
|
54
|
+
export const miniflareHMRPlugin = (givenOptions) => [
|
|
55
|
+
{
|
|
56
|
+
name: "rwsdk:miniflare-hmr",
|
|
57
|
+
async hotUpdate(ctx) {
|
|
58
|
+
const { clientFiles, serverFiles, viteEnvironment: { name: environment }, workerEntryPathname: entry, } = givenOptions;
|
|
59
|
+
if (process.env.VERBOSE) {
|
|
60
|
+
log(`Hot update: (env=${this.environment.name}) ${ctx.file}\nModule graph:\n\n${dumpFullModuleGraph(ctx.server, this.environment.name)}`);
|
|
61
|
+
}
|
|
62
|
+
if (!isJsFile(ctx.file) && !ctx.file.endsWith(".css")) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (this.environment.name === "ssr") {
|
|
66
|
+
log("SSR update, invalidating recursively", ctx.file);
|
|
67
|
+
const isUseClientUpdate = isInUseClientGraph({
|
|
68
|
+
file: ctx.file,
|
|
69
|
+
clientFiles,
|
|
70
|
+
server: ctx.server,
|
|
71
|
+
});
|
|
72
|
+
if (!isUseClientUpdate) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
invalidateModule(ctx.server, "ssr", ctx.file);
|
|
76
|
+
invalidateModule(ctx.server, environment, VIRTUAL_SSR_PREFIX +
|
|
77
|
+
normalizeModulePath(givenOptions.rootDir, ctx.file));
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
if (!["client", environment].includes(this.environment.name)) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
const hasClientDirective = await hasDirective(ctx.file, "use client");
|
|
84
|
+
const hasServerDirective = !hasClientDirective && (await hasDirective(ctx.file, "use server"));
|
|
85
|
+
let clientDirectiveChanged = false;
|
|
86
|
+
let serverDirectiveChanged = false;
|
|
87
|
+
if (!clientFiles.has(ctx.file) && hasClientDirective) {
|
|
88
|
+
clientFiles.add(ctx.file);
|
|
89
|
+
clientDirectiveChanged = true;
|
|
90
|
+
}
|
|
91
|
+
else if (clientFiles.has(ctx.file) && !hasClientDirective) {
|
|
92
|
+
clientFiles.delete(ctx.file);
|
|
93
|
+
clientDirectiveChanged = true;
|
|
94
|
+
}
|
|
95
|
+
if (!serverFiles.has(ctx.file) && hasServerDirective) {
|
|
96
|
+
serverFiles.add(ctx.file);
|
|
97
|
+
serverDirectiveChanged = true;
|
|
98
|
+
}
|
|
99
|
+
else if (serverFiles.has(ctx.file) && !hasServerDirective) {
|
|
100
|
+
serverFiles.delete(ctx.file);
|
|
101
|
+
serverDirectiveChanged = true;
|
|
102
|
+
}
|
|
103
|
+
if (clientDirectiveChanged) {
|
|
104
|
+
["client", "ssr", environment].forEach((environment) => {
|
|
105
|
+
invalidateModule(ctx.server, environment, "virtual:use-client-lookup.js");
|
|
106
|
+
});
|
|
107
|
+
invalidateModule(ctx.server, environment, VIRTUAL_SSR_PREFIX + "/@id/virtual:use-client-lookup.js");
|
|
108
|
+
}
|
|
109
|
+
if (serverDirectiveChanged) {
|
|
110
|
+
["client", "ssr", environment].forEach((environment) => {
|
|
111
|
+
invalidateModule(ctx.server, environment, "virtual:use-server-lookup.js");
|
|
112
|
+
});
|
|
113
|
+
invalidateModule(ctx.server, environment, VIRTUAL_SSR_PREFIX + "/@id/virtual:use-server-lookup.js");
|
|
114
|
+
}
|
|
115
|
+
// todo(justinvdm, 12 Dec 2024): Skip client references
|
|
116
|
+
const modules = Array.from(ctx.server.environments[environment].moduleGraph.getModulesByFile(ctx.file) ?? []);
|
|
117
|
+
const isWorkerUpdate = Boolean(modules);
|
|
118
|
+
// The worker needs an update, but this is the client environment
|
|
119
|
+
// => Notify for HMR update of any css files imported by in worker, that are also in the client module graph
|
|
120
|
+
// Why: There may have been changes to css classes referenced, which might css modules to change
|
|
121
|
+
if (this.environment.name === "client") {
|
|
122
|
+
if (isWorkerUpdate) {
|
|
123
|
+
for (const [_, module] of ctx.server.environments[environment]
|
|
124
|
+
.moduleGraph.idToModuleMap) {
|
|
125
|
+
// todo(justinvdm, 13 Dec 2024): We check+update _all_ css files in worker module graph,
|
|
126
|
+
// but it could just be a subset of css files that are actually affected, depending
|
|
127
|
+
// on the importers and imports of the changed file. We should be smarter about this.
|
|
128
|
+
if (module.file && module.file.endsWith(".css")) {
|
|
129
|
+
const clientModules = ctx.server.environments.client.moduleGraph.getModulesByFile(module.file);
|
|
130
|
+
for (const clientModule of clientModules ?? []) {
|
|
131
|
+
invalidateModule(ctx.server, "client", clientModule);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const isUseClientUpdate = isInUseClientGraph({
|
|
137
|
+
file: ctx.file,
|
|
138
|
+
clientFiles,
|
|
139
|
+
server: ctx.server,
|
|
140
|
+
});
|
|
141
|
+
if (!isUseClientUpdate && !ctx.file.endsWith(".css")) {
|
|
142
|
+
return [];
|
|
143
|
+
}
|
|
144
|
+
return ctx.modules;
|
|
145
|
+
}
|
|
146
|
+
// The worker needs an update, and the hot check is for the worker environment
|
|
147
|
+
// => Notify for custom RSC-based HMR update, then short circuit HMR
|
|
148
|
+
if (isWorkerUpdate && this.environment.name === environment) {
|
|
149
|
+
const shortName = getShortName(ctx.file, ctx.server.config.root);
|
|
150
|
+
this.environment.logger.info(`${colors.green(`worker update`)} ${colors.dim(shortName)}`, {
|
|
151
|
+
clear: true,
|
|
152
|
+
timestamp: true,
|
|
153
|
+
});
|
|
154
|
+
const m = ctx.server.environments.client.moduleGraph
|
|
155
|
+
.getModulesByFile(resolve(givenOptions.rootDir, "src", "app", "style.css"))
|
|
156
|
+
?.values()
|
|
157
|
+
.next().value;
|
|
158
|
+
if (m) {
|
|
159
|
+
invalidateModule(ctx.server, environment, m);
|
|
160
|
+
}
|
|
161
|
+
const virtualSSRModule = ctx.server.environments[environment].moduleGraph.idToModuleMap.get(VIRTUAL_SSR_PREFIX +
|
|
162
|
+
normalizeModulePath(givenOptions.rootDir, ctx.file));
|
|
163
|
+
if (virtualSSRModule) {
|
|
164
|
+
invalidateModule(ctx.server, environment, virtualSSRModule);
|
|
165
|
+
}
|
|
166
|
+
ctx.server.environments.client.hot.send({
|
|
167
|
+
type: "custom",
|
|
168
|
+
event: "rsc:update",
|
|
169
|
+
data: {
|
|
170
|
+
file: ctx.file,
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
return [];
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
];
|
|
178
|
+
function dumpFullModuleGraph(server, environment, { includeDisconnected = true } = {}) {
|
|
179
|
+
const moduleGraph = server.environments[environment].moduleGraph;
|
|
180
|
+
const seen = new Set();
|
|
181
|
+
const output = [];
|
|
182
|
+
function walk(node, depth = 0) {
|
|
183
|
+
const id = node.id || node.url;
|
|
184
|
+
if (!id || seen.has(id))
|
|
185
|
+
return;
|
|
186
|
+
seen.add(id);
|
|
187
|
+
const pad = " ".repeat(depth);
|
|
188
|
+
const suffix = node.id?.startsWith("virtual:") ? " [virtual]" : "";
|
|
189
|
+
output.push(`${pad}- ${id}${suffix}`);
|
|
190
|
+
for (const dep of node.importedModules) {
|
|
191
|
+
walk(dep, depth + 1);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Start with all modules with no importers (roots)
|
|
195
|
+
const roots = Array.from(moduleGraph.urlToModuleMap.values()).filter((mod) => mod.importers.size === 0);
|
|
196
|
+
for (const root of roots) {
|
|
197
|
+
walk(root);
|
|
198
|
+
}
|
|
199
|
+
// If requested, show disconnected modules too
|
|
200
|
+
if (includeDisconnected) {
|
|
201
|
+
for (const mod of moduleGraph.urlToModuleMap.values()) {
|
|
202
|
+
const id = mod.id || mod.url;
|
|
203
|
+
if (!seen.has(id)) {
|
|
204
|
+
output.push(`- ${id} [disconnected]`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return output.join("\n");
|
|
209
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { $sh } from "../lib/$.mjs";
|
|
2
|
+
export const moveStaticAssetsPlugin = ({ rootDir, }) => ({
|
|
3
|
+
name: "rwsdk:move-static-assets",
|
|
4
|
+
apply: "build",
|
|
5
|
+
async closeBundle() {
|
|
6
|
+
if (this.environment.name === "worker") {
|
|
7
|
+
await $sh({
|
|
8
|
+
cwd: rootDir,
|
|
9
|
+
}) `mv dist/worker/assets/*.css dist/client/assets/ || true`;
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const normalizeModulePath: (projectRootDir: string, modulePath: string) => string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
export const normalizeModulePath = (projectRootDir, modulePath) => {
|
|
3
|
+
// /Users/path/to/project/src/foo/bar.ts -> /src/foo/bar.ts
|
|
4
|
+
if (modulePath.startsWith(projectRootDir)) {
|
|
5
|
+
return "/" + path.relative(projectRootDir, modulePath);
|
|
6
|
+
}
|
|
7
|
+
// /src/foo/bar.ts -> /src/foo/bar.ts
|
|
8
|
+
if (modulePath.startsWith("/")) {
|
|
9
|
+
return modulePath;
|
|
10
|
+
}
|
|
11
|
+
// src/foo/bar.ts -> /src/foo/bar.ts
|
|
12
|
+
return "/" + modulePath;
|
|
13
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { invalidateCacheIfPrismaClientChanged } from "./invalidateCacheIfPrismaClientChanged.mjs";
|
|
3
|
+
import { checkPrismaStatus } from "./checkIsUsingPrisma.mjs";
|
|
4
|
+
import { ensureAliasArray } from "./ensureAliasArray.mjs";
|
|
5
|
+
export const prismaPlugin = async ({ projectRootDir, }) => {
|
|
6
|
+
if (!checkPrismaStatus({ projectRootDir }).isUsingPrisma) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
// context(justinvdm, 10 Mar 2025): We need to use vite optimizeDeps for all deps to work with @cloudflare/vite-plugin.
|
|
10
|
+
// Thing is, @prisma/client has generated code. So users end up with a stale @prisma/client
|
|
11
|
+
// when they change their prisma schema and regenerate the client, until clearing out node_modules/.vite
|
|
12
|
+
// We can't exclude @prisma/client from optimizeDeps since we need it there for @cloudflare/vite-plugin to work.
|
|
13
|
+
// But we can manually invalidate the cache if the prisma schema changes.
|
|
14
|
+
await invalidateCacheIfPrismaClientChanged({
|
|
15
|
+
projectRootDir,
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
name: "rwsdk:prisma",
|
|
19
|
+
configEnvironment(name, config) {
|
|
20
|
+
if (name !== "worker") {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const wasmPath = resolve(projectRootDir, "node_modules/.prisma/client/wasm.js");
|
|
24
|
+
config.optimizeDeps ??= {};
|
|
25
|
+
config.optimizeDeps.esbuildOptions ??= {};
|
|
26
|
+
config.optimizeDeps.esbuildOptions.plugins ??= [];
|
|
27
|
+
config.optimizeDeps.esbuildOptions.plugins.push({
|
|
28
|
+
name: "rwsdk:prisma",
|
|
29
|
+
setup(build) {
|
|
30
|
+
build.onResolve({ filter: /^.prisma\/client\/default/ }, async () => {
|
|
31
|
+
return {
|
|
32
|
+
path: wasmPath,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
ensureAliasArray(config).push({
|
|
38
|
+
find: /^\.prisma\/client\/default/,
|
|
39
|
+
replacement: wasmPath,
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
import enhancedResolve from "enhanced-resolve";
|
|
3
|
+
export declare const ENV_REACT_IMPORTS: {
|
|
4
|
+
worker: string[];
|
|
5
|
+
ssr: string[];
|
|
6
|
+
client: string[];
|
|
7
|
+
};
|
|
8
|
+
export declare const ENV_RESOLVERS: {
|
|
9
|
+
ssr: enhancedResolve.ResolveFunction;
|
|
10
|
+
worker: enhancedResolve.ResolveFunction;
|
|
11
|
+
client: enhancedResolve.ResolveFunction;
|
|
12
|
+
};
|
|
13
|
+
export declare const ENV_IMPORT_MAPPINGS: {
|
|
14
|
+
[k: string]: Map<string, string>;
|
|
15
|
+
};
|
|
16
|
+
export declare const reactConditionsResolverPlugin: () => Plugin[];
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import debug from "debug";
|
|
2
|
+
import { ROOT_DIR } from "../lib/constants.mjs";
|
|
3
|
+
import enhancedResolve from "enhanced-resolve";
|
|
4
|
+
import { ensureAliasArray } from "./ensureAliasArray.mjs";
|
|
5
|
+
const log = debug("rwsdk:vite:react-conditions-resolver-plugin");
|
|
6
|
+
export const ENV_REACT_IMPORTS = {
|
|
7
|
+
worker: [
|
|
8
|
+
"react",
|
|
9
|
+
"react-dom",
|
|
10
|
+
"react/jsx-runtime",
|
|
11
|
+
"react/jsx-dev-runtime",
|
|
12
|
+
"react-server-dom-webpack/server.edge",
|
|
13
|
+
],
|
|
14
|
+
ssr: [
|
|
15
|
+
"react",
|
|
16
|
+
"react-dom",
|
|
17
|
+
"react/jsx-runtime",
|
|
18
|
+
"react/jsx-dev-runtime",
|
|
19
|
+
"react-dom/server.edge",
|
|
20
|
+
"react-dom/server",
|
|
21
|
+
"react-server-dom-webpack/client.edge",
|
|
22
|
+
],
|
|
23
|
+
client: [
|
|
24
|
+
"react",
|
|
25
|
+
"react-dom",
|
|
26
|
+
"react-dom/client",
|
|
27
|
+
"react/jsx-runtime",
|
|
28
|
+
"react/jsx-dev-runtime",
|
|
29
|
+
"react-server-dom-webpack/client.browser",
|
|
30
|
+
"react-server-dom-webpack/client.edge",
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
export const ENV_RESOLVERS = {
|
|
34
|
+
ssr: enhancedResolve.create.sync({
|
|
35
|
+
conditionNames: ["workerd", "worker", "edge", "default"],
|
|
36
|
+
}),
|
|
37
|
+
worker: enhancedResolve.create.sync({
|
|
38
|
+
conditionNames: ["react-server", "workerd", "worker", "edge", "default"],
|
|
39
|
+
}),
|
|
40
|
+
client: enhancedResolve.create.sync({
|
|
41
|
+
conditionNames: ["browser", "default"],
|
|
42
|
+
}),
|
|
43
|
+
};
|
|
44
|
+
export const ENV_IMPORT_MAPPINGS = Object.fromEntries(Object.keys(ENV_RESOLVERS).map((env) => [
|
|
45
|
+
env,
|
|
46
|
+
resolveEnvImportMappings(env),
|
|
47
|
+
]));
|
|
48
|
+
function resolveEnvImportMappings(env) {
|
|
49
|
+
process.env.VERBOSE &&
|
|
50
|
+
log("Resolving environment import mappings for env=%s", env);
|
|
51
|
+
const mappings = new Map();
|
|
52
|
+
const reactImports = ENV_REACT_IMPORTS[env];
|
|
53
|
+
for (const importRequest of reactImports) {
|
|
54
|
+
process.env.VERBOSE &&
|
|
55
|
+
log("Resolving import request=%s for env=%s", importRequest, env);
|
|
56
|
+
let resolved = false;
|
|
57
|
+
try {
|
|
58
|
+
resolved = ENV_RESOLVERS[env](ROOT_DIR, importRequest);
|
|
59
|
+
process.env.VERBOSE &&
|
|
60
|
+
log("Successfully resolved %s to %s for env=%s", importRequest, resolved, env);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
process.env.VERBOSE &&
|
|
64
|
+
log("Failed to resolve %s for env=%s", importRequest, env);
|
|
65
|
+
}
|
|
66
|
+
if (resolved) {
|
|
67
|
+
mappings.set(importRequest, resolved);
|
|
68
|
+
log("Added mapping for %s -> %s in env=%s", importRequest, resolved, env);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
log("Environment import mappings complete for env=%s: %d mappings", env, mappings.size);
|
|
72
|
+
return mappings;
|
|
73
|
+
}
|
|
74
|
+
function createEsbuildResolverPlugin(envName) {
|
|
75
|
+
const mappings = ENV_IMPORT_MAPPINGS[envName];
|
|
76
|
+
if (!mappings) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
name: `rwsdk:react-conditions-resolver-esbuild-${envName}`,
|
|
81
|
+
setup(build) {
|
|
82
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
83
|
+
process.env.VERBOSE &&
|
|
84
|
+
log("ESBuild resolving %s for env=%s, args=%O", args.path, envName, args);
|
|
85
|
+
const resolved = mappings.get(args.path);
|
|
86
|
+
if (resolved && args.importer !== "") {
|
|
87
|
+
process.env.VERBOSE &&
|
|
88
|
+
log("ESBuild resolving %s -> %s for env=%s", args.path, resolved, envName);
|
|
89
|
+
if (args.path === "react-server-dom-webpack/client.edge") {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
path: resolved,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
process.env.VERBOSE &&
|
|
98
|
+
log("ESBuild no resolution found for %s for env=%s", args.path, envName);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export const reactConditionsResolverPlugin = () => {
|
|
105
|
+
log("Initializing react conditions resolver plugin");
|
|
106
|
+
let isBuild = false;
|
|
107
|
+
return [
|
|
108
|
+
{
|
|
109
|
+
name: "rwsdk:react-conditions-resolver:config",
|
|
110
|
+
enforce: "post",
|
|
111
|
+
config(config, { command }) {
|
|
112
|
+
isBuild = command === "build";
|
|
113
|
+
log("Configuring plugin for command=%s", command);
|
|
114
|
+
},
|
|
115
|
+
configResolved(config) {
|
|
116
|
+
log("Setting up resolve aliases and optimizeDeps for each environment");
|
|
117
|
+
// Set up aliases and optimizeDeps for each environment
|
|
118
|
+
for (const [envName, mappings] of Object.entries(ENV_IMPORT_MAPPINGS)) {
|
|
119
|
+
const reactImports = ENV_REACT_IMPORTS[envName];
|
|
120
|
+
// Ensure environment config exists
|
|
121
|
+
if (!config.environments) {
|
|
122
|
+
config.environments = {};
|
|
123
|
+
}
|
|
124
|
+
if (!config.environments[envName]) {
|
|
125
|
+
config.environments[envName] = {};
|
|
126
|
+
}
|
|
127
|
+
const envConfig = config.environments[envName];
|
|
128
|
+
const esbuildPlugin = createEsbuildResolverPlugin(envName);
|
|
129
|
+
if (esbuildPlugin && mappings) {
|
|
130
|
+
envConfig.optimizeDeps ??= {};
|
|
131
|
+
envConfig.optimizeDeps.esbuildOptions ??= {};
|
|
132
|
+
envConfig.optimizeDeps.esbuildOptions.define ??= {};
|
|
133
|
+
envConfig.optimizeDeps.esbuildOptions.define["process.env.NODE_ENV"] = JSON.stringify(process.env.NODE_ENV);
|
|
134
|
+
envConfig.optimizeDeps.esbuildOptions.plugins ??= [];
|
|
135
|
+
envConfig.optimizeDeps.esbuildOptions.plugins.push(esbuildPlugin);
|
|
136
|
+
envConfig.optimizeDeps.include ??= [];
|
|
137
|
+
envConfig.optimizeDeps.include.push(...reactImports);
|
|
138
|
+
log("Added esbuild plugin and optimizeDeps includes for environment: %s", envName);
|
|
139
|
+
}
|
|
140
|
+
const aliases = ensureAliasArray(envConfig);
|
|
141
|
+
for (const [find, replacement] of mappings) {
|
|
142
|
+
const findRegex = new RegExp(`^${find.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&")}$`);
|
|
143
|
+
aliases.push({ find: findRegex, replacement });
|
|
144
|
+
log("Added alias for env=%s: %s -> %s", envName, find, replacement);
|
|
145
|
+
}
|
|
146
|
+
log("Environment %s configured with %d aliases and %d optimizeDeps includes", envName, mappings.size, reactImports.length);
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: "rwsdk:react-conditions-resolver:resolveId",
|
|
152
|
+
enforce: "pre",
|
|
153
|
+
async resolveId(id, importer) {
|
|
154
|
+
if (!isBuild) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const envName = this.environment?.name;
|
|
158
|
+
if (!envName) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
process.env.VERBOSE &&
|
|
162
|
+
log("Resolving id=%s, environment=%s, importer=%s", id, envName, importer);
|
|
163
|
+
const mappings = ENV_IMPORT_MAPPINGS[envName];
|
|
164
|
+
if (!mappings) {
|
|
165
|
+
process.env.VERBOSE &&
|
|
166
|
+
log("No mappings found for environment: %s", envName);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const resolved = mappings.get(id);
|
|
170
|
+
if (resolved) {
|
|
171
|
+
log("Resolved %s -> %s for env=%s", id, resolved, envName);
|
|
172
|
+
return resolved;
|
|
173
|
+
}
|
|
174
|
+
process.env.VERBOSE &&
|
|
175
|
+
log("No resolution found for id=%s in env=%s", id, envName);
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
];
|
|
179
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InlineConfig } from "vite";
|
|
2
|
+
export type RedwoodPluginOptions = {
|
|
3
|
+
silent?: boolean;
|
|
4
|
+
rootDir?: string;
|
|
5
|
+
includeCloudflarePlugin?: boolean;
|
|
6
|
+
configPath?: string;
|
|
7
|
+
entry?: {
|
|
8
|
+
client?: string | string[];
|
|
9
|
+
worker?: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare const redwoodPlugin: (options?: RedwoodPluginOptions) => Promise<InlineConfig["plugins"]>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { unstable_readConfig } from "wrangler";
|
|
3
|
+
import { cloudflare } from "@cloudflare/vite-plugin";
|
|
4
|
+
import { hasOwnCloudflareVitePlugin } from "./hasOwnCloudflareVitePlugin.mjs";
|
|
5
|
+
import reactPlugin from "@vitejs/plugin-react";
|
|
6
|
+
import tsconfigPaths from "vite-tsconfig-paths";
|
|
7
|
+
import { transformJsxScriptTagsPlugin } from "./transformJsxScriptTagsPlugin.mjs";
|
|
8
|
+
import { directivesPlugin } from "./directivesPlugin.mjs";
|
|
9
|
+
import { useClientLookupPlugin } from "./useClientLookupPlugin.mjs";
|
|
10
|
+
import { useServerLookupPlugin } from "./useServerLookupPlugin.mjs";
|
|
11
|
+
import { miniflareHMRPlugin } from "./miniflareHMRPlugin.mjs";
|
|
12
|
+
import { moveStaticAssetsPlugin } from "./moveStaticAssetsPlugin.mjs";
|
|
13
|
+
import { configPlugin } from "./configPlugin.mjs";
|
|
14
|
+
import { $ } from "../lib/$.mjs";
|
|
15
|
+
import { reactConditionsResolverPlugin } from "./reactConditionsResolverPlugin.mjs";
|
|
16
|
+
import { findWranglerConfig } from "../lib/findWranglerConfig.mjs";
|
|
17
|
+
import { pathExists } from "fs-extra";
|
|
18
|
+
import { injectVitePreamble } from "./injectVitePreamblePlugin.mjs";
|
|
19
|
+
import { vitePreamblePlugin } from "./vitePreamblePlugin.mjs";
|
|
20
|
+
import { prismaPlugin } from "./prismaPlugin.mjs";
|
|
21
|
+
import { ssrBridgePlugin } from "./ssrBridgePlugin.mjs";
|
|
22
|
+
import { hasPkgScript } from "../lib/hasPkgScript.mjs";
|
|
23
|
+
import { devServerTimingPlugin } from "./devServerTimingPlugin.mjs";
|
|
24
|
+
const determineWorkerEntryPathname = async (projectRootDir, workerConfigPath, options) => {
|
|
25
|
+
if (options.entry?.worker) {
|
|
26
|
+
return resolve(projectRootDir, options.entry.worker);
|
|
27
|
+
}
|
|
28
|
+
const workerConfig = unstable_readConfig({ config: workerConfigPath });
|
|
29
|
+
return resolve(projectRootDir, workerConfig.main ?? "src/worker.tsx");
|
|
30
|
+
};
|
|
31
|
+
export const redwoodPlugin = async (options = {}) => {
|
|
32
|
+
const projectRootDir = process.cwd();
|
|
33
|
+
const workerConfigPath = options.configPath ?? (await findWranglerConfig(projectRootDir));
|
|
34
|
+
const workerEntryPathname = await determineWorkerEntryPathname(projectRootDir, workerConfigPath, options);
|
|
35
|
+
const clientEntryPathnames = (Array.isArray(options.entry?.client)
|
|
36
|
+
? options.entry.client
|
|
37
|
+
: [options.entry?.client ?? "src/client.tsx"]).map((entry) => resolve(projectRootDir, entry));
|
|
38
|
+
const clientFiles = new Set();
|
|
39
|
+
const serverFiles = new Set();
|
|
40
|
+
const shouldIncludeCloudflarePlugin = options.includeCloudflarePlugin ??
|
|
41
|
+
!(await hasOwnCloudflareVitePlugin({ rootProjectDir: projectRootDir }));
|
|
42
|
+
// context(justinvdm, 31 Mar 2025): We assume that if there is no .wrangler directory,
|
|
43
|
+
// then this is fresh install, and we run `npm run dev:init` here.
|
|
44
|
+
if (process.env.RWSDK_WORKER_RUN !== "1" &&
|
|
45
|
+
process.env.RWSDK_DEPLOY !== "1" &&
|
|
46
|
+
!(await pathExists(resolve(projectRootDir, ".wrangler"))) &&
|
|
47
|
+
(await hasPkgScript(projectRootDir, "dev:init"))) {
|
|
48
|
+
console.log("🚀 Project has no .wrangler directory yet, assuming fresh install: running `npm run dev:init`...");
|
|
49
|
+
await $({
|
|
50
|
+
// context(justinvdm, 01 Apr 2025): We want to avoid interactive migration y/n prompt, so we ignore stdin
|
|
51
|
+
// as a signal to operate in no-tty mode
|
|
52
|
+
stdio: ["ignore", "inherit", "inherit"],
|
|
53
|
+
}) `npm run dev:init`;
|
|
54
|
+
}
|
|
55
|
+
return [
|
|
56
|
+
devServerTimingPlugin(),
|
|
57
|
+
configPlugin({
|
|
58
|
+
silent: options.silent ?? false,
|
|
59
|
+
projectRootDir,
|
|
60
|
+
clientEntryPathnames,
|
|
61
|
+
workerEntryPathname,
|
|
62
|
+
}),
|
|
63
|
+
ssrBridgePlugin({
|
|
64
|
+
clientFiles,
|
|
65
|
+
serverFiles,
|
|
66
|
+
projectRootDir,
|
|
67
|
+
}),
|
|
68
|
+
reactConditionsResolverPlugin(),
|
|
69
|
+
tsconfigPaths({ root: projectRootDir }),
|
|
70
|
+
shouldIncludeCloudflarePlugin
|
|
71
|
+
? cloudflare({
|
|
72
|
+
viteEnvironment: { name: "worker" },
|
|
73
|
+
configPath: workerConfigPath,
|
|
74
|
+
})
|
|
75
|
+
: [],
|
|
76
|
+
miniflareHMRPlugin({
|
|
77
|
+
clientFiles,
|
|
78
|
+
serverFiles,
|
|
79
|
+
rootDir: projectRootDir,
|
|
80
|
+
viteEnvironment: { name: "worker" },
|
|
81
|
+
workerEntryPathname,
|
|
82
|
+
}),
|
|
83
|
+
reactPlugin(),
|
|
84
|
+
directivesPlugin({
|
|
85
|
+
projectRootDir,
|
|
86
|
+
clientFiles,
|
|
87
|
+
serverFiles,
|
|
88
|
+
}),
|
|
89
|
+
vitePreamblePlugin(),
|
|
90
|
+
injectVitePreamble({ clientEntryPathnames }),
|
|
91
|
+
useClientLookupPlugin({
|
|
92
|
+
projectRootDir,
|
|
93
|
+
clientFiles,
|
|
94
|
+
}),
|
|
95
|
+
useServerLookupPlugin({
|
|
96
|
+
projectRootDir,
|
|
97
|
+
serverFiles,
|
|
98
|
+
}),
|
|
99
|
+
transformJsxScriptTagsPlugin({
|
|
100
|
+
manifestPath: resolve(projectRootDir, "dist", "client", ".vite", "manifest.json"),
|
|
101
|
+
}),
|
|
102
|
+
moveStaticAssetsPlugin({ rootDir: projectRootDir }),
|
|
103
|
+
prismaPlugin({ projectRootDir }),
|
|
104
|
+
];
|
|
105
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export declare const VIRTUAL_SSR_PREFIX = "virtual:rwsdk:ssr:";
|
|
3
|
+
export declare const ssrBridgePlugin: ({ clientFiles, serverFiles, }: {
|
|
4
|
+
clientFiles: Set<string>;
|
|
5
|
+
serverFiles: Set<string>;
|
|
6
|
+
projectRootDir: string;
|
|
7
|
+
}) => Plugin;
|