Skip to content

Commit

Permalink
lib: make the module easier to bundle again
Browse files Browse the repository at this point in the history
Fixes: #121
  • Loading branch information
punkeel authored and mscdex committed Jan 15, 2022
1 parent 761dbcb commit 5e4072c
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lib/index.js
@@ -1,8 +1,5 @@
'use strict';

const { readdirSync } = require('fs');
const { join } = require('path');

const { parseContentType } = require('./utils.js');

function getInstance(cfg) {
Expand Down Expand Up @@ -37,14 +34,12 @@ function getInstance(cfg) {
throw new Error(`Unsupported content type: ${headers['content-type']}`);
}

const TYPES = [];
for (const file of readdirSync(join(__dirname, 'types'))) {
if (/\.js$/i.test(file)) {
const type = require(`./types/${file}`);
if (type && typeof type.detect === 'function')
TYPES.push(type);
}
}
// Note: types are explicitly listed here for easier bundling
// See: https://github.com/mscdex/busboy/issues/121
const TYPES = [
require('./types/multipart'),
require('./types/urlencoded'),
].filter(function(typemod) { return typeof typemod.detect === 'function'; });

module.exports = (cfg) => {
if (typeof cfg !== 'object' || cfg === null)
Expand Down

0 comments on commit 5e4072c

Please sign in to comment.