mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-15 12:24:47 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8240595d70 | ||
|
|
658d8dd50c | ||
|
|
9eeeaa24c1 | ||
|
|
9c4a3592ff | ||
|
|
be7cff4818 | ||
|
|
d6632cf312 | ||
|
|
f6e012ec73 |
@@ -1,5 +1,13 @@
|
|||||||
# sapper changelog
|
# sapper changelog
|
||||||
|
|
||||||
|
## 0.13.2
|
||||||
|
|
||||||
|
* Emit a `basepath` event ([#284](https://github.com/sveltejs/sapper/pull/284))
|
||||||
|
|
||||||
|
## 0.13.1
|
||||||
|
|
||||||
|
* Reinstate ten-second interval between dev server heartbeats ([#276](https://github.com/sveltejs/sapper/issues/276))
|
||||||
|
|
||||||
## 0.13.0
|
## 0.13.0
|
||||||
|
|
||||||
* Expose `dev`, `build`, `export` and `find_page` APIs ([#272](https://github.com/sveltejs/sapper/issues/272))
|
* Expose `dev`, `build`, `export` and `find_page` APIs ([#272](https://github.com/sveltejs/sapper/issues/272))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sapper",
|
"name": "sapper",
|
||||||
"version": "0.13.0",
|
"version": "0.13.2",
|
||||||
"description": "Military-grade apps, engineered by Svelte",
|
"description": "Military-grade apps, engineered by Svelte",
|
||||||
"main": "dist/middleware.ts.js",
|
"main": "dist/middleware.ts.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import * as ports from 'port-authority';
|
|||||||
import mkdirp from 'mkdirp';
|
import mkdirp from 'mkdirp';
|
||||||
import rimraf from 'rimraf';
|
import rimraf from 'rimraf';
|
||||||
import format_messages from 'webpack-format-messages';
|
import format_messages from 'webpack-format-messages';
|
||||||
import prettyMs from 'pretty-ms';
|
|
||||||
import { locations } from '../config';
|
import { locations } from '../config';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { create_routes, create_main_manifests, create_compilers, create_serviceworker_manifest } from '../core';
|
import { create_routes, create_main_manifests, create_compilers, create_serviceworker_manifest } from '../core';
|
||||||
@@ -172,6 +171,14 @@ class Watcher extends EventEmitter {
|
|||||||
}, process.env),
|
}, process.env),
|
||||||
stdio: ['ipc']
|
stdio: ['ipc']
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.proc.on('message', message => {
|
||||||
|
if (message.__sapper__ && message.event === 'basepath') {
|
||||||
|
this.emit('basepath', {
|
||||||
|
basepath: message.basepath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -353,8 +360,11 @@ class Deferred {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const INTERVAL = 10000;
|
||||||
|
|
||||||
class DevServer {
|
class DevServer {
|
||||||
clients: Set<http.ServerResponse>;
|
clients: Set<http.ServerResponse>;
|
||||||
|
interval: NodeJS.Timer;
|
||||||
_: http.Server;
|
_: http.Server;
|
||||||
|
|
||||||
constructor(port: number, interval = 10000) {
|
constructor(port: number, interval = 10000) {
|
||||||
@@ -385,13 +395,14 @@ class DevServer {
|
|||||||
|
|
||||||
this._.listen(port);
|
this._.listen(port);
|
||||||
|
|
||||||
setInterval(() => {
|
this.interval = setInterval(() => {
|
||||||
this.send(null);
|
this.send(null);
|
||||||
});
|
}, INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
this._.close();
|
this._.close();
|
||||||
|
clearInterval(this.interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
send(data: any) {
|
send(data: any) {
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ async function execute(emitter: EventEmitter, {
|
|||||||
const saved = new Set();
|
const saved = new Set();
|
||||||
|
|
||||||
proc.on('message', message => {
|
proc.on('message', message => {
|
||||||
if (!message.__sapper__) return;
|
if (!message.__sapper__ || message.event !== 'file') return;
|
||||||
|
|
||||||
let file = new URL(message.url, origin).pathname.slice(1);
|
let file = new URL(message.url, origin).pathname.slice(1);
|
||||||
let { body } = message;
|
let { body } = message;
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { resolve, URL } from 'url';
|
import { URL } from 'url';
|
||||||
import { ClientRequest, ServerResponse } from 'http';
|
import { ClientRequest, ServerResponse } from 'http';
|
||||||
import cookie from 'cookie';
|
import cookie from 'cookie';
|
||||||
import mkdirp from 'mkdirp';
|
|
||||||
import rimraf from 'rimraf';
|
|
||||||
import devalue from 'devalue';
|
import devalue from 'devalue';
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import { lookup } from './middleware/mime';
|
import { lookup } from './middleware/mime';
|
||||||
import { locations, dev } from './config';
|
import { locations, dev } from './config';
|
||||||
import { Route, Template } from './interfaces';
|
|
||||||
import sourceMapSupport from 'source-map-support';
|
import sourceMapSupport from 'source-map-support';
|
||||||
|
|
||||||
sourceMapSupport.install();
|
sourceMapSupport.install();
|
||||||
@@ -61,6 +58,8 @@ export default function middleware({ App, routes, store }: {
|
|||||||
|
|
||||||
const client_assets = JSON.parse(fs.readFileSync(path.join(output, 'client_assets.json'), 'utf-8'));
|
const client_assets = JSON.parse(fs.readFileSync(path.join(output, 'client_assets.json'), 'utf-8'));
|
||||||
|
|
||||||
|
let emitted_basepath = false;
|
||||||
|
|
||||||
const middleware = compose_handlers([
|
const middleware = compose_handlers([
|
||||||
(req: Req, res: ServerResponse, next: () => void) => {
|
(req: Req, res: ServerResponse, next: () => void) => {
|
||||||
if (req.baseUrl === undefined) {
|
if (req.baseUrl === undefined) {
|
||||||
@@ -69,6 +68,16 @@ export default function middleware({ App, routes, store }: {
|
|||||||
: '';
|
: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!emitted_basepath && process.send) {
|
||||||
|
process.send({
|
||||||
|
__sapper__: true,
|
||||||
|
event: 'basepath',
|
||||||
|
basepath: req.baseUrl
|
||||||
|
});
|
||||||
|
|
||||||
|
emitted_basepath = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (req.path === undefined) {
|
if (req.path === undefined) {
|
||||||
req.path = req.url.replace(/\?.*/, '');
|
req.path = req.url.replace(/\?.*/, '');
|
||||||
}
|
}
|
||||||
@@ -139,8 +148,6 @@ function serve({ prefix, pathname, cache_control }: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolved = Promise.resolve();
|
|
||||||
|
|
||||||
function get_route_handler(chunks: Record<string, string>, App: Component, routes: RouteObject[], store_getter: (req: Req) => Store) {
|
function get_route_handler(chunks: Record<string, string>, App: Component, routes: RouteObject[], store_getter: (req: Req) => Store) {
|
||||||
const template = dev()
|
const template = dev()
|
||||||
? () => fs.readFileSync(`${locations.app()}/template.html`, 'utf-8')
|
? () => fs.readFileSync(`${locations.app()}/template.html`, 'utf-8')
|
||||||
@@ -281,6 +288,7 @@ function get_route_handler(chunks: Record<string, string>, App: Component, route
|
|||||||
if (process.send) {
|
if (process.send) {
|
||||||
process.send({
|
process.send({
|
||||||
__sapper__: true,
|
__sapper__: true,
|
||||||
|
event: 'file',
|
||||||
url: req.url,
|
url: req.url,
|
||||||
method: req.method,
|
method: req.method,
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -320,6 +328,7 @@ function get_route_handler(chunks: Record<string, string>, App: Component, route
|
|||||||
|
|
||||||
process.send({
|
process.send({
|
||||||
__sapper__: true,
|
__sapper__: true,
|
||||||
|
event: 'file',
|
||||||
url: req.url,
|
url: req.url,
|
||||||
method: req.method,
|
method: req.method,
|
||||||
status: res.statusCode,
|
status: res.statusCode,
|
||||||
@@ -451,10 +460,6 @@ function compose_handlers(handlers: Handler[]) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function read_json(file: string) {
|
|
||||||
return JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function try_serialize(data: any) {
|
function try_serialize(data: any) {
|
||||||
try {
|
try {
|
||||||
return devalue(data);
|
return devalue(data);
|
||||||
|
|||||||
@@ -133,6 +133,7 @@ function run({ mode, basepath = '' }) {
|
|||||||
let capture;
|
let capture;
|
||||||
|
|
||||||
let base;
|
let base;
|
||||||
|
let captured_basepath;
|
||||||
|
|
||||||
const nightmare = new Nightmare();
|
const nightmare = new Nightmare();
|
||||||
|
|
||||||
@@ -179,7 +180,13 @@ function run({ mode, basepath = '' }) {
|
|||||||
let handler;
|
let handler;
|
||||||
|
|
||||||
proc.on('message', message => {
|
proc.on('message', message => {
|
||||||
if (message.__sapper__) return;
|
if (message.__sapper__) {
|
||||||
|
if (message.event === 'basepath') {
|
||||||
|
captured_basepath = basepath;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (handler) handler(message);
|
if (handler) handler(message);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -597,6 +604,10 @@ function run({ mode, basepath = '' }) {
|
|||||||
assert.ok(!hasProgressIndicator);
|
assert.ok(!hasProgressIndicator);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('emits a basepath', () => {
|
||||||
|
assert.equal(captured_basepath, basepath);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('headers', () => {
|
describe('headers', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user