git ssb

1+

dinoworm ๐Ÿ› / catstack



Tree: 49c6e5459b68f2a30bcecf7727b8c9a99cfe4e79

Files: 49c6e5459b68f2a30bcecf7727b8c9a99cfe4e79 / lib / transformModule.js

847 bytesRaw
1const { keys, assign } = Object
2const Matcher = require('minimatch').Minimatch
3const mapValues = require('modify-values')
4
5module.exports = createModuleTransformer
6
7function createModuleTransformer (types) {
8 // pre-compile type matchers
9 const matchers = mapValues(types, ({ glob }) => {
10 const matcher = Matcher(glob)
11 return filename => matcher.match(filename)
12 })
13
14 return function transformModule (exports, path) {
15 const filename = path.join('/') + '.js'
16 const module = assign({ path }, exports)
17 const transformedModule = keys(types).reduce((sofar, typeName) => {
18 if (sofar !== null) return sofar
19 const { transform } = types[typeName]
20 const match = matchers[typeName]
21 return match(filename)
22 ? transform(module, { filename })
23 : null
24 }, null)
25 return transformedModule
26 }
27}
28

Built with git-ssb-web