@powerlines/plugin-babel 0.12.246 → 0.12.248

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 (90) hide show
  1. package/dist/ast-utils-BcmWaIan.cjs +45 -0
  2. package/dist/ast-utils-Bs6DBkKg.d.mts +20 -0
  3. package/dist/ast-utils-Bs6DBkKg.d.mts.map +1 -0
  4. package/dist/ast-utils-DU1foCxH.mjs +33 -0
  5. package/dist/ast-utils-DU1foCxH.mjs.map +1 -0
  6. package/dist/ast-utils-DeuXcuqs.d.cts +20 -0
  7. package/dist/ast-utils-DeuXcuqs.d.cts.map +1 -0
  8. package/dist/{_virtual/rolldown_runtime.cjs → chunk-CbDLau6x.cjs} +6 -1
  9. package/dist/create-plugin-BSNFeead.mjs +40 -0
  10. package/dist/create-plugin-BSNFeead.mjs.map +1 -0
  11. package/dist/create-plugin-Bf7dRYZB.cjs +46 -0
  12. package/dist/create-plugin-DU9FBfyz.d.cts +16 -0
  13. package/dist/create-plugin-DU9FBfyz.d.cts.map +1 -0
  14. package/dist/create-plugin-DgfkdI-s.d.mts +16 -0
  15. package/dist/create-plugin-DgfkdI-s.d.mts.map +1 -0
  16. package/dist/filters-CU0L1nIa.cjs +79 -0
  17. package/dist/filters-CpjboNi8.mjs +56 -0
  18. package/dist/filters-CpjboNi8.mjs.map +1 -0
  19. package/dist/filters-D75MrPzl.d.mts +43 -0
  20. package/dist/filters-D75MrPzl.d.mts.map +1 -0
  21. package/dist/filters-DKyk7Jxg.d.cts +43 -0
  22. package/dist/filters-DKyk7Jxg.d.cts.map +1 -0
  23. package/dist/helpers/ast-utils.cjs +3 -34
  24. package/dist/helpers/ast-utils.d.cts +2 -19
  25. package/dist/helpers/ast-utils.d.mts +2 -19
  26. package/dist/helpers/ast-utils.mjs +1 -30
  27. package/dist/helpers/create-plugin.cjs +2 -40
  28. package/dist/helpers/create-plugin.d.cts +1 -14
  29. package/dist/helpers/create-plugin.d.mts +1 -14
  30. package/dist/helpers/create-plugin.mjs +1 -37
  31. package/dist/helpers/filters.cjs +5 -58
  32. package/dist/helpers/filters.d.cts +1 -41
  33. package/dist/helpers/filters.d.mts +1 -41
  34. package/dist/helpers/filters.mjs +1 -53
  35. package/dist/helpers/index.cjs +22 -21
  36. package/dist/helpers/index.d.cts +6 -5
  37. package/dist/helpers/index.d.mts +6 -5
  38. package/dist/helpers/index.mjs +6 -5
  39. package/dist/helpers/module-helpers.cjs +9 -102
  40. package/dist/helpers/module-helpers.d.cts +1 -48
  41. package/dist/helpers/module-helpers.d.mts +1 -48
  42. package/dist/helpers/module-helpers.mjs +2 -93
  43. package/dist/helpers/options.cjs +4 -48
  44. package/dist/helpers/options.d.cts +1 -17
  45. package/dist/helpers/options.d.mts +1 -17
  46. package/dist/helpers/options.mjs +2 -44
  47. package/dist/helpers-BnW_4z5h.mjs +1 -0
  48. package/dist/helpers-Bx2yBrpn.cjs +0 -0
  49. package/dist/index-BXxhKmeA.d.mts +1 -0
  50. package/dist/index-CqdNToYT.d.cts +1 -0
  51. package/dist/index-DJOHDG5e.d.mts +1 -0
  52. package/dist/index-sQecLSpR.d.cts +1 -0
  53. package/dist/index.cjs +29 -27
  54. package/dist/index.d.cts +10 -9
  55. package/dist/index.d.cts.map +1 -0
  56. package/dist/index.d.mts +10 -9
  57. package/dist/index.d.mts.map +1 -0
  58. package/dist/index.mjs +10 -7
  59. package/dist/index.mjs.map +1 -0
  60. package/dist/module-helpers-07-NCXys.d.cts +50 -0
  61. package/dist/module-helpers-07-NCXys.d.cts.map +1 -0
  62. package/dist/module-helpers-B1gnVB7F.d.mts +50 -0
  63. package/dist/module-helpers-B1gnVB7F.d.mts.map +1 -0
  64. package/dist/module-helpers-Ckq8sc4l.mjs +96 -0
  65. package/dist/module-helpers-Ckq8sc4l.mjs.map +1 -0
  66. package/dist/module-helpers-Non-jHMu.cjs +138 -0
  67. package/dist/options-2JL6WIXT.cjs +59 -0
  68. package/dist/options-CpZXObFr.d.mts +19 -0
  69. package/dist/options-CpZXObFr.d.mts.map +1 -0
  70. package/dist/options-DZkAyLff.d.cts +19 -0
  71. package/dist/options-DZkAyLff.d.cts.map +1 -0
  72. package/dist/options-DwynxlP6.mjs +47 -0
  73. package/dist/options-DwynxlP6.mjs.map +1 -0
  74. package/dist/plugin-BL8TLixo.mjs +1 -0
  75. package/dist/plugin-BSBH78mm.cjs +0 -0
  76. package/dist/plugin-C-FvkCBm.d.cts +20 -0
  77. package/dist/plugin-C-FvkCBm.d.cts.map +1 -0
  78. package/dist/plugin-Sxw1QP5p.d.mts +20 -0
  79. package/dist/plugin-Sxw1QP5p.d.mts.map +1 -0
  80. package/dist/types/index.cjs +2 -0
  81. package/dist/types/index.d.cts +2 -1
  82. package/dist/types/index.d.mts +2 -1
  83. package/dist/types/index.mjs +3 -0
  84. package/dist/types/plugin.cjs +1 -0
  85. package/dist/types/plugin.d.cts +1 -18
  86. package/dist/types/plugin.d.mts +1 -18
  87. package/dist/types/plugin.mjs +2 -0
  88. package/dist/types-CKPddlfS.cjs +0 -0
  89. package/dist/types-CvhspRRt.mjs +1 -0
  90. package/package.json +4 -4
@@ -1,49 +1,2 @@
1
- import { NodePath } from "@babel/core";
2
- import { ParseResult } from "@babel/parser";
3
- import * as t from "@babel/types";
4
- import { ImportSpecifier } from "powerlines/types/babel";
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
1
+ 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-B1gnVB7F.mjs";
49
2
  export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
@@ -1,95 +1,4 @@
1
- import { parseAst } from "./ast-utils.mjs";
2
- import * as t from "@babel/types";
3
- import { isString } from "@stryke/type-checks/is-string";
1
+ import "../ast-utils-DU1foCxH.mjs";
2
+ 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-Ckq8sc4l.mjs";
4
3
 
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
4
  export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
@@ -1,49 +1,5 @@
1
- const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
- const require_helpers_filters = require('./filters.cjs');
3
- let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
4
- let chalk = require("chalk");
5
- chalk = require_rolldown_runtime.__toESM(chalk);
1
+ require('../filters-CU0L1nIa.cjs');
2
+ const require_options = require('../options-2JL6WIXT.cjs');
6
3
 
7
- //#region src/helpers/options.ts
8
- function resolvePluginFunction(context, plugin) {
9
- try {
10
- return Array.isArray(plugin) && plugin.length > 0 && plugin[0] ? (0, __stryke_type_checks_is_function.isFunction)(plugin[0]) ? plugin[0](context) : plugin[0] : (0, __stryke_type_checks_is_function.isFunction)(plugin) ? plugin(context) : plugin;
11
- } catch {
12
- return plugin[0];
13
- }
14
- }
15
- /**
16
- * Resolve the [Babel](https://babeljs.io/) plugin.
17
- *
18
- * @param context - The context for the transformation.
19
- * @param code - The code to be transformed.
20
- * @param id - The ID of the source file.
21
- * @param plugin - The Babel plugin to resolve.
22
- * @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
23
- */
24
- function resolveBabelPlugin(context, code, id, plugin) {
25
- if (Array.isArray(plugin) && plugin.length > 0 && plugin[0]) {
26
- if (plugin.length > 2 && plugin[2] && (0, __stryke_type_checks_is_function.isFunction)(plugin[2]) && !plugin[2](code, id)) {
27
- context.trace(`Skipping filtered Babel plugin ${chalk.default.bold.cyanBright(require_helpers_filters.getPluginName(plugin) || "unnamed")} for ${id}`);
28
- return;
29
- }
30
- return plugin.length > 2 ? [
31
- resolvePluginFunction(context, plugin),
32
- plugin[1],
33
- plugin[2]
34
- ] : [
35
- resolvePluginFunction(context, plugin),
36
- plugin[1],
37
- null
38
- ];
39
- }
40
- return [
41
- resolvePluginFunction(context, plugin),
42
- {},
43
- null
44
- ];
45
- }
46
-
47
- //#endregion
48
- exports.resolveBabelPlugin = resolveBabelPlugin;
49
- exports.resolvePluginFunction = resolvePluginFunction;
4
+ exports.resolveBabelPlugin = require_options.resolveBabelPlugin;
5
+ exports.resolvePluginFunction = require_options.resolvePluginFunction;
@@ -1,18 +1,2 @@
1
- import { BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions } from "powerlines/types/babel";
2
- import { Context } from "powerlines/types/context";
3
- import { PluginOptions, PluginTarget } from "@babel/core";
4
-
5
- //#region src/helpers/options.d.ts
6
- declare function resolvePluginFunction(context: Context, plugin: any | PluginTarget | any[] | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string | undefined]): BabelTransformPluginOptions;
7
- /**
8
- * Resolve the [Babel](https://babeljs.io/) plugin.
9
- *
10
- * @param context - The context for the transformation.
11
- * @param code - The code to be transformed.
12
- * @param id - The ID of the source file.
13
- * @param plugin - The Babel plugin to resolve.
14
- * @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
15
- */
16
- declare function resolveBabelPlugin(context: Context, code: string, id: string, plugin: BabelTransformPluginOptions): ResolvedBabelTransformPluginOptions | undefined;
17
- //#endregion
1
+ import { n as resolvePluginFunction, t as resolveBabelPlugin } from "../options-DZkAyLff.cjs";
18
2
  export { resolveBabelPlugin, resolvePluginFunction };
@@ -1,18 +1,2 @@
1
- import { PluginOptions, PluginTarget } from "@babel/core";
2
- import { BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions } from "powerlines/types/babel";
3
- import { Context } from "powerlines/types/context";
4
-
5
- //#region src/helpers/options.d.ts
6
- declare function resolvePluginFunction(context: Context, plugin: any | PluginTarget | any[] | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string | undefined]): BabelTransformPluginOptions;
7
- /**
8
- * Resolve the [Babel](https://babeljs.io/) plugin.
9
- *
10
- * @param context - The context for the transformation.
11
- * @param code - The code to be transformed.
12
- * @param id - The ID of the source file.
13
- * @param plugin - The Babel plugin to resolve.
14
- * @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
15
- */
16
- declare function resolveBabelPlugin(context: Context, code: string, id: string, plugin: BabelTransformPluginOptions): ResolvedBabelTransformPluginOptions | undefined;
17
- //#endregion
1
+ import { n as resolvePluginFunction, t as resolveBabelPlugin } from "../options-CpZXObFr.mjs";
18
2
  export { resolveBabelPlugin, resolvePluginFunction };
@@ -1,46 +1,4 @@
1
- import { getPluginName } from "./filters.mjs";
2
- import { isFunction } from "@stryke/type-checks/is-function";
3
- import chalk from "chalk";
1
+ import "../filters-CpjboNi8.mjs";
2
+ import { n as resolvePluginFunction, t as resolveBabelPlugin } from "../options-DwynxlP6.mjs";
4
3
 
5
- //#region src/helpers/options.ts
6
- function resolvePluginFunction(context, plugin) {
7
- try {
8
- return Array.isArray(plugin) && plugin.length > 0 && plugin[0] ? isFunction(plugin[0]) ? plugin[0](context) : plugin[0] : isFunction(plugin) ? plugin(context) : plugin;
9
- } catch {
10
- return plugin[0];
11
- }
12
- }
13
- /**
14
- * Resolve the [Babel](https://babeljs.io/) plugin.
15
- *
16
- * @param context - The context for the transformation.
17
- * @param code - The code to be transformed.
18
- * @param id - The ID of the source file.
19
- * @param plugin - The Babel plugin to resolve.
20
- * @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
21
- */
22
- function resolveBabelPlugin(context, code, id, plugin) {
23
- if (Array.isArray(plugin) && plugin.length > 0 && plugin[0]) {
24
- if (plugin.length > 2 && plugin[2] && isFunction(plugin[2]) && !plugin[2](code, id)) {
25
- context.trace(`Skipping filtered Babel plugin ${chalk.bold.cyanBright(getPluginName(plugin) || "unnamed")} for ${id}`);
26
- return;
27
- }
28
- return plugin.length > 2 ? [
29
- resolvePluginFunction(context, plugin),
30
- plugin[1],
31
- plugin[2]
32
- ] : [
33
- resolvePluginFunction(context, plugin),
34
- plugin[1],
35
- null
36
- ];
37
- }
38
- return [
39
- resolvePluginFunction(context, plugin),
40
- {},
41
- null
42
- ];
43
- }
44
-
45
- //#endregion
46
4
  export { resolveBabelPlugin, resolvePluginFunction };
@@ -0,0 +1 @@
1
+ export { };
File without changes
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1 @@
1
+ export { };
package/dist/index.cjs CHANGED
@@ -1,17 +1,19 @@
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-Bf7dRYZB.cjs');
7
+ const require_module_helpers = require('./module-helpers-Non-jHMu.cjs');
8
+ require('./helpers-Bx2yBrpn.cjs');
9
+ require('./plugin-BSBH78mm.cjs');
10
+ require('./types-CKPddlfS.cjs');
9
11
  let __babel_core = require("@babel/core");
10
12
  let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
11
13
  let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
12
14
  let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
13
15
  let defu = require("defu");
14
- defu = require_rolldown_runtime.__toESM(defu);
16
+ defu = require_chunk.__toESM(defu);
15
17
 
16
18
  //#region src/index.ts
17
19
  /**
@@ -44,13 +46,13 @@ const plugin = (options = {}) => {
44
46
  id
45
47
  };
46
48
  }
47
- const plugins = this.config.transform.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.transform.babel.presets.map((preset) => require_helpers_options.resolveBabelPlugin(this, code, id, preset)).filter((preset, _, arr) => preset && !require_helpers_filters.isDuplicatePlugin(arr, preset));
49
+ const plugins = this.config.transform.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));
50
+ const presets = this.config.transform.babel.presets.map((preset) => require_options.resolveBabelPlugin(this, code, id, preset)).filter((preset, _, arr) => preset && !require_filters.isDuplicatePlugin(arr, preset));
49
51
  if (Array.isArray(plugins) && plugins.length === 0 && Array.isArray(presets) && presets.length === 0) return {
50
52
  code,
51
53
  id
52
54
  };
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" }]);
55
+ 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
56
  this.trace(`Running babel transformations with ${plugins.length} plugins and ${presets.length} presets for file: ${id}`);
55
57
  const result = await (0, __babel_core.transformAsync)(code, {
56
58
  highlightCode: true,
@@ -84,21 +86,21 @@ const plugin = (options = {}) => {
84
86
  var src_default = plugin;
85
87
 
86
88
  //#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;
89
+ exports.addImport = require_module_helpers.addImport;
90
+ exports.addImportsToProgram = require_module_helpers.addImportsToProgram;
91
+ exports.addPluginFilter = require_filters.addPluginFilter;
92
+ exports.createBabelPlugin = require_create_plugin.createBabelPlugin;
91
93
  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;
94
+ exports.filterPluginByFileId = require_filters.filterPluginByFileId;
95
+ exports.findExport = require_module_helpers.findExport;
96
+ exports.generateFromAst = require_ast_utils.generateFromAst;
97
+ exports.getImport = require_module_helpers.getImport;
98
+ exports.getPluginName = require_filters.getPluginName;
99
+ exports.isDuplicatePlugin = require_filters.isDuplicatePlugin;
100
+ exports.isImportCall = require_module_helpers.isImportCall;
101
+ exports.listExports = require_module_helpers.listExports;
102
+ exports.listImports = require_module_helpers.listImports;
103
+ exports.parseAst = require_ast_utils.parseAst;
102
104
  exports.plugin = plugin;
103
- exports.resolveBabelPlugin = require_helpers_options.resolveBabelPlugin;
104
- exports.resolvePluginFunction = require_helpers_options.resolvePluginFunction;
105
+ exports.resolveBabelPlugin = require_options.resolveBabelPlugin;
106
+ exports.resolvePluginFunction = require_options.resolvePluginFunction;
package/dist/index.d.cts CHANGED
@@ -1,11 +1,11 @@
1
- import { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, generateFromAst, parseAst } from "./helpers/ast-utils.cjs";
2
- import { createBabelPlugin } from "./helpers/create-plugin.cjs";
3
- import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin } from "./helpers/filters.cjs";
4
- import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./helpers/module-helpers.cjs";
5
- import { resolveBabelPlugin, resolvePluginFunction } from "./helpers/options.cjs";
6
- import "./helpers/index.cjs";
7
- import { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig } from "./types/plugin.cjs";
8
- import "./types/index.cjs";
1
+ import { a as parseAst, i as generateFromAst, n as GeneratorResult, r as __ΩGenerateFromAstOptions, t as GenerateFromAstOptions } from "./ast-utils-DeuXcuqs.cjs";
2
+ import { t as createBabelPlugin } from "./create-plugin-DU9FBfyz.cjs";
3
+ import { i as isDuplicatePlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "./filters-DKyk7Jxg.cjs";
4
+ 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-07-NCXys.cjs";
5
+ import { n as resolvePluginFunction, t as resolveBabelPlugin } from "./options-DZkAyLff.cjs";
6
+ import "./index-CqdNToYT.cjs";
7
+ 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-C-FvkCBm.cjs";
8
+ import "./index-sQecLSpR.cjs";
9
9
  import { Plugin } from "powerlines/types/plugin";
10
10
 
11
11
  //#region src/index.d.ts
@@ -17,4 +17,5 @@ import { Plugin } from "powerlines/types/plugin";
17
17
  */
18
18
  declare const plugin: <TContext extends BabelPluginContext>(options?: BabelPluginOptions) => Plugin<TContext>;
19
19
  //#endregion
20
- export { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, GenerateFromAstOptions, GeneratorResult, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig, __ΩGenerateFromAstOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, plugin as default, plugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolvePluginFunction };
20
+ export { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, GenerateFromAstOptions, GeneratorResult, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig, __ΩGenerateFromAstOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, plugin as default, plugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolvePluginFunction };
21
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;cAyCa,0BAA2B,8BAC7B,uBA0HJ,OAAO"}
package/dist/index.d.mts CHANGED
@@ -1,11 +1,11 @@
1
- import { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, generateFromAst, parseAst } from "./helpers/ast-utils.mjs";
2
- import { createBabelPlugin } from "./helpers/create-plugin.mjs";
3
- import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin } from "./helpers/filters.mjs";
4
- import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./helpers/module-helpers.mjs";
5
- import { resolveBabelPlugin, resolvePluginFunction } from "./helpers/options.mjs";
6
- import "./helpers/index.mjs";
7
- import { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig } from "./types/plugin.mjs";
8
- import "./types/index.mjs";
1
+ import { a as parseAst, i as generateFromAst, n as GeneratorResult, r as __ΩGenerateFromAstOptions, t as GenerateFromAstOptions } from "./ast-utils-Bs6DBkKg.mjs";
2
+ import { t as createBabelPlugin } from "./create-plugin-DgfkdI-s.mjs";
3
+ import { i as isDuplicatePlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "./filters-D75MrPzl.mjs";
4
+ 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-B1gnVB7F.mjs";
5
+ import { n as resolvePluginFunction, t as resolveBabelPlugin } from "./options-CpZXObFr.mjs";
6
+ import "./index-BXxhKmeA.mjs";
7
+ 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-Sxw1QP5p.mjs";
8
+ import "./index-DJOHDG5e.mjs";
9
9
  import { Plugin } from "powerlines/types/plugin";
10
10
 
11
11
  //#region src/index.d.ts
@@ -17,4 +17,5 @@ import { Plugin } from "powerlines/types/plugin";
17
17
  */
18
18
  declare const plugin: <TContext extends BabelPluginContext>(options?: BabelPluginOptions) => Plugin<TContext>;
19
19
  //#endregion
20
- export { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, GenerateFromAstOptions, GeneratorResult, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig, __ΩGenerateFromAstOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, plugin as default, plugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolvePluginFunction };
20
+ export { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, GenerateFromAstOptions, GeneratorResult, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig, __ΩGenerateFromAstOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, plugin as default, plugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolvePluginFunction };
21
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;cAyCa,0BAA2B,8BAC7B,uBA0HJ,OAAO"}
package/dist/index.mjs CHANGED
@@ -1,9 +1,11 @@
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-CpjboNi8.mjs";
2
+ import { n as resolvePluginFunction, t as resolveBabelPlugin } from "./options-DwynxlP6.mjs";
3
+ import { n as parseAst, t as generateFromAst } from "./ast-utils-DU1foCxH.mjs";
4
+ import { t as createBabelPlugin } from "./create-plugin-BSNFeead.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-Ckq8sc4l.mjs";
6
+ import "./helpers-BnW_4z5h.mjs";
7
+ import "./plugin-BL8TLixo.mjs";
8
+ import "./types-CvhspRRt.mjs";
7
9
  import { transformAsync } from "@babel/core";
8
10
  import { findFileExtension, findFileExtensionSafe } from "@stryke/path/file-path-fns";
9
11
  import { isParentPath } from "@stryke/path/is-parent-path";
@@ -81,4 +83,5 @@ const plugin = (options = {}) => {
81
83
  var src_default = plugin;
82
84
 
83
85
  //#endregion
84
- export { addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, src_default as default, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, plugin, resolveBabelPlugin, resolvePluginFunction };
86
+ export { addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, src_default as default, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, plugin, resolveBabelPlugin, resolvePluginFunction };
87
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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 {\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 { ResolvedBabelTransformPluginOptions } from \"powerlines/types/babel\";\nimport { Plugin } from \"powerlines/types/plugin\";\nimport { isDuplicatePlugin } from \"./helpers/filters\";\nimport { resolveBabelPlugin } from \"./helpers/options\";\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 = <TContext extends BabelPluginContext>(\n options: BabelPluginOptions = {}\n) => {\n return {\n name: \"babel\",\n config() {\n if (!isSetObject(options)) {\n return undefined;\n }\n\n return {\n transform: { babel: options }\n };\n },\n configResolved: {\n order: \"pre\",\n handler() {\n this.config.transform.babel = defu(this.config.transform.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.transform.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.transform.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.transform.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,UACX,UAA8B,EAAE,KAC7B;AACH,QAAO;EACL,MAAM;EACN,SAAS;AACP,OAAI,CAAC,YAAY,QAAQ,CACvB;AAGF,UAAO,EACL,WAAW,EAAE,OAAO,SAAS,EAC9B;;EAEH,gBAAgB;GACd,OAAO;GACP,UAAU;AACR,SAAK,OAAO,UAAU,QAAQ,KAAK,KAAK,OAAO,UAAU,SAAS,EAAE,EAAE;KACpE,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,UAAU,MAAM,QACzC,KAAI,aAAU,mBAAmB,MAAM,MAAM,IAAIA,SAAO,CAAC,CACzD,QACE,UAAQ,GAAG,QAAQA,YAAU,CAAC,kBAAkB,KAAKA,SAAO,CAC9D;GACH,MAAM,UAAU,KAAK,OAAO,UAAU,MAAM,QACzC,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,UAAU,SAAS,EAAE;IACrC,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 { ParseResult } from "@babel/parser";
2
+ import * as t from "@babel/types";
3
+ import { ImportSpecifier } from "powerlines/types/babel";
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-07-NCXys.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-helpers-07-NCXys.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,50 @@
1
+ import { NodePath } from "@babel/core";
2
+ import { ParseResult } from "@babel/parser";
3
+ import * as t from "@babel/types";
4
+ import { ImportSpecifier } from "powerlines/types/babel";
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-B1gnVB7F.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-helpers-B1gnVB7F.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"}