merge master -> svelte-3, fix various typescript and webpack oddities

This commit is contained in:
Richard Harris
2019-02-01 08:21:45 -05:00
36 changed files with 794 additions and 200 deletions

View File

@@ -42,7 +42,6 @@ export async function build({
routes = path.resolve(cwd, routes);
output = path.resolve(cwd, output);
static_files = path.resolve(cwd, static_files);
dest = path.resolve(cwd, dest);
if (legacy && bundler === 'webpack') {
throw new Error(`Legacy builds are not supported for projects using webpack`);
@@ -119,10 +118,15 @@ export async function build({
let serviceworker_stats;
if (serviceworker) {
const client_files = client_result.chunks
.filter(chunk => !chunk.file.endsWith('.map')) // SW does not need to cache sourcemap files
.map(chunk => `client/${chunk.file}`);
create_serviceworker_manifest({
manifest_data,
output,
client_files: client_result.chunks.map(chunk => `client/${chunk.file}`),
client_files,
static_files
});

View File

@@ -3,6 +3,7 @@ import * as path from 'path';
import * as sander from 'sander';
import * as url from 'url';
import fetch from 'node-fetch';
import * as yootils from 'yootils';
import * as ports from 'port-authority';
import clean_html from './utils/clean_html';
import minify_html from './utils/minify_html';
@@ -94,7 +95,9 @@ async function _export({
const is_html = type === 'text/html';
if (is_html) {
file = file === '' ? 'index.html' : `${file}/index.html`;
if (pathname !== '/service-worker-index.html') {
file = file === '' ? 'index.html' : `${file}/index.html`;
}
body = minify_html(body);
}
@@ -113,7 +116,10 @@ async function _export({
});
async function handle(url: URL) {
const pathname = (url.pathname.replace(root.pathname, '') || '/');
let pathname = url.pathname;
if (pathname !== '/service-worker-index.html') {
pathname = pathname.replace(root.pathname, '') || '/'
}
if (seen.has(pathname)) return;
seen.add(pathname);
@@ -138,11 +144,12 @@ async function _export({
const range = ~~(r.status / 100);
if (range === 2) {
if (type === 'text/html') {
const urls: URL[] = [];
if (type === 'text/html' && pathname !== '/service-worker-index.html') {
const cleaned = clean_html(body);
const q = yootils.queue(8);
let promise;
const base_match = /<base ([\s\S]+?)>/m.exec(cleaned);
const base_href = base_match && get_href(base_match[1]);
const base = resolve(url.href, base_href);
@@ -158,12 +165,12 @@ async function _export({
const url = resolve(base.href, href);
if (url.protocol === protocol && url.host === host) {
urls.push(url);
promise = q.add(() => handle(url));
}
}
}
await Promise.all(urls.map(handle));
await promise;
}
}
@@ -181,6 +188,7 @@ async function _export({
return ports.wait(port)
.then(() => handle(root))
.then(() => handle(resolve(root.href, 'service-worker-index.html')))
.then(() => proc.kill())
.catch(err => {
proc.kill();