From bf50392df5f9e6d7f8cea1b962bf067a97e657cd Mon Sep 17 00:00:00 2001 From: "Benjamin W. Broersma" Date: Tue, 12 Mar 2019 02:11:09 +0100 Subject: [PATCH] Fixes #604 - using single queue for export. --- package.json | 2 +- src/api/export.ts | 8 ++++---- src/cli.ts | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index eb78f48..049b7b8 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "svelte-loader": "^2.13.3", "webpack": "^4.29.0", "webpack-format-messages": "^2.0.5", - "yootils": "0.0.14" + "yootils": "bwbroersma/yootils#gh-3" }, "peerDependencies": { "svelte": "^3.0.0" diff --git a/src/api/export.ts b/src/api/export.ts index ba6a9db..027e11f 100644 --- a/src/api/export.ts +++ b/src/api/export.ts @@ -19,6 +19,7 @@ type Opts = { static?: string, basepath?: string, timeout?: number | false, + concurrent?: number, oninfo?: ({ message }: { message: string }) => void; onfile?: ({ file, size, status }: { file: string, size: number, status: number }) => void; }; @@ -44,6 +45,7 @@ async function _export({ export_dir = '__sapper__/export', basepath = '', timeout = 5000, + concurrent = 8, oninfo = noop, onfile = noop }: Opts = {}) { @@ -87,6 +89,7 @@ async function _export({ const seen = new Set(); const saved = new Set(); + const q = yootils.queue(concurrent); function save(url: string, status: number, type: string, body: string) { const { pathname } = resolve(origin, url); @@ -162,8 +165,6 @@ async function _export({ if (pathname !== '/service-worker-index.html') { const cleaned = clean_html(body); - const q = yootils.queue(8); - const base_match = //m.exec(cleaned); const base_href = base_match && get_href(base_match[1]); const base = resolve(url.href, base_href); @@ -183,8 +184,6 @@ async function _export({ } } } - - await q.close(); } } } @@ -203,6 +202,7 @@ async function _export({ return ports.wait(port) .then(() => handle(root)) + .then(() => q.close()) .then(() => handle(resolve(root.href, 'service-worker-index.html'))) .then(() => proc.kill()) .catch(err => { diff --git a/src/cli.ts b/src/cli.ts index 5ebacc9..3b7ac79 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -189,6 +189,7 @@ prog.command('export [dest]') .describe('Export your app as static files (if possible)') .option('--build', '(Re)build app before exporting', true) .option('--basepath', 'Specify a base path') + .option('--concurrent', 'Concurrent requests', 8) .option('--timeout', 'Milliseconds to wait for a page (--no-timeout to disable)', 5000) .option('--legacy', 'Create separate legacy build') .option('--bundler', 'Specify a bundler (rollup or webpack, blank for auto)') @@ -203,6 +204,7 @@ prog.command('export [dest]') legacy: boolean, bundler?: 'rollup' | 'webpack', basepath?: string, + concurrent: number, timeout: number | false, cwd: string, src: string, @@ -228,6 +230,7 @@ prog.command('export [dest]') export_dir: dest, basepath: opts.basepath, timeout: opts.timeout, + concurrent: opts.concurrent, oninfo: event => { console.log(colors.bold().cyan(`> ${event.message}`));