@powerlines/plugin-unified 0.1.71 → 0.1.73
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/index.cjs +80 -1
- package/dist/index.mjs +78 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.mjs +1 -1
- package/dist/types/plugin.mjs +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1 +1,80 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
let _rollup_pluginutils = require("@rollup/pluginutils");
|
|
3
|
+
let _stryke_type_checks = require("@stryke/type-checks");
|
|
4
|
+
let unified = require("unified");
|
|
5
|
+
|
|
6
|
+
//#region src/index.ts
|
|
7
|
+
/**
|
|
8
|
+
* UnifiedJs Transformations Plugin
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This plugin allows you to define transformations using the UnifiedJS ecosystem. You can specify rules that match certain files and apply Unified processors to transform their content. This is useful for processing markdown, HTML, or any other text-based files using Unified's powerful plugins and ecosystem.
|
|
12
|
+
*
|
|
13
|
+
* @see https://unified.js.org
|
|
14
|
+
*
|
|
15
|
+
* @param options - The plugin options.
|
|
16
|
+
* @returns A Powerlines plugin instance.
|
|
17
|
+
*/
|
|
18
|
+
const plugin = (options = {}) => {
|
|
19
|
+
const resolved = (options?.rules ?? []).map((rule) => {
|
|
20
|
+
return {
|
|
21
|
+
...rule,
|
|
22
|
+
filter: (0, _stryke_type_checks.isFunction)(rule.include) ? rule.include : (0, _rollup_pluginutils.createFilter)(rule.include, rule.exclude),
|
|
23
|
+
processor: Promise.resolve(rule.setup((0, unified.unified)()))
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
const pre = [];
|
|
27
|
+
const post = [];
|
|
28
|
+
const normal = [];
|
|
29
|
+
for (const rule of resolved) if (rule.enforce === "pre") pre.push(rule);
|
|
30
|
+
else if (rule.enforce === "post") post.push(rule);
|
|
31
|
+
else normal.push(rule);
|
|
32
|
+
return [{
|
|
33
|
+
name: "unified:config",
|
|
34
|
+
config() {
|
|
35
|
+
return { unified: { rules: resolved } };
|
|
36
|
+
}
|
|
37
|
+
}, [
|
|
38
|
+
pre,
|
|
39
|
+
normal,
|
|
40
|
+
post
|
|
41
|
+
].map((rules, idx) => {
|
|
42
|
+
const enforce = [
|
|
43
|
+
"pre",
|
|
44
|
+
void 0,
|
|
45
|
+
"post"
|
|
46
|
+
][idx];
|
|
47
|
+
if (rules.length === 0) return void 0;
|
|
48
|
+
return {
|
|
49
|
+
name: `unified${enforce ? `:${enforce}` : ""}`,
|
|
50
|
+
enforce,
|
|
51
|
+
transform: {
|
|
52
|
+
filter: (id) => rules.some((r) => r.filter(id)),
|
|
53
|
+
async handler(code, id) {
|
|
54
|
+
const rule = rules.find((r) => r.filter(id));
|
|
55
|
+
if (!rule) return;
|
|
56
|
+
code = await rule.transform?.pre?.(code, id) || code;
|
|
57
|
+
const result = await (await rule.processor).process(code);
|
|
58
|
+
let resultCode = result.toString();
|
|
59
|
+
let resultMap = result.map;
|
|
60
|
+
if (rule.transform?.post) {
|
|
61
|
+
const postResult = await rule.transform.post(resultCode, id, resultMap) || resultCode;
|
|
62
|
+
if ((0, _stryke_type_checks.isString)(postResult)) resultCode = postResult;
|
|
63
|
+
else {
|
|
64
|
+
resultCode = postResult.code;
|
|
65
|
+
resultMap = postResult.map;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
code: resultCode,
|
|
70
|
+
map: resultMap
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}).filter(Boolean)].flat();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
exports.default = plugin;
|
|
80
|
+
exports.plugin = plugin;
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,79 @@
|
|
|
1
|
-
import{createFilter
|
|
1
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
2
|
+
import { isFunction, isString } from "@stryke/type-checks";
|
|
3
|
+
import { unified } from "unified";
|
|
4
|
+
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* UnifiedJs Transformations Plugin
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* This plugin allows you to define transformations using the UnifiedJS ecosystem. You can specify rules that match certain files and apply Unified processors to transform their content. This is useful for processing markdown, HTML, or any other text-based files using Unified's powerful plugins and ecosystem.
|
|
11
|
+
*
|
|
12
|
+
* @see https://unified.js.org
|
|
13
|
+
*
|
|
14
|
+
* @param options - The plugin options.
|
|
15
|
+
* @returns A Powerlines plugin instance.
|
|
16
|
+
*/
|
|
17
|
+
const plugin = (options = {}) => {
|
|
18
|
+
const resolved = (options?.rules ?? []).map((rule) => {
|
|
19
|
+
return {
|
|
20
|
+
...rule,
|
|
21
|
+
filter: isFunction(rule.include) ? rule.include : createFilter(rule.include, rule.exclude),
|
|
22
|
+
processor: Promise.resolve(rule.setup(unified()))
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
const pre = [];
|
|
26
|
+
const post = [];
|
|
27
|
+
const normal = [];
|
|
28
|
+
for (const rule of resolved) if (rule.enforce === "pre") pre.push(rule);
|
|
29
|
+
else if (rule.enforce === "post") post.push(rule);
|
|
30
|
+
else normal.push(rule);
|
|
31
|
+
return [{
|
|
32
|
+
name: "unified:config",
|
|
33
|
+
config() {
|
|
34
|
+
return { unified: { rules: resolved } };
|
|
35
|
+
}
|
|
36
|
+
}, [
|
|
37
|
+
pre,
|
|
38
|
+
normal,
|
|
39
|
+
post
|
|
40
|
+
].map((rules, idx) => {
|
|
41
|
+
const enforce = [
|
|
42
|
+
"pre",
|
|
43
|
+
void 0,
|
|
44
|
+
"post"
|
|
45
|
+
][idx];
|
|
46
|
+
if (rules.length === 0) return void 0;
|
|
47
|
+
return {
|
|
48
|
+
name: `unified${enforce ? `:${enforce}` : ""}`,
|
|
49
|
+
enforce,
|
|
50
|
+
transform: {
|
|
51
|
+
filter: (id) => rules.some((r) => r.filter(id)),
|
|
52
|
+
async handler(code, id) {
|
|
53
|
+
const rule = rules.find((r) => r.filter(id));
|
|
54
|
+
if (!rule) return;
|
|
55
|
+
code = await rule.transform?.pre?.(code, id) || code;
|
|
56
|
+
const result = await (await rule.processor).process(code);
|
|
57
|
+
let resultCode = result.toString();
|
|
58
|
+
let resultMap = result.map;
|
|
59
|
+
if (rule.transform?.post) {
|
|
60
|
+
const postResult = await rule.transform.post(resultCode, id, resultMap) || resultCode;
|
|
61
|
+
if (isString(postResult)) resultCode = postResult;
|
|
62
|
+
else {
|
|
63
|
+
resultCode = postResult.code;
|
|
64
|
+
resultMap = postResult.map;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
code: resultCode,
|
|
69
|
+
map: resultMap
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}).filter(Boolean)].flat();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
export { plugin as default, plugin };
|
|
2
79
|
//# 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 { createFilter } from \"@rollup/pluginutils\";\nimport { isFunction, isString } from \"@stryke/type-checks\";\nimport { Plugin } from \"powerlines\";\nimport type { SourceMap } from \"rollup\";\nimport { unified } from \"unified\";\nimport {\n ResolvedUnifiedRule,\n UnifiedPluginContext,\n UnifiedPluginOptions\n} from \"./types/plugin\";\n\nexport * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n unified?: UnifiedPluginOptions;\n }\n}\n\n/**\n * UnifiedJs Transformations Plugin\n *\n * @remarks\n * This plugin allows you to define transformations using the UnifiedJS ecosystem. You can specify rules that match certain files and apply Unified processors to transform their content. This is useful for processing markdown, HTML, or any other text-based files using Unified's powerful plugins and ecosystem.\n *\n * @see https://unified.js.org\n *\n * @param options - The plugin options.\n * @returns A Powerlines plugin instance.\n */\nexport const plugin = <\n TContext extends UnifiedPluginContext = UnifiedPluginContext\n>(\n options: UnifiedPluginOptions = {}\n): Plugin<TContext>[] => {\n const resolved = (options?.rules ?? []).map((rule): ResolvedUnifiedRule => {\n return {\n ...rule,\n filter: isFunction(rule.include)\n ? rule.include\n : createFilter(rule.include, rule.exclude),\n processor: Promise.resolve(rule.setup(unified()))\n };\n });\n\n const pre: ResolvedUnifiedRule[] = [];\n const post: ResolvedUnifiedRule[] = [];\n const normal: ResolvedUnifiedRule[] = [];\n\n for (const rule of resolved) {\n if (rule.enforce === \"pre\") pre.push(rule);\n else if (rule.enforce === \"post\") post.push(rule);\n else normal.push(rule);\n }\n\n return [\n {\n name: \"unified:config\",\n config() {\n return {\n unified: {\n rules: resolved\n }\n };\n }\n },\n [pre, normal, post]\n .map((rules, idx): Plugin<TContext> | undefined => {\n const enforce = ([\"pre\", undefined, \"post\"] as const)[idx];\n if (rules.length === 0) return undefined;\n\n return {\n name: `unified${enforce ? `:${enforce}` : \"\"}`,\n enforce,\n transform: {\n filter: (id: string) => rules.some(r => r.filter(id)),\n async handler(code, id) {\n const rule = rules.find(r => r.filter(id));\n if (!rule) return;\n\n code = (await rule.transform?.pre?.(code, id)) || code;\n\n const processor = await rule.processor;\n const result = await processor.process(code);\n\n let resultCode = result.toString();\n let resultMap = result.map;\n\n if (rule.transform?.post) {\n const postResult =\n (await rule.transform.post(\n resultCode,\n id,\n resultMap as SourceMap\n )) || resultCode;\n if (isString(postResult)) {\n resultCode = postResult;\n } else {\n resultCode = postResult.code;\n resultMap = postResult.map;\n }\n }\n\n return {\n code: resultCode,\n map: resultMap\n };\n }\n }\n };\n })\n .filter(Boolean)\n ].flat() as Plugin<TContext>[];\n};\n\nexport default plugin;\n"],"mappings":"
|
|
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 { createFilter } from \"@rollup/pluginutils\";\nimport { isFunction, isString } from \"@stryke/type-checks\";\nimport { Plugin } from \"powerlines\";\nimport type { SourceMap } from \"rollup\";\nimport { unified } from \"unified\";\nimport {\n ResolvedUnifiedRule,\n UnifiedPluginContext,\n UnifiedPluginOptions\n} from \"./types/plugin\";\n\nexport * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n unified?: UnifiedPluginOptions;\n }\n}\n\n/**\n * UnifiedJs Transformations Plugin\n *\n * @remarks\n * This plugin allows you to define transformations using the UnifiedJS ecosystem. You can specify rules that match certain files and apply Unified processors to transform their content. This is useful for processing markdown, HTML, or any other text-based files using Unified's powerful plugins and ecosystem.\n *\n * @see https://unified.js.org\n *\n * @param options - The plugin options.\n * @returns A Powerlines plugin instance.\n */\nexport const plugin = <\n TContext extends UnifiedPluginContext = UnifiedPluginContext\n>(\n options: UnifiedPluginOptions = {}\n): Plugin<TContext>[] => {\n const resolved = (options?.rules ?? []).map((rule): ResolvedUnifiedRule => {\n return {\n ...rule,\n filter: isFunction(rule.include)\n ? rule.include\n : createFilter(rule.include, rule.exclude),\n processor: Promise.resolve(rule.setup(unified()))\n };\n });\n\n const pre: ResolvedUnifiedRule[] = [];\n const post: ResolvedUnifiedRule[] = [];\n const normal: ResolvedUnifiedRule[] = [];\n\n for (const rule of resolved) {\n if (rule.enforce === \"pre\") pre.push(rule);\n else if (rule.enforce === \"post\") post.push(rule);\n else normal.push(rule);\n }\n\n return [\n {\n name: \"unified:config\",\n config() {\n return {\n unified: {\n rules: resolved\n }\n };\n }\n },\n [pre, normal, post]\n .map((rules, idx): Plugin<TContext> | undefined => {\n const enforce = ([\"pre\", undefined, \"post\"] as const)[idx];\n if (rules.length === 0) return undefined;\n\n return {\n name: `unified${enforce ? `:${enforce}` : \"\"}`,\n enforce,\n transform: {\n filter: (id: string) => rules.some(r => r.filter(id)),\n async handler(code, id) {\n const rule = rules.find(r => r.filter(id));\n if (!rule) return;\n\n code = (await rule.transform?.pre?.(code, id)) || code;\n\n const processor = await rule.processor;\n const result = await processor.process(code);\n\n let resultCode = result.toString();\n let resultMap = result.map;\n\n if (rule.transform?.post) {\n const postResult =\n (await rule.transform.post(\n resultCode,\n id,\n resultMap as SourceMap\n )) || resultCode;\n if (isString(postResult)) {\n resultCode = postResult;\n } else {\n resultCode = postResult.code;\n resultMap = postResult.map;\n }\n }\n\n return {\n code: resultCode,\n map: resultMap\n };\n }\n }\n };\n })\n .filter(Boolean)\n ].flat() as Plugin<TContext>[];\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;AAgDA,MAAa,UAGX,UAAgC,EAAE,KACX;CACvB,MAAM,YAAY,SAAS,SAAS,EAAE,EAAE,KAAK,SAA8B;AACzE,SAAO;GACL,GAAG;GACH,QAAQ,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QAAQ,CACnB,CAAC,MAAM"}
|
package/dist/types/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export { };
|
package/dist/types/plugin.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-unified",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.73",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A Powerlines plugin to use the Unified ecosystem to generate content.",
|
|
6
6
|
"keywords": ["unified", "powerlines", "storm-software", "powerlines-plugin"],
|
|
@@ -95,13 +95,13 @@
|
|
|
95
95
|
"@stryke/types": "^0.12.0",
|
|
96
96
|
"@stryke/type-checks": "^0.6.5",
|
|
97
97
|
"defu": "^6.1.7",
|
|
98
|
-
"powerlines": "^0.46.
|
|
98
|
+
"powerlines": "^0.46.5",
|
|
99
99
|
"unified": "^11.0.5",
|
|
100
100
|
"@rollup/pluginutils": "^4.2.1",
|
|
101
101
|
"rollup": "^4.60.2"
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
104
|
+
"@powerlines/plugin-plugin": "^0.12.409",
|
|
105
105
|
"@types/node": "^25.6.0",
|
|
106
106
|
"@types/hast": "^3.0.4",
|
|
107
107
|
"@types/mdast": "^4.0.4",
|
|
@@ -109,5 +109,5 @@
|
|
|
109
109
|
"@types/estree": "^1.0.8"
|
|
110
110
|
},
|
|
111
111
|
"publishConfig": { "access": "public" },
|
|
112
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "9af888c54e58a82744cc334a6b80da52429fa0ac"
|
|
113
113
|
}
|