@powerlines/plugin-babel 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/package.json +10 -6
  2. package/dist/chunk-SHUYVCID.js +0 -4
  3. package/dist/chunk-USNT2KNT.cjs +0 -6
  4. package/dist/helpers/ast-utils.cjs +0 -37
  5. package/dist/helpers/ast-utils.d.cts +0 -17
  6. package/dist/helpers/ast-utils.d.ts +0 -17
  7. package/dist/helpers/ast-utils.js +0 -30
  8. package/dist/helpers/create-plugin.cjs +0 -38
  9. package/dist/helpers/create-plugin.d.cts +0 -13
  10. package/dist/helpers/create-plugin.d.ts +0 -13
  11. package/dist/helpers/create-plugin.js +0 -32
  12. package/dist/helpers/filters.cjs +0 -50
  13. package/dist/helpers/filters.d.cts +0 -41
  14. package/dist/helpers/filters.d.ts +0 -41
  15. package/dist/helpers/filters.js +0 -45
  16. package/dist/helpers/index.cjs +0 -40
  17. package/dist/helpers/index.d.cts +0 -12
  18. package/dist/helpers/index.d.ts +0 -12
  19. package/dist/helpers/index.js +0 -5
  20. package/dist/helpers/module-helpers.cjs +0 -123
  21. package/dist/helpers/module-helpers.d.cts +0 -47
  22. package/dist/helpers/module-helpers.d.ts +0 -47
  23. package/dist/helpers/module-helpers.js +0 -95
  24. package/dist/helpers/options.cjs +0 -46
  25. package/dist/helpers/options.d.cts +0 -17
  26. package/dist/helpers/options.d.ts +0 -17
  27. package/dist/helpers/options.js +0 -39
  28. package/dist/index.cjs +0 -117
  29. package/dist/index.d.cts +0 -27
  30. package/dist/index.d.ts +0 -27
  31. package/dist/index.js +0 -96
  32. package/dist/types/index.cjs +0 -12
  33. package/dist/types/index.d.cts +0 -4
  34. package/dist/types/index.d.ts +0 -4
  35. package/dist/types/index.js +0 -1
  36. package/dist/types/plugin.cjs +0 -2
  37. package/dist/types/plugin.d.cts +0 -14
  38. package/dist/types/plugin.d.ts +0 -14
  39. package/dist/types/plugin.js +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-babel",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "description": "A package containing a Powerlines plugin to assist in developing other Powerlines plugins.",
6
6
  "repository": {
@@ -133,17 +133,21 @@
133
133
  "@babel/parser": "^7.28.4",
134
134
  "@babel/types": "^7.28.4",
135
135
  "@storm-software/config-tools": "^1.188.6",
136
- "@stryke/fs": "^0.31.4",
137
- "@stryke/path": "^0.15.5",
136
+ "@stryke/fs": "^0.32.2",
137
+ "@stryke/path": "^0.16.0",
138
138
  "@stryke/type-checks": "^0.3.10",
139
139
  "@stryke/types": "^0.10.0",
140
140
  "chalk": "^5.6.2",
141
141
  "defu": "^6.1.4",
142
142
  "jiti": "^2.6.1",
143
- "powerlines": "^0.4.0",
143
+ "powerlines": "^0.5.0",
144
144
  "unplugin": "^2.3.10"
145
145
  },
146
- "devDependencies": { "@powerlines/nx": "^0.5.0", "@types/node": "^22.18.12" },
146
+ "devDependencies": {
147
+ "@powerlines/nx": "^0.5.1",
148
+ "@powerlines/plugin-plugin": "^0.6.1",
149
+ "@types/node": "^22.18.12"
150
+ },
147
151
  "publishConfig": { "access": "public" },
148
- "gitHead": "56dc46d2a2d16d8b13be33fadb90e0e0c328baee"
152
+ "gitHead": "9f798e68652f3be59814d62b30ce3be4710b7ae7"
149
153
  }
@@ -1,4 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- export { __name };
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
-
6
- exports.__name = __name;
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkUSNT2KNT_cjs = require('../chunk-USNT2KNT.cjs');
4
- var _generate = require('@babel/generator');
5
- var parser = require('@babel/parser');
6
-
7
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
-
9
- var _generate__default = /*#__PURE__*/_interopDefault(_generate);
10
-
11
- function parseAst(code, opts = {}) {
12
- return parser.parse(code, {
13
- plugins: [
14
- "typescript"
15
- ],
16
- sourceType: "module",
17
- allowImportExportEverywhere: true,
18
- allowAwaitOutsideFunction: true,
19
- ...opts
20
- });
21
- }
22
- chunkUSNT2KNT_cjs.__name(parseAst, "parseAst");
23
- let generate = _generate__default.default;
24
- if ("default" in generate) {
25
- generate = generate.default;
26
- }
27
- function generateFromAst(ast, opts) {
28
- return generate(ast, opts ? {
29
- importAttributesKeyword: "with",
30
- sourceMaps: true,
31
- ...opts
32
- } : void 0);
33
- }
34
- chunkUSNT2KNT_cjs.__name(generateFromAst, "generateFromAst");
35
-
36
- exports.generateFromAst = generateFromAst;
37
- exports.parseAst = parseAst;
@@ -1,17 +0,0 @@
1
- import { GeneratorOptions, GeneratorResult } from '@babel/generator';
2
- export { GeneratorResult } from '@babel/generator';
3
- import { ParserOptions, ParseResult } from '@babel/parser';
4
- import * as t from '@babel/types';
5
-
6
- /**
7
- * Parse the given code into an AST.
8
- *
9
- * @param code - The code to parse.
10
- * @param opts - The options for parsing.
11
- * @returns The parsed AST.
12
- */
13
- declare function parseAst(code: string, opts?: ParserOptions): ParseResult<t.File>;
14
- type GenerateFromAstOptions = GeneratorOptions & Required<Pick<GeneratorOptions, "sourceFileName" | "filename">>;
15
- declare function generateFromAst(ast: t.Node, opts?: GenerateFromAstOptions): GeneratorResult;
16
-
17
- export { type GenerateFromAstOptions, generateFromAst, parseAst };
@@ -1,17 +0,0 @@
1
- import { GeneratorOptions, GeneratorResult } from '@babel/generator';
2
- export { GeneratorResult } from '@babel/generator';
3
- import { ParserOptions, ParseResult } from '@babel/parser';
4
- import * as t from '@babel/types';
5
-
6
- /**
7
- * Parse the given code into an AST.
8
- *
9
- * @param code - The code to parse.
10
- * @param opts - The options for parsing.
11
- * @returns The parsed AST.
12
- */
13
- declare function parseAst(code: string, opts?: ParserOptions): ParseResult<t.File>;
14
- type GenerateFromAstOptions = GeneratorOptions & Required<Pick<GeneratorOptions, "sourceFileName" | "filename">>;
15
- declare function generateFromAst(ast: t.Node, opts?: GenerateFromAstOptions): GeneratorResult;
16
-
17
- export { type GenerateFromAstOptions, generateFromAst, parseAst };
@@ -1,30 +0,0 @@
1
- import { __name } from '../chunk-SHUYVCID.js';
2
- import _generate from '@babel/generator';
3
- import { parse } from '@babel/parser';
4
-
5
- function parseAst(code, opts = {}) {
6
- return parse(code, {
7
- plugins: [
8
- "typescript"
9
- ],
10
- sourceType: "module",
11
- allowImportExportEverywhere: true,
12
- allowAwaitOutsideFunction: true,
13
- ...opts
14
- });
15
- }
16
- __name(parseAst, "parseAst");
17
- let generate = _generate;
18
- if ("default" in generate) {
19
- generate = generate.default;
20
- }
21
- function generateFromAst(ast, opts) {
22
- return generate(ast, opts ? {
23
- importAttributesKeyword: "with",
24
- sourceMaps: true,
25
- ...opts
26
- } : void 0);
27
- }
28
- __name(generateFromAst, "generateFromAst");
29
-
30
- export { generateFromAst, parseAst };
@@ -1,38 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkUSNT2KNT_cjs = require('../chunk-USNT2KNT.cjs');
4
- var helperPluginUtils = require('@babel/helper-plugin-utils');
5
- var types = require('@storm-software/config-tools/types');
6
- var chalk = require('chalk');
7
- var logger = require('powerlines/lib/logger');
8
-
9
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
-
11
- var chalk__default = /*#__PURE__*/_interopDefault(chalk);
12
-
13
- function createBabelPlugin(name, builder) {
14
- const plugin = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((context) => {
15
- return helperPluginUtils.declare((api, options, dirname) => {
16
- api.cache.using(() => context.meta.checksum);
17
- api.assertVersion("^7.0.0-0");
18
- const log = logger.extendLog(context.log, name);
19
- log(types.LogLevelLabel.TRACE, `Initializing the ${chalk__default.default.bold.cyanBright(name)} Babel plugin`);
20
- const result = builder({
21
- log,
22
- name,
23
- api,
24
- options,
25
- context,
26
- dirname
27
- });
28
- result.name = name;
29
- log(types.LogLevelLabel.TRACE, `Completed initialization of the ${chalk__default.default.bold.cyanBright(name)} Babel plugin`);
30
- return result;
31
- });
32
- }, "plugin");
33
- plugin.$$name = name;
34
- return plugin;
35
- }
36
- chunkUSNT2KNT_cjs.__name(createBabelPlugin, "createBabelPlugin");
37
-
38
- exports.createBabelPlugin = createBabelPlugin;
@@ -1,13 +0,0 @@
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 };
@@ -1,13 +0,0 @@
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 };
@@ -1,32 +0,0 @@
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 };
@@ -1,50 +0,0 @@
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;
@@ -1,41 +0,0 @@
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 };
@@ -1,41 +0,0 @@
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 };
@@ -1,45 +0,0 @@
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 };
@@ -1,40 +0,0 @@
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
- });
@@ -1,12 +0,0 @@
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';
@@ -1,12 +0,0 @@
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';
@@ -1,5 +0,0 @@
1
- export * from './ast-utils';
2
- export * from './create-plugin';
3
- export * from './filters';
4
- export * from './module-helpers';
5
- export * from './options';
@@ -1,123 +0,0 @@
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;