@powerlines/plugin-babel 0.12.125 → 0.12.127

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.
@@ -1 +1,29 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -1 +1,35 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`);let t=require(`@babel/generator`);t=e.__toESM(t);let n=require(`@babel/parser`);function r(e,t={}){return(0,n.parse)(e,{plugins:[`typescript`],sourceType:`module`,allowImportExportEverywhere:!0,allowAwaitOutsideFunction:!0,...t})}let i=t.default;`default`in i&&(i=i.default);function a(e,t){return i(e,t?{importAttributesKeyword:`with`,sourceMaps:!0,...t}:void 0)}exports.generateFromAst=a,exports.parseAst=r;
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let __babel_generator = require("@babel/generator");
3
+ __babel_generator = require_rolldown_runtime.__toESM(__babel_generator);
4
+ let __babel_parser = require("@babel/parser");
5
+
6
+ //#region src/helpers/ast-utils.ts
7
+ /**
8
+ * Parse the given code into an AST.
9
+ *
10
+ * @param code - The code to parse.
11
+ * @param opts - The options for parsing.
12
+ * @returns The parsed AST.
13
+ */
14
+ function parseAst(code, opts = {}) {
15
+ return (0, __babel_parser.parse)(code, {
16
+ plugins: ["typescript"],
17
+ sourceType: "module",
18
+ allowImportExportEverywhere: true,
19
+ allowAwaitOutsideFunction: true,
20
+ ...opts
21
+ });
22
+ }
23
+ let generate = __babel_generator.default;
24
+ if ("default" in generate) generate = generate.default;
25
+ function generateFromAst(ast, opts) {
26
+ return generate(ast, opts ? {
27
+ importAttributesKeyword: "with",
28
+ sourceMaps: true,
29
+ ...opts
30
+ } : void 0);
31
+ }
32
+
33
+ //#endregion
34
+ exports.generateFromAst = generateFromAst;
35
+ exports.parseAst = parseAst;
@@ -1 +1,32 @@
1
- import e from"@babel/generator";import{parse as t}from"@babel/parser";function n(e,n={}){return t(e,{plugins:[`typescript`],sourceType:`module`,allowImportExportEverywhere:!0,allowAwaitOutsideFunction:!0,...n})}let r=e;`default`in r&&(r=r.default);function i(e,t){return r(e,t?{importAttributesKeyword:`with`,sourceMaps:!0,...t}:void 0)}export{i as generateFromAst,n as parseAst};
1
+ import _generate from "@babel/generator";
2
+ import { parse } from "@babel/parser";
3
+
4
+ //#region src/helpers/ast-utils.ts
5
+ /**
6
+ * Parse the given code into an AST.
7
+ *
8
+ * @param code - The code to parse.
9
+ * @param opts - The options for parsing.
10
+ * @returns The parsed AST.
11
+ */
12
+ function parseAst(code, opts = {}) {
13
+ return parse(code, {
14
+ plugins: ["typescript"],
15
+ sourceType: "module",
16
+ allowImportExportEverywhere: true,
17
+ allowAwaitOutsideFunction: true,
18
+ ...opts
19
+ });
20
+ }
21
+ let generate = _generate;
22
+ if ("default" in generate) generate = generate.default;
23
+ function generateFromAst(ast, opts) {
24
+ return generate(ast, opts ? {
25
+ importAttributesKeyword: "with",
26
+ sourceMaps: true,
27
+ ...opts
28
+ } : void 0);
29
+ }
30
+
31
+ //#endregion
32
+ export { generateFromAst, parseAst };
@@ -1 +1,41 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`../powerlines/src/lib/logger.cjs`);let n=require(`@storm-software/config-tools/types`),r=require(`chalk`);r=e.__toESM(r);let i=require(`@babel/helper-plugin-utils`);function a(e,a){let o=o=>(0,i.declare)((i,s,c)=>{i.cache.using(()=>o.meta.checksum),i.assertVersion(`^7.0.0-0`);let l=t.extendLog(o.log,e);l(n.LogLevelLabel.TRACE,`Initializing the ${r.default.bold.cyanBright(e)} Babel plugin`);let u=a({log:l,name:e,api:i,options:s,context:o,dirname:c});return u.name=e,l(n.LogLevelLabel.TRACE,`Completed initialization of the ${r.default.bold.cyanBright(e)} Babel plugin`),u});return o.$$name=e,o}exports.createBabelPlugin=a;
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_logger = require('../powerlines/src/lib/logger.cjs');
3
+ let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
4
+ let chalk = require("chalk");
5
+ chalk = require_rolldown_runtime.__toESM(chalk);
6
+ let __babel_helper_plugin_utils = require("@babel/helper-plugin-utils");
7
+
8
+ //#region src/helpers/create-plugin.ts
9
+ /**
10
+ * Create a Babel plugin using the provided builder function.
11
+ *
12
+ * @param name - The name of the plugin.
13
+ * @param builder - The builder function that defines the plugin behavior.
14
+ * @returns A Babel plugin declaration.
15
+ */
16
+ function createBabelPlugin(name, builder) {
17
+ const plugin = (context) => {
18
+ return (0, __babel_helper_plugin_utils.declare)((api, options, dirname) => {
19
+ api.cache.using(() => context.meta.checksum);
20
+ api.assertVersion("^7.0.0-0");
21
+ const log = require_logger.extendLog(context.log, name);
22
+ log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Initializing the ${chalk.default.bold.cyanBright(name)} Babel plugin`);
23
+ const result = builder({
24
+ log,
25
+ name,
26
+ api,
27
+ options,
28
+ context,
29
+ dirname
30
+ });
31
+ result.name = name;
32
+ log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Completed initialization of the ${chalk.default.bold.cyanBright(name)} Babel plugin`);
33
+ return result;
34
+ });
35
+ };
36
+ plugin.$$name = name;
37
+ return plugin;
38
+ }
39
+
40
+ //#endregion
41
+ exports.createBabelPlugin = createBabelPlugin;
@@ -1 +1,39 @@
1
- import{extendLog as e}from"../powerlines/src/lib/logger.mjs";import{LogLevelLabel as t}from"@storm-software/config-tools/types";import n from"chalk";import{declare as r}from"@babel/helper-plugin-utils";function i(i,a){let o=o=>r((r,s,c)=>{r.cache.using(()=>o.meta.checksum),r.assertVersion(`^7.0.0-0`);let l=e(o.log,i);l(t.TRACE,`Initializing the ${n.bold.cyanBright(i)} Babel plugin`);let u=a({log:l,name:i,api:r,options:s,context:o,dirname:c});return u.name=i,l(t.TRACE,`Completed initialization of the ${n.bold.cyanBright(i)} Babel plugin`),u});return o.$$name=i,o}export{i as createBabelPlugin};
1
+ import { extendLog } from "../powerlines/src/lib/logger.mjs";
2
+ import { LogLevelLabel } from "@storm-software/config-tools/types";
3
+ import chalk from "chalk";
4
+ import { declare } from "@babel/helper-plugin-utils";
5
+
6
+ //#region src/helpers/create-plugin.ts
7
+ /**
8
+ * Create a Babel plugin using the provided builder function.
9
+ *
10
+ * @param name - The name of the plugin.
11
+ * @param builder - The builder function that defines the plugin behavior.
12
+ * @returns A Babel plugin declaration.
13
+ */
14
+ function createBabelPlugin(name, builder) {
15
+ const plugin = (context) => {
16
+ return declare((api, options, dirname) => {
17
+ api.cache.using(() => context.meta.checksum);
18
+ api.assertVersion("^7.0.0-0");
19
+ const log = extendLog(context.log, name);
20
+ log(LogLevelLabel.TRACE, `Initializing the ${chalk.bold.cyanBright(name)} Babel plugin`);
21
+ const result = builder({
22
+ log,
23
+ name,
24
+ api,
25
+ options,
26
+ context,
27
+ dirname
28
+ });
29
+ result.name = name;
30
+ log(LogLevelLabel.TRACE, `Completed initialization of the ${chalk.bold.cyanBright(name)} Babel plugin`);
31
+ return result;
32
+ });
33
+ };
34
+ plugin.$$name = name;
35
+ return plugin;
36
+ }
37
+
38
+ //#endregion
39
+ export { createBabelPlugin };
@@ -1 +1,59 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`);let t=require(`@stryke/type-checks/is-function`),n=require(`@stryke/type-checks/is-object`),r=require(`@stryke/type-checks/is-set-string`);function i(e){return(0,r.isSetString)(e)?e:Array.isArray(e)&&e.length>0?i(e[0]):e.$$name||e.name?e.$$name||e.name:void 0}function a(e,t){return!!(i(t)&&e.some(e=>Array.isArray(e)&&i(e[0])===i(t)))}function o(e,t){return(n,r)=>t!==r&&e.fs.ids[t]!==r&&t!==e.fs.ids[r]&&e.fs.ids[t]!==e.fs.ids[r]}function s(e,a,o,c){if(!Array.isArray(a)||!a.some(e=>Array.isArray(e))&&a.length<4&&a.length>0&&((0,r.isSetString)(a[0])||(0,t.isFunction)(a[0])||a.length>1&&(0,n.isObject)(a[1])||a.length>2&&(0,n.isObject)(a[2])))return Array.isArray(a)?[a[0],a.length>1?a[1]:{},{filter:(e,n)=>o(e,n)&&(a.length<2||!(0,t.isFunction)(a[2])||a[2]?.(e,n))}]:[a,{},{filter:o}];if(!c)throw Error("No name was provided to `addPluginFilter`, could not find babel plugin without it.");let l=a.findIndex(e=>i(e)?.toLowerCase()===c.toLowerCase());return l>-1&&(a[l]=s(e,a[l],o,c)),a}exports.addPluginFilter=s,exports.filterPluginByFileId=o,exports.getPluginName=i,exports.isDuplicatePlugin=a;
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
3
+ let __stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
4
+ let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
5
+
6
+ //#region src/helpers/filters.ts
7
+ function getPluginName(plugin) {
8
+ return (0, __stryke_type_checks_is_set_string.isSetString)(plugin) ? plugin : Array.isArray(plugin) && plugin.length > 0 ? getPluginName(plugin[0]) : plugin.$$name || plugin.name ? plugin.$$name || plugin.name : void 0;
9
+ }
10
+ /**
11
+ * Check if a Babel plugin is a duplicate of another plugin in the list.
12
+ *
13
+ * @param plugins - The list of existing Babel plugins.
14
+ * @param plugin - The Babel plugin to check for duplicates.
15
+ * @returns True if the plugin is a duplicate, false otherwise.
16
+ */
17
+ function isDuplicatePlugin(plugins, plugin) {
18
+ return !!(getPluginName(plugin) && plugins.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(plugin)));
19
+ }
20
+ /**
21
+ * Filters a Babel plugin by its runtime ID.
22
+ *
23
+ * @param context - The context in which the filter is applied.
24
+ * @param fileId - The file ID to filter by.
25
+ * @returns A filter function that checks if a plugin's ID matches the runtime ID.
26
+ */
27
+ function filterPluginByFileId(context, fileId) {
28
+ return (code, id) => fileId !== id && context.fs.ids[fileId] !== id && fileId !== context.fs.ids[id] && context.fs.ids[fileId] !== context.fs.ids[id];
29
+ }
30
+ /**
31
+ * Adds a filter to a Babel plugin or a list of Babel plugins.
32
+ *
33
+ * @param context - The context in which the plugin is being added.
34
+ * @param pluginOrPlugins - The Babel plugin or plugins to add the filter to.
35
+ * @param filter - The filter function to apply to the plugins.
36
+ * @param name - The name of the plugin to add the filter to.
37
+ * @returns The updated list of Babel plugins with the filter applied.
38
+ */
39
+ function addPluginFilter(context, pluginOrPlugins, filter, name) {
40
+ if (!Array.isArray(pluginOrPlugins) || !pluginOrPlugins.some((plugin) => Array.isArray(plugin)) && pluginOrPlugins.length < 4 && pluginOrPlugins.length > 0 && ((0, __stryke_type_checks_is_set_string.isSetString)(pluginOrPlugins[0]) || (0, __stryke_type_checks_is_function.isFunction)(pluginOrPlugins[0]) || pluginOrPlugins.length > 1 && (0, __stryke_type_checks_is_object.isObject)(pluginOrPlugins[1]) || pluginOrPlugins.length > 2 && (0, __stryke_type_checks_is_object.isObject)(pluginOrPlugins[2]))) return Array.isArray(pluginOrPlugins) ? [
41
+ pluginOrPlugins[0],
42
+ pluginOrPlugins.length > 1 ? pluginOrPlugins[1] : {},
43
+ { filter: (code, id) => filter(code, id) && (pluginOrPlugins.length < 2 || !(0, __stryke_type_checks_is_function.isFunction)(pluginOrPlugins[2]) || pluginOrPlugins[2]?.(code, id)) }
44
+ ] : [
45
+ pluginOrPlugins,
46
+ {},
47
+ { filter }
48
+ ];
49
+ if (!name) throw new Error("No name was provided to `addPluginFilter`, could not find babel plugin without it.");
50
+ const foundIndex = pluginOrPlugins.findIndex((plugin) => getPluginName(plugin)?.toLowerCase() === name.toLowerCase());
51
+ if (foundIndex > -1) pluginOrPlugins[foundIndex] = addPluginFilter(context, pluginOrPlugins[foundIndex], filter, name);
52
+ return pluginOrPlugins;
53
+ }
54
+
55
+ //#endregion
56
+ exports.addPluginFilter = addPluginFilter;
57
+ exports.filterPluginByFileId = filterPluginByFileId;
58
+ exports.getPluginName = getPluginName;
59
+ exports.isDuplicatePlugin = isDuplicatePlugin;
@@ -1 +1,55 @@
1
- import{isFunction as e}from"@stryke/type-checks/is-function";import{isObject as t}from"@stryke/type-checks/is-object";import{isSetString as n}from"@stryke/type-checks/is-set-string";function r(e){return n(e)?e:Array.isArray(e)&&e.length>0?r(e[0]):e.$$name||e.name?e.$$name||e.name:void 0}function i(e,t){return!!(r(t)&&e.some(e=>Array.isArray(e)&&r(e[0])===r(t)))}function a(e,t){return(n,r)=>t!==r&&e.fs.ids[t]!==r&&t!==e.fs.ids[r]&&e.fs.ids[t]!==e.fs.ids[r]}function o(i,a,s,c){if(!Array.isArray(a)||!a.some(e=>Array.isArray(e))&&a.length<4&&a.length>0&&(n(a[0])||e(a[0])||a.length>1&&t(a[1])||a.length>2&&t(a[2])))return Array.isArray(a)?[a[0],a.length>1?a[1]:{},{filter:(t,n)=>s(t,n)&&(a.length<2||!e(a[2])||a[2]?.(t,n))}]:[a,{},{filter:s}];if(!c)throw Error("No name was provided to `addPluginFilter`, could not find babel plugin without it.");let l=a.findIndex(e=>r(e)?.toLowerCase()===c.toLowerCase());return l>-1&&(a[l]=o(i,a[l],s,c)),a}export{o as addPluginFilter,a as filterPluginByFileId,r as getPluginName,i as isDuplicatePlugin};
1
+ import { isFunction } from "@stryke/type-checks/is-function";
2
+ import { isObject } from "@stryke/type-checks/is-object";
3
+ import { isSetString } from "@stryke/type-checks/is-set-string";
4
+
5
+ //#region src/helpers/filters.ts
6
+ function getPluginName(plugin) {
7
+ return isSetString(plugin) ? plugin : Array.isArray(plugin) && plugin.length > 0 ? getPluginName(plugin[0]) : plugin.$$name || plugin.name ? plugin.$$name || plugin.name : void 0;
8
+ }
9
+ /**
10
+ * Check if a Babel plugin is a duplicate of another plugin in the list.
11
+ *
12
+ * @param plugins - The list of existing Babel plugins.
13
+ * @param plugin - The Babel plugin to check for duplicates.
14
+ * @returns True if the plugin is a duplicate, false otherwise.
15
+ */
16
+ function isDuplicatePlugin(plugins, plugin) {
17
+ return !!(getPluginName(plugin) && plugins.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(plugin)));
18
+ }
19
+ /**
20
+ * Filters a Babel plugin by its runtime ID.
21
+ *
22
+ * @param context - The context in which the filter is applied.
23
+ * @param fileId - The file ID to filter by.
24
+ * @returns A filter function that checks if a plugin's ID matches the runtime ID.
25
+ */
26
+ function filterPluginByFileId(context, fileId) {
27
+ return (code, id) => fileId !== id && context.fs.ids[fileId] !== id && fileId !== context.fs.ids[id] && context.fs.ids[fileId] !== context.fs.ids[id];
28
+ }
29
+ /**
30
+ * Adds a filter to a Babel plugin or a list of Babel plugins.
31
+ *
32
+ * @param context - The context in which the plugin is being added.
33
+ * @param pluginOrPlugins - The Babel plugin or plugins to add the filter to.
34
+ * @param filter - The filter function to apply to the plugins.
35
+ * @param name - The name of the plugin to add the filter to.
36
+ * @returns The updated list of Babel plugins with the filter applied.
37
+ */
38
+ function addPluginFilter(context, pluginOrPlugins, filter, name) {
39
+ if (!Array.isArray(pluginOrPlugins) || !pluginOrPlugins.some((plugin) => Array.isArray(plugin)) && pluginOrPlugins.length < 4 && pluginOrPlugins.length > 0 && (isSetString(pluginOrPlugins[0]) || isFunction(pluginOrPlugins[0]) || pluginOrPlugins.length > 1 && isObject(pluginOrPlugins[1]) || pluginOrPlugins.length > 2 && isObject(pluginOrPlugins[2]))) return Array.isArray(pluginOrPlugins) ? [
40
+ pluginOrPlugins[0],
41
+ pluginOrPlugins.length > 1 ? pluginOrPlugins[1] : {},
42
+ { filter: (code, id) => filter(code, id) && (pluginOrPlugins.length < 2 || !isFunction(pluginOrPlugins[2]) || pluginOrPlugins[2]?.(code, id)) }
43
+ ] : [
44
+ pluginOrPlugins,
45
+ {},
46
+ { filter }
47
+ ];
48
+ if (!name) throw new Error("No name was provided to `addPluginFilter`, could not find babel plugin without it.");
49
+ const foundIndex = pluginOrPlugins.findIndex((plugin) => getPluginName(plugin)?.toLowerCase() === name.toLowerCase());
50
+ if (foundIndex > -1) pluginOrPlugins[foundIndex] = addPluginFilter(context, pluginOrPlugins[foundIndex], filter, name);
51
+ return pluginOrPlugins;
52
+ }
53
+
54
+ //#endregion
55
+ export { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin };
@@ -1 +1,22 @@
1
- const e=require(`./filters.cjs`),t=require(`./options.cjs`),n=require(`./ast-utils.cjs`),r=require(`./create-plugin.cjs`),i=require(`./module-helpers.cjs`);exports.addImport=i.addImport,exports.addImportsToProgram=i.addImportsToProgram,exports.addPluginFilter=e.addPluginFilter,exports.createBabelPlugin=r.createBabelPlugin,exports.filterPluginByFileId=e.filterPluginByFileId,exports.findExport=i.findExport,exports.generateFromAst=n.generateFromAst,exports.getImport=i.getImport,exports.getPluginName=e.getPluginName,exports.isDuplicatePlugin=e.isDuplicatePlugin,exports.isImportCall=i.isImportCall,exports.listExports=i.listExports,exports.listImports=i.listImports,exports.parseAst=n.parseAst,exports.resolveBabelPlugin=t.resolveBabelPlugin,exports.resolvePluginFunction=t.resolvePluginFunction;
1
+ const require_helpers_filters = require('./filters.cjs');
2
+ const require_helpers_options = require('./options.cjs');
3
+ const require_helpers_ast_utils = require('./ast-utils.cjs');
4
+ const require_helpers_create_plugin = require('./create-plugin.cjs');
5
+ const require_helpers_module_helpers = require('./module-helpers.cjs');
6
+
7
+ exports.addImport = require_helpers_module_helpers.addImport;
8
+ exports.addImportsToProgram = require_helpers_module_helpers.addImportsToProgram;
9
+ exports.addPluginFilter = require_helpers_filters.addPluginFilter;
10
+ exports.createBabelPlugin = require_helpers_create_plugin.createBabelPlugin;
11
+ exports.filterPluginByFileId = require_helpers_filters.filterPluginByFileId;
12
+ exports.findExport = require_helpers_module_helpers.findExport;
13
+ exports.generateFromAst = require_helpers_ast_utils.generateFromAst;
14
+ exports.getImport = require_helpers_module_helpers.getImport;
15
+ exports.getPluginName = require_helpers_filters.getPluginName;
16
+ exports.isDuplicatePlugin = require_helpers_filters.isDuplicatePlugin;
17
+ exports.isImportCall = require_helpers_module_helpers.isImportCall;
18
+ exports.listExports = require_helpers_module_helpers.listExports;
19
+ exports.listImports = require_helpers_module_helpers.listImports;
20
+ exports.parseAst = require_helpers_ast_utils.parseAst;
21
+ exports.resolveBabelPlugin = require_helpers_options.resolveBabelPlugin;
22
+ exports.resolvePluginFunction = require_helpers_options.resolvePluginFunction;
@@ -1 +1,7 @@
1
- import{addPluginFilter as e,filterPluginByFileId as t,getPluginName as n,isDuplicatePlugin as r}from"./filters.mjs";import{resolveBabelPlugin as i,resolvePluginFunction as a}from"./options.mjs";import{generateFromAst as o,parseAst as s}from"./ast-utils.mjs";import{createBabelPlugin as c}from"./create-plugin.mjs";import{addImport as l,addImportsToProgram as u,findExport as d,getImport as f,isImportCall as p,listExports as m,listImports as h}from"./module-helpers.mjs";export{l as addImport,u as addImportsToProgram,e as addPluginFilter,c as createBabelPlugin,t as filterPluginByFileId,d as findExport,o as generateFromAst,f as getImport,n as getPluginName,r as isDuplicatePlugin,p as isImportCall,m as listExports,h as listImports,s as parseAst,i as resolveBabelPlugin,a as resolvePluginFunction};
1
+ import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin } from "./filters.mjs";
2
+ import { resolveBabelPlugin, resolvePluginFunction } from "./options.mjs";
3
+ import { generateFromAst, parseAst } from "./ast-utils.mjs";
4
+ import { createBabelPlugin } from "./create-plugin.mjs";
5
+ import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./module-helpers.mjs";
6
+
7
+ export { addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolvePluginFunction };
@@ -1 +1,103 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`./ast-utils.cjs`);let n=require(`@babel/types`);n=e.__toESM(n);let r=require(`@stryke/type-checks/is-string`);function i(e,t){let n=t===`default`?`ExportDefaultDeclaration`:`ExportNamedDeclaration`;for(let r of e.program.body)if(r.type===n){if(t===`default`)return r.declaration;if(r.declaration&&`declarations`in r.declaration){let e=r.declaration.declarations[0];if(e&&`name`in e.id&&e.id.name===t)return e.init}}}function a(e){return((0,r.isString)(e)?t.parseAst(e):e).program.body.flatMap(e=>e.type===`ExportDefaultDeclaration`?[`default`]:e.type===`ExportNamedDeclaration`&&e.declaration&&`declarations`in e.declaration?e.declaration.declarations.map(e=>`name`in e.id?e.id.name:``):[]).filter(Boolean)}function o(e){return e.program.body.flatMap(e=>e.type===`ImportDeclaration`?e.specifiers.map(e=>e.type===`ImportDefaultSpecifier`?`default`:e.type===`ImportSpecifier`&&`imported`in e?e.imported.type===`Identifier`?e.imported.name:e.imported.value:``):[]).filter(Boolean)}function s(e){return n.isImport(e.node.callee)}function c(e,t,r){return n.importDeclaration([n.importSpecifier(n.identifier(t),n.stringLiteral(r||t))],n.stringLiteral(e))}function l(e,t){f(e.scope.getProgramParent().path,t)}function u(e){return e.get(`specifiers`).filter(Boolean).every(e=>e?.isImportSpecifier())&&e.node.importKind!==`type`&&e.node.importKind!==`typeof`}function d(e){let t=new Map;return e.traverse({ImportDeclaration(e){u(e)&&t.set(e.node.source.value,e)}}),t}function f(e,t){d(e).get(t.module)||e.unshiftContainer(`body`,n.importDeclaration([n.importSpecifier(n.identifier(t.name||t.imported),n.identifier(t.imported))],n.stringLiteral(t.module)))}exports.addImport=l,exports.addImportsToProgram=f,exports.findExport=i,exports.getImport=c,exports.isImportCall=s,exports.listExports=a,exports.listImports=o;
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_helpers_ast_utils = require('./ast-utils.cjs');
3
+ let __babel_types = require("@babel/types");
4
+ __babel_types = require_rolldown_runtime.__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_helpers_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
+ exports.addImport = addImport;
98
+ exports.addImportsToProgram = addImportsToProgram;
99
+ exports.findExport = findExport;
100
+ exports.getImport = getImport;
101
+ exports.isImportCall = isImportCall;
102
+ exports.listExports = listExports;
103
+ exports.listImports = listImports;
@@ -1 +1,95 @@
1
- import{parseAst as e}from"./ast-utils.mjs";import*as t from"@babel/types";import{isString as n}from"@stryke/type-checks/is-string";function r(e,t){let n=t===`default`?`ExportDefaultDeclaration`:`ExportNamedDeclaration`;for(let r of e.program.body)if(r.type===n){if(t===`default`)return r.declaration;if(r.declaration&&`declarations`in r.declaration){let e=r.declaration.declarations[0];if(e&&`name`in e.id&&e.id.name===t)return e.init}}}function i(t){return(n(t)?e(t):t).program.body.flatMap(e=>e.type===`ExportDefaultDeclaration`?[`default`]:e.type===`ExportNamedDeclaration`&&e.declaration&&`declarations`in e.declaration?e.declaration.declarations.map(e=>`name`in e.id?e.id.name:``):[]).filter(Boolean)}function a(e){return e.program.body.flatMap(e=>e.type===`ImportDeclaration`?e.specifiers.map(e=>e.type===`ImportDefaultSpecifier`?`default`:e.type===`ImportSpecifier`&&`imported`in e?e.imported.type===`Identifier`?e.imported.name:e.imported.value:``):[]).filter(Boolean)}function o(e){return t.isImport(e.node.callee)}function s(e,n,r){return t.importDeclaration([t.importSpecifier(t.identifier(n),t.stringLiteral(r||n))],t.stringLiteral(e))}function c(e,t){d(e.scope.getProgramParent().path,t)}function l(e){return e.get(`specifiers`).filter(Boolean).every(e=>e?.isImportSpecifier())&&e.node.importKind!==`type`&&e.node.importKind!==`typeof`}function u(e){let t=new Map;return e.traverse({ImportDeclaration(e){l(e)&&t.set(e.node.source.value,e)}}),t}function d(e,n){u(e).get(n.module)||e.unshiftContainer(`body`,t.importDeclaration([t.importSpecifier(t.identifier(n.name||n.imported),t.identifier(n.imported))],t.stringLiteral(n.module)))}export{c as addImport,d as addImportsToProgram,r as findExport,s as getImport,o as isImportCall,i as listExports,a as listImports};
1
+ import { parseAst } from "./ast-utils.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 { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
@@ -1 +1,50 @@
1
- const e=require(`../_virtual/rolldown_runtime.cjs`),t=require(`./filters.cjs`);let n=require(`@storm-software/config-tools/types`),r=require(`@stryke/type-checks/is-function`),i=require(`chalk`);i=e.__toESM(i);function a(e,t){try{return Array.isArray(t)&&t.length>0&&t[0]?(0,r.isFunction)(t[0])?t[0](e):t[0]:(0,r.isFunction)(t)?t(e):t}catch{return t[0]}}function o(e,o,s,c){if(Array.isArray(c)&&c.length>0&&c[0]){if(c.length>2&&c[2]&&(0,r.isFunction)(c[2])&&!c[2](o,s)){e.log(n.LogLevelLabel.TRACE,`Skipping filtered Babel plugin ${i.default.bold.cyanBright(t.getPluginName(c)||`unnamed`)} for ${s}`);return}return c.length>2?[a(e,c),c[1],c[2]]:[a(e,c),c[1],null]}return[a(e,c),{},null]}exports.resolveBabelPlugin=o,exports.resolvePluginFunction=a;
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
2
+ const require_helpers_filters = require('./filters.cjs');
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);
7
+
8
+ //#region src/helpers/options.ts
9
+ function resolvePluginFunction(context, plugin) {
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;
@@ -1 +1,47 @@
1
- import{getPluginName as e}from"./filters.mjs";import{LogLevelLabel as t}from"@storm-software/config-tools/types";import{isFunction as n}from"@stryke/type-checks/is-function";import r from"chalk";function i(e,t){try{return Array.isArray(t)&&t.length>0&&t[0]?n(t[0])?t[0](e):t[0]:n(t)?t(e):t}catch{return t[0]}}function a(a,o,s,c){if(Array.isArray(c)&&c.length>0&&c[0]){if(c.length>2&&c[2]&&n(c[2])&&!c[2](o,s)){a.log(t.TRACE,`Skipping filtered Babel plugin ${r.bold.cyanBright(e(c)||`unnamed`)} for ${s}`);return}return c.length>2?[i(a,c),c[1],c[2]]:[i(a,c),c[1],null]}return[i(a,c),{},null]}export{a as resolveBabelPlugin,i as resolvePluginFunction};
1
+ import { getPluginName } from "./filters.mjs";
2
+ import { LogLevelLabel } from "@storm-software/config-tools/types";
3
+ import { isFunction } from "@stryke/type-checks/is-function";
4
+ import chalk from "chalk";
5
+
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
+ export { resolveBabelPlugin, resolvePluginFunction };
package/dist/index.cjs CHANGED
@@ -1 +1,110 @@
1
- Object.defineProperty(exports,`__esModule`,{value:!0});const e=require(`./_virtual/rolldown_runtime.cjs`),t=require(`./helpers/filters.cjs`),n=require(`./helpers/options.cjs`),r=require(`./helpers/ast-utils.cjs`),i=require(`./helpers/create-plugin.cjs`),a=require(`./helpers/module-helpers.cjs`);require(`./helpers/index.cjs`);let o=require(`@babel/core`),s=require(`@storm-software/config-tools/types`),c=require(`@stryke/path/file-path-fns`),l=require(`@stryke/path/is-parent-path`),u=require(`@stryke/type-checks/is-set-object`),d=require(`defu`);d=e.__toESM(d);const f=(e={})=>({name:`babel`,config(){if((0,u.isSetObject)(e))return{transform:{babel:e}}},configResolved:{order:`pre`,handler(){this.devDependencies[`@babel/core`]=`^7.28.4`,this.config.transform.babel=(0,d.default)(this.config.transform.babel??{},{plugins:[],presets:[]})}},async transform(r,i){if((0,l.isParentPath)(i,this.powerlinesPath)||r.includes(`/* @storm-ignore */`)||r.includes(`/* @storm-disable */`))return this.log(s.LogLevelLabel.TRACE,`Skipping Babel transformation for: ${i}`),{code:r,id:i};this.log(s.LogLevelLabel.TRACE,`Babel transforming file: ${i}`);let a=this.config.transform.babel.plugins.map(e=>n.resolveBabelPlugin(this,r,i,e)).filter((e,n,r)=>e&&!t.isDuplicatePlugin(r,e)),u=this.config.transform.babel.presets.map(e=>n.resolveBabelPlugin(this,r,i,e)).filter((e,n,r)=>e&&!t.isDuplicatePlugin(r,e));if(Array.isArray(a)&&a.length===0&&Array.isArray(u)&&u.length===0)return{code:r,id:i};[`ts`,`cts`,`mts`,`tsx`].includes((0,c.findFileExtensionSafe)(i))&&!t.isDuplicatePlugin(a,`@babel/plugin-syntax-typescript`)&&!t.isDuplicatePlugin(u,`@babel/preset-typescript`)&&a.unshift([`@babel/plugin-syntax-typescript`,{isTSX:(0,c.findFileExtension)(i)===`.tsx`}]);let f=await(0,o.transformAsync)(r,{highlightCode:!0,code:!0,ast:!1,cloneInputAst:!1,comments:!0,sourceType:`module`,configFile:!1,babelrc:!1,envName:this.config.mode,caller:{name:this.config.framework},...this.config.transform.babel??{},filename:i,plugins:a.map(t=>Array.isArray(t)&&t.length>=2?[t[0],(0,d.default)(t.length>1&&t[1]?t[1]:{},{options:e})]:t).filter(Boolean),presets:u.map(t=>Array.isArray(t)&&t.length>=2?[t[0],(0,d.default)(t.length>1&&t[1]?t[1]:{},{options:e})]:t).filter(Boolean)});if(!f?.code)throw Error(`Powerlines - Babel plugin failed to compile ${i}`);return{code:f.code,id:i}}});var p=f;exports.addImport=a.addImport,exports.addImportsToProgram=a.addImportsToProgram,exports.addPluginFilter=t.addPluginFilter,exports.createBabelPlugin=i.createBabelPlugin,exports.default=p,exports.filterPluginByFileId=t.filterPluginByFileId,exports.findExport=a.findExport,exports.generateFromAst=r.generateFromAst,exports.getImport=a.getImport,exports.getPluginName=t.getPluginName,exports.isDuplicatePlugin=t.isDuplicatePlugin,exports.isImportCall=a.isImportCall,exports.listExports=a.listExports,exports.listImports=a.listImports,exports.parseAst=r.parseAst,exports.plugin=f,exports.resolveBabelPlugin=n.resolveBabelPlugin,exports.resolvePluginFunction=n.resolvePluginFunction;
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');
9
+ let __babel_core = require("@babel/core");
10
+ let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
11
+ let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
12
+ let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
13
+ let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
14
+ let defu = require("defu");
15
+ defu = require_rolldown_runtime.__toESM(defu);
16
+
17
+ //#region src/index.ts
18
+ /**
19
+ * Babel plugin for Powerlines.
20
+ *
21
+ * @param options - The Babel plugin user configuration options.
22
+ * @returns A Powerlines plugin that integrates Babel transformations.
23
+ */
24
+ const plugin = (options = {}) => {
25
+ return {
26
+ name: "babel",
27
+ config() {
28
+ if (!(0, __stryke_type_checks_is_set_object.isSetObject)(options)) return;
29
+ return { transform: { babel: options } };
30
+ },
31
+ configResolved: {
32
+ order: "pre",
33
+ handler() {
34
+ this.devDependencies["@babel/core"] = "^7.28.4";
35
+ this.config.transform.babel = (0, defu.default)(this.config.transform.babel ?? {}, {
36
+ plugins: [],
37
+ presets: []
38
+ });
39
+ }
40
+ },
41
+ async transform(code, id) {
42
+ if ((0, __stryke_path_is_parent_path.isParentPath)(id, this.powerlinesPath) || code.includes("/* @storm-ignore */") || code.includes("/* @storm-disable */")) {
43
+ this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Skipping Babel transformation for: ${id}`);
44
+ return {
45
+ code,
46
+ id
47
+ };
48
+ }
49
+ this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Babel transforming file: ${id}`);
50
+ 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));
51
+ 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));
52
+ if (Array.isArray(plugins) && plugins.length === 0 && Array.isArray(presets) && presets.length === 0) return {
53
+ code,
54
+ id
55
+ };
56
+ if ([
57
+ "ts",
58
+ "cts",
59
+ "mts",
60
+ "tsx"
61
+ ].includes((0, __stryke_path_file_path_fns.findFileExtensionSafe)(id)) && !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" }]);
62
+ const result = await (0, __babel_core.transformAsync)(code, {
63
+ highlightCode: true,
64
+ code: true,
65
+ ast: false,
66
+ cloneInputAst: false,
67
+ comments: true,
68
+ sourceType: "module",
69
+ configFile: false,
70
+ babelrc: false,
71
+ envName: this.config.mode,
72
+ caller: { name: this.config.framework },
73
+ ...this.config.transform.babel ?? {},
74
+ filename: id,
75
+ plugins: plugins.map((plugin$1) => {
76
+ return Array.isArray(plugin$1) && plugin$1.length >= 2 ? [plugin$1[0], (0, defu.default)(plugin$1.length > 1 && plugin$1[1] ? plugin$1[1] : {}, { options })] : plugin$1;
77
+ }).filter(Boolean),
78
+ presets: presets.map((preset) => {
79
+ return Array.isArray(preset) && preset.length >= 2 ? [preset[0], (0, defu.default)(preset.length > 1 && preset[1] ? preset[1] : {}, { options })] : preset;
80
+ }).filter(Boolean)
81
+ });
82
+ if (!result?.code) throw new Error(`Powerlines - Babel plugin failed to compile ${id}`);
83
+ return {
84
+ code: result.code,
85
+ id
86
+ };
87
+ }
88
+ };
89
+ };
90
+ var src_default = plugin;
91
+
92
+ //#endregion
93
+ exports.addImport = require_helpers_module_helpers.addImport;
94
+ exports.addImportsToProgram = require_helpers_module_helpers.addImportsToProgram;
95
+ exports.addPluginFilter = require_helpers_filters.addPluginFilter;
96
+ exports.createBabelPlugin = require_helpers_create_plugin.createBabelPlugin;
97
+ exports.default = src_default;
98
+ exports.filterPluginByFileId = require_helpers_filters.filterPluginByFileId;
99
+ exports.findExport = require_helpers_module_helpers.findExport;
100
+ exports.generateFromAst = require_helpers_ast_utils.generateFromAst;
101
+ exports.getImport = require_helpers_module_helpers.getImport;
102
+ exports.getPluginName = require_helpers_filters.getPluginName;
103
+ exports.isDuplicatePlugin = require_helpers_filters.isDuplicatePlugin;
104
+ exports.isImportCall = require_helpers_module_helpers.isImportCall;
105
+ exports.listExports = require_helpers_module_helpers.listExports;
106
+ exports.listImports = require_helpers_module_helpers.listImports;
107
+ exports.parseAst = require_helpers_ast_utils.parseAst;
108
+ exports.plugin = plugin;
109
+ exports.resolveBabelPlugin = require_helpers_options.resolveBabelPlugin;
110
+ exports.resolvePluginFunction = require_helpers_options.resolvePluginFunction;
package/dist/index.mjs CHANGED
@@ -1 +1,90 @@
1
- import{addPluginFilter as e,filterPluginByFileId as t,getPluginName as n,isDuplicatePlugin as r}from"./helpers/filters.mjs";import{resolveBabelPlugin as i,resolvePluginFunction as a}from"./helpers/options.mjs";import{generateFromAst as o,parseAst as s}from"./helpers/ast-utils.mjs";import{createBabelPlugin as c}from"./helpers/create-plugin.mjs";import{addImport as l,addImportsToProgram as u,findExport as d,getImport as f,isImportCall as p,listExports as m,listImports as h}from"./helpers/module-helpers.mjs";import"./helpers/index.mjs";import{transformAsync as g}from"@babel/core";import{LogLevelLabel as _}from"@storm-software/config-tools/types";import{findFileExtension as v,findFileExtensionSafe as y}from"@stryke/path/file-path-fns";import{isParentPath as b}from"@stryke/path/is-parent-path";import{isSetObject as x}from"@stryke/type-checks/is-set-object";import S from"defu";const C=(e={})=>({name:`babel`,config(){if(x(e))return{transform:{babel:e}}},configResolved:{order:`pre`,handler(){this.devDependencies[`@babel/core`]=`^7.28.4`,this.config.transform.babel=S(this.config.transform.babel??{},{plugins:[],presets:[]})}},async transform(t,n){if(b(n,this.powerlinesPath)||t.includes(`/* @storm-ignore */`)||t.includes(`/* @storm-disable */`))return this.log(_.TRACE,`Skipping Babel transformation for: ${n}`),{code:t,id:n};this.log(_.TRACE,`Babel transforming file: ${n}`);let a=this.config.transform.babel.plugins.map(e=>i(this,t,n,e)).filter((e,t,n)=>e&&!r(n,e)),o=this.config.transform.babel.presets.map(e=>i(this,t,n,e)).filter((e,t,n)=>e&&!r(n,e));if(Array.isArray(a)&&a.length===0&&Array.isArray(o)&&o.length===0)return{code:t,id:n};[`ts`,`cts`,`mts`,`tsx`].includes(y(n))&&!r(a,`@babel/plugin-syntax-typescript`)&&!r(o,`@babel/preset-typescript`)&&a.unshift([`@babel/plugin-syntax-typescript`,{isTSX:v(n)===`.tsx`}]);let s=await g(t,{highlightCode:!0,code:!0,ast:!1,cloneInputAst:!1,comments:!0,sourceType:`module`,configFile:!1,babelrc:!1,envName:this.config.mode,caller:{name:this.config.framework},...this.config.transform.babel??{},filename:n,plugins:a.map(t=>Array.isArray(t)&&t.length>=2?[t[0],S(t.length>1&&t[1]?t[1]:{},{options:e})]:t).filter(Boolean),presets:o.map(t=>Array.isArray(t)&&t.length>=2?[t[0],S(t.length>1&&t[1]?t[1]:{},{options:e})]:t).filter(Boolean)});if(!s?.code)throw Error(`Powerlines - Babel plugin failed to compile ${n}`);return{code:s.code,id:n}}});var w=C;export{l as addImport,u as addImportsToProgram,e as addPluginFilter,c as createBabelPlugin,w as default,t as filterPluginByFileId,d as findExport,o as generateFromAst,f as getImport,n as getPluginName,r as isDuplicatePlugin,p as isImportCall,m as listExports,h as listImports,s as parseAst,C as plugin,i as resolveBabelPlugin,a as resolvePluginFunction};
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";
7
+ import { transformAsync } from "@babel/core";
8
+ import { LogLevelLabel } from "@storm-software/config-tools/types";
9
+ import { findFileExtension, findFileExtensionSafe } from "@stryke/path/file-path-fns";
10
+ import { isParentPath } from "@stryke/path/is-parent-path";
11
+ import { isSetObject } from "@stryke/type-checks/is-set-object";
12
+ import defu from "defu";
13
+
14
+ //#region src/index.ts
15
+ /**
16
+ * Babel plugin for Powerlines.
17
+ *
18
+ * @param options - The Babel plugin user configuration options.
19
+ * @returns A Powerlines plugin that integrates Babel transformations.
20
+ */
21
+ const plugin = (options = {}) => {
22
+ return {
23
+ name: "babel",
24
+ config() {
25
+ if (!isSetObject(options)) return;
26
+ return { transform: { babel: options } };
27
+ },
28
+ configResolved: {
29
+ order: "pre",
30
+ handler() {
31
+ this.devDependencies["@babel/core"] = "^7.28.4";
32
+ this.config.transform.babel = defu(this.config.transform.babel ?? {}, {
33
+ plugins: [],
34
+ presets: []
35
+ });
36
+ }
37
+ },
38
+ async transform(code, id) {
39
+ if (isParentPath(id, this.powerlinesPath) || code.includes("/* @storm-ignore */") || code.includes("/* @storm-disable */")) {
40
+ this.log(LogLevelLabel.TRACE, `Skipping Babel transformation for: ${id}`);
41
+ return {
42
+ code,
43
+ id
44
+ };
45
+ }
46
+ this.log(LogLevelLabel.TRACE, `Babel transforming file: ${id}`);
47
+ const plugins = this.config.transform.babel.plugins.map((plugin$1) => resolveBabelPlugin(this, code, id, plugin$1)).filter((plugin$1, _, arr) => plugin$1 && !isDuplicatePlugin(arr, plugin$1));
48
+ const presets = this.config.transform.babel.presets.map((preset) => resolveBabelPlugin(this, code, id, preset)).filter((preset, _, arr) => preset && !isDuplicatePlugin(arr, preset));
49
+ if (Array.isArray(plugins) && plugins.length === 0 && Array.isArray(presets) && presets.length === 0) return {
50
+ code,
51
+ id
52
+ };
53
+ if ([
54
+ "ts",
55
+ "cts",
56
+ "mts",
57
+ "tsx"
58
+ ].includes(findFileExtensionSafe(id)) && !isDuplicatePlugin(plugins, "@babel/plugin-syntax-typescript") && !isDuplicatePlugin(presets, "@babel/preset-typescript")) plugins.unshift(["@babel/plugin-syntax-typescript", { isTSX: findFileExtension(id) === ".tsx" }]);
59
+ const result = await transformAsync(code, {
60
+ highlightCode: true,
61
+ code: true,
62
+ ast: false,
63
+ cloneInputAst: false,
64
+ comments: true,
65
+ sourceType: "module",
66
+ configFile: false,
67
+ babelrc: false,
68
+ envName: this.config.mode,
69
+ caller: { name: this.config.framework },
70
+ ...this.config.transform.babel ?? {},
71
+ filename: id,
72
+ plugins: plugins.map((plugin$1) => {
73
+ return Array.isArray(plugin$1) && plugin$1.length >= 2 ? [plugin$1[0], defu(plugin$1.length > 1 && plugin$1[1] ? plugin$1[1] : {}, { options })] : plugin$1;
74
+ }).filter(Boolean),
75
+ presets: presets.map((preset) => {
76
+ return Array.isArray(preset) && preset.length >= 2 ? [preset[0], defu(preset.length > 1 && preset[1] ? preset[1] : {}, { options })] : preset;
77
+ }).filter(Boolean)
78
+ });
79
+ if (!result?.code) throw new Error(`Powerlines - Babel plugin failed to compile ${id}`);
80
+ return {
81
+ code: result.code,
82
+ id
83
+ };
84
+ }
85
+ };
86
+ };
87
+ var src_default = plugin;
88
+
89
+ //#endregion
90
+ export { addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, src_default as default, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, plugin, resolveBabelPlugin, resolvePluginFunction };
@@ -1 +1,41 @@
1
- const e=require(`../../../_virtual/rolldown_runtime.cjs`);let t=require(`@storm-software/config-tools/types`),n=require(`chalk`);n=e.__toESM(n),require(`@storm-software/config-tools/logger`),require(`@storm-software/config-tools/utilities/colors`),require(`@stryke/helpers/noop`),require(`@stryke/string-format/kebab-case`);let r=require(`@stryke/string-format/title-case`);const i=[`#00A0DD`,`#6FCE4E`,`#FBBF24`,`#F43F5E`,`#3B82F6`,`#A855F7`,`#469592`,`#288EDF`,`#D8B4FE`,`#10B981`,`#EF4444`,`#F0EC56`,`#F472B6`,`#22D3EE`,`#EAB308`,`#84CC16`,`#F87171`,`#0EA5E9`,`#D946EF`,`#FACC15`,`#34D399`,`#8B5CF6`],a=(e,t)=>(a,...o)=>e(a,` ${n.default.inverse.hex(i[t.split(``).map(e=>e.charCodeAt(0)).reduce((e,t)=>e+t,0)%i.length]||i[0])(` ${(0,r.titleCase)(t)} `)} ${o.join(` `)} `);exports.extendLog=a;
1
+ const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
2
+ let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
3
+ let chalk = require("chalk");
4
+ chalk = require_rolldown_runtime.__toESM(chalk);
5
+ require("@storm-software/config-tools/logger");
6
+ require("@storm-software/config-tools/utilities/colors");
7
+ require("@stryke/helpers/noop");
8
+ require("@stryke/string-format/kebab-case");
9
+ let __stryke_string_format_title_case = require("@stryke/string-format/title-case");
10
+
11
+ //#region ../powerlines/src/lib/logger.ts
12
+ const BADGE_COLORS = [
13
+ "#00A0DD",
14
+ "#6FCE4E",
15
+ "#FBBF24",
16
+ "#F43F5E",
17
+ "#3B82F6",
18
+ "#A855F7",
19
+ "#469592",
20
+ "#288EDF",
21
+ "#D8B4FE",
22
+ "#10B981",
23
+ "#EF4444",
24
+ "#F0EC56",
25
+ "#F472B6",
26
+ "#22D3EE",
27
+ "#EAB308",
28
+ "#84CC16",
29
+ "#F87171",
30
+ "#0EA5E9",
31
+ "#D946EF",
32
+ "#FACC15",
33
+ "#34D399",
34
+ "#8B5CF6"
35
+ ];
36
+ const extendLog = (logFn, name) => {
37
+ return (type, ...args) => logFn(type, ` ${chalk.default.inverse.hex(BADGE_COLORS[name.split("").map((char) => char.charCodeAt(0)).reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length] || BADGE_COLORS[0])(` ${(0, __stryke_string_format_title_case.titleCase)(name)} `)} ${args.join(" ")} `);
38
+ };
39
+
40
+ //#endregion
41
+ exports.extendLog = extendLog;
@@ -1 +1,39 @@
1
- import{LogLevelLabel as e}from"@storm-software/config-tools/types";import t from"chalk";import"@storm-software/config-tools/logger";import"@storm-software/config-tools/utilities/colors";import"@stryke/helpers/noop";import"@stryke/string-format/kebab-case";import{titleCase as n}from"@stryke/string-format/title-case";const r=[`#00A0DD`,`#6FCE4E`,`#FBBF24`,`#F43F5E`,`#3B82F6`,`#A855F7`,`#469592`,`#288EDF`,`#D8B4FE`,`#10B981`,`#EF4444`,`#F0EC56`,`#F472B6`,`#22D3EE`,`#EAB308`,`#84CC16`,`#F87171`,`#0EA5E9`,`#D946EF`,`#FACC15`,`#34D399`,`#8B5CF6`],i=(e,i)=>(a,...o)=>e(a,` ${t.inverse.hex(r[i.split(``).map(e=>e.charCodeAt(0)).reduce((e,t)=>e+t,0)%r.length]||r[0])(` ${n(i)} `)} ${o.join(` `)} `);export{i as extendLog};
1
+ import { LogLevelLabel } from "@storm-software/config-tools/types";
2
+ import chalk from "chalk";
3
+ import "@storm-software/config-tools/logger";
4
+ import "@storm-software/config-tools/utilities/colors";
5
+ import "@stryke/helpers/noop";
6
+ import "@stryke/string-format/kebab-case";
7
+ import { titleCase } from "@stryke/string-format/title-case";
8
+
9
+ //#region ../powerlines/src/lib/logger.ts
10
+ const BADGE_COLORS = [
11
+ "#00A0DD",
12
+ "#6FCE4E",
13
+ "#FBBF24",
14
+ "#F43F5E",
15
+ "#3B82F6",
16
+ "#A855F7",
17
+ "#469592",
18
+ "#288EDF",
19
+ "#D8B4FE",
20
+ "#10B981",
21
+ "#EF4444",
22
+ "#F0EC56",
23
+ "#F472B6",
24
+ "#22D3EE",
25
+ "#EAB308",
26
+ "#84CC16",
27
+ "#F87171",
28
+ "#0EA5E9",
29
+ "#D946EF",
30
+ "#FACC15",
31
+ "#34D399",
32
+ "#8B5CF6"
33
+ ];
34
+ const extendLog = (logFn, name) => {
35
+ return (type, ...args) => logFn(type, ` ${chalk.inverse.hex(BADGE_COLORS[name.split("").map((char) => char.charCodeAt(0)).reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length] || BADGE_COLORS[0])(` ${titleCase(name)} `)} ${args.join(" ")} `);
36
+ };
37
+
38
+ //#endregion
39
+ export { extendLog };
@@ -78,10 +78,18 @@ interface ParseOptions extends ParserOptions {
78
78
  */
79
79
  allowReturnOutsideFunction?: boolean;
80
80
  }
81
+ interface EmitOptions extends WriteOptions {
82
+ /**
83
+ * If true, will emit the file using {@link UnpluginBuildContext.emitFile | the bundler's emit function}.
84
+ */
85
+ emitWithBundler?: boolean;
86
+ needsCodeReference?: Parameters<UnpluginBuildContext["emitFile"]>[0]["needsCodeReference"];
87
+ originalFileName?: Parameters<UnpluginBuildContext["emitFile"]>[0]["originalFileName"];
88
+ }
81
89
  /**
82
90
  * Options for emitting entry virtual files
83
91
  */
84
- type EmitEntryOptions = WriteOptions & Omit<ResolvedEntryTypeDefinition, "file">;
92
+ type EmitEntryOptions = EmitOptions & Omit<ResolvedEntryTypeDefinition, "file">;
85
93
  /**
86
94
  * The unresolved Powerlines context.
87
95
  *
@@ -292,6 +300,22 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
292
300
  * The Powerlines builtin virtual files
293
301
  */
294
302
  getBuiltins: () => Promise<VirtualFile[]>;
303
+ /**
304
+ * Resolves a file and writes it to the VFS if it does not already exist
305
+ *
306
+ * @param code - The source code of the file
307
+ * @param path - The path to write the file to
308
+ * @param options - Additional options for writing the file
309
+ */
310
+ emit: (code: string, path: string, options?: EmitOptions) => Promise<void>;
311
+ /**
312
+ * Synchronously resolves a file and writes it to the VFS if it does not already exist
313
+ *
314
+ * @param code - The source code of the file
315
+ * @param path - The path to write the file to
316
+ * @param options - Additional options for writing the file
317
+ */
318
+ emitSync: (code: string, path: string, options?: EmitOptions) => void;
295
319
  /**
296
320
  * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
297
321
  *
@@ -300,7 +324,16 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
300
324
  * @param path - An optional path to write the builtin file to
301
325
  * @param options - Additional options for writing the builtin file
302
326
  */
303
- emitBuiltin: (code: string, id: string, path?: string, options?: WriteOptions) => Promise<void>;
327
+ emitBuiltin: (code: string, id: string, path?: string, options?: EmitOptions) => Promise<void>;
328
+ /**
329
+ * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
330
+ *
331
+ * @param code - The source code of the builtin file
332
+ * @param id - The unique identifier of the builtin file
333
+ * @param path - An optional path to write the builtin file to
334
+ * @param options - Additional options for writing the builtin file
335
+ */
336
+ emitBuiltinSync: (code: string, id: string, path?: string, options?: EmitOptions) => void;
304
337
  /**
305
338
  * Resolves a entry virtual file and writes it to the VFS if it does not already exist
306
339
  *
@@ -309,6 +342,14 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
309
342
  * @param options - Additional options for writing the entry file
310
343
  */
311
344
  emitEntry: (code: string, path: string, options?: EmitEntryOptions) => Promise<void>;
345
+ /**
346
+ * Synchronously resolves a entry virtual file and writes it to the VFS if it does not already exist
347
+ *
348
+ * @param code - The source code of the entry file
349
+ * @param path - An optional path to write the entry file to
350
+ * @param options - Additional options for writing the entry file
351
+ */
352
+ emitEntrySync: (code: string, path: string, options?: EmitEntryOptions) => void;
312
353
  /**
313
354
  * A function to update the context fields using a new user configuration options
314
355
  */
@@ -80,10 +80,18 @@ interface ParseOptions extends ParserOptions {
80
80
  */
81
81
  allowReturnOutsideFunction?: boolean;
82
82
  }
83
+ interface EmitOptions extends WriteOptions {
84
+ /**
85
+ * If true, will emit the file using {@link UnpluginBuildContext.emitFile | the bundler's emit function}.
86
+ */
87
+ emitWithBundler?: boolean;
88
+ needsCodeReference?: Parameters<UnpluginBuildContext["emitFile"]>[0]["needsCodeReference"];
89
+ originalFileName?: Parameters<UnpluginBuildContext["emitFile"]>[0]["originalFileName"];
90
+ }
83
91
  /**
84
92
  * Options for emitting entry virtual files
85
93
  */
86
- type EmitEntryOptions = WriteOptions & Omit<ResolvedEntryTypeDefinition, "file">;
94
+ type EmitEntryOptions = EmitOptions & Omit<ResolvedEntryTypeDefinition, "file">;
87
95
  /**
88
96
  * The unresolved Powerlines context.
89
97
  *
@@ -294,6 +302,22 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
294
302
  * The Powerlines builtin virtual files
295
303
  */
296
304
  getBuiltins: () => Promise<VirtualFile[]>;
305
+ /**
306
+ * Resolves a file and writes it to the VFS if it does not already exist
307
+ *
308
+ * @param code - The source code of the file
309
+ * @param path - The path to write the file to
310
+ * @param options - Additional options for writing the file
311
+ */
312
+ emit: (code: string, path: string, options?: EmitOptions) => Promise<void>;
313
+ /**
314
+ * Synchronously resolves a file and writes it to the VFS if it does not already exist
315
+ *
316
+ * @param code - The source code of the file
317
+ * @param path - The path to write the file to
318
+ * @param options - Additional options for writing the file
319
+ */
320
+ emitSync: (code: string, path: string, options?: EmitOptions) => void;
297
321
  /**
298
322
  * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
299
323
  *
@@ -302,7 +326,16 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
302
326
  * @param path - An optional path to write the builtin file to
303
327
  * @param options - Additional options for writing the builtin file
304
328
  */
305
- emitBuiltin: (code: string, id: string, path?: string, options?: WriteOptions) => Promise<void>;
329
+ emitBuiltin: (code: string, id: string, path?: string, options?: EmitOptions) => Promise<void>;
330
+ /**
331
+ * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
332
+ *
333
+ * @param code - The source code of the builtin file
334
+ * @param id - The unique identifier of the builtin file
335
+ * @param path - An optional path to write the builtin file to
336
+ * @param options - Additional options for writing the builtin file
337
+ */
338
+ emitBuiltinSync: (code: string, id: string, path?: string, options?: EmitOptions) => void;
306
339
  /**
307
340
  * Resolves a entry virtual file and writes it to the VFS if it does not already exist
308
341
  *
@@ -311,6 +344,14 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
311
344
  * @param options - Additional options for writing the entry file
312
345
  */
313
346
  emitEntry: (code: string, path: string, options?: EmitEntryOptions) => Promise<void>;
347
+ /**
348
+ * Synchronously resolves a entry virtual file and writes it to the VFS if it does not already exist
349
+ *
350
+ * @param code - The source code of the entry file
351
+ * @param path - An optional path to write the entry file to
352
+ * @param options - Additional options for writing the entry file
353
+ */
354
+ emitEntrySync: (code: string, path: string, options?: EmitEntryOptions) => void;
314
355
  /**
315
356
  * A function to update the context fields using a new user configuration options
316
357
  */
@@ -361,4 +402,4 @@ interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedCon
361
402
  }
362
403
  type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = UnpluginBuildContext & PluginContext<TResolvedConfig>;
363
404
  //#endregion
364
- export { BuildPluginContext, Context, EmitEntryOptions, FetchOptions, InitContextOptions, MetaInfo, ParseOptions, PluginContext, Resolver, TransformResult$1 as TransformResult, UnresolvedContext };
405
+ export { BuildPluginContext, Context, EmitEntryOptions, EmitOptions, FetchOptions, InitContextOptions, MetaInfo, ParseOptions, PluginContext, Resolver, TransformResult$1 as TransformResult, UnresolvedContext };
@@ -13,6 +13,13 @@ interface StorageAdapter {
13
13
  * A name identifying the storage adapter type.
14
14
  */
15
15
  name: string;
16
+ /**
17
+ * The storage preset for the adapter.
18
+ *
19
+ * @remarks
20
+ * This can be used as an alternate way to identify the type of storage being used.
21
+ */
22
+ preset?: StoragePreset | null;
16
23
  /**
17
24
  * Checks if a key exists in the storage.
18
25
  *
@@ -207,6 +214,13 @@ interface WriteOptions {
207
214
  * @defaultValue false
208
215
  */
209
216
  skipFormat?: boolean;
217
+ /**
218
+ * The storage preset or adapter name for the output file.
219
+ *
220
+ * @remarks
221
+ * If not specified, the output mode will be determined by the provided `output.mode` value.
222
+ */
223
+ storage?: StoragePreset | string;
210
224
  /**
211
225
  * Additional metadata for the file.
212
226
  */
@@ -13,6 +13,13 @@ interface StorageAdapter {
13
13
  * A name identifying the storage adapter type.
14
14
  */
15
15
  name: string;
16
+ /**
17
+ * The storage preset for the adapter.
18
+ *
19
+ * @remarks
20
+ * This can be used as an alternate way to identify the type of storage being used.
21
+ */
22
+ preset?: StoragePreset | null;
16
23
  /**
17
24
  * Checks if a key exists in the storage.
18
25
  *
@@ -207,6 +214,13 @@ interface WriteOptions {
207
214
  * @defaultValue false
208
215
  */
209
216
  skipFormat?: boolean;
217
+ /**
218
+ * The storage preset or adapter name for the output file.
219
+ *
220
+ * @remarks
221
+ * If not specified, the output mode will be determined by the provided `output.mode` value.
222
+ */
223
+ storage?: StoragePreset | string;
210
224
  /**
211
225
  * Additional metadata for the file.
212
226
  */
@@ -5,7 +5,7 @@ import { BabelResolvedConfig, EnvironmentResolvedConfig, OutputResolvedConfig, R
5
5
  import { BasePluginHookFunctions, BuildPlugin, ConfigResult, Plugin, PluginBuildPlugins, PluginHook, PluginHookObject, PluginHooks, TypesResult } from "./plugin.mjs";
6
6
  import "./hooks.mjs";
7
7
  import { DeepkitOptions, ParsedTypeScriptConfig, RawReflectionMode, ReflectionLevel, ReflectionMode, TSCompilerOptions, TSConfig } from "./tsconfig.mjs";
8
- import { BuildPluginContext, Context, EmitEntryOptions, FetchOptions, InitContextOptions, MetaInfo, ParseOptions, PluginContext, Resolver, TransformResult, UnresolvedContext } from "./context.mjs";
8
+ import { BuildPluginContext, Context, EmitEntryOptions, EmitOptions, FetchOptions, InitContextOptions, MetaInfo, ParseOptions, PluginContext, Resolver, TransformResult, UnresolvedContext } from "./context.mjs";
9
9
  import { BabelUserConfig, BaseConfig, CommonUserConfig, DeployConfig, EnvironmentConfig, InlineConfig, LogFn, OutputConfig, PluginConfig, PluginConfigObject, PluginConfigTuple, PluginFactory, PowerlinesCommand, ProjectType, UserConfig, WorkspaceConfig } from "./config.mjs";
10
10
  import { BabelPluginPass, BabelTransformPlugin, BabelTransformPluginBuilder, BabelTransformPluginBuilderParams, BabelTransformPluginFilter, BabelTransformPluginOptions, DeclareBabelTransformPluginReturn, ImportSpecifier, ResolvedBabelTransformPluginOptions } from "./babel.mjs";
11
11
  import "./api.mjs";
@@ -1 +1 @@
1
- export{};
1
+ export { };
@@ -1 +1 @@
1
- export{};
1
+ export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-babel",
3
- "version": "0.12.125",
3
+ "version": "0.12.127",
4
4
  "type": "module",
5
5
  "description": "A package containing a Powerlines plugin to assist in developing other Powerlines plugins.",
6
6
  "repository": {
@@ -155,22 +155,22 @@
155
155
  "@babel/parser": "^7.28.5",
156
156
  "@babel/types": "^7.28.5",
157
157
  "@storm-software/config-tools": "^1.188.74",
158
- "@stryke/fs": "^0.33.26",
159
- "@stryke/path": "^0.24.0",
160
- "@stryke/type-checks": "^0.5.14",
161
- "@stryke/types": "^0.10.28",
158
+ "@stryke/fs": "^0.33.27",
159
+ "@stryke/path": "^0.24.1",
160
+ "@stryke/type-checks": "^0.5.15",
161
+ "@stryke/types": "^0.10.29",
162
162
  "chalk": "5.6.2",
163
163
  "defu": "^6.1.4",
164
164
  "jiti": "^2.6.1",
165
- "powerlines": "^0.36.21",
165
+ "powerlines": "^0.36.23",
166
166
  "unplugin": "3.0.0-beta.3"
167
167
  },
168
168
  "devDependencies": {
169
169
  "@babel/plugin-syntax-typescript": "^7.27.1",
170
- "@powerlines/nx": "^0.11.47",
171
- "@powerlines/plugin-plugin": "^0.12.68",
170
+ "@powerlines/nx": "^0.11.49",
171
+ "@powerlines/plugin-plugin": "^0.12.70",
172
172
  "@types/node": "^24.10.4"
173
173
  },
174
174
  "publishConfig": { "access": "public" },
175
- "gitHead": "b16324cf857ea5743fd7ad06e18607b1ba32abe0"
175
+ "gitHead": "be47e546b48b9a82e460b5c5d4f02fb66e821f18"
176
176
  }