@powerlines/plugin-tsdown 0.1.243 → 0.1.244
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/src/lib/logger.mjs +40 -0
- package/dist/core/src/lib/logger.mjs.map +1 -0
- package/dist/core/src/lib/unplugin/helpers.mjs +19 -0
- package/dist/core/src/lib/unplugin/helpers.mjs.map +1 -0
- package/dist/core/src/lib/unplugin/index.mjs +5 -0
- package/dist/core/src/lib/unplugin/module-resolution.mjs +66 -0
- package/dist/core/src/lib/unplugin/module-resolution.mjs.map +1 -0
- package/dist/core/src/lib/unplugin/plugin.mjs +71 -0
- package/dist/core/src/lib/unplugin/plugin.mjs.map +1 -0
- package/dist/core/src/lib/utilities/format.mjs +29 -0
- package/dist/core/src/lib/utilities/format.mjs.map +1 -0
- package/dist/core/src/lib/utilities/source-file.mjs +21 -0
- package/dist/core/src/lib/utilities/source-file.mjs.map +1 -0
- package/dist/core/src/plugin-utils/build-helpers.mjs +35 -0
- package/dist/core/src/plugin-utils/build-helpers.mjs.map +1 -0
- package/dist/core/src/plugin-utils/context-helpers.mjs +4 -0
- package/dist/core/src/plugin-utils/extend.mjs +5 -0
- package/dist/core/src/plugin-utils/get-config-path.mjs +3 -0
- package/dist/core/src/plugin-utils/helpers.mjs +48 -0
- package/dist/core/src/plugin-utils/helpers.mjs.map +1 -0
- package/dist/core/src/plugin-utils/index.mjs +9 -0
- package/dist/core/src/plugin-utils/merge.mjs +47 -0
- package/dist/core/src/plugin-utils/merge.mjs.map +1 -0
- package/dist/core/src/plugin-utils/paths.mjs +4 -0
- package/dist/core/src/types/api.d.mts +103 -0
- package/dist/core/src/types/api.d.mts.map +1 -0
- package/dist/core/src/types/commands.d.mts +10 -0
- package/dist/core/src/types/commands.d.mts.map +1 -0
- package/dist/core/src/types/commands.mjs +16 -0
- package/dist/core/src/types/commands.mjs.map +1 -0
- package/dist/core/src/types/config.d.mts +551 -0
- package/dist/core/src/types/config.d.mts.map +1 -0
- package/dist/core/src/types/context.d.mts +511 -0
- package/dist/core/src/types/context.d.mts.map +1 -0
- package/dist/core/src/types/fs.d.mts +487 -0
- package/dist/core/src/types/fs.d.mts.map +1 -0
- package/dist/core/src/types/hooks.d.mts +99 -0
- package/dist/core/src/types/hooks.d.mts.map +1 -0
- package/dist/core/src/types/index.d.mts +9 -0
- package/dist/core/src/types/plugin.d.mts +204 -0
- package/dist/core/src/types/plugin.d.mts.map +1 -0
- package/dist/core/src/types/plugin.mjs +33 -0
- package/dist/core/src/types/plugin.mjs.map +1 -0
- package/dist/core/src/types/tsconfig.d.mts +70 -0
- package/dist/core/src/types/tsconfig.d.mts.map +1 -0
- package/dist/core/src/types/unplugin.d.mts +25 -0
- package/dist/core/src/types/unplugin.d.mts.map +1 -0
- package/dist/core/src/types/unplugin.mjs +22 -0
- package/dist/core/src/types/unplugin.mjs.map +1 -0
- package/dist/helpers/format-package-json.mjs +4 -4
- package/dist/helpers/format-package-json.mjs.map +1 -1
- package/dist/helpers/index.d.mts +3 -1
- package/dist/helpers/index.mjs +3 -1
- package/dist/helpers/resolve-options.d.mts +31 -0
- package/dist/helpers/resolve-options.d.mts.map +1 -0
- package/dist/helpers/resolve-options.mjs +124 -0
- package/dist/helpers/resolve-options.mjs.map +1 -0
- package/dist/helpers/unplugin.mjs +2 -1
- package/dist/helpers/unplugin.mjs.map +1 -1
- package/dist/index.d.mts +6 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +6 -9
- package/dist/index.mjs.map +1 -1
- package/dist/types/build.d.mts +8 -0
- package/dist/types/build.d.mts.map +1 -0
- package/dist/types/build.mjs +1 -0
- package/dist/types/index.d.mts +2 -1
- package/dist/types/plugin.d.mts +11 -7
- package/dist/types/plugin.d.mts.map +1 -1
- package/package.json +28 -107
- package/dist/_virtual/rolldown_runtime.cjs +0 -29
- package/dist/helpers/format-package-json.cjs +0 -19
- package/dist/helpers/format-package-json.d.cts +0 -13
- package/dist/helpers/format-package-json.d.cts.map +0 -1
- package/dist/helpers/index.cjs +0 -3
- package/dist/helpers/index.d.cts +0 -2
- package/dist/helpers/unplugin.cjs +0 -11
- package/dist/helpers/unplugin.d.cts +0 -8
- package/dist/helpers/unplugin.d.cts.map +0 -1
- package/dist/index.cjs +0 -43
- package/dist/index.d.cts +0 -14
- package/dist/index.d.cts.map +0 -1
- package/dist/node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/is-type.cjs +0 -28
- package/dist/node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/is-type.mjs +0 -29
- package/dist/node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/is-type.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/join-paths.cjs +0 -122
- package/dist/node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/join-paths.mjs +0 -123
- package/dist/node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/join-paths.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/regex.cjs +0 -12
- package/dist/node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/regex.mjs +0 -9
- package/dist/node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/regex.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/slash.cjs +0 -15
- package/dist/node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/slash.mjs +0 -15
- package/dist/node_modules/.pnpm/@stryke_path@0.26.6/node_modules/@stryke/path/dist/slash.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-empty.cjs +0 -20
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-empty.mjs +0 -21
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-empty.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-null.cjs +0 -12
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-null.mjs +0 -12
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-null.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-set-string.cjs +0 -20
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-set-string.mjs +0 -21
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-set-string.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-set.cjs +0 -19
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-set.mjs +0 -20
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-set.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-string.cjs +0 -12
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-string.mjs +0 -12
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-string.mjs.map +0 -1
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-undefined.cjs +0 -8
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-undefined.mjs +0 -8
- package/dist/node_modules/.pnpm/@stryke_type-checks@0.5.25/node_modules/@stryke/type-checks/dist/is-undefined.mjs.map +0 -1
- package/dist/types/index.cjs +0 -0
- package/dist/types/index.d.cts +0 -2
- package/dist/types/plugin.cjs +0 -0
- package/dist/types/plugin.d.cts +0 -17
- package/dist/types/plugin.d.cts.map +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
2
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
3
|
+
import { titleCase } from "@stryke/string-format/title-case";
|
|
4
|
+
import "@storm-software/config-tools/logger";
|
|
5
|
+
import "@storm-software/config-tools/utilities/colors";
|
|
6
|
+
import "@stryke/helpers/noop";
|
|
7
|
+
import chalk from "chalk";
|
|
8
|
+
|
|
9
|
+
//#region ../core/src/lib/logger.ts
|
|
10
|
+
const BADGE_COLORS = [
|
|
11
|
+
"#00A0DD",
|
|
12
|
+
"#6FCE4E",
|
|
13
|
+
"#FBBF24",
|
|
14
|
+
"#F43F5E",
|
|
15
|
+
"#3B82F6",
|
|
16
|
+
"#A855F7",
|
|
17
|
+
"#469592",
|
|
18
|
+
"#288EDF",
|
|
19
|
+
"#D8B4FE",
|
|
20
|
+
"#10B981",
|
|
21
|
+
"#EF4444",
|
|
22
|
+
"#F0EC56",
|
|
23
|
+
"#F472B6",
|
|
24
|
+
"#22D3EE",
|
|
25
|
+
"#EAB308",
|
|
26
|
+
"#84CC16",
|
|
27
|
+
"#F87171",
|
|
28
|
+
"#0EA5E9",
|
|
29
|
+
"#D946EF",
|
|
30
|
+
"#FACC15",
|
|
31
|
+
"#34D399",
|
|
32
|
+
"#8B5CF6"
|
|
33
|
+
];
|
|
34
|
+
const extendLog = (logFn, name) => {
|
|
35
|
+
return (type, ...args) => logFn(type, ` ${chalk.inverse.hex(BADGE_COLORS[name.split("").map((char) => char.charCodeAt(0)).reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length] || BADGE_COLORS[0])(` ${titleCase(name)} `)} ${args.join(" ")} `);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { extendLog };
|
|
40
|
+
//# sourceMappingURL=logger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.mjs","names":[],"sources":["../../../../../core/src/lib/logger.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 { getLogFn, getLogLevel } from \"@storm-software/config-tools/logger\";\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { getColor } from \"@storm-software/config-tools/utilities/colors\";\nimport { noop } from \"@stryke/helpers/noop\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport chalk from \"chalk\";\nimport type { LogFn, WorkspaceConfig } from \"../types\";\n\nexport interface CreateLogOptions {\n name?: string;\n logLevel?: LogLevelLabel | null;\n customLogger?: LogFn;\n colors?: WorkspaceConfig[\"colors\"];\n}\n\n/**\n * Create a logging function with a specific name and options.\n *\n * @param name - The name of the logging function.\n * @param options - The options to configure the logging function.\n * @returns A logging function.\n */\nexport const createLog = (\n name: string | null,\n options: CreateLogOptions = {}\n): LogFn => {\n const logLevel =\n options.logLevel === null\n ? LogLevelLabel.SILENT\n : options.logLevel || LogLevelLabel.INFO;\n if (logLevel === LogLevelLabel.SILENT) {\n return noop;\n }\n\n if (options.customLogger) {\n return options.customLogger;\n }\n\n return (type: LogLevelLabel, ...args: string[]) =>\n getLogFn(getLogLevel(type), {\n ...options,\n logLevel\n })(\n `${chalk.bold.hex(\n getColor(\"brand\", options as Parameters<typeof getColor>[1])\n )(\n `${name ? kebabCase(name) : \"\"}${options.name ? `${name ? chalk.gray(\" > \") : \"\"}${kebabCase(options.name)}` : \"\"}${chalk.gray(\" > \")}`\n )}${args.join(\" \")} `.trim()\n );\n};\n\nconst BADGE_COLORS = [\n \"#00A0DD\",\n \"#6FCE4E\",\n \"#FBBF24\",\n \"#F43F5E\",\n \"#3B82F6\",\n \"#A855F7\",\n \"#469592\",\n \"#288EDF\",\n \"#D8B4FE\",\n \"#10B981\",\n \"#EF4444\",\n \"#F0EC56\",\n \"#F472B6\",\n \"#22D3EE\",\n \"#EAB308\",\n \"#84CC16\",\n \"#F87171\",\n \"#0EA5E9\",\n \"#D946EF\",\n \"#FACC15\",\n \"#34D399\",\n \"#8B5CF6\"\n] as const;\n\nexport const extendLog = (logFn: LogFn, name: string): LogFn => {\n return (type: LogLevelLabel, ...args: string[]) =>\n logFn(\n type,\n ` ${chalk.inverse.hex(\n BADGE_COLORS[\n name\n .split(\"\")\n .map(char => char.charCodeAt(0))\n .reduce((ret, charCode) => ret + charCode, 0) % BADGE_COLORS.length\n ] || BADGE_COLORS[0]\n )(` ${titleCase(name)} `)} ${args.join(\" \")} `\n );\n};\n"],"mappings":";;;;;;;;;AAsEA,MAAM,eAAe;CACnB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,aAAa,OAAc,SAAwB;AAC9D,SAAQ,MAAqB,GAAG,SAC9B,MACE,MACA,IAAI,MAAM,QAAQ,IAChB,aACE,KACG,MAAM,GAAG,CACT,KAAI,SAAQ,KAAK,WAAW,EAAE,CAAC,CAC/B,QAAQ,KAAK,aAAa,MAAM,UAAU,EAAE,GAAG,aAAa,WAC5D,aAAa,GACnB,CAAC,IAAI,UAAU,KAAK,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,GAC9C"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import "../../types/unplugin.mjs";
|
|
2
|
+
import { defu } from "defu";
|
|
3
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
4
|
+
|
|
5
|
+
//#region ../core/src/lib/unplugin/helpers.ts
|
|
6
|
+
/**
|
|
7
|
+
* Merges a base plugin context with an unplugin context, combining their properties.
|
|
8
|
+
*
|
|
9
|
+
* @param contextA - The base plugin context to merge into.
|
|
10
|
+
* @param contextB - The unplugin context to merge from.
|
|
11
|
+
* @returns The merged context.
|
|
12
|
+
*/
|
|
13
|
+
function combineContexts(contextA, contextB) {
|
|
14
|
+
return defu(contextA, contextB);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
export { combineContexts };
|
|
19
|
+
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../../../../core/src/lib/unplugin/helpers.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 { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { defu } from \"defu\";\nimport { UnpluginBuildContext } from \"unplugin\";\nimport { UnresolvedContext } from \"../../types/context\";\nimport {\n UNPLUGIN_BUILDER_VARIANTS,\n UnpluginBuilderVariant\n} from \"../../types/unplugin\";\n\n/**\n * Merges a base plugin context with an unplugin context, combining their properties.\n *\n * @param contextA - The base plugin context to merge into.\n * @param contextB - The unplugin context to merge from.\n * @returns The merged context.\n */\nexport function combineContexts<\n TContextA extends UnresolvedContext | UnpluginBuildContext,\n TContextB extends UnresolvedContext | UnpluginBuildContext\n>(contextA: TContextA, contextB: TContextB): TContextA & TContextB {\n return defu(contextA, contextB) as TContextA & TContextB;\n}\n\n/**\n * Checks if a value is a valid UnpluginBuilderVariant.\n *\n * @param str - The value to check.\n * @returns True if the value is a UnpluginBuilderVariant, false otherwise.\n */\nexport function isUnpluginBuilderVariant(\n str: unknown\n): str is UnpluginBuilderVariant {\n return (\n isSetString(str) &&\n UNPLUGIN_BUILDER_VARIANTS.includes(str as UnpluginBuilderVariant)\n );\n}\n"],"mappings":";;;;;;;;;;;;AAkCA,SAAgB,gBAGd,UAAqB,UAA4C;AACjE,QAAO,KAAK,UAAU,SAAS"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//#region ../core/src/lib/unplugin/module-resolution.ts
|
|
2
|
+
/**
|
|
3
|
+
* Creates the module resolution hook functions for a Powerlines unplugin plugin instance.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* This includes the `resolveId` and `load` hooks.
|
|
7
|
+
*
|
|
8
|
+
* @see https://rollupjs.org/plugin-development/#resolveid
|
|
9
|
+
* @see https://rollupjs.org/plugin-development/#load
|
|
10
|
+
*
|
|
11
|
+
* @param context - The plugin context.
|
|
12
|
+
* @returns The module resolution hooks (`resolveId` and `load`).
|
|
13
|
+
*/
|
|
14
|
+
function createUnpluginModuleResolutionFunctions(context) {
|
|
15
|
+
const ctx = context;
|
|
16
|
+
async function resolveId(id, importer, opts = { isEntry: false }) {
|
|
17
|
+
let result = await ctx.$$internal.callHook("resolveId", {
|
|
18
|
+
sequential: true,
|
|
19
|
+
result: "first",
|
|
20
|
+
order: "pre"
|
|
21
|
+
}, id, importer, opts);
|
|
22
|
+
if (result) return result;
|
|
23
|
+
result = await ctx.$$internal.callHook("resolveId", {
|
|
24
|
+
sequential: true,
|
|
25
|
+
result: "first",
|
|
26
|
+
order: "normal"
|
|
27
|
+
}, id, importer, opts);
|
|
28
|
+
if (result) return result;
|
|
29
|
+
result = await ctx.resolve(id, importer, opts);
|
|
30
|
+
if (result) return result;
|
|
31
|
+
return ctx.$$internal.callHook("resolveId", {
|
|
32
|
+
sequential: true,
|
|
33
|
+
result: "first",
|
|
34
|
+
order: "post"
|
|
35
|
+
}, id, importer, opts);
|
|
36
|
+
}
|
|
37
|
+
async function load(id) {
|
|
38
|
+
let result = await ctx.$$internal.callHook("load", {
|
|
39
|
+
sequential: true,
|
|
40
|
+
result: "first",
|
|
41
|
+
order: "pre"
|
|
42
|
+
}, id);
|
|
43
|
+
if (result) return result;
|
|
44
|
+
result = await ctx.$$internal.callHook("load", {
|
|
45
|
+
sequential: true,
|
|
46
|
+
result: "first",
|
|
47
|
+
order: "normal"
|
|
48
|
+
}, id);
|
|
49
|
+
if (result) return result;
|
|
50
|
+
result = await ctx.load(id);
|
|
51
|
+
if (result) return result;
|
|
52
|
+
return ctx.$$internal.callHook("load", {
|
|
53
|
+
sequential: true,
|
|
54
|
+
result: "first",
|
|
55
|
+
order: "post"
|
|
56
|
+
}, id);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
resolveId,
|
|
60
|
+
load
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { createUnpluginModuleResolutionFunctions };
|
|
66
|
+
//# sourceMappingURL=module-resolution.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-resolution.mjs","names":[],"sources":["../../../../../../core/src/lib/unplugin/module-resolution.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 { LoadResult } from \"rollup\";\nimport type {\n ExternalIdResult,\n HookFnMap,\n UnpluginBuildContext,\n UnpluginContext\n} from \"unplugin\";\nimport { UNSAFE_PluginContext } from \"../../types/_internal\";\nimport { PluginContext } from \"../../types/context\";\n\n/**\n * Creates the module resolution hook functions for a Powerlines unplugin plugin instance.\n *\n * @remarks\n * This includes the `resolveId` and `load` hooks.\n *\n * @see https://rollupjs.org/plugin-development/#resolveid\n * @see https://rollupjs.org/plugin-development/#load\n *\n * @param context - The plugin context.\n * @returns The module resolution hooks (`resolveId` and `load`).\n */\nexport function createUnpluginModuleResolutionFunctions<\n TContext extends PluginContext = PluginContext\n>(context: TContext): Pick<HookFnMap, \"resolveId\" | \"load\"> {\n const ctx = context as unknown as UNSAFE_PluginContext;\n\n async function resolveId(\n this: UnpluginBuildContext & UnpluginContext,\n id: string,\n importer?: string,\n opts: {\n isEntry: boolean;\n } = { isEntry: false }\n ): Promise<string | ExternalIdResult | null | undefined> {\n let result = await ctx.$$internal.callHook(\n \"resolveId\",\n {\n sequential: true,\n result: \"first\",\n order: \"pre\"\n },\n id,\n importer,\n opts\n );\n if (result) {\n return result;\n }\n\n result = await ctx.$$internal.callHook(\n \"resolveId\",\n {\n sequential: true,\n result: \"first\",\n order: \"normal\"\n },\n id,\n importer,\n opts\n );\n if (result) {\n return result;\n }\n\n result = await ctx.resolve(id, importer, opts);\n if (result) {\n return result;\n }\n\n return ctx.$$internal.callHook(\n \"resolveId\",\n {\n sequential: true,\n result: \"first\",\n order: \"post\"\n },\n id,\n importer,\n opts\n );\n }\n\n async function load(\n this: UnpluginBuildContext & UnpluginContext,\n id: string\n ): Promise<LoadResult | null | undefined> {\n let result = await ctx.$$internal.callHook(\n \"load\",\n {\n sequential: true,\n result: \"first\",\n order: \"pre\"\n },\n id\n );\n if (result) {\n return result;\n }\n\n result = await ctx.$$internal.callHook(\n \"load\",\n {\n sequential: true,\n result: \"first\",\n order: \"normal\"\n },\n id\n );\n if (result) {\n return result;\n }\n\n result = await ctx.load(id);\n if (result) {\n return result;\n }\n\n return ctx.$$internal.callHook(\n \"load\",\n {\n sequential: true,\n result: \"first\",\n order: \"post\"\n },\n id\n );\n }\n\n return {\n resolveId,\n load\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAwCA,SAAgB,wCAEd,SAA0D;CAC1D,MAAM,MAAM;CAEZ,eAAe,UAEb,IACA,UACA,OAEI,EAAE,SAAS,OAAO,EACiC;EACvD,IAAI,SAAS,MAAM,IAAI,WAAW,SAChC,aACA;GACE,YAAY;GACZ,QAAQ;GACR,OAAO;GACR,EACD,IACA,UACA,KACD;AACD,MAAI,OACF,QAAO;AAGT,WAAS,MAAM,IAAI,WAAW,SAC5B,aACA;GACE,YAAY;GACZ,QAAQ;GACR,OAAO;GACR,EACD,IACA,UACA,KACD;AACD,MAAI,OACF,QAAO;AAGT,WAAS,MAAM,IAAI,QAAQ,IAAI,UAAU,KAAK;AAC9C,MAAI,OACF,QAAO;AAGT,SAAO,IAAI,WAAW,SACpB,aACA;GACE,YAAY;GACZ,QAAQ;GACR,OAAO;GACR,EACD,IACA,UACA,KACD;;CAGH,eAAe,KAEb,IACwC;EACxC,IAAI,SAAS,MAAM,IAAI,WAAW,SAChC,QACA;GACE,YAAY;GACZ,QAAQ;GACR,OAAO;GACR,EACD,GACD;AACD,MAAI,OACF,QAAO;AAGT,WAAS,MAAM,IAAI,WAAW,SAC5B,QACA;GACE,YAAY;GACZ,QAAQ;GACR,OAAO;GACR,EACD,GACD;AACD,MAAI,OACF,QAAO;AAGT,WAAS,MAAM,IAAI,KAAK,GAAG;AAC3B,MAAI,OACF,QAAO;AAGT,SAAO,IAAI,WAAW,SACpB,QACA;GACE,YAAY;GACZ,QAAQ;GACR,OAAO;GACR,EACD,GACD;;AAGH,QAAO;EACL;EACA;EACD"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { combineContexts } from "./helpers.mjs";
|
|
2
|
+
import { createUnpluginModuleResolutionFunctions } from "./module-resolution.mjs";
|
|
3
|
+
import { extendLog } from "../logger.mjs";
|
|
4
|
+
import { getString } from "../utilities/source-file.mjs";
|
|
5
|
+
import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
6
|
+
import { kebabCase } from "@stryke/string-format/kebab-case";
|
|
7
|
+
import { titleCase } from "@stryke/string-format/title-case";
|
|
8
|
+
import { setParseImpl } from "unplugin";
|
|
9
|
+
|
|
10
|
+
//#region ../core/src/lib/unplugin/plugin.ts
|
|
11
|
+
/**
|
|
12
|
+
* Creates a Powerlines unplugin instance.
|
|
13
|
+
*
|
|
14
|
+
* @param context - The plugin context.
|
|
15
|
+
* @returns The unplugin instance.
|
|
16
|
+
*/
|
|
17
|
+
function createUnplugin(context, name = "unplugin") {
|
|
18
|
+
const ctx = context;
|
|
19
|
+
setParseImpl(ctx.parse);
|
|
20
|
+
return () => {
|
|
21
|
+
const log = extendLog(ctx.log, name);
|
|
22
|
+
log(LogLevelLabel.DEBUG, `Initializing ${name.toLowerCase() === "unplugin" ? "Unplugin" : `${titleCase(name)} - Unplugin`} plugin`);
|
|
23
|
+
try {
|
|
24
|
+
const { resolveId, load } = createUnpluginModuleResolutionFunctions(context);
|
|
25
|
+
async function buildStart() {
|
|
26
|
+
log(LogLevelLabel.DEBUG, "Powerlines build plugin starting...");
|
|
27
|
+
await ctx.$$internal.callHook("buildStart", { sequential: true });
|
|
28
|
+
}
|
|
29
|
+
async function transform(code, id) {
|
|
30
|
+
let transformed = code;
|
|
31
|
+
for (const hook of ctx.$$internal.environment.selectHooks("transform")) {
|
|
32
|
+
const result = await hook.handler.apply(combineContexts(ctx, this), [getString(transformed), id]);
|
|
33
|
+
if (result) transformed = result;
|
|
34
|
+
}
|
|
35
|
+
return transformed;
|
|
36
|
+
}
|
|
37
|
+
async function buildEnd() {
|
|
38
|
+
log(LogLevelLabel.DEBUG, "Powerlines build plugin finishing...");
|
|
39
|
+
return ctx.$$internal.callHook("buildEnd", { sequential: true });
|
|
40
|
+
}
|
|
41
|
+
async function writeBundle() {
|
|
42
|
+
log(LogLevelLabel.DEBUG, "Finalizing Powerlines project output...");
|
|
43
|
+
return ctx.$$internal.callHook("writeBundle", { sequential: true });
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
name: name.toLowerCase() === "unplugin" ? "powerlines" : `powerlines:${kebabCase(name)}`,
|
|
47
|
+
api: ctx.$$internal.api,
|
|
48
|
+
resolveId: {
|
|
49
|
+
filter: { id: { include: [/.*/] } },
|
|
50
|
+
handler: resolveId
|
|
51
|
+
},
|
|
52
|
+
load: {
|
|
53
|
+
filter: { id: { include: [/.*/] } },
|
|
54
|
+
handler: load
|
|
55
|
+
},
|
|
56
|
+
transform,
|
|
57
|
+
buildStart,
|
|
58
|
+
buildEnd,
|
|
59
|
+
writeBundle,
|
|
60
|
+
vite: { sharedDuringBuild: true }
|
|
61
|
+
};
|
|
62
|
+
} catch (error) {
|
|
63
|
+
log(LogLevelLabel.FATAL, error?.message);
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
export { createUnplugin };
|
|
71
|
+
//# sourceMappingURL=plugin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.mjs","names":["transformed: TransformResult | string","result: TransformResult | string | undefined"],"sources":["../../../../../../core/src/lib/unplugin/plugin.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 { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport type {\n TransformResult,\n UnpluginBuildContext,\n UnpluginContext\n} from \"unplugin\";\nimport { setParseImpl } from \"unplugin\";\nimport { UNSAFE_PluginContext } from \"../../types/_internal\";\nimport { PluginContext } from \"../../types/context\";\nimport { UnpluginFactory } from \"../../types/unplugin\";\nimport { extendLog } from \"../logger\";\nimport { getString } from \"../utilities/source-file\";\nimport { combineContexts } from \"./helpers\";\nimport { createUnpluginModuleResolutionFunctions } from \"./module-resolution\";\n\n/**\n * Creates a Powerlines unplugin instance.\n *\n * @param context - The plugin context.\n * @returns The unplugin instance.\n */\nexport function createUnpluginResolver<\n TContext extends PluginContext = PluginContext\n>(context: TContext, name = \"unplugin\"): UnpluginFactory<TContext> {\n const ctx = context as unknown as UNSAFE_PluginContext;\n setParseImpl(ctx.parse);\n\n return () => {\n const log = extendLog(ctx.log, name);\n log(\n LogLevelLabel.DEBUG,\n `Initializing ${\n name.toLowerCase() === \"unplugin\"\n ? \"Unplugin\"\n : `${titleCase(name)} - Unplugin`\n } plugin`\n );\n\n try {\n const { resolveId, load } =\n createUnpluginModuleResolutionFunctions<TContext>(context);\n\n return {\n name:\n name.toLowerCase() === \"unplugin\"\n ? \"powerlines\"\n : `powerlines:${kebabCase(name)}`,\n api: ctx.$$internal.api,\n resolveId: {\n filter: {\n id: {\n include: [/.*/]\n }\n },\n handler: resolveId\n },\n load: {\n filter: {\n id: {\n include: [/.*/]\n }\n },\n handler: load\n }\n };\n } catch (error) {\n log(LogLevelLabel.FATAL, (error as Error)?.message);\n\n throw error;\n }\n };\n}\n\n/**\n * Creates a Powerlines unplugin instance.\n *\n * @param context - The plugin context.\n * @returns The unplugin instance.\n */\nexport function createUnplugin<TContext extends PluginContext = PluginContext>(\n context: TContext,\n name = \"unplugin\"\n): UnpluginFactory<TContext> {\n const ctx = context as unknown as UNSAFE_PluginContext;\n setParseImpl(ctx.parse);\n\n return () => {\n const log = extendLog(ctx.log, name);\n log(\n LogLevelLabel.DEBUG,\n `Initializing ${\n name.toLowerCase() === \"unplugin\"\n ? \"Unplugin\"\n : `${titleCase(name)} - Unplugin`\n } plugin`\n );\n\n try {\n const { resolveId, load } =\n createUnpluginModuleResolutionFunctions<TContext>(context);\n\n async function buildStart(this: UnpluginBuildContext) {\n log(LogLevelLabel.DEBUG, \"Powerlines build plugin starting...\");\n\n await ctx.$$internal.callHook(\"buildStart\", {\n sequential: true\n });\n }\n\n async function transform(\n this: UnpluginBuildContext & UnpluginContext,\n code: string,\n id: string\n ): Promise<TransformResult | null | undefined> {\n let transformed: TransformResult | string = code;\n\n for (const hook of ctx.$$internal.environment.selectHooks(\n \"transform\"\n )) {\n const result: TransformResult | string | undefined =\n await hook.handler.apply(combineContexts(ctx, this), [\n getString(transformed),\n id\n ]);\n if (result) {\n transformed = result;\n }\n }\n\n return transformed;\n }\n\n async function buildEnd(this: UnpluginBuildContext): Promise<void> {\n log(LogLevelLabel.DEBUG, \"Powerlines build plugin finishing...\");\n\n return ctx.$$internal.callHook(\"buildEnd\", {\n sequential: true\n });\n }\n\n async function writeBundle(): Promise<void> {\n log(LogLevelLabel.DEBUG, \"Finalizing Powerlines project output...\");\n\n return ctx.$$internal.callHook(\"writeBundle\", {\n sequential: true\n });\n }\n\n return {\n name:\n name.toLowerCase() === \"unplugin\"\n ? \"powerlines\"\n : `powerlines:${kebabCase(name)}`,\n api: ctx.$$internal.api,\n resolveId: {\n filter: {\n id: {\n include: [/.*/]\n }\n },\n handler: resolveId\n },\n load: {\n filter: {\n id: {\n include: [/.*/]\n }\n },\n handler: load\n },\n transform,\n buildStart,\n buildEnd,\n writeBundle,\n vite: {\n sharedDuringBuild: true\n }\n };\n } catch (error) {\n log(LogLevelLabel.FATAL, (error as Error)?.message);\n\n throw error;\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmGA,SAAgB,eACd,SACA,OAAO,YACoB;CAC3B,MAAM,MAAM;AACZ,cAAa,IAAI,MAAM;AAEvB,cAAa;EACX,MAAM,MAAM,UAAU,IAAI,KAAK,KAAK;AACpC,MACE,cAAc,OACd,gBACE,KAAK,aAAa,KAAK,aACnB,aACA,GAAG,UAAU,KAAK,CAAC,aACxB,SACF;AAED,MAAI;GACF,MAAM,EAAE,WAAW,SACjB,wCAAkD,QAAQ;GAE5D,eAAe,aAAuC;AACpD,QAAI,cAAc,OAAO,sCAAsC;AAE/D,UAAM,IAAI,WAAW,SAAS,cAAc,EAC1C,YAAY,MACb,CAAC;;GAGJ,eAAe,UAEb,MACA,IAC6C;IAC7C,IAAIA,cAAwC;AAE5C,SAAK,MAAM,QAAQ,IAAI,WAAW,YAAY,YAC5C,YACD,EAAE;KACD,MAAMC,SACJ,MAAM,KAAK,QAAQ,MAAM,gBAAgB,KAAK,KAAK,EAAE,CACnD,UAAU,YAAY,EACtB,GACD,CAAC;AACJ,SAAI,OACF,eAAc;;AAIlB,WAAO;;GAGT,eAAe,WAAoD;AACjE,QAAI,cAAc,OAAO,uCAAuC;AAEhE,WAAO,IAAI,WAAW,SAAS,YAAY,EACzC,YAAY,MACb,CAAC;;GAGJ,eAAe,cAA6B;AAC1C,QAAI,cAAc,OAAO,0CAA0C;AAEnE,WAAO,IAAI,WAAW,SAAS,eAAe,EAC5C,YAAY,MACb,CAAC;;AAGJ,UAAO;IACL,MACE,KAAK,aAAa,KAAK,aACnB,eACA,cAAc,UAAU,KAAK;IACnC,KAAK,IAAI,WAAW;IACpB,WAAW;KACT,QAAQ,EACN,IAAI,EACF,SAAS,CAAC,KAAK,EAChB,EACF;KACD,SAAS;KACV;IACD,MAAM;KACJ,QAAQ,EACN,IAAI,EACF,SAAS,CAAC,KAAK,EAChB,EACF;KACD,SAAS;KACV;IACD;IACA;IACA;IACA;IACA,MAAM,EACJ,mBAAmB,MACpB;IACF;WACM,OAAO;AACd,OAAI,cAAc,OAAQ,OAAiB,QAAQ;AAEnD,SAAM"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import "@stryke/fs/list-files";
|
|
2
|
+
import { appendPath } from "@stryke/path/append";
|
|
3
|
+
import { isParentPath } from "@stryke/path/is-parent-path";
|
|
4
|
+
import { format, resolveConfig } from "prettier";
|
|
5
|
+
|
|
6
|
+
//#region ../core/src/lib/utilities/format.ts
|
|
7
|
+
/**
|
|
8
|
+
* Formats code using Prettier based on the file path.
|
|
9
|
+
*
|
|
10
|
+
* @param context - The Powerlines context.
|
|
11
|
+
* @param path - The file path to use for resolving Prettier configuration.
|
|
12
|
+
* @param data - The code string to format.
|
|
13
|
+
* @param force - Whether to force formatting even for output/build paths.
|
|
14
|
+
* @returns A promise that resolves to the formatted code string.
|
|
15
|
+
*/
|
|
16
|
+
async function format$1(context, path, data, force = false) {
|
|
17
|
+
if (!force && (isParentPath(path, appendPath(context.config.output.outputPath, context.workspaceConfig.workspaceRoot)) || isParentPath(path, appendPath(context.config.output.buildPath, context.workspaceConfig.workspaceRoot)))) return data;
|
|
18
|
+
let code = data;
|
|
19
|
+
const resolvedConfig = await resolveConfig(path);
|
|
20
|
+
if (resolvedConfig) code = await format(data, {
|
|
21
|
+
absolutePath: path,
|
|
22
|
+
...resolvedConfig
|
|
23
|
+
});
|
|
24
|
+
return code;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { format$1 as format };
|
|
29
|
+
//# sourceMappingURL=format.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.mjs","names":["format","prettier"],"sources":["../../../../../../core/src/lib/utilities/format.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 { listFiles } from \"@stryke/fs/list-files\";\nimport { appendPath } from \"@stryke/path/append\";\nimport { isParentPath } from \"@stryke/path/is-parent-path\";\nimport { format as prettier, resolveConfig } from \"prettier\";\nimport { Context } from \"../../types/context\";\n\n/**\n * Formats code using Prettier based on the file path.\n *\n * @param context - The Powerlines context.\n * @param path - The file path to use for resolving Prettier configuration.\n * @param data - The code string to format.\n * @param force - Whether to force formatting even for output/build paths.\n * @returns A promise that resolves to the formatted code string.\n */\nexport async function format(\n context: Context,\n path: string,\n data: string,\n force = false\n): Promise<string> {\n if (\n !force &&\n (isParentPath(\n path,\n appendPath(\n context.config.output.outputPath,\n context.workspaceConfig.workspaceRoot\n )\n ) ||\n isParentPath(\n path,\n appendPath(\n context.config.output.buildPath,\n context.workspaceConfig.workspaceRoot\n )\n ))\n ) {\n return data;\n }\n\n let code = data;\n const resolvedConfig = await resolveConfig(path);\n if (resolvedConfig) {\n code = await prettier(data, {\n absolutePath: path,\n ...resolvedConfig\n });\n }\n\n return code;\n}\n\n/**\n * Formats all files in a folder using Prettier based on their file paths.\n *\n * @param context - The Powerlines context.\n * @param path - The folder path containing files to format.\n * @returns A promise that resolves when all files have been formatted.\n */\nexport async function formatFolder(context: Context, path: string) {\n if (\n !isParentPath(\n path,\n appendPath(\n context.config.output.outputPath,\n context.workspaceConfig.workspaceRoot\n )\n ) &&\n !isParentPath(\n path,\n appendPath(\n context.config.output.buildPath,\n context.workspaceConfig.workspaceRoot\n )\n )\n ) {\n await Promise.allSettled(\n (await listFiles(path)).map(async file => {\n if (\n !isParentPath(\n file,\n appendPath(\n context.config.output.outputPath,\n context.workspaceConfig.workspaceRoot\n )\n ) &&\n !isParentPath(\n file,\n appendPath(\n context.config.output.buildPath,\n context.workspaceConfig.workspaceRoot\n )\n )\n ) {\n const data = await context.fs.read(file);\n if (data) {\n const formatted = await format(context, file, data);\n\n return context.fs.write(file, formatted);\n }\n }\n })\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAiCA,eAAsBA,SACpB,SACA,MACA,MACA,QAAQ,OACS;AACjB,KACE,CAAC,UACA,aACC,MACA,WACE,QAAQ,OAAO,OAAO,YACtB,QAAQ,gBAAgB,cACzB,CACF,IACC,aACE,MACA,WACE,QAAQ,OAAO,OAAO,WACtB,QAAQ,gBAAgB,cACzB,CACF,EAEH,QAAO;CAGT,IAAI,OAAO;CACX,MAAM,iBAAiB,MAAM,cAAc,KAAK;AAChD,KAAI,eACF,QAAO,MAAMC,OAAS,MAAM;EAC1B,cAAc;EACd,GAAG;EACJ,CAAC;AAGJ,QAAO"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
2
|
+
import { isString } from "@stryke/type-checks/is-string";
|
|
3
|
+
import "@stryke/fs/read-file";
|
|
4
|
+
|
|
5
|
+
//#region ../core/src/lib/utilities/source-file.ts
|
|
6
|
+
/**
|
|
7
|
+
* Get the string from the source.
|
|
8
|
+
*
|
|
9
|
+
* @param code - The source string or magic string.
|
|
10
|
+
* @returns The source string.
|
|
11
|
+
*/
|
|
12
|
+
function getString(code) {
|
|
13
|
+
if (!code) return "";
|
|
14
|
+
if (isString(code)) return code;
|
|
15
|
+
if (isSetObject(code) && "code" in code) return code.code;
|
|
16
|
+
return code.toString();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { getString };
|
|
21
|
+
//# sourceMappingURL=source-file.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-file.mjs","names":[],"sources":["../../../../../../core/src/lib/utilities/source-file.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 { readFileIfExistingSync } from \"@stryke/fs/read-file\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport MagicString from \"magic-string\";\nimport { TransformResult } from \"unplugin\";\nimport { SourceFile } from \"../../types/context\";\n\n/**\n * Get the string from the source.\n *\n * @param code - The source string or magic string.\n * @returns The source string.\n */\nexport function getString(\n code: string | MagicString | TransformResult\n): string {\n if (!code) {\n return \"\";\n }\n\n if (isString(code)) {\n return code;\n }\n\n if (isSetObject(code) && \"code\" in code) {\n return code.code;\n }\n\n return code.toString();\n}\n\n/**\n * Get the magic string.\n *\n * @param code - The source string or magic string.\n * @returns The magic string.\n */\nexport function getMagicString(code: string | MagicString): MagicString {\n if (isString(code)) {\n return new MagicString(code);\n }\n\n return code;\n}\n\n/**\n * Get the source file.\n *\n * @param code - The source code.\n * @param id - The name of the file.\n * @returns The source file.\n */\nexport function getSourceFile(\n code: string | MagicString,\n id: string\n): SourceFile {\n const content = code ?? readFileIfExistingSync(id);\n\n return {\n id,\n code: getMagicString(content),\n env: []\n };\n}\n"],"mappings":";;;;;;;;;;;AA+BA,SAAgB,UACd,MACQ;AACR,KAAI,CAAC,KACH,QAAO;AAGT,KAAI,SAAS,KAAK,CAChB,QAAO;AAGT,KAAI,YAAY,KAAK,IAAI,UAAU,KACjC,QAAO,KAAK;AAGd,QAAO,KAAK,UAAU"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
2
|
+
import { toArray } from "@stryke/convert/to-array";
|
|
3
|
+
import { getUnique } from "@stryke/helpers/get-unique";
|
|
4
|
+
import { isRegExp } from "@stryke/type-checks/is-regexp";
|
|
5
|
+
|
|
6
|
+
//#region ../core/src/plugin-utils/build-helpers.ts
|
|
7
|
+
/**
|
|
8
|
+
* Get the {@link ResolveConfig.external | external} and {@link ResolveConfig.noExternal | noExternal} dependencies for the build configuration.
|
|
9
|
+
*
|
|
10
|
+
* @param context - The build context.
|
|
11
|
+
* @returns The dependency configuration.
|
|
12
|
+
*/
|
|
13
|
+
function getDependencyConfig(context) {
|
|
14
|
+
const noExternal = getUnique(toArray(context.config.resolve.noExternal).concat(context.builtins));
|
|
15
|
+
const external = getUnique(toArray(context.config.resolve.external).reduce((ret, ext) => {
|
|
16
|
+
if (isRegExp(ext)) {
|
|
17
|
+
if (noExternal.some((noExt) => isRegExp(noExt) && noExt.source === ext.source)) return ret;
|
|
18
|
+
const noExts = noExternal.filter((noExt) => isSetString(noExt) && ext.test(noExt));
|
|
19
|
+
if (noExts.length > 0) {
|
|
20
|
+
ret.push(new RegExp(noExts.reduce((regex, noExt) => `(?!${isRegExp(noExt) ? noExt.source : `^${noExt}$`})${regex}`, `${ext.source.replace(/^\^@\?/, "^@").replace(/^@\?/, "@").replace(/\$$/, "").replace(/\.\*$/, "")}.*$`)));
|
|
21
|
+
return ret;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
ret.push(ext);
|
|
25
|
+
return ret;
|
|
26
|
+
}, []));
|
|
27
|
+
return {
|
|
28
|
+
external: external.length === 0 ? void 0 : external,
|
|
29
|
+
noExternal: noExternal.length === 0 ? void 0 : noExternal
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { getDependencyConfig };
|
|
35
|
+
//# sourceMappingURL=build-helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-helpers.mjs","names":[],"sources":["../../../../../core/src/plugin-utils/build-helpers.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 { toArray } from \"@stryke/convert/to-array\";\nimport { getUnique } from \"@stryke/helpers/get-unique\";\nimport { isRegExp } from \"@stryke/type-checks/is-regexp\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { ResolveConfig } from \"../types/config\";\nimport { Context } from \"../types/context\";\n\nexport interface GetDependencyConfigResult {\n external: ResolveConfig[\"external\"];\n noExternal: ResolveConfig[\"noExternal\"];\n}\n\n/**\n * Get the {@link ResolveConfig.external | external} and {@link ResolveConfig.noExternal | noExternal} dependencies for the build configuration.\n *\n * @param context - The build context.\n * @returns The dependency configuration.\n */\nexport function getDependencyConfig(\n context: Context\n): GetDependencyConfigResult {\n const noExternal = getUnique(\n toArray(context.config.resolve.noExternal).concat(context.builtins)\n );\n\n const external = getUnique(\n toArray(context.config.resolve.external).reduce(\n (ret, ext) => {\n if (isRegExp(ext)) {\n if (\n noExternal.some(\n noExt => isRegExp(noExt) && noExt.source === ext.source\n )\n ) {\n return ret;\n }\n\n const noExts = noExternal.filter(\n noExt => isSetString(noExt) && ext.test(noExt)\n );\n if (noExts.length > 0) {\n ret.push(\n new RegExp(\n noExts.reduce(\n (regex: string, noExt: string | RegExp) =>\n `(?!${\n isRegExp(noExt) ? noExt.source : `^${noExt}$`\n })${regex}`,\n `${ext.source\n .replace(/^\\^@\\?/, \"^@\")\n .replace(/^@\\?/, \"@\")\n .replace(/\\$$/, \"\")\n .replace(/\\.\\*$/, \"\")}.*$`\n )\n )\n );\n return ret;\n }\n }\n\n ret.push(ext);\n return ret;\n },\n [] as (string | RegExp)[]\n )\n );\n\n return {\n external: external.length === 0 ? undefined : external,\n noExternal: noExternal.length === 0 ? undefined : noExternal\n };\n}\n"],"mappings":";;;;;;;;;;;;AAoCA,SAAgB,oBACd,SAC2B;CAC3B,MAAM,aAAa,UACjB,QAAQ,QAAQ,OAAO,QAAQ,WAAW,CAAC,OAAO,QAAQ,SAAS,CACpE;CAED,MAAM,WAAW,UACf,QAAQ,QAAQ,OAAO,QAAQ,SAAS,CAAC,QACtC,KAAK,QAAQ;AACZ,MAAI,SAAS,IAAI,EAAE;AACjB,OACE,WAAW,MACT,UAAS,SAAS,MAAM,IAAI,MAAM,WAAW,IAAI,OAClD,CAED,QAAO;GAGT,MAAM,SAAS,WAAW,QACxB,UAAS,YAAY,MAAM,IAAI,IAAI,KAAK,MAAM,CAC/C;AACD,OAAI,OAAO,SAAS,GAAG;AACrB,QAAI,KACF,IAAI,OACF,OAAO,QACJ,OAAe,UACd,MACE,SAAS,MAAM,GAAG,MAAM,SAAS,IAAI,MAAM,GAC5C,GAAG,SACN,GAAG,IAAI,OACJ,QAAQ,UAAU,KAAK,CACvB,QAAQ,QAAQ,IAAI,CACpB,QAAQ,OAAO,GAAG,CAClB,QAAQ,SAAS,GAAG,CAAC,KACzB,CACF,CACF;AACD,WAAO;;;AAIX,MAAI,KAAK,IAAI;AACb,SAAO;IAET,EAAE,CACH,CACF;AAED,QAAO;EACL,UAAU,SAAS,WAAW,IAAI,SAAY;EAC9C,YAAY,WAAW,WAAW,IAAI,SAAY;EACnD"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import "../types/unplugin.mjs";
|
|
2
|
+
import "../types/plugin.mjs";
|
|
3
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
4
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
5
|
+
import { isFunction } from "@stryke/type-checks/is-function";
|
|
6
|
+
import "@stryke/type-checks/is-undefined";
|
|
7
|
+
|
|
8
|
+
//#region ../core/src/plugin-utils/helpers.ts
|
|
9
|
+
/**
|
|
10
|
+
* Type guard to check if an value is a {@link PluginHook} function
|
|
11
|
+
*
|
|
12
|
+
* @param value - The value to check
|
|
13
|
+
* @returns True if the value is a {@link PluginHook} function, false otherwise
|
|
14
|
+
*/
|
|
15
|
+
function isPluginHookObject(value) {
|
|
16
|
+
return isSetObject(value) && "handler" in value && isFunction(value.handler);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Type guard to check if an value is a {@link PluginHook} function
|
|
20
|
+
*
|
|
21
|
+
* @param value - The value to check
|
|
22
|
+
* @returns True if the value is a {@link PluginHook} function, false otherwise
|
|
23
|
+
*/
|
|
24
|
+
function isPluginHookFunction(value) {
|
|
25
|
+
return isFunction(value) || isPluginHookObject(value);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Type guard to check if an object is a {@link PluginHook}
|
|
29
|
+
*
|
|
30
|
+
* @param value - The object to check
|
|
31
|
+
* @returns True if the object is a {@link PluginHook}, false otherwise
|
|
32
|
+
*/
|
|
33
|
+
function isPluginHook(value) {
|
|
34
|
+
return isPluginHookFunction(value) || isPluginHookObject(value);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Extract the hook handler function from a plugin hook
|
|
38
|
+
*
|
|
39
|
+
* @param pluginHook - The plugin hook to extract the handler function from
|
|
40
|
+
* @returns The hook handler function
|
|
41
|
+
*/
|
|
42
|
+
function getHookHandler(pluginHook) {
|
|
43
|
+
return isFunction(pluginHook) ? pluginHook : pluginHook.handler;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { getHookHandler, isPluginHook, isPluginHookFunction, isPluginHookObject };
|
|
48
|
+
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../../../core/src/plugin-utils/helpers.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 { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isUndefined } from \"@stryke/type-checks/is-undefined\";\nimport { AnyFunction } from \"@stryke/types/base\";\nimport {\n PluginConfig,\n PluginConfigObject,\n PluginConfigTuple,\n ResolvedConfig\n} from \"../types/config\";\nimport { PluginContext, WithUnpluginBuildContext } from \"../types/context\";\nimport {\n HookFields,\n PluginHooksListItem,\n UnpluginHooksListItem\n} from \"../types/hooks\";\nimport {\n PLUGIN_HOOKS_FIELDS,\n Plugin,\n PluginHook,\n PluginHookFields,\n PluginHookObject,\n PluginHooks\n} from \"../types/plugin\";\nimport {\n BUILDER_VARIANTS,\n UNPLUGIN_BUILDER_VARIANTS,\n UnpluginBuilderVariant,\n UnpluginOptions\n} from \"../types/unplugin\";\n\n/**\n * Type guard to check if an object is a {@link Plugin}\n *\n * @param value - The object to check\n * @returns True if the object is a {@link Plugin}, false otherwise\n */\nexport function isPlugin<\n TContext extends PluginContext = PluginContext<ResolvedConfig>\n>(value: unknown): value is Plugin<TContext> {\n return (\n isSetObject(value) &&\n \"name\" in value &&\n isSetString(value.name) &&\n (isUndefined((value as Plugin<TContext>).api) ||\n (\"api\" in value && isSetObject(value.api))) &&\n (isUndefined((value as Plugin<TContext>).applyToEnvironment) ||\n (\"applyToEnvironment\" in value &&\n isFunction(value.applyToEnvironment))) &&\n (isUndefined((value as Plugin<TContext>).dedupe) ||\n (\"dedupe\" in value && isFunction(value.dedupe))) &&\n PLUGIN_HOOKS_FIELDS.every(\n hook =>\n isUndefined((value as Plugin<TContext>)[hook]) ||\n (hook in value &&\n (isPluginHookFunction((value as Plugin<TContext>)[hook]) ||\n (hook === \"config\" &&\n isSetObject((value as Plugin<TContext>)[hook]))))\n ) &&\n BUILDER_VARIANTS.every(\n variant =>\n isUndefined((value as Plugin<TContext>)[variant]) ||\n (variant in value && isSetObject((value as Plugin<TContext>)[variant]))\n )\n );\n}\n\n/**\n * Type guard to check if an object is a {@link PluginConfigObject}\n *\n * @param value - The object to check\n * @returns True if the object is a {@link PluginConfigObject}, false otherwise\n */\nexport function isPluginConfigObject<\n TContext extends PluginContext = PluginContext<ResolvedConfig>\n>(value: unknown): value is PluginConfigObject<TContext> {\n return (\n isSetObject(value) &&\n \"plugin\" in value &&\n (((isSetString(value.plugin) || isFunction(value.plugin)) &&\n \"options\" in value &&\n isSetObject(value.options)) ||\n isPlugin(value.plugin))\n );\n}\n\n/**\n * Type guard to check if an object is a {@link PluginConfigTuple}\n *\n * @param value - The object to check\n * @returns True if the object is a {@link PluginConfigTuple}, false otherwise\n */\nexport function isPluginConfigTuple<\n TContext extends PluginContext = PluginContext<ResolvedConfig>\n>(value: unknown): value is PluginConfigTuple<TContext> {\n return (\n Array.isArray(value) &&\n (value.length === 1 || value.length === 2) &&\n (((isSetString(value[0]) || isFunction(value[0])) &&\n value.length > 1 &&\n isSetObject(value[1])) ||\n isPlugin(value[0]))\n );\n}\n\n/**\n * Type guard to check if an object is a {@link PluginConfig}\n *\n * @param value - The object to check\n * @returns True if the object is a {@link PluginConfig}, false otherwise\n */\nexport function isPluginConfig<\n TContext extends PluginContext = PluginContext<ResolvedConfig>\n>(value: unknown): value is PluginConfig<TContext> {\n return (\n isSetString(value) ||\n isFunction(value) ||\n isPlugin<TContext>(value) ||\n isPluginConfigObject(value) ||\n isPluginConfigTuple(value) ||\n (Array.isArray(value) && value.every(item => isPluginConfig(item)))\n );\n}\n\n/**\n * Type guard to check if an value is a {@link PluginHook} function\n *\n * @param value - The value to check\n * @returns True if the value is a {@link PluginHook} function, false otherwise\n */\nexport function isPluginHookObject(\n value: unknown\n): value is PluginHookObject<AnyFunction> {\n return isSetObject(value) && \"handler\" in value && isFunction(value.handler);\n}\n\n/**\n * Type guard to check if an value is a {@link PluginHook} function\n *\n * @param value - The value to check\n * @returns True if the value is a {@link PluginHook} function, false otherwise\n */\nexport function isPluginHookFunction(value: unknown): value is AnyFunction {\n return isFunction(value) || isPluginHookObject(value);\n}\n\n/**\n * Type guard to check if an object is a {@link PluginHook}\n *\n * @param value - The object to check\n * @returns True if the object is a {@link PluginHook}, false otherwise\n */\nexport function isPluginHook(value: unknown): value is PluginHook<AnyFunction> {\n return isPluginHookFunction(value) || isPluginHookObject(value);\n}\n\nexport type GetHookHandlerReturnType<\n TContext extends PluginContext = PluginContext,\n TField extends HookFields<TContext> = HookFields<TContext>\n> = TField extends PluginHookFields\n ? PluginHooksListItem<TContext, TField>[\"handler\"]\n : TField extends UnpluginBuilderVariant\n ? UnpluginHooksListItem<TContext, TField>[\"handler\"]\n : never;\n\ntype HooksListItemForField<\n TContext extends PluginContext = PluginContext,\n TField extends HookFields<TContext> = HookFields<TContext>\n> =\n TField extends PluginHookFields<TContext>\n ? PluginHooksListItem<TContext, Extract<TField, PluginHookFields<TContext>>>\n : TField extends UnpluginBuilderVariant\n ? UnpluginHooksListItem<TContext, Extract<TField, UnpluginBuilderVariant>>\n : never;\n\n/**\n * Extract the hook handler function from a plugin hook\n *\n * @param pluginHook - The plugin hook to extract the handler function from\n * @returns The hook handler function\n */\nexport function getHookHandler<\n TContext extends PluginContext = PluginContext,\n TField extends HookFields<TContext> = HookFields<TContext>\n>(\n pluginHook: PluginHook<AnyFunction>\n): GetHookHandlerReturnType<TContext, TField> {\n return (\n isFunction(pluginHook) ? pluginHook : pluginHook.handler\n ) as GetHookHandlerReturnType<TContext, TField>;\n}\n\n/**\n * Extract a plugin hook from a plugin\n *\n * @param context - The build context\n * @param plugin - The plugin to extract the hook from\n * @param hook - The name of the hook to extract\n * @returns The extracted hook, or undefined if the hook does not exist\n */\nexport function extractPluginHook<\n TContext extends PluginContext = PluginContext,\n TPlugin extends Plugin<TContext> = Plugin<TContext>\n>(context: TContext, plugin: TPlugin, hook: keyof PluginHooks<TContext>) {\n const pluginHook = plugin[hook];\n if (!isPluginHook(pluginHook)) {\n return undefined;\n }\n\n return isFunction(pluginHook)\n ? {\n normal: pluginHook.bind(context)\n }\n : {\n [pluginHook.order ? pluginHook.order : \"normal\"]:\n pluginHook.handler.bind(context)\n };\n}\n\n/**\n * Check if a hook is external.\n *\n * @param keys - The name of the hook to check.\n * @returns True if the hook is external, false otherwise.\n */\nexport function isUnpluginHookKey<\n TUnpluginBuilderVariant extends UnpluginBuilderVariant =\n UnpluginBuilderVariant\n>(\n keys: string\n): keys is `${TUnpluginBuilderVariant}:${keyof UnpluginOptions[TUnpluginBuilderVariant] & string}` {\n return UNPLUGIN_BUILDER_VARIANTS.some(variant =>\n keys.startsWith(`${variant}:`)\n );\n}\n\n/**\n * Check if a hook is internal.\n *\n * @param keys - The name of the hook to check.\n * @returns True if the hook is external, false otherwise.\n */\nexport function isPluginHookField<TContext extends PluginContext>(\n keys: string\n): keys is PluginHookFields<TContext> {\n return (\n !isUnpluginHookKey(keys) &&\n PLUGIN_HOOKS_FIELDS.includes(keys as PluginHookFields<TContext>)\n );\n}\n\n/**\n * Check if a hook is external.\n *\n * @param field - The name of the hook to check.\n * @returns True if the hook is external, false otherwise.\n */\nexport function isUnpluginHookField<\n TUnpluginBuilderVariant extends UnpluginBuilderVariant =\n UnpluginBuilderVariant\n>(field: string): field is TUnpluginBuilderVariant {\n return (\n !isPluginHookField(field) &&\n UNPLUGIN_BUILDER_VARIANTS.includes(field as UnpluginBuilderVariant)\n );\n}\n\n/**\n * Check if a plugin should be deduplicated.\n *\n * @param plugin - The plugin to check\n * @param plugins - The list of plugins to check against\n * @returns True if the plugin should be deduplicated, false otherwise\n */\nexport function checkDedupe<\n TResolvedConfig extends ResolvedConfig = ResolvedConfig,\n TContext extends PluginContext<TResolvedConfig> =\n PluginContext<TResolvedConfig>\n>(plugin: Plugin<TContext>, plugins: Plugin<TContext>[]) {\n return (\n plugin.dedupe === false ||\n plugins.some(\n p =>\n p.dedupe !== false &&\n ((isFunction(p.dedupe) && p.dedupe(plugin)) || p.name === plugin.name)\n )\n );\n}\n\n/**\n * Add a plugin hook to the hooks list.\n *\n * @param context - The plugin context\n * @param plugin - The plugin to add the hook from\n * @param pluginHook - The plugin hook to add\n * @param hooksList - The list of hooks to add to\n */\nexport function addPluginHook<\n TContext extends PluginContext = PluginContext,\n TField extends PluginHookFields<TContext> = PluginHookFields<TContext>,\n TList extends PluginHooksListItem<TContext, TField> = PluginHooksListItem<\n TContext,\n TField\n >\n>(\n context: TContext,\n plugin: Plugin<TContext>,\n pluginHook: PluginHook<AnyFunction>,\n hooksList: TList[]\n) {\n if (\n !checkDedupe(plugin, hooksList.map(hook => hook.plugin).filter(Boolean))\n ) {\n const handler = ((...args: unknown[]) =>\n (\n getHookHandler<WithUnpluginBuildContext<TContext>, TField>(\n pluginHook\n ) as unknown as (...args: unknown[]) => unknown\n ).apply(context, args)) as HooksListItemForField<\n TContext,\n TField\n >[\"handler\"];\n if (!handler) {\n return;\n }\n\n hooksList.push({\n plugin,\n handler\n } as any);\n }\n}\n\n/**\n * Check the provided {@link PluginConfig}, and return a stringified version of the invalid configuration. If an array is provided, check each item in the array.\n *\n * @param config - The plugin configuration to check\n * @returns Null if the configuration is valid, otherwise an array of stringified invalid configurations\n */\nexport function findInvalidPluginConfig<\n TContext extends PluginContext = PluginContext<ResolvedConfig>\n>(config: PluginConfig<TContext>): string[] | null {\n if (isPluginConfig<TContext>(config)) {\n return null;\n }\n\n if (Array.isArray(config as PluginConfig<TContext>[])) {\n const invalidItems: string[] = [];\n (config as PluginConfig<TContext>[]).forEach(item => {\n const invalid = findInvalidPluginConfig<TContext>(item);\n if (invalid) {\n invalidItems.push(...invalid.map(i => JSON.stringify(i, null, 2)));\n }\n });\n\n return invalidItems.length > 0 ? invalidItems : null;\n }\n\n return [JSON.stringify(config, null, 2)];\n}\n"],"mappings":";;;;;;;;;;;;;;AAqJA,SAAgB,mBACd,OACwC;AACxC,QAAO,YAAY,MAAM,IAAI,aAAa,SAAS,WAAW,MAAM,QAAQ;;;;;;;;AAS9E,SAAgB,qBAAqB,OAAsC;AACzE,QAAO,WAAW,MAAM,IAAI,mBAAmB,MAAM;;;;;;;;AASvD,SAAgB,aAAa,OAAkD;AAC7E,QAAO,qBAAqB,MAAM,IAAI,mBAAmB,MAAM;;;;;;;;AA4BjE,SAAgB,eAId,YAC4C;AAC5C,QACE,WAAW,WAAW,GAAG,aAAa,WAAW"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getDependencyConfig } from "./build-helpers.mjs";
|
|
2
|
+
import "./context-helpers.mjs";
|
|
3
|
+
import { getHookHandler, isPluginHook, isPluginHookFunction, isPluginHookObject } from "./helpers.mjs";
|
|
4
|
+
import "./merge.mjs";
|
|
5
|
+
import "./extend.mjs";
|
|
6
|
+
import "./get-config-path.mjs";
|
|
7
|
+
import "./paths.mjs";
|
|
8
|
+
|
|
9
|
+
export { };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getHookHandler, isPluginHook } from "./helpers.mjs";
|
|
2
|
+
import defu$1, { createDefu } from "defu";
|
|
3
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
4
|
+
import { isString } from "@stryke/type-checks/is-string";
|
|
5
|
+
|
|
6
|
+
//#region ../core/src/plugin-utils/merge.ts
|
|
7
|
+
const mergePlugin = createDefu((obj, key, value) => {
|
|
8
|
+
if (isPluginHook(obj[key]) && isPluginHook(value)) {
|
|
9
|
+
obj[key] = {
|
|
10
|
+
...obj[key],
|
|
11
|
+
...value,
|
|
12
|
+
handler: async (...params) => {
|
|
13
|
+
const [resultA, resultB] = await Promise.all([getHookHandler(obj[key])(...params), getHookHandler(value)(...params)]);
|
|
14
|
+
return resultB && resultA ? defu$1(resultA, resultB) : resultA || resultB;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Merges two configuration objects together, with special handling for string values.
|
|
23
|
+
* If the value from the second object is a non-empty string, it will overwrite the value from the first object.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const configA = { name: "Default", version: "1.0.0" };
|
|
28
|
+
* const configB = { name: "Custom", description: "A custom config" };
|
|
29
|
+
* const mergedConfig = mergeConfig(configA, configB);
|
|
30
|
+
* // Result: { name: "Custom", version: "1.0.0", description: "A custom config" }
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param objA - The first configuration object.
|
|
34
|
+
* @param objB - The second configuration object.
|
|
35
|
+
* @returns The merged configuration object.
|
|
36
|
+
*/
|
|
37
|
+
const mergeConfig = createDefu((obj, key, value) => {
|
|
38
|
+
if (isString(obj[key]) && isString(value)) {
|
|
39
|
+
if (isSetString(value)) obj[key] = value;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
export { };
|
|
47
|
+
//# sourceMappingURL=merge.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.mjs","names":["defu"],"sources":["../../../../../core/src/plugin-utils/merge.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 { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport defu, { createDefu } from \"defu\";\nimport { PartialPlugin, ResolvedConfig } from \"../types/config\";\nimport { PluginContext } from \"../types/context\";\nimport { Plugin } from \"../types/plugin\";\nimport { getHookHandler, isPluginHook } from \"./helpers\";\n\nexport type MergeResult<\n TContext extends PluginContext,\n TPluginA extends Plugin<TContext> | PartialPlugin<TContext>,\n TPluginB extends Plugin<TContext> | PartialPlugin<TContext>\n> =\n TPluginA extends Plugin<TContext>\n ? Plugin<TContext>\n : TPluginB extends Plugin<TContext>\n ? Plugin<TContext>\n : PartialPlugin<TContext>;\n\nconst mergePlugin = createDefu((obj, key, value) => {\n if (isPluginHook(obj[key]) && isPluginHook(value)) {\n obj[key] = {\n ...obj[key],\n ...value,\n handler: async (...params: any[]) => {\n const [resultA, resultB] = await Promise.all([\n // eslint-disable-next-line ts/no-unsafe-call\n (getHookHandler(obj[key]) as any)(...params),\n // eslint-disable-next-line ts/no-unsafe-call\n (getHookHandler(value) as any)(...params)\n ]);\n\n return resultB && resultA ? defu(resultA, resultB) : resultA || resultB;\n }\n };\n return true;\n }\n\n return false;\n});\n\n/**\n * Merges two {@link Plugin | plugins} or {@link PartialPlugin | partial plugins} together.\n *\n * @param pluginA - The first {@link Plugin | plugin} or {@link PartialPlugin | partial plugin} to merge.\n * @param pluginB - The second {@link Plugin | plugin} or {@link PartialPlugin | partial plugin} to merge.\n * @returns The merged {@link Plugin | plugin} or {@link PartialPlugin | partial plugin}.\n */\nexport function merge<TContext extends PluginContext = PluginContext>(\n pluginA: Plugin<TContext> | PartialPlugin<TContext>,\n pluginB: Plugin<TContext> | PartialPlugin<TContext>\n): MergeResult<TContext, typeof pluginA, typeof pluginB> {\n return mergePlugin(pluginA, pluginB) as MergeResult<\n TContext,\n typeof pluginA,\n typeof pluginB\n >;\n}\n\n/**\n * Merges two configuration objects together, with special handling for string values.\n * If the value from the second object is a non-empty string, it will overwrite the value from the first object.\n *\n * @example\n * ```ts\n * const configA = { name: \"Default\", version: \"1.0.0\" };\n * const configB = { name: \"Custom\", description: \"A custom config\" };\n * const mergedConfig = mergeConfig(configA, configB);\n * // Result: { name: \"Custom\", version: \"1.0.0\", description: \"A custom config\" }\n * ```\n *\n * @param objA - The first configuration object.\n * @param objB - The second configuration object.\n * @returns The merged configuration object.\n */\nexport const mergeConfig = createDefu((obj, key, value) => {\n if (isString(obj[key]) && isString(value)) {\n if (isSetString(value)) {\n obj[key] = value;\n }\n\n return true;\n }\n\n return false;\n}) as (...configs: unknown[]) => ResolvedConfig;\n"],"mappings":";;;;;;AAqCA,MAAM,cAAc,YAAY,KAAK,KAAK,UAAU;AAClD,KAAI,aAAa,IAAI,KAAK,IAAI,aAAa,MAAM,EAAE;AACjD,MAAI,OAAO;GACT,GAAG,IAAI;GACP,GAAG;GACH,SAAS,OAAO,GAAG,WAAkB;IACnC,MAAM,CAAC,SAAS,WAAW,MAAM,QAAQ,IAAI,CAE1C,eAAe,IAAI,KAAK,CAAS,GAAG,OAAO,EAE3C,eAAe,MAAM,CAAS,GAAG,OAAO,CAC1C,CAAC;AAEF,WAAO,WAAW,UAAUA,OAAK,SAAS,QAAQ,GAAG,WAAW;;GAEnE;AACD,SAAO;;AAGT,QAAO;EACP;;;;;;;;;;;;;;;;;AAoCF,MAAa,cAAc,YAAY,KAAK,KAAK,UAAU;AACzD,KAAI,SAAS,IAAI,KAAK,IAAI,SAAS,MAAM,EAAE;AACzC,MAAI,YAAY,MAAM,CACpB,KAAI,OAAO;AAGb,SAAO;;AAGT,QAAO;EACP"}
|