wait inside handle function when exporting

This commit is contained in:
Rich Harris
2019-04-29 11:55:03 -04:00
parent ff60a7b389
commit 1707fe8e9d
2 changed files with 9 additions and 4 deletions

View File

@@ -58,7 +58,7 @@
"svelte-loader": "^2.13.3", "svelte-loader": "^2.13.3",
"webpack": "^4.29.0", "webpack": "^4.29.0",
"webpack-format-messages": "^2.0.5", "webpack-format-messages": "^2.0.5",
"yootils": "bwbroersma/yootils#gh-3" "yootils": "0.0.15"
}, },
"peerDependencies": { "peerDependencies": {
"svelte": "^3.0.0" "svelte": "^3.0.0"

View File

@@ -126,7 +126,7 @@ async function _export({
async function handle(url: URL) { async function handle(url: URL) {
let pathname = url.pathname; let pathname = url.pathname;
if (pathname !== '/service-worker-index.html') { if (pathname !== '/service-worker-index.html') {
pathname = pathname.replace(root.pathname, '') || '/' pathname = pathname.replace(root.pathname, '') || '/'
} }
if (seen.has(pathname)) return; if (seen.has(pathname)) return;
@@ -162,6 +162,7 @@ async function _export({
`<link rel="preload" as=${JSON.stringify(ref.as)} href=${JSON.stringify(ref.uri)}></head>`) `<link rel="preload" as=${JSON.stringify(ref.as)} href=${JSON.stringify(ref.uri)}></head>`)
} }
}); });
if (pathname !== '/service-worker-index.html') { if (pathname !== '/service-worker-index.html') {
const cleaned = clean_html(body); const cleaned = clean_html(body);
@@ -172,6 +173,8 @@ async function _export({
let match; let match;
let pattern = /<a ([\s\S]+?)>/gm; let pattern = /<a ([\s\S]+?)>/gm;
let promise;
while (match = pattern.exec(cleaned)) { while (match = pattern.exec(cleaned)) {
const attrs = match[1]; const attrs = match[1];
const href = get_href(attrs); const href = get_href(attrs);
@@ -180,10 +183,12 @@ async function _export({
const url = resolve(base.href, href); const url = resolve(base.href, href);
if (url.protocol === protocol && url.host === host) { if (url.protocol === protocol && url.host === host) {
q.add(() => handle(url)); promise = q.add(() => handle(url));
} }
} }
} }
await promise;
} }
} }
} }
@@ -202,8 +207,8 @@ async function _export({
return ports.wait(port) return ports.wait(port)
.then(() => handle(root)) .then(() => handle(root))
.then(() => q.close())
.then(() => handle(resolve(root.href, 'service-worker-index.html'))) .then(() => handle(resolve(root.href, 'service-worker-index.html')))
.then(() => q.close())
.then(() => proc.kill()) .then(() => proc.kill())
.catch(err => { .catch(err => {
proc.kill(); proc.kill();