mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-11 19:04:30 +00:00
Merge branch 'master' into nolan/preload-in-export
This commit is contained in:
@@ -3,7 +3,6 @@ sudo: false
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "6"
|
||||
- "stable"
|
||||
|
||||
env:
|
||||
|
||||
@@ -10,7 +10,7 @@ build: off
|
||||
environment:
|
||||
matrix:
|
||||
# node.js
|
||||
- nodejs_version: 10.5
|
||||
- nodejs_version: 11
|
||||
|
||||
install:
|
||||
- ps: Install-Product node $env:nodejs_version
|
||||
|
||||
2125
package-lock.json
generated
2125
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -21,17 +21,13 @@
|
||||
"html-minifier": "^3.5.21",
|
||||
"http-link-header": "^1.0.2",
|
||||
"shimport": "0.0.14",
|
||||
"source-map-support": "^0.5.10",
|
||||
"sourcemap-codec": "^1.4.4",
|
||||
"string-hash": "^1.1.3",
|
||||
"tslib": "^1.9.3"
|
||||
"string-hash": "^1.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/mkdirp": "^0.5.2",
|
||||
"@types/mocha": "^5.2.5",
|
||||
"@types/node": "^10.12.21",
|
||||
"@types/puppeteer": "^1.11.3",
|
||||
"@types/rimraf": "^2.0.2",
|
||||
"agadoo": "^1.0.1",
|
||||
"cheap-watch": "^1.0.2",
|
||||
"cookie": "^0.3.1",
|
||||
@@ -39,7 +35,6 @@
|
||||
"eslint": "^5.12.1",
|
||||
"eslint-plugin-import": "^2.16.0",
|
||||
"kleur": "^3.0.1",
|
||||
"mkdirp": "^0.5.1",
|
||||
"mocha": "^5.2.0",
|
||||
"node-fetch": "^2.3.0",
|
||||
"npm-run-all": "^4.1.5",
|
||||
@@ -48,7 +43,6 @@
|
||||
"pretty-bytes": "^5.1.0",
|
||||
"puppeteer": "^1.12.0",
|
||||
"require-relative": "^0.8.7",
|
||||
"rimraf": "^2.6.3",
|
||||
"rollup": "^1.1.2",
|
||||
"rollup-plugin-commonjs": "^9.2.0",
|
||||
"rollup-plugin-json": "^3.1.0",
|
||||
@@ -58,7 +52,6 @@
|
||||
"rollup-plugin-sucrase": "^2.1.0",
|
||||
"rollup-plugin-svelte": "^5.0.1",
|
||||
"sade": "^1.4.2",
|
||||
"sander": "^0.6.0",
|
||||
"sirv": "^0.2.2",
|
||||
"sucrase": "^3.9.5",
|
||||
"svelte": "^3.0.0-alpha27",
|
||||
|
||||
@@ -38,7 +38,7 @@ function template(kind, external) {
|
||||
|
||||
export default [
|
||||
template('app', id => /^(svelte\/?|@sapper\/)/.test(id)),
|
||||
template('server', id => builtinModules.includes(id)),
|
||||
template('server', id => /^(svelte\/?|@sapper\/)/.test(id) || builtinModules.includes(id)),
|
||||
|
||||
{
|
||||
input: [
|
||||
|
||||
@@ -158,7 +158,7 @@ export async function navigate(target: Target, id: number, noscroll?: boolean, h
|
||||
|
||||
if (hash) {
|
||||
// scroll is an element id (from a hash), we need to compute y.
|
||||
const deep_linked = document.querySelector(hash);
|
||||
const deep_linked = document.getElementById(hash.slice(1));
|
||||
|
||||
if (deep_linked) {
|
||||
scroll = {
|
||||
@@ -338,4 +338,4 @@ export function load_component(component: ComponentLoader): Promise<{
|
||||
|
||||
function detach(node: Node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,11 +52,6 @@ export default function middleware(opts: {
|
||||
next();
|
||||
},
|
||||
|
||||
fs.existsSync(path.join(build_dir, 'index.html')) && serve({
|
||||
pathname: '/index.html',
|
||||
cache_control: dev ? 'no-cache' : 'max-age=600'
|
||||
}),
|
||||
|
||||
fs.existsSync(path.join(build_dir, 'service-worker.js')) && serve({
|
||||
pathname: '/service-worker.js',
|
||||
cache_control: 'no-cache, no-store, must-revalidate'
|
||||
@@ -143,4 +138,4 @@ export function serve({ prefix, pathname, cache_control }: {
|
||||
};
|
||||
}
|
||||
|
||||
function noop(){}
|
||||
function noop(){}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import mkdirp from 'mkdirp';
|
||||
import rimraf from 'rimraf';
|
||||
import minify_html from './utils/minify_html';
|
||||
import { create_compilers, create_main_manifests, create_manifest_data, create_serviceworker_manifest } from '../core';
|
||||
import { copy_shimport } from './utils/copy_shimport';
|
||||
@@ -10,6 +8,7 @@ import { CompileResult } from '../core/create_compilers/interfaces';
|
||||
import { noop } from './utils/noop';
|
||||
import validate_bundler from './utils/validate_bundler';
|
||||
import { copy_runtime } from './utils/copy_runtime';
|
||||
import { rimraf, mkdirp } from './utils/fs_utils';
|
||||
|
||||
type Opts = {
|
||||
cwd?: string;
|
||||
@@ -48,12 +47,12 @@ export async function build({
|
||||
throw new Error(`Legacy builds are not supported for projects using webpack`);
|
||||
}
|
||||
|
||||
rimraf.sync(path.join(output, '**/*'));
|
||||
mkdirp.sync(output);
|
||||
rimraf(output);
|
||||
mkdirp(output);
|
||||
copy_runtime(output);
|
||||
|
||||
rimraf.sync(path.join(dest, '**/*'));
|
||||
mkdirp.sync(`${dest}/client`);
|
||||
rimraf(dest);
|
||||
mkdirp(`${dest}/client`);
|
||||
copy_shimport(dest);
|
||||
|
||||
// minify src/template.html
|
||||
|
||||
@@ -3,8 +3,6 @@ import * as fs from 'fs';
|
||||
import * as http from 'http';
|
||||
import * as child_process from 'child_process';
|
||||
import * as ports from 'port-authority';
|
||||
import mkdirp from 'mkdirp';
|
||||
import rimraf from 'rimraf';
|
||||
import { EventEmitter } from 'events';
|
||||
import { create_manifest_data, create_main_manifests, create_compilers, create_serviceworker_manifest } from '../core';
|
||||
import { Compiler, Compilers } from '../core/create_compilers';
|
||||
@@ -16,6 +14,7 @@ import { ManifestData, FatalEvent, ErrorEvent, ReadyEvent, InvalidEvent } from '
|
||||
import read_template from '../core/read_template';
|
||||
import { noop } from './utils/noop';
|
||||
import { copy_runtime } from './utils/copy_runtime';
|
||||
import { rimraf, mkdirp } from './utils/fs_utils';
|
||||
|
||||
type Opts = {
|
||||
cwd?: string,
|
||||
@@ -146,12 +145,12 @@ class Watcher extends EventEmitter {
|
||||
|
||||
const { cwd, src, dest, routes, output, static: static_files } = this.dirs;
|
||||
|
||||
rimraf.sync(path.join(output, '**/*'));
|
||||
mkdirp.sync(output);
|
||||
rimraf(output);
|
||||
mkdirp(output);
|
||||
copy_runtime(output);
|
||||
|
||||
rimraf.sync(dest);
|
||||
mkdirp.sync(`${dest}/client`);
|
||||
rimraf(dest);
|
||||
mkdirp(`${dest}/client`);
|
||||
if (this.bundler === 'rollup') copy_shimport(dest);
|
||||
|
||||
if (!this.dev_port) this.dev_port = await ports.find(10000);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as child_process from 'child_process';
|
||||
import * as fs from 'fs';
|
||||
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';
|
||||
@@ -10,6 +10,7 @@ import minify_html from './utils/minify_html';
|
||||
import Deferred from './utils/Deferred';
|
||||
import { noop } from './utils/noop';
|
||||
import { parse as parseLinkHeader } from 'http-link-header';
|
||||
import { rimraf, copy, mkdirp } from './utils/fs_utils';
|
||||
|
||||
type Opts = {
|
||||
build_dir?: string,
|
||||
@@ -54,20 +55,15 @@ async function _export({
|
||||
export_dir = path.resolve(cwd, export_dir, basepath);
|
||||
|
||||
// Prep output directory
|
||||
sander.rimrafSync(export_dir);
|
||||
rimraf(export_dir);
|
||||
|
||||
sander.copydirSync(static_files).to(export_dir);
|
||||
sander.copydirSync(build_dir, 'client').to(export_dir, 'client');
|
||||
copy(static_files, export_dir);
|
||||
copy(path.join(build_dir, 'client'), path.join(export_dir, 'client'));
|
||||
copy(path.join(build_dir, 'service-worker.js'), path.join(export_dir, 'service-worker.js'));
|
||||
copy(path.join(build_dir, 'service-worker.js.map'), path.join(export_dir, 'service-worker.js.map'));
|
||||
|
||||
if (sander.existsSync(build_dir, 'service-worker.js')) {
|
||||
sander.copyFileSync(build_dir, 'service-worker.js').to(export_dir, 'service-worker.js');
|
||||
}
|
||||
|
||||
if (sander.existsSync(build_dir, 'service-worker.js.map')) {
|
||||
sander.copyFileSync(build_dir, 'service-worker.js.map').to(export_dir, 'service-worker.js.map');
|
||||
}
|
||||
|
||||
const port = await ports.find(3000);
|
||||
const defaultPort = process.env.PORT ? parseInt(process.env.PORT) : 3000;
|
||||
const port = await ports.find(defaultPort);
|
||||
|
||||
const protocol = 'http:';
|
||||
const host = `localhost:${port}`;
|
||||
@@ -92,8 +88,8 @@ async function _export({
|
||||
const seen = new Set();
|
||||
const saved = new Set();
|
||||
|
||||
function save(path: string, status: number, type: string, body: string) {
|
||||
const { pathname } = resolve(origin, path);
|
||||
function save(url: string, status: number, type: string, body: string) {
|
||||
const { pathname } = resolve(origin, url);
|
||||
let file = decodeURIComponent(pathname.slice(1));
|
||||
|
||||
if (saved.has(file)) return;
|
||||
@@ -114,7 +110,9 @@ async function _export({
|
||||
status
|
||||
});
|
||||
|
||||
sander.writeFileSync(export_dir, file, body);
|
||||
const export_file = path.join(export_dir, file);
|
||||
mkdirp(path.dirname(export_file));
|
||||
fs.writeFileSync(export_file, body);
|
||||
}
|
||||
|
||||
proc.on('message', message => {
|
||||
@@ -217,4 +215,4 @@ async function _export({
|
||||
function get_href(attrs: string) {
|
||||
const match = /href\s*=\s*(?:"(.*?)"|'(.+?)'|([^\s>]+))/.exec(attrs);
|
||||
return match[1] || match[2] || match[3];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import mkdirp from 'mkdirp';
|
||||
import { mkdirp } from './fs_utils';
|
||||
|
||||
const runtime = [
|
||||
'app.mjs',
|
||||
@@ -16,7 +16,7 @@ const runtime = [
|
||||
|
||||
export function copy_runtime(output: string) {
|
||||
runtime.forEach(({ file, source }) => {
|
||||
mkdirp.sync(path.dirname(`${output}/${file}`));
|
||||
mkdirp(path.dirname(`${output}/${file}`));
|
||||
fs.writeFileSync(`${output}/${file}`, source);
|
||||
});
|
||||
}
|
||||
46
src/api/utils/fs_utils.ts
Normal file
46
src/api/utils/fs_utils.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
export function mkdirp(dir: string) {
|
||||
const parent = path.dirname(dir);
|
||||
if (parent === dir) return;
|
||||
|
||||
mkdirp(parent);
|
||||
|
||||
try {
|
||||
fs.mkdirSync(dir);
|
||||
} catch (err) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
export function rimraf(thing: string) {
|
||||
if (!fs.existsSync(thing)) return;
|
||||
|
||||
const stats = fs.statSync(thing);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
fs.readdirSync(thing).forEach(file => {
|
||||
rimraf(path.join(thing, file));
|
||||
});
|
||||
|
||||
fs.rmdirSync(thing);
|
||||
} else {
|
||||
fs.unlinkSync(thing);
|
||||
}
|
||||
}
|
||||
|
||||
export function copy(from: string, to: string) {
|
||||
if (!fs.existsSync(from)) return;
|
||||
|
||||
const stats = fs.statSync(from);
|
||||
|
||||
if (stats.isDirectory()) {
|
||||
fs.readdirSync(from).forEach(file => {
|
||||
copy(path.join(from, file), path.join(to, file));
|
||||
});
|
||||
} else {
|
||||
mkdirp(path.dirname(to));
|
||||
fs.writeFileSync(to, fs.readFileSync(from));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user