mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 11:35:28 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6765e534e4 | ||
|
|
160a2e2ede | ||
|
|
3ecc21c0d9 | ||
|
|
3ffb396d87 | ||
|
|
59fccc9e9a | ||
|
|
da9a37e125 | ||
|
|
499b377bfd | ||
|
|
1baeb79d4b | ||
|
|
0cc5ff95d6 | ||
|
|
e90525c1e8 | ||
|
|
6ccae0cd33 |
@@ -1,5 +1,9 @@
|
||||
# sapper changelog
|
||||
|
||||
## 0.19.3
|
||||
|
||||
* Better unicode route handling ([#347](https://github.com/sveltejs/sapper/issues/347))
|
||||
|
||||
## 0.19.2
|
||||
|
||||
* Ignore editor tmp files ([#220](https://github.com/sveltejs/sapper/issues/220))
|
||||
|
||||
22
package-lock.json
generated
22
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sapper",
|
||||
"version": "0.19.0",
|
||||
"version": "0.19.3",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@@ -10,6 +10,15 @@
|
||||
"integrity": "sha1-MU+BaPUK5IoDLP2tX9tDb0ZKl6w=",
|
||||
"dev": true
|
||||
},
|
||||
"@types/blessed": {
|
||||
"version": "0.1.10",
|
||||
"resolved": "https://registry.npmjs.org/@types/blessed/-/blessed-0.1.10.tgz",
|
||||
"integrity": "sha512-lCpkGnCq2lj9RBPwh/RH/ZJegYV6JdyyRHmURIW1DwMdtNhRRxYeHllqaMu8K6bDf6zhO7PpHsmEqlYMDPlmhw==",
|
||||
"requires": {
|
||||
"@types/events": "*",
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/estree": {
|
||||
"version": "0.0.39",
|
||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz",
|
||||
@@ -19,8 +28,7 @@
|
||||
"@types/events": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
|
||||
"integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA==",
|
||||
"dev": true
|
||||
"integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA=="
|
||||
},
|
||||
"@types/glob": {
|
||||
"version": "5.0.35",
|
||||
@@ -57,8 +65,7 @@
|
||||
"@types/node": {
|
||||
"version": "10.9.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.9.4.tgz",
|
||||
"integrity": "sha512-fCHV45gS+m3hH17zgkgADUSi2RR1Vht6wOZ0jyHP8rjiQra9f+mIcgwPQHllmDocYOstIEbKlxbFDYlgrTPYqw==",
|
||||
"dev": true
|
||||
"integrity": "sha512-fCHV45gS+m3hH17zgkgADUSi2RR1Vht6wOZ0jyHP8rjiQra9f+mIcgwPQHllmDocYOstIEbKlxbFDYlgrTPYqw=="
|
||||
},
|
||||
"@types/rimraf": {
|
||||
"version": "2.0.2",
|
||||
@@ -1010,6 +1017,11 @@
|
||||
"integrity": "sha1-RqoXUftqL5PuXmibsQh9SxTGwgU=",
|
||||
"dev": true
|
||||
},
|
||||
"blessed": {
|
||||
"version": "0.1.81",
|
||||
"resolved": "https://registry.npmjs.org/blessed/-/blessed-0.1.81.tgz",
|
||||
"integrity": "sha1-+WLWh+wsNpVwrnGvhDJW5tDKESk="
|
||||
},
|
||||
"bluebird": {
|
||||
"version": "3.5.1",
|
||||
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sapper",
|
||||
"version": "0.19.2",
|
||||
"version": "0.19.3",
|
||||
"description": "Military-grade apps, engineered by Svelte",
|
||||
"main": "dist/middleware.js",
|
||||
"bin": {
|
||||
@@ -19,6 +19,8 @@
|
||||
"test": "test"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/blessed": "^0.1.10",
|
||||
"blessed": "^0.1.81",
|
||||
"html-minifier": "^3.5.16",
|
||||
"shimport": "^0.0.10",
|
||||
"source-map-support": "^0.5.6",
|
||||
|
||||
@@ -200,6 +200,8 @@ class Watcher extends EventEmitter {
|
||||
handle_result: (result: CompileResult) => {
|
||||
deferred.promise.then(() => {
|
||||
const restart = () => {
|
||||
this.emit('restart');
|
||||
|
||||
log = '';
|
||||
this.crashed = false;
|
||||
|
||||
|
||||
@@ -15,13 +15,15 @@ prog.command('dev')
|
||||
.option('--hot', 'Use hot module replacement (requires webpack)', true)
|
||||
.option('--live', 'Reload on changes if not using --hot', true)
|
||||
.option('--bundler', 'Specify a bundler (rollup or webpack)')
|
||||
.option('--stream', 'Stream logs, instead of boxing them', false)
|
||||
.action(async (opts: {
|
||||
port: number,
|
||||
open: boolean,
|
||||
'dev-port': number,
|
||||
live: boolean,
|
||||
hot: boolean,
|
||||
bundler?: string
|
||||
bundler?: string,
|
||||
stream: boolean
|
||||
}) => {
|
||||
const { dev } = await import('./cli/dev');
|
||||
dev(opts);
|
||||
|
||||
237
src/cli/dev.ts
237
src/cli/dev.ts
@@ -1,80 +1,263 @@
|
||||
import * as path from 'path';
|
||||
import colors from 'kleur';
|
||||
import * as child_process from 'child_process';
|
||||
import * as blessed from 'blessed';
|
||||
import prettyMs from 'pretty-ms';
|
||||
import { dev as _dev } from '../api/dev';
|
||||
import * as events from '../api/interfaces';
|
||||
|
||||
export function dev(opts: { port: number, open: boolean, bundler?: string }) {
|
||||
function boxed_output() {
|
||||
const screen = blessed.screen({
|
||||
smartCSR: true
|
||||
});
|
||||
|
||||
function box(opts) {
|
||||
opts = Object.assign({
|
||||
width: '100%',
|
||||
height: '50%',
|
||||
scrollable: true,
|
||||
style: {
|
||||
scrollbar: {
|
||||
bg: 'black'
|
||||
}
|
||||
},
|
||||
scrollbar: {},
|
||||
input: true,
|
||||
mouse: true,
|
||||
keys: true,
|
||||
scrollOnInput: false
|
||||
}, opts);
|
||||
|
||||
return blessed.box(opts);
|
||||
}
|
||||
|
||||
const status_box = box({});
|
||||
const log_box = box({
|
||||
bottom: '0'
|
||||
});
|
||||
|
||||
let mouse_is_down = false;
|
||||
let dragging = false;
|
||||
let did_drag = false;
|
||||
|
||||
let divider_is_horizontal = true;
|
||||
|
||||
function update_split(x: number, y: number) {
|
||||
if (divider_is_horizontal) {
|
||||
horizontal_divider.top = y;
|
||||
status_box.width = log_box.width = '100%';
|
||||
status_box.height = y;
|
||||
log_box.height = screen.height - (y + 1);
|
||||
log_box.top = y + 1;
|
||||
log_box.left = 0;
|
||||
} else {
|
||||
vertical_divider.left = x;
|
||||
status_box.height = log_box.height = '100%';
|
||||
status_box.width = x;
|
||||
log_box.width = screen.width - (x + 1);
|
||||
log_box.left = x + 1;
|
||||
log_box.top = 0;
|
||||
}
|
||||
|
||||
screen.render();
|
||||
}
|
||||
|
||||
screen.on('mousedown', data => {
|
||||
if (mouse_is_down) {
|
||||
if (dragging) {
|
||||
update_split(data.x, data.y);
|
||||
did_drag = true;
|
||||
}
|
||||
} else {
|
||||
if (data.y === horizontal_divider.top) {
|
||||
dragging = true;
|
||||
}
|
||||
|
||||
mouse_is_down = true;
|
||||
}
|
||||
});
|
||||
|
||||
screen.on('mouseup', data => {
|
||||
mouse_is_down = false;
|
||||
dragging = false;
|
||||
did_drag = false;
|
||||
});
|
||||
|
||||
const horizontal_divider = blessed.line({
|
||||
top: '50%',
|
||||
orientation: 'horizontal'
|
||||
});
|
||||
|
||||
const vertical_divider = blessed.line({
|
||||
left: '50%',
|
||||
orientation: 'vertical'
|
||||
});
|
||||
|
||||
horizontal_divider.on('click', event => {
|
||||
if (!did_drag) {
|
||||
horizontal_divider.hide();
|
||||
vertical_divider.show();
|
||||
divider_is_horizontal = false;
|
||||
update_split(event.x, event.y);
|
||||
}
|
||||
});
|
||||
|
||||
vertical_divider.on('click', event => {
|
||||
if (!did_drag) {
|
||||
vertical_divider.hide();
|
||||
horizontal_divider.show();
|
||||
divider_is_horizontal = true;
|
||||
update_split(event.x, event.y);
|
||||
}
|
||||
});
|
||||
|
||||
vertical_divider.hide();
|
||||
|
||||
screen.append(status_box);
|
||||
screen.append(log_box);
|
||||
screen.append(horizontal_divider);
|
||||
screen.append(vertical_divider);
|
||||
|
||||
update_split(process.stdout.columns >> 1, process.stdout.rows >> 1);
|
||||
|
||||
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
|
||||
return process.exit(0);
|
||||
});
|
||||
|
||||
const append_log = (data: Buffer | string) => {
|
||||
log_box.setContent(log_box.content + data);
|
||||
screen.render();
|
||||
};
|
||||
|
||||
const append_status = (data: Buffer | string) => {
|
||||
status_box.setContent(status_box.content + data);
|
||||
screen.render();
|
||||
};
|
||||
|
||||
let first = true;
|
||||
|
||||
return {
|
||||
stdout: append_log,
|
||||
|
||||
stderr: append_log,
|
||||
|
||||
clear_logs: () => {
|
||||
let content = `${colors.inverse(` server log • ${new Date().toISOString()}\n`)} \n`;
|
||||
if (first) {
|
||||
content += colors.gray(`> Click/drag the divider to adjust the split\n\n`);
|
||||
first = false;
|
||||
}
|
||||
|
||||
log_box.setContent(content);
|
||||
screen.render();
|
||||
},
|
||||
|
||||
log: (line: string) => {
|
||||
append_status(line + '\n');
|
||||
},
|
||||
|
||||
append: append_status,
|
||||
|
||||
clear: () => {
|
||||
status_box.setContent(`${colors.inverse(` build log • ${new Date().toISOString()}\n`)} \n`);
|
||||
screen.render();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function streamed_output() {
|
||||
return {
|
||||
stdout: process.stdout.write.bind(process.stdout),
|
||||
|
||||
stderr: process.stderr.write.bind(process.stderr),
|
||||
|
||||
clear_logs: () => {},
|
||||
|
||||
log: (line: string) => {
|
||||
console.log(line);
|
||||
},
|
||||
|
||||
append: (data: Buffer | string) => {
|
||||
process.stdout.write(data);
|
||||
},
|
||||
|
||||
clear: () => {}
|
||||
};
|
||||
}
|
||||
|
||||
export function dev(opts: { port: number, open: boolean, bundler?: string, stream: boolean }) {
|
||||
const output = opts.stream
|
||||
? streamed_output()
|
||||
: boxed_output();
|
||||
|
||||
output.clear();
|
||||
|
||||
try {
|
||||
const watcher = _dev(opts);
|
||||
|
||||
let first = true;
|
||||
|
||||
watcher.on('ready', (event: events.ReadyEvent) => {
|
||||
output.log(colors.bold.cyan(`> Listening on http://localhost:${event.port}`));
|
||||
|
||||
if (first) {
|
||||
console.log(colors.bold.cyan(`> Listening on http://localhost:${event.port}`));
|
||||
if (opts.open) child_process.exec(`open http://localhost:${event.port}`);
|
||||
first = false;
|
||||
}
|
||||
|
||||
// TODO clear screen?
|
||||
|
||||
event.process.stdout.on('data', data => {
|
||||
process.stdout.write(data);
|
||||
});
|
||||
|
||||
event.process.stderr.on('data', data => {
|
||||
process.stderr.write(data);
|
||||
});
|
||||
});
|
||||
|
||||
watcher.on('restart', output.clear_logs);
|
||||
watcher.on('stdout', output.stdout);
|
||||
watcher.on('stderr', output.stderr);
|
||||
|
||||
watcher.on('invalid', (event: events.InvalidEvent) => {
|
||||
const changed = event.changed.map(filename => path.relative(process.cwd(), filename)).join(', ');
|
||||
console.log(`\n${colors.bold.cyan(changed)} changed. rebuilding...`);
|
||||
|
||||
output.clear();
|
||||
output.log(`${colors.bold.cyan(changed)} changed. rebuilding...`);
|
||||
});
|
||||
|
||||
watcher.on('error', (event: events.ErrorEvent) => {
|
||||
console.log(colors.red(`✗ ${event.type}`));
|
||||
console.log(colors.red(event.message));
|
||||
output.log(colors.red(`✗ ${event.type}`));
|
||||
output.log(colors.red(event.message));
|
||||
});
|
||||
|
||||
watcher.on('fatal', (event: events.FatalEvent) => {
|
||||
console.log(colors.bold.red(`> ${event.message}`));
|
||||
if (event.log) console.log(event.log);
|
||||
output.log(colors.bold.red(`> ${event.message}`));
|
||||
if (event.log) output.log(event.log);
|
||||
});
|
||||
|
||||
watcher.on('build', (event: events.BuildEvent) => {
|
||||
if (event.errors.length) {
|
||||
console.log(colors.bold.red(`✗ ${event.type}`));
|
||||
output.log(colors.bold.red(`✗ ${event.type}`));
|
||||
|
||||
event.errors.filter(e => !e.duplicate).forEach(error => {
|
||||
if (error.file) console.log(colors.bold(error.file));
|
||||
console.log(error.message);
|
||||
if (error.file) output.log(colors.bold(error.file));
|
||||
output.log(error.message);
|
||||
});
|
||||
|
||||
const hidden = event.errors.filter(e => e.duplicate).length;
|
||||
if (hidden > 0) {
|
||||
console.log(`${hidden} duplicate ${hidden === 1 ? 'error' : 'errors'} hidden\n`);
|
||||
output.log(`${hidden} duplicate ${hidden === 1 ? 'error' : 'errors'} hidden\n`);
|
||||
}
|
||||
} else if (event.warnings.length) {
|
||||
console.log(colors.bold.yellow(`• ${event.type}`));
|
||||
output.log(colors.bold.yellow(`• ${event.type}`));
|
||||
|
||||
event.warnings.filter(e => !e.duplicate).forEach(warning => {
|
||||
if (warning.file) console.log(colors.bold(warning.file));
|
||||
console.log(warning.message);
|
||||
if (warning.file) output.log(colors.bold(warning.file));
|
||||
output.log(warning.message);
|
||||
});
|
||||
|
||||
const hidden = event.warnings.filter(e => e.duplicate).length;
|
||||
if (hidden > 0) {
|
||||
console.log(`${hidden} duplicate ${hidden === 1 ? 'warning' : 'warnings'} hidden\n`);
|
||||
output.log(`${hidden} duplicate ${hidden === 1 ? 'warning' : 'warnings'} hidden\n`);
|
||||
}
|
||||
} else {
|
||||
console.log(`${colors.bold.green(`✔ ${event.type}`)} ${colors.gray(`(${prettyMs(event.duration)})`)}`);
|
||||
output.log(`${colors.bold.green(`✔ ${event.type}`)} ${colors.gray(`(${prettyMs(event.duration)})`)}`);
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(colors.bold.red(`> ${err.message}`));
|
||||
output.log(colors.bold.red(`> ${err.message}`));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
@@ -185,7 +185,8 @@ function serve({ prefix, pathname, cache_control }: {
|
||||
const type = lookup(req.path);
|
||||
|
||||
try {
|
||||
const data = read(req.path.slice(1));
|
||||
const file = decodeURIComponent(req.path.slice(1));
|
||||
const data = read(file);
|
||||
|
||||
res.setHeader('Content-Type', type);
|
||||
res.setHeader('Cache-Control', cache_control);
|
||||
|
||||
@@ -1 +1,11 @@
|
||||
<h1>I'm afraid I just blue myself</h1>
|
||||
<h1>{phrase}</h1>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
preload() {
|
||||
return this.fetch('fünke.json').then(r => r.json()).then(phrase => {
|
||||
return { phrase };
|
||||
});
|
||||
}
|
||||
};
|
||||
</script>
|
||||
9
test/app/routes/fünke.json.js
Normal file
9
test/app/routes/fünke.json.js
Normal file
@@ -0,0 +1,9 @@
|
||||
export function get(req, res) {
|
||||
res.writeHead(200, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
res.end(JSON.stringify(
|
||||
"I'm afraid I just blue myself"
|
||||
));
|
||||
}
|
||||
@@ -746,7 +746,7 @@ function run({ mode, basepath = '' }) {
|
||||
|
||||
it('allows reserved words as route names', () => {
|
||||
return nightmare.goto(`${base}/const`).init()
|
||||
.then(() => nightmare.page.title())
|
||||
.page.title()
|
||||
.then(title => {
|
||||
assert.equal(title, 'reserved words are okay as routes');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user