Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Make mime-types package optional #383

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/cozy-stack-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
},
"dependencies": {
"detect-node": "2.0.4",
"mime-types": "2.1.20",
"qs": "6.6.0"
},
"optionalDependencies": {
"mime-types": "2.1.20"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I understand, if we put mime-types in optionalDependencies, yarn&npm will try by default to install it. I don't know if we shouldn't put in peerDependencies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peerDependency allows us to define the version of the dependency outside of the lib. It's aimed a not duplicating modules across different libraries. peerDependencies are required dependencies, they will always be present in the final lib

"scripts": {
"build": "../../bin/build",
"watch": "yarn run build --watch",
Expand Down
3 changes: 2 additions & 1 deletion packages/cozy-stack-client/src/FileCollection.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import mime from 'mime-types'
import has from 'lodash/has'
import DocumentCollection, { normalizeDoc } from './DocumentCollection'
import { uri, slugify, forceFileDownload } from './utils'
import * as querystring from './querystring'
import mime from './mime-types'

const ROOT_DIR_ID = 'io.cozy.files.root-dir'
const CONTENT_TYPE_OCTET_STREAM = 'application/octet-stream'

Expand Down
14 changes: 14 additions & 0 deletions packages/cozy-stack-client/src/mime-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
let mimeTypes
try {
mimeTypes = require('mime-types')
} catch (e) {
mimeTypes = {
lookup: () => {
console.warn(
'Package mime-types is not installed, cannot guess file type. Please add mime-types to your project via npm/yarn if you want this functionality'
)
}
}
}

module.exports = mimeTypes