mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 19:45:26 +00:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6765e534e4 | ||
|
|
160a2e2ede | ||
|
|
3ecc21c0d9 | ||
|
|
3ffb396d87 | ||
|
|
59fccc9e9a | ||
|
|
da9a37e125 | ||
|
|
499b377bfd | ||
|
|
1baeb79d4b | ||
|
|
0cc5ff95d6 | ||
|
|
e90525c1e8 | ||
|
|
6ccae0cd33 | ||
|
|
8b60d568dc | ||
|
|
64c2394c9d | ||
|
|
b28037291a | ||
|
|
bf9cbe2f3b | ||
|
|
2c507b5a2e | ||
|
|
4a92fbbbfa | ||
|
|
b16440ff0f | ||
|
|
64223b572b | ||
|
|
1b6dfd3580 | ||
|
|
c0b833862a | ||
|
|
45f4c47a3e | ||
|
|
48b87edb5b | ||
|
|
f9f283603e | ||
|
|
a56ee6bdb7 | ||
|
|
a18af2a473 | ||
|
|
fe5a8fb1e7 |
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,5 +1,20 @@
|
|||||||
# sapper changelog
|
# 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))
|
||||||
|
* Ignore clicks an `<a>` element without `href` ([#235](https://github.com/sveltejs/sapper/issues/235))
|
||||||
|
* Allow routes that are reserved JavaScript words ([#315](https://github.com/sveltejs/sapper/issues/315))
|
||||||
|
* Print out webpack errors ([#403](https://github.com/sveltejs/sapper/issues/403))
|
||||||
|
|
||||||
|
## 0.19.1
|
||||||
|
|
||||||
|
* Don't include local origin in export redirects ([#409](https://github.com/sveltejs/sapper/pull/409))
|
||||||
|
|
||||||
## 0.19.0
|
## 0.19.0
|
||||||
|
|
||||||
* Extract styles out of JS into .css files, for Rollup apps ([#388](https://github.com/sveltejs/sapper/issues/388))
|
* Extract styles out of JS into .css files, for Rollup apps ([#388](https://github.com/sveltejs/sapper/issues/388))
|
||||||
|
|||||||
22
package-lock.json
generated
22
package-lock.json
generated
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sapper",
|
"name": "sapper",
|
||||||
"version": "0.18.7",
|
"version": "0.19.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -10,6 +10,15 @@
|
|||||||
"integrity": "sha1-MU+BaPUK5IoDLP2tX9tDb0ZKl6w=",
|
"integrity": "sha1-MU+BaPUK5IoDLP2tX9tDb0ZKl6w=",
|
||||||
"dev": true
|
"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": {
|
"@types/estree": {
|
||||||
"version": "0.0.39",
|
"version": "0.0.39",
|
||||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz",
|
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz",
|
||||||
@@ -19,8 +28,7 @@
|
|||||||
"@types/events": {
|
"@types/events": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
|
||||||
"integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA==",
|
"integrity": "sha512-KEIlhXnIutzKwRbQkGWb/I4HFqBuUykAdHgDED6xqwXJfONCjF5VoE0cXEiurh3XauygxzeDzgtXUqvLkxFzzA=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"@types/glob": {
|
"@types/glob": {
|
||||||
"version": "5.0.35",
|
"version": "5.0.35",
|
||||||
@@ -57,8 +65,7 @@
|
|||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "10.9.4",
|
"version": "10.9.4",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.9.4.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.9.4.tgz",
|
||||||
"integrity": "sha512-fCHV45gS+m3hH17zgkgADUSi2RR1Vht6wOZ0jyHP8rjiQra9f+mIcgwPQHllmDocYOstIEbKlxbFDYlgrTPYqw==",
|
"integrity": "sha512-fCHV45gS+m3hH17zgkgADUSi2RR1Vht6wOZ0jyHP8rjiQra9f+mIcgwPQHllmDocYOstIEbKlxbFDYlgrTPYqw=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"@types/rimraf": {
|
"@types/rimraf": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
@@ -1010,6 +1017,11 @@
|
|||||||
"integrity": "sha1-RqoXUftqL5PuXmibsQh9SxTGwgU=",
|
"integrity": "sha1-RqoXUftqL5PuXmibsQh9SxTGwgU=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"blessed": {
|
||||||
|
"version": "0.1.81",
|
||||||
|
"resolved": "https://registry.npmjs.org/blessed/-/blessed-0.1.81.tgz",
|
||||||
|
"integrity": "sha1-+WLWh+wsNpVwrnGvhDJW5tDKESk="
|
||||||
|
},
|
||||||
"bluebird": {
|
"bluebird": {
|
||||||
"version": "3.5.1",
|
"version": "3.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sapper",
|
"name": "sapper",
|
||||||
"version": "0.19.0",
|
"version": "0.19.3",
|
||||||
"description": "Military-grade apps, engineered by Svelte",
|
"description": "Military-grade apps, engineered by Svelte",
|
||||||
"main": "dist/middleware.js",
|
"main": "dist/middleware.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
@@ -13,12 +13,14 @@
|
|||||||
"config",
|
"config",
|
||||||
"sapper",
|
"sapper",
|
||||||
"components",
|
"components",
|
||||||
"dist"
|
"dist/*.js"
|
||||||
],
|
],
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/blessed": "^0.1.10",
|
||||||
|
"blessed": "^0.1.81",
|
||||||
"html-minifier": "^3.5.16",
|
"html-minifier": "^3.5.16",
|
||||||
"shimport": "^0.0.10",
|
"shimport": "^0.0.10",
|
||||||
"source-map-support": "^0.5.6",
|
"source-map-support": "^0.5.6",
|
||||||
|
|||||||
@@ -200,6 +200,8 @@ class Watcher extends EventEmitter {
|
|||||||
handle_result: (result: CompileResult) => {
|
handle_result: (result: CompileResult) => {
|
||||||
deferred.promise.then(() => {
|
deferred.promise.then(() => {
|
||||||
const restart = () => {
|
const restart = () => {
|
||||||
|
this.emit('restart');
|
||||||
|
|
||||||
log = '';
|
log = '';
|
||||||
this.crashed = false;
|
this.crashed = false;
|
||||||
|
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ async function execute(emitter: EventEmitter, opts: Opts) {
|
|||||||
const location = r.headers.get('Location');
|
const location = r.headers.get('Location');
|
||||||
|
|
||||||
type = 'text/html';
|
type = 'text/html';
|
||||||
body = `<script>window.location.href = "${location}"</script>`;
|
body = `<script>window.location.href = "${location.replace(origin, '')}"</script>`;
|
||||||
|
|
||||||
await handle(resolve(root.href, location));
|
await handle(resolve(root.href, location));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,13 +15,15 @@ prog.command('dev')
|
|||||||
.option('--hot', 'Use hot module replacement (requires webpack)', true)
|
.option('--hot', 'Use hot module replacement (requires webpack)', true)
|
||||||
.option('--live', 'Reload on changes if not using --hot', true)
|
.option('--live', 'Reload on changes if not using --hot', true)
|
||||||
.option('--bundler', 'Specify a bundler (rollup or webpack)')
|
.option('--bundler', 'Specify a bundler (rollup or webpack)')
|
||||||
|
.option('--stream', 'Stream logs, instead of boxing them', false)
|
||||||
.action(async (opts: {
|
.action(async (opts: {
|
||||||
port: number,
|
port: number,
|
||||||
open: boolean,
|
open: boolean,
|
||||||
'dev-port': number,
|
'dev-port': number,
|
||||||
live: boolean,
|
live: boolean,
|
||||||
hot: boolean,
|
hot: boolean,
|
||||||
bundler?: string
|
bundler?: string,
|
||||||
|
stream: boolean
|
||||||
}) => {
|
}) => {
|
||||||
const { dev } = await import('./cli/dev');
|
const { dev } = await import('./cli/dev');
|
||||||
dev(opts);
|
dev(opts);
|
||||||
|
|||||||
237
src/cli/dev.ts
237
src/cli/dev.ts
@@ -1,80 +1,263 @@
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import colors from 'kleur';
|
import colors from 'kleur';
|
||||||
import * as child_process from 'child_process';
|
import * as child_process from 'child_process';
|
||||||
|
import * as blessed from 'blessed';
|
||||||
import prettyMs from 'pretty-ms';
|
import prettyMs from 'pretty-ms';
|
||||||
import { dev as _dev } from '../api/dev';
|
import { dev as _dev } from '../api/dev';
|
||||||
import * as events from '../api/interfaces';
|
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 {
|
try {
|
||||||
const watcher = _dev(opts);
|
const watcher = _dev(opts);
|
||||||
|
|
||||||
let first = true;
|
let first = true;
|
||||||
|
|
||||||
watcher.on('ready', (event: events.ReadyEvent) => {
|
watcher.on('ready', (event: events.ReadyEvent) => {
|
||||||
|
output.log(colors.bold.cyan(`> Listening on http://localhost:${event.port}`));
|
||||||
|
|
||||||
if (first) {
|
if (first) {
|
||||||
console.log(colors.bold.cyan(`> Listening on http://localhost:${event.port}`));
|
|
||||||
if (opts.open) child_process.exec(`open http://localhost:${event.port}`);
|
if (opts.open) child_process.exec(`open http://localhost:${event.port}`);
|
||||||
first = false;
|
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) => {
|
watcher.on('invalid', (event: events.InvalidEvent) => {
|
||||||
const changed = event.changed.map(filename => path.relative(process.cwd(), filename)).join(', ');
|
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) => {
|
watcher.on('error', (event: events.ErrorEvent) => {
|
||||||
console.log(colors.red(`✗ ${event.type}`));
|
output.log(colors.red(`✗ ${event.type}`));
|
||||||
console.log(colors.red(event.message));
|
output.log(colors.red(event.message));
|
||||||
});
|
});
|
||||||
|
|
||||||
watcher.on('fatal', (event: events.FatalEvent) => {
|
watcher.on('fatal', (event: events.FatalEvent) => {
|
||||||
console.log(colors.bold.red(`> ${event.message}`));
|
output.log(colors.bold.red(`> ${event.message}`));
|
||||||
if (event.log) console.log(event.log);
|
if (event.log) output.log(event.log);
|
||||||
});
|
});
|
||||||
|
|
||||||
watcher.on('build', (event: events.BuildEvent) => {
|
watcher.on('build', (event: events.BuildEvent) => {
|
||||||
if (event.errors.length) {
|
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 => {
|
event.errors.filter(e => !e.duplicate).forEach(error => {
|
||||||
if (error.file) console.log(colors.bold(error.file));
|
if (error.file) output.log(colors.bold(error.file));
|
||||||
console.log(error.message);
|
output.log(error.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
const hidden = event.errors.filter(e => e.duplicate).length;
|
const hidden = event.errors.filter(e => e.duplicate).length;
|
||||||
if (hidden > 0) {
|
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) {
|
} 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 => {
|
event.warnings.filter(e => !e.duplicate).forEach(warning => {
|
||||||
if (warning.file) console.log(colors.bold(warning.file));
|
if (warning.file) output.log(colors.bold(warning.file));
|
||||||
console.log(warning.message);
|
output.log(warning.message);
|
||||||
});
|
});
|
||||||
|
|
||||||
const hidden = event.warnings.filter(e => e.duplicate).length;
|
const hidden = event.warnings.filter(e => e.duplicate).length;
|
||||||
if (hidden > 0) {
|
if (hidden > 0) {
|
||||||
console.log(`${hidden} duplicate ${hidden === 1 ? 'warning' : 'warnings'} hidden\n`);
|
output.log(`${hidden} duplicate ${hidden === 1 ? 'warning' : 'warnings'} hidden\n`);
|
||||||
}
|
}
|
||||||
} else {
|
} 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) {
|
} catch (err) {
|
||||||
console.log(colors.bold.red(`> ${err.message}`));
|
output.log(colors.bold.red(`> ${err.message}`));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -28,8 +28,7 @@ export class WebpackCompiler {
|
|||||||
const result = new WebpackResult(stats);
|
const result = new WebpackResult(stats);
|
||||||
|
|
||||||
if (result.errors.length) {
|
if (result.errors.length) {
|
||||||
// TODO print errors
|
console.error(stats.toString({ colors: true }));
|
||||||
// console.error(stats.toString({ colors: true }));
|
|
||||||
reject(new Error(`Encountered errors while building app`));
|
reject(new Error(`Encountered errors while building app`));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import * as fs from 'fs';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { locations } from '../config';
|
import { locations } from '../config';
|
||||||
import { Page, PageComponent, ServerRoute, ManifestData } from '../interfaces';
|
import { Page, PageComponent, ServerRoute, ManifestData } from '../interfaces';
|
||||||
import { posixify } from './utils';
|
import { posixify, reserved_words } from './utils';
|
||||||
|
|
||||||
export default function create_manifest_data(cwd = locations.routes()): ManifestData {
|
export default function create_manifest_data(cwd = locations.routes()): ManifestData {
|
||||||
const components: PageComponent[] = [];
|
const components: PageComponent[] = [];
|
||||||
@@ -30,13 +30,16 @@ export default function create_manifest_data(cwd = locations.routes()): Manifest
|
|||||||
const file = path.relative(cwd, resolved);
|
const file = path.relative(cwd, resolved);
|
||||||
const is_dir = fs.statSync(resolved).isDirectory();
|
const is_dir = fs.statSync(resolved).isDirectory();
|
||||||
|
|
||||||
|
const ext = path.extname(basename);
|
||||||
|
if (!is_dir && !/^\.[a-z]+$/i.test(ext)) return null; // filter out tmp files etc
|
||||||
|
|
||||||
const segment = is_dir
|
const segment = is_dir
|
||||||
? basename
|
? basename
|
||||||
: basename.slice(0, -path.extname(basename).length);
|
: basename.slice(0, -path.extname(basename).length);
|
||||||
|
|
||||||
const parts = get_parts(segment);
|
const parts = get_parts(segment);
|
||||||
const is_index = is_dir ? false : basename.startsWith('index.');
|
const is_index = is_dir ? false : basename.startsWith('index.');
|
||||||
const is_page = path.extname(basename) === '.html';
|
const is_page = ext === '.html';
|
||||||
|
|
||||||
parts.forEach(part => {
|
parts.forEach(part => {
|
||||||
if (/\]\[/.test(part.content)) {
|
if (/\]\[/.test(part.content)) {
|
||||||
@@ -57,6 +60,7 @@ export default function create_manifest_data(cwd = locations.routes()): Manifest
|
|||||||
is_page
|
is_page
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
.filter(Boolean)
|
||||||
.sort(comparator);
|
.sort(comparator);
|
||||||
|
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
@@ -265,7 +269,7 @@ function get_parts(part: string): Part[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_slug(file: string) {
|
function get_slug(file: string) {
|
||||||
return file
|
let name = file
|
||||||
.replace(/[\\\/]index/, '')
|
.replace(/[\\\/]index/, '')
|
||||||
.replace(/_default([\/\\index])?\.html$/, 'index')
|
.replace(/_default([\/\\index])?\.html$/, 'index')
|
||||||
.replace(/[\/\\]/g, '_')
|
.replace(/[\/\\]/g, '_')
|
||||||
@@ -274,6 +278,9 @@ function get_slug(file: string) {
|
|||||||
.replace(/[^a-zA-Z0-9_$]/g, c => {
|
.replace(/[^a-zA-Z0-9_$]/g, c => {
|
||||||
return c === '.' ? '_' : `$${c.charCodeAt(0)}`
|
return c === '.' ? '_' : `$${c.charCodeAt(0)}`
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (reserved_words.has(name)) name += '_';
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_pattern(segments: Part[][], add_trailing_slash: boolean) {
|
function get_pattern(segments: Part[][], add_trailing_slash: boolean) {
|
||||||
|
|||||||
@@ -22,4 +22,55 @@ export function fudge_mtime(file: string) {
|
|||||||
new Date(atime.getTime() - 999999),
|
new Date(atime.getTime() - 999999),
|
||||||
new Date(mtime.getTime() - 999999)
|
new Date(mtime.getTime() - 999999)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const reserved_words = new Set([
|
||||||
|
'arguments',
|
||||||
|
'await',
|
||||||
|
'break',
|
||||||
|
'case',
|
||||||
|
'catch',
|
||||||
|
'class',
|
||||||
|
'const',
|
||||||
|
'continue',
|
||||||
|
'debugger',
|
||||||
|
'default',
|
||||||
|
'delete',
|
||||||
|
'do',
|
||||||
|
'else',
|
||||||
|
'enum',
|
||||||
|
'eval',
|
||||||
|
'export',
|
||||||
|
'extends',
|
||||||
|
'false',
|
||||||
|
'finally',
|
||||||
|
'for',
|
||||||
|
'function',
|
||||||
|
'if',
|
||||||
|
'implements',
|
||||||
|
'import',
|
||||||
|
'in',
|
||||||
|
'instanceof',
|
||||||
|
'interface',
|
||||||
|
'let',
|
||||||
|
'new',
|
||||||
|
'null',
|
||||||
|
'package',
|
||||||
|
'private',
|
||||||
|
'protected',
|
||||||
|
'public',
|
||||||
|
'return',
|
||||||
|
'static',
|
||||||
|
'super',
|
||||||
|
'switch',
|
||||||
|
'this',
|
||||||
|
'throw',
|
||||||
|
'true',
|
||||||
|
'try',
|
||||||
|
'typeof',
|
||||||
|
'var',
|
||||||
|
'void',
|
||||||
|
'while',
|
||||||
|
'with',
|
||||||
|
'yield',
|
||||||
|
]);
|
||||||
@@ -185,7 +185,8 @@ function serve({ prefix, pathname, cache_control }: {
|
|||||||
const type = lookup(req.path);
|
const type = lookup(req.path);
|
||||||
|
|
||||||
try {
|
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('Content-Type', type);
|
||||||
res.setHeader('Cache-Control', cache_control);
|
res.setHeader('Cache-Control', cache_control);
|
||||||
|
|||||||
@@ -336,6 +336,8 @@ function handle_click(event: MouseEvent) {
|
|||||||
const a: HTMLAnchorElement | SVGAElement = <HTMLAnchorElement | SVGAElement>findAnchor(<Node>event.target);
|
const a: HTMLAnchorElement | SVGAElement = <HTMLAnchorElement | SVGAElement>findAnchor(<Node>event.target);
|
||||||
if (!a) return;
|
if (!a) return;
|
||||||
|
|
||||||
|
if (!a.href) return;
|
||||||
|
|
||||||
// check if link is inside an svg
|
// check if link is inside an svg
|
||||||
// in this case, both href and target are always inside an object
|
// in this case, both href and target are always inside an object
|
||||||
const svg = typeof a.href === 'object' && a.href.constructor.name === 'SVGAnimatedString';
|
const svg = typeof a.href === 'object' && a.href.constructor.name === 'SVGAnimatedString';
|
||||||
|
|||||||
1
test/app/routes/const.html
Normal file
1
test/app/routes/const.html
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<h1>reserved words are okay as routes</h1>
|
||||||
@@ -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"
|
||||||
|
));
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
<a href='blog/throw-an-error'>error link</a>
|
<a href='blog/throw-an-error'>error link</a>
|
||||||
<a href='credentials?creds=include'>credentials</a>
|
<a href='credentials?creds=include'>credentials</a>
|
||||||
<a rel=prefetch class='{page === "blog" ? "selected" : ""}' href='blog'>blog</a>
|
<a rel=prefetch class='{page === "blog" ? "selected" : ""}' href='blog'>blog</a>
|
||||||
|
<a href="const">const</a>
|
||||||
|
|
||||||
<div class='hydrate-test'></div>
|
<div class='hydrate-test'></div>
|
||||||
|
|
||||||
|
|||||||
@@ -743,6 +743,14 @@ function run({ mode, basepath = '' }) {
|
|||||||
assert.equal(title, 'root preload function ran: true');
|
assert.equal(title, 'root preload function ran: true');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('allows reserved words as route names', () => {
|
||||||
|
return nightmare.goto(`${base}/const`).init()
|
||||||
|
.page.title()
|
||||||
|
.then(title => {
|
||||||
|
assert.equal(title, 'reserved words are okay as routes');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('headers', () => {
|
describe('headers', () => {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as assert from 'assert';
|
import * as assert from 'assert';
|
||||||
import manifest_data from '../../../src/core/create_manifest_data';
|
import create_manifest_data from '../../../src/core/create_manifest_data';
|
||||||
|
|
||||||
describe('manifest_data', () => {
|
describe('manifest_data', () => {
|
||||||
it('creates routes', () => {
|
it('creates routes', () => {
|
||||||
const { components, pages, server_routes } = manifest_data(path.join(__dirname, 'samples/basic'));
|
const { components, pages, server_routes } = create_manifest_data(path.join(__dirname, 'samples/basic'));
|
||||||
|
|
||||||
const index = { name: 'index', file: 'index.html' };
|
const index = { name: 'index', file: 'index.html' };
|
||||||
const about = { name: 'about', file: 'about.html' };
|
const about = { name: 'about', file: 'about.html' };
|
||||||
@@ -68,7 +68,7 @@ describe('manifest_data', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('encodes invalid characters', () => {
|
it('encodes invalid characters', () => {
|
||||||
const { components, pages } = manifest_data(path.join(__dirname, 'samples/encoding'));
|
const { components, pages } = create_manifest_data(path.join(__dirname, 'samples/encoding'));
|
||||||
|
|
||||||
// had to remove ? and " because windows
|
// had to remove ? and " because windows
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@ describe('manifest_data', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('allows regex qualifiers', () => {
|
it('allows regex qualifiers', () => {
|
||||||
const { pages } = manifest_data(path.join(__dirname, 'samples/qualifiers'));
|
const { pages } = create_manifest_data(path.join(__dirname, 'samples/qualifiers'));
|
||||||
|
|
||||||
assert.deepEqual(pages.map(p => p.pattern), [
|
assert.deepEqual(pages.map(p => p.pattern), [
|
||||||
/^\/([0-9-a-z]{3,})\/?$/,
|
/^\/([0-9-a-z]{3,})\/?$/,
|
||||||
@@ -100,7 +100,7 @@ describe('manifest_data', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('sorts routes correctly', () => {
|
it('sorts routes correctly', () => {
|
||||||
const { pages } = manifest_data(path.join(__dirname, 'samples/sorting'));
|
const { pages } = create_manifest_data(path.join(__dirname, 'samples/sorting'));
|
||||||
|
|
||||||
assert.deepEqual(pages.map(p => p.parts.map(part => part && part.component.file)), [
|
assert.deepEqual(pages.map(p => p.parts.map(part => part && part.component.file)), [
|
||||||
['index.html'],
|
['index.html'],
|
||||||
@@ -116,7 +116,7 @@ describe('manifest_data', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ignores files and directories with leading underscores', () => {
|
it('ignores files and directories with leading underscores', () => {
|
||||||
const { server_routes } = manifest_data(path.join(__dirname, 'samples/hidden-underscore'));
|
const { server_routes } = create_manifest_data(path.join(__dirname, 'samples/hidden-underscore'));
|
||||||
|
|
||||||
assert.deepEqual(server_routes.map(r => r.file), [
|
assert.deepEqual(server_routes.map(r => r.file), [
|
||||||
'index.js',
|
'index.js',
|
||||||
@@ -125,7 +125,7 @@ describe('manifest_data', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ignores files and directories with leading dots except .well-known', () => {
|
it('ignores files and directories with leading dots except .well-known', () => {
|
||||||
const { server_routes } = manifest_data(path.join(__dirname, 'samples/hidden-dot'));
|
const { server_routes } = create_manifest_data(path.join(__dirname, 'samples/hidden-dot'));
|
||||||
|
|
||||||
assert.deepEqual(server_routes.map(r => r.file), [
|
assert.deepEqual(server_routes.map(r => r.file), [
|
||||||
'.well-known/dnt-policy.txt.js'
|
'.well-known/dnt-policy.txt.js'
|
||||||
@@ -134,24 +134,35 @@ describe('manifest_data', () => {
|
|||||||
|
|
||||||
it('fails on clashes', () => {
|
it('fails on clashes', () => {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
const { pages } = manifest_data(path.join(__dirname, 'samples/clash-pages'));
|
const { pages } = create_manifest_data(path.join(__dirname, 'samples/clash-pages'));
|
||||||
}, /The \[bar\]\/index\.html and \[foo\]\.html pages clash/);
|
}, /The \[bar\]\/index\.html and \[foo\]\.html pages clash/);
|
||||||
|
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
const { server_routes } = manifest_data(path.join(__dirname, 'samples/clash-routes'));
|
const { server_routes } = create_manifest_data(path.join(__dirname, 'samples/clash-routes'));
|
||||||
console.log(server_routes);
|
console.log(server_routes);
|
||||||
}, /The \[bar\]\/index\.js and \[foo\]\.js routes clash/);
|
}, /The \[bar\]\/index\.js and \[foo\]\.js routes clash/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails if dynamic params are not separated', () => {
|
it('fails if dynamic params are not separated', () => {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
manifest_data(path.join(__dirname, 'samples/invalid-params'));
|
create_manifest_data(path.join(__dirname, 'samples/invalid-params'));
|
||||||
}, /Invalid route \[foo\]\[bar\]\.js — parameters must be separated/);
|
}, /Invalid route \[foo\]\[bar\]\.js — parameters must be separated/);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('errors when trying to use reserved characters in route regexp', () => {
|
it('errors when trying to use reserved characters in route regexp', () => {
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
manifest_data(path.join(__dirname, 'samples/invalid-qualifier'));
|
create_manifest_data(path.join(__dirname, 'samples/invalid-qualifier'));
|
||||||
}, /Invalid route \[foo\(\[a-z\]\(\[0-9\]\)\)\].js — cannot use \(, \), \? or \: in route qualifiers/);
|
}, /Invalid route \[foo\(\[a-z\]\(\[0-9\]\)\)\].js — cannot use \(, \), \? or \: in route qualifiers/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('ignores things that look like lockfiles' , () => {
|
||||||
|
const { server_routes } = create_manifest_data(path.join(__dirname, 'samples/lockfiles'));
|
||||||
|
|
||||||
|
assert.deepEqual(server_routes, [{
|
||||||
|
file: 'foo.js',
|
||||||
|
name: 'route_foo',
|
||||||
|
params: [],
|
||||||
|
pattern: /^\/foo$/
|
||||||
|
}]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user