Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix adapter-netlify #4702

Merged
merged 1 commit into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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