auth 1.6.16 → 1.6.17

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.
Files changed (3) hide show
  1. package/dist/api.mjs +32 -8
  2. package/dist/index.mjs +279 -124
  3. package/package.json +5 -5
package/dist/api.mjs CHANGED
@@ -404,6 +404,16 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
404
404
  return "Int[]";
405
405
  }
406
406
  }
407
+ function getFieldTypeParts(type) {
408
+ const isArray = type.endsWith("[]");
409
+ const typeWithoutArray = isArray ? type.slice(0, -2) : type;
410
+ const isOptional = typeWithoutArray.endsWith("?");
411
+ return {
412
+ fieldType: isOptional ? typeWithoutArray.slice(0, -1) : typeWithoutArray,
413
+ isArray,
414
+ isOptional
415
+ };
416
+ }
407
417
  const prismaModel = builder.findByType("model", { name: modelName });
408
418
  if (!prismaModel) if (provider === "mongodb") builder.model(modelName).field("id", "String").attribute("id").attribute(`map("_id")`);
409
419
  else {
@@ -416,15 +426,9 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
416
426
  for (const field in fields) {
417
427
  const attr = fields[field];
418
428
  const fieldName = attr.fieldName || field;
419
- if (prismaModel) {
420
- if (builder.findByType("field", {
421
- name: fieldName,
422
- within: prismaModel.properties
423
- })) continue;
424
- }
425
429
  const useUUIDs = options.advanced?.database?.generateId === "uuid";
426
430
  const useNumberId = options.advanced?.database?.generateId === "serial";
427
- const fieldBuilder = builder.model(modelName).field(fieldName, field === "id" && useNumberId ? getType({
431
+ const fieldType = field === "id" && useNumberId ? getType({
428
432
  isBigint: false,
429
433
  isOptional: false,
430
434
  type: "number"
@@ -432,7 +436,27 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
432
436
  isBigint: attr?.bigint || false,
433
437
  isOptional: attr?.required === false,
434
438
  type: attr.references?.field === "id" ? useNumberId ? "number" : "string" : attr.type
435
- }));
439
+ });
440
+ if (prismaModel) {
441
+ const isAlreadyExist = builder.findByType("field", {
442
+ name: fieldName,
443
+ within: prismaModel.properties
444
+ });
445
+ if (isAlreadyExist) {
446
+ if (fieldType && typeof isAlreadyExist.fieldType === "string") {
447
+ const fieldTypeParts = getFieldTypeParts(fieldType);
448
+ const existingFieldTypeParts = getFieldTypeParts(isAlreadyExist.fieldType);
449
+ if ((existingFieldTypeParts.fieldType === "Int" || existingFieldTypeParts.fieldType === "BigInt") && (fieldTypeParts.fieldType === "Int" || fieldTypeParts.fieldType === "BigInt")) {
450
+ isAlreadyExist.fieldType = fieldTypeParts.fieldType;
451
+ isAlreadyExist.optional = fieldTypeParts.isOptional || void 0;
452
+ isAlreadyExist.array = fieldTypeParts.isArray || void 0;
453
+ }
454
+ }
455
+ continue;
456
+ }
457
+ }
458
+ if (!fieldType) throw new Error(`Unsupported Prisma field type for model "${modelName}", field "${fieldName}"${attr.type ? ` (source type: "${attr.type}")` : ""}.`);
459
+ const fieldBuilder = builder.model(modelName).field(fieldName, fieldType);
436
460
  if (field === "id") {
437
461
  fieldBuilder.attribute("id");
438
462
  if (provider === "mongodb") fieldBuilder.attribute(`map("_id")`);
package/dist/index.mjs CHANGED
@@ -1059,6 +1059,16 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
1059
1059
  return "Int[]";
1060
1060
  }
1061
1061
  }
1062
+ function getFieldTypeParts(type) {
1063
+ const isArray = type.endsWith("[]");
1064
+ const typeWithoutArray = isArray ? type.slice(0, -2) : type;
1065
+ const isOptional = typeWithoutArray.endsWith("?");
1066
+ return {
1067
+ fieldType: isOptional ? typeWithoutArray.slice(0, -1) : typeWithoutArray,
1068
+ isArray,
1069
+ isOptional
1070
+ };
1071
+ }
1062
1072
  const prismaModel = builder.findByType("model", { name: modelName });
1063
1073
  if (!prismaModel) if (provider === "mongodb") builder.model(modelName).field("id", "String").attribute("id").attribute(`map("_id")`);
1064
1074
  else {
@@ -1071,15 +1081,9 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
1071
1081
  for (const field in fields) {
1072
1082
  const attr = fields[field];
1073
1083
  const fieldName = attr.fieldName || field;
1074
- if (prismaModel) {
1075
- if (builder.findByType("field", {
1076
- name: fieldName,
1077
- within: prismaModel.properties
1078
- })) continue;
1079
- }
1080
1084
  const useUUIDs = options.advanced?.database?.generateId === "uuid";
1081
1085
  const useNumberId = options.advanced?.database?.generateId === "serial";
1082
- const fieldBuilder = builder.model(modelName).field(fieldName, field === "id" && useNumberId ? getType({
1086
+ const fieldType = field === "id" && useNumberId ? getType({
1083
1087
  isBigint: false,
1084
1088
  isOptional: false,
1085
1089
  type: "number"
@@ -1087,7 +1091,27 @@ const generatePrismaSchema = async ({ adapter, options, file }) => {
1087
1091
  isBigint: attr?.bigint || false,
1088
1092
  isOptional: attr?.required === false,
1089
1093
  type: attr.references?.field === "id" ? useNumberId ? "number" : "string" : attr.type
1090
- }));
1094
+ });
1095
+ if (prismaModel) {
1096
+ const isAlreadyExist = builder.findByType("field", {
1097
+ name: fieldName,
1098
+ within: prismaModel.properties
1099
+ });
1100
+ if (isAlreadyExist) {
1101
+ if (fieldType && typeof isAlreadyExist.fieldType === "string") {
1102
+ const fieldTypeParts = getFieldTypeParts(fieldType);
1103
+ const existingFieldTypeParts = getFieldTypeParts(isAlreadyExist.fieldType);
1104
+ if ((existingFieldTypeParts.fieldType === "Int" || existingFieldTypeParts.fieldType === "BigInt") && (fieldTypeParts.fieldType === "Int" || fieldTypeParts.fieldType === "BigInt")) {
1105
+ isAlreadyExist.fieldType = fieldTypeParts.fieldType;
1106
+ isAlreadyExist.optional = fieldTypeParts.isOptional || void 0;
1107
+ isAlreadyExist.array = fieldTypeParts.isArray || void 0;
1108
+ }
1109
+ }
1110
+ continue;
1111
+ }
1112
+ }
1113
+ if (!fieldType) throw new Error(`Unsupported Prisma field type for model "${modelName}", field "${fieldName}"${attr.type ? ` (source type: "${attr.type}")` : ""}.`);
1114
+ const fieldBuilder = builder.model(modelName).field(fieldName, fieldType);
1091
1115
  if (field === "id") {
1092
1116
  fieldBuilder.attribute("id");
1093
1117
  if (provider === "mongodb") fieldBuilder.attribute(`map("_id")`);
@@ -1231,7 +1255,25 @@ const generateSchema = (opts) => {
1231
1255
  throw new Error(`${adapter.id} is not supported. If it is a custom adapter, please request the maintainer to implement createSchema`);
1232
1256
  };
1233
1257
  //#endregion
1234
- //#region src/utils/add-cloudflare-modules.ts
1258
+ //#region src/utils/cloudflare-virtual-modules.ts
1259
+ /**
1260
+ * `cloudflare:workers` is a Workers-runtime built-in module. The CLI loads
1261
+ * `auth.ts` with jiti, outside that runtime, so a config importing it would
1262
+ * crash. It is aliased to an inert stub whose named exports mirror the real
1263
+ * module so every import links.
1264
+ *
1265
+ * Like the SvelteKit stubs, these are *named* exports that must exist at link
1266
+ * time, so the surface is enumerated by hand. The list mirrors workerd's
1267
+ * `cloudflare:workers` re-export module: the entrypoint/RPC classes are real
1268
+ * classes (so `extends` works), and the value/helper exports are recursive
1269
+ * proxies that absorb any access (so `env.MY_BINDING.get()` does not throw).
1270
+ *
1271
+ * `cloudflare:test` is intentionally NOT stubbed: it is a different module with
1272
+ * a different surface, provided only by `@cloudflare/vitest-pool-workers` for
1273
+ * test runs, and an auth config never imports it.
1274
+ *
1275
+ * @see https://github.com/cloudflare/workerd/blob/main/src/cloudflare/workers.ts
1276
+ */
1235
1277
  const createModule = () => {
1236
1278
  return `data:text/javascript;charset=utf-8,${encodeURIComponent(`
1237
1279
  const createStub = (label) => {
@@ -1244,15 +1286,14 @@ const createStub = (label) => {
1244
1286
  if (prop === "then") return undefined;
1245
1287
  return createStub(label + "." + String(prop));
1246
1288
  },
1247
- apply(_, __, args) {
1248
- return createStub(label + "()")
1289
+ apply() {
1290
+ return createStub(label + "()");
1249
1291
  },
1250
1292
  construct() {
1251
1293
  return createStub(label + "#instance");
1252
1294
  },
1253
1295
  };
1254
- const fn = () => createStub(label + "()");
1255
- return new Proxy(fn, handler);
1296
+ return new Proxy(function () {}, handler);
1256
1297
  };
1257
1298
 
1258
1299
  class WorkerEntrypoint {
@@ -1261,141 +1302,204 @@ class WorkerEntrypoint {
1261
1302
  this.env = env;
1262
1303
  }
1263
1304
  }
1264
-
1265
1305
  class DurableObject {
1266
- constructor(state, env) {
1267
- this.state = state;
1306
+ constructor(ctx, env) {
1307
+ this.ctx = ctx;
1268
1308
  this.env = env;
1269
1309
  }
1270
1310
  }
1271
-
1272
- class RpcTarget {
1273
- constructor(value) {
1274
- this.value = value;
1311
+ class WorkflowEntrypoint {
1312
+ constructor(ctx, env) {
1313
+ this.ctx = ctx;
1314
+ this.env = env;
1275
1315
  }
1276
1316
  }
1277
-
1278
- const RpcStub = RpcTarget;
1317
+ class RpcTarget {}
1318
+ class RpcStub {}
1319
+ class RpcPromise {}
1320
+ class RpcProperty {}
1321
+ class ServiceStub {}
1279
1322
 
1280
1323
  const env = createStub("env");
1281
- const caches = createStub("caches");
1282
- const scheduler = createStub("scheduler");
1283
- const executionCtx = createStub("executionCtx");
1324
+ const exportsStub = createStub("exports");
1325
+ const cache = createStub("cache");
1326
+ const tracing = createStub("tracing");
1327
+ const withEnv = createStub("withEnv");
1328
+ const withExports = createStub("withExports");
1329
+ const withEnvAndExports = createStub("withEnvAndExports");
1330
+ const waitUntil = createStub("waitUntil");
1331
+ const abortIsolate = createStub("abortIsolate");
1284
1332
 
1285
- export { DurableObject, RpcStub, RpcTarget, WorkerEntrypoint, caches, env, executionCtx, scheduler };
1286
-
1287
- const defaultExport = {
1333
+ export {
1334
+ WorkerEntrypoint,
1288
1335
  DurableObject,
1289
- RpcStub,
1336
+ WorkflowEntrypoint,
1290
1337
  RpcTarget,
1291
- WorkerEntrypoint,
1292
- caches,
1338
+ RpcStub,
1339
+ RpcPromise,
1340
+ RpcProperty,
1341
+ ServiceStub,
1293
1342
  env,
1294
- executionCtx,
1295
- scheduler,
1343
+ exportsStub as exports,
1344
+ cache,
1345
+ tracing,
1346
+ withEnv,
1347
+ withExports,
1348
+ withEnvAndExports,
1349
+ waitUntil,
1350
+ abortIsolate,
1296
1351
  };
1297
-
1298
- export default defaultExport;
1299
1352
  // jiti dirty hack: .unknown
1300
1353
  `)}`;
1301
1354
  };
1302
1355
  const CLOUDFLARE_STUB_MODULE = createModule();
1303
- function addCloudflareModules(aliases, _cwd) {
1356
+ function addCloudflareVirtualModules(aliases) {
1304
1357
  if (!aliases["cloudflare:workers"]) aliases["cloudflare:workers"] = CLOUDFLARE_STUB_MODULE;
1305
- if (!aliases["cloudflare:test"]) aliases["cloudflare:test"] = CLOUDFLARE_STUB_MODULE;
1306
1358
  }
1307
1359
  //#endregion
1308
- //#region src/utils/add-svelte-kit-env-modules.ts
1360
+ //#region src/utils/sveltekit-virtual-modules.ts
1309
1361
  /**
1310
- * Adds SvelteKit environment modules and path aliases
1311
- * @param aliases - The aliases object to populate
1312
- * @param cwd - Current working directory (optional, defaults to process.cwd())
1362
+ * SvelteKit exposes virtual runtime modules (`$env/*`, `$app/*`,
1363
+ * `$service-worker`) that exist only while its Vite plugin runs. The CLI loads
1364
+ * `auth.ts` with jiti, outside Vite, so a config importing them would crash the
1365
+ * loader. Each is aliased to an inert stub.
1366
+ *
1367
+ * The stubs are injected unconditionally — a non-SvelteKit config never imports
1368
+ * them, so the unused aliases are harmless, and it keeps this free of project
1369
+ * detection. Real path aliases (`$lib` and any `kit.alias`) are deliberately
1370
+ * NOT handled here: `svelte-kit sync` writes them into `.svelte-kit/tsconfig.json`,
1371
+ * which the tsconfig `paths` matcher in `get-config.ts` resolves.
1372
+ *
1373
+ * Why the export surface is enumerated by hand: these are *named* exports, and
1374
+ * ESM requires every imported name to exist at link time, so an opaque or
1375
+ * wildcard stub is impossible. (Vite asset imports are default-export and so
1376
+ * can be matched by rule in `vite-virtual-modules.ts`; a static analyzer can
1377
+ * ignore these opaquely because it never runs the module — we do, so we have to
1378
+ * provide runnable exports.) The shapes mirror SvelteKit's public, documented
1379
+ * surface, which is the stable contract; the internal `__sveltekit/*` virtual
1380
+ * modules the real files depend on are not, which is why we stub `$app/*`
1381
+ * directly rather than resolving SvelteKit's on-disk files.
1382
+ *
1383
+ * The authoritative export surfaces this mirrors:
1384
+ *
1385
+ * @see https://github.com/sveltejs/kit/tree/main/packages/kit/src/runtime/app
1386
+ * @see https://github.com/sveltejs/kit/blob/main/packages/kit/src/types/ambient.d.ts
1313
1387
  */
1314
- function addSvelteKitEnvModules(aliases, cwd) {
1315
- const workingDir = cwd || process.cwd();
1316
- aliases["$env/dynamic/private"] = createDataUriModule(createDynamicEnvModule());
1317
- aliases["$env/dynamic/public"] = createDataUriModule(createDynamicEnvModule());
1318
- aliases["$env/static/private"] = createDataUriModule(createStaticEnvModule(filterPrivateEnv("PUBLIC_", "")));
1319
- aliases["$env/static/public"] = createDataUriModule(createStaticEnvModule(filterPublicEnv("PUBLIC_", "")));
1320
- const svelteKitAliases = getSvelteKitPathAliases(workingDir);
1321
- Object.assign(aliases, svelteKitAliases);
1322
- }
1323
- function getSvelteKitPathAliases(cwd) {
1324
- const aliases = {};
1325
- const packageJsonPath = path.join(cwd, "package.json");
1326
- const svelteConfigPath = path.join(cwd, "svelte.config.js");
1327
- const svelteConfigTsPath = path.join(cwd, "svelte.config.ts");
1328
- let isSvelteKitProject = false;
1329
- if (fs.existsSync(packageJsonPath)) try {
1330
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
1331
- isSvelteKitProject = !!{
1332
- ...packageJson.dependencies,
1333
- ...packageJson.devDependencies
1334
- }["@sveltejs/kit"];
1335
- } catch {}
1336
- if (!isSvelteKitProject) isSvelteKitProject = fs.existsSync(svelteConfigPath) || fs.existsSync(svelteConfigTsPath);
1337
- if (!isSvelteKitProject) return aliases;
1338
- const libPaths = [path.join(cwd, "src", "lib"), path.join(cwd, "lib")];
1339
- for (const libPath of libPaths) if (fs.existsSync(libPath)) {
1340
- aliases["$lib"] = libPath;
1341
- for (const subPath of [
1342
- "server",
1343
- "utils",
1344
- "components",
1345
- "stores"
1346
- ]) {
1347
- const subDir = path.join(libPath, subPath);
1348
- if (fs.existsSync(subDir)) aliases[`$lib/${subPath}`] = subDir;
1349
- }
1350
- break;
1351
- }
1352
- aliases["$app/server"] = createDataUriModule(createAppServerModule());
1353
- const customAliases = getSvelteConfigAliases(cwd);
1354
- Object.assign(aliases, customAliases);
1355
- return aliases;
1388
+ function addSvelteKitVirtualModules(aliases) {
1389
+ aliases["$env/dynamic/private"] = createStubModule(createDynamicEnvModule("private"));
1390
+ aliases["$env/dynamic/public"] = createStubModule(createDynamicEnvModule("public"));
1391
+ aliases["$env/static/private"] = createStubModule(createStaticEnvModule(filterPrivateEnv("PUBLIC_", "")));
1392
+ aliases["$env/static/public"] = createStubModule(createStaticEnvModule(filterPublicEnv("PUBLIC_", "")));
1393
+ for (const [id, body] of Object.entries(appModuleStubs)) aliases[id] = createStubModule(body);
1356
1394
  }
1357
- function getSvelteConfigAliases(cwd) {
1358
- const aliases = {};
1359
- const configPaths = [path.join(cwd, "svelte.config.js"), path.join(cwd, "svelte.config.ts")];
1360
- for (const configPath of configPaths) if (fs.existsSync(configPath)) {
1361
- try {
1362
- const aliasMatch = fs.readFileSync(configPath, "utf-8").match(/alias\s*:\s*\{([^}]+)\}/);
1363
- if (aliasMatch && aliasMatch[1]) {
1364
- const aliasMatches = aliasMatch[1].matchAll(/['"`](\$[^'"`]+)['"`]\s*:\s*['"`]([^'"`]+)['"`]/g);
1365
- for (const match of aliasMatches) {
1366
- const [, alias, target] = match;
1367
- if (alias && target) {
1368
- aliases[alias + "/*"] = path.resolve(cwd, target) + "/*";
1369
- aliases[alias] = path.resolve(cwd, target);
1370
- }
1371
- }
1372
- }
1373
- } catch {}
1374
- break;
1375
- }
1376
- return aliases;
1377
- }
1378
- function createAppServerModule() {
1379
- return `
1380
- // $app/server stub for CLI compatibility
1381
- export default {};
1382
- // jiti dirty hack: .unknown
1395
+ /**
1396
+ * `$app/env` is SvelteKit's alias for `$app/environment` with an identical
1397
+ * export surface, so both specifiers share this body.
1398
+ * @see https://github.com/sveltejs/kit/pull/15934
1399
+ */
1400
+ const environmentStub = `
1401
+ export const browser = false;
1402
+ export const building = false;
1403
+ export const dev = false;
1404
+ export const version = "";
1383
1405
  `;
1384
- }
1385
- function createDataUriModule(module) {
1386
- return `data:text/javascript;charset=utf-8,${encodeURIComponent(module)}`;
1406
+ /**
1407
+ * Specifier → module source for the inert `$app/*` and `$service-worker`
1408
+ * stubs. The bodies do nothing (the CLI never serves a request); they exist
1409
+ * only so every name a config might import resolves. Keep each entry aligned
1410
+ * with SvelteKit's documented exports.
1411
+ * @see https://svelte.dev/docs/kit/$app-environment
1412
+ * @see https://svelte.dev/docs/kit/$app-server
1413
+ * @see https://svelte.dev/docs/kit/$service-worker
1414
+ */
1415
+ const appModuleStubs = {
1416
+ "$app/environment": environmentStub,
1417
+ "$app/env": environmentStub,
1418
+ "$app/server": `
1419
+ export function getRequestEvent() {}
1420
+ export function read() {}
1421
+ export function query() {}
1422
+ export function prerender() {}
1423
+ export function command() {}
1424
+ export function form() {}
1425
+ export const requested = false;
1426
+ `,
1427
+ "$app/paths": `
1428
+ export const base = "";
1429
+ export const assets = "";
1430
+ export function resolve(path) { return path; }
1431
+ export function resolveRoute(path) { return path; }
1432
+ export function asset(value) { return value; }
1433
+ export async function match() { return null; }
1434
+ `,
1435
+ "$app/navigation": `
1436
+ export function goto() {}
1437
+ export function invalidate() {}
1438
+ export function invalidateAll() {}
1439
+ export function preloadData() {}
1440
+ export function preloadCode() {}
1441
+ export function beforeNavigate() {}
1442
+ export function afterNavigate() {}
1443
+ export function onNavigate() {}
1444
+ export function disableScrollHandling() {}
1445
+ export function pushState() {}
1446
+ export function replaceState() {}
1447
+ export function refreshAll() {}
1448
+ `,
1449
+ "$app/state": `
1450
+ export const page = {};
1451
+ export const navigating = {};
1452
+ export const updated = { check() { return Promise.resolve(false); } };
1453
+ `,
1454
+ "$app/stores": `
1455
+ export const page = { subscribe() { return () => {}; } };
1456
+ export const navigating = { subscribe() { return () => {}; } };
1457
+ export const updated = { subscribe() { return () => {}; }, check() { return Promise.resolve(false); } };
1458
+ export function getStores() { return { page, navigating, updated }; }
1459
+ `,
1460
+ "$app/forms": `
1461
+ export function applyAction() {}
1462
+ export function deserialize() {}
1463
+ export function enhance() {}
1464
+ `,
1465
+ "$service-worker": `
1466
+ export const base = "";
1467
+ export const build = [];
1468
+ export const files = [];
1469
+ export const prerendered = [];
1470
+ export const version = "";
1471
+ `
1472
+ };
1473
+ /**
1474
+ * Wraps a module body as a `data:` URI for use as a jiti alias target. The
1475
+ * trailing marker is load-bearing: without an "extension", jiti resolves the
1476
+ * alias value as a file path and fails with ENOENT, so the comment gives it an
1477
+ * unknown extension and forces a native import instead. (Stubs injected by the
1478
+ * Babel plugin in `vite-virtual-modules.ts` set the specifier directly and do
1479
+ * not go through alias resolution, so they need no marker.)
1480
+ */
1481
+ function createStubModule(body) {
1482
+ const source = `${body}\n// jiti dirty hack: .unknown\n`;
1483
+ return `data:text/javascript;charset=utf-8,${encodeURIComponent(source)}`;
1387
1484
  }
1388
1485
  function createStaticEnvModule(env) {
1389
- return `
1390
- ${Object.keys(env).filter((k) => validIdentifier.test(k) && !reserved.has(k)).map((k) => `export const ${k} = ${JSON.stringify(env[k])};`).join("\n")}
1391
- // jiti dirty hack: .unknown
1392
- `;
1486
+ return Object.keys(env).filter((k) => validIdentifier.test(k) && !reserved.has(k)).map((k) => `export const ${k} = ${JSON.stringify(env[k])};`).join("\n");
1393
1487
  }
1394
- function createDynamicEnvModule() {
1488
+ function createDynamicEnvModule(visibility) {
1395
1489
  return `
1396
- export const env = process.env;
1397
- // jiti dirty hack: .unknown
1398
- `;
1490
+ const keep = (key) => typeof key === "string" && ${visibility === "public" ? `key.startsWith("PUBLIC_")` : `!key.startsWith("PUBLIC_")`};
1491
+ export const env = new Proxy(
1492
+ {},
1493
+ {
1494
+ get: (_, key) => (keep(key) ? process.env[key] : undefined),
1495
+ has: (_, key) => keep(key) && key in process.env,
1496
+ ownKeys: () => Object.keys(process.env).filter(keep),
1497
+ getOwnPropertyDescriptor: (_, key) =>
1498
+ keep(key) && key in process.env
1499
+ ? { value: process.env[key], enumerable: true, configurable: true }
1500
+ : undefined,
1501
+ },
1502
+ );`;
1399
1503
  }
1400
1504
  function filterPrivateEnv(publicPrefix, privatePrefix) {
1401
1505
  return Object.fromEntries(Object.entries(process.env).filter(([k]) => k.startsWith(privatePrefix) && (publicPrefix === "" || !k.startsWith(publicPrefix))));
@@ -1455,6 +1559,50 @@ const reserved = new Set([
1455
1559
  "instanceof"
1456
1560
  ]);
1457
1561
  //#endregion
1562
+ //#region src/utils/vite-virtual-modules.ts
1563
+ /**
1564
+ * Stub modules for Vite's "special" imports (asset and query-suffixed
1565
+ * modules). Vite resolves these through its plugin pipeline at build time; the
1566
+ * CLI loads auth configs with jiti, where no such pipeline exists and there is
1567
+ * no file on disk to read. Without a substitute, a config that transitively
1568
+ * imports e.g. `./logo.svg`, `./app.css?inline`, or `./worker.ts?worker`
1569
+ * crashes the loader.
1570
+ *
1571
+ * Detection mirrors Vite's own classification. The query-suffix patterns are
1572
+ * tested against the full specifier, the extension membership against the
1573
+ * specifier with its query stripped, and query patterns take precedence over
1574
+ * extension membership (so `./a.css?raw` is raw text, not a stylesheet). The
1575
+ * regexes are not part of Vite's public API, so they are copied here.
1576
+ *
1577
+ * @see https://github.com/vitejs/vite/blob/main/packages/vite/src/node/constants.ts
1578
+ * @see https://github.com/vitejs/vite/blob/main/packages/vite/src/node/plugins/asset.ts
1579
+ */
1580
+ const WORKER_RE = /[?&](?:worker|sharedworker)(?:&|$)/;
1581
+ const URL_RE = /[?&]url(?:&|$)/;
1582
+ const RAW_RE = /[?&]raw(?:&|$)/;
1583
+ const INLINE_RE = /[?&]inline(?:&|$)/;
1584
+ const WASM_INIT_RE = /\.wasm\?init\b/;
1585
+ const CSS_MODULE_RE = /\.module\.(?:css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
1586
+ const CSS_LANGS_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
1587
+ const KNOWN_ASSET_RE = /\.(?:apng|bmp|png|jpe?g|jfif|pjpeg|pjp|gif|svg|ico|webp|avif|cur|jxl|mp4|webm|ogg|mp3|wav|flac|aac|opus|mov|m4a|vtt|woff2?|eot|ttf|otf|webmanifest|pdf|txt)(?:\?.*)?$/i;
1588
+ function createDataUriModule(body) {
1589
+ return `data:text/javascript;charset=utf-8,${encodeURIComponent(body)}`;
1590
+ }
1591
+ /**
1592
+ * Returns a data-URI stub module for a Vite special import, or `undefined`
1593
+ * when the specifier is an ordinary module that should resolve normally. The
1594
+ * stub's runtime shape matches what Vite would emit (a string for raw/url, a
1595
+ * worker constructor, a class-name proxy for CSS Modules, and so on).
1596
+ */
1597
+ function getViteAssetStub(specifier) {
1598
+ if (WORKER_RE.test(specifier)) return createDataUriModule(URL_RE.test(specifier) ? `export default "";` : `export default function () {};`);
1599
+ if (WASM_INIT_RE.test(specifier)) return createDataUriModule(`export default async () => ({ exports: {} });`);
1600
+ if (RAW_RE.test(specifier) || INLINE_RE.test(specifier) || URL_RE.test(specifier)) return createDataUriModule(`export default "";`);
1601
+ if (CSS_MODULE_RE.test(specifier)) return createDataUriModule(`export default new Proxy({}, { get: (_, key) => String(key) });`);
1602
+ if (CSS_LANGS_RE.test(specifier)) return createDataUriModule(`export default undefined;`);
1603
+ if (KNOWN_ASSET_RE.test(specifier)) return createDataUriModule(`export default "";`);
1604
+ }
1605
+ //#endregion
1458
1606
  //#region src/utils/get-config.ts
1459
1607
  let possiblePaths$1 = [
1460
1608
  "auth.ts",
@@ -1596,6 +1744,11 @@ function createRewriteImportPathsPlugin(matchers) {
1596
1744
  return ({ types: t }) => {
1597
1745
  const rewrite = (source) => {
1598
1746
  if (!source) return;
1747
+ const stub = getViteAssetStub(source.value);
1748
+ if (stub) {
1749
+ source.value = stub;
1750
+ return;
1751
+ }
1599
1752
  const resolved = resolveWithMatchers(source.value, matchers);
1600
1753
  if (resolved) source.value = resolved;
1601
1754
  };
@@ -1625,16 +1778,15 @@ function createRewriteImportPathsPlugin(matchers) {
1625
1778
  /** Virtual module aliases; real tsconfig paths go through the babel plugin. */
1626
1779
  function getVirtualModuleAliases() {
1627
1780
  const result = {};
1628
- addSvelteKitEnvModules(result);
1629
- addCloudflareModules(result);
1781
+ addSvelteKitVirtualModules(result);
1782
+ addCloudflareVirtualModules(result);
1630
1783
  return result;
1631
1784
  }
1632
1785
  /**
1633
1786
  * .tsx files are not supported by Jiti.
1634
1787
  */
1635
1788
  const jitiOptions = (cwd) => {
1636
- const matchers = collectPathsMatchers(cwd);
1637
- const plugins = matchers.length > 0 ? [createRewriteImportPathsPlugin(matchers)] : [];
1789
+ const plugins = [createRewriteImportPathsPlugin(collectPathsMatchers(cwd))];
1638
1790
  return {
1639
1791
  transformOptions: { babel: {
1640
1792
  presets: [[babelPresetTypeScript, {
@@ -1748,6 +1900,9 @@ function createMockAdapter$1(adapterId, dialect) {
1748
1900
  consumeOne: async () => {
1749
1901
  throw new Error("Mock adapter methods should not be called");
1750
1902
  },
1903
+ incrementOne: async () => {
1904
+ throw new Error("Mock adapter methods should not be called");
1905
+ },
1751
1906
  transaction: async (callback) => {
1752
1907
  throw new Error("Mock adapter methods should not be called");
1753
1908
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auth",
3
- "version": "1.6.16",
3
+ "version": "1.6.17",
4
4
  "description": "The CLI for Better Auth",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -60,9 +60,9 @@
60
60
  "semver": "^7.7.4",
61
61
  "yocto-spinner": "^0.2.3",
62
62
  "zod": "^4.3.6",
63
- "@better-auth/core": "1.6.16",
64
- "@better-auth/telemetry": "1.6.16",
65
- "better-auth": "1.6.16"
63
+ "@better-auth/core": "1.6.17",
64
+ "@better-auth/telemetry": "1.6.17",
65
+ "better-auth": "1.6.17"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/better-sqlite3": "^7.6.13",
@@ -75,7 +75,7 @@
75
75
  "tsx": "^4.21.0",
76
76
  "type-fest": "^5.4.4",
77
77
  "typescript": "^5.9.3",
78
- "@better-auth/passkey": "1.6.16"
78
+ "@better-auth/passkey": "1.6.17"
79
79
  },
80
80
  "scripts": {
81
81
  "build": "tsdown",