appflare 0.2.32 โ 0.2.35
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/cli/commands/index.ts +9 -0
- package/cli/generate.ts +86 -40
- package/dist/cli/index.js +243 -232
- package/dist/cli/index.mjs +243 -232
- package/dist/react/index.js +1 -1
- package/dist/react/index.mjs +1 -1
- package/package.json +3 -3
- package/react/use-infinite-query.ts +2 -2
- package/react/use-query.ts +2 -2
package/cli/commands/index.ts
CHANGED
|
@@ -84,6 +84,15 @@ export async function runDev(
|
|
|
84
84
|
|
|
85
85
|
const watcher = chokidar.watch(loadedConfig.scanDirAbs, {
|
|
86
86
|
ignoreInitial: true,
|
|
87
|
+
ignored: (path: string) => {
|
|
88
|
+
return (
|
|
89
|
+
path.includes("/_generated/") ||
|
|
90
|
+
path.includes("/dist/") ||
|
|
91
|
+
path.includes("/out/") ||
|
|
92
|
+
path.includes("/node_modules/") ||
|
|
93
|
+
path.endsWith(".d.ts")
|
|
94
|
+
);
|
|
95
|
+
},
|
|
87
96
|
});
|
|
88
97
|
|
|
89
98
|
watcher.on("all", async (_eventName, changedPath) => {
|
package/cli/generate.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mkdir, readdir, rm } from "node:fs/promises";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import { join, relative, resolve } from "node:path";
|
|
3
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { generateAuthConfigSource } from "./templates/auth/config";
|
|
5
6
|
import { generateClientArtifacts } from "./templates/core/client.artifacts";
|
|
6
7
|
import { generateDrizzleConfigSource } from "./templates/core/drizzle";
|
|
@@ -31,11 +32,26 @@ export async function generateArtifacts(
|
|
|
31
32
|
configPath,
|
|
32
33
|
);
|
|
33
34
|
|
|
35
|
+
const t0 = performance.now();
|
|
36
|
+
|
|
34
37
|
await Promise.all([
|
|
35
38
|
mkdir(outDirAbs, { recursive: true }),
|
|
36
39
|
mkdir(clientOutDirAbs, { recursive: true }),
|
|
37
40
|
mkdir(wranglerOutDirAbs, { recursive: true }),
|
|
38
41
|
]);
|
|
42
|
+
process.stdout.write(`๐ Directories (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
43
|
+
|
|
44
|
+
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
45
|
+
const tscBin = join(
|
|
46
|
+
dirname(Bun.resolveSync("typescript/package.json", moduleDir)),
|
|
47
|
+
"bin",
|
|
48
|
+
"tsc",
|
|
49
|
+
);
|
|
50
|
+
const betterAuthBin = join(
|
|
51
|
+
dirname(Bun.resolveSync("@better-auth/cli/package.json", moduleDir)),
|
|
52
|
+
"dist",
|
|
53
|
+
"index.mjs",
|
|
54
|
+
);
|
|
39
55
|
|
|
40
56
|
const serverPath = resolve(outDirAbs, "server.ts");
|
|
41
57
|
const clientPath = resolve(outDirAbs, "client.ts");
|
|
@@ -54,6 +70,9 @@ export async function generateArtifacts(
|
|
|
54
70
|
discoveredSchema.schemaPath,
|
|
55
71
|
);
|
|
56
72
|
const discoveredHandlers = await discoverHandlerOperations(loadedConfig);
|
|
73
|
+
process.stdout.write(
|
|
74
|
+
`๐ ${discoveredHandlers.length} handler(s) (${(performance.now() - t0).toFixed(0)}ms)\n`,
|
|
75
|
+
);
|
|
57
76
|
|
|
58
77
|
const serverSource = generateServerSource(
|
|
59
78
|
config.auth.basePath,
|
|
@@ -117,6 +136,7 @@ export async function generateArtifacts(
|
|
|
117
136
|
Bun.write(wranglerPath, `${JSON.stringify(wranglerJson, null, 2)}\n`),
|
|
118
137
|
Bun.write(dashboardPath, dashboardSource),
|
|
119
138
|
]);
|
|
139
|
+
process.stdout.write(`๐ Source artifacts (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
120
140
|
|
|
121
141
|
const authConfigPathFromConfigDir = relative(
|
|
122
142
|
configDir,
|
|
@@ -135,8 +155,8 @@ export async function generateArtifacts(
|
|
|
135
155
|
|
|
136
156
|
const betterAuthGenerate = Bun.spawn(
|
|
137
157
|
[
|
|
138
|
-
|
|
139
|
-
|
|
158
|
+
process.execPath,
|
|
159
|
+
betterAuthBin,
|
|
140
160
|
"generate",
|
|
141
161
|
"--config",
|
|
142
162
|
authConfigCliPath,
|
|
@@ -155,49 +175,69 @@ export async function generateArtifacts(
|
|
|
155
175
|
if (exitCode !== 0) {
|
|
156
176
|
throw new Error(`better-auth generation failed with exit code ${exitCode}`);
|
|
157
177
|
}
|
|
178
|
+
process.stdout.write(`๐ Auth schema (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
158
179
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
180
|
+
function generatedTsconfig(overrides: Record<string, unknown> = {}) {
|
|
181
|
+
return {
|
|
182
|
+
compilerOptions: {
|
|
183
|
+
lib: ["es2024"],
|
|
184
|
+
types: ["@types/node", "@cloudflare/workers-types/2023-07-01"],
|
|
185
|
+
module: "es2022",
|
|
186
|
+
target: "es2024",
|
|
187
|
+
moduleResolution: "bundler",
|
|
188
|
+
strictNullChecks: true,
|
|
189
|
+
skipLibCheck: true,
|
|
190
|
+
declaration: true,
|
|
191
|
+
emitDeclarationOnly: true,
|
|
192
|
+
noCheck: true,
|
|
193
|
+
jsx: "react-jsx",
|
|
194
|
+
paths: {
|
|
195
|
+
"_generated/*": ["./*"],
|
|
196
|
+
},
|
|
197
|
+
...overrides,
|
|
173
198
|
},
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
199
|
+
include: ["./*.ts", "./client/*.ts"],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
177
202
|
|
|
178
|
-
const
|
|
179
|
-
await Bun.write(
|
|
180
|
-
generatedTsconfigPath,
|
|
181
|
-
`${JSON.stringify(generatedTsconfig, null, 2)}\n`,
|
|
182
|
-
);
|
|
203
|
+
const jsTsconfigPath = resolve(outDirAbs, "tsconfig.js.json");
|
|
183
204
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
205
|
+
await Promise.all([
|
|
206
|
+
Bun.write(
|
|
207
|
+
jsTsconfigPath,
|
|
208
|
+
`${JSON.stringify(generatedTsconfig({ declaration:true,emitDeclarationOnly: false }), null, 2)}\n`,
|
|
209
|
+
),
|
|
210
|
+
]);
|
|
211
|
+
process.stdout.write(`๐ TS configs (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
212
|
+
|
|
213
|
+
async function runTsc(configPath: string, label: string): Promise<void> {
|
|
214
|
+
process.stdout.write(`โ๏ธ ${label}... (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
215
|
+
const p = Bun.spawn([process.execPath, tscBin, "-p", configPath], {
|
|
188
216
|
cwd: outDirAbs,
|
|
189
217
|
stdout: "inherit",
|
|
190
218
|
stderr: "inherit",
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const generatedBuildExitCode = await generatedBuild.exited;
|
|
195
|
-
if (generatedBuildExitCode !== 0) {
|
|
196
|
-
throw new Error(
|
|
197
|
-
`Generated code build failed with exit code ${generatedBuildExitCode}`,
|
|
198
|
-
);
|
|
219
|
+
});
|
|
220
|
+
const code = await p.exited;
|
|
221
|
+
if (code !== 0) throw new Error(`tsc ${label} failed with exit code ${code}`);
|
|
199
222
|
}
|
|
200
223
|
|
|
224
|
+
await runTsc(jsTsconfigPath, "JS files");
|
|
225
|
+
process.stdout.write(`โ
JS + declarations (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
226
|
+
async function removeTsFiles(dir: string): Promise<void> {
|
|
227
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
228
|
+
for (const entry of entries) {
|
|
229
|
+
const fullPath = join(dir, entry.name);
|
|
230
|
+
if (entry.isDirectory()) {
|
|
231
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
232
|
+
await removeTsFiles(fullPath);
|
|
233
|
+
} else if (entry.name.endsWith(".ts") && !entry.name.endsWith(".d.ts")) {
|
|
234
|
+
await rm(fullPath);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
await removeTsFiles(outDirAbs);
|
|
239
|
+
process.stdout.write(`๐ฆ Cleaned .ts files (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
240
|
+
|
|
201
241
|
const generatedDirPrefix = outDirAbs + "/";
|
|
202
242
|
async function cleanDtsOutside(dir: string): Promise<void> {
|
|
203
243
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
@@ -213,19 +253,24 @@ export async function generateArtifacts(
|
|
|
213
253
|
}
|
|
214
254
|
await cleanDtsOutside(fullPath);
|
|
215
255
|
} else if (
|
|
216
|
-
|
|
217
|
-
|
|
256
|
+
!fullPath.startsWith(generatedDirPrefix) && (
|
|
257
|
+
entry.name.endsWith(".d.ts") || (
|
|
258
|
+
entry.name.endsWith(".js"))
|
|
259
|
+
)
|
|
218
260
|
) {
|
|
219
261
|
await rm(fullPath);
|
|
220
262
|
}
|
|
221
263
|
}
|
|
222
264
|
}
|
|
223
265
|
await cleanDtsOutside(configDir);
|
|
266
|
+
process.stdout.write(`๐งน Cleanup (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
267
|
+
|
|
224
268
|
|
|
225
269
|
const tsconfigPath = resolve(configDir, "tsconfig.json");
|
|
226
270
|
if (loadedConfig.config.build && existsSync(tsconfigPath)) {
|
|
271
|
+
process.stdout.write(`โ๏ธ Building project... (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
227
272
|
const tsBuild = Bun.spawn(
|
|
228
|
-
[
|
|
273
|
+
[process.execPath, tscBin, "--build"],
|
|
229
274
|
{
|
|
230
275
|
cwd: configDir,
|
|
231
276
|
stdout: "inherit",
|
|
@@ -239,5 +284,6 @@ export async function generateArtifacts(
|
|
|
239
284
|
`TypeScript build failed with exit code ${tsBuildExitCode}`,
|
|
240
285
|
);
|
|
241
286
|
}
|
|
287
|
+
process.stdout.write(`โ
Build complete (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
242
288
|
}
|
|
243
289
|
}
|