This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
Allow export to take multiple entrypoints to use when crawling. #825
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import resolve from 'rollup-plugin-node-resolve'; | ||
import replace from 'rollup-plugin-replace'; | ||
import svelte from 'rollup-plugin-svelte'; | ||
|
||
const mode = process.env.NODE_ENV; | ||
const dev = mode === 'development'; | ||
|
||
const config = require('../../../config/rollup.js'); | ||
|
||
export default { | ||
client: { | ||
input: config.client.input(), | ||
output: config.client.output(), | ||
plugins: [ | ||
replace({ | ||
'process.browser': true, | ||
'process.env.NODE_ENV': JSON.stringify(mode) | ||
}), | ||
svelte({ | ||
dev, | ||
hydratable: true, | ||
emitCss: true | ||
}), | ||
resolve() | ||
] | ||
}, | ||
|
||
server: { | ||
input: config.server.input(), | ||
output: config.server.output(), | ||
plugins: [ | ||
replace({ | ||
'process.browser': false, | ||
'process.env.NODE_ENV': JSON.stringify(mode) | ||
}), | ||
svelte({ | ||
generate: 'ssr', | ||
dev | ||
}), | ||
resolve({ | ||
preferBuiltins: true | ||
}) | ||
], | ||
external: ['sirv', 'polka'] | ||
}, | ||
|
||
serviceworker: { | ||
input: config.serviceworker.input(), | ||
output: config.serviceworker.output(), | ||
plugins: [ | ||
resolve(), | ||
replace({ | ||
'process.browser': true, | ||
'process.env.NODE_ENV': JSON.stringify(mode) | ||
}) | ||
] | ||
} | ||
}; |
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,9 @@ | ||
import * as sapper from '@sapper/app'; | ||
|
||
window.start = () => sapper.start({ | ||
target: document.querySelector('#sapper') | ||
}); | ||
|
||
window.prefetchRoutes = () => sapper.prefetchRoutes(); | ||
window.prefetch = href => sapper.prefetch(href); | ||
window.goto = href => sapper.goto(href); |
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,3 @@ | ||
<h1>{status}</h1> | ||
|
||
<p>{error.message}</p> |
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 @@ | ||
<h1>I am an about page</h1> |
13 changes: 13 additions & 0 deletions
13
test/apps/export-multiple-entry/src/routes/blog/[slug].html
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,13 @@ | ||
<script context="module"> | ||
export function preload({ params }) { | ||
return this.fetch(`blog/${params.slug}.json`).then(r => r.json()).then(post => { | ||
return { post }; | ||
}); | ||
} | ||
</script> | ||
|
||
<script> | ||
export let post; | ||
</script> | ||
|
||
<h1>{post.title}</h1> |
19 changes: 19 additions & 0 deletions
19
test/apps/export-multiple-entry/src/routes/blog/[slug].json.js
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 @@ | ||
import posts from './_posts.js'; | ||
|
||
export function get(req, res) { | ||
const post = posts.find(post => post.slug === req.params.slug); | ||
|
||
if (post) { | ||
res.writeHead(200, { | ||
'Content-Type': 'application/json' | ||
}); | ||
|
||
res.end(JSON.stringify(post)); | ||
} else { | ||
res.writeHead(404, { | ||
'Content-Type': 'application/json' | ||
}); | ||
|
||
res.end(JSON.stringify({ message: 'not found' })); | ||
} | ||
} |
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 @@ | ||
export default [ | ||
{ slug: 'foo', title: 'once upon a foo' }, | ||
{ slug: 'bar', title: 'a bar is born' }, | ||
{ slug: 'baz', title: 'bazzily ever after' } | ||
]; |
17 changes: 17 additions & 0 deletions
17
test/apps/export-multiple-entry/src/routes/blog/index.html
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 @@ | ||
<script context="module"> | ||
export function preload() { | ||
return this.fetch('blog.json').then(r => r.json()).then(posts => { | ||
return { posts }; | ||
}); | ||
} | ||
</script> | ||
|
||
<script> | ||
export let posts; | ||
</script> | ||
|
||
<h1>blog</h1> | ||
|
||
{#each posts as post} | ||
<p><a href="blog/{post.slug}">{post.title}</a></p> | ||
{/each} |
9 changes: 9 additions & 0 deletions
9
test/apps/export-multiple-entry/src/routes/blog/index.json.js
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,9 @@ | ||
import posts from './_posts.js'; | ||
|
||
export function get(req, res) { | ||
res.writeHead(200, { | ||
'Content-Type': 'application/json' | ||
}); | ||
|
||
res.end(JSON.stringify(posts)); | ||
} |
12 changes: 12 additions & 0 deletions
12
test/apps/export-multiple-entry/src/routes/boom/[a]/[b].svelte
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,12 @@ | ||
<script context="module"> | ||
export function preload({ params }) { | ||
return params; | ||
} | ||
</script> | ||
|
||
<script> | ||
export let a; | ||
export let b; | ||
</script> | ||
|
||
<p>{a}/{b}</p> |
15 changes: 15 additions & 0 deletions
15
test/apps/export-multiple-entry/src/routes/boom/[a]/index.svelte
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,15 @@ | ||
<script context="module"> | ||
export function preload({ params }) { | ||
return params; | ||
} | ||
</script> | ||
|
||
<script> | ||
export let a; | ||
|
||
const list = Array(20).fill().map((_, i) => i + 1); | ||
</script> | ||
|
||
{#each list as b} | ||
<a href="boom/{a}/{b}">{a}/{b}</a> | ||
{/each} |
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,7 @@ | ||
<script> | ||
const list = Array(20).fill().map((_, i) => i + 1); | ||
</script> | ||
|
||
{#each list as a} | ||
<a href="boom/{a}">{a}</a> | ||
{/each} |
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 @@ | ||
<h1>I am a contact page</h1> |
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,8 @@ | ||
<h1>Great success!</h1> | ||
|
||
<a href="">empty anchor</a> | ||
<a href="">empty anchor #2</a> | ||
<a href="">empty anchor #3</a> | ||
<a href="">empty anchor #4</a> | ||
<a href>empty anchor #5</a> | ||
<a>empty anchor #6</a> |
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,13 @@ | ||
import sirv from 'sirv'; | ||
import polka from 'polka'; | ||
import * as sapper from '@sapper/server'; | ||
|
||
import { start, dev } from '../../common.js'; | ||
|
||
const app = polka() | ||
.use( | ||
sirv('static', { dev }), | ||
sapper.middleware() | ||
); | ||
|
||
start(app); |
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,82 @@ | ||
import * as sapper from '@sapper/service-worker'; | ||
|
||
const ASSETS = `cache${sapper.timestamp}`; | ||
|
||
// `shell` is an array of all the files generated by webpack, | ||
// `files` is an array of everything in the `static` directory | ||
const to_cache = sapper.shell.concat(sapper.files); | ||
const cached = new Set(to_cache); | ||
|
||
self.addEventListener('install', event => { | ||
event.waitUntil( | ||
caches | ||
.open(ASSETS) | ||
.then(cache => cache.addAll(to_cache)) | ||
.then(() => { | ||
self.skipWaiting(); | ||
}) | ||
); | ||
}); | ||
|
||
self.addEventListener('activate', event => { | ||
event.waitUntil( | ||
caches.keys().then(async keys => { | ||
// delete old caches | ||
for (const key of keys) { | ||
if (key !== ASSETS) await caches.delete(key); | ||
} | ||
|
||
self.clients.claim(); | ||
}) | ||
); | ||
}); | ||
|
||
self.addEventListener('fetch', event => { | ||
if (event.request.method !== 'GET') return; | ||
|
||
const url = new URL(event.request.url); | ||
|
||
// don't try to handle e.g. data: URIs | ||
if (!url.protocol.startsWith('http')) return; | ||
|
||
// ignore dev server requests | ||
if (url.hostname === self.location.hostname && url.port !== self.location.port) return; | ||
|
||
// always serve assets and webpack-generated files from cache | ||
if (url.host === self.location.host && cached.has(url.pathname)) { | ||
event.respondWith(caches.match(event.request)); | ||
return; | ||
} | ||
|
||
// for pages, you might want to serve a shell `index.html` file, | ||
// which Sapper has generated for you. It's not right for every | ||
// app, but if it's right for yours then uncomment this section | ||
/* | ||
if (url.origin === self.origin && routes.find(route => route.pattern.test(url.pathname))) { | ||
event.respondWith(caches.match('/index.html')); | ||
return; | ||
} | ||
*/ | ||
|
||
if (event.request.cache === 'only-if-cached') return; | ||
|
||
// for everything else, try the network first, falling back to | ||
// cache if the user is offline. (If the pages never change, you | ||
// might prefer a cache-first approach to a network-first one.) | ||
event.respondWith( | ||
caches | ||
.open(`offline${sapper.timestamp}`) | ||
.then(async cache => { | ||
try { | ||
const response = await fetch(event.request); | ||
cache.put(event.request, response.clone()); | ||
return response; | ||
} catch(err) { | ||
const response = await cache.match(event.request); | ||
if (response) return response; | ||
|
||
throw err; | ||
} | ||
}) | ||
); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for resolving this relative to the current entry point? I think this should still always be relative to
root
. My understanding is that the multiple entry points is just so that the crawler can find pages it wouldn't ordinarily find. All of them should still have the same base href value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test you wrote still passes when using
root.href
, fwiwThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think you're right. I don't think I looked too deeply into this but I guess this clause is handling redirects/ 300s? I think it's using the
Location
header and building a new url tohandle
from that. My tests definitely don't test this behaviour, I don't know if any of the existing ones do either but resolving with anything but the root url would fail, I think.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, looking back this clears up some of the confusion I had at the time with the whole
entryPoints[currentRoot]
thing, I wondered why that was necessary. This correction removes the need for that entirely. I probably should have taken more time to understand the code before implementing this.