Compare commits

...

16 Commits

Author SHA1 Message Date
Rich Harris
e2d325ec9f -> v0.22.7 2018-10-01 22:58:44 -04:00
Rich Harris
954bcba333 Merge pull request #460 from sveltejs/cookies
more robust cookies
2018-10-01 22:58:30 -04:00
Rich Harris
709c9992e3 more robust cookies 2018-10-01 22:47:11 -04:00
Rich Harris
9773781262 -> v0.22.6 2018-10-01 20:55:25 -04:00
Rich Harris
48b1fafc33 Merge pull request #459 from sveltejs/gh-458
inject a <script> with crossOrigin - fixes #458
2018-10-01 20:48:42 -04:00
Rich Harris
d1624add66 Merge pull request #456 from mrkishi/windows-paths
Fix rollup input paths on Windows
2018-10-01 20:48:21 -04:00
Rich Harris
e2206d0e0d inject a <script> with crossOrigin - fixes #458 2018-10-01 18:55:38 -04:00
Rich Harris
9cd4da4c39 -> v0.22.5 2018-10-01 17:54:29 -04:00
Rich Harris
6ded1a5975 slap self in face 2018-10-01 17:52:57 -04:00
mrkishi
584ddd1c85 Fix rollup input paths on Windows 2018-10-01 17:47:44 -03:00
Rich Harris
4071acf7c0 -> v0.22.4 2018-10-01 15:53:40 -04:00
Rich Harris
e8773d3196 Merge pull request #455 from sveltejs/deconflict-server
put server assets in subfolder
2018-10-01 15:52:14 -04:00
Rich Harris
01a519a4d9 fix everything i just broke 2018-10-01 15:47:01 -04:00
Rich Harris
d9ad1d1b10 put server assets in subfolder 2018-10-01 15:21:35 -04:00
Rich Harris
0826a58995 -> v0.22.3 2018-10-01 12:13:52 -04:00
Rich Harris
6a74097b0c ensure dev client is not imported if server imports client.js 2018-10-01 12:13:03 -04:00
15 changed files with 92 additions and 46 deletions

View File

@@ -1,5 +1,26 @@
# sapper changelog # sapper changelog
## 0.22.7
* Fix cookies ([#460](https://github.com/sveltejs/sapper/pull/460))
## 0.22.6
* Normalise chunk filenames on Windows ([#456](https://github.com/sveltejs/sapper/pull/456))
* Load modules with credentials ([#458](https://github.com/sveltejs/sapper/pull/458))
## 0.22.5
* Fix `sapper dev`. Oops.
## 0.22.4
* Ensure launcher does not overwrite a module ([#455](https://github.com/sveltejs/sapper/pull/455))
## 0.22.3
* Prevent server from accidentally importing dev client
## 0.22.2 ## 0.22.2
* Make paths in generated code relative to project * Make paths in generated code relative to project

2
package-lock.json generated
View File

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

View File

@@ -1,6 +1,6 @@
{ {
"name": "sapper", "name": "sapper",
"version": "0.22.2", "version": "0.22.7",
"description": "Military-grade apps, engineered by Svelte", "description": "Military-grade apps, engineered by Svelte",
"bin": { "bin": {
"sapper": "./sapper" "sapper": "./sapper"

View File

@@ -256,7 +256,7 @@ class Watcher extends EventEmitter {
execArgv.push(`--inspect-port=${this.devtools_port}`); execArgv.push(`--inspect-port=${this.devtools_port}`);
} }
this.proc = child_process.fork(`${dest}/server.js`, [], { this.proc = child_process.fork(`${dest}/server/server.js`, [], {
cwd: process.cwd(), cwd: process.cwd(),
env: Object.assign({ env: Object.assign({
PORT: this.port PORT: this.port

View File

@@ -71,7 +71,7 @@ async function execute(emitter: EventEmitter, opts: Opts) {
message: `Crawling ${root.href}` message: `Crawling ${root.href}`
}); });
const proc = child_process.fork(path.resolve(`${opts.build}/server.js`), [], { const proc = child_process.fork(path.resolve(`${opts.build}/server/server.js`), [], {
cwd: process.cwd(), cwd: process.cwd(),
env: Object.assign({ env: Object.assign({
PORT: port, PORT: port,

View File

@@ -58,7 +58,7 @@ prog.command('build [dest]')
process.env.PORT = process.env.PORT || ${opts.port || 3000}; process.env.PORT = process.env.PORT || ${opts.port || 3000};
console.log('Starting server on port ' + process.env.PORT); console.log('Starting server on port ' + process.env.PORT);
require('./server.js'); require('./server/server.js');
`.replace(/^\t+/gm, '').trim()); `.replace(/^\t+/gm, '').trim());
console.error(`\n> Finished in ${elapsed(start)}. Type ${colors.bold.cyan(`node ${dest}`)} to run the app.`); console.error(`\n> Finished in ${elapsed(start)}. Type ${colors.bold.cyan(`node ${dest}`)} to run the app.`);

View File

@@ -38,11 +38,18 @@ export default class RollupResult implements CompileResult {
// webpack, but we can have a route -> [chunk] map or something // webpack, but we can have a route -> [chunk] map or something
this.assets = {}; this.assets = {};
compiler.chunks.forEach(chunk => { if (typeof compiler.input === 'string') {
if (compiler.input in chunk.modules) { compiler.chunks.forEach(chunk => {
this.assets.main = chunk.fileName; if (compiler.input in chunk.modules) {
this.assets.main = chunk.fileName;
}
});
} else {
for (const name in compiler.input) {
const file = compiler.input[name];
this.assets[name] = compiler.chunks.find(chunk => file in chunk.modules).fileName;
} }
}); }
this.summary = compiler.chunks.map(chunk => { this.summary = compiler.chunks.map(chunk => {
const size_color = chunk.code.length > 150000 ? colors.bold.red : chunk.code.length > 50000 ? colors.bold.yellow : colors.bold.white; const size_color = chunk.code.length > 150000 ? colors.bold.red : chunk.code.length > 50000 ? colors.bold.yellow : colors.bold.white;

View File

@@ -15,6 +15,13 @@ export default async function create_compilers(bundler: 'rollup' | 'webpack'): P
const config = await RollupCompiler.load_config(); const config = await RollupCompiler.load_config();
validate_config(config, 'rollup'); validate_config(config, 'rollup');
normalize_rollup_config(config.client);
normalize_rollup_config(config.server);
if (config.serviceworker) {
normalize_rollup_config(config.serviceworker);
}
return { return {
client: new RollupCompiler(config.client), client: new RollupCompiler(config.client),
server: new RollupCompiler(config.server), server: new RollupCompiler(config.server),
@@ -41,4 +48,14 @@ function validate_config(config: any, bundler: 'rollup' | 'webpack') {
if (!config.client || !config.server) { if (!config.client || !config.server) {
throw new Error(`${bundler}.config.js must export a { client, server, serviceworker? } object`); throw new Error(`${bundler}.config.js must export a { client, server, serviceworker? } object`);
} }
} }
function normalize_rollup_config(config: any) {
if (typeof config.input === 'string') {
config.input = path.normalize(config.input);
} else {
for (const name in config.input) {
config.input[name] = path.normalize(config.input[name]);
}
}
}

View File

@@ -127,9 +127,11 @@ function generate_client(
footer = ` footer = `
import(${stringify(sapper_dev_client)}).then(client => { if (typeof window !== 'undefined') {
client.connect(${dev_port}); import(${stringify(sapper_dev_client)}).then(client => {
});`.replace(/^\t{3}/gm, ''); client.connect(${dev_port});
});
}`.replace(/^\t{3}/gm, '');
} }
return `// This file is generated by Sapper — do not edit it!\n` + template return `// This file is generated by Sapper — do not edit it!\n` + template

View File

@@ -24,12 +24,14 @@ export default {
server: { server: {
input: () => { input: () => {
return `${locations.src()}/server.js` return {
server: `${locations.src()}/server.js`
};
}, },
output: () => { output: () => {
return { return {
dir: locations.dest(), dir: `${locations.dest()}/server`,
format: 'cjs', format: 'cjs',
sourcemap: dev() sourcemap: dev()
}; };

View File

@@ -29,7 +29,7 @@ export default {
output: () => { output: () => {
return { return {
path: locations.dest(), path: `${locations.dest()}/server`,
filename: '[name].js', filename: '[name].js',
chunkFilename: '[hash]/[name].[id].js', chunkFilename: '[hash]/[name].[id].js',
libraryTarget: 'commonjs2' libraryTarget: 'commonjs2'

View File

@@ -93,19 +93,21 @@ export function get_page_handler(
if (include_cookies) { if (include_cookies) {
if (!opts.headers) opts.headers = {}; if (!opts.headers) opts.headers = {};
const str = [] const cookies = Object.assign(
.concat( {},
cookie.parse(req.headers.cookie || ''), cookie.parse(req.headers.cookie || ''),
cookie.parse(opts.headers.cookie || ''), cookie.parse(opts.headers.cookie || '')
cookie.parse(res.getHeader('Set-Cookie') || '') );
)
.map(cookie => { const set_cookie = res.getHeader('Set-Cookie');
return Object.keys(cookie) (Array.isArray(set_cookie) ? set_cookie : [set_cookie]).forEach(str => {
.map(name => `${name}=${encodeURIComponent(cookie[name])}`) const match = /([^=]+)=([^;]+)/.exec(<string>str);
.join('; '); if (match) cookies[match[1]] = match[2];
}) });
.filter(Boolean)
.join(', '); const str = Object.keys(cookies)
.map(key => `${key}=${cookies[key]}`)
.join('; ');
opts.headers.cookie = str; opts.headers.cookie = str;
} }
@@ -222,9 +224,9 @@ export function get_page_handler(
if (build_info.bundler === 'rollup') { if (build_info.bundler === 'rollup') {
if (build_info.legacy_assets) { if (build_info.legacy_assets) {
const legacy_main = `${req.baseUrl}/client/legacy/${build_info.legacy_assets.main}`; const legacy_main = `${req.baseUrl}/client/legacy/${build_info.legacy_assets.main}`;
script += `(function(){try{eval("async function x(){}");var main="${main}"}catch(e){main="${legacy_main}"};try{new Function("import('"+main+"')")();}catch(e){var s=document.createElement("script");s.src="${req.baseUrl}/client/shimport@${build_info.shimport}.js";s.setAttribute("data-main",main);document.head.appendChild(s);}}());`; script += `(function(){try{eval("async function x(){}");var main="${main}"}catch(e){main="${legacy_main}"};var s=document.createElement("script");try{new Function("if(0)import('')")();s.src=main;s.type="module";s.crossOrigin="use-credentials";}catch(e){s.src="${req.baseUrl}/client/shimport@${build_info.shimport}.js";s.setAttribute("data-main",main);}document.head.appendChild(s);}());`;
} else { } else {
script += `try{new Function("import('${main}')")();}catch(e){var s=document.createElement("script");s.src="${req.baseUrl}/client/shimport@${build_info.shimport}.js";s.setAttribute("data-main","${main}");document.head.appendChild(s);}`; script += `var s=document.createElement("script");try{new Function("if(0)import('')")();s.src="${main}";s.type="module";s.crossOrigin="use-credentials";}catch(e){console.error(e);s.src="${req.baseUrl}/client/shimport@${build_info.shimport}.js";s.setAttribute("data-main","${main}")}document.head.appendChild(s)`;
} }
} else { } else {
script += `</script><script src="${main}">`; script += `</script><script src="${main}">`;

View File

@@ -1,20 +1,15 @@
export function get(req, res) { import cookie from 'cookie';
const cookies = req.headers.cookie
? req.headers.cookie.split(/,\s+/).reduce((cookies, cookie) => { export function get(req, res) {
const [pair] = cookie.split('; '); if (req.headers.cookie) {
const [name, value] = pair.split('='); const cookies = cookie.parse(req.headers.cookie);
cookies[name] = value;
return cookies;
}, {})
: {};
if (cookies.test) {
res.writeHead(200, { res.writeHead(200, {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}); });
res.end(JSON.stringify({ res.end(JSON.stringify({
message: cookies.test message: `a: ${cookies.a}, b: ${cookies.b}, max-age: ${cookies['max-age']}`
})); }));
} else { } else {
res.writeHead(403, { res.writeHead(403, {

View File

@@ -44,7 +44,7 @@ const middlewares = [
// set test cookie // set test cookie
(req, res, next) => { (req, res, next) => {
res.setHeader('Set-Cookie', 'test=woohoo!; Max-Age=3600'); res.setHeader('Set-Cookie', ['a=1; Path=/', 'b=2; Path=/']);
next(); next();
}, },

View File

@@ -184,7 +184,7 @@ function run({ mode, basepath = '' }) {
assert.ok(fs.existsSync('__sapper__/build/index.js')); assert.ok(fs.existsSync('__sapper__/build/index.js'));
} }
proc = require('child_process').fork(`${dir}/server.js`, { proc = require('child_process').fork(`${dir}/server/server.js`, {
cwd: process.cwd(), cwd: process.cwd(),
env: { env: {
NODE_ENV: mode, NODE_ENV: mode,
@@ -623,7 +623,7 @@ function run({ mode, basepath = '' }) {
return nightmare.goto(`${base}/credentials?creds=include`) return nightmare.goto(`${base}/credentials?creds=include`)
.page.title() .page.title()
.then(title => { .then(title => {
assert.equal(title, 'woohoo!'); assert.equal(title, 'a: 1, b: 2, max-age: undefined');
}); });
}); });
@@ -641,7 +641,7 @@ function run({ mode, basepath = '' }) {
.wait(100) .wait(100)
.page.title() .page.title()
.then(title => { .then(title => {
assert.equal(title, 'woohoo!'); assert.equal(title, 'a: 1, b: 2, max-age: undefined');
}); });
}); });