Skip to content

Commit

Permalink
Revert vercel adapter to v1 filesystem API (#3149)
Browse files Browse the repository at this point in the history
* revert to v1 filesystem API

* changeset
  • Loading branch information
Rich-Harris authored Dec 30, 2021
1 parent a1e980f commit a1c02e1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-terms-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-vercel': patch
---

Revert to v1 filesystem API
53 changes: 29 additions & 24 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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, {
Expand All @@ -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'
}
])
);
}
};
Expand Down

0 comments on commit a1c02e1

Please sign in to comment.