rwsdk 0.1.15 → 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/runtime/imports/client.js +1 -1
- package/dist/runtime/imports/ssr.js +1 -1
- package/dist/runtime/imports/worker.js +1 -1
- package/dist/runtime/register/ssr.js +1 -1
- package/dist/vite/createDirectiveLookupPlugin.mjs +4 -6
- package/dist/vite/findSsrSpecifiers.mjs +16 -0
- package/dist/vite/miniflareHMRPlugin.mjs +59 -21
- package/dist/vite/ssrBridgePlugin.mjs +18 -5
- package/package.json +1 -1
- package/dist/runtime/lib/db/typeInference/builders/table.d.ts +0 -10
- package/dist/runtime/lib/db/typeInference/builders/table.js +0 -1
- 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/isJsFile.d.ts +0 -1
- package/dist/vite/isJsFile.js +0 -3
- 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
|
@@ -5,7 +5,7 @@ export const loadModule = memoize(async (id) => {
|
|
|
5
5
|
return await import(/* @vite-ignore */ id);
|
|
6
6
|
}
|
|
7
7
|
else {
|
|
8
|
-
const { useClientLookup } = await import("virtual:use-client-lookup");
|
|
8
|
+
const { useClientLookup } = await import("virtual:use-client-lookup.js");
|
|
9
9
|
const moduleFn = useClientLookup[id];
|
|
10
10
|
if (!moduleFn) {
|
|
11
11
|
throw new Error(`(client) No module found for '${id}' in module lookup for "use client" directive`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import memoize from "lodash/memoize";
|
|
2
2
|
export const ssrLoadModule = memoize(async (id) => {
|
|
3
|
-
const { useClientLookup } = await import("virtual:use-client-lookup");
|
|
3
|
+
const { useClientLookup } = await import("virtual:use-client-lookup.js");
|
|
4
4
|
const moduleFn = useClientLookup[id];
|
|
5
5
|
if (!moduleFn) {
|
|
6
6
|
throw new Error(`(ssr) No module found for '${id}' in module lookup for "use client" directive`);
|
|
@@ -2,7 +2,7 @@ import memoize from "lodash/memoize";
|
|
|
2
2
|
import { requestInfo } from "../requestInfo/worker";
|
|
3
3
|
import { ssrWebpackRequire as baseSsrWebpackRequire } from "rwsdk/__ssr_bridge";
|
|
4
4
|
export const loadServerModule = memoize(async (id) => {
|
|
5
|
-
const { useServerLookup } = await import("virtual:use-server-lookup");
|
|
5
|
+
const { useServerLookup } = await import("virtual:use-server-lookup.js");
|
|
6
6
|
const moduleFn = useServerLookup[id];
|
|
7
7
|
if (!moduleFn) {
|
|
8
8
|
throw new Error(`(worker) No module found for '${id}' in module lookup for "use server" directive`);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import memoize from "lodash/memoize";
|
|
2
2
|
import { createServerReference as baseCreateServerReference } from "react-server-dom-webpack/client.edge";
|
|
3
3
|
export const loadServerModule = memoize(async (id) => {
|
|
4
|
-
const { useServerLookup } = await import("virtual:use-server-lookup");
|
|
4
|
+
const { useServerLookup } = await import("virtual:use-server-lookup.js");
|
|
5
5
|
const moduleFn = useServerLookup[id];
|
|
6
6
|
if (!moduleFn) {
|
|
7
7
|
throw new Error(`(worker) No module found for '${id}' in module lookup for "use server" directive`);
|
|
@@ -150,12 +150,12 @@ export const createDirectiveLookupPlugin = async ({ projectRootDir, files, confi
|
|
|
150
150
|
const escapedVirtualModuleName = config.virtualModuleName.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
151
151
|
const escapedPrefixedModuleName = `/@id/${config.virtualModuleName}`.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&");
|
|
152
152
|
build.onResolve({
|
|
153
|
-
filter: new RegExp(`^(${escapedVirtualModuleName}|${escapedPrefixedModuleName})$`),
|
|
153
|
+
filter: new RegExp(`^(${escapedVirtualModuleName}|${escapedPrefixedModuleName})\.js$`),
|
|
154
154
|
}, () => {
|
|
155
155
|
process.env.VERBOSE &&
|
|
156
156
|
log("Esbuild onResolve: marking %s as external", config.virtualModuleName);
|
|
157
157
|
return {
|
|
158
|
-
path: config.virtualModuleName
|
|
158
|
+
path: `${config.virtualModuleName}.js`,
|
|
159
159
|
external: true,
|
|
160
160
|
};
|
|
161
161
|
});
|
|
@@ -184,13 +184,11 @@ export const createDirectiveLookupPlugin = async ({ projectRootDir, files, confi
|
|
|
184
184
|
},
|
|
185
185
|
resolveId(source) {
|
|
186
186
|
process.env.VERBOSE && log("Resolving id=%s", source);
|
|
187
|
-
if (source === config.virtualModuleName
|
|
188
|
-
source === `/@id/${config.virtualModuleName}` ||
|
|
189
|
-
source === `/@id/${config.virtualModuleName}.js`) {
|
|
187
|
+
if (source === `${config.virtualModuleName}.js`) {
|
|
190
188
|
log("Resolving %s module", config.virtualModuleName);
|
|
191
189
|
// context(justinvdm, 16 Jun 2025): Include .js extension
|
|
192
190
|
// so it goes through vite processing chain
|
|
193
|
-
return
|
|
191
|
+
return source;
|
|
194
192
|
}
|
|
195
193
|
process.env.VERBOSE && log("No resolution for id=%s", source);
|
|
196
194
|
},
|
|
@@ -32,6 +32,22 @@ export function findSsrImportSpecifiers(id, code, log) {
|
|
|
32
32
|
pattern: `__vite_ssr_dynamic_import__('$SPECIFIER')`,
|
|
33
33
|
list: dynamicImports,
|
|
34
34
|
},
|
|
35
|
+
{
|
|
36
|
+
pattern: `__vite_ssr_import__("$SPECIFIER", $$$REST)`,
|
|
37
|
+
list: imports,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
pattern: `__vite_ssr_import__('$SPECIFIER', $$$REST)`,
|
|
41
|
+
list: imports,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
pattern: `__vite_ssr_dynamic_import__("$SPECIFIER", $$$REST)`,
|
|
45
|
+
list: dynamicImports,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
pattern: `__vite_ssr_dynamic_import__('$SPECIFIER', $$$REST)`,
|
|
49
|
+
list: dynamicImports,
|
|
50
|
+
},
|
|
35
51
|
];
|
|
36
52
|
for (const { pattern, list } of patterns) {
|
|
37
53
|
const matches = root.root().findAll(pattern);
|
|
@@ -32,13 +32,50 @@ const hasEntryAsAncestor = (module, entryFile, seen = new Set()) => {
|
|
|
32
32
|
}
|
|
33
33
|
return false;
|
|
34
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
|
+
};
|
|
35
54
|
export const miniflareHMRPlugin = (givenOptions) => [
|
|
36
55
|
{
|
|
37
56
|
name: "rwsdk:miniflare-hmr",
|
|
38
57
|
async hotUpdate(ctx) {
|
|
39
58
|
const { clientFiles, serverFiles, viteEnvironment: { name: environment }, workerEntryPathname: entry, } = givenOptions;
|
|
40
59
|
if (process.env.VERBOSE) {
|
|
41
|
-
|
|
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 [];
|
|
42
79
|
}
|
|
43
80
|
if (!["client", environment].includes(this.environment.name)) {
|
|
44
81
|
return [];
|
|
@@ -77,33 +114,34 @@ export const miniflareHMRPlugin = (givenOptions) => [
|
|
|
77
114
|
}
|
|
78
115
|
// todo(justinvdm, 12 Dec 2024): Skip client references
|
|
79
116
|
const modules = Array.from(ctx.server.environments[environment].moduleGraph.getModulesByFile(ctx.file) ?? []);
|
|
80
|
-
const isWorkerUpdate =
|
|
81
|
-
modules.some((module) => hasEntryAsAncestor(module, entry));
|
|
82
|
-
// The worker doesnt need an update
|
|
83
|
-
// => Short circuit HMR
|
|
84
|
-
if (!isWorkerUpdate) {
|
|
85
|
-
return [];
|
|
86
|
-
}
|
|
117
|
+
const isWorkerUpdate = Boolean(modules);
|
|
87
118
|
// The worker needs an update, but this is the client environment
|
|
88
119
|
// => Notify for HMR update of any css files imported by in worker, that are also in the client module graph
|
|
89
120
|
// Why: There may have been changes to css classes referenced, which might css modules to change
|
|
90
121
|
if (this.environment.name === "client") {
|
|
91
|
-
|
|
92
|
-
.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
+
}
|
|
100
133
|
}
|
|
101
134
|
}
|
|
102
135
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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;
|
|
107
145
|
}
|
|
108
146
|
// The worker needs an update, and the hot check is for the worker environment
|
|
109
147
|
// => Notify for custom RSC-based HMR update, then short circuit HMR
|
|
@@ -93,22 +93,35 @@ export const ssrBridgePlugin = ({ clientFiles, serverFiles, }) => {
|
|
|
93
93
|
process.env.VERBOSE &&
|
|
94
94
|
log("Fetch module result: id=%s, result=%O", realId, result);
|
|
95
95
|
const code = "code" in result ? result.code : undefined;
|
|
96
|
+
if (realId.endsWith(".css")) {
|
|
97
|
+
process.env.VERBOSE &&
|
|
98
|
+
log("Not a JS file, returning code: %s", code);
|
|
99
|
+
return code ?? "";
|
|
100
|
+
}
|
|
96
101
|
log("Fetched SSR module code length: %d", code?.length || 0);
|
|
97
102
|
const { imports, dynamicImports } = findSsrImportSpecifiers(realId, code || "", log);
|
|
98
|
-
const allSpecifiers = [
|
|
103
|
+
const allSpecifiers = [
|
|
104
|
+
...new Set([...imports, ...dynamicImports]),
|
|
105
|
+
].map((id) => id.startsWith("/@id/") ? id.slice("/@id/".length) : id);
|
|
99
106
|
const switchCases = allSpecifiers
|
|
100
|
-
.map((specifier) => ` case "${specifier}":
|
|
107
|
+
.map((specifier) => ` case "${specifier}": void import("${VIRTUAL_SSR_PREFIX}${specifier}");`)
|
|
101
108
|
.join("\n");
|
|
102
109
|
const transformedCode = `
|
|
103
110
|
await (async function(__vite_ssr_import__, __vite_ssr_dynamic_import__) {${code}})(
|
|
104
|
-
(
|
|
105
|
-
(
|
|
111
|
+
__ssrImport.bind(null, false),
|
|
112
|
+
__ssrImport.bind(null, true)
|
|
106
113
|
);
|
|
107
114
|
|
|
108
|
-
function
|
|
115
|
+
function __ssrImport(isDynamic, id, ...args) {
|
|
116
|
+
id = id.startsWith('/@id/') ? id.slice('/@id/'.length) : id;
|
|
117
|
+
|
|
109
118
|
switch (id) {
|
|
110
119
|
${switchCases}
|
|
111
120
|
}
|
|
121
|
+
|
|
122
|
+
return isDynamic
|
|
123
|
+
? __vite_ssr_dynamic_import__("/@id/${VIRTUAL_SSR_PREFIX}" + id, ...args)
|
|
124
|
+
: __vite_ssr_import__("/@id/${VIRTUAL_SSR_PREFIX}" + id, ...args);
|
|
112
125
|
}
|
|
113
126
|
`;
|
|
114
127
|
log("Transformed SSR module code length: %d", transformedCode.length);
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { SqlToTsType, ExecutedBuilder, Prettify } from "../utils";
|
|
2
|
-
import { ColumnDefinitionBuilder } from "./columnDefinition";
|
|
3
|
-
export interface TableBuilder<TName extends string, TSchema extends Record<string, any> = {}> {
|
|
4
|
-
readonly __tableName: TName;
|
|
5
|
-
readonly __schema: TSchema;
|
|
6
|
-
addColumn<K extends string, T extends string>(name: K, type: T, build?: (col: ColumnDefinitionBuilder<SqlToTsType<T>>) => ColumnDefinitionBuilder<SqlToTsType<T>>): TableBuilder<TName, Prettify<TSchema & Record<K, SqlToTsType<T>>>>;
|
|
7
|
-
temporary(): this;
|
|
8
|
-
ifNotExists(): this;
|
|
9
|
-
execute(): Promise<ExecutedBuilder<this>>;
|
|
10
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { invalidateModule } from "./invalidateModule.mjs";
|
|
2
|
-
import { normalizeModulePath } from "./normalizeModulePath.mjs";
|
|
3
|
-
import { VIRTUAL_SSR_PREFIX } from "./ssrBridgePlugin.mjs";
|
|
4
|
-
export const invalidateClientModule = (devServer, filePath) => {
|
|
5
|
-
invalidateModule(devServer, "ssr", filePath);
|
|
6
|
-
invalidateModule(devServer, "client", filePath);
|
|
7
|
-
invalidateModule(devServer, "worker", VIRTUAL_SSR_PREFIX + normalizeModulePath(devServer.config.root, filePath));
|
|
8
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import debug from "debug";
|
|
2
|
-
const log = debug("rwsdk:vite:invalidate-module");
|
|
3
|
-
const verboseLog = debug("verbose:rwsdk:vite:invalidate-module");
|
|
4
|
-
export const invalidateModule = (devServer, environment, id) => {
|
|
5
|
-
const [rawId, _query] = id.split("?");
|
|
6
|
-
log("Invalidating module: id=%s, environment=%s", id, environment);
|
|
7
|
-
const moduleNode = devServer?.environments[environment]?.moduleGraph.idToModuleMap.get(rawId);
|
|
8
|
-
if (moduleNode) {
|
|
9
|
-
devServer?.environments[environment]?.moduleGraph.invalidateModule(moduleNode);
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
verboseLog("Module not found: id=%s, environment=%s", id, environment);
|
|
13
|
-
}
|
|
14
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { invalidateModule } from "./invalidateModule.mjs";
|
|
2
|
-
import { normalizeModulePath } from "./normalizeModulePath.mjs";
|
|
3
|
-
import { VIRTUAL_SSR_PREFIX } from "./ssrBridgePlugin.mjs";
|
|
4
|
-
export const invalidateSSRModule = (devServer, filePath) => {
|
|
5
|
-
invalidateModule(devServer, "ssr", filePath);
|
|
6
|
-
invalidateModule(devServer, "worker", VIRTUAL_SSR_PREFIX + normalizeModulePath(devServer.config.root, filePath));
|
|
7
|
-
};
|
package/dist/vite/isJsFile.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isJsFile(filepath: string): boolean;
|
package/dist/vite/isJsFile.js
DELETED
package/dist/vite/mode.d.mts
DELETED
package/dist/vite/mode.mjs
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import debug from "debug";
|
|
2
|
-
const log = debug("rwsdk:vite:mode");
|
|
3
|
-
const initialNodeEnv = process.env.NODE_ENV;
|
|
4
|
-
let mode;
|
|
5
|
-
export const resolveMode = (env) => {
|
|
6
|
-
if (mode) {
|
|
7
|
-
return mode;
|
|
8
|
-
}
|
|
9
|
-
if (initialNodeEnv) {
|
|
10
|
-
mode = initialNodeEnv === "development" ? "development" : "production";
|
|
11
|
-
log(`Resolved mode: %s (from initial NODE_ENV=%s)`, mode, initialNodeEnv);
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
mode =
|
|
15
|
-
env.command === "serve" || env.isPreview ? "development" : "production";
|
|
16
|
-
log(`Resolved mode: %s (env.command=%s, env.isPreview=%s)`, mode, env.isPreview, env.command);
|
|
17
|
-
}
|
|
18
|
-
return mode;
|
|
19
|
-
};
|
|
20
|
-
export const ensureMode = () => {
|
|
21
|
-
if (mode === undefined) {
|
|
22
|
-
throw new Error("RedwoodSDK: mode is not resolved yet");
|
|
23
|
-
}
|
|
24
|
-
return mode;
|
|
25
|
-
};
|