@powerlines/plugin-babel 0.5.0 → 0.6.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/package.json +10 -6
- package/dist/chunk-SHUYVCID.js +0 -4
- package/dist/chunk-USNT2KNT.cjs +0 -6
- package/dist/helpers/ast-utils.cjs +0 -37
- package/dist/helpers/ast-utils.d.cts +0 -17
- package/dist/helpers/ast-utils.d.ts +0 -17
- package/dist/helpers/ast-utils.js +0 -30
- package/dist/helpers/create-plugin.cjs +0 -38
- package/dist/helpers/create-plugin.d.cts +0 -13
- package/dist/helpers/create-plugin.d.ts +0 -13
- package/dist/helpers/create-plugin.js +0 -32
- package/dist/helpers/filters.cjs +0 -50
- package/dist/helpers/filters.d.cts +0 -41
- package/dist/helpers/filters.d.ts +0 -41
- package/dist/helpers/filters.js +0 -45
- package/dist/helpers/index.cjs +0 -40
- package/dist/helpers/index.d.cts +0 -12
- package/dist/helpers/index.d.ts +0 -12
- package/dist/helpers/index.js +0 -5
- package/dist/helpers/module-helpers.cjs +0 -123
- package/dist/helpers/module-helpers.d.cts +0 -47
- package/dist/helpers/module-helpers.d.ts +0 -47
- package/dist/helpers/module-helpers.js +0 -95
- package/dist/helpers/options.cjs +0 -46
- package/dist/helpers/options.d.cts +0 -17
- package/dist/helpers/options.d.ts +0 -17
- package/dist/helpers/options.js +0 -39
- package/dist/index.cjs +0 -117
- package/dist/index.d.cts +0 -27
- package/dist/index.d.ts +0 -27
- package/dist/index.js +0 -96
- package/dist/types/index.cjs +0 -12
- package/dist/types/index.d.cts +0 -4
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.js +0 -1
- package/dist/types/plugin.cjs +0 -2
- package/dist/types/plugin.d.cts +0 -14
- package/dist/types/plugin.d.ts +0 -14
- package/dist/types/plugin.js +0 -1
|
@@ -1,47 +0,0 @@
|
|
|
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 };
|
|
@@ -1,47 +0,0 @@
|
|
|
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 };
|
|
@@ -1,95 +0,0 @@
|
|
|
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 };
|
package/dist/helpers/options.cjs
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { PluginTarget, PluginOptions } from '@babel/core';
|
|
2
|
-
import { BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions } from 'powerlines/types/babel';
|
|
3
|
-
import { Context } from 'powerlines/types/context';
|
|
4
|
-
|
|
5
|
-
declare function resolvePluginFunction(context: Context, plugin: any | PluginTarget | any[] | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string | undefined]): BabelTransformPluginOptions;
|
|
6
|
-
/**
|
|
7
|
-
* Resolve the [Babel](https://babeljs.io/) plugin.
|
|
8
|
-
*
|
|
9
|
-
* @param context - The context for the transformation.
|
|
10
|
-
* @param code - The code to be transformed.
|
|
11
|
-
* @param id - The ID of the source file.
|
|
12
|
-
* @param plugin - The Babel plugin to resolve.
|
|
13
|
-
* @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
|
|
14
|
-
*/
|
|
15
|
-
declare function resolveBabelPlugin(context: Context, code: string, id: string, plugin: BabelTransformPluginOptions): ResolvedBabelTransformPluginOptions | undefined;
|
|
16
|
-
|
|
17
|
-
export { resolveBabelPlugin, resolvePluginFunction };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { PluginTarget, PluginOptions } from '@babel/core';
|
|
2
|
-
import { BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions } from 'powerlines/types/babel';
|
|
3
|
-
import { Context } from 'powerlines/types/context';
|
|
4
|
-
|
|
5
|
-
declare function resolvePluginFunction(context: Context, plugin: any | PluginTarget | any[] | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string | undefined]): BabelTransformPluginOptions;
|
|
6
|
-
/**
|
|
7
|
-
* Resolve the [Babel](https://babeljs.io/) plugin.
|
|
8
|
-
*
|
|
9
|
-
* @param context - The context for the transformation.
|
|
10
|
-
* @param code - The code to be transformed.
|
|
11
|
-
* @param id - The ID of the source file.
|
|
12
|
-
* @param plugin - The Babel plugin to resolve.
|
|
13
|
-
* @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
|
|
14
|
-
*/
|
|
15
|
-
declare function resolveBabelPlugin(context: Context, code: string, id: string, plugin: BabelTransformPluginOptions): ResolvedBabelTransformPluginOptions | undefined;
|
|
16
|
-
|
|
17
|
-
export { resolveBabelPlugin, resolvePluginFunction };
|
package/dist/helpers/options.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { __name } from '../chunk-SHUYVCID.js';
|
|
2
|
-
import { LogLevelLabel } from '@storm-software/config-tools/types';
|
|
3
|
-
import { isFunction } from '@stryke/type-checks/is-function';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import { getPluginName } from './filters';
|
|
6
|
-
|
|
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
|
-
__name(resolvePluginFunction, "resolvePluginFunction");
|
|
15
|
-
function resolveBabelPlugin(context, code, id, plugin) {
|
|
16
|
-
if (Array.isArray(plugin) && plugin.length > 0 && plugin[0]) {
|
|
17
|
-
if (plugin.length > 2 && plugin[2] && isFunction(plugin[2]) && !plugin[2](code, id)) {
|
|
18
|
-
context.log(LogLevelLabel.TRACE, `Skipping filtered Babel plugin ${chalk.bold.cyanBright(getPluginName(plugin) || "unnamed")} for ${id}`);
|
|
19
|
-
return void 0;
|
|
20
|
-
}
|
|
21
|
-
return plugin.length > 2 ? [
|
|
22
|
-
resolvePluginFunction(context, plugin),
|
|
23
|
-
plugin[1],
|
|
24
|
-
plugin[2]
|
|
25
|
-
] : [
|
|
26
|
-
resolvePluginFunction(context, plugin),
|
|
27
|
-
plugin[1],
|
|
28
|
-
null
|
|
29
|
-
];
|
|
30
|
-
}
|
|
31
|
-
return [
|
|
32
|
-
resolvePluginFunction(context, plugin),
|
|
33
|
-
{},
|
|
34
|
-
null
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
__name(resolveBabelPlugin, "resolveBabelPlugin");
|
|
38
|
-
|
|
39
|
-
export { resolveBabelPlugin, resolvePluginFunction };
|
package/dist/index.cjs
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var chunkUSNT2KNT_cjs = require('./chunk-USNT2KNT.cjs');
|
|
6
|
-
var core = require('@babel/core');
|
|
7
|
-
var types$1 = require('@storm-software/config-tools/types');
|
|
8
|
-
var isParentPath = require('@stryke/path/is-parent-path');
|
|
9
|
-
var isSetObject = require('@stryke/type-checks/is-set-object');
|
|
10
|
-
var defu = require('defu');
|
|
11
|
-
var filters = require('./helpers/filters');
|
|
12
|
-
var options = require('./helpers/options');
|
|
13
|
-
var helpers = require('./helpers');
|
|
14
|
-
var types = require('./types');
|
|
15
|
-
|
|
16
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
-
|
|
18
|
-
var defu__default = /*#__PURE__*/_interopDefault(defu);
|
|
19
|
-
|
|
20
|
-
const plugin = /* @__PURE__ */ chunkUSNT2KNT_cjs.__name((options$1 = {}) => {
|
|
21
|
-
return {
|
|
22
|
-
name: "babel",
|
|
23
|
-
config() {
|
|
24
|
-
if (!isSetObject.isSetObject(options$1)) {
|
|
25
|
-
return void 0;
|
|
26
|
-
}
|
|
27
|
-
return {
|
|
28
|
-
transform: {
|
|
29
|
-
babel: options$1
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
},
|
|
33
|
-
configResolved: {
|
|
34
|
-
order: "pre",
|
|
35
|
-
handler() {
|
|
36
|
-
this.devDependencies["@babel/core"] = "^7.28.4";
|
|
37
|
-
this.config.transform.babel = defu__default.default(this.config.transform.babel ?? {}, {
|
|
38
|
-
plugins: [],
|
|
39
|
-
presets: []
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
async transform(code, id) {
|
|
44
|
-
if (isParentPath.isParentPath(id, this.powerlinesPath) || code.includes("/* @storm-ignore */") || code.includes("/* @storm-disable */")) {
|
|
45
|
-
this.log(types$1.LogLevelLabel.TRACE, `Skipping Babel transformation for: ${id}`);
|
|
46
|
-
return {
|
|
47
|
-
code,
|
|
48
|
-
id
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
this.log(types$1.LogLevelLabel.TRACE, `Babel transforming file: ${id}`);
|
|
52
|
-
const plugins = this.config.transform.babel.plugins.map((plugin2) => options.resolveBabelPlugin(this, code, id, plugin2)).filter((plugin2, _, arr) => plugin2 && !filters.isDuplicatePlugin(arr, plugin2));
|
|
53
|
-
const presets = this.config.transform.babel.presets.map((preset) => options.resolveBabelPlugin(this, code, id, preset)).filter((preset, _, arr) => preset && !filters.isDuplicatePlugin(arr, preset));
|
|
54
|
-
if (Array.isArray(plugins) && plugins.length === 0 && Array.isArray(presets) && presets.length === 0) {
|
|
55
|
-
return {
|
|
56
|
-
code,
|
|
57
|
-
id
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
const result = await core.transformAsync(code, {
|
|
61
|
-
highlightCode: true,
|
|
62
|
-
code: true,
|
|
63
|
-
ast: false,
|
|
64
|
-
cloneInputAst: false,
|
|
65
|
-
comments: true,
|
|
66
|
-
sourceType: "module",
|
|
67
|
-
configFile: false,
|
|
68
|
-
babelrc: false,
|
|
69
|
-
envName: this.config.mode,
|
|
70
|
-
caller: {
|
|
71
|
-
name: "powerlines"
|
|
72
|
-
},
|
|
73
|
-
...this.config.transform.babel ?? {},
|
|
74
|
-
filename: id,
|
|
75
|
-
plugins: plugins.map((plugin2) => {
|
|
76
|
-
return Array.isArray(plugin2) && plugin2.length >= 2 ? [
|
|
77
|
-
plugin2[0],
|
|
78
|
-
defu__default.default(plugin2.length > 1 && plugin2[1] ? plugin2[1] : {}, {
|
|
79
|
-
options: options$1
|
|
80
|
-
})
|
|
81
|
-
] : plugin2;
|
|
82
|
-
}).filter(Boolean),
|
|
83
|
-
presets: presets.map((preset) => {
|
|
84
|
-
return Array.isArray(preset) && preset.length >= 2 ? [
|
|
85
|
-
preset[0],
|
|
86
|
-
defu__default.default(preset.length > 1 && preset[1] ? preset[1] : {}, {
|
|
87
|
-
options: options$1
|
|
88
|
-
})
|
|
89
|
-
] : preset;
|
|
90
|
-
}).filter(Boolean)
|
|
91
|
-
});
|
|
92
|
-
if (!result?.code) {
|
|
93
|
-
throw new Error(`Powerlines - Babel plugin failed to compile ${id}`);
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
code: result.code,
|
|
97
|
-
id
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
}, "plugin");
|
|
102
|
-
var index_default = plugin;
|
|
103
|
-
|
|
104
|
-
exports.default = index_default;
|
|
105
|
-
exports.plugin = plugin;
|
|
106
|
-
Object.keys(helpers).forEach(function (k) {
|
|
107
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
108
|
-
enumerable: true,
|
|
109
|
-
get: function () { return helpers[k]; }
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
Object.keys(types).forEach(function (k) {
|
|
113
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
114
|
-
enumerable: true,
|
|
115
|
-
get: function () { return types[k]; }
|
|
116
|
-
});
|
|
117
|
-
});
|
package/dist/index.d.cts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'powerlines/types/plugin';
|
|
2
|
-
import { BabelPluginContext, BabelPluginOptions } from './types/plugin.cjs';
|
|
3
|
-
export { BabelPluginResolvedConfig, BabelPluginUserConfig } from './types/plugin.cjs';
|
|
4
|
-
export { GenerateFromAstOptions, generateFromAst, parseAst } from './helpers/ast-utils.cjs';
|
|
5
|
-
export { createBabelPlugin } from './helpers/create-plugin.cjs';
|
|
6
|
-
export { addPluginFilter, filterPluginByRuntimeId, getPluginName, isDuplicatePlugin } from './helpers/filters.cjs';
|
|
7
|
-
export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from './helpers/module-helpers.cjs';
|
|
8
|
-
export { resolveBabelPlugin, resolvePluginFunction } from './helpers/options.cjs';
|
|
9
|
-
export { GeneratorResult } from '@babel/generator';
|
|
10
|
-
import 'powerlines/types/config';
|
|
11
|
-
import 'powerlines/types/context';
|
|
12
|
-
import 'powerlines/types/resolved';
|
|
13
|
-
import '@babel/parser';
|
|
14
|
-
import '@babel/types';
|
|
15
|
-
import 'powerlines/types/babel';
|
|
16
|
-
import 'powerlines/types';
|
|
17
|
-
import '@babel/core';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Babel plugin for Powerlines.
|
|
21
|
-
*
|
|
22
|
-
* @param options - The Babel plugin user configuration options.
|
|
23
|
-
* @returns A Powerlines plugin that integrates Babel transformations.
|
|
24
|
-
*/
|
|
25
|
-
declare const plugin: <TContext extends BabelPluginContext = BabelPluginContext>(options?: BabelPluginOptions) => Plugin<TContext>;
|
|
26
|
-
|
|
27
|
-
export { BabelPluginContext, BabelPluginOptions, plugin as default, plugin };
|
package/dist/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Plugin } from 'powerlines/types/plugin';
|
|
2
|
-
import { BabelPluginContext, BabelPluginOptions } from './types/plugin.js';
|
|
3
|
-
export { BabelPluginResolvedConfig, BabelPluginUserConfig } from './types/plugin.js';
|
|
4
|
-
export { GenerateFromAstOptions, generateFromAst, parseAst } from './helpers/ast-utils.js';
|
|
5
|
-
export { createBabelPlugin } from './helpers/create-plugin.js';
|
|
6
|
-
export { addPluginFilter, filterPluginByRuntimeId, getPluginName, isDuplicatePlugin } from './helpers/filters.js';
|
|
7
|
-
export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from './helpers/module-helpers.js';
|
|
8
|
-
export { resolveBabelPlugin, resolvePluginFunction } from './helpers/options.js';
|
|
9
|
-
export { GeneratorResult } from '@babel/generator';
|
|
10
|
-
import 'powerlines/types/config';
|
|
11
|
-
import 'powerlines/types/context';
|
|
12
|
-
import 'powerlines/types/resolved';
|
|
13
|
-
import '@babel/parser';
|
|
14
|
-
import '@babel/types';
|
|
15
|
-
import 'powerlines/types/babel';
|
|
16
|
-
import 'powerlines/types';
|
|
17
|
-
import '@babel/core';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Babel plugin for Powerlines.
|
|
21
|
-
*
|
|
22
|
-
* @param options - The Babel plugin user configuration options.
|
|
23
|
-
* @returns A Powerlines plugin that integrates Babel transformations.
|
|
24
|
-
*/
|
|
25
|
-
declare const plugin: <TContext extends BabelPluginContext = BabelPluginContext>(options?: BabelPluginOptions) => Plugin<TContext>;
|
|
26
|
-
|
|
27
|
-
export { BabelPluginContext, BabelPluginOptions, plugin as default, plugin };
|
package/dist/index.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { __name } from './chunk-SHUYVCID.js';
|
|
2
|
-
import { transformAsync } from '@babel/core';
|
|
3
|
-
import { LogLevelLabel } from '@storm-software/config-tools/types';
|
|
4
|
-
import { isParentPath } from '@stryke/path/is-parent-path';
|
|
5
|
-
import { isSetObject } from '@stryke/type-checks/is-set-object';
|
|
6
|
-
import defu from 'defu';
|
|
7
|
-
import { isDuplicatePlugin } from './helpers/filters';
|
|
8
|
-
import { resolveBabelPlugin } from './helpers/options';
|
|
9
|
-
export * from './helpers';
|
|
10
|
-
export * from './types';
|
|
11
|
-
|
|
12
|
-
const plugin = /* @__PURE__ */ __name((options = {}) => {
|
|
13
|
-
return {
|
|
14
|
-
name: "babel",
|
|
15
|
-
config() {
|
|
16
|
-
if (!isSetObject(options)) {
|
|
17
|
-
return void 0;
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
transform: {
|
|
21
|
-
babel: options
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
configResolved: {
|
|
26
|
-
order: "pre",
|
|
27
|
-
handler() {
|
|
28
|
-
this.devDependencies["@babel/core"] = "^7.28.4";
|
|
29
|
-
this.config.transform.babel = defu(this.config.transform.babel ?? {}, {
|
|
30
|
-
plugins: [],
|
|
31
|
-
presets: []
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
async transform(code, id) {
|
|
36
|
-
if (isParentPath(id, this.powerlinesPath) || code.includes("/* @storm-ignore */") || code.includes("/* @storm-disable */")) {
|
|
37
|
-
this.log(LogLevelLabel.TRACE, `Skipping Babel transformation for: ${id}`);
|
|
38
|
-
return {
|
|
39
|
-
code,
|
|
40
|
-
id
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
this.log(LogLevelLabel.TRACE, `Babel transforming file: ${id}`);
|
|
44
|
-
const plugins = this.config.transform.babel.plugins.map((plugin2) => resolveBabelPlugin(this, code, id, plugin2)).filter((plugin2, _, arr) => plugin2 && !isDuplicatePlugin(arr, plugin2));
|
|
45
|
-
const presets = this.config.transform.babel.presets.map((preset) => resolveBabelPlugin(this, code, id, preset)).filter((preset, _, arr) => preset && !isDuplicatePlugin(arr, preset));
|
|
46
|
-
if (Array.isArray(plugins) && plugins.length === 0 && Array.isArray(presets) && presets.length === 0) {
|
|
47
|
-
return {
|
|
48
|
-
code,
|
|
49
|
-
id
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
const result = await transformAsync(code, {
|
|
53
|
-
highlightCode: true,
|
|
54
|
-
code: true,
|
|
55
|
-
ast: false,
|
|
56
|
-
cloneInputAst: false,
|
|
57
|
-
comments: true,
|
|
58
|
-
sourceType: "module",
|
|
59
|
-
configFile: false,
|
|
60
|
-
babelrc: false,
|
|
61
|
-
envName: this.config.mode,
|
|
62
|
-
caller: {
|
|
63
|
-
name: "powerlines"
|
|
64
|
-
},
|
|
65
|
-
...this.config.transform.babel ?? {},
|
|
66
|
-
filename: id,
|
|
67
|
-
plugins: plugins.map((plugin2) => {
|
|
68
|
-
return Array.isArray(plugin2) && plugin2.length >= 2 ? [
|
|
69
|
-
plugin2[0],
|
|
70
|
-
defu(plugin2.length > 1 && plugin2[1] ? plugin2[1] : {}, {
|
|
71
|
-
options
|
|
72
|
-
})
|
|
73
|
-
] : plugin2;
|
|
74
|
-
}).filter(Boolean),
|
|
75
|
-
presets: presets.map((preset) => {
|
|
76
|
-
return Array.isArray(preset) && preset.length >= 2 ? [
|
|
77
|
-
preset[0],
|
|
78
|
-
defu(preset.length > 1 && preset[1] ? preset[1] : {}, {
|
|
79
|
-
options
|
|
80
|
-
})
|
|
81
|
-
] : preset;
|
|
82
|
-
}).filter(Boolean)
|
|
83
|
-
});
|
|
84
|
-
if (!result?.code) {
|
|
85
|
-
throw new Error(`Powerlines - Babel plugin failed to compile ${id}`);
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
code: result.code,
|
|
89
|
-
id
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}, "plugin");
|
|
94
|
-
var index_default = plugin;
|
|
95
|
-
|
|
96
|
-
export { index_default as default, plugin };
|
package/dist/types/index.cjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var plugin = require('./plugin');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.keys(plugin).forEach(function (k) {
|
|
8
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () { return plugin[k]; }
|
|
11
|
-
});
|
|
12
|
-
});
|
package/dist/types/index.d.cts
DELETED
package/dist/types/index.d.ts
DELETED
package/dist/types/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './plugin';
|
package/dist/types/plugin.cjs
DELETED
package/dist/types/plugin.d.cts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { BabelUserConfig, UserConfig } from 'powerlines/types/config';
|
|
2
|
-
import { PluginContext } from 'powerlines/types/context';
|
|
3
|
-
import { ResolvedConfig, BabelResolvedConfig } from 'powerlines/types/resolved';
|
|
4
|
-
|
|
5
|
-
type BabelPluginOptions = Partial<BabelUserConfig>;
|
|
6
|
-
type BabelPluginUserConfig = UserConfig;
|
|
7
|
-
interface BabelPluginResolvedConfig extends ResolvedConfig {
|
|
8
|
-
transform: {
|
|
9
|
-
babel: BabelResolvedConfig;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
type BabelPluginContext<TResolvedConfig extends BabelPluginResolvedConfig = BabelPluginResolvedConfig> = PluginContext<TResolvedConfig>;
|
|
13
|
-
|
|
14
|
-
export type { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig };
|
package/dist/types/plugin.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { BabelUserConfig, UserConfig } from 'powerlines/types/config';
|
|
2
|
-
import { PluginContext } from 'powerlines/types/context';
|
|
3
|
-
import { ResolvedConfig, BabelResolvedConfig } from 'powerlines/types/resolved';
|
|
4
|
-
|
|
5
|
-
type BabelPluginOptions = Partial<BabelUserConfig>;
|
|
6
|
-
type BabelPluginUserConfig = UserConfig;
|
|
7
|
-
interface BabelPluginResolvedConfig extends ResolvedConfig {
|
|
8
|
-
transform: {
|
|
9
|
-
babel: BabelResolvedConfig;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
type BabelPluginContext<TResolvedConfig extends BabelPluginResolvedConfig = BabelPluginResolvedConfig> = PluginContext<TResolvedConfig>;
|
|
13
|
-
|
|
14
|
-
export type { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig };
|
package/dist/types/plugin.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|