Skip to content

Commit

Permalink
Switch to the 2.x version of the mime library.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjeffburke committed May 10, 2021
1 parent 6a6b4f1 commit b3e77ae
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"exif-reader": "^1.0.3",
"icc": "^1.0.0",
"lodash": "^4.17.15",
"mime": "^1.6.0",
"mime": "^2.5.2",
"require-or": "0.0.2"
}
}
5 changes: 0 additions & 5 deletions src/Impro.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
const _ = require('lodash');
const mime = require('mime');
const Pipeline = require('./Pipeline');

mime.define({
'image/vnd.microsoft.icon': ['ico'],
});

module.exports = class Impro {
constructor(options) {
if (!options || typeof options === 'object') {
Expand Down
11 changes: 6 additions & 5 deletions src/Pipeline.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const Stream = require('stream');
const mime = require('mime');
const Path = require('path');

const mime = require('./mime');

module.exports = class Pipeline extends Stream.Duplex {
constructor(impro, options) {
super();
Expand Down Expand Up @@ -164,7 +165,7 @@ module.exports = class Pipeline extends Stream.Duplex {
) {
if (this.impro.isTypeByName[operation.name]) {
this.targetType = operation.name;
this.targetContentType = mime.types[operation.name];
this.targetContentType = mime.getType(operation.name);
}

candidateEngineNames = filteredCandidateEngineNames;
Expand All @@ -179,7 +180,7 @@ module.exports = class Pipeline extends Stream.Duplex {
// only then set the new type after the flush.
if (this.impro.isTypeByName[operation.name]) {
this.targetType = operation.name;
this.targetContentType = mime.types[operation.name];
this.targetContentType = mime.getType(operation.name);
}

lastSelectedEngineName = undefined;
Expand Down Expand Up @@ -363,9 +364,9 @@ module.exports = class Pipeline extends Stream.Duplex {
} else {
if (this.impro.isTypeByName[type]) {
this.sourceType = this.targetType = type;
this.targetContentType = mime.types[type];
this.targetContentType = mime.getType(type);
} else {
const extension = mime.extensions[type.replace(/\s*;.*$/, '')];
const extension = mime.getExtension(type);
if (extension) {
if (this.impro.isTypeByName[extension]) {
this.sourceType = this.targetType = extension;
Expand Down
5 changes: 3 additions & 2 deletions src/engines/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ const requireOr = require('require-or');
const sharp = requireOr('sharp');
const Stream = require('stream');
const createAnimatedGifDetector = requireOr('animated-gif-detector');
const mime = require('mime');
const exifReader = require('exif-reader');
const icc = require('icc');
const _ = require('lodash');

const mime = require('../mime');

module.exports = {
name: 'metadata',
unavailable: !sharp,
Expand Down Expand Up @@ -69,7 +70,7 @@ module.exports = {
const alreadyKnownMetadata = {
format: pipeline.targetType,
contentType:
pipeline.targetContentType || mime.types[pipeline.targetType],
pipeline.targetContentType || mime.getType(pipeline.targetType),
};
if (pipeline._streams.length === 0) {
_.extend(alreadyKnownMetadata, pipeline.sourceMetadata);
Expand Down
4 changes: 4 additions & 0 deletions src/mime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const mime = require('mime');

module.exports.getExtension = (ext) => mime.getExtension(ext) || undefined;
module.exports.getType = (type) => mime.getType(type) || undefined;
5 changes: 5 additions & 0 deletions test/impro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,11 @@ describe('impro', () => {
});

describe('#metadata', () => {
it('should default the output content type to JSON', () =>
expect(impro.metadata().flush(), 'to satisfy', {
targetContentType: 'application/json; charset=utf-8',
}));

it('should produce the metadata of an image as JSON', () =>
expect(
'turtle.jpg',
Expand Down

0 comments on commit b3e77ae

Please sign in to comment.