-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first crack at adapter-auto * make stuff work, maybe * changeset * appease the mighty eslint gods * update readme * add cloudflare pages * add missing adapter * update lockfile * add support for community adapters * update language * update adapter docs * tweak wording
- Loading branch information
1 parent
cc45b2c
commit 324e70a
Showing
15 changed files
with
225 additions
and
85 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,6 @@ | ||
--- | ||
'@sveltejs/adapter-auto': patch | ||
'create-svelte': patch | ||
--- | ||
|
||
Add adapter-auto |
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 was deleted.
Oops, something went wrong.
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,2 @@ | ||
.DS_Store | ||
node_modules |
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,19 @@ | ||
# adapter-auto | ||
|
||
Automatically chooses the adapter for your current environment, if possible. | ||
|
||
## Supported environments | ||
|
||
The following environments are supported out-of-the-box, meaning a newly created project can be deployed on one of these platforms without any additional configuration: | ||
|
||
- [Cloudflare Pages](https://developers.cloudflare.com/pages/) via [adapter-cloudflare](../adapter-cloudflare) | ||
- [Netlify](https://netlify.com/) via [adapter-netlify](../adapter-netlify) | ||
- [Vercel](https://vercel.com/) via [adapter-vercel](../adapter-vercel) | ||
|
||
## Community adapters | ||
|
||
Support for additional environments can be added in [adapters.js](adapters.js). To avoid this package ballooning in size, community-supported adapters should not be added as dependencies — adapter-auto will instead prompt users to install missing packages as needed. | ||
|
||
## Changelog | ||
|
||
[The Changelog for this package is available on GitHub](https://github.com/sveltejs/kit/blob/master/packages/adapter-auto/CHANGELOG.md). |
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,17 @@ | ||
export const adapters = [ | ||
{ | ||
name: 'Vercel', | ||
test: () => !!process.env.VERCEL, | ||
module: '@sveltejs/adapter-vercel' | ||
}, | ||
{ | ||
name: 'Netlify', | ||
test: () => !!process.env.NETLIFY, | ||
module: '@sveltejs/adapter-netlify' | ||
}, | ||
{ | ||
name: 'Cloudflare Pages', | ||
test: () => !!process.env.CF_PAGES, | ||
module: '@sveltejs/adapter-cloudflare' | ||
} | ||
]; |
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,4 @@ | ||
import { Adapter } from '@sveltejs/kit'; | ||
|
||
declare function plugin(): Adapter; | ||
export = plugin; |
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,42 @@ | ||
import { adapters } from './adapters.js'; | ||
|
||
/** @type {import('.')} **/ | ||
export default function () { | ||
return { | ||
name: '@sveltejs/adapter-auto', | ||
|
||
async adapt(options) { | ||
for (const candidate of adapters) { | ||
if (candidate.test()) { | ||
options.utils.log.info( | ||
`Detected environment: \u001B[1m\u001B[92m${candidate.name}\u001B[39m\u001B[22m. Using ${candidate.module}` | ||
); | ||
|
||
let module; | ||
|
||
try { | ||
module = await import(candidate.module); | ||
} catch (error) { | ||
if ( | ||
error.code === 'ERR_MODULE_NOT_FOUND' && | ||
error.message.startsWith(`Cannot find package '${candidate.module}'`) | ||
) { | ||
throw new Error( | ||
`It looks like ${candidate.module} is not installed. Please install it and try building your project again.` | ||
); | ||
} | ||
|
||
throw error; | ||
} | ||
|
||
const adapter = module.default(); | ||
return adapter.adapt(options); | ||
} | ||
} | ||
|
||
options.utils.log.warn( | ||
'Could not detect a supported production environment. See https://kit.svelte.dev/docs#adapters to learn how to configure your app to run on the platform of your choosing' | ||
); | ||
} | ||
}; | ||
} |
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,33 @@ | ||
{ | ||
"name": "@sveltejs/adapter-auto", | ||
"version": "1.0.0-next", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/sveltejs/kit", | ||
"directory": "packages/adapter-auto" | ||
}, | ||
"homepage": "https://kit.svelte.dev", | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"import": "./index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"files", | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format", | ||
"format": "npm run check-format -- --write", | ||
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore" | ||
}, | ||
"dependencies": { | ||
"@sveltejs/adapter-cloudflare": "workspace:*", | ||
"@sveltejs/adapter-netlify": "workspace:*", | ||
"@sveltejs/adapter-vercel": "workspace:*" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,3 +4,5 @@ node_modules | |
/.svelte-kit | ||
/package | ||
.env | ||
.vercel | ||
.output |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,18 @@ | ||
import adapter from '@sveltejs/adapter-auto'; | ||
import preprocess from 'svelte-preprocess'; | ||
|
||
const adapter = process.env.ADAPTER; | ||
const options = JSON.parse(process.env.OPTIONS || '{}'); | ||
|
||
/** @type {import('@sveltejs/kit').Config} */ | ||
const config = { | ||
// Consult https://github.com/sveltejs/svelte-preprocess | ||
// for more information about preprocessors | ||
preprocess: preprocess(), | ||
|
||
kit: { | ||
adapter: adapter(), | ||
|
||
// hydrate the <div id="svelte"> element in src/app.html | ||
target: '#svelte' | ||
} | ||
}; | ||
|
||
if (adapter) { | ||
config.kit.adapter = (await import(adapter)).default(options); | ||
} | ||
|
||
export default config; |
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
Oops, something went wrong.