@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 CHANGED
@@ -1 +1,80 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});let e=require(`@rollup/pluginutils`),t=require(`@stryke/type-checks`),n=require(`unified`);const r=(r={})=>{let i=(r?.rules??[]).map(r=>({...r,filter:(0,t.isFunction)(r.include)?r.include:(0,e.createFilter)(r.include,r.exclude),processor:Promise.resolve(r.setup((0,n.unified)()))})),a=[],o=[],s=[];for(let e of i)e.enforce===`pre`?a.push(e):e.enforce===`post`?o.push(e):s.push(e);return[{name:`unified:config`,config(){return{unified:{rules:i}}}},[a,s,o].map((e,n)=>{let r=[`pre`,void 0,`post`][n];if(e.length!==0)return{name:`unified${r?`:${r}`:``}`,enforce:r,transform:{filter:t=>e.some(e=>e.filter(t)),async handler(n,r){let i=e.find(e=>e.filter(r));if(!i)return;n=await i.transform?.pre?.(n,r)||n;let a=await(await i.processor).process(n),o=a.toString(),s=a.map;if(i.transform?.post){let e=await i.transform.post(o,r,s)||o;(0,t.isString)(e)?o=e:(o=e.code,s=e.map)}return{code:o,map:s}}}}}).filter(Boolean)].flat()};exports.default=r,exports.plugin=r;
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 as e}from"@rollup/pluginutils";import{isFunction as t,isString as n}from"@stryke/type-checks";import{unified as r}from"unified";const i=(i={})=>{let a=(i?.rules??[]).map(n=>({...n,filter:t(n.include)?n.include:e(n.include,n.exclude),processor:Promise.resolve(n.setup(r()))})),o=[],s=[],c=[];for(let e of a)e.enforce===`pre`?o.push(e):e.enforce===`post`?s.push(e):c.push(e);return[{name:`unified:config`,config(){return{unified:{rules:a}}}},[o,c,s].map((e,t)=>{let r=[`pre`,void 0,`post`][t];if(e.length!==0)return{name:`unified${r?`:${r}`:``}`,enforce:r,transform:{filter:t=>e.some(e=>e.filter(t)),async handler(t,r){let i=e.find(e=>e.filter(r));if(!i)return;t=await i.transform?.pre?.(t,r)||t;let a=await(await i.processor).process(t),o=a.toString(),s=a.map;if(i.transform?.post){let e=await i.transform.post(o,r,s)||o;n(e)?o=e:(o=e.code,s=e.map)}return{code:o,map:s}}}}}).filter(Boolean)].flat()};export{i as default,i as plugin};
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
@@ -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":"oJAgDA,MAAa,GAGX,EAAgC,EAAE,GACX,CACvB,IAAM,GAAY,GAAS,OAAS,EAAE,EAAE,IAAK,IACpC,CACL,GAAG,EACH,OAAQ,EAAW,EAAK,QAAQ,CAC5B,EAAK,QACL,EAAa,EAAK,QAAS,EAAK,QAAQ,CAC5C,UAAW,QAAQ,QAAQ,EAAK,MAAM,GAAS,CAAC,CAAC,CAClD,EACD,CAEI,EAA6B,EAAE,CAC/B,EAA8B,EAAE,CAChC,EAAgC,EAAE,CAExC,IAAK,IAAM,KAAQ,EACb,EAAK,UAAY,MAAO,EAAI,KAAK,EAAK,CACjC,EAAK,UAAY,OAAQ,EAAK,KAAK,EAAK,CAC5C,EAAO,KAAK,EAAK,CAGxB,MAAO,CACL,CACE,KAAM,iBACN,QAAS,CACP,MAAO,CACL,QAAS,CACP,MAAO,EACR,CACF,EAEJ,CACD,CAAC,EAAK,EAAQ,EAAK,CAChB,KAAK,EAAO,IAAsC,CACjD,IAAM,EAAW,CAAC,MAAO,IAAA,GAAW,OAAO,CAAW,GAClD,KAAM,SAAW,EAErB,MAAO,CACL,KAAM,UAAU,EAAU,IAAI,IAAY,KAC1C,UACA,UAAW,CACT,OAAS,GAAe,EAAM,KAAK,GAAK,EAAE,OAAO,EAAG,CAAC,CACrD,MAAM,QAAQ,EAAM,EAAI,CACtB,IAAM,EAAO,EAAM,KAAK,GAAK,EAAE,OAAO,EAAG,CAAC,CAC1C,GAAI,CAAC,EAAM,OAEX,EAAQ,MAAM,EAAK,WAAW,MAAM,EAAM,EAAG,EAAK,EAGlD,IAAM,EAAS,MAAM,MADG,EAAK,WACE,QAAQ,EAAK,CAExC,EAAa,EAAO,UAAU,CAC9B,EAAY,EAAO,IAEvB,GAAI,EAAK,WAAW,KAAM,CACxB,IAAM,EACH,MAAM,EAAK,UAAU,KACpB,EACA,EACA,EACD,EAAK,EACJ,EAAS,EAAW,CACtB,EAAa,GAEb,EAAa,EAAW,KACxB,EAAY,EAAW,KAI3B,MAAO,CACL,KAAM,EACN,IAAK,EACN,EAEJ,CACF,EACD,CACD,OAAO,QAAQ,CACnB,CAAC,MAAM"}
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,WAAW,KAAK,QAAQ,GAC5B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}
@@ -1 +1 @@
1
- export{};
1
+ export { };
@@ -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.71",
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.3",
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.407",
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": "9a51041e0817e438c49db05bb757b3bdbaf497ef"
112
+ "gitHead": "9af888c54e58a82744cc334a6b80da52429fa0ac"
113
113
  }