mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-15 12:24:47 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3531cc587d | ||
|
|
562a91fa57 | ||
|
|
93128a0156 | ||
|
|
d7a2132966 | ||
|
|
56ac1aea9d | ||
|
|
37a9fb62e2 | ||
|
|
a70e88b1f4 | ||
|
|
6f9ce9ce85 | ||
|
|
b13cc6f39a | ||
|
|
2758382c68 | ||
|
|
dd7f1ff99c | ||
|
|
45142cd037 |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -1,5 +1,19 @@
|
|||||||
# 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
|
||||||
|
|
||||||
|
* Fix missing service worker ([#231](https://github.com/sveltejs/sapper/pull/231))
|
||||||
|
|
||||||
## 0.10.4
|
## 0.10.4
|
||||||
|
|
||||||
* Upgrade chokidar, this time with a fix ([#227](https://github.com/sveltejs/sapper/pull/227))
|
* Upgrade chokidar, this time with a fix ([#227](https://github.com/sveltejs/sapper/pull/227))
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sapper",
|
"name": "sapper",
|
||||||
"version": "0.10.4",
|
"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": {
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -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
|
||||||
.map((file: string) => {
|
.map((file: string) => {
|
||||||
if (/(^|\/|\\)_/.test(file)) return;
|
if (/(^|\/|\\)_/.test(file)) return;
|
||||||
@@ -33,7 +33,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) {
|
||||||
|
|||||||
@@ -245,11 +245,11 @@ function get_route_handler(chunks: Record<string, string>, routes: RouteObject[]
|
|||||||
`baseUrl: "${req.baseUrl}"`,
|
`baseUrl: "${req.baseUrl}"`,
|
||||||
serialized.preloaded && `preloaded: ${serialized.preloaded}`,
|
serialized.preloaded && `preloaded: ${serialized.preloaded}`,
|
||||||
serialized.store && `store: ${serialized.store}`
|
serialized.store && `store: ${serialized.store}`
|
||||||
].filter(Boolean).join(',')}}`
|
].filter(Boolean).join(',')}};`;
|
||||||
|
|
||||||
const has_service_worker = fs.existsSync(path.join(locations.dest(), 'service-worker.js'));
|
const has_service_worker = fs.existsSync(path.join(locations.dest(), 'service-worker.js'));
|
||||||
if (has_service_worker) {
|
if (has_service_worker) {
|
||||||
`if ('serviceWorker' in navigator) navigator.serviceWorker.register('${req.baseUrl}/service-worker.js')`
|
inline_script += `if ('serviceWorker' in navigator) navigator.serviceWorker.register('${req.baseUrl}/service-worker.js');`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const page = template()
|
const page = template()
|
||||||
|
|||||||
@@ -559,6 +559,12 @@ function run({ mode, basepath = '' }) {
|
|||||||
assert.equal(title, 'woohoo!');
|
assert.equal(title, 'woohoo!');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('includes service worker', () => {
|
||||||
|
return nightmare.goto(base).page.html().then(html => {
|
||||||
|
assert.ok(html.indexOf('service-worker.js') !== -1);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('headers', () => {
|
describe('headers', () => {
|
||||||
|
|||||||
@@ -2,6 +2,25 @@ const assert = require('assert');
|
|||||||
const { create_routes } = require('../../dist/core.ts.js');
|
const { create_routes } = require('../../dist/core.ts.js');
|
||||||
|
|
||||||
describe('create_routes', () => {
|
describe('create_routes', () => {
|
||||||
|
it('encodes caharcters not allowed in path', () => {
|
||||||
|
const routes = create_routes({
|
||||||
|
files: [
|
||||||
|
'"',
|
||||||
|
'#',
|
||||||
|
'?'
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.deepEqual(
|
||||||
|
routes.map(r => r.pattern),
|
||||||
|
[
|
||||||
|
/^\/%22\/?$/,
|
||||||
|
/^\/%23\/?$/,
|
||||||
|
/^\/%3F\/?$/
|
||||||
|
]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('sorts routes correctly', () => {
|
it('sorts routes correctly', () => {
|
||||||
const routes = create_routes({
|
const routes = create_routes({
|
||||||
files: ['index.html', 'about.html', 'post/f[xx].html', '[wildcard].html', 'post/foo.html', 'post/[id].html', 'post/bar.html', 'post/[id].json.js']
|
files: ['index.html', 'about.html', 'post/f[xx].html', '[wildcard].html', 'post/foo.html', 'post/[id].html', 'post/bar.html', 'post/[id].json.js']
|
||||||
|
|||||||
Reference in New Issue
Block a user