rwsdk 0.0.84 → 0.0.85

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.
@@ -1,3 +1,6 @@
1
- export declare const checkIsUsingPrisma: ({ projectRootDir, }: {
1
+ export type PrismaCheckResult = {
2
+ isUsingPrisma: boolean;
3
+ };
4
+ export declare const checkPrismaStatus: ({ projectRootDir, }: {
2
5
  projectRootDir: string;
3
- }) => boolean;
6
+ }) => PrismaCheckResult;
@@ -1,9 +1,18 @@
1
1
  import enhancedResolve from "enhanced-resolve";
2
- export const checkIsUsingPrisma = ({ projectRootDir, }) => {
2
+ const isUsingPrisma = ({ projectRootDir }) => {
3
3
  try {
4
- return Boolean(enhancedResolve.sync(projectRootDir, "@prisma/client"));
4
+ const prismaClientPath = enhancedResolve.sync(projectRootDir, "@prisma/client");
5
+ if (!prismaClientPath) {
6
+ return false;
7
+ }
8
+ return true;
5
9
  }
6
10
  catch {
7
11
  return false;
8
12
  }
9
13
  };
14
+ export const checkPrismaStatus = ({ projectRootDir, }) => {
15
+ return {
16
+ isUsingPrisma: isUsingPrisma({ projectRootDir }),
17
+ };
18
+ };
@@ -1,9 +1,8 @@
1
1
  import { Plugin } from "vite";
2
- export declare const configPlugin: ({ mode, silent, projectRootDir, clientEntryPathname, workerEntryPathname, isUsingPrisma, }: {
2
+ export declare const configPlugin: ({ mode, silent, projectRootDir, clientEntryPathname, workerEntryPathname, }: {
3
3
  mode: "development" | "production";
4
4
  silent: boolean;
5
5
  projectRootDir: string;
6
6
  clientEntryPathname: string;
7
7
  workerEntryPathname: string;
8
- isUsingPrisma: boolean;
9
8
  }) => Plugin;
@@ -8,7 +8,7 @@ const ignoreVirtualModules = {
8
8
  });
9
9
  },
10
10
  };
11
- export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname, workerEntryPathname, isUsingPrisma, }) => ({
11
+ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname, workerEntryPathname, }) => ({
12
12
  name: "rwsdk:config",
13
13
  config: (_, { command }) => {
14
14
  const baseConfig = {
@@ -50,23 +50,7 @@ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname
50
50
  noDiscovery: false,
51
51
  esbuildOptions: {
52
52
  conditions: ["workerd", "react-server"],
53
- plugins: [
54
- ...(isUsingPrisma
55
- ? [
56
- {
57
- name: "rwsdk:prisma-client-wasm",
58
- setup(build) {
59
- build.onResolve({ filter: /.prisma\/client\/default/ }, async (args) => {
60
- return {
61
- path: resolve(projectRootDir, "node_modules/.prisma/client/wasm.js"),
62
- };
63
- });
64
- },
65
- },
66
- ]
67
- : []),
68
- ignoreVirtualModules,
69
- ],
53
+ plugins: [ignoreVirtualModules],
70
54
  },
71
55
  include: [
72
56
  "react/jsx-runtime",
@@ -95,13 +79,7 @@ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname
95
79
  },
96
80
  resolve: {
97
81
  conditions: ["workerd"],
98
- alias: {
99
- ...(isUsingPrisma
100
- ? {
101
- ".prisma/client/default": resolve(projectRootDir, "node_modules/.prisma/client/wasm.js"),
102
- }
103
- : {}),
104
- },
82
+ alias: [],
105
83
  },
106
84
  };
107
85
  if (command === "build") {
@@ -110,7 +88,7 @@ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname
110
88
  worker: {
111
89
  build: {
112
90
  rollupOptions: {
113
- external: ["cloudflare:workers", "node:stream", /\.wasm$/],
91
+ external: ["cloudflare:workers", "node:stream"],
114
92
  },
115
93
  },
116
94
  },
@@ -0,0 +1,2 @@
1
+ import type { Alias, UserConfig } from "vite";
2
+ export declare const ensureAliasArray: (config: UserConfig) => Alias[];
@@ -0,0 +1,11 @@
1
+ export const ensureAliasArray = (config) => {
2
+ config.resolve ??= {};
3
+ if (!config.resolve?.alias) {
4
+ config.resolve.alias = [];
5
+ }
6
+ else if (!Array.isArray(config.resolve.alias)) {
7
+ const existingAlias = config.resolve.alias;
8
+ config.resolve.alias = Object.entries(existingAlias).map(([find, replacement]) => ({ find, replacement }));
9
+ }
10
+ return config.resolve.alias;
11
+ };
@@ -6,8 +6,7 @@ export const moveStaticAssetsPlugin = ({ rootDir, }) => ({
6
6
  if (this.environment.name === "worker") {
7
7
  await $sh({
8
8
  cwd: rootDir,
9
- }) `mv dist/worker/assets/* dist/client/assets || true`;
10
- await $sh({ cwd: rootDir }) `rmdir dist/worker/assets || true`;
9
+ }) `mv dist/worker/assets/*.css dist/client/assets/ || true`;
11
10
  }
12
11
  },
13
12
  });
@@ -0,0 +1,4 @@
1
+ import { Plugin } from "vite";
2
+ export declare const prismaPlugin: ({ projectRootDir, }: {
3
+ projectRootDir: string;
4
+ }) => Promise<Plugin | undefined>;
@@ -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
+ };
@@ -5,6 +5,7 @@ import { pathExists } from "fs-extra";
5
5
  import enhancedResolve from "enhanced-resolve";
6
6
  import { VENDOR_DIST_DIR } from "../lib/constants.mjs";
7
7
  import { createRequire } from "node:module";
8
+ import { ensureAliasArray } from "./ensureAliasArray.mjs";
8
9
  const log = debug("rwsdk:vite:react-conditions");
9
10
  // Define package sets for each environment
10
11
  const WORKER_PACKAGES = [
@@ -127,11 +128,7 @@ export const reactConditionsResolverPlugin = async ({ mode = "development", comm
127
128
  config.optimizeDeps.include ??= [];
128
129
  config.optimizeDeps.include.push(...Object.keys(imports));
129
130
  config.resolve ??= {};
130
- config.resolve.alias ??= [];
131
- if (!Array.isArray(config.resolve.alias)) {
132
- const existingAlias = config.resolve.alias;
133
- config.resolve.alias = Object.entries(existingAlias).map(([find, replacement]) => ({ find, replacement }));
134
- }
131
+ ensureAliasArray(config);
135
132
  Object.entries(imports).forEach(([id, resolvedPath]) => {
136
133
  const exactMatchRegex = new RegExp(`^${id.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&")}$`);
137
134
  config.resolve.alias.push({
@@ -6,17 +6,15 @@ import { useServerPlugin } from "./useServerPlugin.mjs";
6
6
  import { useClientPlugin } from "./useClientPlugin.mjs";
7
7
  import { useClientLookupPlugin } from "./useClientLookupPlugin.mjs";
8
8
  import { miniflarePlugin } from "./miniflarePlugin.mjs";
9
- import { copyPrismaWasmPlugin } from "./copyPrismaWasmPlugin.mjs";
10
9
  import { moveStaticAssetsPlugin } from "./moveStaticAssetsPlugin.mjs";
11
10
  import { configPlugin } from "./configPlugin.mjs";
12
11
  import { $ } from "../lib/$.mjs";
13
12
  import { reactConditionsResolverPlugin } from "./reactConditionsResolverPlugin.mjs";
14
- import { invalidateCacheIfPrismaClientChanged } from "./invalidateCacheIfPrismaClientChanged.mjs";
15
13
  import { findWranglerConfig } from "../lib/findWranglerConfig.mjs";
16
14
  import { pathExists } from "fs-extra";
17
15
  import { injectVitePreamble } from "./injectVitePreamblePlugin.mjs";
18
16
  import { vitePreamblePlugin } from "./vitePreamblePlugin.mjs";
19
- import { checkIsUsingPrisma } from "./checkIsUsingPrisma.mjs";
17
+ import { prismaPlugin } from "./prismaPlugin.mjs";
20
18
  export const redwoodPlugin = async (options = {}) => {
21
19
  const projectRootDir = process.cwd();
22
20
  const mode = options.mode ??
@@ -35,15 +33,6 @@ export const redwoodPlugin = async (options = {}) => {
35
33
  stdio: ["ignore", "inherit", "inherit"],
36
34
  }) `npm run dev:init`;
37
35
  }
38
- const isUsingPrisma = checkIsUsingPrisma({ projectRootDir });
39
- // context(justinvdm, 10 Mar 2025): We need to use vite optimizeDeps for all deps to work with @cloudflare/vite-plugin.
40
- // Thing is, @prisma/client has generated code. So users end up with a stale @prisma/client
41
- // when they change their prisma schema and regenerate the client, until clearing out node_modules/.vite
42
- // We can't exclude @prisma/client from optimizeDeps since we need it there for @cloudflare/vite-plugin to work.
43
- // But we can manually invalidate the cache if the prisma schema changes.
44
- await invalidateCacheIfPrismaClientChanged({
45
- projectRootDir,
46
- });
47
36
  return [
48
37
  configPlugin({
49
38
  mode,
@@ -51,7 +40,6 @@ export const redwoodPlugin = async (options = {}) => {
51
40
  projectRootDir,
52
41
  clientEntryPathname,
53
42
  workerEntryPathname,
54
- isUsingPrisma,
55
43
  }),
56
44
  reactConditionsResolverPlugin({ projectRootDir, mode }),
57
45
  tsconfigPaths({ root: projectRootDir }),
@@ -73,9 +61,7 @@ export const redwoodPlugin = async (options = {}) => {
73
61
  transformJsxScriptTagsPlugin({
74
62
  manifestPath: resolve(projectRootDir, "dist", "client", ".vite", "manifest.json"),
75
63
  }),
76
- ...(isUsingPrisma
77
- ? [copyPrismaWasmPlugin({ rootDir: projectRootDir })]
78
- : []),
79
64
  moveStaticAssetsPlugin({ rootDir: projectRootDir }),
65
+ prismaPlugin({ projectRootDir }),
80
66
  ];
81
67
  };
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from "vite";
2
+ export declare const wasmPlugin: () => Plugin;
@@ -0,0 +1,14 @@
1
+ export const wasmPlugin = () => {
2
+ return {
3
+ name: "rwsdk:wasm",
4
+ resolveId(id) {
5
+ console.log("######", id);
6
+ if (id.startsWith("@id/__CLOUDFLARE_MODULE__CompiledWasm__") &&
7
+ id.endsWith(".wasm__")) {
8
+ const r = id.slice("@id/__CLOUDFLARE_MODULE__CompiledWasm__".length, id.length - "__".length);
9
+ console.log("##################33", r);
10
+ return r;
11
+ }
12
+ },
13
+ };
14
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwsdk",
3
- "version": "0.0.84",
3
+ "version": "0.0.85",
4
4
  "description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
5
5
  "type": "module",
6
6
  "bin": {
@@ -89,7 +89,7 @@
89
89
  "author": "RedwoodSDK <peter@redwoodjs.com>",
90
90
  "license": "MIT",
91
91
  "dependencies": {
92
- "@cloudflare/vite-plugin": "^1.1.0",
92
+ "@cloudflare/vite-plugin": "0.0.0-1bae8618b",
93
93
  "@cloudflare/workers-types": "^4.20250407.0",
94
94
  "@puppeteer/browsers": "^2.8.0",
95
95
  "@types/fs-extra": "^11.0.4",
@@ -120,7 +120,7 @@
120
120
  "unique-names-generator": "^4.7.1",
121
121
  "vibe-rules": "^0.2.31",
122
122
  "vite-tsconfig-paths": "^5.1.4",
123
- "wrangler": "^4.14.1"
123
+ "wrangler": "^4.16.0"
124
124
  },
125
125
  "peerDependencies": {
126
126
  "vite": "^6.2.6"