rwsdk 0.1.0 → 0.1.1

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.
@@ -6,7 +6,7 @@ export declare class SqliteDurableObject<T = any> extends DurableObject {
6
6
  private initialized;
7
7
  private migrationTableName;
8
8
  constructor(ctx: DurableObjectState, env: any, migrations: Record<string, any>, migrationTableName?: string);
9
- private initialize;
9
+ initialize(): Promise<void>;
10
10
  kyselyExecuteQuery<R>(compiledQuery: {
11
11
  sql: string;
12
12
  parameters: readonly unknown[];
@@ -4,19 +4,25 @@ import { DOWorkerDialect } from "./DOWorkerDialect.js";
4
4
  const createDurableObjectDb = (durableObjectBinding, name = "main") => {
5
5
  const durableObjectId = durableObjectBinding.idFromName(name);
6
6
  const stub = durableObjectBinding.get(durableObjectId);
7
+ stub.initialize();
7
8
  return new Kysely({
8
9
  dialect: new DOWorkerDialect({ stub }),
9
10
  });
10
11
  };
11
12
  export function createDb(durableObjectBinding, name = "main") {
12
13
  const cacheKey = `${durableObjectBinding}_${name}`;
14
+ const doCreateDb = () => {
15
+ let db = requestInfo.rw.databases.get(cacheKey);
16
+ if (!db) {
17
+ db = createDurableObjectDb(durableObjectBinding, name);
18
+ requestInfo.rw.databases.set(cacheKey, db);
19
+ }
20
+ return db;
21
+ };
22
+ doCreateDb();
13
23
  return new Proxy({}, {
14
24
  get(target, prop, receiver) {
15
- let db = requestInfo.rw.databases.get(cacheKey);
16
- if (!db) {
17
- db = createDurableObjectDb(durableObjectBinding, name);
18
- requestInfo.rw.databases.set(cacheKey, db);
19
- }
25
+ const db = doCreateDb();
20
26
  const value = db[prop];
21
27
  if (typeof value === "function") {
22
28
  return value.bind(db);
@@ -1,10 +1,10 @@
1
1
  import { Plugin } from "vite";
2
2
  export declare const cloudflareBuiltInModules: string[];
3
3
  export declare const externalModules: string[];
4
- export declare const configPlugin: ({ mode, silent, projectRootDir, clientEntryPathname, workerEntryPathname, }: {
4
+ export declare const configPlugin: ({ mode, silent, projectRootDir, clientEntryPathnames, workerEntryPathname, }: {
5
5
  mode: "development" | "production";
6
6
  silent: boolean;
7
7
  projectRootDir: string;
8
- clientEntryPathname: string;
8
+ clientEntryPathnames: string[];
9
9
  workerEntryPathname: string;
10
10
  }) => Plugin;
@@ -15,7 +15,7 @@ export const externalModules = [
15
15
  ...builtinModules,
16
16
  ...builtinModules.map((m) => `node:${m}`),
17
17
  ];
18
- export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname, workerEntryPathname, }) => ({
18
+ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathnames, workerEntryPathname, }) => ({
19
19
  name: "rwsdk:config",
20
20
  config: (_, { command }) => {
21
21
  const baseConfig = {
@@ -39,9 +39,7 @@ export const configPlugin = ({ mode, silent, projectRootDir, clientEntryPathname
39
39
  outDir: resolve(projectRootDir, "dist", "client"),
40
40
  manifest: true,
41
41
  rollupOptions: {
42
- input: {
43
- client: clientEntryPathname,
44
- },
42
+ input: clientEntryPathnames,
45
43
  },
46
44
  },
47
45
  define: {
@@ -1,5 +1,5 @@
1
1
  import { type Plugin } from "vite";
2
- export declare const injectVitePreamble: ({ clientEntryPathname, mode, }: {
3
- clientEntryPathname: string;
2
+ export declare const injectVitePreamble: ({ clientEntryPathnames, mode, }: {
3
+ clientEntryPathnames: string[];
4
4
  mode: "development" | "production";
5
5
  }) => Plugin;
@@ -1,9 +1,12 @@
1
1
  import MagicString from "magic-string";
2
- export const injectVitePreamble = ({ clientEntryPathname, mode, }) => ({
2
+ export const injectVitePreamble = ({ clientEntryPathnames, mode, }) => ({
3
3
  name: "rwsdk:inject-vite-preamble",
4
4
  apply: "serve",
5
5
  transform(code, id) {
6
- if (id !== clientEntryPathname) {
6
+ if (this.environment.name !== "client") {
7
+ return;
8
+ }
9
+ if (!clientEntryPathnames.includes(id)) {
7
10
  return;
8
11
  }
9
12
  // Only inject preamble in development mode
@@ -13,4 +13,4 @@ export declare const ENV_RESOLVERS: {
13
13
  export declare const ENV_IMPORT_MAPPINGS: {
14
14
  [k: string]: Map<string, string>;
15
15
  };
16
- export declare const reactConditionsResolverPlugin: () => Promise<Plugin>;
16
+ export declare const reactConditionsResolverPlugin: () => Plugin[];
@@ -95,71 +95,76 @@ function createEsbuildResolverPlugin(envName) {
95
95
  },
96
96
  };
97
97
  }
98
- export const reactConditionsResolverPlugin = async () => {
98
+ export const reactConditionsResolverPlugin = () => {
99
99
  log("Initializing react conditions resolver plugin");
100
100
  let isBuild = false;
101
- return {
102
- name: "rwsdk:react-conditions-resolver",
103
- enforce: "post",
104
- config(config, { command }) {
105
- isBuild = command === "build";
106
- log("Configuring plugin for command=%s", command);
101
+ return [
102
+ {
103
+ name: "rwsdk:react-conditions-resolver:config",
104
+ enforce: "post",
105
+ config(config, { command }) {
106
+ isBuild = command === "build";
107
+ log("Configuring plugin for command=%s", command);
108
+ },
109
+ configResolved(config) {
110
+ log("Setting up resolve aliases and optimizeDeps for each environment");
111
+ // Set up aliases and optimizeDeps for each environment
112
+ for (const [envName, mappings] of Object.entries(ENV_IMPORT_MAPPINGS)) {
113
+ const reactImports = ENV_REACT_IMPORTS[envName];
114
+ // Ensure environment config exists
115
+ if (!config.environments) {
116
+ config.environments = {};
117
+ }
118
+ if (!config.environments[envName]) {
119
+ config.environments[envName] = {};
120
+ }
121
+ const envConfig = config.environments[envName];
122
+ const esbuildPlugin = createEsbuildResolverPlugin(envName);
123
+ if (esbuildPlugin && mappings) {
124
+ envConfig.optimizeDeps ??= {};
125
+ envConfig.optimizeDeps.esbuildOptions ??= {};
126
+ envConfig.optimizeDeps.esbuildOptions.define ??= {};
127
+ envConfig.optimizeDeps.esbuildOptions.define["process.env.NODE_ENV"] = JSON.stringify(process.env.NODE_ENV ?? "production");
128
+ envConfig.optimizeDeps.esbuildOptions.plugins ??= [];
129
+ envConfig.optimizeDeps.esbuildOptions.plugins.push(esbuildPlugin);
130
+ envConfig.optimizeDeps.include ??= [];
131
+ envConfig.optimizeDeps.include.push(...reactImports);
132
+ log("Added esbuild plugin and optimizeDeps includes for environment: %s", envName);
133
+ }
134
+ const aliases = ensureAliasArray(envConfig);
135
+ for (const [find, replacement] of mappings) {
136
+ const findRegex = new RegExp(`^${find.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&")}$`);
137
+ aliases.push({ find: findRegex, replacement });
138
+ log("Added alias for env=%s: %s -> %s", envName, find, replacement);
139
+ }
140
+ log("Environment %s configured with %d aliases and %d optimizeDeps includes", envName, mappings.size, reactImports.length);
141
+ }
142
+ },
107
143
  },
108
- configResolved(config) {
109
- log("Setting up resolve aliases and optimizeDeps for each environment");
110
- // Set up aliases and optimizeDeps for each environment
111
- for (const [envName, mappings] of Object.entries(ENV_IMPORT_MAPPINGS)) {
112
- const reactImports = ENV_REACT_IMPORTS[envName];
113
- // Ensure environment config exists
114
- if (!config.environments) {
115
- config.environments = {};
144
+ {
145
+ name: "rwsdk:react-conditions-resolver:resolveId",
146
+ enforce: "pre",
147
+ async resolveId(id, importer) {
148
+ if (!isBuild) {
149
+ return;
116
150
  }
117
- if (!config.environments[envName]) {
118
- config.environments[envName] = {};
151
+ const envName = this.environment?.name;
152
+ if (!envName) {
153
+ return;
119
154
  }
120
- const envConfig = config.environments[envName];
121
- const esbuildPlugin = createEsbuildResolverPlugin(envName);
122
- if (esbuildPlugin && mappings) {
123
- envConfig.optimizeDeps ??= {};
124
- envConfig.optimizeDeps.esbuildOptions ??= {};
125
- envConfig.optimizeDeps.esbuildOptions.define ??= {};
126
- envConfig.optimizeDeps.esbuildOptions.define["process.env.NODE_ENV"] =
127
- JSON.stringify(process.env.NODE_ENV ?? "production");
128
- envConfig.optimizeDeps.esbuildOptions.plugins ??= [];
129
- envConfig.optimizeDeps.esbuildOptions.plugins.push(esbuildPlugin);
130
- envConfig.optimizeDeps.include ??= [];
131
- envConfig.optimizeDeps.include.push(...reactImports);
132
- log("Added esbuild plugin and optimizeDeps includes for environment: %s", envName);
155
+ verboseLog("Resolving id=%s, environment=%s, importer=%s", id, envName, importer);
156
+ const mappings = ENV_IMPORT_MAPPINGS[envName];
157
+ if (!mappings) {
158
+ verboseLog("No mappings found for environment: %s", envName);
159
+ return;
133
160
  }
134
- const aliases = ensureAliasArray(envConfig);
135
- for (const [find, replacement] of mappings) {
136
- const findRegex = new RegExp(`^${find.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&")}$`);
137
- aliases.push({ find: findRegex, replacement });
138
- log("Added alias for env=%s: %s -> %s", envName, find, replacement);
161
+ const resolved = mappings.get(id);
162
+ if (resolved) {
163
+ log("Resolved %s -> %s for env=%s", id, resolved, envName);
164
+ return resolved;
139
165
  }
140
- log("Environment %s configured with %d aliases and %d optimizeDeps includes", envName, mappings.size, reactImports.length);
141
- }
166
+ verboseLog("No resolution found for id=%s in env=%s", id, envName);
167
+ },
142
168
  },
143
- async resolveId(id, importer) {
144
- if (!isBuild) {
145
- return;
146
- }
147
- const envName = this.environment?.name;
148
- if (!envName) {
149
- return;
150
- }
151
- verboseLog("Resolving id=%s, environment=%s, importer=%s", id, envName, importer);
152
- const mappings = ENV_IMPORT_MAPPINGS[envName];
153
- if (!mappings) {
154
- verboseLog("No mappings found for environment: %s", envName);
155
- return;
156
- }
157
- const resolved = mappings.get(id);
158
- if (resolved) {
159
- log("Resolved %s -> %s for env=%s", id, resolved, envName);
160
- return resolved;
161
- }
162
- verboseLog("No resolution found for id=%s in env=%s", id, envName);
163
- },
164
- };
169
+ ];
165
170
  };
@@ -6,7 +6,7 @@ export type RedwoodPluginOptions = {
6
6
  includeCloudflarePlugin?: boolean;
7
7
  configPath?: string;
8
8
  entry?: {
9
- client?: string;
9
+ client?: string | string[];
10
10
  worker?: string;
11
11
  };
12
12
  };
@@ -24,7 +24,9 @@ export const redwoodPlugin = async (options = {}) => {
24
24
  const projectRootDir = process.cwd();
25
25
  const mode = options.mode ??
26
26
  (process.env.NODE_ENV === "development" ? "development" : "production");
27
- const clientEntryPathname = resolve(projectRootDir, options?.entry?.client ?? "src/client.tsx");
27
+ const clientEntryPathnames = (Array.isArray(options.entry?.client)
28
+ ? options.entry.client
29
+ : [options.entry?.client ?? "src/client.tsx"]).map((entry) => resolve(projectRootDir, entry));
28
30
  const workerEntryPathname = resolve(projectRootDir, options?.entry?.worker ?? "src/worker.tsx");
29
31
  const clientFiles = new Set();
30
32
  const serverFiles = new Set();
@@ -49,7 +51,7 @@ export const redwoodPlugin = async (options = {}) => {
49
51
  mode,
50
52
  silent: options.silent ?? false,
51
53
  projectRootDir,
52
- clientEntryPathname,
54
+ clientEntryPathnames,
53
55
  workerEntryPathname,
54
56
  }),
55
57
  ssrBridgePlugin({
@@ -77,7 +79,7 @@ export const redwoodPlugin = async (options = {}) => {
77
79
  serverFiles,
78
80
  }),
79
81
  vitePreamblePlugin(),
80
- injectVitePreamble({ clientEntryPathname, mode }),
82
+ injectVitePreamble({ clientEntryPathnames, mode }),
81
83
  useClientLookupPlugin({
82
84
  projectRootDir,
83
85
  clientFiles,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rwsdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Build fast, server-driven webapps on Cloudflare with SSR, RSC, and realtime",
5
5
  "type": "module",
6
6
  "bin": {