aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/fruity-pugs-cross.md5
-rw-r--r--packages/astro/package.json1
-rw-r--r--packages/astro/src/core/build/plugins/plugin-manifest.ts24
-rw-r--r--packages/astro/src/core/session.ts20
-rw-r--r--pnpm-lock.yaml3
5 files changed, 44 insertions, 9 deletions
diff --git a/.changeset/fruity-pugs-cross.md b/.changeset/fruity-pugs-cross.md
new file mode 100644
index 000000000..fac0042df
--- /dev/null
+++ b/.changeset/fruity-pugs-cross.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Fixes an issue where session modules would fail to resolve in Node.js < 20.6
diff --git a/packages/astro/package.json b/packages/astro/package.json
index 9c7c47191..26cf92caf 100644
--- a/packages/astro/package.json
+++ b/packages/astro/package.json
@@ -143,6 +143,7 @@
"github-slugger": "^2.0.0",
"html-escaper": "3.0.3",
"http-cache-semantics": "^4.1.1",
+ "import-meta-resolve": "^4.1.0",
"js-yaml": "^4.1.0",
"kleur": "^4.1.5",
"magic-string": "^0.30.17",
diff --git a/packages/astro/src/core/build/plugins/plugin-manifest.ts b/packages/astro/src/core/build/plugins/plugin-manifest.ts
index cd7f62a82..ee5b47ab9 100644
--- a/packages/astro/src/core/build/plugins/plugin-manifest.ts
+++ b/packages/astro/src/core/build/plugins/plugin-manifest.ts
@@ -1,6 +1,8 @@
import { fileURLToPath } from 'node:url';
+import { resolve as importMetaResolve } from 'import-meta-resolve';
import type { OutputChunk } from 'rollup';
import { glob } from 'tinyglobby';
+import { builtinDrivers, type BuiltinDriverName } from 'unstorage';
import type { Plugin as VitePlugin } from 'vite';
import { getAssetsPrefix } from '../../../assets/utils/getAssetsPrefix.js';
import { normalizeTheLocale } from '../../../i18n/index.js';
@@ -16,7 +18,6 @@ import { encodeKey } from '../../encryption.js';
import { fileExtension, joinPaths, prependForwardSlash } from '../../path.js';
import { DEFAULT_COMPONENTS } from '../../routing/default.js';
import { serializeRouteData } from '../../routing/index.js';
-import { resolveSessionDriver } from '../../session.js';
import { addRollupInput } from '../add-rollup-input.js';
import { getOutFile, getOutFolder } from '../common.js';
import { type BuildInternals, cssOrder, mergeInlineCss } from '../internal.js';
@@ -30,6 +31,27 @@ const replaceExp = new RegExp(`['"]${manifestReplace}['"]`, 'g');
export const SSR_MANIFEST_VIRTUAL_MODULE_ID = '@astrojs-manifest';
export const RESOLVED_SSR_MANIFEST_VIRTUAL_MODULE_ID = '\0' + SSR_MANIFEST_VIRTUAL_MODULE_ID;
+function resolveSessionDriver(driver: string | undefined): string | null {
+ if (!driver) {
+ return null;
+ }
+ try {
+ if (driver === 'fs') {
+ return importMetaResolve(builtinDrivers.fsLite, import.meta.url);
+ }
+ if (driver in builtinDrivers) {
+ return importMetaResolve(
+ builtinDrivers[driver as BuiltinDriverName],
+ import.meta.url,
+ );
+ }
+ } catch {
+ return null;
+ }
+
+ return driver;
+}
+
function vitePluginManifest(options: StaticBuildOptions, internals: BuildInternals): VitePlugin {
return {
name: '@astro/plugin-build-manifest',
diff --git a/packages/astro/src/core/session.ts b/packages/astro/src/core/session.ts
index e4d4b40ec..67c48f725 100644
--- a/packages/astro/src/core/session.ts
+++ b/packages/astro/src/core/session.ts
@@ -1,5 +1,7 @@
import { stringify as rawStringify, unflatten as rawUnflatten } from 'devalue';
+
import {
+ type BuiltinDriverName,
type BuiltinDriverOptions,
type Driver,
type Storage,
@@ -447,12 +449,14 @@ export class AstroSession<TDriver extends SessionDriverName = any> {
let driver: ((config: SessionConfig<TDriver>['options']) => Driver) | null = null;
- const driverPackage = await resolveSessionDriver(this.#config.driver);
try {
if (this.#config.driverModule) {
driver = (await this.#config.driverModule()).default;
- } else if (driverPackage) {
- driver = (await import(driverPackage)).default;
+ } else if (this.#config.driver) {
+ const driverName = resolveSessionDriverName(this.#config.driver);
+ if (driverName) {
+ driver = (await import(driverName)).default;
+ }
}
} catch (err: any) {
// If the driver failed to load, throw an error.
@@ -461,7 +465,7 @@ export class AstroSession<TDriver extends SessionDriverName = any> {
{
...SessionStorageInitError,
message: SessionStorageInitError.message(
- err.message.includes(`Cannot find package '${driverPackage}'`)
+ err.message.includes(`Cannot find package`)
? 'The driver module could not be found.'
: err.message,
this.#config.driver,
@@ -500,17 +504,17 @@ export class AstroSession<TDriver extends SessionDriverName = any> {
}
}
}
-// TODO: make this sync when we drop support for Node < 18.19.0
-export async function resolveSessionDriver(driver: string | undefined): Promise<string | null> {
+
+function resolveSessionDriverName(driver: string | undefined): string | null {
if (!driver) {
return null;
}
try {
if (driver === 'fs') {
- return await import.meta.resolve(builtinDrivers.fsLite);
+ return builtinDrivers.fsLite;
}
if (driver in builtinDrivers) {
- return await import.meta.resolve(builtinDrivers[driver as keyof typeof builtinDrivers]);
+ return builtinDrivers[driver as BuiltinDriverName];
}
} catch {
return null;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index adfb2d03f..68a91bb77 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -553,6 +553,9 @@ importers:
http-cache-semantics:
specifier: ^4.1.1
version: 4.1.1
+ import-meta-resolve:
+ specifier: ^4.1.0
+ version: 4.1.0
js-yaml:
specifier: ^4.1.0
version: 4.1.0