@powerlines/plugin-babel 0.12.299 → 0.12.300
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/src/lib/logger.mjs +40 -0
- package/dist/core/src/lib/logger.mjs.map +1 -0
- package/dist/core/src/types/api.d.mts +103 -0
- package/dist/core/src/types/api.d.mts.map +1 -0
- package/dist/core/src/types/commands.d.mts +10 -0
- package/dist/core/src/types/commands.d.mts.map +1 -0
- package/dist/core/src/types/config.d.mts +551 -0
- package/dist/core/src/types/config.d.mts.map +1 -0
- package/dist/core/src/types/context.d.mts +511 -0
- package/dist/core/src/types/context.d.mts.map +1 -0
- package/dist/core/src/types/fs.d.mts +487 -0
- package/dist/core/src/types/fs.d.mts.map +1 -0
- package/dist/core/src/types/hooks.d.mts +99 -0
- package/dist/core/src/types/hooks.d.mts.map +1 -0
- package/dist/core/src/types/index.d.mts +9 -0
- package/dist/core/src/types/plugin.d.mts +204 -0
- package/dist/core/src/types/plugin.d.mts.map +1 -0
- package/dist/core/src/types/tsconfig.d.mts +70 -0
- package/dist/core/src/types/tsconfig.d.mts.map +1 -0
- package/dist/core/src/types/unplugin.d.mts +25 -0
- package/dist/core/src/types/unplugin.d.mts.map +1 -0
- package/dist/helpers/create-plugin.d.mts +3 -2
- package/dist/helpers/create-plugin.d.mts.map +1 -1
- package/dist/helpers/create-plugin.mjs +1 -1
- package/dist/helpers/create-plugin.mjs.map +1 -1
- package/dist/helpers/filters.d.mts +4 -3
- package/dist/helpers/filters.d.mts.map +1 -1
- package/dist/helpers/filters.mjs.map +1 -1
- package/dist/helpers/module-helpers.d.mts +1 -1
- package/dist/helpers/module-helpers.mjs.map +1 -1
- package/dist/helpers/options.d.mts +3 -2
- package/dist/helpers/options.d.mts.map +1 -1
- package/dist/helpers/options.mjs.map +1 -1
- package/dist/index.d.mts +5 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/index.mjs.map +1 -1
- package/dist/types/config.d.mts +88 -0
- package/dist/types/config.d.mts.map +1 -0
- package/dist/types/config.mjs +1 -0
- package/dist/types/index.d.mts +2 -1
- package/dist/types/plugin.d.mts +8 -7
- package/dist/types/plugin.d.mts.map +1 -1
- package/package.json +36 -153
- package/dist/_virtual/rolldown_runtime.cjs +0 -29
- package/dist/helpers/ast-utils.cjs +0 -35
- package/dist/helpers/ast-utils.d.cts +0 -20
- package/dist/helpers/ast-utils.d.cts.map +0 -1
- package/dist/helpers/create-plugin.cjs +0 -41
- package/dist/helpers/create-plugin.d.cts +0 -16
- package/dist/helpers/create-plugin.d.cts.map +0 -1
- package/dist/helpers/filters.cjs +0 -59
- package/dist/helpers/filters.d.cts +0 -43
- package/dist/helpers/filters.d.cts.map +0 -1
- package/dist/helpers/index.cjs +0 -22
- package/dist/helpers/index.d.cts +0 -6
- package/dist/helpers/module-helpers.cjs +0 -103
- package/dist/helpers/module-helpers.d.cts +0 -50
- package/dist/helpers/module-helpers.d.cts.map +0 -1
- package/dist/helpers/options.cjs +0 -49
- package/dist/helpers/options.d.cts +0 -19
- package/dist/helpers/options.d.cts.map +0 -1
- package/dist/index.cjs +0 -104
- package/dist/index.d.cts +0 -21
- package/dist/index.d.cts.map +0 -1
- package/dist/types/index.cjs +0 -0
- package/dist/types/index.d.cts +0 -2
- package/dist/types/plugin.cjs +0 -0
- package/dist/types/plugin.d.cts +0 -20
- package/dist/types/plugin.d.cts.map +0 -1
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { BabelTransformPlugin, BabelTransformPluginFilter, BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions } from "powerlines/types/babel";
|
|
2
|
-
import { Context } from "powerlines/types";
|
|
3
|
-
|
|
4
|
-
//#region src/helpers/filters.d.ts
|
|
5
|
-
declare function getPluginName(plugin: BabelTransformPluginOptions): string | undefined;
|
|
6
|
-
/**
|
|
7
|
-
* Check if a Babel plugin is a duplicate of another plugin in the list.
|
|
8
|
-
*
|
|
9
|
-
* @param plugins - The list of existing Babel plugins.
|
|
10
|
-
* @param plugin - The Babel plugin to check for duplicates.
|
|
11
|
-
* @returns True if the plugin is a duplicate, false otherwise.
|
|
12
|
-
*/
|
|
13
|
-
declare function isDuplicatePlugin(plugins: (ResolvedBabelTransformPluginOptions | undefined)[], plugin: BabelTransformPluginOptions): boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Filters a Babel plugin by its runtime ID.
|
|
16
|
-
*
|
|
17
|
-
* @param context - The context in which the filter is applied.
|
|
18
|
-
* @param fileId - The file ID to filter by.
|
|
19
|
-
* @returns A filter function that checks if a plugin's ID matches the runtime ID.
|
|
20
|
-
*/
|
|
21
|
-
declare function filterPluginByFileId<TContext extends Context = Context>(context: TContext, fileId: string): BabelTransformPluginFilter;
|
|
22
|
-
/**
|
|
23
|
-
* Adds a filter to a Babel plugin or a list of Babel plugins.
|
|
24
|
-
*
|
|
25
|
-
* @param context - The context in which the plugin is being added.
|
|
26
|
-
* @param plugins - The Babel plugins to add the filter to.
|
|
27
|
-
* @param filter - The filter function to apply to the plugins.
|
|
28
|
-
* @param name - The name of the plugin to add the filter to.
|
|
29
|
-
* @returns The updated list of Babel plugins with the filter applied.
|
|
30
|
-
*/
|
|
31
|
-
declare function addPluginFilter(context: Context, plugins: BabelTransformPluginOptions[], filter: BabelTransformPluginFilter | null | undefined, name: string): BabelTransformPluginOptions[];
|
|
32
|
-
/**
|
|
33
|
-
* Adds a filter to a Babel plugin or a list of Babel plugins.
|
|
34
|
-
*
|
|
35
|
-
* @param context - The context in which the plugin is being added.
|
|
36
|
-
* @param plugin - The Babel plugin to add the filter to.
|
|
37
|
-
* @param filter - The filter function to apply to the plugin.
|
|
38
|
-
* @returns The updated Babel plugin with the filter applied.
|
|
39
|
-
*/
|
|
40
|
-
declare function addPluginFilter(context: Context, plugin: BabelTransformPlugin | BabelTransformPluginOptions, filter: NonNullable<BabelTransformPluginFilter>): BabelTransformPluginOptions;
|
|
41
|
-
//#endregion
|
|
42
|
-
export { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin };
|
|
43
|
-
//# sourceMappingURL=filters.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filters.d.cts","names":[],"sources":["../../src/helpers/filters.ts"],"sourcesContent":[],"mappings":";;;;iBA6BgB,aAAA,SACN;;AADV;AAqBA;AAqBA;;;;AAGG,iBAxBa,iBAAA,CAwBb,OAAA,EAAA,CAvBS,mCAuBT,GAAA,SAAA,CAAA,EAAA,EAAA,MAAA,EAtBO,2BAsBP,CAAA,EAAA,OAAA;;AAoBH;;;;;;AAegB,iBAtCA,oBAsCe,CAAA,iBAtCuB,OAsCvB,GAtCiC,OAsCjC,CAAA,CAAA,OAAA,EArCpB,QAqCoB,EAAA,MAAA,EAAA,MAAA,CAAA,EAnC5B,0BAmC4B;;;;;;;;;;iBAff,eAAA,UACL,kBACA,uCACD,8DAEP;;;;;;;;;iBAUa,eAAA,UACL,iBACD,uBAAuB,qCACvB,YAAY,8BACnB"}
|
package/dist/helpers/index.cjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const require_helpers_filters = require('./filters.cjs');
|
|
2
|
-
const require_helpers_options = require('./options.cjs');
|
|
3
|
-
const require_helpers_ast_utils = require('./ast-utils.cjs');
|
|
4
|
-
const require_helpers_create_plugin = require('./create-plugin.cjs');
|
|
5
|
-
const require_helpers_module_helpers = require('./module-helpers.cjs');
|
|
6
|
-
|
|
7
|
-
exports.addImport = require_helpers_module_helpers.addImport;
|
|
8
|
-
exports.addImportsToProgram = require_helpers_module_helpers.addImportsToProgram;
|
|
9
|
-
exports.addPluginFilter = require_helpers_filters.addPluginFilter;
|
|
10
|
-
exports.createBabelPlugin = require_helpers_create_plugin.createBabelPlugin;
|
|
11
|
-
exports.filterPluginByFileId = require_helpers_filters.filterPluginByFileId;
|
|
12
|
-
exports.findExport = require_helpers_module_helpers.findExport;
|
|
13
|
-
exports.generateFromAst = require_helpers_ast_utils.generateFromAst;
|
|
14
|
-
exports.getImport = require_helpers_module_helpers.getImport;
|
|
15
|
-
exports.getPluginName = require_helpers_filters.getPluginName;
|
|
16
|
-
exports.isDuplicatePlugin = require_helpers_filters.isDuplicatePlugin;
|
|
17
|
-
exports.isImportCall = require_helpers_module_helpers.isImportCall;
|
|
18
|
-
exports.listExports = require_helpers_module_helpers.listExports;
|
|
19
|
-
exports.listImports = require_helpers_module_helpers.listImports;
|
|
20
|
-
exports.parseAst = require_helpers_ast_utils.parseAst;
|
|
21
|
-
exports.resolveBabelPlugin = require_helpers_options.resolveBabelPlugin;
|
|
22
|
-
exports.resolvePluginFunction = require_helpers_options.resolvePluginFunction;
|
package/dist/helpers/index.d.cts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, generateFromAst, parseAst } from "./ast-utils.cjs";
|
|
2
|
-
import { createBabelPlugin } from "./create-plugin.cjs";
|
|
3
|
-
import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin } from "./filters.cjs";
|
|
4
|
-
import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./module-helpers.cjs";
|
|
5
|
-
import { resolveBabelPlugin, resolvePluginFunction } from "./options.cjs";
|
|
6
|
-
export { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolvePluginFunction };
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_helpers_ast_utils = require('./ast-utils.cjs');
|
|
3
|
-
let __babel_types = require("@babel/types");
|
|
4
|
-
__babel_types = require_rolldown_runtime.__toESM(__babel_types);
|
|
5
|
-
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
6
|
-
|
|
7
|
-
//#region src/helpers/module-helpers.ts
|
|
8
|
-
/**
|
|
9
|
-
* Finds an export in the given Babel AST program by its key.
|
|
10
|
-
*
|
|
11
|
-
* @param ast - The parsed Babel AST result containing the program body.
|
|
12
|
-
* @param key - The name of the export to find (e.g., "default" or a named export).
|
|
13
|
-
* @returns The declaration of the export if found, otherwise undefined.
|
|
14
|
-
*/
|
|
15
|
-
function findExport(ast, key) {
|
|
16
|
-
const type = key === "default" ? "ExportDefaultDeclaration" : "ExportNamedDeclaration";
|
|
17
|
-
for (const node of ast.program.body) if (node.type === type) {
|
|
18
|
-
if (key === "default") return node.declaration;
|
|
19
|
-
if (node.declaration && "declarations" in node.declaration) {
|
|
20
|
-
const declaration = node.declaration.declarations[0];
|
|
21
|
-
if (declaration && "name" in declaration.id && declaration.id.name === key) return declaration.init;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Lists all exports from the given Babel AST program.
|
|
27
|
-
*
|
|
28
|
-
* @param codeOrAst - The parsed Babel AST result containing the program body.
|
|
29
|
-
* @returns An array of export names, including "default" for default exports.
|
|
30
|
-
*/
|
|
31
|
-
function listExports(codeOrAst) {
|
|
32
|
-
return ((0, __stryke_type_checks_is_string.isString)(codeOrAst) ? require_helpers_ast_utils.parseAst(codeOrAst) : codeOrAst).program.body.flatMap((i) => {
|
|
33
|
-
if (i.type === "ExportDefaultDeclaration") return ["default"];
|
|
34
|
-
if (i.type === "ExportNamedDeclaration" && i.declaration && "declarations" in i.declaration) return i.declaration.declarations.map((d) => "name" in d.id ? d.id.name : "");
|
|
35
|
-
return [];
|
|
36
|
-
}).filter(Boolean);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Lists all imports from the given Babel AST program.
|
|
40
|
-
*
|
|
41
|
-
* @param ast - The parsed Babel AST result containing the program body.
|
|
42
|
-
* @returns An array of import names, including "default" for default imports.
|
|
43
|
-
*/
|
|
44
|
-
function listImports(ast) {
|
|
45
|
-
return ast.program.body.flatMap((i) => {
|
|
46
|
-
if (i.type === "ImportDeclaration") return i.specifiers.map((s) => {
|
|
47
|
-
if (s.type === "ImportDefaultSpecifier") return "default";
|
|
48
|
-
if (s.type === "ImportSpecifier" && "imported" in s) return s.imported.type === "Identifier" ? s.imported.name : s.imported.value;
|
|
49
|
-
return "";
|
|
50
|
-
});
|
|
51
|
-
return [];
|
|
52
|
-
}).filter(Boolean);
|
|
53
|
-
}
|
|
54
|
-
function isImportCall(calleePath) {
|
|
55
|
-
return __babel_types.isImport(calleePath.node.callee);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Gets the import declaration for a given name and specifier.
|
|
59
|
-
*
|
|
60
|
-
* @param specifier - The specifier of the import.
|
|
61
|
-
* @param name - The name of the import.
|
|
62
|
-
* @param named - Optional named import.
|
|
63
|
-
* @returns The import declaration.
|
|
64
|
-
*/
|
|
65
|
-
function getImport(specifier, name, named) {
|
|
66
|
-
return __babel_types.importDeclaration([__babel_types.importSpecifier(__babel_types.identifier(name), __babel_types.stringLiteral(named || name))], __babel_types.stringLiteral(specifier));
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Adds an import to the program if it doesn't already exist.
|
|
70
|
-
*
|
|
71
|
-
* @param path - The current NodePath in the AST.
|
|
72
|
-
* @param specifier - The import specifier.
|
|
73
|
-
*/
|
|
74
|
-
function addImport(path, specifier) {
|
|
75
|
-
addImportsToProgram(path.scope.getProgramParent().path, specifier);
|
|
76
|
-
}
|
|
77
|
-
function isNonNamespacedImport(importDeclPath) {
|
|
78
|
-
return importDeclPath.get("specifiers").filter(Boolean).every((specifier) => specifier?.isImportSpecifier()) && importDeclPath.node.importKind !== "type" && importDeclPath.node.importKind !== "typeof";
|
|
79
|
-
}
|
|
80
|
-
function getExistingImports(program) {
|
|
81
|
-
const existingImports = /* @__PURE__ */ new Map();
|
|
82
|
-
program.traverse({ ImportDeclaration(path) {
|
|
83
|
-
if (isNonNamespacedImport(path)) existingImports.set(path.node.source.value, path);
|
|
84
|
-
} });
|
|
85
|
-
return existingImports;
|
|
86
|
-
}
|
|
87
|
-
function addImportsToProgram(path, specifier) {
|
|
88
|
-
/**
|
|
89
|
-
* If an existing import of this module exists (ie \`import \{ ... \} from
|
|
90
|
-
* '<moduleName>'\`), inject new imported specifiers into the list of
|
|
91
|
-
* destructured variables.
|
|
92
|
-
*/
|
|
93
|
-
if (!getExistingImports(path).get(specifier.module)) path.unshiftContainer("body", __babel_types.importDeclaration([__babel_types.importSpecifier(__babel_types.identifier(specifier.name || specifier.imported), __babel_types.identifier(specifier.imported))], __babel_types.stringLiteral(specifier.module)));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
//#endregion
|
|
97
|
-
exports.addImport = addImport;
|
|
98
|
-
exports.addImportsToProgram = addImportsToProgram;
|
|
99
|
-
exports.findExport = findExport;
|
|
100
|
-
exports.getImport = getImport;
|
|
101
|
-
exports.isImportCall = isImportCall;
|
|
102
|
-
exports.listExports = listExports;
|
|
103
|
-
exports.listImports = listImports;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { ParseResult } from "@babel/parser";
|
|
2
|
-
import * as t from "@babel/types";
|
|
3
|
-
import { ImportSpecifier } from "powerlines/types/babel";
|
|
4
|
-
import { NodePath } from "@babel/core";
|
|
5
|
-
|
|
6
|
-
//#region src/helpers/module-helpers.d.ts
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Finds an export in the given Babel AST program by its key.
|
|
10
|
-
*
|
|
11
|
-
* @param ast - The parsed Babel AST result containing the program body.
|
|
12
|
-
* @param key - The name of the export to find (e.g., "default" or a named export).
|
|
13
|
-
* @returns The declaration of the export if found, otherwise undefined.
|
|
14
|
-
*/
|
|
15
|
-
declare function findExport(ast: ParseResult<t.File>, key: string): any;
|
|
16
|
-
/**
|
|
17
|
-
* Lists all exports from the given Babel AST program.
|
|
18
|
-
*
|
|
19
|
-
* @param codeOrAst - The parsed Babel AST result containing the program body.
|
|
20
|
-
* @returns An array of export names, including "default" for default exports.
|
|
21
|
-
*/
|
|
22
|
-
declare function listExports(codeOrAst: ParseResult<t.File> | string): string[];
|
|
23
|
-
/**
|
|
24
|
-
* Lists all imports from the given Babel AST program.
|
|
25
|
-
*
|
|
26
|
-
* @param ast - The parsed Babel AST result containing the program body.
|
|
27
|
-
* @returns An array of import names, including "default" for default imports.
|
|
28
|
-
*/
|
|
29
|
-
declare function listImports(ast: ParseResult<t.File> | t.File): string[];
|
|
30
|
-
declare function isImportCall(calleePath: NodePath<t.CallExpression | t.NewExpression>): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Gets the import declaration for a given name and specifier.
|
|
33
|
-
*
|
|
34
|
-
* @param specifier - The specifier of the import.
|
|
35
|
-
* @param name - The name of the import.
|
|
36
|
-
* @param named - Optional named import.
|
|
37
|
-
* @returns The import declaration.
|
|
38
|
-
*/
|
|
39
|
-
declare function getImport(specifier: string, name: string, named?: string): t.ImportDeclaration;
|
|
40
|
-
/**
|
|
41
|
-
* Adds an import to the program if it doesn't already exist.
|
|
42
|
-
*
|
|
43
|
-
* @param path - The current NodePath in the AST.
|
|
44
|
-
* @param specifier - The import specifier.
|
|
45
|
-
*/
|
|
46
|
-
declare function addImport(path: NodePath<any>, specifier: ImportSpecifier): void;
|
|
47
|
-
declare function addImportsToProgram(path: NodePath<t.Program>, specifier: ImportSpecifier): void;
|
|
48
|
-
//#endregion
|
|
49
|
-
export { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports };
|
|
50
|
-
//# sourceMappingURL=module-helpers.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module-helpers.d.cts","names":[],"sources":["../../src/helpers/module-helpers.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAgCA;AA6BA;AA4BA;;;AAAyD,iBAzDzC,UAAA,CAyDyC,GAAA,EAzDzB,WAyDyB,CAzDb,CAAA,CAAE,IAyDW,CAAA,EAAA,GAAA,EAAA,MAAA,CAAA,EAAA,GAAA;;AAsBzD;;;;;AAcgB,iBAhEA,WAAA,CAoEX,SAAA,EApEkC,WAoEjB,CApE6B,CAAA,CAAE,IAoE/B,CAAA,GAAA,MAAA,CAAA,EAAA,MAAA,EAAA;AAatB;AAuCA;;;;;iBA5FgB,WAAA,MAAiB,YAAY,CAAA,CAAE,QAAQ,CAAA,CAAE;iBAsBzC,YAAA,aACF,SAAS,CAAA,CAAE,iBAAiB,CAAA,CAAE;;;;;;;;;iBAa5B,SAAA,mDAIb,CAAA,CAAE;;;;;;;iBAaW,SAAA,OAAgB,0BAA0B;iBAuC1C,mBAAA,OACR,SAAS,CAAA,CAAE,qBACN"}
|
package/dist/helpers/options.cjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_helpers_filters = require('./filters.cjs');
|
|
3
|
-
let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
4
|
-
let chalk = require("chalk");
|
|
5
|
-
chalk = require_rolldown_runtime.__toESM(chalk);
|
|
6
|
-
|
|
7
|
-
//#region src/helpers/options.ts
|
|
8
|
-
function resolvePluginFunction(context, plugin) {
|
|
9
|
-
try {
|
|
10
|
-
return Array.isArray(plugin) && plugin.length > 0 && plugin[0] ? (0, __stryke_type_checks_is_function.isFunction)(plugin[0]) ? plugin[0](context) : plugin[0] : (0, __stryke_type_checks_is_function.isFunction)(plugin) ? plugin(context) : plugin;
|
|
11
|
-
} catch {
|
|
12
|
-
return plugin[0];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Resolve the [Babel](https://babeljs.io/) plugin.
|
|
17
|
-
*
|
|
18
|
-
* @param context - The context for the transformation.
|
|
19
|
-
* @param code - The code to be transformed.
|
|
20
|
-
* @param id - The ID of the source file.
|
|
21
|
-
* @param plugin - The Babel plugin to resolve.
|
|
22
|
-
* @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
|
|
23
|
-
*/
|
|
24
|
-
function resolveBabelPlugin(context, code, id, plugin) {
|
|
25
|
-
if (Array.isArray(plugin) && plugin.length > 0 && plugin[0]) {
|
|
26
|
-
if (plugin.length > 2 && plugin[2] && (0, __stryke_type_checks_is_function.isFunction)(plugin[2]) && !plugin[2](code, id)) {
|
|
27
|
-
context.trace(`Skipping filtered Babel plugin ${chalk.default.bold.cyanBright(require_helpers_filters.getPluginName(plugin) || "unnamed")} for ${id}`);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
return plugin.length > 2 ? [
|
|
31
|
-
resolvePluginFunction(context, plugin),
|
|
32
|
-
plugin[1],
|
|
33
|
-
plugin[2]
|
|
34
|
-
] : [
|
|
35
|
-
resolvePluginFunction(context, plugin),
|
|
36
|
-
plugin[1],
|
|
37
|
-
null
|
|
38
|
-
];
|
|
39
|
-
}
|
|
40
|
-
return [
|
|
41
|
-
resolvePluginFunction(context, plugin),
|
|
42
|
-
{},
|
|
43
|
-
null
|
|
44
|
-
];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
exports.resolveBabelPlugin = resolveBabelPlugin;
|
|
49
|
-
exports.resolvePluginFunction = resolvePluginFunction;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { BabelTransformPluginOptions, ResolvedBabelTransformPluginOptions } from "powerlines/types/babel";
|
|
2
|
-
import { Context } from "powerlines/types/context";
|
|
3
|
-
import { PluginOptions, PluginTarget } from "@babel/core";
|
|
4
|
-
|
|
5
|
-
//#region src/helpers/options.d.ts
|
|
6
|
-
declare function resolvePluginFunction(context: Context, plugin: any | PluginTarget | any[] | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string | undefined]): BabelTransformPluginOptions;
|
|
7
|
-
/**
|
|
8
|
-
* Resolve the [Babel](https://babeljs.io/) plugin.
|
|
9
|
-
*
|
|
10
|
-
* @param context - The context for the transformation.
|
|
11
|
-
* @param code - The code to be transformed.
|
|
12
|
-
* @param id - The ID of the source file.
|
|
13
|
-
* @param plugin - The Babel plugin to resolve.
|
|
14
|
-
* @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.
|
|
15
|
-
*/
|
|
16
|
-
declare function resolveBabelPlugin(context: Context, code: string, id: string, plugin: BabelTransformPluginOptions): ResolvedBabelTransformPluginOptions | undefined;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { resolveBabelPlugin, resolvePluginFunction };
|
|
19
|
-
//# sourceMappingURL=options.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.cts","names":[],"sources":["../../src/helpers/options.ts"],"sourcesContent":[],"mappings":";;;;;iBA4BgB,qBAAA,UACL,uBAGL,wBAEC,cAAc,kBACd,cAAc,qCAClB;;AARH;;;;;;;;AAQ8B,iBAuBd,kBAAA,CAvBc,OAAA,EAwBnB,OAxBmB,EAAA,IAAA,EAAA,MAAA,EAAA,EAAA,EAAA,MAAA,EAAA,MAAA,EA2BpB,2BA3BoB,CAAA,EA4B3B,mCA5B2B,GAAA,SAAA"}
|
package/dist/index.cjs
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
|
-
const require_helpers_filters = require('./helpers/filters.cjs');
|
|
4
|
-
const require_helpers_options = require('./helpers/options.cjs');
|
|
5
|
-
const require_helpers_ast_utils = require('./helpers/ast-utils.cjs');
|
|
6
|
-
const require_helpers_create_plugin = require('./helpers/create-plugin.cjs');
|
|
7
|
-
const require_helpers_module_helpers = require('./helpers/module-helpers.cjs');
|
|
8
|
-
require('./helpers/index.cjs');
|
|
9
|
-
let __babel_core = require("@babel/core");
|
|
10
|
-
let __stryke_path_file_path_fns = require("@stryke/path/file-path-fns");
|
|
11
|
-
let __stryke_path_is_parent_path = require("@stryke/path/is-parent-path");
|
|
12
|
-
let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
13
|
-
let defu = require("defu");
|
|
14
|
-
defu = require_rolldown_runtime.__toESM(defu);
|
|
15
|
-
|
|
16
|
-
//#region src/index.ts
|
|
17
|
-
/**
|
|
18
|
-
* Babel plugin for Powerlines.
|
|
19
|
-
*
|
|
20
|
-
* @param options - The Babel plugin user configuration options.
|
|
21
|
-
* @returns A Powerlines plugin that integrates Babel transformations.
|
|
22
|
-
*/
|
|
23
|
-
const plugin = (options = {}) => {
|
|
24
|
-
return {
|
|
25
|
-
name: "babel",
|
|
26
|
-
config() {
|
|
27
|
-
if (!(0, __stryke_type_checks_is_set_object.isSetObject)(options)) return;
|
|
28
|
-
return { transform: { babel: options } };
|
|
29
|
-
},
|
|
30
|
-
configResolved: {
|
|
31
|
-
order: "pre",
|
|
32
|
-
handler() {
|
|
33
|
-
this.config.transform.babel = (0, defu.default)(this.config.transform.babel ?? {}, {
|
|
34
|
-
plugins: [],
|
|
35
|
-
presets: []
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
async transform(code, id) {
|
|
40
|
-
if ((0, __stryke_path_is_parent_path.isParentPath)(id, this.powerlinesPath) || code.includes("/* @powerlines-ignore */") || code.includes("/* @powerlines-disable */")) {
|
|
41
|
-
this.trace(`Skipping Babel transformation for: ${id}`);
|
|
42
|
-
return {
|
|
43
|
-
code,
|
|
44
|
-
id
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
const plugins = this.config.transform.babel.plugins.map((plugin$1) => require_helpers_options.resolveBabelPlugin(this, code, id, plugin$1)).filter((plugin$1, _, arr) => plugin$1 && !require_helpers_filters.isDuplicatePlugin(arr, plugin$1));
|
|
48
|
-
const presets = this.config.transform.babel.presets.map((preset) => require_helpers_options.resolveBabelPlugin(this, code, id, preset)).filter((preset, _, arr) => preset && !require_helpers_filters.isDuplicatePlugin(arr, preset));
|
|
49
|
-
if (Array.isArray(plugins) && plugins.length === 0 && Array.isArray(presets) && presets.length === 0) return {
|
|
50
|
-
code,
|
|
51
|
-
id
|
|
52
|
-
};
|
|
53
|
-
if (/^(?:m|c)?tsx?$/.test((0, __stryke_path_file_path_fns.findFileExtensionSafe)(id, { fullExtension: true })) && !require_helpers_filters.isDuplicatePlugin(plugins, "@babel/plugin-syntax-typescript") && !require_helpers_filters.isDuplicatePlugin(presets, "@babel/preset-typescript")) plugins.unshift(["@babel/plugin-syntax-typescript", { isTSX: (0, __stryke_path_file_path_fns.findFileExtension)(id) === "tsx" }]);
|
|
54
|
-
this.trace(`Running babel transformations with ${plugins.length} plugins and ${presets.length} presets for file: ${id}`);
|
|
55
|
-
const result = await (0, __babel_core.transformAsync)(code, {
|
|
56
|
-
highlightCode: true,
|
|
57
|
-
code: true,
|
|
58
|
-
ast: false,
|
|
59
|
-
cloneInputAst: false,
|
|
60
|
-
comments: true,
|
|
61
|
-
sourceType: "module",
|
|
62
|
-
configFile: false,
|
|
63
|
-
babelrc: false,
|
|
64
|
-
envName: this.config.mode,
|
|
65
|
-
caller: { name: this.config.framework },
|
|
66
|
-
...this.config.transform.babel ?? {},
|
|
67
|
-
filename: id,
|
|
68
|
-
plugins: plugins.map((plugin$1) => {
|
|
69
|
-
return Array.isArray(plugin$1) && plugin$1.length >= 2 ? [plugin$1[0], (0, defu.default)(plugin$1.length > 1 && plugin$1[1] ? plugin$1[1] : {}, { options })] : plugin$1;
|
|
70
|
-
}).filter(Boolean),
|
|
71
|
-
presets: presets.map((preset) => {
|
|
72
|
-
return Array.isArray(preset) && preset.length >= 2 ? [preset[0], (0, defu.default)(preset.length > 1 && preset[1] ? preset[1] : {}, { options })] : preset;
|
|
73
|
-
}).filter(Boolean)
|
|
74
|
-
});
|
|
75
|
-
if (!result?.code) throw new Error(`Powerlines - Babel plugin failed to compile ${id}`);
|
|
76
|
-
this.trace(`Completed babel transformations for file: ${id}`);
|
|
77
|
-
return {
|
|
78
|
-
code: result.code,
|
|
79
|
-
id
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
var src_default = plugin;
|
|
85
|
-
|
|
86
|
-
//#endregion
|
|
87
|
-
exports.addImport = require_helpers_module_helpers.addImport;
|
|
88
|
-
exports.addImportsToProgram = require_helpers_module_helpers.addImportsToProgram;
|
|
89
|
-
exports.addPluginFilter = require_helpers_filters.addPluginFilter;
|
|
90
|
-
exports.createBabelPlugin = require_helpers_create_plugin.createBabelPlugin;
|
|
91
|
-
exports.default = src_default;
|
|
92
|
-
exports.filterPluginByFileId = require_helpers_filters.filterPluginByFileId;
|
|
93
|
-
exports.findExport = require_helpers_module_helpers.findExport;
|
|
94
|
-
exports.generateFromAst = require_helpers_ast_utils.generateFromAst;
|
|
95
|
-
exports.getImport = require_helpers_module_helpers.getImport;
|
|
96
|
-
exports.getPluginName = require_helpers_filters.getPluginName;
|
|
97
|
-
exports.isDuplicatePlugin = require_helpers_filters.isDuplicatePlugin;
|
|
98
|
-
exports.isImportCall = require_helpers_module_helpers.isImportCall;
|
|
99
|
-
exports.listExports = require_helpers_module_helpers.listExports;
|
|
100
|
-
exports.listImports = require_helpers_module_helpers.listImports;
|
|
101
|
-
exports.parseAst = require_helpers_ast_utils.parseAst;
|
|
102
|
-
exports.plugin = plugin;
|
|
103
|
-
exports.resolveBabelPlugin = require_helpers_options.resolveBabelPlugin;
|
|
104
|
-
exports.resolvePluginFunction = require_helpers_options.resolvePluginFunction;
|
package/dist/index.d.cts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { GenerateFromAstOptions, GeneratorResult, __ΩGenerateFromAstOptions, generateFromAst, parseAst } from "./helpers/ast-utils.cjs";
|
|
2
|
-
import { createBabelPlugin } from "./helpers/create-plugin.cjs";
|
|
3
|
-
import { addPluginFilter, filterPluginByFileId, getPluginName, isDuplicatePlugin } from "./helpers/filters.cjs";
|
|
4
|
-
import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./helpers/module-helpers.cjs";
|
|
5
|
-
import { resolveBabelPlugin, resolvePluginFunction } from "./helpers/options.cjs";
|
|
6
|
-
import "./helpers/index.cjs";
|
|
7
|
-
import { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig } from "./types/plugin.cjs";
|
|
8
|
-
import "./types/index.cjs";
|
|
9
|
-
import { Plugin } from "powerlines/types/plugin";
|
|
10
|
-
|
|
11
|
-
//#region src/index.d.ts
|
|
12
|
-
/**
|
|
13
|
-
* Babel plugin for Powerlines.
|
|
14
|
-
*
|
|
15
|
-
* @param options - The Babel plugin user configuration options.
|
|
16
|
-
* @returns A Powerlines plugin that integrates Babel transformations.
|
|
17
|
-
*/
|
|
18
|
-
declare const plugin: <TContext extends BabelPluginContext>(options?: BabelPluginOptions) => Plugin<TContext>;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, GenerateFromAstOptions, GeneratorResult, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig, __ΩGenerateFromAstOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, plugin as default, plugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, isDuplicatePlugin, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolvePluginFunction };
|
|
21
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;cAyCa,0BAA2B,8BAC7B,uBA0HJ,OAAO"}
|
package/dist/types/index.cjs
DELETED
|
File without changes
|
package/dist/types/index.d.cts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig } from "./plugin.cjs";
|
|
2
|
-
export { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig };
|
package/dist/types/plugin.cjs
DELETED
|
File without changes
|
package/dist/types/plugin.d.cts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { PluginContext } from "powerlines/types/context";
|
|
2
|
-
import { BabelUserConfig, UserConfig } from "powerlines/types/config";
|
|
3
|
-
import { BabelResolvedConfig, ResolvedConfig } from "powerlines/types/resolved";
|
|
4
|
-
|
|
5
|
-
//#region src/types/plugin.d.ts
|
|
6
|
-
type BabelPluginOptions = Partial<BabelUserConfig>;
|
|
7
|
-
type BabelPluginUserConfig = UserConfig;
|
|
8
|
-
interface BabelPluginResolvedConfig extends ResolvedConfig {
|
|
9
|
-
transform: {
|
|
10
|
-
babel: BabelResolvedConfig;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
type BabelPluginContext<TResolvedConfig extends BabelPluginResolvedConfig = BabelPluginResolvedConfig> = PluginContext<TResolvedConfig>;
|
|
14
|
-
declare type __ΩBabelPluginOptions = any[];
|
|
15
|
-
declare type __ΩBabelPluginUserConfig = any[];
|
|
16
|
-
declare type __ΩBabelPluginResolvedConfig = any[];
|
|
17
|
-
declare type __ΩBabelPluginContext = any[];
|
|
18
|
-
//#endregion
|
|
19
|
-
export { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig, __ΩBabelPluginContext, __ΩBabelPluginOptions, __ΩBabelPluginResolvedConfig, __ΩBabelPluginUserConfig };
|
|
20
|
-
//# sourceMappingURL=plugin.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.cts","names":[],"sources":["../../src/types/plugin.ts"],"sourcesContent":[],"mappings":";;;;;KAsBY,kBAAA,GAAqB,QAAQ;KAE7B,qBAAA,GAAwB;AAFxB,UAIK,yBAAA,SAAkC,cAJX,CAAA;EAE5B,SAAA,EAAA;IAEK,KAAA,EAEN,mBAFgC;EAM/B,CAAA;;AAC0C,KAD1C,kBAC0C,CAAA,wBAA5B,yBAA4B,GAAA,yBAAA,CAAA,GAClD,aADkD,CACpC,eADoC,CAAA;AACpC,qCAAA,GAAA,EAAA;AAAd,wCAAA,GAAA,EAAA;AAAa,4CAAA,GAAA,EAAA"}
|