@powerlines/plugin-babel 0.12.307 → 0.12.308

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 (159) hide show
  1. package/dist/ast-utils-BcmWaIan.cjs +45 -0
  2. package/dist/ast-utils-BgcE0CUh.mjs +33 -0
  3. package/dist/ast-utils-BgcE0CUh.mjs.map +1 -0
  4. package/dist/ast-utils-BrOP-SXX.d.cts +20 -0
  5. package/dist/ast-utils-BrOP-SXX.d.cts.map +1 -0
  6. package/dist/ast-utils-c95WpQzC.d.mts +20 -0
  7. package/dist/ast-utils-c95WpQzC.d.mts.map +1 -0
  8. package/dist/{_virtual/rolldown_runtime.cjs → chunk-CbDLau6x.cjs} +6 -1
  9. package/dist/config-B8fQjuSs.d.cts +86 -0
  10. package/dist/config-B8fQjuSs.d.cts.map +1 -0
  11. package/dist/config-BGnCc0aq.d.mts +86 -0
  12. package/dist/config-BGnCc0aq.d.mts.map +1 -0
  13. package/dist/config-BLkkDfsC.mjs +1 -0
  14. package/dist/config-QK0F_KAD.cjs +0 -0
  15. package/dist/create-plugin-BbG_dRTl.mjs +40 -0
  16. package/dist/create-plugin-BbG_dRTl.mjs.map +1 -0
  17. package/dist/create-plugin-D1_rga7H.d.cts +16 -0
  18. package/dist/create-plugin-D1_rga7H.d.cts.map +1 -0
  19. package/dist/create-plugin-DaXcRyMI.cjs +46 -0
  20. package/dist/create-plugin-H35OVSz7.d.mts +16 -0
  21. package/dist/create-plugin-H35OVSz7.d.mts.map +1 -0
  22. package/dist/filters-CU0L1nIa.cjs +79 -0
  23. package/dist/filters-DX-_VLWz.d.mts +43 -0
  24. package/dist/filters-DX-_VLWz.d.mts.map +1 -0
  25. package/dist/filters-DjAUc6r9.mjs +56 -0
  26. package/dist/filters-DjAUc6r9.mjs.map +1 -0
  27. package/dist/filters-xc5uoxxD.d.cts +43 -0
  28. package/dist/filters-xc5uoxxD.d.cts.map +1 -0
  29. package/dist/helpers/ast-utils.cjs +3 -34
  30. package/dist/helpers/ast-utils.d.cts +2 -20
  31. package/dist/helpers/ast-utils.d.mts +2 -20
  32. package/dist/helpers/ast-utils.mjs +2 -32
  33. package/dist/helpers/create-plugin.cjs +2 -40
  34. package/dist/helpers/create-plugin.d.cts +3 -16
  35. package/dist/helpers/create-plugin.d.mts +3 -17
  36. package/dist/helpers/create-plugin.mjs +2 -39
  37. package/dist/helpers/filters.cjs +5 -58
  38. package/dist/helpers/filters.d.cts +3 -43
  39. package/dist/helpers/filters.d.mts +3 -44
  40. package/dist/helpers/filters.mjs +2 -55
  41. package/dist/helpers/index.cjs +22 -21
  42. package/dist/helpers/index.d.cts +7 -5
  43. package/dist/helpers/index.d.mts +7 -5
  44. package/dist/helpers/index.mjs +6 -5
  45. package/dist/helpers/module-helpers.cjs +9 -102
  46. package/dist/helpers/module-helpers.d.cts +3 -50
  47. package/dist/helpers/module-helpers.d.mts +3 -50
  48. package/dist/helpers/module-helpers.mjs +3 -95
  49. package/dist/helpers/options.cjs +4 -48
  50. package/dist/helpers/options.d.cts +3 -19
  51. package/dist/helpers/options.d.mts +3 -20
  52. package/dist/helpers/options.mjs +3 -46
  53. package/dist/helpers-Bx2yBrpn.cjs +0 -0
  54. package/dist/helpers-DemUUgdw.mjs +1 -0
  55. package/dist/index-C2gUMYkE.d.cts +1 -0
  56. package/dist/index-D8dPsry7.d.mts +1 -0
  57. package/dist/index-OEBbnNdr.d.mts +1 -0
  58. package/dist/index-uTS5iDq_.d.cts +1 -0
  59. package/dist/index.cjs +30 -27
  60. package/dist/index.d.cts +10 -8
  61. package/dist/index.d.cts.map +1 -1
  62. package/dist/index.d.mts +10 -11
  63. package/dist/index.d.mts.map +1 -1
  64. package/dist/index.mjs +9 -6
  65. package/dist/index.mjs.map +1 -1
  66. package/dist/module-helpers-B913A2FR.d.mts +50 -0
  67. package/dist/module-helpers-B913A2FR.d.mts.map +1 -0
  68. package/dist/module-helpers-BBKb6fKg.d.cts +50 -0
  69. package/dist/module-helpers-BBKb6fKg.d.cts.map +1 -0
  70. package/dist/module-helpers-DtOc93YQ.mjs +96 -0
  71. package/dist/module-helpers-DtOc93YQ.mjs.map +1 -0
  72. package/dist/module-helpers-Non-jHMu.cjs +138 -0
  73. package/dist/options-2JL6WIXT.cjs +59 -0
  74. package/dist/options-CNyetWnk.d.cts +19 -0
  75. package/dist/options-CNyetWnk.d.cts.map +1 -0
  76. package/dist/options-DT_wvMGu.mjs +47 -0
  77. package/dist/options-DT_wvMGu.mjs.map +1 -0
  78. package/dist/options-Z_v0-Y5V.d.mts +19 -0
  79. package/dist/options-Z_v0-Y5V.d.mts.map +1 -0
  80. package/dist/plugin-10Y9IjgN.d.cts +19 -0
  81. package/dist/plugin-10Y9IjgN.d.cts.map +1 -0
  82. package/dist/plugin-25m6BdNV.d.mts +19 -0
  83. package/dist/plugin-25m6BdNV.d.mts.map +1 -0
  84. package/dist/plugin-BX9Q6Mnb.mjs +1 -0
  85. package/dist/plugin-DkYJiG5m.cjs +0 -0
  86. package/dist/types/config.cjs +1 -0
  87. package/dist/types/config.d.cts +2 -87
  88. package/dist/types/config.d.mts +2 -88
  89. package/dist/types/config.mjs +2 -0
  90. package/dist/types/index.cjs +3 -0
  91. package/dist/types/index.d.cts +3 -2
  92. package/dist/types/index.d.mts +3 -2
  93. package/dist/types/index.mjs +4 -0
  94. package/dist/types/plugin.cjs +1 -0
  95. package/dist/types/plugin.d.cts +3 -20
  96. package/dist/types/plugin.d.mts +3 -21
  97. package/dist/types/plugin.mjs +2 -0
  98. package/dist/types-Bjn15Uy6.mjs +1 -0
  99. package/dist/types-D10T4PdD.cjs +0 -0
  100. package/package.json +2 -2
  101. package/dist/core/src/lib/logger.cjs +0 -41
  102. package/dist/core/src/lib/logger.mjs +0 -40
  103. package/dist/core/src/lib/logger.mjs.map +0 -1
  104. package/dist/core/src/types/api.d.cts +0 -103
  105. package/dist/core/src/types/api.d.cts.map +0 -1
  106. package/dist/core/src/types/api.d.mts +0 -103
  107. package/dist/core/src/types/api.d.mts.map +0 -1
  108. package/dist/core/src/types/commands.d.cts +0 -9
  109. package/dist/core/src/types/commands.d.cts.map +0 -1
  110. package/dist/core/src/types/commands.d.mts +0 -10
  111. package/dist/core/src/types/commands.d.mts.map +0 -1
  112. package/dist/core/src/types/config.d.cts +0 -551
  113. package/dist/core/src/types/config.d.cts.map +0 -1
  114. package/dist/core/src/types/config.d.mts +0 -551
  115. package/dist/core/src/types/config.d.mts.map +0 -1
  116. package/dist/core/src/types/context.d.cts +0 -511
  117. package/dist/core/src/types/context.d.cts.map +0 -1
  118. package/dist/core/src/types/context.d.mts +0 -511
  119. package/dist/core/src/types/context.d.mts.map +0 -1
  120. package/dist/core/src/types/fs.d.cts +0 -487
  121. package/dist/core/src/types/fs.d.cts.map +0 -1
  122. package/dist/core/src/types/fs.d.mts +0 -487
  123. package/dist/core/src/types/fs.d.mts.map +0 -1
  124. package/dist/core/src/types/hooks.d.cts +0 -99
  125. package/dist/core/src/types/hooks.d.cts.map +0 -1
  126. package/dist/core/src/types/hooks.d.mts +0 -99
  127. package/dist/core/src/types/hooks.d.mts.map +0 -1
  128. package/dist/core/src/types/index.d.mts +0 -9
  129. package/dist/core/src/types/plugin.d.cts +0 -204
  130. package/dist/core/src/types/plugin.d.cts.map +0 -1
  131. package/dist/core/src/types/plugin.d.mts +0 -204
  132. package/dist/core/src/types/plugin.d.mts.map +0 -1
  133. package/dist/core/src/types/tsconfig.d.cts +0 -70
  134. package/dist/core/src/types/tsconfig.d.cts.map +0 -1
  135. package/dist/core/src/types/tsconfig.d.mts +0 -70
  136. package/dist/core/src/types/tsconfig.d.mts.map +0 -1
  137. package/dist/core/src/types/unplugin.d.cts +0 -24
  138. package/dist/core/src/types/unplugin.d.cts.map +0 -1
  139. package/dist/core/src/types/unplugin.d.mts +0 -25
  140. package/dist/core/src/types/unplugin.d.mts.map +0 -1
  141. package/dist/helpers/ast-utils.d.cts.map +0 -1
  142. package/dist/helpers/ast-utils.d.mts.map +0 -1
  143. package/dist/helpers/ast-utils.mjs.map +0 -1
  144. package/dist/helpers/create-plugin.d.cts.map +0 -1
  145. package/dist/helpers/create-plugin.d.mts.map +0 -1
  146. package/dist/helpers/create-plugin.mjs.map +0 -1
  147. package/dist/helpers/filters.d.cts.map +0 -1
  148. package/dist/helpers/filters.d.mts.map +0 -1
  149. package/dist/helpers/filters.mjs.map +0 -1
  150. package/dist/helpers/module-helpers.d.cts.map +0 -1
  151. package/dist/helpers/module-helpers.d.mts.map +0 -1
  152. package/dist/helpers/module-helpers.mjs.map +0 -1
  153. package/dist/helpers/options.d.cts.map +0 -1
  154. package/dist/helpers/options.d.mts.map +0 -1
  155. package/dist/helpers/options.mjs.map +0 -1
  156. package/dist/types/config.d.cts.map +0 -1
  157. package/dist/types/config.d.mts.map +0 -1
  158. package/dist/types/plugin.d.cts.map +0 -1
  159. package/dist/types/plugin.d.mts.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,17 +1,20 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
3
- const require_helpers_filters = require('./helpers/filters.cjs');
4
- const require_helpers_options = require('./helpers/options.cjs');
5
- const require_helpers_ast_utils = require('./helpers/ast-utils.cjs');
6
- const require_helpers_create_plugin = require('./helpers/create-plugin.cjs');
7
- const require_helpers_module_helpers = require('./helpers/module-helpers.cjs');
8
- require('./helpers/index.cjs');
2
+ const require_chunk = require('./chunk-CbDLau6x.cjs');
3
+ const require_filters = require('./filters-CU0L1nIa.cjs');
4
+ const require_options = require('./options-2JL6WIXT.cjs');
5
+ const require_ast_utils = require('./ast-utils-BcmWaIan.cjs');
6
+ const require_create_plugin = require('./create-plugin-DaXcRyMI.cjs');
7
+ const require_module_helpers = require('./module-helpers-Non-jHMu.cjs');
8
+ require('./helpers-Bx2yBrpn.cjs');
9
+ require('./config-QK0F_KAD.cjs');
10
+ require('./plugin-DkYJiG5m.cjs');
11
+ require('./types-D10T4PdD.cjs');
9
12
  let __babel_core = require("@babel/core");
10
13
  let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
11
14
  let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
12
15
  let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
13
16
  let defu = require("defu");
14
- defu = require_rolldown_runtime.__toESM(defu);
17
+ defu = require_chunk.__toESM(defu);
15
18
 
16
19
  //#region src/index.ts
17
20
  /**
@@ -44,13 +47,13 @@ const plugin = (options = {}) => {
44
47
  id
45
48
  };
46
49
  }
47
- const plugins = this.config.babel.plugins.map((plugin$1) => require_helpers_options.resolveBabelPlugin(this, code, id, plugin$1)).filter((plugin$1, _, arr) => plugin$1 && !require_helpers_filters.isDuplicatePlugin(arr, plugin$1));
48
- const presets = this.config.babel.presets.map((preset) => require_helpers_options.resolveBabelPlugin(this, code, id, preset)).filter((preset, _, arr) => preset && !require_helpers_filters.isDuplicatePlugin(arr, preset));
50
+ const plugins = this.config.babel.plugins.map((plugin$1) => require_options.resolveBabelPlugin(this, code, id, plugin$1)).filter((plugin$1, _, arr) => plugin$1 && !require_filters.isDuplicatePlugin(arr, plugin$1));
51
+ const presets = this.config.babel.presets.map((preset) => require_options.resolveBabelPlugin(this, code, id, preset)).filter((preset, _, arr) => preset && !require_filters.isDuplicatePlugin(arr, preset));
49
52
  if (Array.isArray(plugins) && plugins.length === 0 && Array.isArray(presets) && presets.length === 0) return {
50
53
  code,
51
54
  id
52
55
  };
53
- if (/^(?:m|c)?tsx?$/.test((0, __stryke_path_file_path_fns.findFileExtensionSafe)(id, { fullExtension: true })) && !require_helpers_filters.isDuplicatePlugin(plugins, "@babel/plugin-syntax-typescript") && !require_helpers_filters.isDuplicatePlugin(presets, "@babel/preset-typescript")) plugins.unshift(["@babel/plugin-syntax-typescript", { isTSX: (0, __stryke_path_file_path_fns.findFileExtension)(id) === "tsx" }]);
56
+ if (/^(?:m|c)?tsx?$/.test((0, __stryke_path_file_path_fns.findFileExtensionSafe)(id, { fullExtension: true })) && !require_filters.isDuplicatePlugin(plugins, "@babel/plugin-syntax-typescript") && !require_filters.isDuplicatePlugin(presets, "@babel/preset-typescript")) plugins.unshift(["@babel/plugin-syntax-typescript", { isTSX: (0, __stryke_path_file_path_fns.findFileExtension)(id) === "tsx" }]);
54
57
  this.trace(`Running babel transformations with ${plugins.length} plugins and ${presets.length} presets for file: ${id}`);
55
58
  const result = await (0, __babel_core.transformAsync)(code, {
56
59
  highlightCode: true,
@@ -84,21 +87,21 @@ const plugin = (options = {}) => {
84
87
  var src_default = plugin;
85
88
 
86
89
  //#endregion
87
- exports.addImport = require_helpers_module_helpers.addImport;
88
- exports.addImportsToProgram = require_helpers_module_helpers.addImportsToProgram;
89
- exports.addPluginFilter = require_helpers_filters.addPluginFilter;
90
- exports.createBabelPlugin = require_helpers_create_plugin.createBabelPlugin;
90
+ exports.addImport = require_module_helpers.addImport;
91
+ exports.addImportsToProgram = require_module_helpers.addImportsToProgram;
92
+ exports.addPluginFilter = require_filters.addPluginFilter;
93
+ exports.createBabelPlugin = require_create_plugin.createBabelPlugin;
91
94
  exports.default = src_default;
92
- exports.filterPluginByFileId = require_helpers_filters.filterPluginByFileId;
93
- exports.findExport = require_helpers_module_helpers.findExport;
94
- exports.generateFromAst = require_helpers_ast_utils.generateFromAst;
95
- exports.getImport = require_helpers_module_helpers.getImport;
96
- exports.getPluginName = require_helpers_filters.getPluginName;
97
- exports.isDuplicatePlugin = require_helpers_filters.isDuplicatePlugin;
98
- exports.isImportCall = require_helpers_module_helpers.isImportCall;
99
- exports.listExports = require_helpers_module_helpers.listExports;
100
- exports.listImports = require_helpers_module_helpers.listImports;
101
- exports.parseAst = require_helpers_ast_utils.parseAst;
95
+ exports.filterPluginByFileId = require_filters.filterPluginByFileId;
96
+ exports.findExport = require_module_helpers.findExport;
97
+ exports.generateFromAst = require_ast_utils.generateFromAst;
98
+ exports.getImport = require_module_helpers.getImport;
99
+ exports.getPluginName = require_filters.getPluginName;
100
+ exports.isDuplicatePlugin = require_filters.isDuplicatePlugin;
101
+ exports.isImportCall = require_module_helpers.isImportCall;
102
+ exports.listExports = require_module_helpers.listExports;
103
+ exports.listImports = require_module_helpers.listImports;
104
+ exports.parseAst = require_ast_utils.parseAst;
102
105
  exports.plugin = plugin;
103
- exports.resolveBabelPlugin = require_helpers_options.resolveBabelPlugin;
104
- exports.resolvePluginFunction = require_helpers_options.resolvePluginFunction;
106
+ exports.resolveBabelPlugin = require_options.resolveBabelPlugin;
107
+ exports.resolvePluginFunction = require_options.resolvePluginFunction;
package/dist/index.d.cts CHANGED
@@ -1,11 +1,13 @@
1
- import { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, generateFromAst, parseAst } from "./helpers/ast-utils.cjs";
2
- import { Plugin } from "./core/src/types/plugin.cjs";
3
- import { BabelPluginPass, BabelResolvedConfig, BabelTransformInput, BabelTransformPlugin, BabelTransformPluginBuilder, BabelTransformPluginBuilderParams, BabelTransformPluginFilter, BabelTransformPluginOptions, BabelUserConfig, DeclareBabelTransformPluginReturn, DefaultImportDefinition, ImportDefinition, ImportSpecifier, NamedImportDefinition, ResolvedBabelTransformPluginOptions, __ΩBabelPluginPass, __ΩBabelResolvedConfig, __ΩBabelTransformInput, __ΩBabelTransformPlugin, __ΩBabelTransformPluginBuilder, __ΩBabelTransformPluginBuilderParams, __ΩBabelTransformPluginFilter, __ΩBabelTransformPluginOptions, __ΩBabelUserConfig, __ΩDeclareBabelTransformPluginReturn, __ΩDefaultImportDefinition, __ΩImportDefinition, __ΩImportSpecifier, __ΩNamedImportDefinition, __ΩResolvedBabelTransformPluginOptions } from "./types/config.cjs";
4
- import { createBabelPlugin } from "./helpers/create-plugin.cjs";
5
- import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin } from "./helpers/filters.cjs";
6
- import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./helpers/module-helpers.cjs";
7
- import { resolveBabelPlugin, resolvePluginFunction } from "./helpers/options.cjs";
8
- import { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig } from "./types/plugin.cjs";
1
+ import { a as parseAst, i as generateFromAst, n as GeneratorResult, r as __ΩGenerateFromAstOptions, t as GenerateFromAstOptions } from "./ast-utils-BrOP-SXX.cjs";
2
+ import { A as __ΩResolvedBabelTransformPluginOptions, C as __ΩBabelTransformPluginOptions, D as __ΩImportDefinition, E as __ΩDefaultImportDefinition, O as __ΩImportSpecifier, S as __ΩBabelTransformPluginFilter, T as __ΩDeclareBabelTransformPluginReturn, _ as __ΩBabelResolvedConfig, a as BabelTransformPluginBuilder, b as __ΩBabelTransformPluginBuilder, c as BabelTransformPluginOptions, d as DefaultImportDefinition, f as ImportDefinition, g as __ΩBabelPluginPass, h as ResolvedBabelTransformPluginOptions, i as BabelTransformPlugin, k as __ΩNamedImportDefinition, l as BabelUserConfig, m as NamedImportDefinition, n as BabelResolvedConfig, o as BabelTransformPluginBuilderParams, p as ImportSpecifier, r as BabelTransformInput, s as BabelTransformPluginFilter, t as BabelPluginPass, u as DeclareBabelTransformPluginReturn, v as __ΩBabelTransformInput, w as __ΩBabelUserConfig, x as __ΩBabelTransformPluginBuilderParams, y as __ΩBabelTransformPlugin } from "./config-B8fQjuSs.cjs";
3
+ import { t as createBabelPlugin } from "./create-plugin-D1_rga7H.cjs";
4
+ import { i as isDuplicatePlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "./filters-xc5uoxxD.cjs";
5
+ import { a as isImportCall, i as getImport, n as addImportsToProgram, o as listExports, r as findExport, s as listImports, t as addImport } from "./module-helpers-BBKb6fKg.cjs";
6
+ import { n as resolvePluginFunction, t as resolveBabelPlugin } from "./options-CNyetWnk.cjs";
7
+ import "./index-C2gUMYkE.cjs";
8
+ import { a as __ΩBabelPluginContext, c as __ΩBabelPluginUserConfig, i as BabelPluginUserConfig, n as BabelPluginOptions, o as __ΩBabelPluginOptions, r as BabelPluginResolvedConfig, s as __ΩBabelPluginResolvedConfig, t as BabelPluginContext } from "./plugin-10Y9IjgN.cjs";
9
+ import "./index-uTS5iDq_.cjs";
10
+ import { Plugin } from "@powerlines/core/types";
9
11
 
10
12
  //#region src/index.d.ts
11
13
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;AAyCa,cAAA,MA8HZ,EAAA,CAAA,iBA7HkB,kBA6HlB,GA7HuC,kBA6HvC,CAAA,CAAA,OAAA,CAAA,EA3HU,kBA2HV,EAAA,GA1HE,MA0HF,CA1HS,QA0HT,CAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;cAyCa,0BACM,qBAAqB,8BAE7B,uBACR,OAAO"}
package/dist/index.d.mts CHANGED
@@ -1,14 +1,13 @@
1
- import { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, generateFromAst, parseAst } from "./helpers/ast-utils.mjs";
2
- import { Plugin } from "./core/src/types/plugin.mjs";
3
- import "./core/src/types/index.mjs";
4
- import { BabelPluginPass, BabelResolvedConfig, BabelTransformInput, BabelTransformPlugin, BabelTransformPluginBuilder, BabelTransformPluginBuilderParams, BabelTransformPluginFilter, BabelTransformPluginOptions, BabelUserConfig, DeclareBabelTransformPluginReturn, DefaultImportDefinition, ImportDefinition, ImportSpecifier, NamedImportDefinition, ResolvedBabelTransformPluginOptions, __ΩBabelPluginPass, __ΩBabelResolvedConfig, __ΩBabelTransformInput, __ΩBabelTransformPlugin, __ΩBabelTransformPluginBuilder, __ΩBabelTransformPluginBuilderParams, __ΩBabelTransformPluginFilter, __ΩBabelTransformPluginOptions, __ΩBabelUserConfig, __ΩDeclareBabelTransformPluginReturn, __ΩDefaultImportDefinition, __ΩImportDefinition, __ΩImportSpecifier, __ΩNamedImportDefinition, __ΩResolvedBabelTransformPluginOptions } from "./types/config.mjs";
5
- import { createBabelPlugin } from "./helpers/create-plugin.mjs";
6
- import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin } from "./helpers/filters.mjs";
7
- import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./helpers/module-helpers.mjs";
8
- import { resolveBabelPlugin, resolvePluginFunction } from "./helpers/options.mjs";
9
- import "./helpers/index.mjs";
10
- import { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig } from "./types/plugin.mjs";
11
- import "./types/index.mjs";
1
+ import { a as parseAst, i as generateFromAst, n as GeneratorResult, r as __ΩGenerateFromAstOptions, t as GenerateFromAstOptions } from "./ast-utils-c95WpQzC.mjs";
2
+ import { A as __ΩResolvedBabelTransformPluginOptions, C as __ΩBabelTransformPluginOptions, D as __ΩImportDefinition, E as __ΩDefaultImportDefinition, O as __ΩImportSpecifier, S as __ΩBabelTransformPluginFilter, T as __ΩDeclareBabelTransformPluginReturn, _ as __ΩBabelResolvedConfig, a as BabelTransformPluginBuilder, b as __ΩBabelTransformPluginBuilder, c as BabelTransformPluginOptions, d as DefaultImportDefinition, f as ImportDefinition, g as __ΩBabelPluginPass, h as ResolvedBabelTransformPluginOptions, i as BabelTransformPlugin, k as __ΩNamedImportDefinition, l as BabelUserConfig, m as NamedImportDefinition, n as BabelResolvedConfig, o as BabelTransformPluginBuilderParams, p as ImportSpecifier, r as BabelTransformInput, s as BabelTransformPluginFilter, t as BabelPluginPass, u as DeclareBabelTransformPluginReturn, v as __ΩBabelTransformInput, w as __ΩBabelUserConfig, x as __ΩBabelTransformPluginBuilderParams, y as __ΩBabelTransformPlugin } from "./config-BGnCc0aq.mjs";
3
+ import { t as createBabelPlugin } from "./create-plugin-H35OVSz7.mjs";
4
+ import { i as isDuplicatePlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "./filters-DX-_VLWz.mjs";
5
+ import { a as isImportCall, i as getImport, n as addImportsToProgram, o as listExports, r as findExport, s as listImports, t as addImport } from "./module-helpers-B913A2FR.mjs";
6
+ import { n as resolvePluginFunction, t as resolveBabelPlugin } from "./options-Z_v0-Y5V.mjs";
7
+ import "./index-OEBbnNdr.mjs";
8
+ import { a as __ΩBabelPluginContext, c as __ΩBabelPluginUserConfig, i as BabelPluginUserConfig, n as BabelPluginOptions, o as __ΩBabelPluginOptions, r as BabelPluginResolvedConfig, s as __ΩBabelPluginResolvedConfig, t as BabelPluginContext } from "./plugin-25m6BdNV.mjs";
9
+ import "./index-D8dPsry7.mjs";
10
+ import { Plugin } from "@powerlines/core/types";
12
11
 
13
12
  //#region src/index.d.ts
14
13
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;cAyCa,0BACM,qBAAqB,8BAE7B,uBACR,OAAO"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;cAyCa,0BACM,qBAAqB,8BAE7B,uBACR,OAAO"}
package/dist/index.mjs CHANGED
@@ -1,9 +1,12 @@
1
- import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin } from "./helpers/filters.mjs";
2
- import { resolveBabelPlugin, resolvePluginFunction } from "./helpers/options.mjs";
3
- import { generateFromAst, parseAst } from "./helpers/ast-utils.mjs";
4
- import { createBabelPlugin } from "./helpers/create-plugin.mjs";
5
- import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./helpers/module-helpers.mjs";
6
- import "./helpers/index.mjs";
1
+ import { i as isDuplicatePlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "./filters-DjAUc6r9.mjs";
2
+ import { n as resolvePluginFunction, t as resolveBabelPlugin } from "./options-DT_wvMGu.mjs";
3
+ import { n as parseAst, t as generateFromAst } from "./ast-utils-BgcE0CUh.mjs";
4
+ import { t as createBabelPlugin } from "./create-plugin-BbG_dRTl.mjs";
5
+ import { a as isImportCall, i as getImport, n as addImportsToProgram, o as listExports, r as findExport, s as listImports, t as addImport } from "./module-helpers-DtOc93YQ.mjs";
6
+ import "./helpers-DemUUgdw.mjs";
7
+ import "./config-BLkkDfsC.mjs";
8
+ import "./plugin-BX9Q6Mnb.mjs";
9
+ import "./types-Bjn15Uy6.mjs";
7
10
  import { transformAsync } from "@babel/core";
8
11
  import { findFileExtension, findFileExtensionSafe } from "@stryke/path/file-path-fns";
9
12
  import { isParentPath } from "@stryke/path/is-parent-path";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["plugin"],"sources":["../src/index.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 { transformAsync } from \"@babel/core\";\nimport type { Plugin } from \"@powerlines/core/types\";\nimport {\n findFileExtension,\n findFileExtensionSafe\n} from \"@stryke/path/file-path-fns\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport defu from \"defu\";\nimport { isDuplicatePlugin } from \"./helpers/filters\";\nimport { resolveBabelPlugin } from \"./helpers/options\";\nimport { ResolvedBabelTransformPluginOptions } from \"./types/config\";\nimport { BabelPluginContext, BabelPluginOptions } from \"./types/plugin\";\n\nexport * from \"./helpers\";\nexport * from \"./types\";\n\n/**\n * Babel plugin for Powerlines.\n *\n * @param options - The Babel plugin user configuration options.\n * @returns A Powerlines plugin that integrates Babel transformations.\n */\nexport const plugin = <\n TContext extends BabelPluginContext = BabelPluginContext\n>(\n options: BabelPluginOptions = {}\n): Plugin<TContext> => {\n return {\n name: \"babel\",\n config() {\n if (!isSetObject(options)) {\n return undefined;\n }\n\n return {\n babel: options\n };\n },\n configResolved: {\n order: \"pre\",\n handler() {\n this.config.babel = defu(this.config.babel ?? {}, {\n plugins: [],\n presets: []\n });\n }\n },\n async transform(code: string, id: string) {\n if (\n isParentPath(id, this.powerlinesPath) ||\n code.includes(\"/* @powerlines-ignore */\") ||\n code.includes(\"/* @powerlines-disable */\")\n ) {\n this.trace(`Skipping Babel transformation for: ${id}`);\n\n return { code, id };\n }\n\n const plugins = this.config.babel.plugins\n .map(plugin => resolveBabelPlugin(this, code, id, plugin))\n .filter(\n (plugin, _, arr) => plugin && !isDuplicatePlugin(arr, plugin)\n ) as ResolvedBabelTransformPluginOptions[];\n const presets = this.config.babel.presets\n .map(preset => resolveBabelPlugin(this, code, id, preset))\n .filter(\n (preset, _, arr) => preset && !isDuplicatePlugin(arr, preset)\n ) as ResolvedBabelTransformPluginOptions[];\n\n if (\n Array.isArray(plugins) &&\n plugins.length === 0 &&\n Array.isArray(presets) &&\n presets.length === 0\n ) {\n return { code, id };\n }\n\n if (\n /^(?:m|c)?tsx?$/.test(\n findFileExtensionSafe(id, {\n fullExtension: true\n })\n ) &&\n !isDuplicatePlugin(plugins, \"@babel/plugin-syntax-typescript\") &&\n !isDuplicatePlugin(presets, \"@babel/preset-typescript\")\n ) {\n plugins.unshift([\n \"@babel/plugin-syntax-typescript\",\n { isTSX: findFileExtension(id) === \"tsx\" }\n ]);\n }\n\n this.trace(\n `Running babel transformations with ${plugins.length} plugins and ${\n presets.length\n } presets for file: ${id}`\n );\n\n const result = await transformAsync(code, {\n highlightCode: true,\n code: true,\n ast: false,\n cloneInputAst: false,\n comments: true,\n sourceType: \"module\",\n configFile: false,\n babelrc: false,\n envName: this.config.mode,\n caller: {\n name: this.config.framework\n },\n ...(this.config.babel ?? {}),\n filename: id,\n plugins: plugins\n .map(plugin => {\n return Array.isArray(plugin) && plugin.length >= 2\n ? [\n plugin[0],\n defu(plugin.length > 1 && plugin[1] ? plugin[1] : {}, {\n options\n })\n ]\n : plugin;\n })\n .filter(Boolean),\n presets: presets\n .map(preset => {\n return Array.isArray(preset) && preset.length >= 2\n ? [\n preset[0],\n defu(preset.length > 1 && preset[1] ? preset[1] : {}, {\n options\n })\n ]\n : preset;\n })\n .filter(Boolean)\n });\n if (!result?.code) {\n throw new Error(`Powerlines - Babel plugin failed to compile ${id}`);\n }\n\n this.trace(`Completed babel transformations for file: ${id}`);\n\n return { code: result.code, id };\n }\n } as Plugin<TContext>;\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyCA,MAAa,UAGX,UAA8B,EAAE,KACX;AACrB,QAAO;EACL,MAAM;EACN,SAAS;AACP,OAAI,CAAC,YAAY,QAAQ,CACvB;AAGF,UAAO,EACL,OAAO,SACR;;EAEH,gBAAgB;GACd,OAAO;GACP,UAAU;AACR,SAAK,OAAO,QAAQ,KAAK,KAAK,OAAO,SAAS,EAAE,EAAE;KAChD,SAAS,EAAE;KACX,SAAS,EAAE;KACZ,CAAC;;GAEL;EACD,MAAM,UAAU,MAAc,IAAY;AACxC,OACE,aAAa,IAAI,KAAK,eAAe,IACrC,KAAK,SAAS,2BAA2B,IACzC,KAAK,SAAS,4BAA4B,EAC1C;AACA,SAAK,MAAM,sCAAsC,KAAK;AAEtD,WAAO;KAAE;KAAM;KAAI;;GAGrB,MAAM,UAAU,KAAK,OAAO,MAAM,QAC/B,KAAI,aAAU,mBAAmB,MAAM,MAAM,IAAIA,SAAO,CAAC,CACzD,QACE,UAAQ,GAAG,QAAQA,YAAU,CAAC,kBAAkB,KAAKA,SAAO,CAC9D;GACH,MAAM,UAAU,KAAK,OAAO,MAAM,QAC/B,KAAI,WAAU,mBAAmB,MAAM,MAAM,IAAI,OAAO,CAAC,CACzD,QACE,QAAQ,GAAG,QAAQ,UAAU,CAAC,kBAAkB,KAAK,OAAO,CAC9D;AAEH,OACE,MAAM,QAAQ,QAAQ,IACtB,QAAQ,WAAW,KACnB,MAAM,QAAQ,QAAQ,IACtB,QAAQ,WAAW,EAEnB,QAAO;IAAE;IAAM;IAAI;AAGrB,OACE,iBAAiB,KACf,sBAAsB,IAAI,EACxB,eAAe,MAChB,CAAC,CACH,IACD,CAAC,kBAAkB,SAAS,kCAAkC,IAC9D,CAAC,kBAAkB,SAAS,2BAA2B,CAEvD,SAAQ,QAAQ,CACd,mCACA,EAAE,OAAO,kBAAkB,GAAG,KAAK,OAAO,CAC3C,CAAC;AAGJ,QAAK,MACH,sCAAsC,QAAQ,OAAO,eACnD,QAAQ,OACT,qBAAqB,KACvB;GAED,MAAM,SAAS,MAAM,eAAe,MAAM;IACxC,eAAe;IACf,MAAM;IACN,KAAK;IACL,eAAe;IACf,UAAU;IACV,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,SAAS,KAAK,OAAO;IACrB,QAAQ,EACN,MAAM,KAAK,OAAO,WACnB;IACD,GAAI,KAAK,OAAO,SAAS,EAAE;IAC3B,UAAU;IACV,SAAS,QACN,KAAI,aAAU;AACb,YAAO,MAAM,QAAQA,SAAO,IAAIA,SAAO,UAAU,IAC7C,CACEA,SAAO,IACP,KAAKA,SAAO,SAAS,KAAKA,SAAO,KAAKA,SAAO,KAAK,EAAE,EAAE,EACpD,SACD,CAAC,CACH,GACDA;MACJ,CACD,OAAO,QAAQ;IAClB,SAAS,QACN,KAAI,WAAU;AACb,YAAO,MAAM,QAAQ,OAAO,IAAI,OAAO,UAAU,IAC7C,CACE,OAAO,IACP,KAAK,OAAO,SAAS,KAAK,OAAO,KAAK,OAAO,KAAK,EAAE,EAAE,EACpD,SACD,CAAC,CACH,GACD;MACJ,CACD,OAAO,QAAQ;IACnB,CAAC;AACF,OAAI,CAAC,QAAQ,KACX,OAAM,IAAI,MAAM,+CAA+C,KAAK;AAGtE,QAAK,MAAM,6CAA6C,KAAK;AAE7D,UAAO;IAAE,MAAM,OAAO;IAAM;IAAI;;EAEnC;;AAGH,kBAAe"}
1
+ {"version":3,"file":"index.mjs","names":["plugin"],"sources":["../src/index.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 { transformAsync } from \"@babel/core\";\nimport type { Plugin } from \"@powerlines/core/types\";\nimport {\n findFileExtension,\n findFileExtensionSafe\n} from \"@stryke/path/file-path-fns\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport defu from \"defu\";\nimport { isDuplicatePlugin } from \"./helpers/filters\";\nimport { resolveBabelPlugin } from \"./helpers/options\";\nimport { ResolvedBabelTransformPluginOptions } from \"./types/config\";\nimport { BabelPluginContext, BabelPluginOptions } from \"./types/plugin\";\n\nexport * from \"./helpers\";\nexport * from \"./types\";\n\n/**\n * Babel plugin for Powerlines.\n *\n * @param options - The Babel plugin user configuration options.\n * @returns A Powerlines plugin that integrates Babel transformations.\n */\nexport const plugin = <\n TContext extends BabelPluginContext = BabelPluginContext\n>(\n options: BabelPluginOptions = {}\n): Plugin<TContext> => {\n return {\n name: \"babel\",\n config() {\n if (!isSetObject(options)) {\n return undefined;\n }\n\n return {\n babel: options\n };\n },\n configResolved: {\n order: \"pre\",\n handler() {\n this.config.babel = defu(this.config.babel ?? {}, {\n plugins: [],\n presets: []\n });\n }\n },\n async transform(code: string, id: string) {\n if (\n isParentPath(id, this.powerlinesPath) ||\n code.includes(\"/* @powerlines-ignore */\") ||\n code.includes(\"/* @powerlines-disable */\")\n ) {\n this.trace(`Skipping Babel transformation for: ${id}`);\n\n return { code, id };\n }\n\n const plugins = this.config.babel.plugins\n .map(plugin => resolveBabelPlugin(this, code, id, plugin))\n .filter(\n (plugin, _, arr) => plugin && !isDuplicatePlugin(arr, plugin)\n ) as ResolvedBabelTransformPluginOptions[];\n const presets = this.config.babel.presets\n .map(preset => resolveBabelPlugin(this, code, id, preset))\n .filter(\n (preset, _, arr) => preset && !isDuplicatePlugin(arr, preset)\n ) as ResolvedBabelTransformPluginOptions[];\n\n if (\n Array.isArray(plugins) &&\n plugins.length === 0 &&\n Array.isArray(presets) &&\n presets.length === 0\n ) {\n return { code, id };\n }\n\n if (\n /^(?:m|c)?tsx?$/.test(\n findFileExtensionSafe(id, {\n fullExtension: true\n })\n ) &&\n !isDuplicatePlugin(plugins, \"@babel/plugin-syntax-typescript\") &&\n !isDuplicatePlugin(presets, \"@babel/preset-typescript\")\n ) {\n plugins.unshift([\n \"@babel/plugin-syntax-typescript\",\n { isTSX: findFileExtension(id) === \"tsx\" }\n ]);\n }\n\n this.trace(\n `Running babel transformations with ${plugins.length} plugins and ${\n presets.length\n } presets for file: ${id}`\n );\n\n const result = await transformAsync(code, {\n highlightCode: true,\n code: true,\n ast: false,\n cloneInputAst: false,\n comments: true,\n sourceType: \"module\",\n configFile: false,\n babelrc: false,\n envName: this.config.mode,\n caller: {\n name: this.config.framework\n },\n ...(this.config.babel ?? {}),\n filename: id,\n plugins: plugins\n .map(plugin => {\n return Array.isArray(plugin) && plugin.length >= 2\n ? [\n plugin[0],\n defu(plugin.length > 1 && plugin[1] ? plugin[1] : {}, {\n options\n })\n ]\n : plugin;\n })\n .filter(Boolean),\n presets: presets\n .map(preset => {\n return Array.isArray(preset) && preset.length >= 2\n ? [\n preset[0],\n defu(preset.length > 1 && preset[1] ? preset[1] : {}, {\n options\n })\n ]\n : preset;\n })\n .filter(Boolean)\n });\n if (!result?.code) {\n throw new Error(`Powerlines - Babel plugin failed to compile ${id}`);\n }\n\n this.trace(`Completed babel transformations for file: ${id}`);\n\n return { code: result.code, id };\n }\n } as Plugin<TContext>;\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAyCA,MAAa,UAGX,UAA8B,EAAE,KACX;AACrB,QAAO;EACL,MAAM;EACN,SAAS;AACP,OAAI,CAAC,YAAY,QAAQ,CACvB;AAGF,UAAO,EACL,OAAO,SACR;;EAEH,gBAAgB;GACd,OAAO;GACP,UAAU;AACR,SAAK,OAAO,QAAQ,KAAK,KAAK,OAAO,SAAS,EAAE,EAAE;KAChD,SAAS,EAAE;KACX,SAAS,EAAE;KACZ,CAAC;;GAEL;EACD,MAAM,UAAU,MAAc,IAAY;AACxC,OACE,aAAa,IAAI,KAAK,eAAe,IACrC,KAAK,SAAS,2BAA2B,IACzC,KAAK,SAAS,4BAA4B,EAC1C;AACA,SAAK,MAAM,sCAAsC,KAAK;AAEtD,WAAO;KAAE;KAAM;KAAI;;GAGrB,MAAM,UAAU,KAAK,OAAO,MAAM,QAC/B,KAAI,aAAU,mBAAmB,MAAM,MAAM,IAAIA,SAAO,CAAC,CACzD,QACE,UAAQ,GAAG,QAAQA,YAAU,CAAC,kBAAkB,KAAKA,SAAO,CAC9D;GACH,MAAM,UAAU,KAAK,OAAO,MAAM,QAC/B,KAAI,WAAU,mBAAmB,MAAM,MAAM,IAAI,OAAO,CAAC,CACzD,QACE,QAAQ,GAAG,QAAQ,UAAU,CAAC,kBAAkB,KAAK,OAAO,CAC9D;AAEH,OACE,MAAM,QAAQ,QAAQ,IACtB,QAAQ,WAAW,KACnB,MAAM,QAAQ,QAAQ,IACtB,QAAQ,WAAW,EAEnB,QAAO;IAAE;IAAM;IAAI;AAGrB,OACE,iBAAiB,KACf,sBAAsB,IAAI,EACxB,eAAe,MAChB,CAAC,CACH,IACD,CAAC,kBAAkB,SAAS,kCAAkC,IAC9D,CAAC,kBAAkB,SAAS,2BAA2B,CAEvD,SAAQ,QAAQ,CACd,mCACA,EAAE,OAAO,kBAAkB,GAAG,KAAK,OAAO,CAC3C,CAAC;AAGJ,QAAK,MACH,sCAAsC,QAAQ,OAAO,eACnD,QAAQ,OACT,qBAAqB,KACvB;GAED,MAAM,SAAS,MAAM,eAAe,MAAM;IACxC,eAAe;IACf,MAAM;IACN,KAAK;IACL,eAAe;IACf,UAAU;IACV,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,SAAS,KAAK,OAAO;IACrB,QAAQ,EACN,MAAM,KAAK,OAAO,WACnB;IACD,GAAI,KAAK,OAAO,SAAS,EAAE;IAC3B,UAAU;IACV,SAAS,QACN,KAAI,aAAU;AACb,YAAO,MAAM,QAAQA,SAAO,IAAIA,SAAO,UAAU,IAC7C,CACEA,SAAO,IACP,KAAKA,SAAO,SAAS,KAAKA,SAAO,KAAKA,SAAO,KAAK,EAAE,EAAE,EACpD,SACD,CAAC,CACH,GACDA;MACJ,CACD,OAAO,QAAQ;IAClB,SAAS,QACN,KAAI,WAAU;AACb,YAAO,MAAM,QAAQ,OAAO,IAAI,OAAO,UAAU,IAC7C,CACE,OAAO,IACP,KAAK,OAAO,SAAS,KAAK,OAAO,KAAK,OAAO,KAAK,EAAE,EAAE,EACpD,SACD,CAAC,CACH,GACD;MACJ,CACD,OAAO,QAAQ;IACnB,CAAC;AACF,OAAI,CAAC,QAAQ,KACX,OAAM,IAAI,MAAM,+CAA+C,KAAK;AAGtE,QAAK,MAAM,6CAA6C,KAAK;AAE7D,UAAO;IAAE,MAAM,OAAO;IAAM;IAAI;;EAEnC;;AAGH,kBAAe"}
@@ -0,0 +1,50 @@
1
+ import { p as ImportSpecifier } from "./config-BGnCc0aq.mjs";
2
+ import { NodePath } from "@babel/core";
3
+ import { ParseResult } from "@babel/parser";
4
+ import * as t from "@babel/types";
5
+
6
+ //#region src/helpers/module-helpers.d.ts
7
+
8
+ /**
9
+ * Finds an export in the given Babel AST program by its key.
10
+ *
11
+ * @param ast - The parsed Babel AST result containing the program body.
12
+ * @param key - The name of the export to find (e.g., "default" or a named export).
13
+ * @returns The declaration of the export if found, otherwise undefined.
14
+ */
15
+ declare function findExport(ast: ParseResult<t.File>, key: string): any;
16
+ /**
17
+ * Lists all exports from the given Babel AST program.
18
+ *
19
+ * @param codeOrAst - The parsed Babel AST result containing the program body.
20
+ * @returns An array of export names, including "default" for default exports.
21
+ */
22
+ declare function listExports(codeOrAst: ParseResult<t.File> | string): string[];
23
+ /**
24
+ * Lists all imports from the given Babel AST program.
25
+ *
26
+ * @param ast - The parsed Babel AST result containing the program body.
27
+ * @returns An array of import names, including "default" for default imports.
28
+ */
29
+ declare function listImports(ast: ParseResult<t.File> | t.File): string[];
30
+ declare function isImportCall(calleePath: NodePath<t.CallExpression | t.NewExpression>): boolean;
31
+ /**
32
+ * Gets the import declaration for a given name and specifier.
33
+ *
34
+ * @param specifier - The specifier of the import.
35
+ * @param name - The name of the import.
36
+ * @param named - Optional named import.
37
+ * @returns The import declaration.
38
+ */
39
+ declare function getImport(specifier: string, name: string, named?: string): t.ImportDeclaration;
40
+ /**
41
+ * Adds an import to the program if it doesn't already exist.
42
+ *
43
+ * @param path - The current NodePath in the AST.
44
+ * @param specifier - The import specifier.
45
+ */
46
+ declare function addImport(path: NodePath<any>, specifier: ImportSpecifier): void;
47
+ declare function addImportsToProgram(path: NodePath<t.Program>, specifier: ImportSpecifier): void;
48
+ //#endregion
49
+ export { isImportCall as a, getImport as i, addImportsToProgram as n, listExports as o, findExport as r, listImports as s, addImport as t };
50
+ //# sourceMappingURL=module-helpers-B913A2FR.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-helpers-B913A2FR.d.mts","names":[],"sources":["../src/helpers/module-helpers.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAgCA;AA6BA;AA4BA;;;AAAyD,iBAzDzC,UAAA,CAyDyC,GAAA,EAzDzB,WAyDyB,CAzDb,CAAA,CAAE,IAyDW,CAAA,EAAA,GAAA,EAAA,MAAA,CAAA,EAAA,GAAA;;AAsBzD;;;;;AAcgB,iBAhEA,WAAA,CAoEX,SAAA,EApEkC,WAoEjB,CApE6B,CAAA,CAAE,IAoE/B,CAAA,GAAA,MAAA,CAAA,EAAA,MAAA,EAAA;AAatB;AAuCA;;;;;iBA5FgB,WAAA,MAAiB,YAAY,CAAA,CAAE,QAAQ,CAAA,CAAE;iBAsBzC,YAAA,aACF,SAAS,CAAA,CAAE,iBAAiB,CAAA,CAAE;;;;;;;;;iBAa5B,SAAA,mDAIb,CAAA,CAAE;;;;;;;iBAaW,SAAA,OAAgB,0BAA0B;iBAuC1C,mBAAA,OACR,SAAS,CAAA,CAAE,qBACN"}
@@ -0,0 +1,50 @@
1
+ import { p as ImportSpecifier } from "./config-B8fQjuSs.cjs";
2
+ import { ParseResult } from "@babel/parser";
3
+ import * as t from "@babel/types";
4
+ import { NodePath } from "@babel/core";
5
+
6
+ //#region src/helpers/module-helpers.d.ts
7
+
8
+ /**
9
+ * Finds an export in the given Babel AST program by its key.
10
+ *
11
+ * @param ast - The parsed Babel AST result containing the program body.
12
+ * @param key - The name of the export to find (e.g., "default" or a named export).
13
+ * @returns The declaration of the export if found, otherwise undefined.
14
+ */
15
+ declare function findExport(ast: ParseResult<t.File>, key: string): any;
16
+ /**
17
+ * Lists all exports from the given Babel AST program.
18
+ *
19
+ * @param codeOrAst - The parsed Babel AST result containing the program body.
20
+ * @returns An array of export names, including "default" for default exports.
21
+ */
22
+ declare function listExports(codeOrAst: ParseResult<t.File> | string): string[];
23
+ /**
24
+ * Lists all imports from the given Babel AST program.
25
+ *
26
+ * @param ast - The parsed Babel AST result containing the program body.
27
+ * @returns An array of import names, including "default" for default imports.
28
+ */
29
+ declare function listImports(ast: ParseResult<t.File> | t.File): string[];
30
+ declare function isImportCall(calleePath: NodePath<t.CallExpression | t.NewExpression>): boolean;
31
+ /**
32
+ * Gets the import declaration for a given name and specifier.
33
+ *
34
+ * @param specifier - The specifier of the import.
35
+ * @param name - The name of the import.
36
+ * @param named - Optional named import.
37
+ * @returns The import declaration.
38
+ */
39
+ declare function getImport(specifier: string, name: string, named?: string): t.ImportDeclaration;
40
+ /**
41
+ * Adds an import to the program if it doesn't already exist.
42
+ *
43
+ * @param path - The current NodePath in the AST.
44
+ * @param specifier - The import specifier.
45
+ */
46
+ declare function addImport(path: NodePath<any>, specifier: ImportSpecifier): void;
47
+ declare function addImportsToProgram(path: NodePath<t.Program>, specifier: ImportSpecifier): void;
48
+ //#endregion
49
+ export { isImportCall as a, getImport as i, addImportsToProgram as n, listExports as o, findExport as r, listImports as s, addImport as t };
50
+ //# sourceMappingURL=module-helpers-BBKb6fKg.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-helpers-BBKb6fKg.d.cts","names":[],"sources":["../src/helpers/module-helpers.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAgCA;AA6BA;AA4BA;;;AAAyD,iBAzDzC,UAAA,CAyDyC,GAAA,EAzDzB,WAyDyB,CAzDb,CAAA,CAAE,IAyDW,CAAA,EAAA,GAAA,EAAA,MAAA,CAAA,EAAA,GAAA;;AAsBzD;;;;;AAcgB,iBAhEA,WAAA,CAoEX,SAAA,EApEkC,WAoEjB,CApE6B,CAAA,CAAE,IAoE/B,CAAA,GAAA,MAAA,CAAA,EAAA,MAAA,EAAA;AAatB;AAuCA;;;;;iBA5FgB,WAAA,MAAiB,YAAY,CAAA,CAAE,QAAQ,CAAA,CAAE;iBAsBzC,YAAA,aACF,SAAS,CAAA,CAAE,iBAAiB,CAAA,CAAE;;;;;;;;;iBAa5B,SAAA,mDAIb,CAAA,CAAE;;;;;;;iBAaW,SAAA,OAAgB,0BAA0B;iBAuC1C,mBAAA,OACR,SAAS,CAAA,CAAE,qBACN"}
@@ -0,0 +1,96 @@
1
+ import { n as parseAst } from "./ast-utils-BgcE0CUh.mjs";
2
+ import * as t from "@babel/types";
3
+ import { isString } from "@stryke/type-checks/is-string";
4
+
5
+ //#region src/helpers/module-helpers.ts
6
+ /**
7
+ * Finds an export in the given Babel AST program by its key.
8
+ *
9
+ * @param ast - The parsed Babel AST result containing the program body.
10
+ * @param key - The name of the export to find (e.g., "default" or a named export).
11
+ * @returns The declaration of the export if found, otherwise undefined.
12
+ */
13
+ function findExport(ast, key) {
14
+ const type = key === "default" ? "ExportDefaultDeclaration" : "ExportNamedDeclaration";
15
+ for (const node of ast.program.body) if (node.type === type) {
16
+ if (key === "default") return node.declaration;
17
+ if (node.declaration && "declarations" in node.declaration) {
18
+ const declaration = node.declaration.declarations[0];
19
+ if (declaration && "name" in declaration.id && declaration.id.name === key) return declaration.init;
20
+ }
21
+ }
22
+ }
23
+ /**
24
+ * Lists all exports from the given Babel AST program.
25
+ *
26
+ * @param codeOrAst - The parsed Babel AST result containing the program body.
27
+ * @returns An array of export names, including "default" for default exports.
28
+ */
29
+ function listExports(codeOrAst) {
30
+ return (isString(codeOrAst) ? parseAst(codeOrAst) : codeOrAst).program.body.flatMap((i) => {
31
+ if (i.type === "ExportDefaultDeclaration") return ["default"];
32
+ if (i.type === "ExportNamedDeclaration" && i.declaration && "declarations" in i.declaration) return i.declaration.declarations.map((d) => "name" in d.id ? d.id.name : "");
33
+ return [];
34
+ }).filter(Boolean);
35
+ }
36
+ /**
37
+ * Lists all imports from the given Babel AST program.
38
+ *
39
+ * @param ast - The parsed Babel AST result containing the program body.
40
+ * @returns An array of import names, including "default" for default imports.
41
+ */
42
+ function listImports(ast) {
43
+ return ast.program.body.flatMap((i) => {
44
+ if (i.type === "ImportDeclaration") return i.specifiers.map((s) => {
45
+ if (s.type === "ImportDefaultSpecifier") return "default";
46
+ if (s.type === "ImportSpecifier" && "imported" in s) return s.imported.type === "Identifier" ? s.imported.name : s.imported.value;
47
+ return "";
48
+ });
49
+ return [];
50
+ }).filter(Boolean);
51
+ }
52
+ function isImportCall(calleePath) {
53
+ return t.isImport(calleePath.node.callee);
54
+ }
55
+ /**
56
+ * Gets the import declaration for a given name and specifier.
57
+ *
58
+ * @param specifier - The specifier of the import.
59
+ * @param name - The name of the import.
60
+ * @param named - Optional named import.
61
+ * @returns The import declaration.
62
+ */
63
+ function getImport(specifier, name, named) {
64
+ return t.importDeclaration([t.importSpecifier(t.identifier(name), t.stringLiteral(named || name))], t.stringLiteral(specifier));
65
+ }
66
+ /**
67
+ * Adds an import to the program if it doesn't already exist.
68
+ *
69
+ * @param path - The current NodePath in the AST.
70
+ * @param specifier - The import specifier.
71
+ */
72
+ function addImport(path, specifier) {
73
+ addImportsToProgram(path.scope.getProgramParent().path, specifier);
74
+ }
75
+ function isNonNamespacedImport(importDeclPath) {
76
+ return importDeclPath.get("specifiers").filter(Boolean).every((specifier) => specifier?.isImportSpecifier()) && importDeclPath.node.importKind !== "type" && importDeclPath.node.importKind !== "typeof";
77
+ }
78
+ function getExistingImports(program) {
79
+ const existingImports = /* @__PURE__ */ new Map();
80
+ program.traverse({ ImportDeclaration(path) {
81
+ if (isNonNamespacedImport(path)) existingImports.set(path.node.source.value, path);
82
+ } });
83
+ return existingImports;
84
+ }
85
+ function addImportsToProgram(path, specifier) {
86
+ /**
87
+ * If an existing import of this module exists (ie \`import \{ ... \} from
88
+ * '<moduleName>'\`), inject new imported specifiers into the list of
89
+ * destructured variables.
90
+ */
91
+ if (!getExistingImports(path).get(specifier.module)) path.unshiftContainer("body", t.importDeclaration([t.importSpecifier(t.identifier(specifier.name || specifier.imported), t.identifier(specifier.imported))], t.stringLiteral(specifier.module)));
92
+ }
93
+
94
+ //#endregion
95
+ export { isImportCall as a, getImport as i, addImportsToProgram as n, listExports as o, findExport as r, listImports as s, addImport as t };
96
+ //# sourceMappingURL=module-helpers-DtOc93YQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-helpers-DtOc93YQ.mjs","names":[],"sources":["../src/helpers/module-helpers.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 { NodePath } from \"@babel/core\";\nimport { ParseResult } from \"@babel/parser\";\nimport * as t from \"@babel/types\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { ImportSpecifier } from \"../types/config\";\nimport { parseAst } from \"./ast-utils\";\n\n/**\n * Finds an export in the given Babel AST program by its key.\n *\n * @param ast - The parsed Babel AST result containing the program body.\n * @param key - The name of the export to find (e.g., \"default\" or a named export).\n * @returns The declaration of the export if found, otherwise undefined.\n */\nexport function findExport(ast: ParseResult<t.File>, key: string) {\n const type =\n key === \"default\" ? \"ExportDefaultDeclaration\" : \"ExportNamedDeclaration\";\n\n for (const node of ast.program.body) {\n if (node.type === type) {\n if (key === \"default\") {\n return node.declaration;\n }\n if (node.declaration && \"declarations\" in node.declaration) {\n const declaration = node.declaration.declarations[0];\n if (\n declaration &&\n \"name\" in declaration.id &&\n declaration.id.name === key\n ) {\n return declaration.init as any;\n }\n }\n }\n }\n}\n\n/**\n * Lists all exports from the given Babel AST program.\n *\n * @param codeOrAst - The parsed Babel AST result containing the program body.\n * @returns An array of export names, including \"default\" for default exports.\n */\nexport function listExports(codeOrAst: ParseResult<t.File> | string) {\n const ast = isString(codeOrAst) ? parseAst(codeOrAst) : codeOrAst;\n\n return ast.program.body\n .flatMap(i => {\n if (i.type === \"ExportDefaultDeclaration\") {\n return [\"default\"];\n }\n if (\n i.type === \"ExportNamedDeclaration\" &&\n i.declaration &&\n \"declarations\" in i.declaration\n ) {\n return i.declaration.declarations.map(d =>\n \"name\" in d.id ? d.id.name : \"\"\n );\n }\n return [];\n })\n .filter(Boolean);\n}\n\n/**\n * Lists all imports from the given Babel AST program.\n *\n * @param ast - The parsed Babel AST result containing the program body.\n * @returns An array of import names, including \"default\" for default imports.\n */\nexport function listImports(ast: ParseResult<t.File> | t.File) {\n return ast.program.body\n .flatMap(i => {\n if (i.type === \"ImportDeclaration\") {\n return i.specifiers.map(s => {\n if (s.type === \"ImportDefaultSpecifier\") {\n return \"default\";\n }\n if (s.type === \"ImportSpecifier\" && \"imported\" in s) {\n return s.imported.type === \"Identifier\"\n ? s.imported.name\n : s.imported.value;\n }\n return \"\";\n });\n }\n\n return [];\n })\n .filter(Boolean);\n}\n\nexport function isImportCall(\n calleePath: NodePath<t.CallExpression | t.NewExpression>\n) {\n return t.isImport(calleePath.node.callee);\n}\n\n/**\n * Gets the import declaration for a given name and specifier.\n *\n * @param specifier - The specifier of the import.\n * @param name - The name of the import.\n * @param named - Optional named import.\n * @returns The import declaration.\n */\nexport function getImport(\n specifier: string,\n name: string,\n named?: string\n): t.ImportDeclaration {\n return t.importDeclaration(\n [t.importSpecifier(t.identifier(name), t.stringLiteral(named || name))],\n t.stringLiteral(specifier)\n );\n}\n\n/**\n * Adds an import to the program if it doesn't already exist.\n *\n * @param path - The current NodePath in the AST.\n * @param specifier - The import specifier.\n */\nexport function addImport(path: NodePath<any>, specifier: ImportSpecifier) {\n addImportsToProgram(\n path.scope.getProgramParent().path as NodePath<t.Program>,\n specifier\n );\n}\n\n/*\n * Matches `import { ... } from <moduleName>;`\n * but not `import * as React from <moduleName>;`\n * `import type { Foo } from <moduleName>;`\n */\nfunction isNonNamespacedImport(\n importDeclPath: NodePath<t.ImportDeclaration>\n): boolean {\n return (\n importDeclPath\n .get(\"specifiers\")\n .filter(Boolean)\n .every(specifier => specifier?.isImportSpecifier()) &&\n importDeclPath.node.importKind !== \"type\" &&\n importDeclPath.node.importKind !== \"typeof\"\n );\n}\n\nfunction getExistingImports(\n program: NodePath<t.Program>\n): Map<string, NodePath<t.ImportDeclaration>> {\n const existingImports = new Map<string, NodePath<t.ImportDeclaration>>();\n program.traverse({\n ImportDeclaration(path) {\n if (isNonNamespacedImport(path)) {\n existingImports.set(path.node.source.value, path);\n }\n }\n });\n return existingImports;\n}\n\nexport function addImportsToProgram(\n path: NodePath<t.Program>,\n specifier: ImportSpecifier\n): void {\n const existingImports = getExistingImports(path);\n\n /**\n * If an existing import of this module exists (ie \\`import \\{ ... \\} from\n * '<moduleName>'\\`), inject new imported specifiers into the list of\n * destructured variables.\n */\n if (!existingImports.get(specifier.module)) {\n path.unshiftContainer(\n \"body\",\n t.importDeclaration(\n [\n t.importSpecifier(\n t.identifier(specifier.name || specifier.imported),\n t.identifier(specifier.imported)\n )\n ],\n t.stringLiteral(specifier.module)\n )\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AAgCA,SAAgB,WAAW,KAA0B,KAAa;CAChE,MAAM,OACJ,QAAQ,YAAY,6BAA6B;AAEnD,MAAK,MAAM,QAAQ,IAAI,QAAQ,KAC7B,KAAI,KAAK,SAAS,MAAM;AACtB,MAAI,QAAQ,UACV,QAAO,KAAK;AAEd,MAAI,KAAK,eAAe,kBAAkB,KAAK,aAAa;GAC1D,MAAM,cAAc,KAAK,YAAY,aAAa;AAClD,OACE,eACA,UAAU,YAAY,MACtB,YAAY,GAAG,SAAS,IAExB,QAAO,YAAY;;;;;;;;;;AAa7B,SAAgB,YAAY,WAAyC;AAGnE,SAFY,SAAS,UAAU,GAAG,SAAS,UAAU,GAAG,WAE7C,QAAQ,KAChB,SAAQ,MAAK;AACZ,MAAI,EAAE,SAAS,2BACb,QAAO,CAAC,UAAU;AAEpB,MACE,EAAE,SAAS,4BACX,EAAE,eACF,kBAAkB,EAAE,YAEpB,QAAO,EAAE,YAAY,aAAa,KAAI,MACpC,UAAU,EAAE,KAAK,EAAE,GAAG,OAAO,GAC9B;AAEH,SAAO,EAAE;GACT,CACD,OAAO,QAAQ;;;;;;;;AASpB,SAAgB,YAAY,KAAmC;AAC7D,QAAO,IAAI,QAAQ,KAChB,SAAQ,MAAK;AACZ,MAAI,EAAE,SAAS,oBACb,QAAO,EAAE,WAAW,KAAI,MAAK;AAC3B,OAAI,EAAE,SAAS,yBACb,QAAO;AAET,OAAI,EAAE,SAAS,qBAAqB,cAAc,EAChD,QAAO,EAAE,SAAS,SAAS,eACvB,EAAE,SAAS,OACX,EAAE,SAAS;AAEjB,UAAO;IACP;AAGJ,SAAO,EAAE;GACT,CACD,OAAO,QAAQ;;AAGpB,SAAgB,aACd,YACA;AACA,QAAO,EAAE,SAAS,WAAW,KAAK,OAAO;;;;;;;;;;AAW3C,SAAgB,UACd,WACA,MACA,OACqB;AACrB,QAAO,EAAE,kBACP,CAAC,EAAE,gBAAgB,EAAE,WAAW,KAAK,EAAE,EAAE,cAAc,SAAS,KAAK,CAAC,CAAC,EACvE,EAAE,cAAc,UAAU,CAC3B;;;;;;;;AASH,SAAgB,UAAU,MAAqB,WAA4B;AACzE,qBACE,KAAK,MAAM,kBAAkB,CAAC,MAC9B,UACD;;AAQH,SAAS,sBACP,gBACS;AACT,QACE,eACG,IAAI,aAAa,CACjB,OAAO,QAAQ,CACf,OAAM,cAAa,WAAW,mBAAmB,CAAC,IACrD,eAAe,KAAK,eAAe,UACnC,eAAe,KAAK,eAAe;;AAIvC,SAAS,mBACP,SAC4C;CAC5C,MAAM,kCAAkB,IAAI,KAA4C;AACxE,SAAQ,SAAS,EACf,kBAAkB,MAAM;AACtB,MAAI,sBAAsB,KAAK,CAC7B,iBAAgB,IAAI,KAAK,KAAK,OAAO,OAAO,KAAK;IAGtD,CAAC;AACF,QAAO;;AAGT,SAAgB,oBACd,MACA,WACM;;;;;;AAQN,KAAI,CAPoB,mBAAmB,KAAK,CAO3B,IAAI,UAAU,OAAO,CACxC,MAAK,iBACH,QACA,EAAE,kBACA,CACE,EAAE,gBACA,EAAE,WAAW,UAAU,QAAQ,UAAU,SAAS,EAClD,EAAE,WAAW,UAAU,SAAS,CACjC,CACF,EACD,EAAE,cAAc,UAAU,OAAO,CAClC,CACF"}
@@ -0,0 +1,138 @@
1
+ const require_chunk = require('./chunk-CbDLau6x.cjs');
2
+ const require_ast_utils = require('./ast-utils-BcmWaIan.cjs');
3
+ let __babel_types = require("@babel/types");
4
+ __babel_types = require_chunk.__toESM(__babel_types);
5
+ let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
6
+
7
+ //#region src/helpers/module-helpers.ts
8
+ /**
9
+ * Finds an export in the given Babel AST program by its key.
10
+ *
11
+ * @param ast - The parsed Babel AST result containing the program body.
12
+ * @param key - The name of the export to find (e.g., "default" or a named export).
13
+ * @returns The declaration of the export if found, otherwise undefined.
14
+ */
15
+ function findExport(ast, key) {
16
+ const type = key === "default" ? "ExportDefaultDeclaration" : "ExportNamedDeclaration";
17
+ for (const node of ast.program.body) if (node.type === type) {
18
+ if (key === "default") return node.declaration;
19
+ if (node.declaration && "declarations" in node.declaration) {
20
+ const declaration = node.declaration.declarations[0];
21
+ if (declaration && "name" in declaration.id && declaration.id.name === key) return declaration.init;
22
+ }
23
+ }
24
+ }
25
+ /**
26
+ * Lists all exports from the given Babel AST program.
27
+ *
28
+ * @param codeOrAst - The parsed Babel AST result containing the program body.
29
+ * @returns An array of export names, including "default" for default exports.
30
+ */
31
+ function listExports(codeOrAst) {
32
+ return ((0, __stryke_type_checks_is_string.isString)(codeOrAst) ? require_ast_utils.parseAst(codeOrAst) : codeOrAst).program.body.flatMap((i) => {
33
+ if (i.type === "ExportDefaultDeclaration") return ["default"];
34
+ if (i.type === "ExportNamedDeclaration" && i.declaration && "declarations" in i.declaration) return i.declaration.declarations.map((d) => "name" in d.id ? d.id.name : "");
35
+ return [];
36
+ }).filter(Boolean);
37
+ }
38
+ /**
39
+ * Lists all imports from the given Babel AST program.
40
+ *
41
+ * @param ast - The parsed Babel AST result containing the program body.
42
+ * @returns An array of import names, including "default" for default imports.
43
+ */
44
+ function listImports(ast) {
45
+ return ast.program.body.flatMap((i) => {
46
+ if (i.type === "ImportDeclaration") return i.specifiers.map((s) => {
47
+ if (s.type === "ImportDefaultSpecifier") return "default";
48
+ if (s.type === "ImportSpecifier" && "imported" in s) return s.imported.type === "Identifier" ? s.imported.name : s.imported.value;
49
+ return "";
50
+ });
51
+ return [];
52
+ }).filter(Boolean);
53
+ }
54
+ function isImportCall(calleePath) {
55
+ return __babel_types.isImport(calleePath.node.callee);
56
+ }
57
+ /**
58
+ * Gets the import declaration for a given name and specifier.
59
+ *
60
+ * @param specifier - The specifier of the import.
61
+ * @param name - The name of the import.
62
+ * @param named - Optional named import.
63
+ * @returns The import declaration.
64
+ */
65
+ function getImport(specifier, name, named) {
66
+ return __babel_types.importDeclaration([__babel_types.importSpecifier(__babel_types.identifier(name), __babel_types.stringLiteral(named || name))], __babel_types.stringLiteral(specifier));
67
+ }
68
+ /**
69
+ * Adds an import to the program if it doesn't already exist.
70
+ *
71
+ * @param path - The current NodePath in the AST.
72
+ * @param specifier - The import specifier.
73
+ */
74
+ function addImport(path, specifier) {
75
+ addImportsToProgram(path.scope.getProgramParent().path, specifier);
76
+ }
77
+ function isNonNamespacedImport(importDeclPath) {
78
+ return importDeclPath.get("specifiers").filter(Boolean).every((specifier) => specifier?.isImportSpecifier()) && importDeclPath.node.importKind !== "type" && importDeclPath.node.importKind !== "typeof";
79
+ }
80
+ function getExistingImports(program) {
81
+ const existingImports = /* @__PURE__ */ new Map();
82
+ program.traverse({ ImportDeclaration(path) {
83
+ if (isNonNamespacedImport(path)) existingImports.set(path.node.source.value, path);
84
+ } });
85
+ return existingImports;
86
+ }
87
+ function addImportsToProgram(path, specifier) {
88
+ /**
89
+ * If an existing import of this module exists (ie \`import \{ ... \} from
90
+ * '<moduleName>'\`), inject new imported specifiers into the list of
91
+ * destructured variables.
92
+ */
93
+ if (!getExistingImports(path).get(specifier.module)) path.unshiftContainer("body", __babel_types.importDeclaration([__babel_types.importSpecifier(__babel_types.identifier(specifier.name || specifier.imported), __babel_types.identifier(specifier.imported))], __babel_types.stringLiteral(specifier.module)));
94
+ }
95
+
96
+ //#endregion
97
+ Object.defineProperty(exports, 'addImport', {
98
+ enumerable: true,
99
+ get: function () {
100
+ return addImport;
101
+ }
102
+ });
103
+ Object.defineProperty(exports, 'addImportsToProgram', {
104
+ enumerable: true,
105
+ get: function () {
106
+ return addImportsToProgram;
107
+ }
108
+ });
109
+ Object.defineProperty(exports, 'findExport', {
110
+ enumerable: true,
111
+ get: function () {
112
+ return findExport;
113
+ }
114
+ });
115
+ Object.defineProperty(exports, 'getImport', {
116
+ enumerable: true,
117
+ get: function () {
118
+ return getImport;
119
+ }
120
+ });
121
+ Object.defineProperty(exports, 'isImportCall', {
122
+ enumerable: true,
123
+ get: function () {
124
+ return isImportCall;
125
+ }
126
+ });
127
+ Object.defineProperty(exports, 'listExports', {
128
+ enumerable: true,
129
+ get: function () {
130
+ return listExports;
131
+ }
132
+ });
133
+ Object.defineProperty(exports, 'listImports', {
134
+ enumerable: true,
135
+ get: function () {
136
+ return listImports;
137
+ }
138
+ });