feat: inspect folder structure if asset not found

This commit is contained in:
Lucas Nogueira
2020-01-26 11:21:32 -03:00
parent a984ea8553
commit 920fc24e30
4 changed files with 17 additions and 1 deletions

View File

@@ -37,7 +37,11 @@ module.exports = function get(url, options) {
cache[url] = fs.readFile(fileName).catch(function (error) {
if (error.code === 'ENOENT' || error.code === 'ENAMETOOLONG') {
debug(error.code + ': ' + base + ', trying decodeURI');
return fs.readFile(decodeURI(url));
return fs.readFile(decodeURI(url)).catch(function (error) {
const nextTry = url.split('/').slice(1).join('/');
debug(error.code + ': ' + base + ', trying ' + nextTry);
return get.call(inliner, nextTry, options).then(res => res.body);
});
}
throw error;
}).then(function read(body) {

View File

@@ -0,0 +1 @@
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>public path script</title> </head> <body> <script>function surroundWithScriptTag(r){return"<script>"+r+"<\/script>"}for(var array=[4,8,15,16,23,42],i=0;i<array.length;i++)console.log(array[i]);</script> </body> </html>

View File

@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>public path script</title>
</head>
<body>
<script src="/test/inner/public-path/script-local.js"></script>
</body>
</html>

View File

@@ -111,6 +111,7 @@ test('inliner fixtures', function fixtureTests(t) {
error.message += ' @ ' + basename;
return reject(error);
}
t.equal(html.trim(), results[i].trim(), basename + ' matches');
debug('result', html.trim());
// debug('expected', results[i].trim());