diff --git a/packages/cozy-stack-client/package.json b/packages/cozy-stack-client/package.json index ea2b796030..d32bd355ae 100644 --- a/packages/cozy-stack-client/package.json +++ b/packages/cozy-stack-client/package.json @@ -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" + }, "scripts": { "build": "../../bin/build", "watch": "yarn run build --watch", diff --git a/packages/cozy-stack-client/src/FileCollection.js b/packages/cozy-stack-client/src/FileCollection.js index a3fd474e26..253fdf64e9 100644 --- a/packages/cozy-stack-client/src/FileCollection.js +++ b/packages/cozy-stack-client/src/FileCollection.js @@ -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' diff --git a/packages/cozy-stack-client/src/mime-types.js b/packages/cozy-stack-client/src/mime-types.js new file mode 100644 index 0000000000..5a4d27c29c --- /dev/null +++ b/packages/cozy-stack-client/src/mime-types.js @@ -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