Compare commits

...

16 Commits

Author SHA1 Message Date
Rich Harris
8b60d568dc -> v0.19.2 2018-09-02 21:56:45 -04:00
Rich Harris
64c2394c9d Merge branch 'master' of github.com:sveltejs/sapper 2018-09-02 21:54:13 -04:00
Rich Harris
b28037291a Merge pull request #412 from sveltejs/gh-315
allow reserved words as route names
2018-09-02 21:54:09 -04:00
Rich Harris
bf9cbe2f3b print details of webpack errors - fixes #403 2018-09-02 21:53:46 -04:00
Rich Harris
2c507b5a2e allow reserved words as route names - fixes #315 2018-09-02 21:46:25 -04:00
Rich Harris
4a92fbbbfa Merge pull request #410 from sveltejs/gh-220
ignore things that look like temp files when generating manifest data
2018-09-02 21:13:33 -04:00
Rich Harris
b16440ff0f Merge pull request #411 from sveltejs/gh-235
ignore clicks on <a> elements without hrefs
2018-09-02 21:13:18 -04:00
Rich Harris
64223b572b ignore clicks on <a> elements without hrefs - fixes #235 2018-09-02 20:56:50 -04:00
Rich Harris
1b6dfd3580 ignore things that look like temp files when generating manifest data - fixes #220 2018-09-02 20:33:00 -04:00
Rich Harris
c0b833862a -> v0.19.1 2018-09-02 18:41:32 -04:00
Rich Harris
45f4c47a3e oops that wasnt quite right 2018-09-02 18:41:17 -04:00
Rich Harris
48b87edb5b Merge branch 'master' of github.com:sveltejs/sapper 2018-09-02 18:27:20 -04:00
Rich Harris
f9f283603e Merge pull request #409 from sveltejs/fix-redirects
don't include origin in export redirects
2018-09-02 18:26:56 -04:00
Rich Harris
a56ee6bdb7 regenerate lockfile 2018-09-02 17:01:43 -04:00
Rich Harris
a18af2a473 dont include origin in export redirects 2018-09-02 17:01:29 -04:00
Rich Harris
fe5a8fb1e7 dont include .map files in package 2018-09-02 14:53:12 -04:00
14 changed files with 112 additions and 21 deletions

View File

@@ -1,5 +1,16 @@
# sapper changelog
## 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
View File

@@ -1,6 +1,6 @@
{
"name": "sapper",
"version": "0.18.7",
"version": "0.19.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@@ -1,6 +1,6 @@
{
"name": "sapper",
"version": "0.19.0",
"version": "0.19.2",
"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"

View File

@@ -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));
}

View File

@@ -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`));
}

View File

@@ -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) {

View File

@@ -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',
]);

View File

@@ -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';

View File

@@ -0,0 +1 @@
<h1>reserved words are okay as routes</h1>

View File

@@ -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>

View File

@@ -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()
.then(() => nightmare.page.title())
.then(title => {
assert.equal(title, 'reserved words are okay as routes');
});
});
});
describe('headers', () => {

View File

@@ -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$/
}]);
});
});