@sveltejs/adapter-vercel 4.0.5 → 5.0.0

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.
@@ -1,5 +1,5 @@
1
1
  import { installPolyfills } from '@sveltejs/kit/node/polyfills';
2
- import { getRequest, setResponse } from '@sveltejs/kit/node';
2
+ import { getRequest, setResponse, createReadableStream } from '@sveltejs/kit/node';
3
3
  import { Server } from 'SERVER';
4
4
  import { manifest } from 'MANIFEST';
5
5
 
@@ -8,7 +8,8 @@ installPolyfills();
8
8
  const server = new Server(manifest);
9
9
 
10
10
  await server.init({
11
- env: /** @type {Record<string, string>} */ (process.env)
11
+ env: /** @type {Record<string, string>} */ (process.env),
12
+ read: createReadableStream
12
13
  });
13
14
 
14
15
  const DATA_SUFFIX = '/__data.json';
package/index.js CHANGED
@@ -5,6 +5,7 @@ import { nodeFileTrace } from '@vercel/nft';
5
5
  import esbuild from 'esbuild';
6
6
  import { get_pathname } from './utils.js';
7
7
 
8
+ const name = '@sveltejs/adapter-vercel';
8
9
  const DEFAULT_FUNCTION_NAME = 'fn';
9
10
 
10
11
  const get_default_runtime = () => {
@@ -24,7 +25,7 @@ const plugin = function (defaults = {}) {
24
25
  }
25
26
 
26
27
  return {
27
- name: '@sveltejs/adapter-vercel',
28
+ name,
28
29
 
29
30
  async adapt(builder) {
30
31
  if (!builder.routes) {
@@ -63,6 +64,8 @@ const plugin = function (defaults = {}) {
63
64
  * @param {import('@sveltejs/kit').RouteDefinition<import('.').Config>[]} routes
64
65
  */
65
66
  async function generate_serverless_function(name, config, routes) {
67
+ const dir = `${dirs.functions}/${name}.func`;
68
+
66
69
  const relativePath = path.posix.relative(tmp, builder.getServerDirectory());
67
70
 
68
71
  builder.copy(`${files}/serverless.js`, `${tmp}/index.js`, {
@@ -77,12 +80,12 @@ const plugin = function (defaults = {}) {
77
80
  `export const manifest = ${builder.generateManifest({ relativePath, routes })};\n`
78
81
  );
79
82
 
80
- await create_function_bundle(
81
- builder,
82
- `${tmp}/index.js`,
83
- `${dirs.functions}/${name}.func`,
84
- config
85
- );
83
+ await create_function_bundle(builder, `${tmp}/index.js`, dir, config);
84
+
85
+ for (const asset of builder.findServerAssets(routes)) {
86
+ // TODO use symlinks, once Build Output API supports doing so
87
+ builder.copy(`${builder.getServerDirectory()}/${asset}`, `${dir}/${asset}`);
88
+ }
86
89
  }
87
90
 
88
91
  /**
@@ -335,6 +338,21 @@ const plugin = function (defaults = {}) {
335
338
  builder.log.minor('Writing routes...');
336
339
 
337
340
  write(`${dir}/config.json`, JSON.stringify(static_config, null, '\t'));
341
+ },
342
+
343
+ supports: {
344
+ // reading from the filesystem only works in serverless functions
345
+ read: ({ config, route }) => {
346
+ const runtime = config.runtime ?? defaults.runtime;
347
+
348
+ if (runtime === 'edge') {
349
+ throw new Error(
350
+ `${name}: Cannot use \`read\` from \`$app/server\` in route \`${route.id}\` configured with \`runtime: 'edge'\``
351
+ );
352
+ }
353
+
354
+ return true;
355
+ }
338
356
  }
339
357
  };
340
358
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-vercel",
3
- "version": "4.0.5",
3
+ "version": "5.0.0",
4
4
  "description": "A SvelteKit adapter that creates a Vercel app",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,10 +33,10 @@
33
33
  "@types/node": "^18.19.3",
34
34
  "typescript": "^5.3.3",
35
35
  "vitest": "^1.2.0",
36
- "@sveltejs/kit": "^2.3.3"
36
+ "@sveltejs/kit": "^2.4.0"
37
37
  },
38
38
  "peerDependencies": {
39
- "@sveltejs/kit": "^2.0.0"
39
+ "@sveltejs/kit": "^2.4.0"
40
40
  },
41
41
  "scripts": {
42
42
  "lint": "prettier --check .",