1 | import { createReplaceBabelHelperByNamedImportsBabelPlugin } from "./replace-babel-helper-by-named-imports-babel-plugin.js"
|
2 | import { createImportMetaUrlNamedImportBabelPlugin } from "./createImportMetaUrlNamedImportBabelPlugin.js"
|
3 | import { jsenvBundlingProjectPathname } from "../jsenv-bundling-project.js"
|
4 |
|
5 | export const generateBabelPluginMapOption = ({
|
6 | format,
|
7 | babelPluginMap,
|
8 | featureNameArray,
|
9 | babelHelpersFacadePath,
|
10 | }) => {
|
11 | return {
|
12 | ...generateBabelPluginMapSubset({
|
13 | babelPluginMap,
|
14 | featureNameArray,
|
15 | }),
|
16 | ...generateBabelPluginMapForBundle({
|
17 | format,
|
18 | babelHelpersFacadePath,
|
19 | }),
|
20 | }
|
21 | }
|
22 |
|
23 | const generateBabelPluginMapSubset = ({ babelPluginMap, featureNameArray }) => {
|
24 | const babelPluginMapSubset = {}
|
25 |
|
26 | Object.keys(babelPluginMap).forEach((babelPluginName) => {
|
27 | if (featureNameArray.includes(babelPluginName)) {
|
28 | babelPluginMapSubset[babelPluginName] = babelPluginMap[babelPluginName]
|
29 | }
|
30 | })
|
31 |
|
32 | return babelPluginMapSubset
|
33 | }
|
34 |
|
35 | const generateBabelPluginMapForBundle = ({ format, babelHelpersFacadePath }) => {
|
36 | const bundleBabelPluginMap = {}
|
37 |
|
38 | const replaceBabelHelperByNamedImportsBabelPlugin = createReplaceBabelHelperByNamedImportsBabelPlugin(
|
39 | {
|
40 | babelHelpersFacadePath,
|
41 | },
|
42 | )
|
43 | bundleBabelPluginMap["replace-babel-helper-by-named-imports"] = [
|
44 | replaceBabelHelperByNamedImportsBabelPlugin,
|
45 | ]
|
46 |
|
47 | if (format === "commonjs" || format === "global") {
|
48 | const importMetaFacadePath = `file://${jsenvBundlingProjectPathname}/src/babel-plugin-map/import-meta-${format}.js`
|
49 |
|
50 | bundleBabelPluginMap[
|
51 | "import-meta-url-named-import"
|
52 | ] = createImportMetaUrlNamedImportBabelPlugin({
|
53 | importMetaFacadePath,
|
54 | })
|
55 | }
|
56 |
|
57 | return bundleBabelPluginMap
|
58 | }
|