Merge branch 'master' into collision

This commit is contained in:
Rich Harris
2018-05-03 21:44:28 -04:00
committed by GitHub
6 changed files with 37 additions and 8 deletions

View File

@@ -1,5 +1,15 @@
# sapper changelog # sapper changelog
## 0.10.7
* Allow routes to have a leading `.` ([#243](https://github.com/sveltejs/sapper/pull/243))
* Only encode necessary characters in routes ([#234](https://github.com/sveltejs/sapper/pull/234))
* Preserve existing `process.env` when exporting ([#245](https://github.com/sveltejs/sapper/pull/245))
## 0.10.6
* Fix error reporting in `sapper start`
## 0.10.5 ## 0.10.5
* Fix missing service worker ([#231](https://github.com/sveltejs/sapper/pull/231)) * Fix missing service worker ([#231](https://github.com/sveltejs/sapper/pull/231))

View File

@@ -1,6 +1,6 @@
{ {
"name": "sapper", "name": "sapper",
"version": "0.10.5", "version": "0.10.7",
"description": "Military-grade apps, engineered by Svelte", "description": "Military-grade apps, engineered by Svelte",
"main": "dist/middleware.ts.js", "main": "dist/middleware.ts.js",
"bin": { "bin": {

View File

@@ -35,12 +35,12 @@ export async function exporter(export_dir: string, { basepath = '' }) {
const proc = child_process.fork(path.resolve(`${build_dir}/server.js`), [], { const proc = child_process.fork(path.resolve(`${build_dir}/server.js`), [], {
cwd: process.cwd(), cwd: process.cwd(),
env: { env: Object.assign({
PORT: port, PORT: port,
NODE_ENV: 'production', NODE_ENV: 'production',
SAPPER_DEST: build_dir, SAPPER_DEST: build_dir,
SAPPER_EXPORT: 'true' SAPPER_EXPORT: 'true'
} }, process.env)
}); });
const seen = new Set(); const seen = new Set();
@@ -103,4 +103,4 @@ export async function exporter(export_dir: string, { basepath = '' }) {
return ports.wait(port) return ports.wait(port)
.then(() => handle(new URL(`/${basepath}`, origin))) // TODO all static routes .then(() => handle(new URL(`/${basepath}`, origin))) // TODO all static routes
.then(() => proc.kill()); .then(() => proc.kill());
} }

View File

@@ -11,13 +11,13 @@ export async function start(dir: string, opts: { port: number, open: boolean })
const server = path.resolve(dir, 'server.js'); const server = path.resolve(dir, 'server.js');
if (!fs.existsSync(server)) { if (!fs.existsSync(server)) {
console.log(clorox.bold.red(`> ${dir}/server.js does not exist — type ${clorox.bold.cyan(dir === 'build' ? `npx sapper build` : `npx sapper build ${dir}`)} to create it`)); console.log(`${clorox.bold.red(`> ${dir}/server.js does not exist — type ${clorox.bold.cyan(dir === 'build' ? `npx sapper build` : `npx sapper build ${dir}`)} to create it`)}`);
return; return;
} }
if (port) { if (port) {
if (!await ports.check(port)) { if (!await ports.check(port)) {
console.log(clorox.bold.red(`> Port ${port} is unavailable`)); console.log(`${clorox.bold.red(`> Port ${port} is unavailable`)}`);
return; return;
} }
} else { } else {

View File

@@ -3,7 +3,7 @@ import glob from 'glob';
import { locations } from '../config'; import { locations } from '../config';
import { Route } from '../interfaces'; import { Route } from '../interfaces';
export default function create_routes({ files } = { files: glob.sync('**/*.*', { cwd: locations.routes(), nodir: true }) }) { export default function create_routes({ files } = { files: glob.sync('**/*.*', { cwd: locations.routes(), dot: true, nodir: true }) }) {
const routes: Route[] = files const routes: Route[] = files
.filter((file: string) => !/(^|\/|\\)_/.test(file)) .filter((file: string) => !/(^|\/|\\)_/.test(file))
.map((file: string) => { .map((file: string) => {
@@ -85,7 +85,7 @@ export default function create_routes({ files } = { files: glob.sync('**/*.*', {
let i = parts.length; let i = parts.length;
let nested = true; let nested = true;
while (i--) { while (i--) {
const part = encodeURIComponent(parts[i].normalize()).replace(/%5B/g, '[').replace(/%5D/g, ']'); const part = encodeURI(parts[i].normalize()).replace(/\?/g, '%3F').replace(/#/g, '%23').replace(/%5B/g, '[').replace(/%5D/g, ']');
const dynamic = ~part.indexOf('['); const dynamic = ~part.indexOf('[');
if (dynamic) { if (dynamic) {

View File

@@ -20,6 +20,25 @@ describe('create_routes', () => {
file: 'foo.html' file: 'foo.html'
} }
] ]
]
)
});
it('encodes caharcters not allowed in path', () => {
const routes = create_routes({
files: [
'"',
'#',
'?'
]
});
assert.deepEqual(
routes.map(r => r.pattern),
[
/^\/%22\/?$/,
/^\/%23\/?$/,
/^\/%3F\/?$/
] ]
); );
}); });