@sveltejs/adapter-netlify 2.0.2 → 2.0.4

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,6 +1,7 @@
1
1
  import './shims.js';
2
2
  import { Server } from '0SERVER';
3
3
  import 'node:stream/web';
4
+ import 'node:buffer';
4
5
  import 'node:crypto';
5
6
  import 'assert';
6
7
  import 'net';
@@ -1,4 +1,5 @@
1
1
  import { ReadableStream as ReadableStream$1, TransformStream, WritableStream } from 'node:stream/web';
2
+ import buffer from 'node:buffer';
2
3
  import { webcrypto } from 'node:crypto';
3
4
  import require$$0$1 from 'assert';
4
5
  import require$$4 from 'net';
@@ -20744,6 +20745,9 @@ function requireUndici () {
20744
20745
 
20745
20746
  var undiciExports = requireUndici();
20746
20747
 
20748
+ // @ts-expect-error
20749
+ const File = buffer.File ?? undiciExports.File;
20750
+
20747
20751
  /** @type {Record<string, any>} */
20748
20752
  const globals = {
20749
20753
  crypto: webcrypto,
@@ -20754,7 +20758,8 @@ const globals = {
20754
20758
  ReadableStream: ReadableStream$1,
20755
20759
  TransformStream,
20756
20760
  WritableStream,
20757
- FormData: undiciExports.FormData
20761
+ FormData: undiciExports.FormData,
20762
+ File
20758
20763
  };
20759
20764
 
20760
20765
  // exported for dev/preview and node environments
package/index.js CHANGED
@@ -1,16 +1,8 @@
1
- import {
2
- appendFileSync,
3
- existsSync,
4
- readFileSync,
5
- writeFileSync,
6
- unlinkSync,
7
- createReadStream
8
- } from 'fs';
9
- import { dirname, join, resolve, posix } from 'path';
10
- import { fileURLToPath } from 'url';
1
+ import { appendFileSync, existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { dirname, join, resolve, posix } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
11
4
  import esbuild from 'esbuild';
12
5
  import toml from '@iarna/toml';
13
- import { createInterface } from 'readline';
14
6
 
15
7
  /**
16
8
  * @typedef {{
@@ -41,6 +33,8 @@ const edge_set_in_env_var =
41
33
  process.env.NETLIFY_SVELTEKIT_USE_EDGE === 'true' ||
42
34
  process.env.NETLIFY_SVELTEKIT_USE_EDGE === '1';
43
35
 
36
+ const FUNCTION_PREFIX = 'sveltekit-';
37
+
44
38
  /** @type {import('.').default} */
45
39
  export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
46
40
  return {
@@ -59,40 +53,6 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
59
53
  // "build" is the default publish directory when Netlify detects SvelteKit
60
54
  const publish = get_publish_directory(netlify_config, builder) || 'build';
61
55
 
62
- const redirects_file_path = join(publish, '_redirects');
63
-
64
- // If redirects file exists - empty any netlify generated files in functions-internal
65
- // Without removing other files that may have been auto generated by integrations
66
- if (existsSync(redirects_file_path)) {
67
- // Read each line of the file
68
- const fileStream = createReadStream(redirects_file_path);
69
- const rl = createInterface({
70
- input: fileStream,
71
- crlfDelay: Infinity
72
- });
73
-
74
- // Create an array of lines
75
- const lines = [];
76
- for await (const line of rl) {
77
- lines.push(line);
78
- }
79
-
80
- const functions_internal = join('.netlify', 'functions-internal');
81
-
82
- // Loop through redirects, and delete corresponding functions-internal files
83
- lines.forEach((line) => {
84
- if (line) {
85
- // example line /.netlify/functions/{function_name} 200
86
- const path = line.split(' ')[1];
87
- const function_name = path.split('/').pop();
88
- const mjsFile = join(functions_internal, `${function_name}.mjs`);
89
- const jsonFile = join(functions_internal, `${function_name}.json`);
90
- if (existsSync(mjsFile)) unlinkSync(mjsFile);
91
- if (existsSync(jsonFile)) unlinkSync(jsonFile);
92
- }
93
- });
94
- }
95
-
96
56
  // empty out existing build directories
97
57
  builder.rimraf(publish);
98
58
  builder.rimraf('.netlify/edge-functions');
@@ -100,6 +60,14 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
100
60
  builder.rimraf('.netlify/package.json');
101
61
  builder.rimraf('.netlify/serverless.js');
102
62
 
63
+ if (existsSync('.netlify/functions-internal')) {
64
+ for (const file of readdirSync('.netlify/functions-internal')) {
65
+ if (file.startsWith(FUNCTION_PREFIX)) {
66
+ builder.rimraf(join('.netlify/functions-internal', file));
67
+ }
68
+ }
69
+ }
70
+
103
71
  builder.log.minor(`Publishing to "${publish}"`);
104
72
 
105
73
  builder.log.minor('Copying assets...');
@@ -195,7 +163,7 @@ async function generate_edge_functions({ builder }) {
195
163
  * @param { boolean } params.split
196
164
  */
197
165
  async function generate_lambda_functions({ builder, publish, split }) {
198
- builder.mkdirp('.netlify/functions-internal');
166
+ builder.mkdirp('.netlify/functions-internal/.svelte-kit');
199
167
 
200
168
  /** @type {string[]} */
201
169
  const redirects = [];
@@ -236,7 +204,8 @@ async function generate_lambda_functions({ builder, publish, split }) {
236
204
  }
237
205
 
238
206
  const pattern = `/${parts.join('/')}`;
239
- const name = parts.join('-').replace(/[:.]/g, '_').replace('*', '__rest') || 'index';
207
+ const name =
208
+ FUNCTION_PREFIX + (parts.join('-').replace(/[:.]/g, '_').replace('*', '__rest') || 'index');
240
209
 
241
210
  // skip routes with identical patterns, they were already folded into another function
242
211
  if (seen.has(pattern)) continue;
@@ -244,10 +213,11 @@ async function generate_lambda_functions({ builder, publish, split }) {
244
213
 
245
214
  // figure out which lower priority routes should be considered fallbacks
246
215
  for (let j = i + 1; j < builder.routes.length; j += 1) {
247
- if (routes[j].prerender === true) continue;
216
+ const other = builder.routes[j];
217
+ if (other.prerender === true) continue;
248
218
 
249
- if (matches(route.segments, routes[j].segments)) {
250
- routes.push(builder.routes[j]);
219
+ if (matches(route.segments, other.segments)) {
220
+ routes.push(other);
251
221
  }
252
222
  }
253
223
 
@@ -261,8 +231,9 @@ async function generate_lambda_functions({ builder, publish, split }) {
261
231
  writeFileSync(`.netlify/functions-internal/${name}.mjs`, fn);
262
232
  writeFileSync(`.netlify/functions-internal/${name}.json`, fn_config);
263
233
 
264
- redirects.push(`${pattern} /.netlify/functions/${name} 200`);
265
- redirects.push(`${pattern}/__data.json /.netlify/functions/${name} 200`);
234
+ const redirect = `/.netlify/functions/${name} 200`;
235
+ redirects.push(`${pattern} ${redirect}`);
236
+ redirects.push(`${pattern === '/' ? '' : pattern}/__data.json ${redirect}`);
266
237
  }
267
238
  } else {
268
239
  const manifest = builder.generateManifest({
@@ -271,9 +242,9 @@ async function generate_lambda_functions({ builder, publish, split }) {
271
242
 
272
243
  const fn = `import { init } from '../serverless.js';\n\nexport const handler = init(${manifest});\n`;
273
244
 
274
- writeFileSync(`.netlify/functions-internal/render.json`, fn_config);
275
- writeFileSync('.netlify/functions-internal/render.mjs', fn);
276
- redirects.push('* /.netlify/functions/render 200');
245
+ writeFileSync(`.netlify/functions-internal/${FUNCTION_PREFIX}render.json`, fn_config);
246
+ writeFileSync(`.netlify/functions-internal/${FUNCTION_PREFIX}render.mjs`, fn);
247
+ redirects.push(`* /.netlify/functions/${FUNCTION_PREFIX}render 200`);
277
248
  }
278
249
 
279
250
  // this should happen at the end, after builder.writeClient(...),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-netlify",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -38,7 +38,7 @@
38
38
  "rollup": "^3.7.0",
39
39
  "typescript": "^4.9.4",
40
40
  "uvu": "^0.5.6",
41
- "@sveltejs/kit": "^1.5.1"
41
+ "@sveltejs/kit": "^1.5.6"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@sveltejs/kit": "^1.5.0"