UNPKG

1.54 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = normalizeOptions;
7
8function _path() {
9 const data = require("path");
10
11 _path = function () {
12 return data;
13 };
14
15 return data;
16}
17
18function normalizeOptions(config) {
19 const {
20 filename,
21 cwd,
22 filenameRelative = typeof filename === "string" ? _path().relative(cwd, filename) : "unknown",
23 sourceType = "module",
24 inputSourceMap,
25 sourceMaps = !!inputSourceMap,
26 sourceRoot = config.options.moduleRoot,
27 sourceFileName = _path().basename(filenameRelative),
28 comments = true,
29 compact = "auto"
30 } = config.options;
31 const opts = config.options;
32 const options = Object.assign({}, opts, {
33 parserOpts: Object.assign({
34 sourceType: _path().extname(filenameRelative) === ".mjs" ? "module" : sourceType,
35 sourceFileName: filename,
36 plugins: []
37 }, opts.parserOpts),
38 generatorOpts: Object.assign({
39 filename,
40 auxiliaryCommentBefore: opts.auxiliaryCommentBefore,
41 auxiliaryCommentAfter: opts.auxiliaryCommentAfter,
42 retainLines: opts.retainLines,
43 comments,
44 shouldPrintComment: opts.shouldPrintComment,
45 compact,
46 minified: opts.minified,
47 sourceMaps,
48 sourceRoot,
49 sourceFileName
50 }, opts.generatorOpts)
51 });
52
53 for (const plugins of config.passes) {
54 for (const plugin of plugins) {
55 if (plugin.manipulateOptions) {
56 plugin.manipulateOptions(options, options.parserOpts);
57 }
58 }
59 }
60
61 return options;
62}
\No newline at end of file