@sveltejs/adapter-vercel 1.0.0-next.32 → 1.0.0-next.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,37 +19,6 @@ export default {
19
19
  };
20
20
  ```
21
21
 
22
- ## Advanced Configuration
23
-
24
- ### esbuild
25
-
26
- As an escape hatch, you may optionally specify a function which will receive the final esbuild options generated by this adapter and returns a modified esbuild configuration. The result of this function will be passed as-is to esbuild. The function can be async.
27
-
28
- For example, you may wish to add a plugin:
29
-
30
- ```js
31
- adapterVercel({
32
- esbuild(defaultOptions) {
33
- return {
34
- ...defaultOptions,
35
- plugins: []
36
- };
37
- }
38
- });
39
- ```
40
-
41
- The default options for this version are as follows:
42
-
43
- ```js
44
- {
45
- entryPoints: ['.svelte-kit/vercel/entry.js'],
46
- outfile: `pathToLambdaFolder/index.js`,
47
- bundle: true,
48
- inject: ['pathTo/shims.js'],
49
- platform: 'node'
50
- }
51
- ```
52
-
53
22
  ## Changelog
54
23
 
55
24
  [The Changelog for this package is available on GitHub](https://github.com/sveltejs/kit/blob/master/packages/adapter-vercel/CHANGELOG.md).
package/files/entry.js CHANGED
@@ -1,13 +1,13 @@
1
+ import { __fetch_polyfill } from '@sveltejs/kit/install-fetch';
1
2
  import { getRawBody } from '@sveltejs/kit/node';
3
+ import { App } from 'APP';
4
+ import { manifest } from 'MANIFEST';
2
5
 
3
- // TODO hardcoding the relative location makes this brittle
4
- import { init, render } from '../output/server/app.js';
6
+ __fetch_polyfill();
5
7
 
6
- init();
8
+ const app = new App(manifest);
7
9
 
8
10
  export default async (req, res) => {
9
- const { pathname, searchParams } = new URL(req.url || '', 'http://localhost');
10
-
11
11
  let body;
12
12
 
13
13
  try {
@@ -17,11 +17,10 @@ export default async (req, res) => {
17
17
  return res.end(err.reason || 'Invalid request body');
18
18
  }
19
19
 
20
- const rendered = await render({
20
+ const rendered = await app.render({
21
+ url: req.url,
21
22
  method: req.method,
22
23
  headers: req.headers,
23
- path: pathname,
24
- query: searchParams,
25
24
  rawBody: body
26
25
  });
27
26
 
package/index.d.ts CHANGED
@@ -1,9 +1,4 @@
1
1
  import { Adapter } from '@sveltejs/kit';
2
- import { BuildOptions } from 'esbuild';
3
2
 
4
- interface AdapterOptions {
5
- esbuild?: (options: BuildOptions) => Promise<BuildOptions> | BuildOptions;
6
- }
7
-
8
- declare function plugin(options?: AdapterOptions): Adapter;
3
+ declare function plugin(): Adapter;
9
4
  export = plugin;
package/index.js CHANGED
@@ -1,63 +1,77 @@
1
1
  import { writeFileSync } from 'fs';
2
- import { join } from 'path';
2
+ import { relative } from 'path';
3
3
  import { fileURLToPath } from 'url';
4
4
  import esbuild from 'esbuild';
5
5
 
6
- /**
7
- * @typedef {import('esbuild').BuildOptions} BuildOptions
8
- */
6
+ // By writing to .output, we opt in to the Vercel filesystem API:
7
+ // https://vercel.com/docs/file-system-api
8
+ const VERCEL_OUTPUT = '.output';
9
9
 
10
10
  /** @type {import('.')} **/
11
- export default function (options) {
11
+ export default function () {
12
12
  return {
13
13
  name: '@sveltejs/adapter-vercel',
14
14
 
15
- async adapt({ utils }) {
16
- const dir = '.vercel_build_output';
17
- utils.rimraf(dir);
15
+ async adapt(builder) {
16
+ const tmp = builder.getBuildDirectory('vercel-tmp');
18
17
 
19
- const files = fileURLToPath(new URL('./files', import.meta.url));
18
+ builder.rimraf(VERCEL_OUTPUT);
19
+ builder.rimraf(tmp);
20
20
 
21
- const dirs = {
22
- static: join(dir, 'static'),
23
- lambda: join(dir, 'functions/node/render')
24
- };
25
-
26
- // TODO ideally we'd have something like utils.tmpdir('vercel')
27
- // rather than hardcoding '.svelte-kit/vercel/entry.js', and the
28
- // relative import from that file to output/server/app.js
29
- // would be controlled. at the moment we're exposing
30
- // implementation details that could change
31
- utils.log.minor('Generating serverless function...');
32
- utils.copy(join(files, 'entry.js'), '.svelte-kit/vercel/entry.js');
33
-
34
- /** @type {BuildOptions} */
35
- const default_options = {
36
- entryPoints: ['.svelte-kit/vercel/entry.js'],
37
- outfile: join(dirs.lambda, 'index.js'),
38
- bundle: true,
39
- inject: [join(files, 'shims.js')],
40
- platform: 'node'
41
- };
21
+ builder.log.minor('Prerendering static pages...');
22
+ await builder.prerender({
23
+ dest: `${VERCEL_OUTPUT}/static`
24
+ });
25
+
26
+ builder.log.minor('Generating serverless function...');
42
27
 
43
- const build_options =
44
- options && options.esbuild ? await options.esbuild(default_options) : default_options;
28
+ const files = fileURLToPath(new URL('./files', import.meta.url));
29
+ const relativePath = relative(tmp, builder.getServerDirectory());
45
30
 
46
- await esbuild.build(build_options);
31
+ builder.copy(files, tmp, {
32
+ replace: {
33
+ APP: `${relativePath}/app.js`,
34
+ MANIFEST: './manifest.js'
35
+ }
36
+ });
47
37
 
48
- writeFileSync(join(dirs.lambda, 'package.json'), JSON.stringify({ type: 'commonjs' }));
38
+ writeFileSync(
39
+ `${tmp}/manifest.js`,
40
+ `export const manifest = ${builder.generateManifest({
41
+ relativePath
42
+ })};\n`
43
+ );
49
44
 
50
- utils.log.minor('Prerendering static pages...');
51
- await utils.prerender({
52
- dest: dirs.static
45
+ await esbuild.build({
46
+ entryPoints: [`${tmp}/entry.js`],
47
+ outfile: `${VERCEL_OUTPUT}/server/pages/__render.js`,
48
+ target: 'node14',
49
+ bundle: true,
50
+ platform: 'node'
53
51
  });
54
52
 
55
- utils.log.minor('Copying assets...');
56
- utils.copy_static_files(dirs.static);
57
- utils.copy_client_files(dirs.static);
53
+ writeFileSync(
54
+ `${VERCEL_OUTPUT}/server/pages/package.json`,
55
+ JSON.stringify({ type: 'commonjs' })
56
+ );
57
+
58
+ builder.log.minor('Copying assets...');
59
+ builder.writeClient(`${VERCEL_OUTPUT}/static`);
60
+ builder.writeStatic(`${VERCEL_OUTPUT}/static`);
58
61
 
59
- utils.log.minor('Writing routes...');
60
- utils.copy(join(files, 'routes.json'), join(dir, 'config/routes.json'));
62
+ builder.log.minor('Writing manifests...');
63
+ writeFileSync(
64
+ `${VERCEL_OUTPUT}/routes-manifest.json`,
65
+ JSON.stringify({
66
+ version: 3,
67
+ dynamicRoutes: [
68
+ {
69
+ page: '/__render',
70
+ regex: '^/.*'
71
+ }
72
+ ]
73
+ })
74
+ );
61
75
  }
62
76
  };
63
77
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "1.0.0-next.32",
3
+ "version": "1.0.0-next.33",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -25,7 +25,7 @@
25
25
  "esbuild": "^0.13.15"
26
26
  },
27
27
  "devDependencies": {
28
- "@sveltejs/kit": "1.0.0-next.202"
28
+ "@sveltejs/kit": "1.0.0-next.208"
29
29
  },
30
30
  "scripts": {
31
31
  "lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
package/files/routes.json DELETED
@@ -1,9 +0,0 @@
1
- [
2
- {
3
- "handle": "filesystem"
4
- },
5
- {
6
- "src": "/.*",
7
- "dest": ".vercel/functions/render"
8
- }
9
- ]
package/files/shims.js DELETED
@@ -1 +0,0 @@
1
- export { fetch, Response, Request, Headers } from '@sveltejs/kit/install-fetch';