Skip to content

Commit

Permalink
fix adapter-netlify (#4702)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored Apr 22, 2022
1 parent e3e9373 commit 40e5032
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/great-lies-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-netlify': patch
---

Fix adapter-netlify edge functions
18 changes: 9 additions & 9 deletions packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import toml from '@iarna/toml';
*/

const files = fileURLToPath(new URL('./files', import.meta.url).href);
const src = fileURLToPath(new URL('./src', import.meta.url).href);
const edgeSetInEnvVar =

const edge_set_in_env_var =
process.env.NETLIFY_SVELTEKIT_USE_EDGE === 'true' ||
process.env.NETLIFY_SVELTEKIT_USE_EDGE === '1';

/** @type {import('.')} */
export default function ({ split = false, edge = edgeSetInEnvVar } = {}) {
export default function ({ split = false, edge = edge_set_in_env_var } = {}) {
return {
name: '@sveltejs/adapter-netlify',

Expand All @@ -50,7 +50,7 @@ export default function ({ split = false, edge = edgeSetInEnvVar } = {}) {
builder.rimraf('.netlify/functions-internal');
builder.rimraf('.netlify/server');
builder.rimraf('.netlify/package.json');
builder.rimraf('.netlify/handler.js');
builder.rimraf('.netlify/serverless.js');

builder.log.minor(`Publishing to "${publish}"`);

Expand Down Expand Up @@ -114,7 +114,7 @@ async function generate_edge_functions({ builder }) {
builder.log.minor('Generating Edge Function...');
const relativePath = posix.relative(tmp, builder.getServerDirectory());

builder.copy(`${src}/edge_function.js`, `${tmp}/entry.js`, {
builder.copy(`${files}/edge.js`, `${tmp}/entry.js`, {
replace: {
'0SERVER': `${relativePath}/index.js`,
MANIFEST: './manifest.js'
Expand Down Expand Up @@ -205,8 +205,8 @@ function generate_lambda_functions({ builder, publish, split, esm }) {
});

const fn = esm
? `import { init } from '../handler.js';\n\nexport const handler = init(${manifest});\n`
: `const { init } = require('../handler.js');\n\nexports.handler = init(${manifest});\n`;
? `import { init } from '../serverless.js';\n\nexport const handler = init(${manifest});\n`
: `const { init } = require('../serverless.js');\n\nexports.handler = init(${manifest});\n`;

writeFileSync(`.netlify/functions-internal/${name}.js`, fn);

Expand All @@ -223,8 +223,8 @@ function generate_lambda_functions({ builder, publish, split, esm }) {
});

const fn = esm
? `import { init } from '../handler.js';\n\nexport const handler = init(${manifest});\n`
: `const { init } = require('../handler.js');\n\nexports.handler = init(${manifest});\n`;
? `import { init } from '../serverless.js';\n\nexport const handler = init(${manifest});\n`
: `const { init } = require('../serverless.js');\n\nexports.handler = init(${manifest});\n`;

writeFileSync('.netlify/functions-internal/render.js', fn);
redirects.push('* /.netlify/functions/render 200');
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
"scripts": {
"dev": "rimraf files && rollup -cw",
"build": "rimraf files && rollup -c",
"build": "rimraf files && rollup -c && cp src/edge.js files/edge.js",
"test": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
"check": "tsc",
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-netlify/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import json from '@rollup/plugin-json';
/** @type {import('rollup').RollupOptions} */
const config = {
input: {
handler: 'src/handler.js',
serverless: 'src/serverless.js',
shims: 'src/shims.js'
},
output: [
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 40e5032

Please sign in to comment.