Skip to content

Commit b02d5a6

Browse files
authored
Merge pull request #4 from shaunwarman/simplify-logic
chore: simplify code
2 parents b0b6355 + a744e74 commit b02d5a6

File tree

2 files changed

+3
-52
lines changed

2 files changed

+3
-52
lines changed

index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@ module.exports = function(opts) {
2424
return (str, prop = 'path') => {
2525
let output = opts.prepend + str;
2626
try {
27-
if (!PROD) manifest = require(opts.manifest);
28-
if (typeof manifest[str] === 'string') {
29-
output = opts.prepend + String(manifest[str] || str);
30-
} else if (typeof manifest[str] === 'object') {
31-
const val = String((manifest[str] && manifest[str][prop]) || str);
32-
if (prop === 'path') return opts.prepend + val;
33-
output = PROD ? val : false;
34-
}
27+
const val = String((manifest[str] && manifest[str][prop]) || str);
28+
if (prop === 'path') return opts.prepend + val;
29+
output = PROD ? val : false;
3530
} catch (err) {}
3631

3732
return output;

test/test.js

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@ test('throws error without opts.manifest string', t => {
1313
t.is(error.message, '`manifest` property is required');
1414
});
1515

16-
test('throws error with opts.prepend non-string with old format', t => {
17-
const manifest = path.join(__dirname, 'fixtures', 'old-rev-manifest.json');
18-
const error = t.throws(() =>
19-
manifestRev({
20-
manifest,
21-
prepend: true
22-
})
23-
);
24-
t.is(error.message, '`prepend` property defined, but it was not a string');
25-
});
26-
2716
test('throws error with opts.prepend non-string with new format', t => {
2817
const manifest = path.join(__dirname, 'fixtures', 'rev-manifest.json');
2918
const error = t.throws(() =>
@@ -35,59 +24,26 @@ test('throws error with opts.prepend non-string with new format', t => {
3524
t.is(error.message, '`prepend` property defined, but it was not a string');
3625
});
3726

38-
test('exposes manifest function with old format', t => {
39-
const manifest = path.join(__dirname, 'fixtures', 'old-rev-manifest.json');
40-
t.true(typeof manifestRev({ manifest }) === 'function');
41-
});
42-
4327
test('exposes manifest function with new format', t => {
4428
const manifest = path.join(__dirname, 'fixtures', 'rev-manifest.json');
4529
t.true(typeof manifestRev({ manifest }) === 'function');
4630
});
4731

48-
test('returns output when manifest invoked with old format', t => {
49-
const manifest = path.join(__dirname, 'fixtures', 'old-rev-manifest.json');
50-
t.is(manifestRev({ manifest })('script.js'), '/script-d80c4dea53.js');
51-
});
52-
5332
test('returns output when manifest invoked with new format', t => {
5433
const manifest = path.join(__dirname, 'fixtures', 'rev-manifest.json');
5534
t.is(manifestRev({ manifest })('script.js'), '/script-d80c4dea53.js');
5635
});
5736

58-
test('returns output of path when manifest invoked with old format', t => {
59-
const manifest = path.join(__dirname, 'fixtures', 'old-rev-manifest.json');
60-
t.is(manifestRev({ manifest })('script.js', 'path'), '/script-d80c4dea53.js');
61-
});
62-
6337
test('returns output of path when manifest invoked with new format', t => {
6438
const manifest = path.join(__dirname, 'fixtures', 'rev-manifest.json');
6539
t.is(manifestRev({ manifest })('script.js', 'path'), '/script-d80c4dea53.js');
6640
});
6741

68-
test('returns output of integrity when manifest invoked with old format', t => {
69-
const manifest = path.join(__dirname, 'fixtures', 'old-rev-manifest.json');
70-
t.is(
71-
manifestRev({ manifest })('script.js', 'integrity'),
72-
'/script-d80c4dea53.js'
73-
);
74-
});
75-
7642
test('returns output of integrity when manifest invoked with new format', t => {
7743
const manifest = path.join(__dirname, 'fixtures', 'rev-manifest.json');
7844
t.is(manifestRev({ manifest })('script.js', 'integrity'), false);
7945
});
8046

81-
test('returns output of integrity when manifest invoked in PROD with old format', t => {
82-
const manifest = path.join(__dirname, 'fixtures', 'old-rev-manifest.json');
83-
process.env.NODE_ENV = 'production';
84-
t.is(
85-
manifestRev({ manifest })('script.js', 'integrity'),
86-
'/script-d80c4dea53.js'
87-
);
88-
delete process.env.NODE_ENV;
89-
});
90-
9147
test('returns output of integrity when manifest invoked in PROD with new format', t => {
9248
const manifest = path.join(__dirname, 'fixtures', 'rev-manifest.json');
9349
process.env.NODE_ENV = 'production';

0 commit comments

Comments
 (0)