Compare commits

...

6 Commits

Author SHA1 Message Date
Rich Harris
442ce366e2 -> v0.1.1 2017-12-17 15:18:03 -05:00
Rich Harris
dc929fcd83 inject app path, since dest might be /tmp causing resolution failure 2017-12-17 15:17:23 -05:00
Rich Harris
2dc246398b -> v0.1.0 2017-12-17 15:05:51 -05:00
Rich Harris
b7ac067459 always write to .sapper, not templates, since we cant guarantee fs access 2017-12-17 15:04:20 -05:00
Rich Harris
8b50ff34b8 named exports, for tree-shakeability when we add new stuff 2017-12-17 15:01:26 -05:00
Rich Harris
62abdb2a87 remove magic return values from server routes 2017-12-17 15:01:05 -05:00
7 changed files with 41 additions and 48 deletions

9
CHANGELOG.md Normal file
View File

@@ -0,0 +1,9 @@
# sapper changelog
## 0.1.1
* Expose resolved pathname to `sapper/runtime/app.js` as `__app__` inside main.js
## 0.1.0
* First public preview

View File

@@ -11,6 +11,4 @@ exports.dest = path.resolve(
process.env.SAPPER_DEST || '.sapper'
);
exports.main_built = path.resolve('templates/.main.tmp.js');
exports.server_routes = path.resolve(exports.dest, 'server-routes.js');

View File

@@ -94,7 +94,7 @@ module.exports = function connect(opts) {
}
}
async function handle_route(url, req, res) {
async function handle_route(url, req, res, next) {
// whatever happens, we're going to serve some HTML
res.set({
'Content-Type': 'text/html'
@@ -128,20 +128,7 @@ module.exports = function connect(opts) {
else {
const handler = mod[req.method.toLowerCase()];
if (handler) {
if (handler.length === 2) {
handler(req, res);
} else {
const data = await handler(req);
// TODO headers, error handling
if (typeof data === 'string') {
res.end(data);
} else {
res.end(JSON.stringify(data));
}
}
}
if (handler) handler(req, res, next);
}
return;
@@ -170,7 +157,7 @@ module.exports = function connect(opts) {
handle_index(url, req, res, () => {
handle_service_worker(url, req, res, () => {
handle_webpack_generated_files(url, req, res, () => {
handle_route(url, req, res);
handle_route(url, req, res, next);
});
});
});

View File

@@ -1,6 +1,6 @@
const fs = require('fs');
const path = require('path');
const { dest, main_built, server_routes, dev } = require('../config.js');
const { dest, server_routes, dev } = require('../config.js');
module.exports = function create_app(src, dest, routes, options) {
function create_client_main() {
@@ -20,14 +20,17 @@ module.exports = function create_app(src, dest, routes, options) {
}]`;
const main = template
.replace(/__app__/g, path.resolve(__dirname, '../../runtime/app.js'))
.replace(/__routes__/g, code)
.replace(/__dev__/g, String(dev));
fs.writeFileSync(main_built, main);
const file = path.resolve(dest, 'main.js');
fs.writeFileSync(file, main);
// need to fudge the mtime, because webpack is soft in the head
const stats = fs.statSync(main_built);
fs.utimesSync(main_built, stats.atimeMs - 999999, stats.mtimeMs - 999999);
const stats = fs.statSync(file);
fs.utimesSync(file, stats.atimeMs - 999999, stats.mtimeMs - 999999);
}
function create_server_routes() {

View File

@@ -1,7 +1,7 @@
{
"name": "sapper",
"version": "0.0.22",
"description": "Combat-ready apps, engineered by Svelte",
"version": "0.1.1",
"description": "Military-grade apps, engineered by Svelte",
"main": "lib/index.js",
"directories": {
"test": "test"

View File

@@ -2,7 +2,7 @@ const detach = node => {
node.parentNode.removeChild(node);
};
let component;
export let component;
let target;
let routes;
@@ -158,28 +158,26 @@ function findAnchor(node) {
let inited;
const app = {
init(_target, _routes) {
target = _target;
routes = _routes;
export function init(_target, _routes) {
target = _target;
routes = _routes;
if (!inited) { // this check makes HMR possible
window.addEventListener('click', handle_click);
window.addEventListener('popstate', handle_popstate);
if (!inited) { // this check makes HMR possible
window.addEventListener('click', handle_click);
window.addEventListener('popstate', handle_popstate);
// prefetch
window.addEventListener('touchstart', prefetch);
window.addEventListener('mouseover', prefetch);
// prefetch
window.addEventListener('touchstart', prefetch);
window.addEventListener('mouseover', prefetch);
inited = true;
}
const scroll = scroll_history[uid] = scroll_state();
history.replaceState({ id: uid }, '', window.location.href);
navigate(new URL(window.location), uid);
inited = true;
}
};
const scroll = scroll_history[uid] = scroll_state();
history.replaceState({ id: uid }, '', window.location.href);
navigate(new URL(window.location), uid);
}
function which(event) {
event = event || window.event;
@@ -191,6 +189,4 @@ function scroll_state() {
x: window.scrollX,
y: window.scrollY
};
}
export default app;
}

View File

@@ -1,6 +1,6 @@
const path = require('path');
const route_manager = require('../lib/route_manager.js');
const { src, dest, dev, main_built, server_routes } = require('../lib/config.js');
const { src, dest, dev, server_routes } = require('../lib/config.js');
module.exports = {
dev,
@@ -8,7 +8,7 @@ module.exports = {
client: {
entry: () => {
return {
main: main_built
main: `${dest}/main.js`
};
},