From af0488d895c36cbad6f3bc3d4679539af40dffae Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 30 Dec 2021 20:27:08 +0000 Subject: [PATCH 1/2] revert to v1 filesystem API --- packages/adapter-vercel/index.js | 53 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 24 deletions(-) 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' + } + ]) ); } }; From cc49cd5888bef5fe2329d94b2319c22683303803 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 30 Dec 2021 20:27:27 +0000 Subject: [PATCH 2/2] changeset --- .changeset/quiet-terms-fail.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/quiet-terms-fail.md 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