Skip to content

Commit

Permalink
[breaking] rename prerender.pages config option to prerender.entries (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Sep 7, 2021
1 parent b4eacd6 commit d23c8b8
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-lemons-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[breaking] rename prerender.pages config option to prerender.entries
7 changes: 3 additions & 4 deletions documentation/docs/14-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const config = {
prerender: {
crawl: true,
enabled: true,
onError: 'fail',
pages: ['*']
entries: ['*'],
onError: 'fail'
},
router: true,
serviceWorker: {
Expand Down Expand Up @@ -148,6 +148,7 @@ See [Prerendering](#ssr-and-javascript-prerender). An object containing zero or

- `crawl` — determines whether SvelteKit should find pages to prerender by following links from the seed page(s)
- `enabled` — set to `false` to disable prerendering altogether
- `entries` — an array of pages to prerender, or start crawling from (if `crawl: true`). The `*` string includes all non-dynamic routes (i.e. pages with no `[parameters]` )
- `onError`

- `'fail'` — (default) fails the build when a routing error is encountered when following a link
Expand All @@ -172,8 +173,6 @@ See [Prerendering](#ssr-and-javascript-prerender). An object containing zero or
};
```

- `pages`an array of pages to prerender, or start crawling from (if `crawl: true`). The `*` string includes all non-dynamic routes (i.e. pages with no `[parameters]` )

### router

Enables or disables the client-side [router](#ssr-and-javascript-router) app-wide.
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/adapt/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a
}

if (config.kit.prerender.enabled) {
for (const entry of config.kit.prerender.pages) {
for (const entry of config.kit.prerender.entries) {
if (entry === '*') {
for (const entry of build_data.entries) {
await visit(entry, null);
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/core/adapt/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ suite('prerender', async () => {
},
appDir: '_app',
prerender: {
pages: ['*'],
enabled: true
enabled: true,
entries: ['*']
}
}
};
Expand Down
14 changes: 7 additions & 7 deletions packages/kit/src/core/config/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ test('fills in defaults', () => {
prerender: {
crawl: true,
enabled: true,
// TODO: remove this for the 1.0 release
entries: ['*'],
force: undefined,
onError: 'fail',
pages: ['*']
pages: undefined
},
router: true,
ssr: true,
Expand Down Expand Up @@ -156,10 +156,10 @@ test('fills in partial blanks', () => {
prerender: {
crawl: true,
enabled: true,
// TODO: remove this for the 1.0 release
entries: ['*'],
force: undefined,
onError: 'fail',
pages: ['*']
pages: undefined
},
router: true,
ssr: true,
Expand Down Expand Up @@ -257,16 +257,16 @@ test('fails if paths.assets has trailing slash', () => {
}, /^config\.kit\.paths\.assets option must not end with '\/'. See https:\/\/kit\.svelte\.dev\/docs#configuration-paths$/);
});

test('fails if prerender.pages are invalid', () => {
test('fails if prerender.entries are invalid', () => {
assert.throws(() => {
validate_config({
kit: {
prerender: {
pages: ['foo']
entries: ['foo']
}
}
});
}, /^Each member of config\.kit.prerender.pages must be either '\*' or an absolute path beginning with '\/' — saw 'foo'$/);
}, /^Each member of config\.kit.prerender.entries must be either '\*' or an absolute path beginning with '\/' — saw 'foo'$/);
});

/**
Expand Down
32 changes: 19 additions & 13 deletions packages/kit/src/core/config/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,21 @@ const options = object(
prerender: object({
crawl: boolean(true),
enabled: boolean(true),
entries: validate(['*'], (input, keypath) => {
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
throw new Error(`${keypath} must be an array of strings`);
}

input.forEach((page) => {
if (page !== '*' && page[0] !== '/') {
throw new Error(
`Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
);
}
});

return input;
}),
// TODO: remove this for the 1.0 release
force: validate(undefined, (input, keypath) => {
if (typeof input !== undefined) {
Expand All @@ -141,20 +156,11 @@ const options = object(
`${keypath} should be either a custom function or one of "continue" or "fail"`
);
}),
pages: validate(['*'], (input, keypath) => {
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
throw new Error(`${keypath} must be an array of strings`);
// TODO: remove this for the 1.0 release
pages: validate(undefined, (input, keypath) => {
if (typeof input !== undefined) {
throw new Error(`${keypath} has been renamed to \`entries\`.`);
}

input.forEach((page) => {
if (page !== '*' && page[0] !== '/') {
throw new Error(
`Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
);
}
});

return input;
})
}),

Expand Down
9 changes: 8 additions & 1 deletion packages/kit/src/core/config/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ async function testLoadDefaultConfig(path) {
exclude: []
},
paths: { base: '', assets: '' },
prerender: { crawl: true, enabled: true, force: undefined, onError: 'fail', pages: ['*'] },
prerender: {
crawl: true,
enabled: true,
entries: ['*'],
force: undefined,
onError: 'fail',
pages: undefined
},
router: true,
ssr: true,
target: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export interface Config {
prerender?: {
crawl?: boolean;
enabled?: boolean;
entries?: string[];
onError?: PrerenderOnErrorValue;
pages?: string[];
};
router?: boolean;
serviceWorker?: {
Expand Down

0 comments on commit d23c8b8

Please sign in to comment.