1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
'use strict'
const path = require('path')
const cloneDeep = require('lodash.clonedeep')
const collector = require('./lib/collector')
const currentEnv = require('./lib/currentEnv')
const ResolvedConfig = require('./lib/ResolvedConfig')
const Verifier = require('./lib/Verifier')
function createConfig (options) {
if (!options || !options.options || !options.source) {
throw new TypeError("Expected 'options' and 'source' options")
}
if (typeof options.options !== 'object' || Array.isArray(options.options)) {
throw new TypeError("'options' must be an actual object")
}
const source = options.source
const dir = options.dir || path.dirname(source)
const hash = options.hash || null
const json5 = options.json5 !== false
const babelOptions = cloneDeep(options.options)
return new collector.Config(dir, null, hash, json5, babelOptions, source)
}
exports.createConfig = createConfig
exports.currentEnv = currentEnv
function fromConfig (baseConfig, options) {
options = options || {}
return collector.fromConfig(baseConfig, options.cache)
.then(chains => new ResolvedConfig(chains, options.cache))
}
exports.fromConfig = fromConfig
function fromDirectory (dir, options) {
options = options || {}
return collector.fromDirectory(dir, options.cache)
.then(chains => chains && new ResolvedConfig(chains, options.cache))
}
exports.fromDirectory = fromDirectory
function prepareCache () {
return {
dependencyHashes: new Map(),
fileExistence: new Map(),
files: new Map(),
pluginsAndPresets: new Map(),
sourceHashes: new Map()
}
}
exports.prepareCache = prepareCache
function restoreVerifier (buffer) {
return Verifier.fromBuffer(buffer)
}
exports.restoreVerifier = restoreVerifier
|