mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-12 19:25:10 +00:00
ignore things that look like temp files when generating manifest data - fixes #220
This commit is contained in:
@@ -30,13 +30,16 @@ export default function create_manifest_data(cwd = locations.routes()): Manifest
|
||||
const file = path.relative(cwd, resolved);
|
||||
const is_dir = fs.statSync(resolved).isDirectory();
|
||||
|
||||
const ext = path.extname(basename);
|
||||
if (!is_dir && !/^\.[a-z]+$/i.test(ext)) return null; // filter out tmp files etc
|
||||
|
||||
const segment = is_dir
|
||||
? basename
|
||||
: basename.slice(0, -path.extname(basename).length);
|
||||
|
||||
const parts = get_parts(segment);
|
||||
const is_index = is_dir ? false : basename.startsWith('index.');
|
||||
const is_page = path.extname(basename) === '.html';
|
||||
const is_page = ext === '.html';
|
||||
|
||||
parts.forEach(part => {
|
||||
if (/\]\[/.test(part.content)) {
|
||||
@@ -57,6 +60,7 @@ export default function create_manifest_data(cwd = locations.routes()): Manifest
|
||||
is_page
|
||||
};
|
||||
})
|
||||
.filter(Boolean)
|
||||
.sort(comparator);
|
||||
|
||||
items.forEach(item => {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import * as path from 'path';
|
||||
import * as assert from 'assert';
|
||||
import manifest_data from '../../../src/core/create_manifest_data';
|
||||
import create_manifest_data from '../../../src/core/create_manifest_data';
|
||||
|
||||
describe('manifest_data', () => {
|
||||
it('creates routes', () => {
|
||||
const { components, pages, server_routes } = manifest_data(path.join(__dirname, 'samples/basic'));
|
||||
const { components, pages, server_routes } = create_manifest_data(path.join(__dirname, 'samples/basic'));
|
||||
|
||||
const index = { name: 'index', file: 'index.html' };
|
||||
const about = { name: 'about', file: 'about.html' };
|
||||
@@ -68,7 +68,7 @@ describe('manifest_data', () => {
|
||||
});
|
||||
|
||||
it('encodes invalid characters', () => {
|
||||
const { components, pages } = manifest_data(path.join(__dirname, 'samples/encoding'));
|
||||
const { components, pages } = create_manifest_data(path.join(__dirname, 'samples/encoding'));
|
||||
|
||||
// had to remove ? and " because windows
|
||||
|
||||
@@ -90,7 +90,7 @@ describe('manifest_data', () => {
|
||||
});
|
||||
|
||||
it('allows regex qualifiers', () => {
|
||||
const { pages } = manifest_data(path.join(__dirname, 'samples/qualifiers'));
|
||||
const { pages } = create_manifest_data(path.join(__dirname, 'samples/qualifiers'));
|
||||
|
||||
assert.deepEqual(pages.map(p => p.pattern), [
|
||||
/^\/([0-9-a-z]{3,})\/?$/,
|
||||
@@ -100,7 +100,7 @@ describe('manifest_data', () => {
|
||||
});
|
||||
|
||||
it('sorts routes correctly', () => {
|
||||
const { pages } = manifest_data(path.join(__dirname, 'samples/sorting'));
|
||||
const { pages } = create_manifest_data(path.join(__dirname, 'samples/sorting'));
|
||||
|
||||
assert.deepEqual(pages.map(p => p.parts.map(part => part && part.component.file)), [
|
||||
['index.html'],
|
||||
@@ -116,7 +116,7 @@ describe('manifest_data', () => {
|
||||
});
|
||||
|
||||
it('ignores files and directories with leading underscores', () => {
|
||||
const { server_routes } = manifest_data(path.join(__dirname, 'samples/hidden-underscore'));
|
||||
const { server_routes } = create_manifest_data(path.join(__dirname, 'samples/hidden-underscore'));
|
||||
|
||||
assert.deepEqual(server_routes.map(r => r.file), [
|
||||
'index.js',
|
||||
@@ -125,7 +125,7 @@ describe('manifest_data', () => {
|
||||
});
|
||||
|
||||
it('ignores files and directories with leading dots except .well-known', () => {
|
||||
const { server_routes } = manifest_data(path.join(__dirname, 'samples/hidden-dot'));
|
||||
const { server_routes } = create_manifest_data(path.join(__dirname, 'samples/hidden-dot'));
|
||||
|
||||
assert.deepEqual(server_routes.map(r => r.file), [
|
||||
'.well-known/dnt-policy.txt.js'
|
||||
@@ -134,24 +134,35 @@ describe('manifest_data', () => {
|
||||
|
||||
it('fails on clashes', () => {
|
||||
assert.throws(() => {
|
||||
const { pages } = manifest_data(path.join(__dirname, 'samples/clash-pages'));
|
||||
const { pages } = create_manifest_data(path.join(__dirname, 'samples/clash-pages'));
|
||||
}, /The \[bar\]\/index\.html and \[foo\]\.html pages clash/);
|
||||
|
||||
assert.throws(() => {
|
||||
const { server_routes } = manifest_data(path.join(__dirname, 'samples/clash-routes'));
|
||||
const { server_routes } = create_manifest_data(path.join(__dirname, 'samples/clash-routes'));
|
||||
console.log(server_routes);
|
||||
}, /The \[bar\]\/index\.js and \[foo\]\.js routes clash/);
|
||||
});
|
||||
|
||||
it('fails if dynamic params are not separated', () => {
|
||||
assert.throws(() => {
|
||||
manifest_data(path.join(__dirname, 'samples/invalid-params'));
|
||||
create_manifest_data(path.join(__dirname, 'samples/invalid-params'));
|
||||
}, /Invalid route \[foo\]\[bar\]\.js — parameters must be separated/);
|
||||
});
|
||||
|
||||
it('errors when trying to use reserved characters in route regexp', () => {
|
||||
assert.throws(() => {
|
||||
manifest_data(path.join(__dirname, 'samples/invalid-qualifier'));
|
||||
create_manifest_data(path.join(__dirname, 'samples/invalid-qualifier'));
|
||||
}, /Invalid route \[foo\(\[a-z\]\(\[0-9\]\)\)\].js — cannot use \(, \), \? or \: in route qualifiers/);
|
||||
});
|
||||
|
||||
it('ignores things that look like lockfiles' , () => {
|
||||
const { server_routes } = create_manifest_data(path.join(__dirname, 'samples/lockfiles'));
|
||||
|
||||
assert.deepEqual(server_routes, [{
|
||||
file: 'foo.js',
|
||||
name: 'route_foo',
|
||||
params: [],
|
||||
pattern: /^\/foo$/
|
||||
}]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user