Skip to content

Commit

Permalink
Update parser to treat file extensions as case-insensitive (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon93s authored and devongovett committed Feb 5, 2018
1 parent 55b9640 commit ab713a3
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ class Parser {
ext = '.' + ext;
}

this.extensions[ext] = parser;
this.extensions[ext.toLowerCase()] = parser;
}

findParser(filename) {
if (glob.hasMagic(filename)) {
return GlobAsset;
}

let extension = path.extname(filename);
let extension = path.extname(filename).toLowerCase();
let parser = this.extensions[extension] || RawAsset;
if (typeof parser === 'string') {
parser = this.extensions[extension] = require(parser);
Expand Down
5 changes: 5 additions & 0 deletions test/integration/parser-case-insensitive-ext/icons.SVG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions test/integration/parser-case-insensitive-ext/index.cSs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
background: red;
}
17 changes: 17 additions & 0 deletions test/integration/parser-case-insensitive-ext/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="index.cSs" />
</head>
<body>
<h1>Hello world</h1>
<p>Linking to <a href="other.HTM">another page</a></p>
<a href="#hash_link">Hash link</a>
<a href="mailto:someone@acme.com">Mailto link</a>
<a href="tel:+33636757575">Tel link</a>
<script src="index.js"></script>
<script src="https://unpkg.com/parcel-bundler"></script>
<i>hello</i> <i>world</i>
<svg><use xlink:href="icons.SVG#icon-repo-pull"></use></svg>
</body>
</html>
1 change: 1 addition & 0 deletions test/integration/parser-case-insensitive-ext/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alert('Hi');
10 changes: 10 additions & 0 deletions test/integration/parser-case-insensitive-ext/other.HTM
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="index.cSs" />
</head>
<body>
<h1>Other page</h1>
<script src="index.js"></script>
</body>
</html>
66 changes: 66 additions & 0 deletions test/parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const assert = require('assert');
const fs = require('fs');
const {bundle, assertBundleTree} = require('./utils');

describe('parser', function() {
it('should support case-insensitive file extension', async function() {
let b = await bundle(
__dirname + '/integration/parser-case-insensitive-ext/index.html'
);

assertBundleTree(b, {
name: 'index.html',
assets: ['index.html'],
childBundles: [
{
type: 'svg',
assets: ['icons.SVG'],
childBundles: []
},
{
type: 'css',
assets: ['index.cSs'],
childBundles: []
},
{
type: 'js',
assets: ['index.js'],
childBundles: [
{
type: 'map'
}
]
},
{
type: 'html',
assets: ['other.HTM'],
childBundles: [
{
type: 'css',
assets: ['index.cSs'],
childBundles: []
},
{
type: 'js',
assets: ['index.js'],
childBundles: [
{
type: 'map'
}
]
}
]
}
]
});

let files = fs.readdirSync(__dirname + '/dist');
let html = fs.readFileSync(__dirname + '/dist/index.html');
for (let file of files) {
let ext = file.match(/\.([0-9a-z]+)(?:[?#]|$)/i)[0];
if (file !== 'index.html' && ext !== '.map') {
assert(html.includes(file));
}
}
});
});
2 changes: 1 addition & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function assertBundleTree(bundle, tree) {
}

if (tree.type) {
assert.equal(bundle.type, tree.type);
assert.equal(bundle.type.toLowerCase(), tree.type.toLowerCase());
}

if (tree.assets) {
Expand Down

0 comments on commit ab713a3

Please sign in to comment.