diff --git a/.changeset/quiet-terms-fail.md b/.changeset/quiet-terms-fail.md new file mode 100644 index 000000000000..de8f9aa2192a --- /dev/null +++ b/.changeset/quiet-terms-fail.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-vercel': patch +--- + +Revert to v1 filesystem API diff --git a/packages/adapter-vercel/index.js b/packages/adapter-vercel/index.js index b2ee92c82070..069a6d02146f 100644 --- a/packages/adapter-vercel/index.js +++ b/packages/adapter-vercel/index.js @@ -3,9 +3,7 @@ import { relative } from 'path'; import { fileURLToPath } from 'url'; import esbuild from 'esbuild'; -// By writing to .output, we opt in to the Vercel filesystem API: -// https://vercel.com/docs/file-system-api -const VERCEL_OUTPUT = '.output'; +const dir = '.vercel_build_output'; /** @type {import('.')} **/ export default function () { @@ -15,17 +13,24 @@ export default function () { async adapt(builder) { const tmp = builder.getBuildDirectory('vercel-tmp'); - builder.rimraf(VERCEL_OUTPUT); + builder.rimraf(dir); builder.rimraf(tmp); + const files = fileURLToPath(new URL('./files', import.meta.url)); + + const dirs = { + static: `${dir}/static`, + lambda: `${dir}/functions/node/render` + }; + builder.log.minor('Prerendering static pages...'); + await builder.prerender({ - dest: `${VERCEL_OUTPUT}/static` + dest: `${dir}/static` }); builder.log.minor('Generating serverless function...'); - const files = fileURLToPath(new URL('./files', import.meta.url)); const relativePath = relative(tmp, builder.getServerDirectory()); builder.copy(files, tmp, { @@ -44,33 +49,33 @@ export default function () { await esbuild.build({ entryPoints: [`${tmp}/entry.js`], - outfile: `${VERCEL_OUTPUT}/server/pages/__render.js`, + outfile: `${dirs.lambda}/index.js`, target: 'node14', bundle: true, platform: 'node' }); - writeFileSync( - `${VERCEL_OUTPUT}/server/pages/package.json`, - JSON.stringify({ type: 'commonjs' }) - ); + writeFileSync(`${dirs.lambda}/package.json`, JSON.stringify({ type: 'commonjs' })); builder.log.minor('Copying assets...'); - builder.writeClient(`${VERCEL_OUTPUT}/static`); - builder.writeStatic(`${VERCEL_OUTPUT}/static`); - builder.log.minor('Writing manifests...'); + builder.writeStatic(dirs.static); + builder.writeClient(dirs.static); + + builder.log.minor('Writing routes...'); + + builder.mkdirp(`${dir}/config`); writeFileSync( - `${VERCEL_OUTPUT}/routes-manifest.json`, - JSON.stringify({ - version: 3, - dynamicRoutes: [ - { - page: '/__render', - regex: '^/.*' - } - ] - }) + `${dir}/config/routes.json`, + JSON.stringify([ + { + handle: 'filesystem' + }, + { + src: '/.*', + dest: '.vercel/functions/render' + } + ]) ); } };