0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-17 23:11:29 -05:00

fix: set default storage path

This commit is contained in:
Matt Kane 2024-11-27 09:56:38 +00:00
parent 666781b07b
commit dd3d990e24
3 changed files with 10 additions and 7 deletions

View file

@ -1,5 +1,5 @@
import { stringify, unflatten } from 'devalue';
import { type Driver, type Storage, builtinDrivers, createStorage } from 'unstorage';
import { type BuiltinDriverOptions, type Driver, type Storage, builtinDrivers, createStorage } from 'unstorage';
import type { SessionConfig, SessionDriverName } from '../types/public/config.js';
import type { AstroCookies } from './cookies/cookies.js';
import type { AstroCookieSetOptions } from './cookies/cookies.js';
@ -353,6 +353,13 @@ export class AstroSession<TDriver extends SessionDriverName = any> {
this.#storage = (this.#config as SessionConfig<'test'>).options.mockStorage;
return this.#storage;
}
// Use fsLite rather than fs, because fs can't be bundled. Add a default base path if not provided.
if(this.#config.driver === 'fs' || this.#config.driver === 'fsLite') {
this.#config.options ??= {};
this.#config.driver = 'fsLite';
(this.#config.options as BuiltinDriverOptions['fsLite']).base ??= '.astro/session';
}
if (!this.#config?.driver) {
throw new AstroError({
...SessionStorageInitError,

View file

@ -25,6 +25,7 @@ export default function vitePluginSessions({ settings }: { settings: AstroSettin
if (driver && driver in builtinDrivers) {
if (driver === 'fs') {
// fs tries to bundle chokidar (and therefore fsevents), which is a binary
// fsLite is identical except it doesn't include a filesystem watcher (which we don't need)
driver = 'fsLite';
}
driver = builtinDrivers[driver as keyof typeof builtinDrivers];

View file

@ -1,18 +1,13 @@
// @ts-check
import { defineConfig } from 'astro/config';
import testAdapter from '../../test-adapter.js';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
export default defineConfig({
adapter: testAdapter(),
output: 'server',
experimental: {
session: {
driver: 'fsLite',
options: {
base: join(tmpdir(), 'sessions'),
},
driver: 'fs',
},
},
});