Skip to content

Commit

Permalink
Merge branch 'master' into client-address
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored Mar 14, 2022
2 parents e5475bc + c3c700f commit a548fa8
Show file tree
Hide file tree
Showing 29 changed files with 199 additions and 54 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-crabs-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Allow adapter.adapt to be synchronous
5 changes: 5 additions & 0 deletions .changeset/early-pants-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Make `manifest.mimeTypes` part of the public API
5 changes: 5 additions & 0 deletions .changeset/long-guests-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Allow routes with the same name as fallback components
8 changes: 8 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"brave-toys-joke",
"brave-turkeys-bathe",
"brave-weeks-allow",
"breezy-ears-fetch",
"breezy-games-count",
"breezy-onions-remember",
"breezy-sheep-dress",
Expand Down Expand Up @@ -113,6 +114,7 @@
"cold-pants-unite",
"cold-tables-shake",
"cool-bananas-share",
"cool-crabs-listen",
"cool-ducks-cheat",
"cool-hounds-divide",
"cool-spoons-dress",
Expand Down Expand Up @@ -148,6 +150,7 @@
"early-clocks-sneeze",
"early-lemons-collect",
"early-news-taste",
"early-pants-unite",
"early-snakes-peel",
"early-wasps-obey",
"eight-birds-run",
Expand Down Expand Up @@ -295,6 +298,7 @@
"honest-jars-report",
"honest-singers-guess",
"hot-bags-jump",
"hot-clouds-work",
"hot-dogs-fry",
"hot-keys-walk",
"hot-kings-confess",
Expand Down Expand Up @@ -355,6 +359,7 @@
"little-shirts-happen",
"little-tables-decide",
"long-bulldogs-invent",
"long-guests-trade",
"long-hotels-hunt",
"long-moles-fold",
"loud-dancers-cough",
Expand Down Expand Up @@ -657,6 +662,7 @@
"spotty-parents-love",
"spotty-ties-love",
"spotty-timers-fix",
"stale-crabs-carry",
"stale-dodos-type",
"stale-geckos-call",
"stale-glasses-brake",
Expand Down Expand Up @@ -701,6 +707,7 @@
"tasty-cars-love",
"tasty-donkeys-wait",
"tasty-islands-drive",
"tasty-squids-share",
"ten-hairs-perform",
"ten-mice-kneel",
"ten-plants-sleep",
Expand Down Expand Up @@ -817,6 +824,7 @@
"wild-pumas-jam",
"wise-bees-juggle",
"wise-bugs-run",
"wise-pens-ring",
"wise-rules-cry",
"witty-bottles-press",
"witty-eyes-relax",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/stale-crabs-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

load hooks after server initialisation, to ensure `prerendering` is correct
5 changes: 5 additions & 0 deletions .changeset/stale-dogs-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Return 404 when fetching missing data during prerender
5 changes: 5 additions & 0 deletions .changeset/tasty-squids-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-auto': patch
---

Select adapter immediately
5 changes: 5 additions & 0 deletions .changeset/wise-pens-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-svelte': patch
---

[fix] check for app.d.ts rather than global.d.ts
10 changes: 10 additions & 0 deletions packages/adapter-auto/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @sveltejs/adapter-auto

## 1.0.0-next.32

### Patch Changes

- Select adapter immediately ([#4299](https://github.com/sveltejs/kit/pull/4299))

- Updated dependencies []:
- @sveltejs/adapter-netlify@1.0.0-next.50
- @sveltejs/adapter-vercel@1.0.0-next.46

## 1.0.0-next.31

### Patch Changes
Expand Down
68 changes: 40 additions & 28 deletions packages/adapter-auto/index.js
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;
2 changes: 1 addition & 1 deletion packages/adapter-auto/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/adapter-auto",
"version": "1.0.0-next.31",
"version": "1.0.0-next.32",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/kit",
Expand Down
3 changes: 3 additions & 0 deletions packages/adapter-auto/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"module": "esnext",
"target": "esnext",
"moduleResolution": "node",
"baseUrl": ".",
"paths": {
"@sveltejs/kit": ["../kit/types/index"]
Expand Down
2 changes: 2 additions & 0 deletions packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export default function ({ split = false } = {}) {
builder.createEntries((route) => {
const parts = [];

// Netlify's syntax uses '*' and ':param' as "splats" and "placeholders"
// https://docs.netlify.com/routing/redirects/redirect-options/#splats
for (const segment of route.segments) {
if (segment.rest) {
parts.push('*');
Expand Down
6 changes: 6 additions & 0 deletions packages/create-svelte/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# create-svelte

## 2.0.0-next.125

### Patch Changes

- [fix] check for app.d.ts rather than global.d.ts ([#4295](https://github.com/sveltejs/kit/pull/4295))

## 2.0.0-next.124

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/create-svelte/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-svelte",
"version": "2.0.0-next.124",
"version": "2.0.0-next.125",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/kit",
Expand Down
4 changes: 2 additions & 2 deletions packages/create-svelte/scripts/build-templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ async function generate_templates(shared) {
const js = [];

for (const file of ts) {
// The global.d.ts file makes TS/JS aware of some ambient modules, which are
// The app.d.ts file makes TS/JS aware of some ambient modules, which are
// also needed for JS projects if people turn on "checkJs" in their jsonfig
if (file.name.endsWith('.d.ts')) {
if (file.name.endsWith('global.d.ts')) js.push(file);
if (file.name.endsWith('app.d.ts')) js.push(file);
} else if (file.name.endsWith('.ts')) {
const transformed = transform(file.contents, {
transforms: ['typescript']
Expand Down
20 changes: 20 additions & 0 deletions packages/kit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# @sveltejs/kit

## 1.0.0-next.296

### Patch Changes

- Allow adapter.adapt to be synchronous ([#4299](https://github.com/sveltejs/kit/pull/4299))

* Make `manifest.mimeTypes` part of the public API ([#4302](https://github.com/sveltejs/kit/pull/4302))

- load hooks after server initialisation, to ensure `prerendering` is correct ([#4322](https://github.com/sveltejs/kit/pull/4322))

## 1.0.0-next.295

### Patch Changes

- fix error message for invalid request object ([#4277](https://github.com/sveltejs/kit/pull/4277))

* Handle explicit redirects from endpoints ([#4260](https://github.com/sveltejs/kit/pull/4260))

- Allow routes with the same name as fallback components ([#4284](https://github.com/sveltejs/kit/pull/4284))

## 1.0.0-next.294

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sveltejs/kit",
"version": "1.0.0-next.294",
"version": "1.0.0-next.296",
"repository": {
"type": "git",
"url": "https://github.com/sveltejs/kit",
Expand Down
29 changes: 14 additions & 15 deletions packages/kit/src/core/build/build_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ let read = null;
set_paths(${s(config.kit.paths)});
// this looks redundant, but the indirection allows us to access
// named imports without triggering Rollup's missing import detection
const get_hooks = hooks => ({
getSession: hooks.getSession || (() => ({})),
handle: hooks.handle || (({ event, resolve }) => resolve(event)),
handleError: hooks.handleError || (({ error }) => console.error(error.stack)),
externalFetch: hooks.externalFetch || fetch
});
let default_protocol = 'https';
// allow paths to be globally overridden
Expand All @@ -57,16 +48,14 @@ export function override(settings) {
export class Server {
constructor(manifest) {
const hooks = get_hooks(user_hooks);
this.options = {
amp: ${config.kit.amp},
csp: ${s(config.kit.csp)},
dev: false,
floc: ${config.kit.floc},
get_stack: error => String(error), // for security
handle_error: (error, event) => {
hooks.handleError({
this.options.hooks.handleError({
error,
event,
Expand All @@ -78,7 +67,7 @@ export class Server {
});
error.stack = this.options.get_stack(error);
},
hooks,
hooks: null,
hydrate: ${s(config.kit.browser.hydrate)},
manifest,
method_override: ${s(config.kit.methodOverride)},
Expand All @@ -95,11 +84,21 @@ export class Server {
};
}
respond(request, options = {}) {
async respond(request, options = {}) {
if (!(request instanceof Request)) {
throw new Error('The first argument to server.respond must be a Request object. See https://github.com/sveltejs/kit/pull/3384 for details');
}
if (!this.options.hooks) {
const module = await import(${s(hooks)});
this.options.hooks = {
getSession: module.getSession || (() => ({})),
handle: module.handle || (({ event, resolve }) => resolve(event)),
handleError: module.handleError || (({ error }) => console.error(error.stack)),
externalFetch: module.externalFetch || fetch
};
}
return respond(request, this.options, options);
}
}
Expand Down Expand Up @@ -160,7 +159,7 @@ export async function build_server(
const relative = path.relative(config.kit.files.routes, resolved);

const name = relative.startsWith('..')
? posixify(path.join('entries/pages', path.basename(file)))
? posixify(path.join('entries/fallbacks', path.basename(file)))
: posixify(path.join('entries/pages', relative));
input[name] = resolved;
});
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/dev/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export async function create_plugin(config, cwd) {
manifest = {
appDir: config.kit.appDir,
assets: new Set(manifest_data.assets.map((asset) => asset.file)),
mimeTypes: get_mime_lookup(manifest_data),
_: {
mime: get_mime_lookup(manifest_data),
entry: {
file: `/@fs${runtime}/client/start.js`,
css: [],
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/generate_manifest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export function generate_manifest({ build_data, relative_path, routes, format =
return `{
appDir: ${s(build_data.app_dir)},
assets: new Set(${s(assets)}),
mimeTypes: ${s(get_mime_lookup(build_data.manifest_data))},
_: {
mime: ${s(get_mime_lookup(build_data.manifest_data))},
entry: ${s(build_data.client.entry)},
nodes: [
${Array.from(bundled_nodes.values()).map(node => importer(node.path)).join(',\n\t\t\t\t')}
Expand Down
Loading

0 comments on commit a548fa8

Please sign in to comment.