Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 4a92fbb

Browse files
authored
Merge pull request #410 from sveltejs/gh-220
ignore things that look like temp files when generating manifest data
2 parents b16440f + 1b6dfd3 commit 4a92fbb

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

src/core/create_manifest_data.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ export default function create_manifest_data(cwd = locations.routes()): Manifest
3030
const file = path.relative(cwd, resolved);
3131
const is_dir = fs.statSync(resolved).isDirectory();
3232

33+
const ext = path.extname(basename);
34+
if (!is_dir && !/^\.[a-z]+$/i.test(ext)) return null; // filter out tmp files etc
35+
3336
const segment = is_dir
3437
? basename
3538
: basename.slice(0, -path.extname(basename).length);
3639

3740
const parts = get_parts(segment);
3841
const is_index = is_dir ? false : basename.startsWith('index.');
39-
const is_page = path.extname(basename) === '.html';
42+
const is_page = ext === '.html';
4043

4144
parts.forEach(part => {
4245
if (/\]\[/.test(part.content)) {
@@ -57,6 +60,7 @@ export default function create_manifest_data(cwd = locations.routes()): Manifest
5760
is_page
5861
};
5962
})
63+
.filter(Boolean)
6064
.sort(comparator);
6165

6266
items.forEach(item => {

test/unit/create_manifest_data/index.ts

+22-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as path from 'path';
22
import * as assert from 'assert';
3-
import manifest_data from '../../../src/core/create_manifest_data';
3+
import create_manifest_data from '../../../src/core/create_manifest_data';
44

55
describe('manifest_data', () => {
66
it('creates routes', () => {
7-
const { components, pages, server_routes } = manifest_data(path.join(__dirname, 'samples/basic'));
7+
const { components, pages, server_routes } = create_manifest_data(path.join(__dirname, 'samples/basic'));
88

99
const index = { name: 'index', file: 'index.html' };
1010
const about = { name: 'about', file: 'about.html' };
@@ -68,7 +68,7 @@ describe('manifest_data', () => {
6868
});
6969

7070
it('encodes invalid characters', () => {
71-
const { components, pages } = manifest_data(path.join(__dirname, 'samples/encoding'));
71+
const { components, pages } = create_manifest_data(path.join(__dirname, 'samples/encoding'));
7272

7373
// had to remove ? and " because windows
7474

@@ -90,7 +90,7 @@ describe('manifest_data', () => {
9090
});
9191

9292
it('allows regex qualifiers', () => {
93-
const { pages } = manifest_data(path.join(__dirname, 'samples/qualifiers'));
93+
const { pages } = create_manifest_data(path.join(__dirname, 'samples/qualifiers'));
9494

9595
assert.deepEqual(pages.map(p => p.pattern), [
9696
/^\/([0-9-a-z]{3,})\/?$/,
@@ -100,7 +100,7 @@ describe('manifest_data', () => {
100100
});
101101

102102
it('sorts routes correctly', () => {
103-
const { pages } = manifest_data(path.join(__dirname, 'samples/sorting'));
103+
const { pages } = create_manifest_data(path.join(__dirname, 'samples/sorting'));
104104

105105
assert.deepEqual(pages.map(p => p.parts.map(part => part && part.component.file)), [
106106
['index.html'],
@@ -116,7 +116,7 @@ describe('manifest_data', () => {
116116
});
117117

118118
it('ignores files and directories with leading underscores', () => {
119-
const { server_routes } = manifest_data(path.join(__dirname, 'samples/hidden-underscore'));
119+
const { server_routes } = create_manifest_data(path.join(__dirname, 'samples/hidden-underscore'));
120120

121121
assert.deepEqual(server_routes.map(r => r.file), [
122122
'index.js',
@@ -125,7 +125,7 @@ describe('manifest_data', () => {
125125
});
126126

127127
it('ignores files and directories with leading dots except .well-known', () => {
128-
const { server_routes } = manifest_data(path.join(__dirname, 'samples/hidden-dot'));
128+
const { server_routes } = create_manifest_data(path.join(__dirname, 'samples/hidden-dot'));
129129

130130
assert.deepEqual(server_routes.map(r => r.file), [
131131
'.well-known/dnt-policy.txt.js'
@@ -134,24 +134,35 @@ describe('manifest_data', () => {
134134

135135
it('fails on clashes', () => {
136136
assert.throws(() => {
137-
const { pages } = manifest_data(path.join(__dirname, 'samples/clash-pages'));
137+
const { pages } = create_manifest_data(path.join(__dirname, 'samples/clash-pages'));
138138
}, /The \[bar\]\/index\.html and \[foo\]\.html pages clash/);
139139

140140
assert.throws(() => {
141-
const { server_routes } = manifest_data(path.join(__dirname, 'samples/clash-routes'));
141+
const { server_routes } = create_manifest_data(path.join(__dirname, 'samples/clash-routes'));
142142
console.log(server_routes);
143143
}, /The \[bar\]\/index\.js and \[foo\]\.js routes clash/);
144144
});
145145

146146
it('fails if dynamic params are not separated', () => {
147147
assert.throws(() => {
148-
manifest_data(path.join(__dirname, 'samples/invalid-params'));
148+
create_manifest_data(path.join(__dirname, 'samples/invalid-params'));
149149
}, /Invalid route \[foo\]\[bar\]\.js parameters must be separated/);
150150
});
151151

152152
it('errors when trying to use reserved characters in route regexp', () => {
153153
assert.throws(() => {
154-
manifest_data(path.join(__dirname, 'samples/invalid-qualifier'));
154+
create_manifest_data(path.join(__dirname, 'samples/invalid-qualifier'));
155155
}, /Invalid route \[foo\(\[a-z\]\(\[0-9\]\)\)\].js cannot use \(, \), \? or \: in route qualifiers/);
156156
});
157+
158+
it('ignores things that look like lockfiles' , () => {
159+
const { server_routes } = create_manifest_data(path.join(__dirname, 'samples/lockfiles'));
160+
161+
assert.deepEqual(server_routes, [{
162+
file: 'foo.js',
163+
name: 'route_foo',
164+
params: [],
165+
pattern: /^\/foo$/
166+
}]);
167+
});
157168
});

test/unit/create_manifest_data/samples/lockfiles/foo.js

Whitespace-only changes.

test/unit/create_manifest_data/samples/lockfiles/foo.js_tmp

Whitespace-only changes.

0 commit comments

Comments
 (0)