@powerlines/plugin-babel 0.12.395 → 0.12.397

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/helpers/ast-utils.cjs +0 -1
  2. package/dist/helpers/ast-utils.mjs +0 -1
  3. package/dist/helpers/ast-utils.mjs.map +1 -1
  4. package/dist/helpers/create-plugin.cjs +1 -1
  5. package/dist/helpers/create-plugin.d.cts +1 -1
  6. package/dist/helpers/create-plugin.d.cts.map +1 -1
  7. package/dist/helpers/create-plugin.d.mts +1 -1
  8. package/dist/helpers/create-plugin.d.mts.map +1 -1
  9. package/dist/helpers/create-plugin.mjs +1 -1
  10. package/dist/helpers/create-plugin.mjs.map +1 -1
  11. package/dist/helpers/filters.cjs +24 -10
  12. package/dist/helpers/filters.d.cts +11 -3
  13. package/dist/helpers/filters.d.cts.map +1 -1
  14. package/dist/helpers/filters.d.mts +11 -3
  15. package/dist/helpers/filters.d.mts.map +1 -1
  16. package/dist/helpers/filters.mjs +23 -10
  17. package/dist/helpers/filters.mjs.map +1 -1
  18. package/dist/helpers/index.cjs +6 -1
  19. package/dist/helpers/index.d.cts +3 -3
  20. package/dist/helpers/index.d.mts +3 -3
  21. package/dist/helpers/index.mjs +3 -3
  22. package/dist/helpers/options.cjs +67 -1
  23. package/dist/helpers/options.d.cts +29 -4
  24. package/dist/helpers/options.d.cts.map +1 -1
  25. package/dist/helpers/options.d.mts +29 -4
  26. package/dist/helpers/options.d.mts.map +1 -1
  27. package/dist/helpers/options.mjs +64 -2
  28. package/dist/helpers/options.mjs.map +1 -1
  29. package/dist/index.cjs +12 -10
  30. package/dist/index.d.cts +4 -4
  31. package/dist/index.d.cts.map +1 -1
  32. package/dist/index.d.mts +4 -4
  33. package/dist/index.d.mts.map +1 -1
  34. package/dist/index.mjs +9 -12
  35. package/dist/index.mjs.map +1 -1
  36. package/dist/types/config.d.cts +29 -15
  37. package/dist/types/config.d.cts.map +1 -1
  38. package/dist/types/config.d.mts +29 -15
  39. package/dist/types/config.d.mts.map +1 -1
  40. package/dist/types/index.d.cts +2 -2
  41. package/dist/types/index.d.mts +2 -2
  42. package/package.json +10 -10
@@ -25,7 +25,6 @@ let generate = _babel_generator.default;
25
25
  if ("default" in generate) generate = generate.default;
26
26
  function generateFromAst(ast, opts) {
27
27
  return generate(ast, opts ? {
28
- importAttributesKeyword: "with",
29
28
  sourceMaps: true,
30
29
  ...opts
31
30
  } : void 0);
@@ -22,7 +22,6 @@ let generate = _generate;
22
22
  if ("default" in generate) generate = generate.default;
23
23
  function generateFromAst(ast, opts) {
24
24
  return generate(ast, opts ? {
25
- importAttributesKeyword: "with",
26
25
  sourceMaps: true,
27
26
  ...opts
28
27
  } : void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"ast-utils.mjs","names":[],"sources":["../../src/helpers/ast-utils.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { GeneratorOptions, GeneratorResult } from \"@babel/generator\";\nimport _generate from \"@babel/generator\";\nimport type { ParseResult, ParserOptions } from \"@babel/parser\";\nimport { parse } from \"@babel/parser\";\nimport type * as t from \"@babel/types\";\n\n/**\n * Parse the given code into an AST.\n *\n * @param code - The code to parse.\n * @param opts - The options for parsing.\n * @returns The parsed AST.\n */\nexport function parseAst(\n code: string,\n opts: ParserOptions = {}\n): ParseResult<t.File> {\n return parse(code, {\n plugins: [\"typescript\"],\n sourceType: \"module\",\n allowImportExportEverywhere: true,\n allowAwaitOutsideFunction: true,\n ...opts\n });\n}\n\nlet generate = _generate;\nif (\"default\" in generate) {\n generate = generate.default as typeof generate;\n}\n\nexport type GenerateFromAstOptions = GeneratorOptions &\n Required<Pick<GeneratorOptions, \"sourceFileName\" | \"filename\">>;\n\nexport function generateFromAst(\n ast: t.Node,\n opts?: GenerateFromAstOptions\n): GeneratorResult {\n return generate(\n ast,\n opts\n ? { importAttributesKeyword: \"with\", sourceMaps: true, ...opts }\n : undefined\n );\n}\n\nexport type { GeneratorResult } from \"@babel/generator\";\n"],"mappings":";;;;;;;;;;;AA+BA,SAAgB,SACd,MACA,OAAsB,EAAE,EACH;AACrB,QAAO,MAAM,MAAM;EACjB,SAAS,CAAC,aAAa;EACvB,YAAY;EACZ,6BAA6B;EAC7B,2BAA2B;EAC3B,GAAG;EACJ,CAAC;;AAGJ,IAAI,WAAW;AACf,IAAI,aAAa,SACf,YAAW,SAAS;AAMtB,SAAgB,gBACd,KACA,MACiB;AACjB,QAAO,SACL,KACA,OACI;EAAE,yBAAyB;EAAQ,YAAY;EAAM,GAAG;EAAM,GAC9D,OACL"}
1
+ {"version":3,"file":"ast-utils.mjs","names":[],"sources":["../../src/helpers/ast-utils.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { GeneratorOptions, GeneratorResult } from \"@babel/generator\";\nimport _generate from \"@babel/generator\";\nimport type { ParseResult, ParserOptions } from \"@babel/parser\";\nimport { parse } from \"@babel/parser\";\nimport type * as t from \"@babel/types\";\n\n/**\n * Parse the given code into an AST.\n *\n * @param code - The code to parse.\n * @param opts - The options for parsing.\n * @returns The parsed AST.\n */\nexport function parseAst(\n code: string,\n opts: ParserOptions = {}\n): ParseResult<t.File> {\n return parse(code, {\n plugins: [\"typescript\"],\n sourceType: \"module\",\n allowImportExportEverywhere: true,\n allowAwaitOutsideFunction: true,\n ...opts\n });\n}\n\nlet generate = _generate;\nif (\"default\" in generate) {\n generate = generate.default as typeof generate;\n}\n\nexport type GenerateFromAstOptions = GeneratorOptions &\n Required<Pick<GeneratorOptions, \"sourceFileName\" | \"filename\">>;\n\nexport function generateFromAst(\n ast: t.Node,\n opts?: GenerateFromAstOptions\n): GeneratorResult {\n return generate(ast, opts ? { sourceMaps: true, ...opts } : undefined);\n}\n\nexport type { GeneratorResult } from \"@babel/generator\";\n"],"mappings":";;;;;;;;;;;AA+BA,SAAgB,SACd,MACA,OAAsB,EAAE,EACH;AACrB,QAAO,MAAM,MAAM;EACjB,SAAS,CAAC,aAAa;EACvB,YAAY;EACZ,6BAA6B;EAC7B,2BAA2B;EAC3B,GAAG;EACJ,CAAC;;AAGJ,IAAI,WAAW;AACf,IAAI,aAAa,SACf,YAAW,SAAS;AAMtB,SAAgB,gBACd,KACA,MACiB;AACjB,QAAO,SAAS,KAAK,OAAO;EAAE,YAAY;EAAM,GAAG;EAAM,GAAG,OAAU"}
@@ -18,7 +18,7 @@ function createBabelPlugin(name, builder) {
18
18
  const plugin = (context) => {
19
19
  return (0, _babel_helper_plugin_utils.declare)((api, options, dirname) => {
20
20
  api.cache.using(() => context.meta.checksum);
21
- api.assertVersion("^7.0.0-0");
21
+ api.assertVersion("^8.0.0-0");
22
22
  const log = (0, _powerlines_core_lib_logger.extendLog)(context.log, name);
23
23
  log(_storm_software_config_tools_types.LogLevelLabel.TRACE, `Initializing the ${chalk.default.bold.cyanBright(name)} Babel plugin`);
24
24
  const result = builder({
@@ -9,7 +9,7 @@ import { Context } from "@powerlines/core";
9
9
  * @param builder - The builder function that defines the plugin behavior.
10
10
  * @returns A Babel plugin declaration.
11
11
  */
12
- declare function createBabelPlugin<TContext extends Context = Context, TOptions extends Record<string, any> = Record<string, any>>(name: string, builder: BabelTransformPluginBuilder<TContext, TOptions>): DeclareBabelTransformPluginReturn<TContext, TOptions>;
12
+ declare function createBabelPlugin<TContext extends Context = Context, TOptions extends object = object>(name: string, builder: BabelTransformPluginBuilder<TContext, TOptions>): DeclareBabelTransformPluginReturn<TContext, TOptions>;
13
13
  //#endregion
14
14
  export { createBabelPlugin };
15
15
  //# sourceMappingURL=create-plugin.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-plugin.d.cts","names":[],"sources":["../../src/helpers/create-plugin.ts"],"mappings":";;;;;;AAmCA;;;;;iBAAgB,iBAAA,kBACG,OAAA,GAAU,OAAA,mBACV,MAAA,gBAAsB,MAAA,cAAA,CAEvC,IAAA,UACA,OAAA,EAAS,2BAAA,CAA4B,QAAA,EAAU,QAAA,IAC9C,iCAAA,CAAkC,QAAA,EAAU,QAAA"}
1
+ {"version":3,"file":"create-plugin.d.cts","names":[],"sources":["../../src/helpers/create-plugin.ts"],"mappings":";;;;;;AAmCA;;;;;iBAAgB,iBAAA,kBACG,OAAA,GAAU,OAAA,mCAAA,CAG3B,IAAA,UACA,OAAA,EAAS,2BAAA,CAA4B,QAAA,EAAU,QAAA,IAC9C,iCAAA,CAAkC,QAAA,EAAU,QAAA"}
@@ -9,7 +9,7 @@ import { Context } from "@powerlines/core";
9
9
  * @param builder - The builder function that defines the plugin behavior.
10
10
  * @returns A Babel plugin declaration.
11
11
  */
12
- declare function createBabelPlugin<TContext extends Context = Context, TOptions extends Record<string, any> = Record<string, any>>(name: string, builder: BabelTransformPluginBuilder<TContext, TOptions>): DeclareBabelTransformPluginReturn<TContext, TOptions>;
12
+ declare function createBabelPlugin<TContext extends Context = Context, TOptions extends object = object>(name: string, builder: BabelTransformPluginBuilder<TContext, TOptions>): DeclareBabelTransformPluginReturn<TContext, TOptions>;
13
13
  //#endregion
14
14
  export { createBabelPlugin };
15
15
  //# sourceMappingURL=create-plugin.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-plugin.d.mts","names":[],"sources":["../../src/helpers/create-plugin.ts"],"mappings":";;;;;;AAmCA;;;;;iBAAgB,iBAAA,kBACG,OAAA,GAAU,OAAA,mBACV,MAAA,gBAAsB,MAAA,cAAA,CAEvC,IAAA,UACA,OAAA,EAAS,2BAAA,CAA4B,QAAA,EAAU,QAAA,IAC9C,iCAAA,CAAkC,QAAA,EAAU,QAAA"}
1
+ {"version":3,"file":"create-plugin.d.mts","names":[],"sources":["../../src/helpers/create-plugin.ts"],"mappings":";;;;;;AAmCA;;;;;iBAAgB,iBAAA,kBACG,OAAA,GAAU,OAAA,mCAAA,CAG3B,IAAA,UACA,OAAA,EAAS,2BAAA,CAA4B,QAAA,EAAU,QAAA,IAC9C,iCAAA,CAAkC,QAAA,EAAU,QAAA"}
@@ -15,7 +15,7 @@ function createBabelPlugin(name, builder) {
15
15
  const plugin = (context) => {
16
16
  return declare((api, options, dirname) => {
17
17
  api.cache.using(() => context.meta.checksum);
18
- api.assertVersion("^7.0.0-0");
18
+ api.assertVersion("^8.0.0-0");
19
19
  const log = extendLog(context.log, name);
20
20
  log(LogLevelLabel.TRACE, `Initializing the ${chalk.bold.cyanBright(name)} Babel plugin`);
21
21
  const result = builder({
@@ -1 +1 @@
1
- {"version":3,"file":"create-plugin.mjs","names":[],"sources":["../../src/helpers/create-plugin.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { declare } from \"@babel/helper-plugin-utils\";\nimport { Context } from \"@powerlines/core\";\nimport { extendLog } from \"@powerlines/core/lib/logger\";\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport chalk from \"chalk\";\nimport {\n BabelTransformPluginBuilder,\n DeclareBabelTransformPluginReturn\n} from \"../types/config\";\n\n/**\n * Create a Babel plugin using the provided builder function.\n *\n * @param name - The name of the plugin.\n * @param builder - The builder function that defines the plugin behavior.\n * @returns A Babel plugin declaration.\n */\nexport function createBabelPlugin<\n TContext extends Context = Context,\n TOptions extends Record<string, any> = Record<string, any>\n>(\n name: string,\n builder: BabelTransformPluginBuilder<TContext, TOptions>\n): DeclareBabelTransformPluginReturn<TContext, TOptions> {\n const plugin = (context: TContext) => {\n return declare<TOptions>((api, options, dirname) => {\n api.cache.using(() => context.meta.checksum);\n api.assertVersion(\"^7.0.0-0\");\n\n const log = extendLog(context.log, name);\n log(\n LogLevelLabel.TRACE,\n `Initializing the ${chalk.bold.cyanBright(name)} Babel plugin`\n );\n\n const result = builder({\n log,\n name,\n api,\n options,\n context,\n dirname\n });\n result.name = name;\n\n log(\n LogLevelLabel.TRACE,\n `Completed initialization of the ${chalk.bold.cyanBright(name)} Babel plugin`\n );\n\n return result;\n });\n };\n plugin.$$name = name;\n\n return plugin;\n}\n"],"mappings":";;;;;;;;;;;;;AAmCA,SAAgB,kBAId,MACA,SACuD;CACvD,MAAM,UAAU,YAAsB;AACpC,SAAO,SAAmB,KAAK,SAAS,YAAY;AAClD,OAAI,MAAM,YAAY,QAAQ,KAAK,SAAS;AAC5C,OAAI,cAAc,WAAW;GAE7B,MAAM,MAAM,UAAU,QAAQ,KAAK,KAAK;AACxC,OACE,cAAc,OACd,oBAAoB,MAAM,KAAK,WAAW,KAAK,CAAC,eACjD;GAED,MAAM,SAAS,QAAQ;IACrB;IACA;IACA;IACA;IACA;IACA;IACD,CAAC;AACF,UAAO,OAAO;AAEd,OACE,cAAc,OACd,mCAAmC,MAAM,KAAK,WAAW,KAAK,CAAC,eAChE;AAED,UAAO;IACP;;AAEJ,QAAO,SAAS;AAEhB,QAAO"}
1
+ {"version":3,"file":"create-plugin.mjs","names":[],"sources":["../../src/helpers/create-plugin.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { declare } from \"@babel/helper-plugin-utils\";\nimport type { Context } from \"@powerlines/core\";\nimport { extendLog } from \"@powerlines/core/lib/logger\";\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport chalk from \"chalk\";\nimport type {\n BabelTransformPluginBuilder,\n DeclareBabelTransformPluginReturn\n} from \"../types/config\";\n\n/**\n * Create a Babel plugin using the provided builder function.\n *\n * @param name - The name of the plugin.\n * @param builder - The builder function that defines the plugin behavior.\n * @returns A Babel plugin declaration.\n */\nexport function createBabelPlugin<\n TContext extends Context = Context,\n TOptions extends object = object\n>(\n name: string,\n builder: BabelTransformPluginBuilder<TContext, TOptions>\n): DeclareBabelTransformPluginReturn<TContext, TOptions> {\n const plugin = (context: TContext) => {\n return declare<TOptions>((api, options, dirname) => {\n api.cache.using(() => context.meta.checksum);\n api.assertVersion(\"^8.0.0-0\");\n\n const log = extendLog(context.log, name);\n log(\n LogLevelLabel.TRACE,\n `Initializing the ${chalk.bold.cyanBright(name)} Babel plugin`\n );\n\n const result = builder({\n log,\n name,\n api,\n options: options as TOptions,\n context,\n dirname\n });\n result.name = name;\n\n log(\n LogLevelLabel.TRACE,\n `Completed initialization of the ${chalk.bold.cyanBright(name)} Babel plugin`\n );\n\n return result;\n });\n };\n plugin.$$name = name;\n\n return plugin;\n}\n"],"mappings":";;;;;;;;;;;;;AAmCA,SAAgB,kBAId,MACA,SACuD;CACvD,MAAM,UAAU,YAAsB;AACpC,SAAO,SAAmB,KAAK,SAAS,YAAY;AAClD,OAAI,MAAM,YAAY,QAAQ,KAAK,SAAS;AAC5C,OAAI,cAAc,WAAW;GAE7B,MAAM,MAAM,UAAU,QAAQ,KAAK,KAAK;AACxC,OACE,cAAc,OACd,oBAAoB,MAAM,KAAK,WAAW,KAAK,CAAC,eACjD;GAED,MAAM,SAAS,QAAQ;IACrB;IACA;IACA;IACS;IACT;IACA;IACD,CAAC;AACF,UAAO,OAAO;AAEd,OACE,cAAc,OACd,mCAAmC,MAAM,KAAK,WAAW,KAAK,CAAC,eAChE;AAED,UAAO;IACP;;AAEJ,QAAO,SAAS;AAEhB,QAAO"}
@@ -19,6 +19,16 @@ function isDuplicatePlugin(plugins, plugin) {
19
19
  return !!(getPluginName(plugin) && plugins.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(plugin)));
20
20
  }
21
21
  /**
22
+ * Check if a Babel preset is a duplicate of another preset in the list.
23
+ *
24
+ * @param presets - The list of existing Babel presets.
25
+ * @param preset - The Babel preset to check for duplicates.
26
+ * @returns True if the preset is a duplicate, false otherwise.
27
+ */
28
+ function isDuplicatePreset(presets, preset) {
29
+ return !!(getPluginName(preset) && presets.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(preset)));
30
+ }
31
+ /**
22
32
  * Filters a Babel plugin by its runtime ID.
23
33
  *
24
34
  * @param context - The context in which the filter is applied.
@@ -38,15 +48,18 @@ function filterPluginByFileId(context, fileId) {
38
48
  * @returns The updated list of Babel plugins with the filter applied.
39
49
  */
40
50
  function addPluginFilter(context, pluginOrPlugins, filter, name) {
41
- if (!Array.isArray(pluginOrPlugins) || !pluginOrPlugins.some((plugin) => Array.isArray(plugin)) && pluginOrPlugins.length < 4 && pluginOrPlugins.length > 0 && ((0, _stryke_type_checks_is_set_string.isSetString)(pluginOrPlugins[0]) || (0, _stryke_type_checks_is_function.isFunction)(pluginOrPlugins[0]) || pluginOrPlugins.length > 1 && (0, _stryke_type_checks_is_object.isObject)(pluginOrPlugins[1]) || pluginOrPlugins.length > 2 && (0, _stryke_type_checks_is_object.isObject)(pluginOrPlugins[2]))) return Array.isArray(pluginOrPlugins) ? [
42
- pluginOrPlugins[0],
43
- pluginOrPlugins.length > 1 ? pluginOrPlugins[1] : {},
44
- { filter: (code, id) => filter(code, id) && (pluginOrPlugins.length < 2 || !(0, _stryke_type_checks_is_function.isFunction)(pluginOrPlugins[2]) || pluginOrPlugins[2]?.(code, id)) }
45
- ] : [
46
- pluginOrPlugins,
47
- {},
48
- { filter }
49
- ];
51
+ if (!Array.isArray(pluginOrPlugins) || !pluginOrPlugins.some((plugin) => Array.isArray(plugin)) && pluginOrPlugins.length < 4 && pluginOrPlugins.length > 0 && ((0, _stryke_type_checks_is_set_string.isSetString)(pluginOrPlugins[0]) || (0, _stryke_type_checks_is_function.isFunction)(pluginOrPlugins[0]) || pluginOrPlugins.length > 1 && (0, _stryke_type_checks_is_object.isObject)(pluginOrPlugins[1]) || pluginOrPlugins.length > 2 && (0, _stryke_type_checks_is_object.isObject)(pluginOrPlugins[2]))) {
52
+ if (Array.isArray(pluginOrPlugins)) return [
53
+ pluginOrPlugins[0],
54
+ pluginOrPlugins.length > 1 ? pluginOrPlugins[1] : {},
55
+ { filter: (code, id) => filter(code, id) && (pluginOrPlugins.length < 3 || !(0, _stryke_type_checks_is_function.isFunction)(pluginOrPlugins[2]) || pluginOrPlugins[2]?.(code, id)) }
56
+ ];
57
+ return [
58
+ pluginOrPlugins,
59
+ {},
60
+ { filter }
61
+ ];
62
+ }
50
63
  if (!name) throw new Error("No name was provided to `addPluginFilter`, could not find babel plugin without it.");
51
64
  const foundIndex = pluginOrPlugins.findIndex((plugin) => getPluginName(plugin)?.toLowerCase() === name.toLowerCase());
52
65
  if (foundIndex > -1) pluginOrPlugins[foundIndex] = addPluginFilter(context, pluginOrPlugins[foundIndex], filter, name);
@@ -57,4 +70,5 @@ function addPluginFilter(context, pluginOrPlugins, filter, name) {
57
70
  exports.addPluginFilter = addPluginFilter;
58
71
  exports.filterPluginByFileId = filterPluginByFileId;
59
72
  exports.getPluginName = getPluginName;
60
- exports.isDuplicatePlugin = isDuplicatePlugin;
73
+ exports.isDuplicatePlugin = isDuplicatePlugin;
74
+ exports.isDuplicatePreset = isDuplicatePreset;
@@ -1,4 +1,4 @@
1
- import { BabelTransformPlugin, BabelTransformPluginFilter, BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions } from "../types/config.cjs";
1
+ import { BabelTransformPlugin, BabelTransformPluginFilter, BabelTransformPluginOptions, BabelTransformPresetOptions, ResolvedBabelTransformPluginOptions, ResolvedBabelTransformPresetOptions } from "../types/config.cjs";
2
2
  import { Context } from "@powerlines/core";
3
3
 
4
4
  //#region src/helpers/filters.d.ts
@@ -10,7 +10,15 @@ declare function getPluginName(plugin?: BabelTransformPluginOptions | string | f
10
10
  * @param plugin - The Babel plugin to check for duplicates.
11
11
  * @returns True if the plugin is a duplicate, false otherwise.
12
12
  */
13
- declare function isDuplicatePlugin(plugins: (ResolvedBabelTransformPluginOptions | undefined)[], plugin: BabelTransformPluginOptions): boolean;
13
+ declare function isDuplicatePlugin<T extends BabelTransformPluginOptions | ResolvedBabelTransformPluginOptions>(plugins: T[], plugin: T): boolean;
14
+ /**
15
+ * Check if a Babel preset is a duplicate of another preset in the list.
16
+ *
17
+ * @param presets - The list of existing Babel presets.
18
+ * @param preset - The Babel preset to check for duplicates.
19
+ * @returns True if the preset is a duplicate, false otherwise.
20
+ */
21
+ declare function isDuplicatePreset<T extends BabelTransformPresetOptions | ResolvedBabelTransformPresetOptions>(presets: T[], preset: T): boolean;
14
22
  /**
15
23
  * Filters a Babel plugin by its runtime ID.
16
24
  *
@@ -39,5 +47,5 @@ declare function addPluginFilter(context: Context, plugins: BabelTransformPlugin
39
47
  */
40
48
  declare function addPluginFilter(context: Context, plugin: BabelTransformPlugin | BabelTransformPluginOptions, filter: NonNullable<BabelTransformPluginFilter>): BabelTransformPluginOptions;
41
49
  //#endregion
42
- export { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin };
50
+ export { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin, isDuplicatePreset };
43
51
  //# sourceMappingURL=filters.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filters.d.cts","names":[],"sources":["../../src/helpers/filters.ts"],"mappings":";;;;iBA6BgB,aAAA,CACd,MAAA,GACI,2BAAA,kCAIK,IAAA;;AANX;;;;;;iBA2BgB,iBAAA,CACd,OAAA,GAAU,mCAAA,iBACV,MAAA,EAAQ,2BAAA;;;AAFV;;;;;iBAqBgB,oBAAA,kBAAsC,OAAA,GAAU,OAAA,CAAA,CAC9D,OAAA,EAAS,QAAA,EACT,MAAA,WACC,0BAAA;;;;;AAHH;;;;;iBAuBgB,eAAA,CACd,OAAA,EAAS,OAAA,EACT,OAAA,EAAS,2BAAA,IACT,MAAA,EAAQ,0BAAA,qBACR,IAAA,WACC,2BAAA;;;;;;;;;iBAUa,eAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,EAAQ,oBAAA,GAAuB,2BAAA,EAC/B,MAAA,EAAQ,WAAA,CAAY,0BAAA,IACnB,2BAAA"}
1
+ {"version":3,"file":"filters.d.cts","names":[],"sources":["../../src/helpers/filters.ts"],"mappings":";;;;iBA+BgB,aAAA,CACd,MAAA,GACI,2BAAA,kCAIK,IAAA;;AANX;;;;;;iBA2BgB,iBAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,IAAK,MAAA,EAAQ,CAAA;;;AAFxB;;;;;iBAoBgB,iBAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,IAAK,MAAA,EAAQ,CAAA;;;;;;;;iBAkBR,oBAAA,kBAAsC,OAAA,GAAU,OAAA,CAAA,CAC9D,OAAA,EAAS,QAAA,EACT,MAAA,WACC,0BAAA;;;;;AAvBH;;;;;iBA2CgB,eAAA,CACd,OAAA,EAAS,OAAA,EACT,OAAA,EAAS,2BAAA,IACT,MAAA,EAAQ,0BAAA,qBACR,IAAA,WACC,2BAAA;;;;;;;;;iBAUa,eAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,EAAQ,oBAAA,GAAuB,2BAAA,EAC/B,MAAA,EAAQ,WAAA,CAAY,0BAAA,IACnB,2BAAA"}
@@ -1,4 +1,4 @@
1
- import { BabelTransformPlugin, BabelTransformPluginFilter, BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions } from "../types/config.mjs";
1
+ import { BabelTransformPlugin, BabelTransformPluginFilter, BabelTransformPluginOptions, BabelTransformPresetOptions, ResolvedBabelTransformPluginOptions, ResolvedBabelTransformPresetOptions } from "../types/config.mjs";
2
2
  import { Context } from "@powerlines/core";
3
3
 
4
4
  //#region src/helpers/filters.d.ts
@@ -10,7 +10,15 @@ declare function getPluginName(plugin?: BabelTransformPluginOptions | string | f
10
10
  * @param plugin - The Babel plugin to check for duplicates.
11
11
  * @returns True if the plugin is a duplicate, false otherwise.
12
12
  */
13
- declare function isDuplicatePlugin(plugins: (ResolvedBabelTransformPluginOptions | undefined)[], plugin: BabelTransformPluginOptions): boolean;
13
+ declare function isDuplicatePlugin<T extends BabelTransformPluginOptions | ResolvedBabelTransformPluginOptions>(plugins: T[], plugin: T): boolean;
14
+ /**
15
+ * Check if a Babel preset is a duplicate of another preset in the list.
16
+ *
17
+ * @param presets - The list of existing Babel presets.
18
+ * @param preset - The Babel preset to check for duplicates.
19
+ * @returns True if the preset is a duplicate, false otherwise.
20
+ */
21
+ declare function isDuplicatePreset<T extends BabelTransformPresetOptions | ResolvedBabelTransformPresetOptions>(presets: T[], preset: T): boolean;
14
22
  /**
15
23
  * Filters a Babel plugin by its runtime ID.
16
24
  *
@@ -39,5 +47,5 @@ declare function addPluginFilter(context: Context, plugins: BabelTransformPlugin
39
47
  */
40
48
  declare function addPluginFilter(context: Context, plugin: BabelTransformPlugin | BabelTransformPluginOptions, filter: NonNullable<BabelTransformPluginFilter>): BabelTransformPluginOptions;
41
49
  //#endregion
42
- export { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin };
50
+ export { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin, isDuplicatePreset };
43
51
  //# sourceMappingURL=filters.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"filters.d.mts","names":[],"sources":["../../src/helpers/filters.ts"],"mappings":";;;;iBA6BgB,aAAA,CACd,MAAA,GACI,2BAAA,kCAIK,IAAA;;AANX;;;;;;iBA2BgB,iBAAA,CACd,OAAA,GAAU,mCAAA,iBACV,MAAA,EAAQ,2BAAA;;;AAFV;;;;;iBAqBgB,oBAAA,kBAAsC,OAAA,GAAU,OAAA,CAAA,CAC9D,OAAA,EAAS,QAAA,EACT,MAAA,WACC,0BAAA;;;;;AAHH;;;;;iBAuBgB,eAAA,CACd,OAAA,EAAS,OAAA,EACT,OAAA,EAAS,2BAAA,IACT,MAAA,EAAQ,0BAAA,qBACR,IAAA,WACC,2BAAA;;;;;;;;;iBAUa,eAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,EAAQ,oBAAA,GAAuB,2BAAA,EAC/B,MAAA,EAAQ,WAAA,CAAY,0BAAA,IACnB,2BAAA"}
1
+ {"version":3,"file":"filters.d.mts","names":[],"sources":["../../src/helpers/filters.ts"],"mappings":";;;;iBA+BgB,aAAA,CACd,MAAA,GACI,2BAAA,kCAIK,IAAA;;AANX;;;;;;iBA2BgB,iBAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,IAAK,MAAA,EAAQ,CAAA;;;AAFxB;;;;;iBAoBgB,iBAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,IAAK,MAAA,EAAQ,CAAA;;;;;;;;iBAkBR,oBAAA,kBAAsC,OAAA,GAAU,OAAA,CAAA,CAC9D,OAAA,EAAS,QAAA,EACT,MAAA,WACC,0BAAA;;;;;AAvBH;;;;;iBA2CgB,eAAA,CACd,OAAA,EAAS,OAAA,EACT,OAAA,EAAS,2BAAA,IACT,MAAA,EAAQ,0BAAA,qBACR,IAAA,WACC,2BAAA;;;;;;;;;iBAUa,eAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,EAAQ,oBAAA,GAAuB,2BAAA,EAC/B,MAAA,EAAQ,WAAA,CAAY,0BAAA,IACnB,2BAAA"}
@@ -17,6 +17,16 @@ function isDuplicatePlugin(plugins, plugin) {
17
17
  return !!(getPluginName(plugin) && plugins.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(plugin)));
18
18
  }
19
19
  /**
20
+ * Check if a Babel preset is a duplicate of another preset in the list.
21
+ *
22
+ * @param presets - The list of existing Babel presets.
23
+ * @param preset - The Babel preset to check for duplicates.
24
+ * @returns True if the preset is a duplicate, false otherwise.
25
+ */
26
+ function isDuplicatePreset(presets, preset) {
27
+ return !!(getPluginName(preset) && presets.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(preset)));
28
+ }
29
+ /**
20
30
  * Filters a Babel plugin by its runtime ID.
21
31
  *
22
32
  * @param context - The context in which the filter is applied.
@@ -36,15 +46,18 @@ function filterPluginByFileId(context, fileId) {
36
46
  * @returns The updated list of Babel plugins with the filter applied.
37
47
  */
38
48
  function addPluginFilter(context, pluginOrPlugins, filter, name) {
39
- if (!Array.isArray(pluginOrPlugins) || !pluginOrPlugins.some((plugin) => Array.isArray(plugin)) && pluginOrPlugins.length < 4 && pluginOrPlugins.length > 0 && (isSetString(pluginOrPlugins[0]) || isFunction(pluginOrPlugins[0]) || pluginOrPlugins.length > 1 && isObject(pluginOrPlugins[1]) || pluginOrPlugins.length > 2 && isObject(pluginOrPlugins[2]))) return Array.isArray(pluginOrPlugins) ? [
40
- pluginOrPlugins[0],
41
- pluginOrPlugins.length > 1 ? pluginOrPlugins[1] : {},
42
- { filter: (code, id) => filter(code, id) && (pluginOrPlugins.length < 2 || !isFunction(pluginOrPlugins[2]) || pluginOrPlugins[2]?.(code, id)) }
43
- ] : [
44
- pluginOrPlugins,
45
- {},
46
- { filter }
47
- ];
49
+ if (!Array.isArray(pluginOrPlugins) || !pluginOrPlugins.some((plugin) => Array.isArray(plugin)) && pluginOrPlugins.length < 4 && pluginOrPlugins.length > 0 && (isSetString(pluginOrPlugins[0]) || isFunction(pluginOrPlugins[0]) || pluginOrPlugins.length > 1 && isObject(pluginOrPlugins[1]) || pluginOrPlugins.length > 2 && isObject(pluginOrPlugins[2]))) {
50
+ if (Array.isArray(pluginOrPlugins)) return [
51
+ pluginOrPlugins[0],
52
+ pluginOrPlugins.length > 1 ? pluginOrPlugins[1] : {},
53
+ { filter: (code, id) => filter(code, id) && (pluginOrPlugins.length < 3 || !isFunction(pluginOrPlugins[2]) || pluginOrPlugins[2]?.(code, id)) }
54
+ ];
55
+ return [
56
+ pluginOrPlugins,
57
+ {},
58
+ { filter }
59
+ ];
60
+ }
48
61
  if (!name) throw new Error("No name was provided to `addPluginFilter`, could not find babel plugin without it.");
49
62
  const foundIndex = pluginOrPlugins.findIndex((plugin) => getPluginName(plugin)?.toLowerCase() === name.toLowerCase());
50
63
  if (foundIndex > -1) pluginOrPlugins[foundIndex] = addPluginFilter(context, pluginOrPlugins[foundIndex], filter, name);
@@ -52,5 +65,5 @@ function addPluginFilter(context, pluginOrPlugins, filter, name) {
52
65
  }
53
66
 
54
67
  //#endregion
55
- export { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin };
68
+ export { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin, isDuplicatePreset };
56
69
  //# sourceMappingURL=filters.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"filters.mjs","names":[],"sources":["../../src/helpers/filters.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { Context } from \"@powerlines/core\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport {\n BabelTransformPlugin,\n BabelTransformPluginFilter,\n BabelTransformPluginOptions,\n ResolvedBabelTransformPluginOptions\n} from \"../types/config\";\n\nexport function getPluginName(\n plugin?:\n | BabelTransformPluginOptions\n | string\n | false\n | object\n | ((...args: any[]) => any)\n | undefined\n): string | undefined {\n return isSetString(plugin)\n ? plugin\n : Array.isArray(plugin) && plugin.length > 0\n ? getPluginName(plugin[0])\n : (plugin as BabelTransformPlugin).$$name ||\n (plugin as BabelTransformPlugin).name\n ? (plugin as BabelTransformPlugin).$$name ||\n (plugin as BabelTransformPlugin).name\n : undefined;\n}\n\n/**\n * Check if a Babel plugin is a duplicate of another plugin in the list.\n *\n * @param plugins - The list of existing Babel plugins.\n * @param plugin - The Babel plugin to check for duplicates.\n * @returns True if the plugin is a duplicate, false otherwise.\n */\nexport function isDuplicatePlugin(\n plugins: (ResolvedBabelTransformPluginOptions | undefined)[],\n plugin: BabelTransformPluginOptions\n): boolean {\n return !!(\n getPluginName(plugin) &&\n plugins.some(\n existing =>\n Array.isArray(existing) &&\n getPluginName(existing[0]) === getPluginName(plugin)\n )\n );\n}\n\n/**\n * Filters a Babel plugin by its runtime ID.\n *\n * @param context - The context in which the filter is applied.\n * @param fileId - The file ID to filter by.\n * @returns A filter function that checks if a plugin's ID matches the runtime ID.\n */\nexport function filterPluginByFileId<TContext extends Context = Context>(\n context: TContext,\n fileId: string\n): BabelTransformPluginFilter {\n return (code: string, id: string): boolean =>\n fileId !== id &&\n context.fs.ids[fileId] !== id &&\n fileId !== context.fs.ids[id] &&\n context.fs.ids[fileId] !== context.fs.ids[id] &&\n context.fs.paths[fileId] !== id &&\n fileId !== context.fs.paths[id] &&\n context.fs.paths[fileId] !== context.fs.paths[id];\n}\n\n/**\n * Adds a filter to a Babel plugin or a list of Babel plugins.\n *\n * @param context - The context in which the plugin is being added.\n * @param plugins - The Babel plugins to add the filter to.\n * @param filter - The filter function to apply to the plugins.\n * @param name - The name of the plugin to add the filter to.\n * @returns The updated list of Babel plugins with the filter applied.\n */\nexport function addPluginFilter(\n context: Context,\n plugins: BabelTransformPluginOptions[],\n filter: BabelTransformPluginFilter | null | undefined,\n name: string\n): BabelTransformPluginOptions[];\n\n/**\n * Adds a filter to a Babel plugin or a list of Babel plugins.\n *\n * @param context - The context in which the plugin is being added.\n * @param plugin - The Babel plugin to add the filter to.\n * @param filter - The filter function to apply to the plugin.\n * @returns The updated Babel plugin with the filter applied.\n */\nexport function addPluginFilter(\n context: Context,\n plugin: BabelTransformPlugin | BabelTransformPluginOptions,\n filter: NonNullable<BabelTransformPluginFilter>\n): BabelTransformPluginOptions;\n\n/**\n * Adds a filter to a Babel plugin or a list of Babel plugins.\n *\n * @param context - The context in which the plugin is being added.\n * @param pluginOrPlugins - The Babel plugin or plugins to add the filter to.\n * @param filter - The filter function to apply to the plugins.\n * @param name - The name of the plugin to add the filter to.\n * @returns The updated list of Babel plugins with the filter applied.\n */\nexport function addPluginFilter<\n T extends\n | BabelTransformPlugin\n | BabelTransformPluginOptions\n | BabelTransformPluginOptions[]\n>(\n context: Context,\n pluginOrPlugins: T,\n filter: NonNullable<BabelTransformPluginFilter>,\n name?: string\n): T extends BabelTransformPluginOptions[]\n ? BabelTransformPluginOptions[]\n : BabelTransformPluginOptions {\n if (\n !Array.isArray(pluginOrPlugins) ||\n (!pluginOrPlugins.some(plugin => Array.isArray(plugin)) &&\n pluginOrPlugins.length < 4 &&\n pluginOrPlugins.length > 0 &&\n (isSetString(pluginOrPlugins[0]) ||\n isFunction(pluginOrPlugins[0]) ||\n (pluginOrPlugins.length > 1 && isObject(pluginOrPlugins[1])) ||\n (pluginOrPlugins.length > 2 && isObject(pluginOrPlugins[2]))))\n ) {\n return Array.isArray(pluginOrPlugins)\n ? [\n pluginOrPlugins[0],\n pluginOrPlugins.length > 1 ? pluginOrPlugins[1] : {},\n {\n filter: (code, id) =>\n filter(code, id) &&\n (pluginOrPlugins.length < 2 ||\n !isFunction(pluginOrPlugins[2]) ||\n pluginOrPlugins[2]?.(code, id))\n }\n ]\n : [\n pluginOrPlugins,\n {},\n {\n filter\n }\n ];\n }\n\n if (!name) {\n throw new Error(\n \"No name was provided to \\`addPluginFilter\\`, could not find babel plugin without it.\"\n );\n }\n\n const foundIndex = pluginOrPlugins.findIndex(\n plugin => getPluginName(plugin)?.toLowerCase() === name.toLowerCase()\n );\n if (foundIndex > -1) {\n pluginOrPlugins[foundIndex] = addPluginFilter(\n context,\n pluginOrPlugins[foundIndex],\n filter,\n name\n );\n }\n\n return pluginOrPlugins;\n}\n"],"mappings":";;;;;AA6BA,SAAgB,cACd,QAOoB;AACpB,QAAO,YAAY,OAAO,GACtB,SACA,MAAM,QAAQ,OAAO,IAAI,OAAO,SAAS,IACvC,cAAc,OAAO,GAAG,GACvB,OAAgC,UAC9B,OAAgC,OAChC,OAAgC,UAChC,OAAgC,OACjC;;;;;;;;;AAUV,SAAgB,kBACd,SACA,QACS;AACT,QAAO,CAAC,EACN,cAAc,OAAO,IACrB,QAAQ,MACN,aACE,MAAM,QAAQ,SAAS,IACvB,cAAc,SAAS,GAAG,KAAK,cAAc,OAAO,CACvD;;;;;;;;;AAWL,SAAgB,qBACd,SACA,QAC4B;AAC5B,SAAQ,MAAc,OACpB,WAAW,MACX,QAAQ,GAAG,IAAI,YAAY,MAC3B,WAAW,QAAQ,GAAG,IAAI,OAC1B,QAAQ,GAAG,IAAI,YAAY,QAAQ,GAAG,IAAI,OAC1C,QAAQ,GAAG,MAAM,YAAY,MAC7B,WAAW,QAAQ,GAAG,MAAM,OAC5B,QAAQ,GAAG,MAAM,YAAY,QAAQ,GAAG,MAAM;;;;;;;;;;;AA0ClD,SAAgB,gBAMd,SACA,iBACA,QACA,MAG8B;AAC9B,KACE,CAAC,MAAM,QAAQ,gBAAgB,IAC9B,CAAC,gBAAgB,MAAK,WAAU,MAAM,QAAQ,OAAO,CAAC,IACrD,gBAAgB,SAAS,KACzB,gBAAgB,SAAS,MACxB,YAAY,gBAAgB,GAAG,IAC9B,WAAW,gBAAgB,GAAG,IAC7B,gBAAgB,SAAS,KAAK,SAAS,gBAAgB,GAAG,IAC1D,gBAAgB,SAAS,KAAK,SAAS,gBAAgB,GAAG,EAE/D,QAAO,MAAM,QAAQ,gBAAgB,GACjC;EACE,gBAAgB;EAChB,gBAAgB,SAAS,IAAI,gBAAgB,KAAK,EAAE;EACpD,EACE,SAAS,MAAM,OACb,OAAO,MAAM,GAAG,KACf,gBAAgB,SAAS,KACxB,CAAC,WAAW,gBAAgB,GAAG,IAC/B,gBAAgB,KAAK,MAAM,GAAG,GACnC;EACF,GACD;EACE;EACA,EAAE;EACF,EACE,QACD;EACF;AAGP,KAAI,CAAC,KACH,OAAM,IAAI,MACR,qFACD;CAGH,MAAM,aAAa,gBAAgB,WACjC,WAAU,cAAc,OAAO,EAAE,aAAa,KAAK,KAAK,aAAa,CACtE;AACD,KAAI,aAAa,GACf,iBAAgB,cAAc,gBAC5B,SACA,gBAAgB,aAChB,QACA,KACD;AAGH,QAAO"}
1
+ {"version":3,"file":"filters.mjs","names":[],"sources":["../../src/helpers/filters.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { Context } from \"@powerlines/core\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport {\n BabelTransformPlugin,\n BabelTransformPluginFilter,\n BabelTransformPluginOptions,\n BabelTransformPresetOptions,\n ResolvedBabelTransformPluginOptions,\n ResolvedBabelTransformPresetOptions\n} from \"../types/config\";\n\nexport function getPluginName(\n plugin?:\n | BabelTransformPluginOptions\n | string\n | false\n | object\n | ((...args: any[]) => any)\n | undefined\n): string | undefined {\n return isSetString(plugin)\n ? plugin\n : Array.isArray(plugin) && plugin.length > 0\n ? getPluginName(plugin[0])\n : (plugin as BabelTransformPlugin).$$name ||\n (plugin as BabelTransformPlugin).name\n ? (plugin as BabelTransformPlugin).$$name ||\n (plugin as BabelTransformPlugin).name\n : undefined;\n}\n\n/**\n * Check if a Babel plugin is a duplicate of another plugin in the list.\n *\n * @param plugins - The list of existing Babel plugins.\n * @param plugin - The Babel plugin to check for duplicates.\n * @returns True if the plugin is a duplicate, false otherwise.\n */\nexport function isDuplicatePlugin<\n T extends BabelTransformPluginOptions | ResolvedBabelTransformPluginOptions\n>(plugins: T[], plugin: T): boolean {\n return !!(\n getPluginName(plugin) &&\n plugins.some(\n existing =>\n Array.isArray(existing) &&\n getPluginName(existing[0]) === getPluginName(plugin)\n )\n );\n}\n\n/**\n * Check if a Babel preset is a duplicate of another preset in the list.\n *\n * @param presets - The list of existing Babel presets.\n * @param preset - The Babel preset to check for duplicates.\n * @returns True if the preset is a duplicate, false otherwise.\n */\nexport function isDuplicatePreset<\n T extends BabelTransformPresetOptions | ResolvedBabelTransformPresetOptions\n>(presets: T[], preset: T): boolean {\n return !!(\n getPluginName(preset) &&\n presets.some(\n existing =>\n Array.isArray(existing) &&\n getPluginName(existing[0]) === getPluginName(preset)\n )\n );\n}\n\n/**\n * Filters a Babel plugin by its runtime ID.\n *\n * @param context - The context in which the filter is applied.\n * @param fileId - The file ID to filter by.\n * @returns A filter function that checks if a plugin's ID matches the runtime ID.\n */\nexport function filterPluginByFileId<TContext extends Context = Context>(\n context: TContext,\n fileId: string\n): BabelTransformPluginFilter {\n return (code: string, id: string): boolean =>\n fileId !== id &&\n context.fs.ids[fileId] !== id &&\n fileId !== context.fs.ids[id] &&\n context.fs.ids[fileId] !== context.fs.ids[id] &&\n context.fs.paths[fileId] !== id &&\n fileId !== context.fs.paths[id] &&\n context.fs.paths[fileId] !== context.fs.paths[id];\n}\n\n/**\n * Adds a filter to a Babel plugin or a list of Babel plugins.\n *\n * @param context - The context in which the plugin is being added.\n * @param plugins - The Babel plugins to add the filter to.\n * @param filter - The filter function to apply to the plugins.\n * @param name - The name of the plugin to add the filter to.\n * @returns The updated list of Babel plugins with the filter applied.\n */\nexport function addPluginFilter(\n context: Context,\n plugins: BabelTransformPluginOptions[],\n filter: BabelTransformPluginFilter | null | undefined,\n name: string\n): BabelTransformPluginOptions[];\n\n/**\n * Adds a filter to a Babel plugin or a list of Babel plugins.\n *\n * @param context - The context in which the plugin is being added.\n * @param plugin - The Babel plugin to add the filter to.\n * @param filter - The filter function to apply to the plugin.\n * @returns The updated Babel plugin with the filter applied.\n */\nexport function addPluginFilter(\n context: Context,\n plugin: BabelTransformPlugin | BabelTransformPluginOptions,\n filter: NonNullable<BabelTransformPluginFilter>\n): BabelTransformPluginOptions;\n\n/**\n * Adds a filter to a Babel plugin or a list of Babel plugins.\n *\n * @param context - The context in which the plugin is being added.\n * @param pluginOrPlugins - The Babel plugin or plugins to add the filter to.\n * @param filter - The filter function to apply to the plugins.\n * @param name - The name of the plugin to add the filter to.\n * @returns The updated list of Babel plugins with the filter applied.\n */\nexport function addPluginFilter<\n T extends\n | BabelTransformPlugin\n | BabelTransformPluginOptions\n | BabelTransformPluginOptions[]\n>(\n context: Context,\n pluginOrPlugins: T,\n filter: NonNullable<BabelTransformPluginFilter>,\n name?: string\n): T extends BabelTransformPluginOptions[]\n ? BabelTransformPluginOptions[]\n : BabelTransformPluginOptions {\n if (\n !Array.isArray(pluginOrPlugins) ||\n (!pluginOrPlugins.some(plugin => Array.isArray(plugin)) &&\n pluginOrPlugins.length < 4 &&\n pluginOrPlugins.length > 0 &&\n (isSetString(pluginOrPlugins[0]) ||\n isFunction(pluginOrPlugins[0]) ||\n (pluginOrPlugins.length > 1 && isObject(pluginOrPlugins[1])) ||\n (pluginOrPlugins.length > 2 && isObject(pluginOrPlugins[2]))))\n ) {\n if (Array.isArray(pluginOrPlugins)) {\n return [\n pluginOrPlugins[0],\n pluginOrPlugins.length > 1 ? pluginOrPlugins[1] : {},\n {\n filter: (code, id) =>\n filter(code, id) &&\n (pluginOrPlugins.length < 3 ||\n !isFunction(pluginOrPlugins[2]) ||\n (pluginOrPlugins[2] as BabelTransformPluginFilter)?.(code, id))\n }\n ] as any;\n }\n return [\n pluginOrPlugins,\n {},\n {\n filter\n }\n ] as any;\n }\n\n if (!name) {\n throw new Error(\n \"No name was provided to \\`addPluginFilter\\`, could not find babel plugin without it.\"\n );\n }\n\n const foundIndex = pluginOrPlugins.findIndex(\n plugin => getPluginName(plugin)?.toLowerCase() === name.toLowerCase()\n );\n if (foundIndex > -1) {\n pluginOrPlugins[foundIndex] = addPluginFilter(\n context,\n pluginOrPlugins[foundIndex] as BabelTransformPluginOptions[],\n filter,\n name\n );\n }\n\n return pluginOrPlugins as any;\n}\n"],"mappings":";;;;;AA+BA,SAAgB,cACd,QAOoB;AACpB,QAAO,YAAY,OAAO,GACtB,SACA,MAAM,QAAQ,OAAO,IAAI,OAAO,SAAS,IACvC,cAAc,OAAO,GAAG,GACvB,OAAgC,UAC9B,OAAgC,OAChC,OAAgC,UAChC,OAAgC,OACjC;;;;;;;;;AAUV,SAAgB,kBAEd,SAAc,QAAoB;AAClC,QAAO,CAAC,EACN,cAAc,OAAO,IACrB,QAAQ,MACN,aACE,MAAM,QAAQ,SAAS,IACvB,cAAc,SAAS,GAAG,KAAK,cAAc,OAAO,CACvD;;;;;;;;;AAWL,SAAgB,kBAEd,SAAc,QAAoB;AAClC,QAAO,CAAC,EACN,cAAc,OAAO,IACrB,QAAQ,MACN,aACE,MAAM,QAAQ,SAAS,IACvB,cAAc,SAAS,GAAG,KAAK,cAAc,OAAO,CACvD;;;;;;;;;AAWL,SAAgB,qBACd,SACA,QAC4B;AAC5B,SAAQ,MAAc,OACpB,WAAW,MACX,QAAQ,GAAG,IAAI,YAAY,MAC3B,WAAW,QAAQ,GAAG,IAAI,OAC1B,QAAQ,GAAG,IAAI,YAAY,QAAQ,GAAG,IAAI,OAC1C,QAAQ,GAAG,MAAM,YAAY,MAC7B,WAAW,QAAQ,GAAG,MAAM,OAC5B,QAAQ,GAAG,MAAM,YAAY,QAAQ,GAAG,MAAM;;;;;;;;;;;AA0ClD,SAAgB,gBAMd,SACA,iBACA,QACA,MAG8B;AAC9B,KACE,CAAC,MAAM,QAAQ,gBAAgB,IAC9B,CAAC,gBAAgB,MAAK,WAAU,MAAM,QAAQ,OAAO,CAAC,IACrD,gBAAgB,SAAS,KACzB,gBAAgB,SAAS,MACxB,YAAY,gBAAgB,GAAG,IAC9B,WAAW,gBAAgB,GAAG,IAC7B,gBAAgB,SAAS,KAAK,SAAS,gBAAgB,GAAG,IAC1D,gBAAgB,SAAS,KAAK,SAAS,gBAAgB,GAAG,GAC/D;AACA,MAAI,MAAM,QAAQ,gBAAgB,CAChC,QAAO;GACL,gBAAgB;GAChB,gBAAgB,SAAS,IAAI,gBAAgB,KAAK,EAAE;GACpD,EACE,SAAS,MAAM,OACb,OAAO,MAAM,GAAG,KACf,gBAAgB,SAAS,KACxB,CAAC,WAAW,gBAAgB,GAAG,IAC9B,gBAAgB,KAAoC,MAAM,GAAG,GACnE;GACF;AAEH,SAAO;GACL;GACA,EAAE;GACF,EACE,QACD;GACF;;AAGH,KAAI,CAAC,KACH,OAAM,IAAI,MACR,qFACD;CAGH,MAAM,aAAa,gBAAgB,WACjC,WAAU,cAAc,OAAO,EAAE,aAAa,KAAK,KAAK,aAAa,CACtE;AACD,KAAI,aAAa,GACf,iBAAgB,cAAc,gBAC5B,SACA,gBAAgB,aAChB,QACA,KACD;AAGH,QAAO"}
@@ -14,10 +14,15 @@ exports.findExport = require_helpers_module_helpers.findExport;
14
14
  exports.generateFromAst = require_helpers_ast_utils.generateFromAst;
15
15
  exports.getImport = require_helpers_module_helpers.getImport;
16
16
  exports.getPluginName = require_helpers_filters.getPluginName;
17
+ exports.getUniquePlugins = require_helpers_options.getUniquePlugins;
18
+ exports.getUniquePresets = require_helpers_options.getUniquePresets;
17
19
  exports.isDuplicatePlugin = require_helpers_filters.isDuplicatePlugin;
20
+ exports.isDuplicatePreset = require_helpers_filters.isDuplicatePreset;
18
21
  exports.isImportCall = require_helpers_module_helpers.isImportCall;
19
22
  exports.listExports = require_helpers_module_helpers.listExports;
20
23
  exports.listImports = require_helpers_module_helpers.listImports;
21
24
  exports.parseAst = require_helpers_ast_utils.parseAst;
22
25
  exports.resolveBabelPlugin = require_helpers_options.resolveBabelPlugin;
23
- exports.resolvePluginFunction = require_helpers_options.resolvePluginFunction;
26
+ exports.resolveBabelPreset = require_helpers_options.resolveBabelPreset;
27
+ exports.resolvePluginFunction = require_helpers_options.resolvePluginFunction;
28
+ exports.resolvePresetFunction = require_helpers_options.resolvePresetFunction;
@@ -1,6 +1,6 @@
1
1
  import { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, generateFromAst, parseAst } from "./ast-utils.cjs";
2
2
  import { createBabelPlugin } from "./create-plugin.cjs";
3
- import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin } from "./filters.cjs";
3
+ import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin, isDuplicatePreset } from "./filters.cjs";
4
4
  import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./module-helpers.cjs";
5
- import { resolveBabelPlugin, resolvePluginFunction } from "./options.cjs";
6
- export { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolvePluginFunction };
5
+ import { getUniquePlugins, getUniquePresets, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction } from "./options.cjs";
6
+ export { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets, isDuplicatePlugin, isDuplicatePreset, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction };
@@ -1,6 +1,6 @@
1
1
  import { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, generateFromAst, parseAst } from "./ast-utils.mjs";
2
2
  import { createBabelPlugin } from "./create-plugin.mjs";
3
- import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin } from "./filters.mjs";
3
+ import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin, isDuplicatePreset } from "./filters.mjs";
4
4
  import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./module-helpers.mjs";
5
- import { resolveBabelPlugin, resolvePluginFunction } from "./options.mjs";
6
- export { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolvePluginFunction };
5
+ import { getUniquePlugins, getUniquePresets, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction } from "./options.mjs";
6
+ export { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets, isDuplicatePlugin, isDuplicatePreset, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction };
@@ -1,7 +1,7 @@
1
- import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin } from "./filters.mjs";
2
- import { resolveBabelPlugin, resolvePluginFunction } from "./options.mjs";
1
+ import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin, isDuplicatePreset } from "./filters.mjs";
2
+ import { getUniquePlugins, getUniquePresets, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction } from "./options.mjs";
3
3
  import { generateFromAst, parseAst } from "./ast-utils.mjs";
4
4
  import { createBabelPlugin } from "./create-plugin.mjs";
5
5
  import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./module-helpers.mjs";
6
6
 
7
- export { addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolvePluginFunction };
7
+ export { addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets, isDuplicatePlugin, isDuplicatePreset, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction };
@@ -13,6 +13,13 @@ function resolvePluginFunction(context, plugin) {
13
13
  return plugin[0];
14
14
  }
15
15
  }
16
+ function resolvePresetFunction(context, preset) {
17
+ try {
18
+ return Array.isArray(preset) && preset.length > 0 && preset[0] ? (0, _stryke_type_checks_is_function.isFunction)(preset[0]) ? preset[0](context) : preset[0] : (0, _stryke_type_checks_is_function.isFunction)(preset) ? preset(context) : preset;
19
+ } catch {
20
+ return preset[0];
21
+ }
22
+ }
16
23
  /**
17
24
  * Resolve the [Babel](https://babeljs.io/) plugin.
18
25
  *
@@ -44,7 +51,66 @@ function resolveBabelPlugin(context, code, id, plugin) {
44
51
  null
45
52
  ];
46
53
  }
54
+ /**
55
+ * Resolve the [Babel](https://babeljs.io/) preset.
56
+ *
57
+ * @param context - The context for the transformation.
58
+ * @param code - The code to be transformed.
59
+ * @param id - The ID of the source file.
60
+ * @param preset - The Babel preset to resolve.
61
+ * @returns The resolved Babel preset options, or undefined if the preset is filtered out.
62
+ */
63
+ function resolveBabelPreset(context, code, id, preset) {
64
+ if (Array.isArray(preset) && preset.length > 0 && preset[0]) {
65
+ if (preset.length > 2 && preset[2] && (0, _stryke_type_checks_is_function.isFunction)(preset[2]) && !preset[2](code, id)) {
66
+ context.trace(`Skipping filtered Babel preset ${chalk.default.bold.cyanBright(require_helpers_filters.getPluginName(preset) || "unnamed")} for ${id}`);
67
+ return;
68
+ }
69
+ return preset.length > 2 ? [
70
+ resolvePresetFunction(context, preset),
71
+ preset[1],
72
+ preset[2]
73
+ ] : [
74
+ resolvePresetFunction(context, preset),
75
+ preset[1],
76
+ null
77
+ ];
78
+ }
79
+ return [
80
+ resolvePresetFunction(context, preset),
81
+ {},
82
+ null
83
+ ];
84
+ }
85
+ /**
86
+ * Get a list of unique Babel plugins, filtering out duplicates based on their names.
87
+ *
88
+ * @param plugins - The list of Babel plugins to filter for uniqueness.
89
+ * @returns A list of unique Babel plugins.
90
+ */
91
+ function getUniquePlugins(plugins) {
92
+ return plugins.reduce((ret, plugin) => {
93
+ if (plugin && !require_helpers_filters.isDuplicatePlugin(ret, plugin)) ret.push(plugin);
94
+ return ret;
95
+ }, []);
96
+ }
97
+ /**
98
+ * Get a list of unique Babel presets, filtering out duplicates based on their names.
99
+ *
100
+ * @param presets - The list of Babel presets to filter for uniqueness.
101
+ * @returns A list of unique Babel presets.
102
+ */
103
+ function getUniquePresets(presets) {
104
+ return presets.reduce((ret, preset) => {
105
+ if (preset && !require_helpers_filters.isDuplicatePreset(ret, preset)) ret.push(preset);
106
+ return ret;
107
+ }, []);
108
+ }
47
109
 
48
110
  //#endregion
111
+ exports.getUniquePlugins = getUniquePlugins;
112
+ exports.getUniquePresets = getUniquePresets;
49
113
  exports.resolveBabelPlugin = resolveBabelPlugin;
50
- exports.resolvePluginFunction = resolvePluginFunction;
114
+ exports.resolveBabelPreset = resolveBabelPreset;
115
+ exports.resolvePluginFunction = resolvePluginFunction;
116
+ exports.resolvePresetFunction = resolvePresetFunction;
@@ -1,9 +1,10 @@
1
- import { BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions } from "../types/config.cjs";
1
+ import { BabelTransformPluginOptions, BabelTransformPresetOptions, ResolvedBabelTransformPluginOptions, ResolvedBabelTransformPresetOptions } from "../types/config.cjs";
2
2
  import { Context } from "@powerlines/core";
3
- import { PluginOptions, PluginTarget } from "@babel/core";
3
+ import { PluginItem, PluginTarget, PresetItem, PresetTarget } from "@babel/core";
4
4
 
5
5
  //#region src/helpers/options.d.ts
6
- declare function resolvePluginFunction(context: Context, plugin: any | PluginTarget | any[] | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string | undefined]): BabelTransformPluginOptions;
6
+ declare function resolvePluginFunction(context: Context, plugin: any | PluginTarget | any[] | [PluginTarget, PluginItem] | [PluginTarget, PluginItem, string | undefined]): BabelTransformPluginOptions;
7
+ declare function resolvePresetFunction(context: Context, preset: any | PresetTarget | any[] | [PresetTarget, PresetItem] | [PresetTarget, PresetItem, string | undefined]): BabelTransformPresetOptions;
7
8
  /**
8
9
  * Resolve the [Babel](https://babeljs.io/) plugin.
9
10
  *
@@ -14,6 +15,30 @@ declare function resolvePluginFunction(context: Context, plugin: any | PluginTar
14
15
  * @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
15
16
  */
16
17
  declare function resolveBabelPlugin(context: Context, code: string, id: string, plugin: BabelTransformPluginOptions): ResolvedBabelTransformPluginOptions | undefined;
18
+ /**
19
+ * Resolve the [Babel](https://babeljs.io/) preset.
20
+ *
21
+ * @param context - The context for the transformation.
22
+ * @param code - The code to be transformed.
23
+ * @param id - The ID of the source file.
24
+ * @param preset - The Babel preset to resolve.
25
+ * @returns The resolved Babel preset options, or undefined if the preset is filtered out.
26
+ */
27
+ declare function resolveBabelPreset(context: Context, code: string, id: string, preset: BabelTransformPresetOptions): ResolvedBabelTransformPresetOptions | undefined;
28
+ /**
29
+ * Get a list of unique Babel plugins, filtering out duplicates based on their names.
30
+ *
31
+ * @param plugins - The list of Babel plugins to filter for uniqueness.
32
+ * @returns A list of unique Babel plugins.
33
+ */
34
+ declare function getUniquePlugins<T extends BabelTransformPluginOptions | ResolvedBabelTransformPluginOptions>(plugins: T[]): T[];
35
+ /**
36
+ * Get a list of unique Babel presets, filtering out duplicates based on their names.
37
+ *
38
+ * @param presets - The list of Babel presets to filter for uniqueness.
39
+ * @returns A list of unique Babel presets.
40
+ */
41
+ declare function getUniquePresets<T extends BabelTransformPresetOptions | ResolvedBabelTransformPresetOptions>(presets: T[]): T[];
17
42
  //#endregion
18
- export { resolveBabelPlugin, resolvePluginFunction };
43
+ export { getUniquePlugins, getUniquePresets, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction };
19
44
  //# sourceMappingURL=options.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.cts","names":[],"sources":["../../src/helpers/options.ts"],"mappings":";;;;;iBA4BgB,qBAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,QAEI,YAAA,YAEC,YAAA,EAAc,aAAA,KACd,YAAA,EAAc,aAAA,wBAClB,2BAAA;;AARH;;;;;;;;iBA+BgB,kBAAA,CACd,OAAA,EAAS,OAAA,EACT,IAAA,UACA,EAAA,UACA,MAAA,EAAQ,2BAAA,GACP,mCAAA"}
1
+ {"version":3,"file":"options.d.cts","names":[],"sources":["../../src/helpers/options.ts"],"mappings":";;;;;iBAmCgB,qBAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,QAEI,YAAA,YAEC,YAAA,EAAc,UAAA,KACd,YAAA,EAAc,UAAA,wBAClB,2BAAA;AAAA,iBAca,qBAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,QAEI,YAAA,YAEC,YAAA,EAAc,UAAA,KACd,YAAA,EAAc,UAAA,wBAClB,2BAAA;AA9BH;;;;;;;;;AAAA,iBAqDgB,kBAAA,CACd,OAAA,EAAS,OAAA,EACT,IAAA,UACA,EAAA,UACA,MAAA,EAAQ,2BAAA,GACP,mCAAA;;;;;;;;;;iBAwCa,kBAAA,CACd,OAAA,EAAS,OAAA,EACT,IAAA,UACA,EAAA,UACA,MAAA,EAAQ,2BAAA,GACP,mCAAA;;;;AAjFH;;;iBAsHgB,gBAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,KAAM,CAAA;;;;;;;iBAgBD,gBAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,KAAM,CAAA"}
@@ -1,9 +1,10 @@
1
- import { BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions } from "../types/config.mjs";
2
- import { PluginOptions, PluginTarget } from "@babel/core";
1
+ import { BabelTransformPluginOptions, BabelTransformPresetOptions, ResolvedBabelTransformPluginOptions, ResolvedBabelTransformPresetOptions } from "../types/config.mjs";
2
+ import { PluginItem, PluginTarget, PresetItem, PresetTarget } from "@babel/core";
3
3
  import { Context } from "@powerlines/core";
4
4
 
5
5
  //#region src/helpers/options.d.ts
6
- declare function resolvePluginFunction(context: Context, plugin: any | PluginTarget | any[] | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string | undefined]): BabelTransformPluginOptions;
6
+ declare function resolvePluginFunction(context: Context, plugin: any | PluginTarget | any[] | [PluginTarget, PluginItem] | [PluginTarget, PluginItem, string | undefined]): BabelTransformPluginOptions;
7
+ declare function resolvePresetFunction(context: Context, preset: any | PresetTarget | any[] | [PresetTarget, PresetItem] | [PresetTarget, PresetItem, string | undefined]): BabelTransformPresetOptions;
7
8
  /**
8
9
  * Resolve the [Babel](https://babeljs.io/) plugin.
9
10
  *
@@ -14,6 +15,30 @@ declare function resolvePluginFunction(context: Context, plugin: any | PluginTar
14
15
  * @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
15
16
  */
16
17
  declare function resolveBabelPlugin(context: Context, code: string, id: string, plugin: BabelTransformPluginOptions): ResolvedBabelTransformPluginOptions | undefined;
18
+ /**
19
+ * Resolve the [Babel](https://babeljs.io/) preset.
20
+ *
21
+ * @param context - The context for the transformation.
22
+ * @param code - The code to be transformed.
23
+ * @param id - The ID of the source file.
24
+ * @param preset - The Babel preset to resolve.
25
+ * @returns The resolved Babel preset options, or undefined if the preset is filtered out.
26
+ */
27
+ declare function resolveBabelPreset(context: Context, code: string, id: string, preset: BabelTransformPresetOptions): ResolvedBabelTransformPresetOptions | undefined;
28
+ /**
29
+ * Get a list of unique Babel plugins, filtering out duplicates based on their names.
30
+ *
31
+ * @param plugins - The list of Babel plugins to filter for uniqueness.
32
+ * @returns A list of unique Babel plugins.
33
+ */
34
+ declare function getUniquePlugins<T extends BabelTransformPluginOptions | ResolvedBabelTransformPluginOptions>(plugins: T[]): T[];
35
+ /**
36
+ * Get a list of unique Babel presets, filtering out duplicates based on their names.
37
+ *
38
+ * @param presets - The list of Babel presets to filter for uniqueness.
39
+ * @returns A list of unique Babel presets.
40
+ */
41
+ declare function getUniquePresets<T extends BabelTransformPresetOptions | ResolvedBabelTransformPresetOptions>(presets: T[]): T[];
17
42
  //#endregion
18
- export { resolveBabelPlugin, resolvePluginFunction };
43
+ export { getUniquePlugins, getUniquePresets, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction };
19
44
  //# sourceMappingURL=options.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.d.mts","names":[],"sources":["../../src/helpers/options.ts"],"mappings":";;;;;iBA4BgB,qBAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,QAEI,YAAA,YAEC,YAAA,EAAc,aAAA,KACd,YAAA,EAAc,aAAA,wBAClB,2BAAA;;AARH;;;;;;;;iBA+BgB,kBAAA,CACd,OAAA,EAAS,OAAA,EACT,IAAA,UACA,EAAA,UACA,MAAA,EAAQ,2BAAA,GACP,mCAAA"}
1
+ {"version":3,"file":"options.d.mts","names":[],"sources":["../../src/helpers/options.ts"],"mappings":";;;;;iBAmCgB,qBAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,QAEI,YAAA,YAEC,YAAA,EAAc,UAAA,KACd,YAAA,EAAc,UAAA,wBAClB,2BAAA;AAAA,iBAca,qBAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,QAEI,YAAA,YAEC,YAAA,EAAc,UAAA,KACd,YAAA,EAAc,UAAA,wBAClB,2BAAA;AA9BH;;;;;;;;;AAAA,iBAqDgB,kBAAA,CACd,OAAA,EAAS,OAAA,EACT,IAAA,UACA,EAAA,UACA,MAAA,EAAQ,2BAAA,GACP,mCAAA;;;;;;;;;;iBAwCa,kBAAA,CACd,OAAA,EAAS,OAAA,EACT,IAAA,UACA,EAAA,UACA,MAAA,EAAQ,2BAAA,GACP,mCAAA;;;;AAjFH;;;iBAsHgB,gBAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,KAAM,CAAA;;;;;;;iBAgBD,gBAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,KAAM,CAAA"}