-
-
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.
select adapter immediately on startup (#4299)
* select adapter immediately on startup * simplify * changesets * lint
- Loading branch information
1 parent
2f21125
commit 818b489
Showing
5 changed files
with
54 additions
and
29 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,5 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
Allow adapter.adapt to be synchronous |
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,5 @@ | ||
--- | ||
'@sveltejs/adapter-auto': patch | ||
--- | ||
|
||
Select adapter immediately |
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,40 +1,52 @@ | ||
import { adapters } from './adapters.js'; | ||
|
||
/** @type {import('.')} **/ | ||
export default function () { | ||
return { | ||
name: '@sveltejs/adapter-auto', | ||
/** @type {import('./index')} */ | ||
let fn; | ||
|
||
for (const candidate of adapters) { | ||
if (candidate.test()) { | ||
/** @type {{ default: () => import('@sveltejs/kit').Adapter }} */ | ||
let module; | ||
|
||
async adapt(builder) { | ||
for (const candidate of adapters) { | ||
if (candidate.test()) { | ||
builder.log.info(`Detected environment: ${candidate.name}. 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; | ||
try { | ||
module = await import(candidate.module); | ||
|
||
fn = () => { | ||
const adapter = module.default(); | ||
return { | ||
...adapter, | ||
adapt: (builder) => { | ||
builder.log.info(`Detected environment: ${candidate.name}. Using ${candidate.module}`); | ||
return adapter.adapt(builder); | ||
} | ||
}; | ||
}; | ||
|
||
const adapter = module.default(); | ||
return adapter.adapt(builder); | ||
} | ||
break; | ||
} 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; | ||
} | ||
} | ||
} | ||
|
||
if (!fn) { | ||
fn = () => ({ | ||
name: '@sveltejs/adapter-auto', | ||
adapt: (builder) => { | ||
builder.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' | ||
); | ||
} | ||
}; | ||
}); | ||
} | ||
|
||
export default fn; |
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