-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* future-proof adapters * changeset * make function anonymous
- Loading branch information
Rich Harris
authored
Mar 12, 2021
1 parent
2f70cc1
commit f35a5cd
Showing
8 changed files
with
166 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@sveltejs/adapter-begin': patch | ||
'@sveltejs/adapter-netlify': patch | ||
'@sveltejs/adapter-node': patch | ||
'@sveltejs/adapter-static': patch | ||
'@sveltejs/adapter-vercel': patch | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
Change adapter signature |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,63 @@ | ||
'use strict'; | ||
|
||
import { existsSync, readFileSync, copyFileSync, writeFileSync, renameSync } from 'fs'; | ||
import { dirname, resolve } from 'path'; | ||
import toml from 'toml'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
export default async function adapter(builder) { | ||
let netlify_config; | ||
|
||
if (existsSync('netlify.toml')) { | ||
try { | ||
netlify_config = toml.parse(readFileSync('netlify.toml', 'utf-8')); | ||
} catch (err) { | ||
err.message = `Error parsing netlify.toml: ${err.message}`; | ||
throw err; | ||
export default function () { | ||
return { | ||
async adapt(builder) { | ||
let netlify_config; | ||
|
||
if (existsSync('netlify.toml')) { | ||
try { | ||
netlify_config = toml.parse(readFileSync('netlify.toml', 'utf-8')); | ||
} catch (err) { | ||
err.message = `Error parsing netlify.toml: ${err.message}`; | ||
throw err; | ||
} | ||
} else { | ||
// TODO offer to create one? | ||
throw new Error( | ||
'Missing a netlify.toml file. Consult /~https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify#configuration' | ||
); | ||
} | ||
|
||
if ( | ||
!netlify_config.build || | ||
!netlify_config.build.publish || | ||
!netlify_config.build.functions | ||
) { | ||
throw new Error( | ||
'You must specify build.publish and build.functions in netlify.toml. Consult /~https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify#configuration' | ||
); | ||
} | ||
|
||
const publish = resolve(netlify_config.build.publish); | ||
const functions = resolve(netlify_config.build.functions); | ||
|
||
builder.copy_static_files(publish); | ||
builder.copy_client_files(publish); | ||
builder.copy_server_files(`${functions}/render`); | ||
|
||
// rename app to .mjs | ||
renameSync(`${functions}/render/app.js`, `${functions}/render/app.mjs`); | ||
|
||
// copy the renderer | ||
copyFileSync(resolve(__dirname, 'files/render.js'), `${functions}/render/handler.mjs`); | ||
|
||
// copy the entry point | ||
copyFileSync(resolve(__dirname, 'files/index.cjs'), `${functions}/render/index.js`); | ||
|
||
// create _redirects | ||
writeFileSync(`${publish}/_redirects`, '/* /.netlify/functions/render 200'); | ||
|
||
// prerender | ||
builder.log.info('Prerendering static pages...'); | ||
await builder.prerender({ | ||
dest: publish | ||
}); | ||
} | ||
} else { | ||
// TODO offer to create one? | ||
throw new Error( | ||
'Missing a netlify.toml file. Consult /~https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify#configuration' | ||
); | ||
} | ||
|
||
if (!netlify_config.build || !netlify_config.build.publish || !netlify_config.build.functions) { | ||
throw new Error( | ||
'You must specify build.publish and build.functions in netlify.toml. Consult /~https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify#configuration' | ||
); | ||
} | ||
|
||
const publish = resolve(netlify_config.build.publish); | ||
const functions = resolve(netlify_config.build.functions); | ||
|
||
builder.copy_static_files(publish); | ||
builder.copy_client_files(publish); | ||
builder.copy_server_files(`${functions}/render`); | ||
|
||
// rename app to .mjs | ||
renameSync(`${functions}/render/app.js`, `${functions}/render/app.mjs`); | ||
|
||
// copy the renderer | ||
copyFileSync(resolve(__dirname, 'files/render.js'), `${functions}/render/handler.mjs`); | ||
|
||
// copy the entry point | ||
copyFileSync(resolve(__dirname, 'files/index.cjs'), `${functions}/render/index.js`); | ||
|
||
// create _redirects | ||
writeFileSync(`${publish}/_redirects`, '/* /.netlify/functions/render 200'); | ||
|
||
// prerender | ||
builder.log.info('Prerendering static pages...'); | ||
await builder.prerender({ | ||
dest: publish | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
'use strict'; | ||
export default function ({ pages = 'build', assets = 'build' } = {}) { | ||
return { | ||
async adapt(builder) { | ||
builder.copy_static_files(assets); | ||
builder.copy_client_files(assets); | ||
|
||
export default async function adapter(builder, { pages = 'build', assets = 'build' } = {}) { | ||
builder.copy_static_files(assets); | ||
builder.copy_client_files(assets); | ||
|
||
await builder.prerender({ | ||
force: true, | ||
dest: pages | ||
}); | ||
await builder.prerender({ | ||
force: true, | ||
dest: pages | ||
}); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters