@sveltejs/adapter-netlify 1.0.0-next.53 → 1.0.0-next.56

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
@@ -16,19 +16,19 @@ You can then configure it inside of `svelte.config.js`:
16
16
  import adapter from '@sveltejs/adapter-netlify';
17
17
 
18
18
  export default {
19
- kit: {
20
- // default options are shown
21
- adapter: adapter({
22
- // if true, will create a Netlify Edge Function rather
23
- // than using standard Node-based functions
24
- edge: false,
25
-
26
- // if true, will split your app into multiple functions
27
- // instead of creating a single one for the entire app.
28
- // if `edge` is true, this option cannot be used
29
- split: false
30
- })
31
- }
19
+ kit: {
20
+ // default options are shown
21
+ adapter: adapter({
22
+ // if true, will create a Netlify Edge Function rather
23
+ // than using standard Node-based functions
24
+ edge: false,
25
+
26
+ // if true, will split your app into multiple functions
27
+ // instead of creating a single one for the entire app.
28
+ // if `edge` is true, this option cannot be used
29
+ split: false
30
+ })
31
+ }
32
32
  };
33
33
  ```
34
34
 
File without changes
package/files/edge.js ADDED
@@ -0,0 +1,51 @@
1
+ import { Server } from '0SERVER';
2
+ import { manifest, prerendered } from 'MANIFEST';
3
+
4
+ const server = new Server(manifest);
5
+ const prefix = `/${manifest.appDir}/`;
6
+
7
+ /**
8
+ * @param { Request } request
9
+ * @param { any } context
10
+ * @returns { Promise<Response> }
11
+ */
12
+ export default function handler(request, context) {
13
+ if (is_static_file(request)) {
14
+ // Static files can skip the handler
15
+ return;
16
+ }
17
+
18
+ return server.respond(request, {
19
+ platform: { context },
20
+ getClientAddress() {
21
+ return request.headers.get('x-nf-client-connection-ip');
22
+ }
23
+ });
24
+ }
25
+
26
+ /**
27
+ * @param {Request} request
28
+ */
29
+ function is_static_file(request) {
30
+ const url = new URL(request.url);
31
+
32
+ // Assets in the app dir
33
+ if (url.pathname.startsWith(prefix)) {
34
+ return true;
35
+ }
36
+ // prerendered pages and index.html files
37
+ const pathname = url.pathname.replace(/\/$/, '');
38
+ let file = pathname.substring(1);
39
+
40
+ try {
41
+ file = decodeURIComponent(file);
42
+ } catch (err) {
43
+ // ignore
44
+ }
45
+
46
+ return (
47
+ manifest.assets.has(file) ||
48
+ manifest.assets.has(file + '/index.html') ||
49
+ prerendered.has(pathname || '/')
50
+ );
51
+ }
File without changes
package/index.js CHANGED
@@ -29,13 +29,13 @@ import toml from '@iarna/toml';
29
29
  */
30
30
 
31
31
  const files = fileURLToPath(new URL('./files', import.meta.url).href);
32
- const src = fileURLToPath(new URL('./src', import.meta.url).href);
33
- const edgeSetInEnvVar =
32
+
33
+ const edge_set_in_env_var =
34
34
  process.env.NETLIFY_SVELTEKIT_USE_EDGE === 'true' ||
35
35
  process.env.NETLIFY_SVELTEKIT_USE_EDGE === '1';
36
36
 
37
37
  /** @type {import('.')} */
38
- export default function ({ split = false, edge = edgeSetInEnvVar } = {}) {
38
+ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
39
39
  return {
40
40
  name: '@sveltejs/adapter-netlify',
41
41
 
@@ -50,7 +50,7 @@ export default function ({ split = false, edge = edgeSetInEnvVar } = {}) {
50
50
  builder.rimraf('.netlify/functions-internal');
51
51
  builder.rimraf('.netlify/server');
52
52
  builder.rimraf('.netlify/package.json');
53
- builder.rimraf('.netlify/handler.js');
53
+ builder.rimraf('.netlify/serverless.js');
54
54
 
55
55
  builder.log.minor(`Publishing to "${publish}"`);
56
56
 
@@ -88,6 +88,12 @@ export default function ({ split = false, edge = edgeSetInEnvVar } = {}) {
88
88
  * @param {import('@sveltejs/kit').Builder} params.builder
89
89
  */
90
90
  async function generate_edge_functions({ builder }) {
91
+ const tmp = builder.getBuildDirectory('netlify-tmp');
92
+ builder.rimraf(tmp);
93
+ builder.mkdirp(tmp);
94
+
95
+ builder.mkdirp('.netlify/edge-functions');
96
+
91
97
  // Don't match the static directory
92
98
  const pattern = '^/.*$';
93
99
 
@@ -104,16 +110,11 @@ async function generate_edge_functions({ builder }) {
104
110
  ],
105
111
  version: 1
106
112
  };
107
- const tmp = builder.getBuildDirectory('netlify-tmp');
108
-
109
- builder.rimraf(tmp);
110
-
111
- builder.mkdirp('.netlify/edge-functions');
112
113
 
113
114
  builder.log.minor('Generating Edge Function...');
114
115
  const relativePath = posix.relative(tmp, builder.getServerDirectory());
115
116
 
116
- builder.copy(`${src}/edge_function.js`, `${tmp}/entry.js`, {
117
+ builder.copy(`${files}/edge.js`, `${tmp}/entry.js`, {
117
118
  replace: {
118
119
  '0SERVER': `${relativePath}/index.js`,
119
120
  MANIFEST: './manifest.js'
@@ -204,8 +205,8 @@ function generate_lambda_functions({ builder, publish, split, esm }) {
204
205
  });
205
206
 
206
207
  const fn = esm
207
- ? `import { init } from '../handler.js';\n\nexport const handler = init(${manifest});\n`
208
- : `const { init } = require('../handler.js');\n\nexports.handler = init(${manifest});\n`;
208
+ ? `import { init } from '../serverless.js';\n\nexport const handler = init(${manifest});\n`
209
+ : `const { init } = require('../serverless.js');\n\nexports.handler = init(${manifest});\n`;
209
210
 
210
211
  writeFileSync(`.netlify/functions-internal/${name}.js`, fn);
211
212
 
@@ -222,8 +223,8 @@ function generate_lambda_functions({ builder, publish, split, esm }) {
222
223
  });
223
224
 
224
225
  const fn = esm
225
- ? `import { init } from '../handler.js';\n\nexport const handler = init(${manifest});\n`
226
- : `const { init } = require('../handler.js');\n\nexports.handler = init(${manifest});\n`;
226
+ ? `import { init } from '../serverless.js';\n\nexport const handler = init(${manifest});\n`
227
+ : `const { init } = require('../serverless.js');\n\nexports.handler = init(${manifest});\n`;
227
228
 
228
229
  writeFileSync('.netlify/functions-internal/render.js', fn);
229
230
  redirects.push('* /.netlify/functions/render 200');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-netlify",
3
- "version": "1.0.0-next.53",
3
+ "version": "1.0.0-next.56",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -31,7 +31,7 @@
31
31
  "@rollup/plugin-commonjs": "^21.0.0",
32
32
  "@rollup/plugin-json": "^4.1.0",
33
33
  "@rollup/plugin-node-resolve": "^13.0.5",
34
- "@sveltejs/kit": "1.0.0-next.318",
34
+ "@sveltejs/kit": "1.0.0-next.323",
35
35
  "rimraf": "^3.0.2",
36
36
  "rollup": "^2.58.0",
37
37
  "typescript": "^4.6.2",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "scripts": {
41
41
  "dev": "rimraf files && rollup -cw",
42
- "build": "rimraf files && rollup -c",
42
+ "build": "rimraf files && rollup -c && cp src/edge.js files/edge.js",
43
43
  "test": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
44
44
  "check": "tsc",
45
45
  "lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",