@powerlines/plugin-babel 0.1.0
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/LICENSE +201 -0
- package/README.md +294 -0
- package/dist/chunk-SHUYVCID.js +4 -0
- package/dist/chunk-USNT2KNT.cjs +6 -0
- package/dist/helpers/ast-utils.cjs +37 -0
- package/dist/helpers/ast-utils.d.cts +17 -0
- package/dist/helpers/ast-utils.d.ts +17 -0
- package/dist/helpers/ast-utils.js +30 -0
- package/dist/helpers/create-plugin.cjs +38 -0
- package/dist/helpers/create-plugin.d.cts +13 -0
- package/dist/helpers/create-plugin.d.ts +13 -0
- package/dist/helpers/create-plugin.js +32 -0
- package/dist/helpers/filters.cjs +50 -0
- package/dist/helpers/filters.d.cts +41 -0
- package/dist/helpers/filters.d.ts +41 -0
- package/dist/helpers/filters.js +45 -0
- package/dist/helpers/index.cjs +40 -0
- package/dist/helpers/index.d.cts +12 -0
- package/dist/helpers/index.d.ts +12 -0
- package/dist/helpers/index.js +5 -0
- package/dist/helpers/module-helpers.cjs +123 -0
- package/dist/helpers/module-helpers.d.cts +47 -0
- package/dist/helpers/module-helpers.d.ts +47 -0
- package/dist/helpers/module-helpers.js +95 -0
- package/dist/helpers/options.cjs +46 -0
- package/dist/helpers/options.d.cts +17 -0
- package/dist/helpers/options.d.ts +17 -0
- package/dist/helpers/options.js +39 -0
- package/dist/index.cjs +120 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +99 -0
- package/dist/types/index.cjs +12 -0
- package/dist/types/index.d.cts +4 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +1 -0
- package/dist/types/plugin.cjs +2 -0
- package/dist/types/plugin.d.cts +14 -0
- package/dist/types/plugin.d.ts +14 -0
- package/dist/types/plugin.js +1 -0
- package/package.json +149 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BabelTransformPluginBuilder, DeclareBabelTransformPluginReturn } from 'powerlines/types/babel';
|
|
2
|
+
import { Context } from 'powerlines/types/context';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create a Babel plugin using the provided builder function.
|
|
6
|
+
*
|
|
7
|
+
* @param name - The name of the plugin.
|
|
8
|
+
* @param builder - The builder function that defines the plugin behavior.
|
|
9
|
+
* @returns A Babel plugin declaration.
|
|
10
|
+
*/
|
|
11
|
+
declare function createBabelPlugin<TContext extends Context = Context, TOptions extends Record<string, any> = Record<string, any>>(name: string, builder: BabelTransformPluginBuilder<TContext, TOptions>): DeclareBabelTransformPluginReturn<TContext, TOptions>;
|
|
12
|
+
|
|
13
|
+
export { createBabelPlugin };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { __name } from '../chunk-SHUYVCID.js';
|
|
2
|
+
import { declare } from '@babel/helper-plugin-utils';
|
|
3
|
+
import { LogLevelLabel } from '@storm-software/config-tools/types';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { extendLog } from 'powerlines/lib/logger';
|
|
6
|
+
|
|
7
|
+
function createBabelPlugin(name, builder) {
|
|
8
|
+
const plugin = /* @__PURE__ */ __name((context) => {
|
|
9
|
+
return declare((api, options, dirname) => {
|
|
10
|
+
api.cache.using(() => context.meta.checksum);
|
|
11
|
+
api.assertVersion("^7.0.0-0");
|
|
12
|
+
const log = extendLog(context.log, name);
|
|
13
|
+
log(LogLevelLabel.TRACE, `Initializing the ${chalk.bold.cyanBright(name)} Babel plugin`);
|
|
14
|
+
const result = builder({
|
|
15
|
+
log,
|
|
16
|
+
name,
|
|
17
|
+
api,
|
|
18
|
+
options,
|
|
19
|
+
context,
|
|
20
|
+
dirname
|
|
21
|
+
});
|
|
22
|
+
result.name = name;
|
|
23
|
+
log(LogLevelLabel.TRACE, `Completed initialization of the ${chalk.bold.cyanBright(name)} Babel plugin`);
|
|
24
|
+
return result;
|
|
25
|
+
});
|
|
26
|
+
}, "plugin");
|
|
27
|
+
plugin.$$name = name;
|
|
28
|
+
return plugin;
|
|
29
|
+
}
|
|
30
|
+
__name(createBabelPlugin, "createBabelPlugin");
|
|
31
|
+
|
|
32
|
+
export { createBabelPlugin };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkUSNT2KNT_cjs = require('../chunk-USNT2KNT.cjs');
|
|
4
|
+
var isFunction = require('@stryke/type-checks/is-function');
|
|
5
|
+
var isObject = require('@stryke/type-checks/is-object');
|
|
6
|
+
var isSetString = require('@stryke/type-checks/is-set-string');
|
|
7
|
+
|
|
8
|
+
function getPluginName(plugin) {
|
|
9
|
+
return isSetString.isSetString(plugin) ? plugin : Array.isArray(plugin) && plugin.length > 0 ? getPluginName(plugin[0]) : plugin.$$name || plugin.name ? plugin.$$name || plugin.name : void 0;
|
|
10
|
+
}
|
|
11
|
+
chunkUSNT2KNT_cjs.__name(getPluginName, "getPluginName");
|
|
12
|
+
function isDuplicatePlugin(plugins, plugin) {
|
|
13
|
+
return !!(getPluginName(plugin) && plugins.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(plugin)));
|
|
14
|
+
}
|
|
15
|
+
chunkUSNT2KNT_cjs.__name(isDuplicatePlugin, "isDuplicatePlugin");
|
|
16
|
+
function filterPluginByRuntimeId(context, runtimeId) {
|
|
17
|
+
return (code, id) => !context.fs.isMatchingBuiltinId(runtimeId, id);
|
|
18
|
+
}
|
|
19
|
+
chunkUSNT2KNT_cjs.__name(filterPluginByRuntimeId, "filterPluginByRuntimeId");
|
|
20
|
+
function addPluginFilter(context, pluginOrPlugins, filter, name) {
|
|
21
|
+
if (!Array.isArray(pluginOrPlugins) || !pluginOrPlugins.some((plugin) => Array.isArray(plugin)) && pluginOrPlugins.length < 4 && pluginOrPlugins.length > 0 && (isSetString.isSetString(pluginOrPlugins[0]) || isFunction.isFunction(pluginOrPlugins[0]) || pluginOrPlugins.length > 1 && isObject.isObject(pluginOrPlugins[1]) || pluginOrPlugins.length > 2 && isObject.isObject(pluginOrPlugins[2]))) {
|
|
22
|
+
return Array.isArray(pluginOrPlugins) ? [
|
|
23
|
+
pluginOrPlugins[0],
|
|
24
|
+
pluginOrPlugins.length > 1 ? pluginOrPlugins[1] : {},
|
|
25
|
+
{
|
|
26
|
+
filter: /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((code, id) => filter(code, id) && (pluginOrPlugins.length < 2 || !isFunction.isFunction(pluginOrPlugins[2]) || pluginOrPlugins[2]?.(code, id)), "filter")
|
|
27
|
+
}
|
|
28
|
+
] : [
|
|
29
|
+
pluginOrPlugins,
|
|
30
|
+
{},
|
|
31
|
+
{
|
|
32
|
+
filter
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
}
|
|
36
|
+
if (!name) {
|
|
37
|
+
throw new Error("No name was provided to `addPluginFilter`, could not find babel plugin without it.");
|
|
38
|
+
}
|
|
39
|
+
const foundIndex = pluginOrPlugins.findIndex((plugin) => getPluginName(plugin)?.toLowerCase() === name.toLowerCase());
|
|
40
|
+
if (foundIndex > -1) {
|
|
41
|
+
pluginOrPlugins[foundIndex] = addPluginFilter(context, pluginOrPlugins[foundIndex], filter, name);
|
|
42
|
+
}
|
|
43
|
+
return pluginOrPlugins;
|
|
44
|
+
}
|
|
45
|
+
chunkUSNT2KNT_cjs.__name(addPluginFilter, "addPluginFilter");
|
|
46
|
+
|
|
47
|
+
exports.addPluginFilter = addPluginFilter;
|
|
48
|
+
exports.filterPluginByRuntimeId = filterPluginByRuntimeId;
|
|
49
|
+
exports.getPluginName = getPluginName;
|
|
50
|
+
exports.isDuplicatePlugin = isDuplicatePlugin;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Context } from 'powerlines/types';
|
|
2
|
+
import { BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions, BabelTransformPluginFilter, BabelTransformPlugin } from 'powerlines/types/babel';
|
|
3
|
+
|
|
4
|
+
declare function getPluginName(plugin: BabelTransformPluginOptions): string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Check if a Babel plugin is a duplicate of another plugin in the list.
|
|
7
|
+
*
|
|
8
|
+
* @param plugins - The list of existing Babel plugins.
|
|
9
|
+
* @param plugin - The Babel plugin to check for duplicates.
|
|
10
|
+
* @returns True if the plugin is a duplicate, false otherwise.
|
|
11
|
+
*/
|
|
12
|
+
declare function isDuplicatePlugin(plugins: (ResolvedBabelTransformPluginOptions | undefined)[], plugin: BabelTransformPluginOptions): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Filters a Babel plugin by its runtime ID.
|
|
15
|
+
*
|
|
16
|
+
* @param context - The context in which the filter is applied.
|
|
17
|
+
* @param runtimeId - The runtime ID to filter by.
|
|
18
|
+
* @returns A filter function that checks if a plugin's ID matches the runtime ID.
|
|
19
|
+
*/
|
|
20
|
+
declare function filterPluginByRuntimeId<TContext extends Context = Context>(context: TContext, runtimeId: string): BabelTransformPluginFilter;
|
|
21
|
+
/**
|
|
22
|
+
* Adds a filter to a Babel plugin or a list of Babel plugins.
|
|
23
|
+
*
|
|
24
|
+
* @param context - The context in which the plugin is being added.
|
|
25
|
+
* @param plugins - The Babel plugins to add the filter to.
|
|
26
|
+
* @param filter - The filter function to apply to the plugins.
|
|
27
|
+
* @param name - The name of the plugin to add the filter to.
|
|
28
|
+
* @returns The updated list of Babel plugins with the filter applied.
|
|
29
|
+
*/
|
|
30
|
+
declare function addPluginFilter(context: Context, plugins: BabelTransformPluginOptions[], filter: BabelTransformPluginFilter | null | undefined, name: string): BabelTransformPluginOptions[];
|
|
31
|
+
/**
|
|
32
|
+
* Adds a filter to a Babel plugin or a list of Babel plugins.
|
|
33
|
+
*
|
|
34
|
+
* @param context - The context in which the plugin is being added.
|
|
35
|
+
* @param plugin - The Babel plugin to add the filter to.
|
|
36
|
+
* @param filter - The filter function to apply to the plugin.
|
|
37
|
+
* @returns The updated Babel plugin with the filter applied.
|
|
38
|
+
*/
|
|
39
|
+
declare function addPluginFilter(context: Context, plugin: BabelTransformPlugin | BabelTransformPluginOptions, filter: NonNullable<BabelTransformPluginFilter>): BabelTransformPluginOptions;
|
|
40
|
+
|
|
41
|
+
export { addPluginFilter, filterPluginByRuntimeId, getPluginName, isDuplicatePlugin };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Context } from 'powerlines/types';
|
|
2
|
+
import { BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions, BabelTransformPluginFilter, BabelTransformPlugin } from 'powerlines/types/babel';
|
|
3
|
+
|
|
4
|
+
declare function getPluginName(plugin: BabelTransformPluginOptions): string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Check if a Babel plugin is a duplicate of another plugin in the list.
|
|
7
|
+
*
|
|
8
|
+
* @param plugins - The list of existing Babel plugins.
|
|
9
|
+
* @param plugin - The Babel plugin to check for duplicates.
|
|
10
|
+
* @returns True if the plugin is a duplicate, false otherwise.
|
|
11
|
+
*/
|
|
12
|
+
declare function isDuplicatePlugin(plugins: (ResolvedBabelTransformPluginOptions | undefined)[], plugin: BabelTransformPluginOptions): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Filters a Babel plugin by its runtime ID.
|
|
15
|
+
*
|
|
16
|
+
* @param context - The context in which the filter is applied.
|
|
17
|
+
* @param runtimeId - The runtime ID to filter by.
|
|
18
|
+
* @returns A filter function that checks if a plugin's ID matches the runtime ID.
|
|
19
|
+
*/
|
|
20
|
+
declare function filterPluginByRuntimeId<TContext extends Context = Context>(context: TContext, runtimeId: string): BabelTransformPluginFilter;
|
|
21
|
+
/**
|
|
22
|
+
* Adds a filter to a Babel plugin or a list of Babel plugins.
|
|
23
|
+
*
|
|
24
|
+
* @param context - The context in which the plugin is being added.
|
|
25
|
+
* @param plugins - The Babel plugins to add the filter to.
|
|
26
|
+
* @param filter - The filter function to apply to the plugins.
|
|
27
|
+
* @param name - The name of the plugin to add the filter to.
|
|
28
|
+
* @returns The updated list of Babel plugins with the filter applied.
|
|
29
|
+
*/
|
|
30
|
+
declare function addPluginFilter(context: Context, plugins: BabelTransformPluginOptions[], filter: BabelTransformPluginFilter | null | undefined, name: string): BabelTransformPluginOptions[];
|
|
31
|
+
/**
|
|
32
|
+
* Adds a filter to a Babel plugin or a list of Babel plugins.
|
|
33
|
+
*
|
|
34
|
+
* @param context - The context in which the plugin is being added.
|
|
35
|
+
* @param plugin - The Babel plugin to add the filter to.
|
|
36
|
+
* @param filter - The filter function to apply to the plugin.
|
|
37
|
+
* @returns The updated Babel plugin with the filter applied.
|
|
38
|
+
*/
|
|
39
|
+
declare function addPluginFilter(context: Context, plugin: BabelTransformPlugin | BabelTransformPluginOptions, filter: NonNullable<BabelTransformPluginFilter>): BabelTransformPluginOptions;
|
|
40
|
+
|
|
41
|
+
export { addPluginFilter, filterPluginByRuntimeId, getPluginName, isDuplicatePlugin };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { __name } from '../chunk-SHUYVCID.js';
|
|
2
|
+
import { isFunction } from '@stryke/type-checks/is-function';
|
|
3
|
+
import { isObject } from '@stryke/type-checks/is-object';
|
|
4
|
+
import { isSetString } from '@stryke/type-checks/is-set-string';
|
|
5
|
+
|
|
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
|
+
__name(getPluginName, "getPluginName");
|
|
10
|
+
function isDuplicatePlugin(plugins, plugin) {
|
|
11
|
+
return !!(getPluginName(plugin) && plugins.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(plugin)));
|
|
12
|
+
}
|
|
13
|
+
__name(isDuplicatePlugin, "isDuplicatePlugin");
|
|
14
|
+
function filterPluginByRuntimeId(context, runtimeId) {
|
|
15
|
+
return (code, id) => !context.fs.isMatchingBuiltinId(runtimeId, id);
|
|
16
|
+
}
|
|
17
|
+
__name(filterPluginByRuntimeId, "filterPluginByRuntimeId");
|
|
18
|
+
function addPluginFilter(context, pluginOrPlugins, filter, name) {
|
|
19
|
+
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]))) {
|
|
20
|
+
return Array.isArray(pluginOrPlugins) ? [
|
|
21
|
+
pluginOrPlugins[0],
|
|
22
|
+
pluginOrPlugins.length > 1 ? pluginOrPlugins[1] : {},
|
|
23
|
+
{
|
|
24
|
+
filter: /* @__PURE__ */ __name((code, id) => filter(code, id) && (pluginOrPlugins.length < 2 || !isFunction(pluginOrPlugins[2]) || pluginOrPlugins[2]?.(code, id)), "filter")
|
|
25
|
+
}
|
|
26
|
+
] : [
|
|
27
|
+
pluginOrPlugins,
|
|
28
|
+
{},
|
|
29
|
+
{
|
|
30
|
+
filter
|
|
31
|
+
}
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
if (!name) {
|
|
35
|
+
throw new Error("No name was provided to `addPluginFilter`, could not find babel plugin without it.");
|
|
36
|
+
}
|
|
37
|
+
const foundIndex = pluginOrPlugins.findIndex((plugin) => getPluginName(plugin)?.toLowerCase() === name.toLowerCase());
|
|
38
|
+
if (foundIndex > -1) {
|
|
39
|
+
pluginOrPlugins[foundIndex] = addPluginFilter(context, pluginOrPlugins[foundIndex], filter, name);
|
|
40
|
+
}
|
|
41
|
+
return pluginOrPlugins;
|
|
42
|
+
}
|
|
43
|
+
__name(addPluginFilter, "addPluginFilter");
|
|
44
|
+
|
|
45
|
+
export { addPluginFilter, filterPluginByRuntimeId, getPluginName, isDuplicatePlugin };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var astUtils = require('./ast-utils');
|
|
4
|
+
var createPlugin = require('./create-plugin');
|
|
5
|
+
var filters = require('./filters');
|
|
6
|
+
var moduleHelpers = require('./module-helpers');
|
|
7
|
+
var options = require('./options');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
Object.keys(astUtils).forEach(function (k) {
|
|
12
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return astUtils[k]; }
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
Object.keys(createPlugin).forEach(function (k) {
|
|
18
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return createPlugin[k]; }
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
Object.keys(filters).forEach(function (k) {
|
|
24
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return filters[k]; }
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
Object.keys(moduleHelpers).forEach(function (k) {
|
|
30
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return moduleHelpers[k]; }
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
Object.keys(options).forEach(function (k) {
|
|
36
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () { return options[k]; }
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { GenerateFromAstOptions, generateFromAst, parseAst } from './ast-utils.cjs';
|
|
2
|
+
export { createBabelPlugin } from './create-plugin.cjs';
|
|
3
|
+
export { addPluginFilter, filterPluginByRuntimeId, getPluginName, isDuplicatePlugin } from './filters.cjs';
|
|
4
|
+
export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from './module-helpers.cjs';
|
|
5
|
+
export { resolveBabelPlugin, resolvePluginFunction } from './options.cjs';
|
|
6
|
+
export { GeneratorResult } from '@babel/generator';
|
|
7
|
+
import '@babel/parser';
|
|
8
|
+
import '@babel/types';
|
|
9
|
+
import 'powerlines/types/babel';
|
|
10
|
+
import 'powerlines/types/context';
|
|
11
|
+
import 'powerlines/types';
|
|
12
|
+
import '@babel/core';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { GenerateFromAstOptions, generateFromAst, parseAst } from './ast-utils.js';
|
|
2
|
+
export { createBabelPlugin } from './create-plugin.js';
|
|
3
|
+
export { addPluginFilter, filterPluginByRuntimeId, getPluginName, isDuplicatePlugin } from './filters.js';
|
|
4
|
+
export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from './module-helpers.js';
|
|
5
|
+
export { resolveBabelPlugin, resolvePluginFunction } from './options.js';
|
|
6
|
+
export { GeneratorResult } from '@babel/generator';
|
|
7
|
+
import '@babel/parser';
|
|
8
|
+
import '@babel/types';
|
|
9
|
+
import 'powerlines/types/babel';
|
|
10
|
+
import 'powerlines/types/context';
|
|
11
|
+
import 'powerlines/types';
|
|
12
|
+
import '@babel/core';
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkUSNT2KNT_cjs = require('../chunk-USNT2KNT.cjs');
|
|
4
|
+
var t = require('@babel/types');
|
|
5
|
+
var isString = require('@stryke/type-checks/is-string');
|
|
6
|
+
var astUtils = require('./ast-utils');
|
|
7
|
+
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule) return e;
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var t__namespace = /*#__PURE__*/_interopNamespace(t);
|
|
27
|
+
|
|
28
|
+
function findExport(ast, key) {
|
|
29
|
+
const type = key === "default" ? "ExportDefaultDeclaration" : "ExportNamedDeclaration";
|
|
30
|
+
for (const node of ast.program.body) {
|
|
31
|
+
if (node.type === type) {
|
|
32
|
+
if (key === "default") {
|
|
33
|
+
return node.declaration;
|
|
34
|
+
}
|
|
35
|
+
if (node.declaration && "declarations" in node.declaration) {
|
|
36
|
+
const declaration = node.declaration.declarations[0];
|
|
37
|
+
if (declaration && "name" in declaration.id && declaration.id.name === key) {
|
|
38
|
+
return declaration.init;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
chunkUSNT2KNT_cjs.__name(findExport, "findExport");
|
|
45
|
+
function listExports(codeOrAst) {
|
|
46
|
+
const ast = isString.isString(codeOrAst) ? astUtils.parseAst(codeOrAst) : codeOrAst;
|
|
47
|
+
return ast.program.body.flatMap((i) => {
|
|
48
|
+
if (i.type === "ExportDefaultDeclaration") {
|
|
49
|
+
return [
|
|
50
|
+
"default"
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
if (i.type === "ExportNamedDeclaration" && i.declaration && "declarations" in i.declaration) {
|
|
54
|
+
return i.declaration.declarations.map((d) => "name" in d.id ? d.id.name : "");
|
|
55
|
+
}
|
|
56
|
+
return [];
|
|
57
|
+
}).filter(Boolean);
|
|
58
|
+
}
|
|
59
|
+
chunkUSNT2KNT_cjs.__name(listExports, "listExports");
|
|
60
|
+
function listImports(ast) {
|
|
61
|
+
return ast.program.body.flatMap((i) => {
|
|
62
|
+
if (i.type === "ImportDeclaration") {
|
|
63
|
+
return i.specifiers.map((s) => {
|
|
64
|
+
if (s.type === "ImportDefaultSpecifier") {
|
|
65
|
+
return "default";
|
|
66
|
+
}
|
|
67
|
+
if (s.type === "ImportSpecifier" && "imported" in s) {
|
|
68
|
+
return s.imported.type === "Identifier" ? s.imported.name : s.imported.value;
|
|
69
|
+
}
|
|
70
|
+
return "";
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return [];
|
|
74
|
+
}).filter(Boolean);
|
|
75
|
+
}
|
|
76
|
+
chunkUSNT2KNT_cjs.__name(listImports, "listImports");
|
|
77
|
+
function isImportCall(calleePath) {
|
|
78
|
+
return t__namespace.isImport(calleePath.node.callee);
|
|
79
|
+
}
|
|
80
|
+
chunkUSNT2KNT_cjs.__name(isImportCall, "isImportCall");
|
|
81
|
+
function getImport(specifier, name, named) {
|
|
82
|
+
return t__namespace.importDeclaration([
|
|
83
|
+
t__namespace.importSpecifier(t__namespace.identifier(name), t__namespace.stringLiteral(named || name))
|
|
84
|
+
], t__namespace.stringLiteral(specifier));
|
|
85
|
+
}
|
|
86
|
+
chunkUSNT2KNT_cjs.__name(getImport, "getImport");
|
|
87
|
+
function addImport(path, specifier) {
|
|
88
|
+
addImportsToProgram(path.scope.getProgramParent().path, specifier);
|
|
89
|
+
}
|
|
90
|
+
chunkUSNT2KNT_cjs.__name(addImport, "addImport");
|
|
91
|
+
function isNonNamespacedImport(importDeclPath) {
|
|
92
|
+
return importDeclPath.get("specifiers").filter(Boolean).every((specifier) => specifier?.isImportSpecifier()) && importDeclPath.node.importKind !== "type" && importDeclPath.node.importKind !== "typeof";
|
|
93
|
+
}
|
|
94
|
+
chunkUSNT2KNT_cjs.__name(isNonNamespacedImport, "isNonNamespacedImport");
|
|
95
|
+
function getExistingImports(program) {
|
|
96
|
+
const existingImports = /* @__PURE__ */ new Map();
|
|
97
|
+
program.traverse({
|
|
98
|
+
ImportDeclaration(path) {
|
|
99
|
+
if (isNonNamespacedImport(path)) {
|
|
100
|
+
existingImports.set(path.node.source.value, path);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return existingImports;
|
|
105
|
+
}
|
|
106
|
+
chunkUSNT2KNT_cjs.__name(getExistingImports, "getExistingImports");
|
|
107
|
+
function addImportsToProgram(path, specifier) {
|
|
108
|
+
const existingImports = getExistingImports(path);
|
|
109
|
+
if (!existingImports.get(specifier.module)) {
|
|
110
|
+
path.unshiftContainer("body", t__namespace.importDeclaration([
|
|
111
|
+
t__namespace.importSpecifier(t__namespace.identifier(specifier.name || specifier.imported), t__namespace.identifier(specifier.imported))
|
|
112
|
+
], t__namespace.stringLiteral(specifier.module)));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
chunkUSNT2KNT_cjs.__name(addImportsToProgram, "addImportsToProgram");
|
|
116
|
+
|
|
117
|
+
exports.addImport = addImport;
|
|
118
|
+
exports.addImportsToProgram = addImportsToProgram;
|
|
119
|
+
exports.findExport = findExport;
|
|
120
|
+
exports.getImport = getImport;
|
|
121
|
+
exports.isImportCall = isImportCall;
|
|
122
|
+
exports.listExports = listExports;
|
|
123
|
+
exports.listImports = listImports;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { NodePath } from '@babel/core';
|
|
2
|
+
import { ParseResult } from '@babel/parser';
|
|
3
|
+
import * as t from '@babel/types';
|
|
4
|
+
import { ImportSpecifier } from 'powerlines/types/babel';
|
|
5
|
+
|
|
6
|
+
/**
|
|
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
|
+
declare function findExport(ast: ParseResult<t.File>, key: string): any;
|
|
14
|
+
/**
|
|
15
|
+
* Lists all exports from the given Babel AST program.
|
|
16
|
+
*
|
|
17
|
+
* @param codeOrAst - The parsed Babel AST result containing the program body.
|
|
18
|
+
* @returns An array of export names, including "default" for default exports.
|
|
19
|
+
*/
|
|
20
|
+
declare function listExports(codeOrAst: ParseResult<t.File> | string): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Lists all imports from the given Babel AST program.
|
|
23
|
+
*
|
|
24
|
+
* @param ast - The parsed Babel AST result containing the program body.
|
|
25
|
+
* @returns An array of import names, including "default" for default imports.
|
|
26
|
+
*/
|
|
27
|
+
declare function listImports(ast: ParseResult<t.File> | t.File): string[];
|
|
28
|
+
declare function isImportCall(calleePath: NodePath<t.CallExpression | t.NewExpression>): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the import declaration for a given name and specifier.
|
|
31
|
+
*
|
|
32
|
+
* @param specifier - The specifier of the import.
|
|
33
|
+
* @param name - The name of the import.
|
|
34
|
+
* @param named - Optional named import.
|
|
35
|
+
* @returns The import declaration.
|
|
36
|
+
*/
|
|
37
|
+
declare function getImport(specifier: string, name: string, named?: string): t.ImportDeclaration;
|
|
38
|
+
/**
|
|
39
|
+
* Adds an import to the program if it doesn't already exist.
|
|
40
|
+
*
|
|
41
|
+
* @param path - The current NodePath in the AST.
|
|
42
|
+
* @param specifier - The import specifier.
|
|
43
|
+
*/
|
|
44
|
+
declare function addImport(path: NodePath<any>, specifier: ImportSpecifier): void;
|
|
45
|
+
declare function addImportsToProgram(path: NodePath<t.Program>, specifier: ImportSpecifier): void;
|
|
46
|
+
|
|
47
|
+
export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { NodePath } from '@babel/core';
|
|
2
|
+
import { ParseResult } from '@babel/parser';
|
|
3
|
+
import * as t from '@babel/types';
|
|
4
|
+
import { ImportSpecifier } from 'powerlines/types/babel';
|
|
5
|
+
|
|
6
|
+
/**
|
|
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
|
+
declare function findExport(ast: ParseResult<t.File>, key: string): any;
|
|
14
|
+
/**
|
|
15
|
+
* Lists all exports from the given Babel AST program.
|
|
16
|
+
*
|
|
17
|
+
* @param codeOrAst - The parsed Babel AST result containing the program body.
|
|
18
|
+
* @returns An array of export names, including "default" for default exports.
|
|
19
|
+
*/
|
|
20
|
+
declare function listExports(codeOrAst: ParseResult<t.File> | string): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Lists all imports from the given Babel AST program.
|
|
23
|
+
*
|
|
24
|
+
* @param ast - The parsed Babel AST result containing the program body.
|
|
25
|
+
* @returns An array of import names, including "default" for default imports.
|
|
26
|
+
*/
|
|
27
|
+
declare function listImports(ast: ParseResult<t.File> | t.File): string[];
|
|
28
|
+
declare function isImportCall(calleePath: NodePath<t.CallExpression | t.NewExpression>): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Gets the import declaration for a given name and specifier.
|
|
31
|
+
*
|
|
32
|
+
* @param specifier - The specifier of the import.
|
|
33
|
+
* @param name - The name of the import.
|
|
34
|
+
* @param named - Optional named import.
|
|
35
|
+
* @returns The import declaration.
|
|
36
|
+
*/
|
|
37
|
+
declare function getImport(specifier: string, name: string, named?: string): t.ImportDeclaration;
|
|
38
|
+
/**
|
|
39
|
+
* Adds an import to the program if it doesn't already exist.
|
|
40
|
+
*
|
|
41
|
+
* @param path - The current NodePath in the AST.
|
|
42
|
+
* @param specifier - The import specifier.
|
|
43
|
+
*/
|
|
44
|
+
declare function addImport(path: NodePath<any>, specifier: ImportSpecifier): void;
|
|
45
|
+
declare function addImportsToProgram(path: NodePath<t.Program>, specifier: ImportSpecifier): void;
|
|
46
|
+
|
|
47
|
+
export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { __name } from '../chunk-SHUYVCID.js';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
import { isString } from '@stryke/type-checks/is-string';
|
|
4
|
+
import { parseAst } from './ast-utils';
|
|
5
|
+
|
|
6
|
+
function findExport(ast, key) {
|
|
7
|
+
const type = key === "default" ? "ExportDefaultDeclaration" : "ExportNamedDeclaration";
|
|
8
|
+
for (const node of ast.program.body) {
|
|
9
|
+
if (node.type === type) {
|
|
10
|
+
if (key === "default") {
|
|
11
|
+
return node.declaration;
|
|
12
|
+
}
|
|
13
|
+
if (node.declaration && "declarations" in node.declaration) {
|
|
14
|
+
const declaration = node.declaration.declarations[0];
|
|
15
|
+
if (declaration && "name" in declaration.id && declaration.id.name === key) {
|
|
16
|
+
return declaration.init;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
__name(findExport, "findExport");
|
|
23
|
+
function listExports(codeOrAst) {
|
|
24
|
+
const ast = isString(codeOrAst) ? parseAst(codeOrAst) : codeOrAst;
|
|
25
|
+
return ast.program.body.flatMap((i) => {
|
|
26
|
+
if (i.type === "ExportDefaultDeclaration") {
|
|
27
|
+
return [
|
|
28
|
+
"default"
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
if (i.type === "ExportNamedDeclaration" && i.declaration && "declarations" in i.declaration) {
|
|
32
|
+
return i.declaration.declarations.map((d) => "name" in d.id ? d.id.name : "");
|
|
33
|
+
}
|
|
34
|
+
return [];
|
|
35
|
+
}).filter(Boolean);
|
|
36
|
+
}
|
|
37
|
+
__name(listExports, "listExports");
|
|
38
|
+
function listImports(ast) {
|
|
39
|
+
return ast.program.body.flatMap((i) => {
|
|
40
|
+
if (i.type === "ImportDeclaration") {
|
|
41
|
+
return i.specifiers.map((s) => {
|
|
42
|
+
if (s.type === "ImportDefaultSpecifier") {
|
|
43
|
+
return "default";
|
|
44
|
+
}
|
|
45
|
+
if (s.type === "ImportSpecifier" && "imported" in s) {
|
|
46
|
+
return s.imported.type === "Identifier" ? s.imported.name : s.imported.value;
|
|
47
|
+
}
|
|
48
|
+
return "";
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return [];
|
|
52
|
+
}).filter(Boolean);
|
|
53
|
+
}
|
|
54
|
+
__name(listImports, "listImports");
|
|
55
|
+
function isImportCall(calleePath) {
|
|
56
|
+
return t.isImport(calleePath.node.callee);
|
|
57
|
+
}
|
|
58
|
+
__name(isImportCall, "isImportCall");
|
|
59
|
+
function getImport(specifier, name, named) {
|
|
60
|
+
return t.importDeclaration([
|
|
61
|
+
t.importSpecifier(t.identifier(name), t.stringLiteral(named || name))
|
|
62
|
+
], t.stringLiteral(specifier));
|
|
63
|
+
}
|
|
64
|
+
__name(getImport, "getImport");
|
|
65
|
+
function addImport(path, specifier) {
|
|
66
|
+
addImportsToProgram(path.scope.getProgramParent().path, specifier);
|
|
67
|
+
}
|
|
68
|
+
__name(addImport, "addImport");
|
|
69
|
+
function isNonNamespacedImport(importDeclPath) {
|
|
70
|
+
return importDeclPath.get("specifiers").filter(Boolean).every((specifier) => specifier?.isImportSpecifier()) && importDeclPath.node.importKind !== "type" && importDeclPath.node.importKind !== "typeof";
|
|
71
|
+
}
|
|
72
|
+
__name(isNonNamespacedImport, "isNonNamespacedImport");
|
|
73
|
+
function getExistingImports(program) {
|
|
74
|
+
const existingImports = /* @__PURE__ */ new Map();
|
|
75
|
+
program.traverse({
|
|
76
|
+
ImportDeclaration(path) {
|
|
77
|
+
if (isNonNamespacedImport(path)) {
|
|
78
|
+
existingImports.set(path.node.source.value, path);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
return existingImports;
|
|
83
|
+
}
|
|
84
|
+
__name(getExistingImports, "getExistingImports");
|
|
85
|
+
function addImportsToProgram(path, specifier) {
|
|
86
|
+
const existingImports = getExistingImports(path);
|
|
87
|
+
if (!existingImports.get(specifier.module)) {
|
|
88
|
+
path.unshiftContainer("body", t.importDeclaration([
|
|
89
|
+
t.importSpecifier(t.identifier(specifier.name || specifier.imported), t.identifier(specifier.imported))
|
|
90
|
+
], t.stringLiteral(specifier.module)));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
__name(addImportsToProgram, "addImportsToProgram");
|
|
94
|
+
|
|
95
|
+
export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkUSNT2KNT_cjs = require('../chunk-USNT2KNT.cjs');
|
|
4
|
+
var types = require('@storm-software/config-tools/types');
|
|
5
|
+
var isFunction = require('@stryke/type-checks/is-function');
|
|
6
|
+
var chalk = require('chalk');
|
|
7
|
+
var filters = require('./filters');
|
|
8
|
+
|
|
9
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
|
|
11
|
+
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
12
|
+
|
|
13
|
+
function resolvePluginFunction(context, plugin) {
|
|
14
|
+
try {
|
|
15
|
+
return Array.isArray(plugin) && plugin.length > 0 && plugin[0] ? isFunction.isFunction(plugin[0]) ? plugin[0](context) : plugin[0] : isFunction.isFunction(plugin) ? plugin(context) : plugin;
|
|
16
|
+
} catch {
|
|
17
|
+
return plugin[0];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
chunkUSNT2KNT_cjs.__name(resolvePluginFunction, "resolvePluginFunction");
|
|
21
|
+
function resolveBabelPlugin(context, code, id, plugin) {
|
|
22
|
+
if (Array.isArray(plugin) && plugin.length > 0 && plugin[0]) {
|
|
23
|
+
if (plugin.length > 2 && plugin[2] && isFunction.isFunction(plugin[2]) && !plugin[2](code, id)) {
|
|
24
|
+
context.log(types.LogLevelLabel.TRACE, `Skipping filtered Babel plugin ${chalk__default.default.bold.cyanBright(filters.getPluginName(plugin) || "unnamed")} for ${id}`);
|
|
25
|
+
return void 0;
|
|
26
|
+
}
|
|
27
|
+
return plugin.length > 2 ? [
|
|
28
|
+
resolvePluginFunction(context, plugin),
|
|
29
|
+
plugin[1],
|
|
30
|
+
plugin[2]
|
|
31
|
+
] : [
|
|
32
|
+
resolvePluginFunction(context, plugin),
|
|
33
|
+
plugin[1],
|
|
34
|
+
null
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
return [
|
|
38
|
+
resolvePluginFunction(context, plugin),
|
|
39
|
+
{},
|
|
40
|
+
null
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
chunkUSNT2KNT_cjs.__name(resolveBabelPlugin, "resolveBabelPlugin");
|
|
44
|
+
|
|
45
|
+
exports.resolveBabelPlugin = resolveBabelPlugin;
|
|
46
|
+
exports.resolvePluginFunction = resolvePluginFunction;
|