@powerlines/plugin-babel 0.12.129 → 0.12.131
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.
- package/dist/ast-utils-BcmWaIan.cjs +45 -0
- package/dist/ast-utils-Bs6DBkKg.d.mts +19 -0
- package/dist/ast-utils-DU1foCxH.mjs +32 -0
- package/dist/ast-utils-DeuXcuqs.d.cts +19 -0
- package/dist/babel-B9i2IAT_.d.cts +1805 -0
- package/dist/babel-DY_imD3U.d.mts +1805 -0
- package/dist/{_virtual/rolldown_runtime.cjs → chunk-CbDLau6x.cjs} +6 -1
- package/dist/create-plugin-BPSvsem_.mjs +73 -0
- package/dist/create-plugin-CNzMrex8.d.mts +14 -0
- package/dist/create-plugin-CQA6zFdt.d.cts +14 -0
- package/dist/create-plugin-Cs1zZrvI.cjs +80 -0
- package/dist/filters-93Z-7Nov.d.mts +44 -0
- package/dist/filters-C04cfcQR.mjs +55 -0
- package/dist/filters-D6Qe6UbO.d.cts +41 -0
- package/dist/filters-Dl2RKvrm.cjs +79 -0
- package/dist/helpers/ast-utils.cjs +3 -34
- package/dist/helpers/ast-utils.d.cts +2 -19
- package/dist/helpers/ast-utils.d.mts +2 -19
- package/dist/helpers/ast-utils.mjs +1 -30
- package/dist/helpers/create-plugin.cjs +2 -40
- package/dist/helpers/create-plugin.d.cts +2 -14
- package/dist/helpers/create-plugin.d.mts +2 -14
- package/dist/helpers/create-plugin.mjs +1 -37
- package/dist/helpers/filters.cjs +5 -58
- package/dist/helpers/filters.d.cts +2 -41
- package/dist/helpers/filters.d.mts +2 -42
- package/dist/helpers/filters.mjs +1 -53
- package/dist/helpers/index.cjs +22 -21
- package/dist/helpers/index.d.cts +7 -5
- package/dist/helpers/index.d.mts +7 -5
- package/dist/helpers/index.mjs +6 -5
- package/dist/helpers/module-helpers.cjs +9 -102
- package/dist/helpers/module-helpers.d.cts +2 -48
- package/dist/helpers/module-helpers.d.mts +2 -48
- package/dist/helpers/module-helpers.mjs +2 -93
- package/dist/helpers/options.cjs +4 -49
- package/dist/helpers/options.d.cts +2 -17
- package/dist/helpers/options.d.mts +2 -17
- package/dist/helpers/options.mjs +2 -45
- package/dist/helpers-BnW_4z5h.mjs +1 -0
- package/dist/helpers-Bx2yBrpn.cjs +0 -0
- package/dist/index-ClXLQ1fw.d.mts +1 -0
- package/dist/index-DeEmP3Jc.d.cts +1 -0
- package/dist/index-QbUkWSLh.d.mts +1 -0
- package/dist/index-zO0Ly4bS.d.cts +1 -0
- package/dist/index.cjs +29 -27
- package/dist/index.d.cts +9 -8
- package/dist/index.d.mts +9 -9
- package/dist/index.mjs +8 -6
- package/dist/module-helpers-Ckq8sc4l.mjs +95 -0
- package/dist/module-helpers-DRUocgcq.d.cts +49 -0
- package/dist/module-helpers-DiSYdstQ.d.mts +49 -0
- package/dist/module-helpers-Non-jHMu.cjs +138 -0
- package/dist/options-BQhc80ih.mjs +47 -0
- package/dist/options-CCMyIIWc.d.cts +17 -0
- package/dist/options-DgdPmsbF.d.mts +17 -0
- package/dist/options-u2MhTIFH.cjs +60 -0
- package/dist/plugin-BL8TLixo.mjs +1 -0
- package/dist/plugin-BSBH78mm.cjs +0 -0
- package/dist/plugin-Bc0EOyGF.d.mts +17 -0
- package/dist/plugin-DhjfPNQS.d.cts +17 -0
- package/dist/types/index.cjs +2 -0
- package/dist/types/index.d.cts +3 -1
- package/dist/types/index.d.mts +3 -1
- package/dist/types/index.mjs +3 -0
- package/dist/types/plugin.cjs +1 -0
- package/dist/types/plugin.d.cts +2 -18
- package/dist/types/plugin.d.mts +2 -18
- package/dist/types/plugin.mjs +2 -0
- package/dist/types-CKPddlfS.cjs +0 -0
- package/dist/types-CvhspRRt.mjs +1 -0
- package/package.json +5 -5
- package/dist/powerlines/src/internal/helpers/hooks.d.mts +0 -5
- package/dist/powerlines/src/lib/logger.cjs +0 -41
- package/dist/powerlines/src/lib/logger.mjs +0 -39
- package/dist/powerlines/src/types/api.d.mts +0 -5
- package/dist/powerlines/src/types/babel.d.cts +0 -50
- package/dist/powerlines/src/types/babel.d.mts +0 -50
- package/dist/powerlines/src/types/build.d.cts +0 -145
- package/dist/powerlines/src/types/build.d.mts +0 -145
- package/dist/powerlines/src/types/commands.d.cts +0 -8
- package/dist/powerlines/src/types/commands.d.mts +0 -9
- package/dist/powerlines/src/types/config.d.cts +0 -380
- package/dist/powerlines/src/types/config.d.mts +0 -380
- package/dist/powerlines/src/types/context.d.cts +0 -403
- package/dist/powerlines/src/types/context.d.mts +0 -405
- package/dist/powerlines/src/types/fs.d.cts +0 -486
- package/dist/powerlines/src/types/fs.d.mts +0 -486
- package/dist/powerlines/src/types/hooks.d.mts +0 -2
- package/dist/powerlines/src/types/index.d.mts +0 -12
- package/dist/powerlines/src/types/plugin.d.cts +0 -231
- package/dist/powerlines/src/types/plugin.d.mts +0 -231
- package/dist/powerlines/src/types/resolved.d.cts +0 -82
- package/dist/powerlines/src/types/resolved.d.mts +0 -82
- package/dist/powerlines/src/types/tsconfig.d.cts +0 -69
- package/dist/powerlines/src/types/tsconfig.d.mts +0 -69
- package/dist/powerlines/src/types/unplugin.d.mts +0 -6
package/dist/helpers/options.cjs
CHANGED
|
@@ -1,50 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
|
|
4
|
-
let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
5
|
-
let chalk = require("chalk");
|
|
6
|
-
chalk = require_rolldown_runtime.__toESM(chalk);
|
|
1
|
+
require('../filters-Dl2RKvrm.cjs');
|
|
2
|
+
const require_options = require('../options-u2MhTIFH.cjs');
|
|
7
3
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
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;
|
|
12
|
-
} catch {
|
|
13
|
-
return plugin[0];
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Resolve the [Babel](https://babeljs.io/) plugin.
|
|
18
|
-
*
|
|
19
|
-
* @param context - The context for the transformation.
|
|
20
|
-
* @param code - The code to be transformed.
|
|
21
|
-
* @param id - The ID of the source file.
|
|
22
|
-
* @param plugin - The Babel plugin to resolve.
|
|
23
|
-
* @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
|
|
24
|
-
*/
|
|
25
|
-
function resolveBabelPlugin(context, code, id, plugin) {
|
|
26
|
-
if (Array.isArray(plugin) && plugin.length > 0 && plugin[0]) {
|
|
27
|
-
if (plugin.length > 2 && plugin[2] && (0, __stryke_type_checks_is_function.isFunction)(plugin[2]) && !plugin[2](code, id)) {
|
|
28
|
-
context.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Skipping filtered Babel plugin ${chalk.default.bold.cyanBright(require_helpers_filters.getPluginName(plugin) || "unnamed")} for ${id}`);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
return plugin.length > 2 ? [
|
|
32
|
-
resolvePluginFunction(context, plugin),
|
|
33
|
-
plugin[1],
|
|
34
|
-
plugin[2]
|
|
35
|
-
] : [
|
|
36
|
-
resolvePluginFunction(context, plugin),
|
|
37
|
-
plugin[1],
|
|
38
|
-
null
|
|
39
|
-
];
|
|
40
|
-
}
|
|
41
|
-
return [
|
|
42
|
-
resolvePluginFunction(context, plugin),
|
|
43
|
-
{},
|
|
44
|
-
null
|
|
45
|
-
];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
//#endregion
|
|
49
|
-
exports.resolveBabelPlugin = resolveBabelPlugin;
|
|
50
|
-
exports.resolvePluginFunction = resolvePluginFunction;
|
|
4
|
+
exports.resolveBabelPlugin = require_options.resolveBabelPlugin;
|
|
5
|
+
exports.resolvePluginFunction = require_options.resolvePluginFunction;
|
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
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 "../babel-B9i2IAT_.cjs";
|
|
2
|
+
import { n as resolvePluginFunction, t as resolveBabelPlugin } from "../options-CCMyIIWc.cjs";
|
|
18
3
|
export { resolveBabelPlugin, resolvePluginFunction };
|
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
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 "../babel-DY_imD3U.mjs";
|
|
2
|
+
import { n as resolvePluginFunction, t as resolveBabelPlugin } from "../options-DgdPmsbF.mjs";
|
|
18
3
|
export { resolveBabelPlugin, resolvePluginFunction };
|
package/dist/helpers/options.mjs
CHANGED
|
@@ -1,47 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { isFunction } from "@stryke/type-checks/is-function";
|
|
4
|
-
import chalk from "chalk";
|
|
1
|
+
import "../filters-C04cfcQR.mjs";
|
|
2
|
+
import { n as resolvePluginFunction, t as resolveBabelPlugin } from "../options-BQhc80ih.mjs";
|
|
5
3
|
|
|
6
|
-
//#region src/helpers/options.ts
|
|
7
|
-
function resolvePluginFunction(context, plugin) {
|
|
8
|
-
try {
|
|
9
|
-
return Array.isArray(plugin) && plugin.length > 0 && plugin[0] ? isFunction(plugin[0]) ? plugin[0](context) : plugin[0] : isFunction(plugin) ? plugin(context) : plugin;
|
|
10
|
-
} catch {
|
|
11
|
-
return plugin[0];
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Resolve the [Babel](https://babeljs.io/) plugin.
|
|
16
|
-
*
|
|
17
|
-
* @param context - The context for the transformation.
|
|
18
|
-
* @param code - The code to be transformed.
|
|
19
|
-
* @param id - The ID of the source file.
|
|
20
|
-
* @param plugin - The Babel plugin to resolve.
|
|
21
|
-
* @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
|
|
22
|
-
*/
|
|
23
|
-
function resolveBabelPlugin(context, code, id, plugin) {
|
|
24
|
-
if (Array.isArray(plugin) && plugin.length > 0 && plugin[0]) {
|
|
25
|
-
if (plugin.length > 2 && plugin[2] && isFunction(plugin[2]) && !plugin[2](code, id)) {
|
|
26
|
-
context.log(LogLevelLabel.TRACE, `Skipping filtered Babel plugin ${chalk.bold.cyanBright(getPluginName(plugin) || "unnamed")} for ${id}`);
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
return plugin.length > 2 ? [
|
|
30
|
-
resolvePluginFunction(context, plugin),
|
|
31
|
-
plugin[1],
|
|
32
|
-
plugin[2]
|
|
33
|
-
] : [
|
|
34
|
-
resolvePluginFunction(context, plugin),
|
|
35
|
-
plugin[1],
|
|
36
|
-
null
|
|
37
|
-
];
|
|
38
|
-
}
|
|
39
|
-
return [
|
|
40
|
-
resolvePluginFunction(context, plugin),
|
|
41
|
-
{},
|
|
42
|
-
null
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
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,18 +1,20 @@
|
|
|
1
1
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
require('./helpers
|
|
2
|
+
const require_chunk = require('./chunk-CbDLau6x.cjs');
|
|
3
|
+
const require_filters = require('./filters-Dl2RKvrm.cjs');
|
|
4
|
+
const require_options = require('./options-u2MhTIFH.cjs');
|
|
5
|
+
const require_ast_utils = require('./ast-utils-BcmWaIan.cjs');
|
|
6
|
+
const require_create_plugin = require('./create-plugin-Cs1zZrvI.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 __storm_software_config_tools_types = require("@storm-software/config-tools/types");
|
|
11
13
|
let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
|
|
12
14
|
let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
|
|
13
15
|
let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
14
16
|
let defu = require("defu");
|
|
15
|
-
defu =
|
|
17
|
+
defu = require_chunk.__toESM(defu);
|
|
16
18
|
|
|
17
19
|
//#region src/index.ts
|
|
18
20
|
/**
|
|
@@ -47,8 +49,8 @@ const plugin = (options = {}) => {
|
|
|
47
49
|
};
|
|
48
50
|
}
|
|
49
51
|
this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Babel transforming file: ${id}`);
|
|
50
|
-
const plugins = this.config.transform.babel.plugins.map((plugin$1) =>
|
|
51
|
-
const presets = this.config.transform.babel.presets.map((preset) =>
|
|
52
|
+
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));
|
|
53
|
+
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));
|
|
52
54
|
if (Array.isArray(plugins) && plugins.length === 0 && Array.isArray(presets) && presets.length === 0) return {
|
|
53
55
|
code,
|
|
54
56
|
id
|
|
@@ -58,7 +60,7 @@ const plugin = (options = {}) => {
|
|
|
58
60
|
"cts",
|
|
59
61
|
"mts",
|
|
60
62
|
"tsx"
|
|
61
|
-
].includes((0, __stryke_path_file_path_fns.findFileExtensionSafe)(id)) && !
|
|
63
|
+
].includes((0, __stryke_path_file_path_fns.findFileExtensionSafe)(id)) && !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" }]);
|
|
62
64
|
const result = await (0, __babel_core.transformAsync)(code, {
|
|
63
65
|
highlightCode: true,
|
|
64
66
|
code: true,
|
|
@@ -90,21 +92,21 @@ const plugin = (options = {}) => {
|
|
|
90
92
|
var src_default = plugin;
|
|
91
93
|
|
|
92
94
|
//#endregion
|
|
93
|
-
exports.addImport =
|
|
94
|
-
exports.addImportsToProgram =
|
|
95
|
-
exports.addPluginFilter =
|
|
96
|
-
exports.createBabelPlugin =
|
|
95
|
+
exports.addImport = require_module_helpers.addImport;
|
|
96
|
+
exports.addImportsToProgram = require_module_helpers.addImportsToProgram;
|
|
97
|
+
exports.addPluginFilter = require_filters.addPluginFilter;
|
|
98
|
+
exports.createBabelPlugin = require_create_plugin.createBabelPlugin;
|
|
97
99
|
exports.default = src_default;
|
|
98
|
-
exports.filterPluginByFileId =
|
|
99
|
-
exports.findExport =
|
|
100
|
-
exports.generateFromAst =
|
|
101
|
-
exports.getImport =
|
|
102
|
-
exports.getPluginName =
|
|
103
|
-
exports.isDuplicatePlugin =
|
|
104
|
-
exports.isImportCall =
|
|
105
|
-
exports.listExports =
|
|
106
|
-
exports.listImports =
|
|
107
|
-
exports.parseAst =
|
|
100
|
+
exports.filterPluginByFileId = require_filters.filterPluginByFileId;
|
|
101
|
+
exports.findExport = require_module_helpers.findExport;
|
|
102
|
+
exports.generateFromAst = require_ast_utils.generateFromAst;
|
|
103
|
+
exports.getImport = require_module_helpers.getImport;
|
|
104
|
+
exports.getPluginName = require_filters.getPluginName;
|
|
105
|
+
exports.isDuplicatePlugin = require_filters.isDuplicatePlugin;
|
|
106
|
+
exports.isImportCall = require_module_helpers.isImportCall;
|
|
107
|
+
exports.listExports = require_module_helpers.listExports;
|
|
108
|
+
exports.listImports = require_module_helpers.listImports;
|
|
109
|
+
exports.parseAst = require_ast_utils.parseAst;
|
|
108
110
|
exports.plugin = plugin;
|
|
109
|
-
exports.resolveBabelPlugin =
|
|
110
|
-
exports.resolvePluginFunction =
|
|
111
|
+
exports.resolveBabelPlugin = require_options.resolveBabelPlugin;
|
|
112
|
+
exports.resolvePluginFunction = require_options.resolvePluginFunction;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Plugin } from "./
|
|
3
|
-
import { createBabelPlugin } from "./
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
1
|
+
import { a as parseAst, i as generateFromAst, n as GeneratorResult, r as __ΩGenerateFromAstOptions, t as GenerateFromAstOptions } from "./ast-utils-DeuXcuqs.cjs";
|
|
2
|
+
import { f as Plugin } from "./babel-B9i2IAT_.cjs";
|
|
3
|
+
import { t as createBabelPlugin } from "./create-plugin-CQA6zFdt.cjs";
|
|
4
|
+
import { i as isDuplicatePlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "./filters-D6Qe6UbO.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-DRUocgcq.cjs";
|
|
6
|
+
import { n as resolvePluginFunction, t as resolveBabelPlugin } from "./options-CCMyIIWc.cjs";
|
|
7
|
+
import "./index-DeEmP3Jc.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-DhjfPNQS.cjs";
|
|
9
|
+
import "./index-zO0Ly4bS.cjs";
|
|
8
10
|
|
|
9
11
|
//#region src/index.d.ts
|
|
10
|
-
|
|
11
12
|
/**
|
|
12
13
|
* Babel plugin for Powerlines.
|
|
13
14
|
*
|
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Plugin } from "./
|
|
3
|
-
import { createBabelPlugin } from "./
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import "./
|
|
8
|
-
import { BabelPluginContext,
|
|
9
|
-
import "./
|
|
1
|
+
import { a as parseAst, i as generateFromAst, n as GeneratorResult, r as __ΩGenerateFromAstOptions, t as GenerateFromAstOptions } from "./ast-utils-Bs6DBkKg.mjs";
|
|
2
|
+
import { f as Plugin } from "./babel-DY_imD3U.mjs";
|
|
3
|
+
import { t as createBabelPlugin } from "./create-plugin-CNzMrex8.mjs";
|
|
4
|
+
import { i as isDuplicatePlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "./filters-93Z-7Nov.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-DiSYdstQ.mjs";
|
|
6
|
+
import { n as resolvePluginFunction, t as resolveBabelPlugin } from "./options-DgdPmsbF.mjs";
|
|
7
|
+
import "./index-ClXLQ1fw.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-Bc0EOyGF.mjs";
|
|
9
|
+
import "./index-QbUkWSLh.mjs";
|
|
10
10
|
|
|
11
11
|
//#region src/index.d.ts
|
|
12
12
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { createBabelPlugin } from "./
|
|
5
|
-
import {
|
|
6
|
-
import "./helpers
|
|
1
|
+
import { i as isDuplicatePlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "./filters-C04cfcQR.mjs";
|
|
2
|
+
import { n as resolvePluginFunction, t as resolveBabelPlugin } from "./options-BQhc80ih.mjs";
|
|
3
|
+
import { n as parseAst, t as generateFromAst } from "./ast-utils-DU1foCxH.mjs";
|
|
4
|
+
import { t as createBabelPlugin } from "./create-plugin-BPSvsem_.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 { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
9
11
|
import { findFileExtension, findFileExtensionSafe } from "@stryke/path/file-path-fns";
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { n as parseAst } from "./ast-utils-DU1foCxH.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 };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { o as ImportSpecifier } from "./babel-B9i2IAT_.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 };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { o as ImportSpecifier } from "./babel-DY_imD3U.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 };
|