| 1 |
import path from "path"; |
| 2 |
import type { ResolvedConfig } from "../config"; |
| 3 |
|
| 4 |
export default function normalizeOptions(config: ResolvedConfig): {} { |
| 5 |
const { |
| 6 |
filename, |
| 7 |
cwd, |
| 8 |
filenameRelative = typeof filename === "string" |
| 9 |
? path.relative(cwd, filename) |
| 10 |
: "unknown", |
| 11 |
sourceType = "module", |
| 12 |
inputSourceMap, |
| 13 |
sourceMaps = !!inputSourceMap, |
| 14 |
sourceRoot = process.env.BABEL_8_BREAKING |
| 15 |
? undefined |
| 16 |
: config.options.moduleRoot, |
| 17 |
|
| 18 |
sourceFileName = path.basename(filenameRelative), |
| 19 |
|
| 20 |
comments = true, |
| 21 |
compact = "auto", |
| 22 |
} = config.options; |
| 23 |
|
| 24 |
const opts = config.options; |
| 25 |
|
| 26 |
const options = { |
| 27 |
...opts, |
| 28 |
|
| 29 |
parserOpts: { |
| 30 |
sourceType: |
| 31 |
path.extname(filenameRelative) === ".mjs" ? "module" : sourceType, |
| 32 |
|
| 33 |
sourceFileName: filename, |
| 34 |
plugins: [], |
| 35 |
...opts.parserOpts, |
| 36 |
}, |
| 37 |
|
| 38 |
generatorOpts: { |
| 39 |
// General generator flags. |
| 40 |
filename, |
| 41 |
|
| 42 |
auxiliaryCommentBefore: opts.auxiliaryCommentBefore, |
| 43 |
auxiliaryCommentAfter: opts.auxiliaryCommentAfter, |
| 44 |
retainLines: opts.retainLines, |
| 45 |
comments, |
| 46 |
shouldPrintComment: opts.shouldPrintComment, |
| 47 |
compact, |
| 48 |
minified: opts.minified, |
| 49 |
|
| 50 |
// Source-map generation flags. |
| 51 |
sourceMaps, |
| 52 |
|
| 53 |
sourceRoot, |
| 54 |
sourceFileName, |
| 55 |
...opts.generatorOpts, |
| 56 |
}, |
| 57 |
}; |
| 58 |
|
| 59 |
for (const plugins of config.passes) { |
| 60 |
for (const plugin of plugins) { |
| 61 |
if (plugin.manipulateOptions) { |
| 62 |
plugin.manipulateOptions(options, options.parserOpts); |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
return options; |
| 68 |
} |