mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-15 12:24:47 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b60d568dc | ||
|
|
64c2394c9d | ||
|
|
b28037291a | ||
|
|
bf9cbe2f3b | ||
|
|
2c507b5a2e | ||
|
|
4a92fbbbfa | ||
|
|
b16440ff0f | ||
|
|
64223b572b | ||
|
|
1b6dfd3580 |
@@ -1,5 +1,12 @@
|
|||||||
# sapper changelog
|
# 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
|
## 0.19.1
|
||||||
|
|
||||||
* Don't include local origin in export redirects ([#409](https://github.com/sveltejs/sapper/pull/409))
|
* Don't include local origin in export redirects ([#409](https://github.com/sveltejs/sapper/pull/409))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sapper",
|
"name": "sapper",
|
||||||
"version": "0.19.1",
|
"version": "0.19.2",
|
||||||
"description": "Military-grade apps, engineered by Svelte",
|
"description": "Military-grade apps, engineered by Svelte",
|
||||||
"main": "dist/middleware.js",
|
"main": "dist/middleware.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -23,3 +23,54 @@ export function fudge_mtime(file: string) {
|
|||||||
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',
|
||||||
|
]);
|
||||||
@@ -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>
|
||||||
@@ -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()
|
||||||
|
.then(() => nightmare.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