@sveltejs/adapter-netlify
Advanced tools
Comparing version 2.0.2 to 2.0.3
import './shims.js'; | ||
import { Server } from '0SERVER'; | ||
import 'node:stream/web'; | ||
import 'node:buffer'; | ||
import 'node:crypto'; | ||
@@ -5,0 +6,0 @@ import 'assert'; |
72
index.js
@@ -1,9 +0,2 @@ | ||
import { | ||
appendFileSync, | ||
existsSync, | ||
readFileSync, | ||
writeFileSync, | ||
unlinkSync, | ||
createReadStream | ||
} from 'fs'; | ||
import { appendFileSync, existsSync, readdirSync, readFileSync, writeFileSync } from 'fs'; | ||
import { dirname, join, resolve, posix } from 'path'; | ||
@@ -13,3 +6,2 @@ import { fileURLToPath } from 'url'; | ||
import toml from '@iarna/toml'; | ||
import { createInterface } from 'readline'; | ||
@@ -45,2 +37,4 @@ /** | ||
const FUNCTION_PREFIX = 'sveltekit-'; | ||
/** @type {import('.').default} */ | ||
@@ -64,36 +58,2 @@ export default function ({ split = false, edge = edge_set_in_env_var } = {}) { | ||
const redirects_file_path = join(publish, '_redirects'); | ||
// If redirects file exists - empty any netlify generated files in functions-internal | ||
// Without removing other files that may have been auto generated by integrations | ||
if (existsSync(redirects_file_path)) { | ||
// Read each line of the file | ||
const fileStream = createReadStream(redirects_file_path); | ||
const rl = createInterface({ | ||
input: fileStream, | ||
crlfDelay: Infinity | ||
}); | ||
// Create an array of lines | ||
const lines = []; | ||
for await (const line of rl) { | ||
lines.push(line); | ||
} | ||
const functions_internal = join('.netlify', 'functions-internal'); | ||
// Loop through redirects, and delete corresponding functions-internal files | ||
lines.forEach((line) => { | ||
if (line) { | ||
// example line /.netlify/functions/{function_name} 200 | ||
const path = line.split(' ')[1]; | ||
const function_name = path.split('/').pop(); | ||
const mjsFile = join(functions_internal, `${function_name}.mjs`); | ||
const jsonFile = join(functions_internal, `${function_name}.json`); | ||
if (existsSync(mjsFile)) unlinkSync(mjsFile); | ||
if (existsSync(jsonFile)) unlinkSync(jsonFile); | ||
} | ||
}); | ||
} | ||
// empty out existing build directories | ||
@@ -106,2 +66,10 @@ builder.rimraf(publish); | ||
if (existsSync('.netlify/functions-internal')) { | ||
for (const file of readdirSync('.netlify/functions-internal')) { | ||
if (file.startsWith(FUNCTION_PREFIX)) { | ||
builder.rimraf(join('.netlify/functions-internal', file)); | ||
} | ||
} | ||
} | ||
builder.log.minor(`Publishing to "${publish}"`); | ||
@@ -202,3 +170,3 @@ | ||
async function generate_lambda_functions({ builder, publish, split }) { | ||
builder.mkdirp('.netlify/functions-internal'); | ||
builder.mkdirp('.netlify/functions-internal/.svelte-kit'); | ||
@@ -244,3 +212,4 @@ /** @type {string[]} */ | ||
const pattern = `/${parts.join('/')}`; | ||
const name = parts.join('-').replace(/[:.]/g, '_').replace('*', '__rest') || 'index'; | ||
const name = | ||
FUNCTION_PREFIX + (parts.join('-').replace(/[:.]/g, '_').replace('*', '__rest') || 'index'); | ||
@@ -253,6 +222,7 @@ // skip routes with identical patterns, they were already folded into another function | ||
for (let j = i + 1; j < builder.routes.length; j += 1) { | ||
if (routes[j].prerender === true) continue; | ||
const other = builder.routes[j]; | ||
if (other.prerender === true) continue; | ||
if (matches(route.segments, routes[j].segments)) { | ||
routes.push(builder.routes[j]); | ||
if (matches(route.segments, other.segments)) { | ||
routes.push(other); | ||
} | ||
@@ -281,5 +251,5 @@ } | ||
writeFileSync(`.netlify/functions-internal/render.json`, fn_config); | ||
writeFileSync('.netlify/functions-internal/render.mjs', fn); | ||
redirects.push('* /.netlify/functions/render 200'); | ||
writeFileSync(`.netlify/functions-internal/${FUNCTION_PREFIX}render.json`, fn_config); | ||
writeFileSync(`.netlify/functions-internal/${FUNCTION_PREFIX}render.mjs`, fn); | ||
redirects.push(`* /.netlify/functions/${FUNCTION_PREFIX}render 200`); | ||
} | ||
@@ -286,0 +256,0 @@ |
{ | ||
"name": "@sveltejs/adapter-netlify", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"repository": { | ||
@@ -41,3 +41,3 @@ "type": "git", | ||
"uvu": "^0.5.6", | ||
"@sveltejs/kit": "^1.5.1" | ||
"@sveltejs/kit": "^1.5.3" | ||
}, | ||
@@ -44,0 +44,0 @@ "peerDependencies": { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
797358
18718