Compare commits

...

4 Commits

Author SHA1 Message Date
Rich Harris
666c113297 -> v0.15.6 2018-08-06 22:36:17 -04:00
Rich Harris
84a58f34a0 add test for exporting with custom basepath 2018-08-06 22:35:02 -04:00
Rich Harris
75f5b5c721 Merge pull request #342 from aubergene/gh-338
Remove basepath from deferred urls and add trailing slash to root
2018-08-06 22:06:09 -04:00
Julian Burgess
a176a3b79b Remove basepath from deferred urls and add trailing slash to root request 2018-08-06 16:43:02 +01:00
4 changed files with 32 additions and 9 deletions

View File

@@ -1,5 +1,9 @@
# sapper changelog
## 0.15.6
* Fix exporting with custom basepath ([#342](https://github.com/sveltejs/sapper/pull/342))
## 0.15.5
* Faster `export` with more explanatory output ([#335](https://github.com/sveltejs/sapper/pull/335))

View File

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

View File

@@ -51,9 +51,10 @@ async function execute(emitter: EventEmitter, {
const port = await ports.find(3000);
const origin = `http://localhost:${port}`;
const root = new URL(basepath || '', origin);
emitter.emit('info', {
message: `Crawling ${origin}`
message: `Crawling ${root.href}`
});
const proc = child_process.fork(path.resolve(`${build}/server.js`), [], {
@@ -71,8 +72,10 @@ async function execute(emitter: EventEmitter, {
const deferreds = new Map();
function get_deferred(pathname: string) {
pathname = pathname.replace(root.pathname, '');
if (!deferreds.has(pathname)) {
deferreds.set(pathname, new Deferred()) ;
deferreds.set(pathname, new Deferred());
}
return deferreds.get(pathname);
@@ -107,7 +110,7 @@ async function execute(emitter: EventEmitter, {
});
async function handle(url: URL) {
const pathname = url.pathname || '/';
const pathname = (url.pathname.replace(root.pathname, '') || '/');
if (seen.has(pathname)) return;
seen.add(pathname);
@@ -138,6 +141,9 @@ async function execute(emitter: EventEmitter, {
}
return ports.wait(port)
.then(() => handle(new URL(`/${basepath}`, origin))) // TODO all static routes
.then(() => {
// TODO all static routes
return handle(root);
})
.then(() => proc.kill());
}

View File

@@ -59,9 +59,19 @@ describe('sapper', function() {
basepath: '/custom-basepath'
});
describe('export', () => {
testExport({});
testExport({ basepath: '/custom-basepath' });
});
function testExport({ basepath = '' }) {
describe(basepath ? `export --basepath ${basepath}` : 'export', () => {
before(() => {
return exec(`node ${cli} export`);
if (basepath) {
process.env.BASEPATH = basepath;
}
return exec(`node ${cli} export ${basepath ? `--basepath ${basepath}` : ''}`);
});
it('export all pages', () => {
@@ -96,7 +106,10 @@ describe('sapper', function() {
'service-worker.js',
'svelte-logo-192.png',
'svelte-logo-512.png',
];
].map(file => {
return basepath ? path.join(basepath.replace(/^\//, ''), file) : file;
});
// Client scripts that should show up in the extraction directory.
const expectedClientRegexes = [
/client\/[^/]+\/main(\.\d+)?\.js/,
@@ -126,7 +139,7 @@ describe('sapper', function() {
});
});
});
});
}
function run({ mode, basepath = '' }) {
describe(`mode=${mode}`, function () {