appflare 0.2.32 โ 0.2.34
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 +87 -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,70 @@ 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", "bun", "@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
|
-
|
|
195
|
-
if (generatedBuildExitCode !== 0) {
|
|
196
|
-
throw new Error(
|
|
197
|
-
`Generated code build failed with exit code ${generatedBuildExitCode}`,
|
|
198
|
-
);
|
|
219
|
+
});
|
|
220
|
+
console.log(process.execPath, tscBin, "-p", configPath, { cwd: outDirAbs });
|
|
221
|
+
const code = await p.exited;
|
|
222
|
+
if (code !== 0) throw new Error(`tsc ${label} failed with exit code ${code}`);
|
|
199
223
|
}
|
|
200
224
|
|
|
225
|
+
await runTsc(jsTsconfigPath, "JS files");
|
|
226
|
+
process.stdout.write(`โ
JS + declarations (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
227
|
+
async function removeTsFiles(dir: string): Promise<void> {
|
|
228
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
229
|
+
for (const entry of entries) {
|
|
230
|
+
const fullPath = join(dir, entry.name);
|
|
231
|
+
if (entry.isDirectory()) {
|
|
232
|
+
if (entry.name === "node_modules" || entry.name.startsWith(".")) continue;
|
|
233
|
+
await removeTsFiles(fullPath);
|
|
234
|
+
} else if (entry.name.endsWith(".ts") && !entry.name.endsWith(".d.ts")) {
|
|
235
|
+
await rm(fullPath);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
await removeTsFiles(outDirAbs);
|
|
240
|
+
process.stdout.write(`๐ฆ Cleaned .ts files (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
241
|
+
|
|
201
242
|
const generatedDirPrefix = outDirAbs + "/";
|
|
202
243
|
async function cleanDtsOutside(dir: string): Promise<void> {
|
|
203
244
|
const entries = await readdir(dir, { withFileTypes: true });
|
|
@@ -213,19 +254,24 @@ export async function generateArtifacts(
|
|
|
213
254
|
}
|
|
214
255
|
await cleanDtsOutside(fullPath);
|
|
215
256
|
} else if (
|
|
216
|
-
|
|
217
|
-
|
|
257
|
+
!fullPath.startsWith(generatedDirPrefix) && (
|
|
258
|
+
entry.name.endsWith(".d.ts") || (
|
|
259
|
+
entry.name.endsWith(".js"))
|
|
260
|
+
)
|
|
218
261
|
) {
|
|
219
262
|
await rm(fullPath);
|
|
220
263
|
}
|
|
221
264
|
}
|
|
222
265
|
}
|
|
223
266
|
await cleanDtsOutside(configDir);
|
|
267
|
+
process.stdout.write(`๐งน Cleanup (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
268
|
+
|
|
224
269
|
|
|
225
270
|
const tsconfigPath = resolve(configDir, "tsconfig.json");
|
|
226
271
|
if (loadedConfig.config.build && existsSync(tsconfigPath)) {
|
|
272
|
+
process.stdout.write(`โ๏ธ Building project... (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
227
273
|
const tsBuild = Bun.spawn(
|
|
228
|
-
[
|
|
274
|
+
[process.execPath, tscBin, "--build"],
|
|
229
275
|
{
|
|
230
276
|
cwd: configDir,
|
|
231
277
|
stdout: "inherit",
|
|
@@ -239,5 +285,6 @@ export async function generateArtifacts(
|
|
|
239
285
|
`TypeScript build failed with exit code ${tsBuildExitCode}`,
|
|
240
286
|
);
|
|
241
287
|
}
|
|
288
|
+
process.stdout.write(`โ
Build complete (${(performance.now() - t0).toFixed(0)}ms)\n`);
|
|
242
289
|
}
|
|
243
290
|
}
|