mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-13 19:45:26 +00:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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
|
||||
|
||||
## 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
|
||||
|
||||
* Extract styles out of JS into .css files, for Rollup apps ([#388](https://github.com/sveltejs/sapper/issues/388))
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sapper",
|
||||
"version": "0.18.7",
|
||||
"version": "0.19.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "sapper",
|
||||
"version": "0.19.0",
|
||||
"version": "0.19.3",
|
||||
"description": "Military-grade apps, engineered by Svelte",
|
||||
"main": "dist/middleware.js",
|
||||
"bin": {
|
||||
@@ -13,7 +13,7 @@
|
||||
"config",
|
||||
"sapper",
|
||||
"components",
|
||||
"dist"
|
||||
"dist/*.js"
|
||||
],
|
||||
"directories": {
|
||||
"test": "test"
|
||||
|
||||
@@ -170,7 +170,7 @@ async function execute(emitter: EventEmitter, opts: Opts) {
|
||||
const location = r.headers.get('Location');
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ export class WebpackCompiler {
|
||||
const result = new WebpackResult(stats);
|
||||
|
||||
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`));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import { locations } from '../config';
|
||||
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 {
|
||||
const components: PageComponent[] = [];
|
||||
@@ -30,13 +30,16 @@ export default function create_manifest_data(cwd = locations.routes()): Manifest
|
||||
const file = path.relative(cwd, resolved);
|
||||
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
|
||||
? basename
|
||||
: basename.slice(0, -path.extname(basename).length);
|
||||
|
||||
const parts = get_parts(segment);
|
||||
const is_index = is_dir ? false : basename.startsWith('index.');
|
||||
const is_page = path.extname(basename) === '.html';
|
||||
const is_page = ext === '.html';
|
||||
|
||||
parts.forEach(part => {
|
||||
if (/\]\[/.test(part.content)) {
|
||||
@@ -57,6 +60,7 @@ export default function create_manifest_data(cwd = locations.routes()): Manifest
|
||||
is_page
|
||||
};
|
||||
})
|
||||
.filter(Boolean)
|
||||
.sort(comparator);
|
||||
|
||||
items.forEach(item => {
|
||||
@@ -265,7 +269,7 @@ function get_parts(part: string): Part[] {
|
||||
}
|
||||
|
||||
function get_slug(file: string) {
|
||||
return file
|
||||
let name = file
|
||||
.replace(/[\\\/]index/, '')
|
||||
.replace(/_default([\/\\index])?\.html$/, 'index')
|
||||
.replace(/[\/\\]/g, '_')
|
||||
@@ -274,6 +278,9 @@ function get_slug(file: string) {
|
||||
.replace(/[^a-zA-Z0-9_$]/g, c => {
|
||||
return c === '.' ? '_' : `$${c.charCodeAt(0)}`
|
||||
});
|
||||
|
||||
if (reserved_words.has(name)) name += '_';
|
||||
return name;
|
||||
}
|
||||
|
||||
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(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);
|
||||
|
||||
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);
|
||||
|
||||
@@ -336,6 +336,8 @@ function handle_click(event: MouseEvent) {
|
||||
const a: HTMLAnchorElement | SVGAElement = <HTMLAnchorElement | SVGAElement>findAnchor(<Node>event.target);
|
||||
if (!a) return;
|
||||
|
||||
if (!a.href) return;
|
||||
|
||||
// check if link is inside an svg
|
||||
// in this case, both href and target are always inside an object
|
||||
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='credentials?creds=include'>credentials</a>
|
||||
<a rel=prefetch class='{page === "blog" ? "selected" : ""}' href='blog'>blog</a>
|
||||
<a href="const">const</a>
|
||||
|
||||
<div class='hydrate-test'></div>
|
||||
|
||||
|
||||
@@ -743,6 +743,14 @@ function run({ mode, basepath = '' }) {
|
||||
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', () => {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import * as path from 'path';
|
||||
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', () => {
|
||||
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 about = { name: 'about', file: 'about.html' };
|
||||
@@ -68,7 +68,7 @@ describe('manifest_data', () => {
|
||||
});
|
||||
|
||||
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
|
||||
|
||||
@@ -90,7 +90,7 @@ describe('manifest_data', () => {
|
||||
});
|
||||
|
||||
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), [
|
||||
/^\/([0-9-a-z]{3,})\/?$/,
|
||||
@@ -100,7 +100,7 @@ describe('manifest_data', () => {
|
||||
});
|
||||
|
||||
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)), [
|
||||
['index.html'],
|
||||
@@ -116,7 +116,7 @@ describe('manifest_data', () => {
|
||||
});
|
||||
|
||||
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), [
|
||||
'index.js',
|
||||
@@ -125,7 +125,7 @@ describe('manifest_data', () => {
|
||||
});
|
||||
|
||||
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), [
|
||||
'.well-known/dnt-policy.txt.js'
|
||||
@@ -134,24 +134,35 @@ describe('manifest_data', () => {
|
||||
|
||||
it('fails on clashes', () => {
|
||||
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/);
|
||||
|
||||
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);
|
||||
}, /The \[bar\]\/index\.js and \[foo\]\.js routes clash/);
|
||||
});
|
||||
|
||||
it('fails if dynamic params are not separated', () => {
|
||||
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/);
|
||||
});
|
||||
|
||||
it('errors when trying to use reserved characters in route regexp', () => {
|
||||
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/);
|
||||
});
|
||||
|
||||
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