@powerlines/plugin-babel 0.13.71 → 0.13.72
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/{filters-Rm2dAJYH.d.cts → filters-Bf8O8lmm.d.cts} +4 -4
- package/dist/filters-Bf8O8lmm.d.cts.map +1 -0
- package/dist/{filters-jhxE0J9i.d.mts → filters-DQ9zgW82.d.mts} +4 -4
- package/dist/filters-DQ9zgW82.d.mts.map +1 -0
- package/dist/helpers/filters.cjs +4 -4
- package/dist/helpers/filters.d.cts +2 -2
- package/dist/helpers/filters.d.mts +2 -2
- package/dist/helpers/filters.mjs +3 -3
- package/dist/helpers/filters.mjs.map +1 -1
- package/dist/helpers/index.cjs +2 -2
- package/dist/helpers/index.d.cts +2 -2
- package/dist/helpers/index.d.mts +2 -2
- package/dist/helpers/index.mjs +2 -2
- package/dist/helpers/options.cjs +2 -2
- package/dist/helpers/options.mjs +3 -3
- package/dist/helpers/options.mjs.map +1 -1
- package/dist/index.cjs +9 -5
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +9 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/dist/filters-Rm2dAJYH.d.cts.map +0 -1
- package/dist/filters-jhxE0J9i.d.mts.map +0 -1
|
@@ -10,7 +10,7 @@ declare function getPluginName(plugin?: BabelTransformPluginOptions | string | f
|
|
|
10
10
|
* @param plugin - The Babel plugin to check for duplicates.
|
|
11
11
|
* @returns True if the plugin is a duplicate, false otherwise.
|
|
12
12
|
*/
|
|
13
|
-
declare function
|
|
13
|
+
declare function includesPlugin<T extends BabelTransformPluginOptions | ResolvedBabelTransformPluginOptions>(plugins: T[], plugin: T): boolean;
|
|
14
14
|
/**
|
|
15
15
|
* Check if a Babel preset is a duplicate of another preset in the list.
|
|
16
16
|
*
|
|
@@ -18,7 +18,7 @@ declare function isDuplicatePlugin<T extends BabelTransformPluginOptions | Resol
|
|
|
18
18
|
* @param preset - The Babel preset to check for duplicates.
|
|
19
19
|
* @returns True if the preset is a duplicate, false otherwise.
|
|
20
20
|
*/
|
|
21
|
-
declare function
|
|
21
|
+
declare function includesPreset<T extends BabelTransformPresetOptions | ResolvedBabelTransformPresetOptions>(presets: T[], preset: T): boolean;
|
|
22
22
|
/**
|
|
23
23
|
* Filters a Babel plugin by its runtime ID.
|
|
24
24
|
*
|
|
@@ -47,5 +47,5 @@ declare function addPluginFilter(context: Context, plugins: BabelTransformPlugin
|
|
|
47
47
|
*/
|
|
48
48
|
declare function addPluginFilter(context: Context, plugin: BabelTransformPlugin | BabelTransformPluginOptions, filter: NonNullable<BabelTransformPluginFilter>): BabelTransformPluginOptions;
|
|
49
49
|
//#endregion
|
|
50
|
-
export {
|
|
51
|
-
//# sourceMappingURL=filters-
|
|
50
|
+
export { includesPreset as a, includesPlugin as i, filterPluginByFileId as n, getPluginName as r, addPluginFilter as t };
|
|
51
|
+
//# sourceMappingURL=filters-Bf8O8lmm.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters-Bf8O8lmm.d.cts","names":[],"sources":["../src/helpers/filters.ts"],"mappings":";;;;iBA+BgB,aAAA,CACd,MAAA,GACI,2BAA2B,kCAItB,IAAA;;AANX;;;;;;iBA2BgB,cAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,IAAK,MAAA,EAAQ,CAAA;;AAtBT;AAoBf;;;;;iBAoBgB,cAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,IAAK,MAAA,EAAQ,CAAA;;;;;;;;iBAkBR,oBAAA,kBAAsC,OAAA,GAAU,OAAA,CAAA,CAC9D,OAAA,EAAS,QAAA,EACT,MAAA,WACC,0BAAA;;;;AAzCsB;AAkBzB;;;;;iBA2CgB,eAAA,CACd,OAAA,EAAS,OAAA,EACT,OAAA,EAAS,2BAAA,IACT,MAAA,EAAQ,0BAAA,qBACR,IAAA,WACC,2BAAA;;;;;;;;;iBAUa,eAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,EAAQ,oBAAA,GAAuB,2BAAA,EAC/B,MAAA,EAAQ,WAAA,CAAY,0BAAA,IACnB,2BAAA"}
|
|
@@ -10,7 +10,7 @@ declare function getPluginName(plugin?: BabelTransformPluginOptions | string | f
|
|
|
10
10
|
* @param plugin - The Babel plugin to check for duplicates.
|
|
11
11
|
* @returns True if the plugin is a duplicate, false otherwise.
|
|
12
12
|
*/
|
|
13
|
-
declare function
|
|
13
|
+
declare function includesPlugin<T extends BabelTransformPluginOptions | ResolvedBabelTransformPluginOptions>(plugins: T[], plugin: T): boolean;
|
|
14
14
|
/**
|
|
15
15
|
* Check if a Babel preset is a duplicate of another preset in the list.
|
|
16
16
|
*
|
|
@@ -18,7 +18,7 @@ declare function isDuplicatePlugin<T extends BabelTransformPluginOptions | Resol
|
|
|
18
18
|
* @param preset - The Babel preset to check for duplicates.
|
|
19
19
|
* @returns True if the preset is a duplicate, false otherwise.
|
|
20
20
|
*/
|
|
21
|
-
declare function
|
|
21
|
+
declare function includesPreset<T extends BabelTransformPresetOptions | ResolvedBabelTransformPresetOptions>(presets: T[], preset: T): boolean;
|
|
22
22
|
/**
|
|
23
23
|
* Filters a Babel plugin by its runtime ID.
|
|
24
24
|
*
|
|
@@ -47,5 +47,5 @@ declare function addPluginFilter(context: Context, plugins: BabelTransformPlugin
|
|
|
47
47
|
*/
|
|
48
48
|
declare function addPluginFilter(context: Context, plugin: BabelTransformPlugin | BabelTransformPluginOptions, filter: NonNullable<BabelTransformPluginFilter>): BabelTransformPluginOptions;
|
|
49
49
|
//#endregion
|
|
50
|
-
export {
|
|
51
|
-
//# sourceMappingURL=filters-
|
|
50
|
+
export { includesPreset as a, includesPlugin as i, filterPluginByFileId as n, getPluginName as r, addPluginFilter as t };
|
|
51
|
+
//# sourceMappingURL=filters-DQ9zgW82.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filters-DQ9zgW82.d.mts","names":[],"sources":["../src/helpers/filters.ts"],"mappings":";;;;iBA+BgB,aAAA,CACd,MAAA,GACI,2BAA2B,kCAItB,IAAA;;AANX;;;;;;iBA2BgB,cAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,IAAK,MAAA,EAAQ,CAAA;;AAtBT;AAoBf;;;;;iBAoBgB,cAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,IAAK,MAAA,EAAQ,CAAA;;;;;;;;iBAkBR,oBAAA,kBAAsC,OAAA,GAAU,OAAA,CAAA,CAC9D,OAAA,EAAS,QAAA,EACT,MAAA,WACC,0BAAA;;;;AAzCsB;AAkBzB;;;;;iBA2CgB,eAAA,CACd,OAAA,EAAS,OAAA,EACT,OAAA,EAAS,2BAAA,IACT,MAAA,EAAQ,0BAAA,qBACR,IAAA,WACC,2BAAA;;;;;;;;;iBAUa,eAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,EAAQ,oBAAA,GAAuB,2BAAA,EAC/B,MAAA,EAAQ,WAAA,CAAY,0BAAA,IACnB,2BAAA"}
|
package/dist/helpers/filters.cjs
CHANGED
|
@@ -14,7 +14,7 @@ function getPluginName(plugin) {
|
|
|
14
14
|
* @param plugin - The Babel plugin to check for duplicates.
|
|
15
15
|
* @returns True if the plugin is a duplicate, false otherwise.
|
|
16
16
|
*/
|
|
17
|
-
function
|
|
17
|
+
function includesPlugin(plugins, plugin) {
|
|
18
18
|
return !!(getPluginName(plugin) && plugins.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(plugin)));
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
@@ -24,7 +24,7 @@ function isDuplicatePlugin(plugins, plugin) {
|
|
|
24
24
|
* @param preset - The Babel preset to check for duplicates.
|
|
25
25
|
* @returns True if the preset is a duplicate, false otherwise.
|
|
26
26
|
*/
|
|
27
|
-
function
|
|
27
|
+
function includesPreset(presets, preset) {
|
|
28
28
|
return !!(getPluginName(preset) && presets.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(preset)));
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
@@ -69,5 +69,5 @@ function addPluginFilter(context, pluginOrPlugins, filter, name) {
|
|
|
69
69
|
exports.addPluginFilter = addPluginFilter;
|
|
70
70
|
exports.filterPluginByFileId = filterPluginByFileId;
|
|
71
71
|
exports.getPluginName = getPluginName;
|
|
72
|
-
exports.
|
|
73
|
-
exports.
|
|
72
|
+
exports.includesPlugin = includesPlugin;
|
|
73
|
+
exports.includesPreset = includesPreset;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { addPluginFilter, filterPluginByFileId, getPluginName,
|
|
1
|
+
import { a as includesPreset, i as includesPlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "../filters-Bf8O8lmm.cjs";
|
|
2
|
+
export { addPluginFilter, filterPluginByFileId, getPluginName, includesPlugin, includesPreset };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { addPluginFilter, filterPluginByFileId, getPluginName,
|
|
1
|
+
import { a as includesPreset, i as includesPlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "../filters-DQ9zgW82.mjs";
|
|
2
|
+
export { addPluginFilter, filterPluginByFileId, getPluginName, includesPlugin, includesPreset };
|
package/dist/helpers/filters.mjs
CHANGED
|
@@ -13,7 +13,7 @@ function getPluginName(plugin) {
|
|
|
13
13
|
* @param plugin - The Babel plugin to check for duplicates.
|
|
14
14
|
* @returns True if the plugin is a duplicate, false otherwise.
|
|
15
15
|
*/
|
|
16
|
-
function
|
|
16
|
+
function includesPlugin(plugins, plugin) {
|
|
17
17
|
return !!(getPluginName(plugin) && plugins.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(plugin)));
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -23,7 +23,7 @@ function isDuplicatePlugin(plugins, plugin) {
|
|
|
23
23
|
* @param preset - The Babel preset to check for duplicates.
|
|
24
24
|
* @returns True if the preset is a duplicate, false otherwise.
|
|
25
25
|
*/
|
|
26
|
-
function
|
|
26
|
+
function includesPreset(presets, preset) {
|
|
27
27
|
return !!(getPluginName(preset) && presets.some((existing) => Array.isArray(existing) && getPluginName(existing[0]) === getPluginName(preset)));
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
@@ -65,5 +65,5 @@ function addPluginFilter(context, pluginOrPlugins, filter, name) {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
//#endregion
|
|
68
|
-
export { addPluginFilter, filterPluginByFileId, getPluginName,
|
|
68
|
+
export { addPluginFilter, filterPluginByFileId, getPluginName, includesPlugin, includesPreset };
|
|
69
69
|
//# sourceMappingURL=filters.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filters.mjs","names":[],"sources":["../../src/helpers/filters.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { Context } from \"powerlines\";\nimport {\n BabelTransformPlugin,\n BabelTransformPluginFilter,\n BabelTransformPluginOptions,\n BabelTransformPresetOptions,\n ResolvedBabelTransformPluginOptions,\n ResolvedBabelTransformPresetOptions\n} from \"../types/config\";\n\nexport function getPluginName(\n plugin?:\n | BabelTransformPluginOptions\n | string\n | false\n | object\n | ((...args: any[]) => any)\n | undefined\n): string | undefined {\n return isSetString(plugin)\n ? plugin\n : Array.isArray(plugin) && plugin.length > 0\n ? getPluginName(plugin[0])\n : (plugin as BabelTransformPlugin).$$name ||\n (plugin as BabelTransformPlugin).name\n ? (plugin as BabelTransformPlugin).$$name ||\n (plugin as BabelTransformPlugin).name\n : undefined;\n}\n\n/**\n * Check if a Babel plugin is a duplicate of another plugin in the list.\n *\n * @param plugins - The list of existing Babel plugins.\n * @param plugin - The Babel plugin to check for duplicates.\n * @returns True if the plugin is a duplicate, false otherwise.\n */\nexport function
|
|
1
|
+
{"version":3,"file":"filters.mjs","names":[],"sources":["../../src/helpers/filters.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport { isObject } from \"@stryke/type-checks/is-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { Context } from \"powerlines\";\nimport {\n BabelTransformPlugin,\n BabelTransformPluginFilter,\n BabelTransformPluginOptions,\n BabelTransformPresetOptions,\n ResolvedBabelTransformPluginOptions,\n ResolvedBabelTransformPresetOptions\n} from \"../types/config\";\n\nexport function getPluginName(\n plugin?:\n | BabelTransformPluginOptions\n | string\n | false\n | object\n | ((...args: any[]) => any)\n | undefined\n): string | undefined {\n return isSetString(plugin)\n ? plugin\n : Array.isArray(plugin) && plugin.length > 0\n ? getPluginName(plugin[0])\n : (plugin as BabelTransformPlugin).$$name ||\n (plugin as BabelTransformPlugin).name\n ? (plugin as BabelTransformPlugin).$$name ||\n (plugin as BabelTransformPlugin).name\n : undefined;\n}\n\n/**\n * Check if a Babel plugin is a duplicate of another plugin in the list.\n *\n * @param plugins - The list of existing Babel plugins.\n * @param plugin - The Babel plugin to check for duplicates.\n * @returns True if the plugin is a duplicate, false otherwise.\n */\nexport function includesPlugin<\n T extends BabelTransformPluginOptions | ResolvedBabelTransformPluginOptions\n>(plugins: T[], plugin: T): boolean {\n return !!(\n getPluginName(plugin) &&\n plugins.some(\n existing =>\n Array.isArray(existing) &&\n getPluginName(existing[0]) === getPluginName(plugin)\n )\n );\n}\n\n/**\n * Check if a Babel preset is a duplicate of another preset in the list.\n *\n * @param presets - The list of existing Babel presets.\n * @param preset - The Babel preset to check for duplicates.\n * @returns True if the preset is a duplicate, false otherwise.\n */\nexport function includesPreset<\n T extends BabelTransformPresetOptions | ResolvedBabelTransformPresetOptions\n>(presets: T[], preset: T): boolean {\n return !!(\n getPluginName(preset) &&\n presets.some(\n existing =>\n Array.isArray(existing) &&\n getPluginName(existing[0]) === getPluginName(preset)\n )\n );\n}\n\n/**\n * Filters a Babel plugin by its runtime ID.\n *\n * @param context - The context in which the filter is applied.\n * @param fileId - The file ID to filter by.\n * @returns A filter function that checks if a plugin's ID matches the runtime ID.\n */\nexport function filterPluginByFileId<TContext extends Context = Context>(\n context: TContext,\n fileId: string\n): BabelTransformPluginFilter {\n return (code: string, id: string): boolean =>\n fileId !== id &&\n context.fs.ids[fileId] !== id &&\n fileId !== context.fs.ids[id] &&\n context.fs.ids[fileId] !== context.fs.ids[id] &&\n context.fs.paths[fileId] !== id &&\n fileId !== context.fs.paths[id] &&\n context.fs.paths[fileId] !== context.fs.paths[id];\n}\n\n/**\n * Adds a filter to a Babel plugin or a list of Babel plugins.\n *\n * @param context - The context in which the plugin is being added.\n * @param plugins - The Babel plugins to add the filter to.\n * @param filter - The filter function to apply to the plugins.\n * @param name - The name of the plugin to add the filter to.\n * @returns The updated list of Babel plugins with the filter applied.\n */\nexport function addPluginFilter(\n context: Context,\n plugins: BabelTransformPluginOptions[],\n filter: BabelTransformPluginFilter | null | undefined,\n name: string\n): BabelTransformPluginOptions[];\n\n/**\n * Adds a filter to a Babel plugin or a list of Babel plugins.\n *\n * @param context - The context in which the plugin is being added.\n * @param plugin - The Babel plugin to add the filter to.\n * @param filter - The filter function to apply to the plugin.\n * @returns The updated Babel plugin with the filter applied.\n */\nexport function addPluginFilter(\n context: Context,\n plugin: BabelTransformPlugin | BabelTransformPluginOptions,\n filter: NonNullable<BabelTransformPluginFilter>\n): BabelTransformPluginOptions;\n\n/**\n * Adds a filter to a Babel plugin or a list of Babel plugins.\n *\n * @param context - The context in which the plugin is being added.\n * @param pluginOrPlugins - The Babel plugin or plugins to add the filter to.\n * @param filter - The filter function to apply to the plugins.\n * @param name - The name of the plugin to add the filter to.\n * @returns The updated list of Babel plugins with the filter applied.\n */\nexport function addPluginFilter<\n T extends\n | BabelTransformPlugin\n | BabelTransformPluginOptions\n | BabelTransformPluginOptions[]\n>(\n context: Context,\n pluginOrPlugins: T,\n filter: NonNullable<BabelTransformPluginFilter>,\n name?: string\n): T extends BabelTransformPluginOptions[]\n ? BabelTransformPluginOptions[]\n : BabelTransformPluginOptions {\n if (\n !Array.isArray(pluginOrPlugins) ||\n (!pluginOrPlugins.some(plugin => Array.isArray(plugin)) &&\n pluginOrPlugins.length < 4 &&\n pluginOrPlugins.length > 0 &&\n (isSetString(pluginOrPlugins[0]) ||\n isFunction(pluginOrPlugins[0]) ||\n (pluginOrPlugins.length > 1 && isObject(pluginOrPlugins[1])) ||\n (pluginOrPlugins.length > 2 && isObject(pluginOrPlugins[2]))))\n ) {\n if (Array.isArray(pluginOrPlugins)) {\n return [\n pluginOrPlugins[0],\n pluginOrPlugins.length > 1 ? pluginOrPlugins[1] : {},\n {\n filter: (code, id) =>\n filter(code, id) &&\n (pluginOrPlugins.length < 3 ||\n !isFunction(pluginOrPlugins[2]) ||\n (pluginOrPlugins[2] as BabelTransformPluginFilter)?.(code, id))\n }\n ] as any;\n }\n return [\n pluginOrPlugins,\n {},\n {\n filter\n }\n ] as any;\n }\n\n if (!name) {\n throw new Error(\n \"No name was provided to \\`addPluginFilter\\`, could not find babel plugin without it.\"\n );\n }\n\n const foundIndex = pluginOrPlugins.findIndex(\n plugin => getPluginName(plugin)?.toLowerCase() === name.toLowerCase()\n );\n if (foundIndex > -1) {\n pluginOrPlugins[foundIndex] = addPluginFilter(\n context,\n pluginOrPlugins[foundIndex] as BabelTransformPluginOptions[],\n filter,\n name\n );\n }\n\n return pluginOrPlugins as any;\n}\n"],"mappings":";;;;;AA+BA,SAAgB,cACd,QAOoB;CACpB,OAAO,YAAY,MAAM,IACrB,SACA,MAAM,QAAQ,MAAM,KAAK,OAAO,SAAS,IACvC,cAAc,OAAO,EAAE,IACtB,OAAgC,UAC9B,OAAgC,OAChC,OAAgC,UAChC,OAAgC,OACjC;AACV;;;;;;;;AASA,SAAgB,eAEd,SAAc,QAAoB;CAClC,OAAO,CAAC,EACN,cAAc,MAAM,KACpB,QAAQ,MACN,aACE,MAAM,QAAQ,QAAQ,KACtB,cAAc,SAAS,EAAE,MAAM,cAAc,MAAM,CACvD;AAEJ;;;;;;;;AASA,SAAgB,eAEd,SAAc,QAAoB;CAClC,OAAO,CAAC,EACN,cAAc,MAAM,KACpB,QAAQ,MACN,aACE,MAAM,QAAQ,QAAQ,KACtB,cAAc,SAAS,EAAE,MAAM,cAAc,MAAM,CACvD;AAEJ;;;;;;;;AASA,SAAgB,qBACd,SACA,QAC4B;CAC5B,QAAQ,MAAc,OACpB,WAAW,MACX,QAAQ,GAAG,IAAI,YAAY,MAC3B,WAAW,QAAQ,GAAG,IAAI,OAC1B,QAAQ,GAAG,IAAI,YAAY,QAAQ,GAAG,IAAI,OAC1C,QAAQ,GAAG,MAAM,YAAY,MAC7B,WAAW,QAAQ,GAAG,MAAM,OAC5B,QAAQ,GAAG,MAAM,YAAY,QAAQ,GAAG,MAAM;AAClD;;;;;;;;;;AAyCA,SAAgB,gBAMd,SACA,iBACA,QACA,MAG8B;CAC9B,IACE,CAAC,MAAM,QAAQ,eAAe,KAC7B,CAAC,gBAAgB,MAAK,WAAU,MAAM,QAAQ,MAAM,CAAC,KACpD,gBAAgB,SAAS,KACzB,gBAAgB,SAAS,MACxB,YAAY,gBAAgB,EAAE,KAC7B,WAAW,gBAAgB,EAAE,KAC5B,gBAAgB,SAAS,KAAK,SAAS,gBAAgB,EAAE,KACzD,gBAAgB,SAAS,KAAK,SAAS,gBAAgB,EAAE,IAC9D;EACA,IAAI,MAAM,QAAQ,eAAe,GAC/B,OAAO;GACL,gBAAgB;GAChB,gBAAgB,SAAS,IAAI,gBAAgB,KAAK,CAAC;GACnD,EACE,SAAS,MAAM,OACb,OAAO,MAAM,EAAE,MACd,gBAAgB,SAAS,KACxB,CAAC,WAAW,gBAAgB,EAAE,KAC7B,gBAAgB,KAAoC,MAAM,EAAE,GACnE;EACF;EAEF,OAAO;GACL;GACA,CAAC;GACD,EACE,OACF;EACF;CACF;CAEA,IAAI,CAAC,MACH,MAAM,IAAI,MACR,oFACF;CAGF,MAAM,aAAa,gBAAgB,WACjC,WAAU,cAAc,MAAM,GAAG,YAAY,MAAM,KAAK,YAAY,CACtE;CACA,IAAI,aAAa,IACf,gBAAgB,cAAc,gBAC5B,SACA,gBAAgB,aAChB,QACA,IACF;CAGF,OAAO;AACT"}
|
package/dist/helpers/index.cjs
CHANGED
|
@@ -16,8 +16,8 @@ exports.getImport = require_helpers_module_helpers.getImport;
|
|
|
16
16
|
exports.getPluginName = require_helpers_filters.getPluginName;
|
|
17
17
|
exports.getUniquePlugins = require_helpers_options.getUniquePlugins;
|
|
18
18
|
exports.getUniquePresets = require_helpers_options.getUniquePresets;
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
19
|
+
exports.includesPlugin = require_helpers_filters.includesPlugin;
|
|
20
|
+
exports.includesPreset = require_helpers_filters.includesPreset;
|
|
21
21
|
exports.isImportCall = require_helpers_module_helpers.isImportCall;
|
|
22
22
|
exports.listExports = require_helpers_module_helpers.listExports;
|
|
23
23
|
exports.listImports = require_helpers_module_helpers.listImports;
|
package/dist/helpers/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as parseAst, n as GeneratorResult, r as generateFromAst, t as GenerateFromAstOptions } from "../ast-utils-Bh-E-kGU.cjs";
|
|
2
2
|
import { t as createBabelPlugin } from "../create-plugin-BCjqxmR3.cjs";
|
|
3
|
-
import { a as
|
|
3
|
+
import { a as includesPreset, i as includesPlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "../filters-Bf8O8lmm.cjs";
|
|
4
4
|
import { a as isImportCall, i as getImport, n as addImportsToProgram, o as listExports, r as findExport, s as listImports, t as addImport } from "../module-helpers-BWcDQR8b.cjs";
|
|
5
5
|
import { a as resolvePluginFunction, i as resolveBabelPreset, n as getUniquePresets, o as resolvePresetFunction, r as resolveBabelPlugin, t as getUniquePlugins } from "../options-CyU9E_re.cjs";
|
|
6
|
-
export { GenerateFromAstOptions, type GeneratorResult, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets,
|
|
6
|
+
export { GenerateFromAstOptions, type GeneratorResult, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets, includesPlugin, includesPreset, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction };
|
package/dist/helpers/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { i as parseAst, n as GeneratorResult, r as generateFromAst, t as GenerateFromAstOptions } from "../ast-utils-Bh-E-kGU.mjs";
|
|
2
2
|
import { t as createBabelPlugin } from "../create-plugin-B53ThfQZ.mjs";
|
|
3
|
-
import { a as
|
|
3
|
+
import { a as includesPreset, i as includesPlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "../filters-DQ9zgW82.mjs";
|
|
4
4
|
import { a as isImportCall, i as getImport, n as addImportsToProgram, o as listExports, r as findExport, s as listImports, t as addImport } from "../module-helpers-bI0F0O26.mjs";
|
|
5
5
|
import { a as resolvePluginFunction, i as resolveBabelPreset, n as getUniquePresets, o as resolvePresetFunction, r as resolveBabelPlugin, t as getUniquePlugins } from "../options-BumyQlgw.mjs";
|
|
6
|
-
export { GenerateFromAstOptions, type GeneratorResult, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets,
|
|
6
|
+
export { GenerateFromAstOptions, type GeneratorResult, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets, includesPlugin, includesPreset, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction };
|
package/dist/helpers/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { addPluginFilter, filterPluginByFileId, getPluginName,
|
|
1
|
+
import { addPluginFilter, filterPluginByFileId, getPluginName, includesPlugin, includesPreset } from "./filters.mjs";
|
|
2
2
|
import { getUniquePlugins, getUniquePresets, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction } from "./options.mjs";
|
|
3
3
|
import { generateFromAst, parseAst } from "./ast-utils.mjs";
|
|
4
4
|
import { createBabelPlugin } from "./create-plugin.mjs";
|
|
5
5
|
import { addImport, addImportsToProgram, findExport, getImport, isImportCall, listExports, listImports } from "./module-helpers.mjs";
|
|
6
6
|
|
|
7
|
-
export { addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets,
|
|
7
|
+
export { addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets, includesPlugin, includesPreset, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction };
|
package/dist/helpers/options.cjs
CHANGED
|
@@ -90,7 +90,7 @@ function resolveBabelPreset(context, code, id, preset) {
|
|
|
90
90
|
*/
|
|
91
91
|
function getUniquePlugins(plugins) {
|
|
92
92
|
return plugins.reduce((ret, plugin) => {
|
|
93
|
-
if (plugin && !require_helpers_filters.
|
|
93
|
+
if (plugin && !require_helpers_filters.includesPlugin(ret, plugin)) ret.push(plugin);
|
|
94
94
|
return ret;
|
|
95
95
|
}, []);
|
|
96
96
|
}
|
|
@@ -102,7 +102,7 @@ function getUniquePlugins(plugins) {
|
|
|
102
102
|
*/
|
|
103
103
|
function getUniquePresets(presets) {
|
|
104
104
|
return presets.reduce((ret, preset) => {
|
|
105
|
-
if (preset && !require_helpers_filters.
|
|
105
|
+
if (preset && !require_helpers_filters.includesPreset(ret, preset)) ret.push(preset);
|
|
106
106
|
return ret;
|
|
107
107
|
}, []);
|
|
108
108
|
}
|
package/dist/helpers/options.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getPluginName,
|
|
1
|
+
import { getPluginName, includesPlugin, includesPreset } from "./filters.mjs";
|
|
2
2
|
import { isFunction } from "@stryke/type-checks/is-function";
|
|
3
3
|
import chalk from "chalk";
|
|
4
4
|
|
|
@@ -87,7 +87,7 @@ function resolveBabelPreset(context, code, id, preset) {
|
|
|
87
87
|
*/
|
|
88
88
|
function getUniquePlugins(plugins) {
|
|
89
89
|
return plugins.reduce((ret, plugin) => {
|
|
90
|
-
if (plugin && !
|
|
90
|
+
if (plugin && !includesPlugin(ret, plugin)) ret.push(plugin);
|
|
91
91
|
return ret;
|
|
92
92
|
}, []);
|
|
93
93
|
}
|
|
@@ -99,7 +99,7 @@ function getUniquePlugins(plugins) {
|
|
|
99
99
|
*/
|
|
100
100
|
function getUniquePresets(presets) {
|
|
101
101
|
return presets.reduce((ret, preset) => {
|
|
102
|
-
if (preset && !
|
|
102
|
+
if (preset && !includesPreset(ret, preset)) ret.push(preset);
|
|
103
103
|
return ret;
|
|
104
104
|
}, []);
|
|
105
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.mjs","names":[],"sources":["../../src/helpers/options.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport {\n PluginItem,\n PluginTarget,\n PresetItem,\n PresetTarget\n} from \"@babel/core\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport chalk from \"chalk\";\nimport { Context } from \"powerlines\";\nimport {\n BabelTransformPluginOptions,\n BabelTransformPresetOptions,\n ResolvedBabelTransformPluginOptions,\n ResolvedBabelTransformPresetOptions\n} from \"../types/config\";\nimport { getPluginName,
|
|
1
|
+
{"version":3,"file":"options.mjs","names":[],"sources":["../../src/helpers/options.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport {\n PluginItem,\n PluginTarget,\n PresetItem,\n PresetTarget\n} from \"@babel/core\";\nimport { isFunction } from \"@stryke/type-checks/is-function\";\nimport chalk from \"chalk\";\nimport { Context } from \"powerlines\";\nimport {\n BabelTransformPluginOptions,\n BabelTransformPresetOptions,\n ResolvedBabelTransformPluginOptions,\n ResolvedBabelTransformPresetOptions\n} from \"../types/config\";\nimport { getPluginName, includesPlugin, includesPreset } from \"./filters\";\n\nexport function resolvePluginFunction(\n context: Context,\n plugin:\n | any\n | PluginTarget\n | any[]\n | [PluginTarget, PluginItem]\n | [PluginTarget, PluginItem, string | undefined]\n): BabelTransformPluginOptions {\n try {\n return Array.isArray(plugin) && plugin.length > 0 && plugin[0]\n ? isFunction(plugin[0])\n ? plugin[0](context)\n : plugin[0]\n : isFunction(plugin)\n ? plugin(context)\n : plugin;\n } catch {\n return plugin[0];\n }\n}\n\nexport function resolvePresetFunction(\n context: Context,\n preset:\n | any\n | PresetTarget\n | any[]\n | [PresetTarget, PresetItem]\n | [PresetTarget, PresetItem, string | undefined]\n): BabelTransformPresetOptions {\n try {\n return Array.isArray(preset) && preset.length > 0 && preset[0]\n ? isFunction(preset[0])\n ? preset[0](context)\n : preset[0]\n : isFunction(preset)\n ? preset(context)\n : preset;\n } catch {\n return preset[0];\n }\n}\n\n/**\n * Resolve the [Babel](https://babeljs.io/) plugin.\n *\n * @param context - The context for the transformation.\n * @param code - The code to be transformed.\n * @param id - The ID of the source file.\n * @param plugin - The Babel plugin to resolve.\n * @returns The resolved Babel plugin options, or undefined if the plugin is filtered out.\n */\nexport function resolveBabelPlugin(\n context: Context,\n code: string,\n id: string,\n plugin: BabelTransformPluginOptions\n): ResolvedBabelTransformPluginOptions | undefined {\n if (Array.isArray(plugin) && plugin.length > 0 && plugin[0]) {\n if (\n plugin.length > 2 &&\n plugin[2] &&\n isFunction(plugin[2]) &&\n !plugin[2](code, id)\n ) {\n context.trace(\n `Skipping filtered Babel plugin ${chalk.bold.cyanBright(\n getPluginName(plugin) || \"unnamed\"\n )} for ${id}`\n );\n\n return undefined;\n }\n\n return (\n plugin.length > 2\n ? [resolvePluginFunction(context, plugin), plugin[1], plugin[2]]\n : [resolvePluginFunction(context, plugin), plugin[1], null]\n ) as ResolvedBabelTransformPluginOptions;\n }\n\n return [\n resolvePluginFunction(context, plugin),\n {},\n null\n ] as ResolvedBabelTransformPluginOptions;\n}\n\n/**\n * Resolve the [Babel](https://babeljs.io/) preset.\n *\n * @param context - The context for the transformation.\n * @param code - The code to be transformed.\n * @param id - The ID of the source file.\n * @param preset - The Babel preset to resolve.\n * @returns The resolved Babel preset options, or undefined if the preset is filtered out.\n */\nexport function resolveBabelPreset(\n context: Context,\n code: string,\n id: string,\n preset: BabelTransformPresetOptions\n): ResolvedBabelTransformPresetOptions | undefined {\n if (Array.isArray(preset) && preset.length > 0 && preset[0]) {\n if (\n preset.length > 2 &&\n preset[2] &&\n isFunction(preset[2]) &&\n !preset[2](code, id)\n ) {\n context.trace(\n `Skipping filtered Babel preset ${chalk.bold.cyanBright(\n getPluginName(preset) || \"unnamed\"\n )} for ${id}`\n );\n\n return undefined;\n }\n\n return (\n preset.length > 2\n ? [resolvePresetFunction(context, preset), preset[1], preset[2]]\n : [resolvePresetFunction(context, preset), preset[1], null]\n ) as ResolvedBabelTransformPresetOptions;\n }\n\n return [\n resolvePresetFunction(context, preset),\n {},\n null\n ] as ResolvedBabelTransformPresetOptions;\n}\n\n/**\n * Get a list of unique Babel plugins, filtering out duplicates based on their names.\n *\n * @param plugins - The list of Babel plugins to filter for uniqueness.\n * @returns A list of unique Babel plugins.\n */\nexport function getUniquePlugins<\n T extends BabelTransformPluginOptions | ResolvedBabelTransformPluginOptions\n>(plugins: T[]): T[] {\n return plugins.reduce((ret: T[], plugin: T) => {\n if (plugin && !includesPlugin(ret, plugin)) {\n ret.push(plugin);\n }\n\n return ret;\n }, []);\n}\n\n/**\n * Get a list of unique Babel presets, filtering out duplicates based on their names.\n *\n * @param presets - The list of Babel presets to filter for uniqueness.\n * @returns A list of unique Babel presets.\n */\nexport function getUniquePresets<\n T extends BabelTransformPresetOptions | ResolvedBabelTransformPresetOptions\n>(presets: T[]): T[] {\n return presets.reduce((ret: T[], preset: T) => {\n if (preset && !includesPreset(ret, preset)) {\n ret.push(preset);\n }\n\n return ret;\n }, []);\n}\n"],"mappings":";;;;;AAmCA,SAAgB,sBACd,SACA,QAM6B;CAC7B,IAAI;EACF,OAAO,MAAM,QAAQ,MAAM,KAAK,OAAO,SAAS,KAAK,OAAO,KACxD,WAAW,OAAO,EAAE,IAClB,OAAO,GAAG,OAAO,IACjB,OAAO,KACT,WAAW,MAAM,IACf,OAAO,OAAO,IACd;CACR,QAAQ;EACN,OAAO,OAAO;CAChB;AACF;AAEA,SAAgB,sBACd,SACA,QAM6B;CAC7B,IAAI;EACF,OAAO,MAAM,QAAQ,MAAM,KAAK,OAAO,SAAS,KAAK,OAAO,KACxD,WAAW,OAAO,EAAE,IAClB,OAAO,GAAG,OAAO,IACjB,OAAO,KACT,WAAW,MAAM,IACf,OAAO,OAAO,IACd;CACR,QAAQ;EACN,OAAO,OAAO;CAChB;AACF;;;;;;;;;;AAWA,SAAgB,mBACd,SACA,MACA,IACA,QACiD;CACjD,IAAI,MAAM,QAAQ,MAAM,KAAK,OAAO,SAAS,KAAK,OAAO,IAAI;EAC3D,IACE,OAAO,SAAS,KAChB,OAAO,MACP,WAAW,OAAO,EAAE,KACpB,CAAC,OAAO,GAAG,MAAM,EAAE,GACnB;GACA,QAAQ,MACN,kCAAkC,MAAM,KAAK,WAC3C,cAAc,MAAM,KAAK,SAC3B,EAAE,OAAO,IACX;GAEA;EACF;EAEA,OACE,OAAO,SAAS,IACZ;GAAC,sBAAsB,SAAS,MAAM;GAAG,OAAO;GAAI,OAAO;EAAE,IAC7D;GAAC,sBAAsB,SAAS,MAAM;GAAG,OAAO;GAAI;EAAI;CAEhE;CAEA,OAAO;EACL,sBAAsB,SAAS,MAAM;EACrC,CAAC;EACD;CACF;AACF;;;;;;;;;;AAWA,SAAgB,mBACd,SACA,MACA,IACA,QACiD;CACjD,IAAI,MAAM,QAAQ,MAAM,KAAK,OAAO,SAAS,KAAK,OAAO,IAAI;EAC3D,IACE,OAAO,SAAS,KAChB,OAAO,MACP,WAAW,OAAO,EAAE,KACpB,CAAC,OAAO,GAAG,MAAM,EAAE,GACnB;GACA,QAAQ,MACN,kCAAkC,MAAM,KAAK,WAC3C,cAAc,MAAM,KAAK,SAC3B,EAAE,OAAO,IACX;GAEA;EACF;EAEA,OACE,OAAO,SAAS,IACZ;GAAC,sBAAsB,SAAS,MAAM;GAAG,OAAO;GAAI,OAAO;EAAE,IAC7D;GAAC,sBAAsB,SAAS,MAAM;GAAG,OAAO;GAAI;EAAI;CAEhE;CAEA,OAAO;EACL,sBAAsB,SAAS,MAAM;EACrC,CAAC;EACD;CACF;AACF;;;;;;;AAQA,SAAgB,iBAEd,SAAmB;CACnB,OAAO,QAAQ,QAAQ,KAAU,WAAc;EAC7C,IAAI,UAAU,CAAC,eAAe,KAAK,MAAM,GACvC,IAAI,KAAK,MAAM;EAGjB,OAAO;CACT,GAAG,CAAC,CAAC;AACP;;;;;;;AAQA,SAAgB,iBAEd,SAAmB;CACnB,OAAO,QAAQ,QAAQ,KAAU,WAAc;EAC7C,IAAI,UAAU,CAAC,eAAe,KAAK,MAAM,GACvC,IAAI,KAAK,MAAM;EAGjB,OAAO;CACT,GAAG,CAAC,CAAC;AACP"}
|
package/dist/index.cjs
CHANGED
|
@@ -56,10 +56,14 @@ const plugin = (options = {}) => {
|
|
|
56
56
|
id
|
|
57
57
|
};
|
|
58
58
|
if (!this.config.babel?.skipConfigResolution) {
|
|
59
|
-
if (!require_helpers_filters.
|
|
60
|
-
if (/^(?:m|c)?tsx?$/.test((0, _stryke_path_file_path_fns.findFileExtensionSafe)(id, { fullExtension: true })) && !require_helpers_filters.
|
|
61
|
-
if (/^(?:t|j)sx$/.test((0, _stryke_path_file_path_fns.findFileExtensionSafe)(id, { fullExtension: true })) && !require_helpers_filters.
|
|
59
|
+
if (!require_helpers_filters.includesPlugin(plugins, "@babel/plugin-transform-json-modules")) plugins.push("@babel/plugin-transform-json-modules");
|
|
60
|
+
if (/^(?:m|c)?tsx?$/.test((0, _stryke_path_file_path_fns.findFileExtensionSafe)(id, { fullExtension: true })) && !require_helpers_filters.includesPlugin(plugins, "@babel/plugin-syntax-typescript") && !require_helpers_filters.includesPreset(presets, "@babel/preset-typescript")) plugins.unshift("@babel/plugin-syntax-typescript");
|
|
61
|
+
if (/^(?:t|j)sx$/.test((0, _stryke_path_file_path_fns.findFileExtensionSafe)(id, { fullExtension: true })) && !require_helpers_filters.includesPlugin(plugins, "@babel/plugin-syntax-jsx") && !require_helpers_filters.includesPreset(presets, "@babel/preset-react")) plugins.unshift("@babel/plugin-syntax-jsx");
|
|
62
62
|
}
|
|
63
|
+
if (!require_helpers_filters.includesPlugin(plugins, "@babel/plugin-transform-json-modules") && !require_helpers_filters.includesPreset(presets, "@babel/preset-env") && (0, _stryke_path_file_path_fns.findFileExtensionSafe)(id).startsWith("json")) return {
|
|
64
|
+
code,
|
|
65
|
+
id
|
|
66
|
+
};
|
|
63
67
|
this.trace(`Running babel transformations with ${plugins.length} plugins and ${presets.length} presets for file: ${id}`);
|
|
64
68
|
const result = await (0, _babel_core.transformAsync)(code, {
|
|
65
69
|
cwd: this.config.cwd,
|
|
@@ -114,8 +118,8 @@ exports.getImport = require_helpers_module_helpers.getImport;
|
|
|
114
118
|
exports.getPluginName = require_helpers_filters.getPluginName;
|
|
115
119
|
exports.getUniquePlugins = require_helpers_options.getUniquePlugins;
|
|
116
120
|
exports.getUniquePresets = require_helpers_options.getUniquePresets;
|
|
117
|
-
exports.
|
|
118
|
-
exports.
|
|
121
|
+
exports.includesPlugin = require_helpers_filters.includesPlugin;
|
|
122
|
+
exports.includesPreset = require_helpers_filters.includesPreset;
|
|
119
123
|
exports.isImportCall = require_helpers_module_helpers.isImportCall;
|
|
120
124
|
exports.listExports = require_helpers_module_helpers.listExports;
|
|
121
125
|
exports.listImports = require_helpers_module_helpers.listImports;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as parseAst, n as GeneratorResult, r as generateFromAst, t as GenerateFromAstOptions } from "./ast-utils-Bh-E-kGU.cjs";
|
|
2
2
|
import { _ as ResolvedBabelTransformPluginOptions, a as BabelTransformPluginBuilder, c as BabelTransformPluginOptions, d as BabelUserConfig, f as DeclareBabelTransformPluginReturn, g as NamedImportDefinition, h as ImportSpecifier, i as BabelTransformPlugin, l as BabelTransformPreset, m as ImportDefinition, n as BabelResolvedConfig, o as BabelTransformPluginBuilderParams, p as DefaultImportDefinition, r as BabelTransformInput, s as BabelTransformPluginFilter, t as BabelPluginPass, u as BabelTransformPresetOptions, v as ResolvedBabelTransformPresetOptions } from "./config-Cwum-7c8.cjs";
|
|
3
3
|
import { t as createBabelPlugin } from "./create-plugin-BCjqxmR3.cjs";
|
|
4
|
-
import { a as
|
|
4
|
+
import { a as includesPreset, i as includesPlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "./filters-Bf8O8lmm.cjs";
|
|
5
5
|
import { a as isImportCall, i as getImport, n as addImportsToProgram, o as listExports, r as findExport, s as listImports, t as addImport } from "./module-helpers-BWcDQR8b.cjs";
|
|
6
6
|
import { a as resolvePluginFunction, i as resolveBabelPreset, n as getUniquePresets, o as resolvePresetFunction, r as resolveBabelPlugin, t as getUniquePlugins } from "./options-CyU9E_re.cjs";
|
|
7
7
|
import { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig } from "./types/plugin.cjs";
|
|
@@ -21,5 +21,5 @@ declare module "powerlines" {
|
|
|
21
21
|
*/
|
|
22
22
|
declare const plugin: <TContext extends BabelPluginContext = BabelPluginContext>(options?: BabelPluginOptions) => Plugin<TContext>;
|
|
23
23
|
//#endregion
|
|
24
|
-
export { type BabelPluginContext, type BabelPluginOptions, type BabelPluginPass, type BabelPluginResolvedConfig, type BabelPluginUserConfig, type BabelResolvedConfig, type BabelTransformInput, type BabelTransformPlugin, type BabelTransformPluginBuilder, type BabelTransformPluginBuilderParams, type BabelTransformPluginFilter, type BabelTransformPluginOptions, type BabelTransformPreset, type BabelTransformPresetOptions, type BabelUserConfig, type DeclareBabelTransformPluginReturn, type DefaultImportDefinition, GenerateFromAstOptions, type GeneratorResult, type ImportDefinition, type ImportSpecifier, type NamedImportDefinition, type ResolvedBabelTransformPluginOptions, type ResolvedBabelTransformPresetOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, plugin as default, plugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets,
|
|
24
|
+
export { type BabelPluginContext, type BabelPluginOptions, type BabelPluginPass, type BabelPluginResolvedConfig, type BabelPluginUserConfig, type BabelResolvedConfig, type BabelTransformInput, type BabelTransformPlugin, type BabelTransformPluginBuilder, type BabelTransformPluginBuilderParams, type BabelTransformPluginFilter, type BabelTransformPluginOptions, type BabelTransformPreset, type BabelTransformPresetOptions, type BabelUserConfig, type DeclareBabelTransformPluginReturn, type DefaultImportDefinition, GenerateFromAstOptions, type GeneratorResult, type ImportDefinition, type ImportSpecifier, type NamedImportDefinition, type ResolvedBabelTransformPluginOptions, type ResolvedBabelTransformPresetOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, plugin as default, plugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets, includesPlugin, includesPreset, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction };
|
|
25
25
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as parseAst, n as GeneratorResult, r as generateFromAst, t as GenerateFromAstOptions } from "./ast-utils-Bh-E-kGU.mjs";
|
|
2
2
|
import { _ as ResolvedBabelTransformPluginOptions, a as BabelTransformPluginBuilder, c as BabelTransformPluginOptions, d as BabelUserConfig, f as DeclareBabelTransformPluginReturn, g as NamedImportDefinition, h as ImportSpecifier, i as BabelTransformPlugin, l as BabelTransformPreset, m as ImportDefinition, n as BabelResolvedConfig, o as BabelTransformPluginBuilderParams, p as DefaultImportDefinition, r as BabelTransformInput, s as BabelTransformPluginFilter, t as BabelPluginPass, u as BabelTransformPresetOptions, v as ResolvedBabelTransformPresetOptions } from "./config-DbMevRzn.mjs";
|
|
3
3
|
import { t as createBabelPlugin } from "./create-plugin-B53ThfQZ.mjs";
|
|
4
|
-
import { a as
|
|
4
|
+
import { a as includesPreset, i as includesPlugin, n as filterPluginByFileId, r as getPluginName, t as addPluginFilter } from "./filters-DQ9zgW82.mjs";
|
|
5
5
|
import { a as isImportCall, i as getImport, n as addImportsToProgram, o as listExports, r as findExport, s as listImports, t as addImport } from "./module-helpers-bI0F0O26.mjs";
|
|
6
6
|
import { a as resolvePluginFunction, i as resolveBabelPreset, n as getUniquePresets, o as resolvePresetFunction, r as resolveBabelPlugin, t as getUniquePlugins } from "./options-BumyQlgw.mjs";
|
|
7
7
|
import { BabelPluginContext, BabelPluginOptions, BabelPluginResolvedConfig, BabelPluginUserConfig } from "./types/plugin.mjs";
|
|
@@ -21,5 +21,5 @@ declare module "powerlines" {
|
|
|
21
21
|
*/
|
|
22
22
|
declare const plugin: <TContext extends BabelPluginContext = BabelPluginContext>(options?: BabelPluginOptions) => Plugin<TContext>;
|
|
23
23
|
//#endregion
|
|
24
|
-
export { type BabelPluginContext, type BabelPluginOptions, type BabelPluginPass, type BabelPluginResolvedConfig, type BabelPluginUserConfig, type BabelResolvedConfig, type BabelTransformInput, type BabelTransformPlugin, type BabelTransformPluginBuilder, type BabelTransformPluginBuilderParams, type BabelTransformPluginFilter, type BabelTransformPluginOptions, type BabelTransformPreset, type BabelTransformPresetOptions, type BabelUserConfig, type DeclareBabelTransformPluginReturn, type DefaultImportDefinition, GenerateFromAstOptions, type GeneratorResult, type ImportDefinition, type ImportSpecifier, type NamedImportDefinition, type ResolvedBabelTransformPluginOptions, type ResolvedBabelTransformPresetOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, plugin as default, plugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets,
|
|
24
|
+
export { type BabelPluginContext, type BabelPluginOptions, type BabelPluginPass, type BabelPluginResolvedConfig, type BabelPluginUserConfig, type BabelResolvedConfig, type BabelTransformInput, type BabelTransformPlugin, type BabelTransformPluginBuilder, type BabelTransformPluginBuilderParams, type BabelTransformPluginFilter, type BabelTransformPluginOptions, type BabelTransformPreset, type BabelTransformPresetOptions, type BabelUserConfig, type DeclareBabelTransformPluginReturn, type DefaultImportDefinition, GenerateFromAstOptions, type GeneratorResult, type ImportDefinition, type ImportSpecifier, type NamedImportDefinition, type ResolvedBabelTransformPluginOptions, type ResolvedBabelTransformPresetOptions, addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, plugin as default, plugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets, includesPlugin, includesPreset, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction };
|
|
25
25
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addPluginFilter, filterPluginByFileId, getPluginName,
|
|
1
|
+
import { addPluginFilter, filterPluginByFileId, getPluginName, includesPlugin, includesPreset } from "./helpers/filters.mjs";
|
|
2
2
|
import { getUniquePlugins, getUniquePresets, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction } from "./helpers/options.mjs";
|
|
3
3
|
import { generateFromAst, parseAst } from "./helpers/ast-utils.mjs";
|
|
4
4
|
import { createBabelPlugin } from "./helpers/create-plugin.mjs";
|
|
@@ -53,10 +53,14 @@ const plugin = (options = {}) => {
|
|
|
53
53
|
id
|
|
54
54
|
};
|
|
55
55
|
if (!this.config.babel?.skipConfigResolution) {
|
|
56
|
-
if (!
|
|
57
|
-
if (/^(?:m|c)?tsx?$/.test(findFileExtensionSafe(id, { fullExtension: true })) && !
|
|
58
|
-
if (/^(?:t|j)sx$/.test(findFileExtensionSafe(id, { fullExtension: true })) && !
|
|
56
|
+
if (!includesPlugin(plugins, "@babel/plugin-transform-json-modules")) plugins.push("@babel/plugin-transform-json-modules");
|
|
57
|
+
if (/^(?:m|c)?tsx?$/.test(findFileExtensionSafe(id, { fullExtension: true })) && !includesPlugin(plugins, "@babel/plugin-syntax-typescript") && !includesPreset(presets, "@babel/preset-typescript")) plugins.unshift("@babel/plugin-syntax-typescript");
|
|
58
|
+
if (/^(?:t|j)sx$/.test(findFileExtensionSafe(id, { fullExtension: true })) && !includesPlugin(plugins, "@babel/plugin-syntax-jsx") && !includesPreset(presets, "@babel/preset-react")) plugins.unshift("@babel/plugin-syntax-jsx");
|
|
59
59
|
}
|
|
60
|
+
if (!includesPlugin(plugins, "@babel/plugin-transform-json-modules") && !includesPreset(presets, "@babel/preset-env") && findFileExtensionSafe(id).startsWith("json")) return {
|
|
61
|
+
code,
|
|
62
|
+
id
|
|
63
|
+
};
|
|
60
64
|
this.trace(`Running babel transformations with ${plugins.length} plugins and ${presets.length} presets for file: ${id}`);
|
|
61
65
|
const result = await transformAsync(code, {
|
|
62
66
|
cwd: this.config.cwd,
|
|
@@ -98,5 +102,5 @@ const plugin = (options = {}) => {
|
|
|
98
102
|
};
|
|
99
103
|
|
|
100
104
|
//#endregion
|
|
101
|
-
export { addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, plugin as default, plugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets,
|
|
105
|
+
export { addImport, addImportsToProgram, addPluginFilter, createBabelPlugin, plugin as default, plugin, filterPluginByFileId, findExport, generateFromAst, getImport, getPluginName, getUniquePlugins, getUniquePresets, includesPlugin, includesPreset, isImportCall, listExports, listImports, parseAst, resolveBabelPlugin, resolveBabelPreset, resolvePluginFunction, resolvePresetFunction };
|
|
102
106
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { PluginItem, PresetItem } from \"@babel/core\";\nimport { transformAsync } from \"@babel/core\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { findFileExtensionSafe } from \"@stryke/path/file-path-fns\";\nimport { isEmptyObject } from \"@stryke/type-checks/is-empty-object\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport defu from \"defu\";\nimport { isSet } from \"node:util/types\";\nimport type { Plugin } from \"powerlines\";\nimport { removeVirtualPrefix } from \"powerlines/plugin-utils\";\nimport { isDuplicatePlugin, isDuplicatePreset } from \"./helpers/filters\";\nimport {\n getUniquePlugins,\n getUniquePresets,\n resolveBabelPlugin,\n resolveBabelPreset\n} from \"./helpers/options\";\nimport type {\n ResolvedBabelTransformPluginOptions,\n ResolvedBabelTransformPresetOptions\n} from \"./types/config\";\nimport type { BabelPluginContext, BabelPluginOptions } from \"./types/plugin\";\n\nexport * from \"./helpers\";\nexport type * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n babel?: BabelPluginOptions;\n }\n}\n\n/**\n * Babel plugin for Powerlines.\n *\n * @param options - The Babel plugin user configuration options.\n * @returns A Powerlines plugin that integrates Babel transformations.\n */\nexport const plugin = <\n TContext extends BabelPluginContext = BabelPluginContext\n>(\n options: BabelPluginOptions = {}\n): Plugin<TContext> => {\n return {\n name: \"babel\",\n config() {\n if (!isSetObject(options)) {\n return undefined;\n }\n\n return {\n babel: options\n };\n },\n configResolved: {\n order: \"pre\",\n handler() {\n this.config.babel = defu(this.config.babel ?? {}, {\n plugins: [],\n presets: []\n });\n\n this.config.babel.plugins = getUniquePlugins(this.config.babel.plugins);\n this.config.babel.presets = getUniquePresets(this.config.babel.presets);\n }\n },\n async transform(code: string, id: string) {\n if (\n // isParentPath(id, this.powerlinesPath) ||\n code.includes(\"/* @powerlines-ignore */\") ||\n code.includes(\"/* @powerlines-disable */\")\n ) {\n this.trace(`Skipping Babel transformation for: ${id}`);\n\n return { code, id };\n }\n\n const plugins = getUniquePlugins(\n this.config.babel.plugins\n .map(plugin => resolveBabelPlugin(this, code, id, plugin))\n .filter(Boolean) as ResolvedBabelTransformPluginOptions[]\n );\n const presets = getUniquePresets(\n this.config.babel.presets\n .map(preset => resolveBabelPreset(this, code, id, preset))\n .filter(Boolean) as ResolvedBabelTransformPresetOptions[]\n );\n\n if (\n Array.isArray(plugins) &&\n plugins.length === 0 &&\n Array.isArray(presets) &&\n presets.length === 0\n ) {\n return { code, id };\n }\n\n if (!this.config.babel?.skipConfigResolution) {\n if (\n !isDuplicatePlugin(plugins, \"@babel/plugin-transform-json-modules\")\n ) {\n plugins.push(\"@babel/plugin-transform-json-modules\");\n }\n\n if (\n /^(?:m|c)?tsx?$/.test(\n findFileExtensionSafe(id, {\n fullExtension: true\n })\n ) &&\n !isDuplicatePlugin(plugins, \"@babel/plugin-syntax-typescript\") &&\n !isDuplicatePreset(presets, \"@babel/preset-typescript\")\n ) {\n plugins.unshift(\"@babel/plugin-syntax-typescript\");\n }\n\n if (\n /^(?:t|j)sx$/.test(\n findFileExtensionSafe(id, {\n fullExtension: true\n })\n ) &&\n !isDuplicatePlugin(plugins, \"@babel/plugin-syntax-jsx\") &&\n !isDuplicatePreset(presets, \"@babel/preset-react\")\n ) {\n plugins.unshift(\"@babel/plugin-syntax-jsx\");\n }\n }\n\n this.trace(\n `Running babel transformations with ${plugins.length} plugins and ${\n presets.length\n } presets for file: ${id}`\n );\n\n const result = await transformAsync(code, {\n cwd: this.config.cwd,\n highlightCode: true,\n code: true,\n ast: false,\n cloneInputAst: false,\n comments: true,\n sourceType: \"module\",\n configFile: false,\n babelrc: false,\n envName: this.config.mode,\n caller: {\n name: this.config.framework?.name || \"powerlines\"\n },\n ...omit(this.config.babel ?? {}, [\n \"skipConfigResolution\",\n \"skipTransform\"\n ]),\n filename: removeVirtualPrefix(id),\n plugins: plugins\n .map(plugin => {\n if (Array.isArray(plugin) && plugin.length >= 2) {\n if (\n plugin\n .slice(1)\n .every(item => !isSet(item) || isEmptyObject(item))\n ) {\n return plugin[0];\n }\n\n return [\n plugin[0],\n plugin.length > 1 && plugin[1] ? plugin[1] : {}\n ];\n }\n\n return plugin;\n })\n .filter(Boolean) as PluginItem<object>[],\n presets: presets\n .map(preset => {\n if (Array.isArray(preset) && preset.length >= 2) {\n if (\n preset\n .slice(1)\n .every(item => !isSet(item) || isEmptyObject(item))\n ) {\n return preset[0];\n }\n\n return [\n preset[0],\n preset.length > 1 && preset[1] ? preset[1] : {}\n ];\n }\n\n return preset;\n })\n .filter(Boolean) as PresetItem<object>[]\n });\n if (!result?.code) {\n throw new Error(`Powerlines - Babel plugin failed to compile ${id}`);\n }\n\n this.trace(`Completed babel transformations for file: ${id}`);\n\n return {\n code: this.config.babel?.skipTransform ? code : result.code,\n id\n };\n }\n } as Plugin<TContext>;\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwDA,MAAa,UAGX,UAA8B,CAAC,MACV;CACrB,OAAO;EACL,MAAM;EACN,SAAS;GACP,IAAI,CAAC,YAAY,OAAO,GACtB;GAGF,OAAO,EACL,OAAO,QACT;EACF;E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ACvD;GACF;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport type { PluginItem, PresetItem } from \"@babel/core\";\nimport { transformAsync } from \"@babel/core\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { findFileExtensionSafe } from \"@stryke/path/file-path-fns\";\nimport { isEmptyObject } from \"@stryke/type-checks/is-empty-object\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport defu from \"defu\";\nimport { isSet } from \"node:util/types\";\nimport type { Plugin } from \"powerlines\";\nimport { removeVirtualPrefix } from \"powerlines/plugin-utils\";\nimport { includesPlugin, includesPreset } from \"./helpers/filters\";\nimport {\n getUniquePlugins,\n getUniquePresets,\n resolveBabelPlugin,\n resolveBabelPreset\n} from \"./helpers/options\";\nimport type {\n ResolvedBabelTransformPluginOptions,\n ResolvedBabelTransformPresetOptions\n} from \"./types/config\";\nimport type { BabelPluginContext, BabelPluginOptions } from \"./types/plugin\";\n\nexport * from \"./helpers\";\nexport type * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n babel?: BabelPluginOptions;\n }\n}\n\n/**\n * Babel plugin for Powerlines.\n *\n * @param options - The Babel plugin user configuration options.\n * @returns A Powerlines plugin that integrates Babel transformations.\n */\nexport const plugin = <\n TContext extends BabelPluginContext = BabelPluginContext\n>(\n options: BabelPluginOptions = {}\n): Plugin<TContext> => {\n return {\n name: \"babel\",\n config() {\n if (!isSetObject(options)) {\n return undefined;\n }\n\n return {\n babel: options\n };\n },\n configResolved: {\n order: \"pre\",\n handler() {\n this.config.babel = defu(this.config.babel ?? {}, {\n plugins: [],\n presets: []\n });\n\n this.config.babel.plugins = getUniquePlugins(this.config.babel.plugins);\n this.config.babel.presets = getUniquePresets(this.config.babel.presets);\n }\n },\n async transform(code: string, id: string) {\n if (\n // isParentPath(id, this.powerlinesPath) ||\n code.includes(\"/* @powerlines-ignore */\") ||\n code.includes(\"/* @powerlines-disable */\")\n ) {\n this.trace(`Skipping Babel transformation for: ${id}`);\n\n return { code, id };\n }\n\n const plugins = getUniquePlugins(\n this.config.babel.plugins\n .map(plugin => resolveBabelPlugin(this, code, id, plugin))\n .filter(Boolean) as ResolvedBabelTransformPluginOptions[]\n );\n const presets = getUniquePresets(\n this.config.babel.presets\n .map(preset => resolveBabelPreset(this, code, id, preset))\n .filter(Boolean) as ResolvedBabelTransformPresetOptions[]\n );\n\n if (\n Array.isArray(plugins) &&\n plugins.length === 0 &&\n Array.isArray(presets) &&\n presets.length === 0\n ) {\n return { code, id };\n }\n\n if (!this.config.babel?.skipConfigResolution) {\n if (!includesPlugin(plugins, \"@babel/plugin-transform-json-modules\")) {\n plugins.push(\"@babel/plugin-transform-json-modules\");\n }\n\n if (\n /^(?:m|c)?tsx?$/.test(\n findFileExtensionSafe(id, {\n fullExtension: true\n })\n ) &&\n !includesPlugin(plugins, \"@babel/plugin-syntax-typescript\") &&\n !includesPreset(presets, \"@babel/preset-typescript\")\n ) {\n plugins.unshift(\"@babel/plugin-syntax-typescript\");\n }\n\n if (\n /^(?:t|j)sx$/.test(\n findFileExtensionSafe(id, {\n fullExtension: true\n })\n ) &&\n !includesPlugin(plugins, \"@babel/plugin-syntax-jsx\") &&\n !includesPreset(presets, \"@babel/preset-react\")\n ) {\n plugins.unshift(\"@babel/plugin-syntax-jsx\");\n }\n }\n\n if (\n !includesPlugin(plugins, \"@babel/plugin-transform-json-modules\") &&\n !includesPreset(presets, \"@babel/preset-env\") &&\n findFileExtensionSafe(id).startsWith(\"json\")\n ) {\n // Skipping transformation for JSON files if the transform-json-modules plugin is not included, as Babel cannot process JSON files without it.\n return { code, id };\n }\n\n this.trace(\n `Running babel transformations with ${plugins.length} plugins and ${\n presets.length\n } presets for file: ${id}`\n );\n\n const result = await transformAsync(code, {\n cwd: this.config.cwd,\n highlightCode: true,\n code: true,\n ast: false,\n cloneInputAst: false,\n comments: true,\n sourceType: \"module\",\n configFile: false,\n babelrc: false,\n envName: this.config.mode,\n caller: {\n name: this.config.framework?.name || \"powerlines\"\n },\n ...omit(this.config.babel ?? {}, [\n \"skipConfigResolution\",\n \"skipTransform\"\n ]),\n filename: removeVirtualPrefix(id),\n plugins: plugins\n .map(plugin => {\n if (Array.isArray(plugin) && plugin.length >= 2) {\n if (\n plugin\n .slice(1)\n .every(item => !isSet(item) || isEmptyObject(item))\n ) {\n return plugin[0];\n }\n\n return [\n plugin[0],\n plugin.length > 1 && plugin[1] ? plugin[1] : {}\n ];\n }\n\n return plugin;\n })\n .filter(Boolean) as PluginItem<object>[],\n presets: presets\n .map(preset => {\n if (Array.isArray(preset) && preset.length >= 2) {\n if (\n preset\n .slice(1)\n .every(item => !isSet(item) || isEmptyObject(item))\n ) {\n return preset[0];\n }\n\n return [\n preset[0],\n preset.length > 1 && preset[1] ? preset[1] : {}\n ];\n }\n\n return preset;\n })\n .filter(Boolean) as PresetItem<object>[]\n });\n if (!result?.code) {\n throw new Error(`Powerlines - Babel plugin failed to compile ${id}`);\n }\n\n this.trace(`Completed babel transformations for file: ${id}`);\n\n return {\n code: this.config.babel?.skipTransform ? code : result.code,\n id\n };\n }\n } as Plugin<TContext>;\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAwDA,MAAa,UAGX,UAA8B,CAAC,MACV;CACrB,OAAO;EACL,MAAM;EACN,SAAS;GACP,IAAI,CAAC,YAAY,OAAO,GACtB;GAGF,OAAO,EACL,OAAO,QACT;EACF;EACA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MAAM,IAAI,MAAM,+CAA+C,IAAI;GAGrE,KAAK,MAAM,6CAA6C,IAAI;GAE5D,OAAO;IACL,MAAM,KAAK,OAAO,OAAO,gBAAgB,OAAO,OAAO;IACvD;GACF;EACF;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-babel",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.72",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A package containing a Powerlines plugin to assist in developing other Powerlines plugins.",
|
|
6
6
|
"keywords": ["babel", "powerlines", "storm-software", "powerlines-plugin"],
|
|
@@ -90,16 +90,16 @@
|
|
|
90
90
|
"@babel/helper-plugin-utils": "8.0.0-rc.6",
|
|
91
91
|
"@babel/parser": "8.0.0-rc.6",
|
|
92
92
|
"@babel/types": "8.0.0-rc.6",
|
|
93
|
-
"@powerlines/core": "^0.48.
|
|
93
|
+
"@powerlines/core": "^0.48.19",
|
|
94
94
|
"@storm-software/config-tools": "^1.190.33",
|
|
95
|
-
"@stryke/fs": "^0.33.
|
|
96
|
-
"@stryke/path": "^0.29.
|
|
97
|
-
"@stryke/type-checks": "^0.6.
|
|
98
|
-
"@stryke/types": "^0.12.
|
|
95
|
+
"@stryke/fs": "^0.33.78",
|
|
96
|
+
"@stryke/path": "^0.29.5",
|
|
97
|
+
"@stryke/type-checks": "^0.6.11",
|
|
98
|
+
"@stryke/types": "^0.12.6",
|
|
99
99
|
"chalk": "5.6.2",
|
|
100
100
|
"defu": "^6.1.7",
|
|
101
101
|
"jiti": "^2.7.0",
|
|
102
|
-
"powerlines": "^0.47.
|
|
102
|
+
"powerlines": "^0.47.76"
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": {
|
|
105
105
|
"@types/babel__helper-plugin-utils": "^7.10.3",
|
|
@@ -116,5 +116,5 @@
|
|
|
116
116
|
"@babel/plugin-transform-json-modules": { "optional": false }
|
|
117
117
|
},
|
|
118
118
|
"publishConfig": { "access": "public" },
|
|
119
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "53c5911f6d02444075c38d2965bb8361ae30f7e5"
|
|
120
120
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filters-Rm2dAJYH.d.cts","names":[],"sources":["../src/helpers/filters.ts"],"mappings":";;;;iBA+BgB,aAAA,CACd,MAAA,GACI,2BAA2B,kCAItB,IAAA;;AANX;;;;;;iBA2BgB,iBAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,IAAK,MAAA,EAAQ,CAAA;;AAtBT;AAoBf;;;;;iBAoBgB,iBAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,IAAK,MAAA,EAAQ,CAAA;;;;;;;;iBAkBR,oBAAA,kBAAsC,OAAA,GAAU,OAAA,CAAA,CAC9D,OAAA,EAAS,QAAA,EACT,MAAA,WACC,0BAAA;;;;AAzCsB;AAkBzB;;;;;iBA2CgB,eAAA,CACd,OAAA,EAAS,OAAA,EACT,OAAA,EAAS,2BAAA,IACT,MAAA,EAAQ,0BAAA,qBACR,IAAA,WACC,2BAAA;;;;;;;;;iBAUa,eAAA,CACd,OAAA,EAAS,OAAA,EACT,MAAA,EAAQ,oBAAA,GAAuB,2BAAA,EAC/B,MAAA,EAAQ,WAAA,CAAY,0BAAA,IACnB,2BAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"filters-jhxE0J9i.d.mts","names":[],"sources":["../src/helpers/filters.ts"],"mappings":";;;;iBA+BgB,aAAA,CACd,MAAA,GACI,2BAA2B,kCAItB,IAAA;;AANX;;;;;;iBA2BgB,iBAAA,WACJ,2BAAA,GAA8B,mCAAA,CAAA,CACxC,OAAA,EAAS,CAAA,IAAK,MAAA,EAAQ,CAAA;;AAtBT;AAoBf;;;;;iBAoBgB,iBAAA,WACJ,2BAAA,GAA8B,mCA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