Skip to content

Commit ab713a3

Browse files
brandon93sdevongovett
authored andcommitted
Update parser to treat file extensions as case-insensitive (#743)
1 parent 55b9640 commit ab713a3

File tree

8 files changed

+105
-3
lines changed

8 files changed

+105
-3
lines changed

src/Parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ class Parser {
4949
ext = '.' + ext;
5050
}
5151

52-
this.extensions[ext] = parser;
52+
this.extensions[ext.toLowerCase()] = parser;
5353
}
5454

5555
findParser(filename) {
5656
if (glob.hasMagic(filename)) {
5757
return GlobAsset;
5858
}
5959

60-
let extension = path.extname(filename);
60+
let extension = path.extname(filename).toLowerCase();
6161
let parser = this.extensions[extension] || RawAsset;
6262
if (typeof parser === 'string') {
6363
parser = this.extensions[extension] = require(parser);
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background: red;
3+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<link rel="stylesheet" href="index.cSs" />
5+
</head>
6+
<body>
7+
<h1>Hello world</h1>
8+
<p>Linking to <a href="other.HTM">another page</a></p>
9+
<a href="#hash_link">Hash link</a>
10+
<a href="mailto:someone@acme.com">Mailto link</a>
11+
<a href="tel:+33636757575">Tel link</a>
12+
<script src="index.js"></script>
13+
<script src="https://unpkg.com/parcel-bundler"></script>
14+
<i>hello</i> <i>world</i>
15+
<svg><use xlink:href="icons.SVG#icon-repo-pull"></use></svg>
16+
</body>
17+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
alert('Hi');
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<link rel="stylesheet" href="index.cSs" />
5+
</head>
6+
<body>
7+
<h1>Other page</h1>
8+
<script src="index.js"></script>
9+
</body>
10+
</html>

test/parser.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
const assert = require('assert');
2+
const fs = require('fs');
3+
const {bundle, assertBundleTree} = require('./utils');
4+
5+
describe('parser', function() {
6+
it('should support case-insensitive file extension', async function() {
7+
let b = await bundle(
8+
__dirname + '/integration/parser-case-insensitive-ext/index.html'
9+
);
10+
11+
assertBundleTree(b, {
12+
name: 'index.html',
13+
assets: ['index.html'],
14+
childBundles: [
15+
{
16+
type: 'svg',
17+
assets: ['icons.SVG'],
18+
childBundles: []
19+
},
20+
{
21+
type: 'css',
22+
assets: ['index.cSs'],
23+
childBundles: []
24+
},
25+
{
26+
type: 'js',
27+
assets: ['index.js'],
28+
childBundles: [
29+
{
30+
type: 'map'
31+
}
32+
]
33+
},
34+
{
35+
type: 'html',
36+
assets: ['other.HTM'],
37+
childBundles: [
38+
{
39+
type: 'css',
40+
assets: ['index.cSs'],
41+
childBundles: []
42+
},
43+
{
44+
type: 'js',
45+
assets: ['index.js'],
46+
childBundles: [
47+
{
48+
type: 'map'
49+
}
50+
]
51+
}
52+
]
53+
}
54+
]
55+
});
56+
57+
let files = fs.readdirSync(__dirname + '/dist');
58+
let html = fs.readFileSync(__dirname + '/dist/index.html');
59+
for (let file of files) {
60+
let ext = file.match(/\.([0-9a-z]+)(?:[?#]|$)/i)[0];
61+
if (file !== 'index.html' && ext !== '.map') {
62+
assert(html.includes(file));
63+
}
64+
}
65+
});
66+
});

test/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ function assertBundleTree(bundle, tree) {
147147
}
148148

149149
if (tree.type) {
150-
assert.equal(bundle.type, tree.type);
150+
assert.equal(bundle.type.toLowerCase(), tree.type.toLowerCase());
151151
}
152152

153153
if (tree.assets) {

0 commit comments

Comments
 (0)