@powerlines/core 0.48.44 → 0.48.46

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.
Files changed (35) hide show
  1. package/dist/context/context.mjs.map +1 -1
  2. package/dist/context/environment-context.mjs.map +1 -1
  3. package/dist/context/execution-context.mjs.map +1 -1
  4. package/dist/context/plugin-context.mjs.map +1 -1
  5. package/dist/lib/config.mjs.map +1 -1
  6. package/dist/lib/context-helpers.mjs.map +1 -1
  7. package/dist/lib/entry.mjs.map +1 -1
  8. package/dist/lib/environment.mjs.map +1 -1
  9. package/dist/lib/events.mjs.map +1 -1
  10. package/dist/lib/generate-types.mjs.map +1 -1
  11. package/dist/lib/hooks.mjs.map +1 -1
  12. package/dist/lib/install-dependencies.mjs.map +1 -1
  13. package/dist/lib/plugins.mjs.map +1 -1
  14. package/dist/lib/typescript/ts-morph.mjs.map +1 -1
  15. package/dist/lib/typescript/tsconfig.mjs.map +1 -1
  16. package/dist/lib/utilities/file-header.mjs.map +1 -1
  17. package/dist/lib/utilities/format.mjs.map +1 -1
  18. package/dist/lib/vfs.mjs.map +1 -1
  19. package/dist/plugin-base.mjs.map +1 -1
  20. package/dist/plugin-utils/build-helpers.mjs.map +1 -1
  21. package/dist/plugin-utils/combine-plugins.mjs.map +1 -1
  22. package/dist/plugin-utils/context-helpers.mjs.map +1 -1
  23. package/dist/plugin-utils/enable-plugin.mjs.map +1 -1
  24. package/dist/plugin-utils/extend.mjs.map +1 -1
  25. package/dist/plugin-utils/filter.mjs.map +1 -1
  26. package/dist/plugin-utils/format.mjs.map +1 -1
  27. package/dist/plugin-utils/helpers.mjs.map +1 -1
  28. package/dist/plugin-utils/logging.mjs.map +1 -1
  29. package/dist/plugin-utils/merge.mjs.map +1 -1
  30. package/dist/plugin-utils/modules.mjs.map +1 -1
  31. package/dist/plugin-utils/paths.mjs.map +1 -1
  32. package/dist/storage/base.mjs.map +1 -1
  33. package/dist/storage/file-system.mjs.map +1 -1
  34. package/dist/storage/virtual.mjs.map +1 -1
  35. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"extend.mjs","names":[],"sources":["../../src/plugin-utils/extend.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 { isFunction } from \"@stryke/type-checks/is-function\";\nimport {\n PartialPlugin,\n PartialPluginFactory,\n PluginFactory\n} from \"../types/config\";\nimport { PluginContext } from \"../types/context\";\nimport { Plugin } from \"../types/plugin\";\nimport { merge } from \"./merge\";\n\n/**\n * Adds additional helper functionality to a plugin via a plugin builder function.\n *\n * @param plugin - The base plugin object or factory function to extend.\n * @param extension - The plugin extension object or factory function. This function receives the plugin options and returns a plugin object.\n * @returns A function accepting the plugin options and returning the extended plugin.\n */\nexport function extend<\n TContext extends PluginContext = PluginContext,\n TPluginOptions = unknown,\n TExtensionOptions = unknown\n>(\n plugin: PluginFactory<TContext, TPluginOptions>,\n extension: PartialPluginFactory<TContext, TExtensionOptions>\n): PluginFactory<TContext, TPluginOptions & TExtensionOptions>;\nexport function extend<\n TContext extends PluginContext = PluginContext,\n TPluginOptions = unknown\n>(\n plugin: PluginFactory<TContext, TPluginOptions>,\n extension: PartialPlugin<TContext>\n): PluginFactory<TContext, TPluginOptions>;\nexport function extend<\n TContext extends PluginContext = PluginContext,\n TExtensionOptions = unknown\n>(\n plugin: Plugin<TContext> | Plugin<TContext>[],\n extension: PartialPluginFactory<TContext, TExtensionOptions>\n): PluginFactory<TContext, TExtensionOptions>;\nexport function extend<TContext extends PluginContext = PluginContext>(\n plugin: Plugin<TContext> | Plugin<TContext>[],\n extension: PartialPlugin<TContext>\n): Plugin<TContext>[];\nexport function extend<TContext extends PluginContext = PluginContext>(\n plugin: Plugin<TContext> | Plugin<TContext>[] | PluginFactory<TContext, any>,\n extension: PartialPlugin<TContext> | PartialPluginFactory<TContext, any>\n): PluginFactory<TContext, any> | Plugin<TContext>[] {\n if (isFunction(plugin)) {\n if (isFunction(extension)) {\n return async (options: any) => {\n const pluginResult = toArray(await Promise.resolve(plugin(options)));\n const extensionResult = toArray(\n await Promise.resolve(extension(options))\n );\n\n return pluginResult\n .map(p => extensionResult.map(e => merge(p, e) as Plugin<TContext>))\n .flat();\n };\n }\n\n return async (options: any) => {\n const result = toArray(await Promise.resolve(plugin(options)));\n\n return result.map(p => merge(p, extension) as Plugin<TContext>);\n };\n } else if (isFunction(extension)) {\n return async (options: any) => {\n const result = toArray(await Promise.resolve(extension(options)));\n\n return result\n .map(e => toArray(plugin).map(p => merge(p, e) as Plugin<TContext>))\n .flat();\n };\n }\n\n return toArray(plugin).map(p => merge(p, extension) as Plugin<TContext>);\n}\n"],"mappings":";;;;;AA8DA,SAAgB,OACd,QACA,WACmD;CACnD,IAAI,WAAW,MAAM,GAAG;EACtB,IAAI,WAAW,SAAS,GACtB,OAAO,OAAO,YAAiB;GAC7B,MAAM,eAAe,QAAQ,MAAM,QAAQ,QAAQ,OAAO,OAAO,CAAC,CAAC;GACnE,MAAM,kBAAkB,QACtB,MAAM,QAAQ,QAAQ,UAAU,OAAO,CAAC,CAC1C;GAEA,OAAO,aACJ,KAAI,MAAK,gBAAgB,KAAI,MAAK,MAAM,GAAG,CAAC,CAAqB,CAAC,EAClE,KAAK;EACV;EAGF,OAAO,OAAO,YAAiB;GAG7B,OAFe,QAAQ,MAAM,QAAQ,QAAQ,OAAO,OAAO,CAAC,CAEhD,EAAE,KAAI,MAAK,MAAM,GAAG,SAAS,CAAqB;EAChE;CACF,OAAO,IAAI,WAAW,SAAS,GAC7B,OAAO,OAAO,YAAiB;EAG7B,OAFe,QAAQ,MAAM,QAAQ,QAAQ,UAAU,OAAO,CAAC,CAEnD,EACT,KAAI,MAAK,QAAQ,MAAM,EAAE,KAAI,MAAK,MAAM,GAAG,CAAC,CAAqB,CAAC,EAClE,KAAK;CACV;CAGF,OAAO,QAAQ,MAAM,EAAE,KAAI,MAAK,MAAM,GAAG,SAAS,CAAqB;AACzE"}
1
+ {"version":3,"file":"extend.mjs","names":[],"sources":["../../src/plugin-utils/extend.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 { isFunction } from \"@stryke/type-checks/is-function\";\nimport {\n PartialPlugin,\n PartialPluginFactory,\n PluginFactory\n} from \"../types/config\";\nimport { PluginContext } from \"../types/context\";\nimport { Plugin } from \"../types/plugin\";\nimport { merge } from \"./merge\";\n\n/**\n * Adds additional helper functionality to a plugin via a plugin builder function.\n *\n * @param plugin - The base plugin object or factory function to extend.\n * @param extension - The plugin extension object or factory function. This function receives the plugin options and returns a plugin object.\n * @returns A function accepting the plugin options and returning the extended plugin.\n */\nexport function extend<\n TContext extends PluginContext = PluginContext,\n TPluginOptions = unknown,\n TExtensionOptions = unknown\n>(\n plugin: PluginFactory<TContext, TPluginOptions>,\n extension: PartialPluginFactory<TContext, TExtensionOptions>\n): PluginFactory<TContext, TPluginOptions & TExtensionOptions>;\nexport function extend<\n TContext extends PluginContext = PluginContext,\n TPluginOptions = unknown\n>(\n plugin: PluginFactory<TContext, TPluginOptions>,\n extension: PartialPlugin<TContext>\n): PluginFactory<TContext, TPluginOptions>;\nexport function extend<\n TContext extends PluginContext = PluginContext,\n TExtensionOptions = unknown\n>(\n plugin: Plugin<TContext> | Plugin<TContext>[],\n extension: PartialPluginFactory<TContext, TExtensionOptions>\n): PluginFactory<TContext, TExtensionOptions>;\nexport function extend<TContext extends PluginContext = PluginContext>(\n plugin: Plugin<TContext> | Plugin<TContext>[],\n extension: PartialPlugin<TContext>\n): Plugin<TContext>[];\nexport function extend<TContext extends PluginContext = PluginContext>(\n plugin: Plugin<TContext> | Plugin<TContext>[] | PluginFactory<TContext, any>,\n extension: PartialPlugin<TContext> | PartialPluginFactory<TContext, any>\n): PluginFactory<TContext, any> | Plugin<TContext>[] {\n if (isFunction(plugin)) {\n if (isFunction(extension)) {\n return async (options: any) => {\n const pluginResult = toArray(await Promise.resolve(plugin(options)));\n const extensionResult = toArray(\n await Promise.resolve(extension(options))\n );\n\n return pluginResult\n .map(p => extensionResult.map(e => merge(p, e) as Plugin<TContext>))\n .flat();\n };\n }\n\n return async (options: any) => {\n const result = toArray(await Promise.resolve(plugin(options)));\n\n return result.map(p => merge(p, extension) as Plugin<TContext>);\n };\n } else if (isFunction(extension)) {\n return async (options: any) => {\n const result = toArray(await Promise.resolve(extension(options)));\n\n return result\n .map(e => toArray(plugin).map(p => merge(p, e) as Plugin<TContext>))\n .flat();\n };\n }\n\n return toArray(plugin).map(p => merge(p, extension) as Plugin<TContext>);\n}\n"],"mappings":";;;;;AA8DA,SAAgB,OACd,QACA,WACmD;CACnD,IAAI,WAAW,MAAM,GAAG;EACtB,IAAI,WAAW,SAAS,GACtB,OAAO,OAAO,YAAiB;GAC7B,MAAM,eAAe,QAAQ,MAAM,QAAQ,QAAQ,OAAO,OAAO,CAAC,CAAC;GACnE,MAAM,kBAAkB,QACtB,MAAM,QAAQ,QAAQ,UAAU,OAAO,CAAC,CAC1C;GAEA,OAAO,aACJ,KAAI,MAAK,gBAAgB,KAAI,MAAK,MAAM,GAAG,CAAC,CAAqB,CAAC,CAAC,CACnE,KAAK;EACV;EAGF,OAAO,OAAO,YAAiB;GAG7B,OAFe,QAAQ,MAAM,QAAQ,QAAQ,OAAO,OAAO,CAAC,CAEhD,CAAC,CAAC,KAAI,MAAK,MAAM,GAAG,SAAS,CAAqB;EAChE;CACF,OAAO,IAAI,WAAW,SAAS,GAC7B,OAAO,OAAO,YAAiB;EAG7B,OAFe,QAAQ,MAAM,QAAQ,QAAQ,UAAU,OAAO,CAAC,CAEnD,CAAC,CACV,KAAI,MAAK,QAAQ,MAAM,CAAC,CAAC,KAAI,MAAK,MAAM,GAAG,CAAC,CAAqB,CAAC,CAAC,CACnE,KAAK;CACV;CAGF,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAI,MAAK,MAAM,GAAG,SAAS,CAAqB;AACzE"}
@@ -1 +1 @@
1
- {"version":3,"file":"filter.mjs","names":[],"sources":["../../src/plugin-utils/filter.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 { isAbsolutePath } from \"@stryke/path/is-type\";\nimport { isRegExp } from \"@stryke/type-checks/is-regexp\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolve } from \"node:path\";\nimport picomatch from \"picomatch\";\nimport type { StringFilter, StringOrRegExp } from \"unplugin\";\nimport {\n NormalizedStringFilter,\n PluginFilter,\n TransformHookFilter\n} from \"../types/hooks\";\nimport { removeVirtualPrefix } from \"./virtual\";\n\nconst BACKSLASH_REGEX = /\\\\/g;\nfunction normalize(path: string): string {\n return removeVirtualPrefix(path).replace(BACKSLASH_REGEX, \"/\");\n}\n\nfunction getMatcherString(glob: string, cwd: string) {\n if (glob.startsWith(\"**\") || isAbsolutePath(glob)) {\n return normalize(glob);\n }\n\n const resolved = resolve(cwd, glob);\n\n return normalize(resolved);\n}\n\nexport function patternToIdFilter(pattern: StringOrRegExp): PluginFilter {\n if (pattern instanceof RegExp) {\n return (id: string) => {\n const normalizedId = normalize(id);\n const result = pattern.test(normalizedId);\n pattern.lastIndex = 0;\n return result;\n };\n }\n const cwd = process.cwd();\n const glob = getMatcherString(pattern, cwd);\n const matcher = picomatch(glob, { dot: true });\n\n return (id: string) => {\n const normalizedId = normalize(id);\n\n return matcher(normalizedId);\n };\n}\n\nexport function patternToCodeFilter(pattern: StringOrRegExp): PluginFilter {\n if (pattern instanceof RegExp) {\n return (code: string) => {\n const result = pattern.test(code);\n pattern.lastIndex = 0;\n return result;\n };\n }\n return (code: string) => code.includes(pattern);\n}\n\nexport function createFilter(\n exclude: PluginFilter[] | undefined,\n include: PluginFilter[] | undefined\n): PluginFilter | undefined {\n if (!exclude && !include) {\n return;\n }\n\n return input => {\n if (exclude?.some(filter => filter(input))) {\n return false;\n }\n if (include?.some(filter => filter(input))) {\n return true;\n }\n return !(include && include.length > 0);\n };\n}\n\nexport function normalizeSingleFilter(\n filter: string | RegExp\n): string | RegExp {\n if (isSetString(filter)) {\n return removeVirtualPrefix(filter);\n }\n\n return filter;\n}\n\nexport function normalizeFilter(filter: StringFilter): NormalizedStringFilter {\n if (isSetString(filter) || isRegExp(filter)) {\n return {\n include: [normalizeSingleFilter(filter)]\n };\n }\n\n if (Array.isArray(filter)) {\n return {\n include: filter.map(normalizeSingleFilter)\n };\n }\n\n return {\n exclude: filter.exclude\n ? toArray(filter.exclude).map(normalizeSingleFilter)\n : undefined,\n include: filter.include\n ? toArray(filter.include).map(normalizeSingleFilter)\n : undefined\n };\n}\n\nexport function createIdFilter(\n filter: StringFilter | undefined\n): PluginFilter | undefined {\n if (!filter) return;\n const { exclude, include } = normalizeFilter(filter);\n const excludeFilter = exclude?.map(patternToIdFilter);\n const includeFilter = include?.map(patternToIdFilter);\n\n return createFilter(excludeFilter, includeFilter);\n}\n\nexport function createCodeFilter(\n filter: StringFilter | undefined\n): PluginFilter | undefined {\n if (!filter) return;\n const { exclude, include } = normalizeFilter(filter);\n const excludeFilter = exclude?.map(patternToCodeFilter);\n const includeFilter = include?.map(patternToCodeFilter);\n\n return createFilter(excludeFilter, includeFilter);\n}\n\nexport function createFilterForId(\n filter: StringFilter | undefined\n): PluginFilter | undefined {\n const filterFunction = createIdFilter(filter);\n\n return filterFunction ? id => !!filterFunction(id) : undefined;\n}\n\nexport function createFilterForTransform(\n idFilter: StringFilter | undefined,\n codeFilter: StringFilter | undefined\n): TransformHookFilter | undefined {\n if (!idFilter && !codeFilter) return;\n const idFilterFunction = createIdFilter(idFilter);\n const codeFilterFunction = createCodeFilter(codeFilter);\n\n return (id, code) => {\n let fallback = true;\n if (idFilterFunction) {\n fallback &&= idFilterFunction(id);\n }\n if (!fallback) {\n return false;\n }\n\n if (codeFilterFunction) {\n fallback &&= codeFilterFunction(code);\n }\n return fallback;\n };\n}\n"],"mappings":";;;;;;;;;AAgCA,MAAM,kBAAkB;AACxB,SAAS,UAAU,MAAsB;CACvC,OAAO,oBAAoB,IAAI,EAAE,QAAQ,iBAAiB,GAAG;AAC/D;AAEA,SAAS,iBAAiB,MAAc,KAAa;CACnD,IAAI,KAAK,WAAW,IAAI,KAAK,eAAe,IAAI,GAC9C,OAAO,UAAU,IAAI;CAKvB,OAAO,UAFU,QAAQ,KAAK,IAEN,CAAC;AAC3B;AAEA,SAAgB,kBAAkB,SAAuC;CACvE,IAAI,mBAAmB,QACrB,QAAQ,OAAe;EACrB,MAAM,eAAe,UAAU,EAAE;EACjC,MAAM,SAAS,QAAQ,KAAK,YAAY;EACxC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AM,gBAAgB,SAAS,IAAI,iBAAiB;CAEpD,OAAO,aAAa,eAAe,aAAa;AAClD;AAEA,SAAgB,iBACd,QAC0B;CAC1B,IAAI,CAAC,QAAQ;CACb,MAAM,EAAE,SAAS,YAAY,gBAAgB,MAAM;CACnD,MAAM,gBAAgB,SAAS,IAAI,mBAAmB;CACtD,MAAM,gBAAgB,SAAS,IAAI,mBAAmB;CAEtD,OAAO,aAAa,eAAe,aAAa;AAClD;AAEA,SAAgB,kBACd,QAC0B;CAC1B,MAAM,iBAAiB,eAAe,MAAM;CAE5C,OAAO,kBAAiB,OAAM,CAAC,CAAC,eAAe,EAAE,IAAI;AACvD;AAEA,SAAgB,yBACd,UACA,YACiC;CACjC,IAAI,CAAC,YAAY,CAAC,YAAY;CAC9B,MAAM,mBAAmB,eAAe,QAAQ;CAChD,MAAM,qBAAqB,iBAAiB,UAAU;CAEtD,QAAQ,IAAI,SAAS;EACnB,IAAI,WAAW;EACf,IAAI,kBACF,aAAa,iBAAiB,EAAE;EAElC,IAAI,CAAC,UACH,OAAO;EAGT,IAAI,oBACF,aAAa,mBAAmB,IAAI;EAEtC,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"filter.mjs","names":[],"sources":["../../src/plugin-utils/filter.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 { isAbsolutePath } from \"@stryke/path/is-type\";\nimport { isRegExp } from \"@stryke/type-checks/is-regexp\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { resolve } from \"node:path\";\nimport picomatch from \"picomatch\";\nimport type { StringFilter, StringOrRegExp } from \"unplugin\";\nimport {\n NormalizedStringFilter,\n PluginFilter,\n TransformHookFilter\n} from \"../types/hooks\";\nimport { removeVirtualPrefix } from \"./virtual\";\n\nconst BACKSLASH_REGEX = /\\\\/g;\nfunction normalize(path: string): string {\n return removeVirtualPrefix(path).replace(BACKSLASH_REGEX, \"/\");\n}\n\nfunction getMatcherString(glob: string, cwd: string) {\n if (glob.startsWith(\"**\") || isAbsolutePath(glob)) {\n return normalize(glob);\n }\n\n const resolved = resolve(cwd, glob);\n\n return normalize(resolved);\n}\n\nexport function patternToIdFilter(pattern: StringOrRegExp): PluginFilter {\n if (pattern instanceof RegExp) {\n return (id: string) => {\n const normalizedId = normalize(id);\n const result = pattern.test(normalizedId);\n pattern.lastIndex = 0;\n return result;\n };\n }\n const cwd = process.cwd();\n const glob = getMatcherString(pattern, cwd);\n const matcher = picomatch(glob, { dot: true });\n\n return (id: string) => {\n const normalizedId = normalize(id);\n\n return matcher(normalizedId);\n };\n}\n\nexport function patternToCodeFilter(pattern: StringOrRegExp): PluginFilter {\n if (pattern instanceof RegExp) {\n return (code: string) => {\n const result = pattern.test(code);\n pattern.lastIndex = 0;\n return result;\n };\n }\n return (code: string) => code.includes(pattern);\n}\n\nexport function createFilter(\n exclude: PluginFilter[] | undefined,\n include: PluginFilter[] | undefined\n): PluginFilter | undefined {\n if (!exclude && !include) {\n return;\n }\n\n return input => {\n if (exclude?.some(filter => filter(input))) {\n return false;\n }\n if (include?.some(filter => filter(input))) {\n return true;\n }\n return !(include && include.length > 0);\n };\n}\n\nexport function normalizeSingleFilter(\n filter: string | RegExp\n): string | RegExp {\n if (isSetString(filter)) {\n return removeVirtualPrefix(filter);\n }\n\n return filter;\n}\n\nexport function normalizeFilter(filter: StringFilter): NormalizedStringFilter {\n if (isSetString(filter) || isRegExp(filter)) {\n return {\n include: [normalizeSingleFilter(filter)]\n };\n }\n\n if (Array.isArray(filter)) {\n return {\n include: filter.map(normalizeSingleFilter)\n };\n }\n\n return {\n exclude: filter.exclude\n ? toArray(filter.exclude).map(normalizeSingleFilter)\n : undefined,\n include: filter.include\n ? toArray(filter.include).map(normalizeSingleFilter)\n : undefined\n };\n}\n\nexport function createIdFilter(\n filter: StringFilter | undefined\n): PluginFilter | undefined {\n if (!filter) return;\n const { exclude, include } = normalizeFilter(filter);\n const excludeFilter = exclude?.map(patternToIdFilter);\n const includeFilter = include?.map(patternToIdFilter);\n\n return createFilter(excludeFilter, includeFilter);\n}\n\nexport function createCodeFilter(\n filter: StringFilter | undefined\n): PluginFilter | undefined {\n if (!filter) return;\n const { exclude, include } = normalizeFilter(filter);\n const excludeFilter = exclude?.map(patternToCodeFilter);\n const includeFilter = include?.map(patternToCodeFilter);\n\n return createFilter(excludeFilter, includeFilter);\n}\n\nexport function createFilterForId(\n filter: StringFilter | undefined\n): PluginFilter | undefined {\n const filterFunction = createIdFilter(filter);\n\n return filterFunction ? id => !!filterFunction(id) : undefined;\n}\n\nexport function createFilterForTransform(\n idFilter: StringFilter | undefined,\n codeFilter: StringFilter | undefined\n): TransformHookFilter | undefined {\n if (!idFilter && !codeFilter) return;\n const idFilterFunction = createIdFilter(idFilter);\n const codeFilterFunction = createCodeFilter(codeFilter);\n\n return (id, code) => {\n let fallback = true;\n if (idFilterFunction) {\n fallback &&= idFilterFunction(id);\n }\n if (!fallback) {\n return false;\n }\n\n if (codeFilterFunction) {\n fallback &&= codeFilterFunction(code);\n }\n return fallback;\n };\n}\n"],"mappings":";;;;;;;;;AAgCA,MAAM,kBAAkB;AACxB,SAAS,UAAU,MAAsB;CACvC,OAAO,oBAAoB,IAAI,CAAC,CAAC,QAAQ,iBAAiB,GAAG;AAC/D;AAEA,SAAS,iBAAiB,MAAc,KAAa;CACnD,IAAI,KAAK,WAAW,IAAI,KAAK,eAAe,IAAI,GAC9C,OAAO,UAAU,IAAI;CAKvB,OAAO,UAFU,QAAQ,KAAK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AAI,qBAAqB,IACjD;CACN;AACF;AAEA,SAAgB,eACd,QAC0B;CAC1B,IAAI,CAAC,QAAQ;CACb,MAAM,EAAE,SAAS,YAAY,gBAAgB,MAAM;CACnD,MAAM,gBAAgB,SAAS,IAAI,iBAAiB;CACpD,MAAM,gBAAgB,SAAS,IAAI,iBAAiB;CAEpD,OAAO,aAAa,eAAe,aAAa;AAClD;AAEA,SAAgB,iBACd,QAC0B;CAC1B,IAAI,CAAC,QAAQ;CACb,MAAM,EAAE,SAAS,YAAY,gBAAgB,MAAM;CACnD,MAAM,gBAAgB,SAAS,IAAI,mBAAmB;CACtD,MAAM,gBAAgB,SAAS,IAAI,mBAAmB;CAEtD,OAAO,aAAa,eAAe,aAAa;AAClD;AAEA,SAAgB,kBACd,QAC0B;CAC1B,MAAM,iBAAiB,eAAe,MAAM;CAE5C,OAAO,kBAAiB,OAAM,CAAC,CAAC,eAAe,EAAE,IAAI;AACvD;AAEA,SAAgB,yBACd,UACA,YACiC;CACjC,IAAI,CAAC,YAAY,CAAC,YAAY;CAC9B,MAAM,mBAAmB,eAAe,QAAQ;CAChD,MAAM,qBAAqB,iBAAiB,UAAU;CAEtD,QAAQ,IAAI,SAAS;EACnB,IAAI,WAAW;EACf,IAAI,kBACF,aAAa,iBAAiB,EAAE;EAElC,IAAI,CAAC,UACH,OAAO;EAGT,IAAI,oBACF,aAAa,mBAAmB,IAAI;EAEtC,OAAO;CACT;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"format.mjs","names":[],"sources":["../../src/plugin-utils/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 { toArray } from \"@stryke/convert/to-array\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { isRegExp } from \"@stryke/type-checks/is-regexp\";\nimport { isSetArray } from \"@stryke/type-checks/is-set-array\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { ResolveConfig, ResolvedConfig } from \"../types/config\";\n\n/**\n * Formats a configuration object into a human-readable string, omitting certain properties and simplifying others for better readability.\n *\n * @param config - The configuration object to format.\n * @returns A formatted string representation of the configuration.\n */\nexport function formatConfig(config: Record<string, any>): string {\n return JSON.stringify(\n Object.fromEntries(\n Object.entries({\n ...omit(config, [\n \"deps\",\n \"resolve\",\n \"plugins\",\n \"initialConfig\",\n \"userConfig\",\n \"inlineConfig\",\n \"pluginConfig\",\n \"environmentConfig\"\n ]),\n deps: isSetObject(config.deps)\n ? {\n alwaysBundle: isSetArray(\n (config.deps as { alwaysBundle?: unknown[] })?.alwaysBundle\n )\n ? (\n (config.deps as { alwaysBundle?: unknown[] })\n ?.alwaysBundle ?? []\n )\n .filter(Boolean)\n .map(alwaysBundle =>\n isSetString(alwaysBundle)\n ? alwaysBundle\n : isRegExp(alwaysBundle)\n ? alwaysBundle.source\n : \"<unknown-bundle>\"\n )\n : undefined,\n onlyBundle: isSetArray(\n (config.deps as { onlyBundle?: unknown[] })?.onlyBundle\n )\n ? (\n (config.deps as { onlyBundle?: unknown[] })?.onlyBundle ??\n []\n )\n .filter(Boolean)\n .map(onlyBundle =>\n isSetString(onlyBundle)\n ? onlyBundle\n : isRegExp(onlyBundle)\n ? onlyBundle.source\n : \"<unknown-bundle>\"\n )\n : undefined,\n neverBundle: isSetArray(\n (config.deps as { neverBundle?: unknown[] })?.neverBundle\n )\n ? (\n (config.deps as { neverBundle?: unknown[] })?.neverBundle ??\n []\n )\n .filter(Boolean)\n .map(neverBundle =>\n isSetString(neverBundle)\n ? neverBundle\n : isRegExp(neverBundle)\n ? neverBundle.source\n : \"<unknown-bundle>\"\n )\n : undefined\n }\n : undefined,\n\n resolve: isSetObject(config.resolve)\n ? {\n ...config.resolve,\n external: isSetArray((config.resolve as ResolveConfig)?.external)\n ? ((config.resolve as ResolveConfig)?.external ?? [])\n .filter(Boolean)\n .map(external =>\n isSetString(external)\n ? external\n : isRegExp(external)\n ? external.source\n : \"<unknown-bundle>\"\n )\n : undefined,\n noExternal: isSetArray(\n (config.resolve as ResolveConfig)?.noExternal\n )\n ? ((config.resolve as ResolveConfig)?.noExternal ?? [])\n .filter(Boolean)\n .map(noExternal =>\n isSetString(noExternal)\n ? noExternal\n : isRegExp(noExternal)\n ? noExternal.source\n : \"<unknown-bundle>\"\n )\n : undefined\n }\n : undefined,\n plugins: isSetArray(config.plugins)\n ? (toArray(config.plugins) as ResolvedConfig[\"plugins\"])\n ?.flatMap(plugin => toArray(plugin))\n ?.map(plugin =>\n String(\n isSetString(plugin)\n ? plugin\n : isSetObject(plugin) &&\n isSetString((plugin as { name: string }).name)\n ? (plugin as { name: string }).name\n : Array.isArray(plugin) && isSetString(plugin[0])\n ? plugin[0]\n : \"<function-plugin>\"\n )\n )\n : undefined\n }).sort(([key1], [key2]) => key1.localeCompare(key2))\n ),\n null,\n 4\n )\n .replace(/\"([^\"]+)\":/g, \"$1:\")\n .replace(/,\\s*$/g, \"\");\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,SAAgB,aAAa,QAAqC;CAChE,OAAO,KAAK,UACV,OAAO,YACL,OAAO,QAAQ;EACb,GAAG,KAAK,QAAQ;GACd;GACA;GACA;GACA;GACA;GACA;GACA;GACA;EACF,CAAC;EACD,MAAM,YAAY,OAAO,IAAI,IACzB;GACE,cAAc,WACX,OAAO,MAAuC,YACjD,KAEO,OAAO,MACJ,gBAAgB,CAAC,GAEpB,OAAO,OAAO,EACd,KAAI,iBACH,YAAY,YAAY,IACpB,eACA,SAAS,YAAY,IACnB,a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/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 { toArray } from \"@stryke/convert/to-array\";\nimport { omit } from \"@stryke/helpers/omit\";\nimport { isRegExp } from \"@stryke/type-checks/is-regexp\";\nimport { isSetArray } from \"@stryke/type-checks/is-set-array\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { ResolveConfig, ResolvedConfig } from \"../types/config\";\n\n/**\n * Formats a configuration object into a human-readable string, omitting certain properties and simplifying others for better readability.\n *\n * @param config - The configuration object to format.\n * @returns A formatted string representation of the configuration.\n */\nexport function formatConfig(config: Record<string, any>): string {\n return JSON.stringify(\n Object.fromEntries(\n Object.entries({\n ...omit(config, [\n \"deps\",\n \"resolve\",\n \"plugins\",\n \"initialConfig\",\n \"userConfig\",\n \"inlineConfig\",\n \"pluginConfig\",\n \"environmentConfig\"\n ]),\n deps: isSetObject(config.deps)\n ? {\n alwaysBundle: isSetArray(\n (config.deps as { alwaysBundle?: unknown[] })?.alwaysBundle\n )\n ? (\n (config.deps as { alwaysBundle?: unknown[] })\n ?.alwaysBundle ?? []\n )\n .filter(Boolean)\n .map(alwaysBundle =>\n isSetString(alwaysBundle)\n ? alwaysBundle\n : isRegExp(alwaysBundle)\n ? alwaysBundle.source\n : \"<unknown-bundle>\"\n )\n : undefined,\n onlyBundle: isSetArray(\n (config.deps as { onlyBundle?: unknown[] })?.onlyBundle\n )\n ? (\n (config.deps as { onlyBundle?: unknown[] })?.onlyBundle ??\n []\n )\n .filter(Boolean)\n .map(onlyBundle =>\n isSetString(onlyBundle)\n ? onlyBundle\n : isRegExp(onlyBundle)\n ? onlyBundle.source\n : \"<unknown-bundle>\"\n )\n : undefined,\n neverBundle: isSetArray(\n (config.deps as { neverBundle?: unknown[] })?.neverBundle\n )\n ? (\n (config.deps as { neverBundle?: unknown[] })?.neverBundle ??\n []\n )\n .filter(Boolean)\n .map(neverBundle =>\n isSetString(neverBundle)\n ? neverBundle\n : isRegExp(neverBundle)\n ? neverBundle.source\n : \"<unknown-bundle>\"\n )\n : undefined\n }\n : undefined,\n\n resolve: isSetObject(config.resolve)\n ? {\n ...config.resolve,\n external: isSetArray((config.resolve as ResolveConfig)?.external)\n ? ((config.resolve as ResolveConfig)?.external ?? [])\n .filter(Boolean)\n .map(external =>\n isSetString(external)\n ? external\n : isRegExp(external)\n ? external.source\n : \"<unknown-bundle>\"\n )\n : undefined,\n noExternal: isSetArray(\n (config.resolve as ResolveConfig)?.noExternal\n )\n ? ((config.resolve as ResolveConfig)?.noExternal ?? [])\n .filter(Boolean)\n .map(noExternal =>\n isSetString(noExternal)\n ? noExternal\n : isRegExp(noExternal)\n ? noExternal.source\n : \"<unknown-bundle>\"\n )\n : undefined\n }\n : undefined,\n plugins: isSetArray(config.plugins)\n ? (toArray(config.plugins) as ResolvedConfig[\"plugins\"])\n ?.flatMap(plugin => toArray(plugin))\n ?.map(plugin =>\n String(\n isSetString(plugin)\n ? plugin\n : isSetObject(plugin) &&\n isSetString((plugin as { name: string }).name)\n ? (plugin as { name: string }).name\n : Array.isArray(plugin) && isSetString(plugin[0])\n ? plugin[0]\n : \"<function-plugin>\"\n )\n )\n : undefined\n }).sort(([key1], [key2]) => key1.localeCompare(key2))\n ),\n null,\n 4\n )\n .replace(/\"([^\"]+)\":/g, \"$1:\")\n .replace(/,\\s*$/g, \"\");\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,SAAgB,aAAa,QAAqC;CAChE,OAAO,KAAK,UACV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AAM,IACd,SACA,YAAY,MAAM,KAChB,YAAa,OAA4B,IAAI,IAC5C,OAA4B,OAC7B,MAAM,QAAQ,MAAM,KAAK,YAAY,OAAO,EAAE,IAC5C,OAAO,KACP,mBACV,CACF,IACF;CACN,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,KAAK,cAAc,IAAI,CAAC,CACtD,GACA,MACA,CACF,CAAC,CACE,QAAQ,eAAe,KAAK,CAAC,CAC7B,QAAQ,UAAU,EAAE;AACzB"}
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.mjs","names":[],"sources":["../../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 { kebabCase } from \"@stryke/string-format/kebab-case\";\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 type { AnyFunction } from \"@stryke/types/base\";\nimport {\n PLUGIN_HOOKS_FIELDS,\n PLUGIN_NON_HOOK_FIELDS,\n UNPLUGIN_BUILDER_VARIANTS\n} from \"../constants/plugin\";\nimport type {\n PluginConfig,\n PluginConfigObject,\n PluginConfigTuple\n} from \"../types/config\";\nimport type { PluginContext, WithUnpluginBuildContext } from \"../types/context\";\nimport type { HooksListItem } from \"../types/hooks\";\nimport type {\n Plugin,\n PluginHook,\n PluginHookFields,\n PluginHookObject,\n PluginHooks\n} from \"../types/plugin\";\nimport type {\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<TContext extends PluginContext = PluginContext>(\n value: unknown\n): 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 Record<string, unknown>)[hook]) ||\n (hook in value &&\n (isPluginHookFunction((value as Record<string, unknown>)[hook]) ||\n (hook === \"config\" &&\n isSetObject((value as Plugin<TContext>)[hook]))))\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\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\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<TContext extends PluginContext = PluginContext>(\n value: unknown\n): value is PluginConfig<TContext> {\n return (\n isSetString(value) ||\n isFunction(value) ||\n isPlugin(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 string = string\n> = HooksListItem<TContext, TField>[\"handler\"];\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 TKey extends string = string\n>(\n pluginHook: PluginHook<AnyFunction>\n): GetHookHandlerReturnType<TContext, TKey> {\n return (\n isFunction(pluginHook) ? pluginHook : pluginHook.handler\n ) as GetHookHandlerReturnType<TContext, TKey>;\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 TContext extends PluginContext = PluginContext\n>(\n keys: string\n): keys is `${TUnpluginBuilderVariant}:${keyof UnpluginOptions<TContext>[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) {\n return !PLUGIN_NON_HOOK_FIELDS.includes(keys as PluginHookFields<TContext>);\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 isDuplicate<TContext extends PluginContext = PluginContext>(\n plugin: Plugin<TContext>,\n plugins: Plugin<TContext>[]\n) {\n return (\n plugin.dedupe !== false &&\n plugins.some(\n p =>\n p.dedupe !== false &&\n ((isFunction(p.dedupe) && p.dedupe(plugin)) ||\n kebabCase(p.name) === kebabCase(plugin.name))\n )\n );\n}\n\n/**\n * Remove duplicate hooks from a list of hooks, keeping the first occurrence of each plugin.\n *\n * @param hooksList - The list of hooks to deduplicate.\n * @returns A new list of hooks with duplicates removed.\n */\nexport function dedupeHooklist<\n TContext extends PluginContext = PluginContext,\n TField extends PluginHookFields<TContext> = PluginHookFields<TContext>,\n TList extends HooksListItem<TContext, TField> = HooksListItem<\n TContext,\n TField\n >\n>(hooksList: TList[]): TList[] {\n return hooksList.reduce((ret, hook) => {\n if (\n !isDuplicate(\n hook.plugin,\n ret.map(h => h.plugin)\n )\n ) {\n ret.push(hook);\n }\n return ret;\n }, [] as TList[]);\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 HooksListItem<TContext, TField> = HooksListItem<\n TContext,\n TField\n >\n>(\n context: TContext,\n plugin: Plugin<TContext>,\n pluginHook: PluginHook<AnyFunction>,\n hooksList: TList[]\n): TList[] {\n if (\n !isDuplicate(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 GetHookHandlerReturnType<TContext, TField>;\n if (!handler) {\n return hooksList;\n }\n\n hooksList.push({\n plugin,\n handler\n } as any);\n }\n\n return hooksList;\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\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":";;;;;;;;;;;;;;AAsDA,SAAgB,SACd,OAC2B;CAC3B,OACE,YAAY,KAAK,KACjB,UAAU,SACV,YAAY,MAAM,IAAI,MACrB,YAAa,MAA2B,GAAG,KACzC,SAAS,SAAS,YAAY,MAAM,GAAG,OACzC,YAAa,MAA2B,kBAAkB,KACxD,wBAAwB,SACvB,WAAW,MAAM,kBAAkB,OACtC,YAAa,MAA2B,MAAM,KAC5C,YAAY,SAAS,WAAW,MAAM,MAAM,MAC/C,oBAAoB,OAClB,SACE,YAAa,MAAkC,KAAK,KACnD,QAAQ,UACN,qBAAsB,MAAkC,KAAK,KAC3D,SAAS,YACR,YAAa,MAA2B,KAAK,EACvD;AAEJ;;;;;;;AAQA,SAAgB,qBAEd,OAAuD;CACvD,OACE,YAAY,KAAK,KACjB,YAAY,WACT,YAAY,MAAM,MAAM,KAAK,WAAW,MAAM,MAAM,MACrD,aAAa,SACb,YAAY,MAAM,OAAO,KACzB,SAAS,MAAM,MAAM;AAE3B;;;;;;;AAQA,SAAgB,oBAEd,OAAsD;CACtD,OACE,MAAM,QAAQ,KAAK,MAClB,MAAM,WAAW,KAAK,MAAM,WAAW,QACrC,YAAY,MAAM,EAAE,KAAK,WAAW,MAAM,EAAE,MAC7C,MAAM,SAAS,KACf,YAAY,MAAM,EAAE,KACpB,SAAS,MAAM,EAAE;A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AK,EAAE,OAAO,MAAM,KACvC,UAAU,EAAE,IAAI,MAAM,UAAU,OAAO,IAAI,EACjD;AAEJ;;;;;;;AAQA,SAAgB,eAOd,WAA6B;CAC7B,OAAO,UAAU,QAAQ,KAAK,SAAS;EACrC,IACE,CAAC,YACC,KAAK,QACL,IAAI,KAAI,MAAK,EAAE,MAAM,CACvB,GAEA,IAAI,KAAK,IAAI;EAEf,OAAO;CACT,GAAG,CAAC,CAAY;AAClB;;;;;;;;;AAUA,SAAgB,cAQd,SACA,QACA,YACA,WACS;CACT,IACE,CAAC,YAAY,QAAQ,UAAU,KAAI,SAAQ,KAAK,MAAM,EAAE,OAAO,OAAO,CAAC,GACvE;EACA,MAAM,YAAY,GAAG,SAEjB,eACE,UACF,EACA,MAAM,SAAS,IAAI;EACvB,IAAI,CAAC,SACH,OAAO;EAGT,UAAU,KAAK;GACb;GACA;EACF,CAAQ;CACV;CAEA,OAAO;AACT;;;;;;;AAQA,SAAgB,wBAEd,QAAiD;CACjD,IAAI,eAAyB,MAAM,GACjC,OAAO;CAGT,IAAI,MAAM,QAAQ,MAAkC,GAAG;EACrD,MAAM,eAAyB,CAAC;EAChC,AAAC,OAAoC,SAAQ,SAAQ;GACnD,MAAM,UAAU,wBAAkC,IAAI;GACtD,IAAI,SACF,aAAa,KAAK,GAAG,QAAQ,KAAI,MAAK,KAAK,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC;EAErE,CAAC;EAED,OAAO,aAAa,SAAS,IAAI,eAAe;CAClD;CAEA,OAAO,CAAC,KAAK,UAAU,QAAQ,MAAM,CAAC,CAAC;AACzC"}
1
+ {"version":3,"file":"helpers.mjs","names":[],"sources":["../../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 { kebabCase } from \"@stryke/string-format/kebab-case\";\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 type { AnyFunction } from \"@stryke/types/base\";\nimport {\n PLUGIN_HOOKS_FIELDS,\n PLUGIN_NON_HOOK_FIELDS,\n UNPLUGIN_BUILDER_VARIANTS\n} from \"../constants/plugin\";\nimport type {\n PluginConfig,\n PluginConfigObject,\n PluginConfigTuple\n} from \"../types/config\";\nimport type { PluginContext, WithUnpluginBuildContext } from \"../types/context\";\nimport type { HooksListItem } from \"../types/hooks\";\nimport type {\n Plugin,\n PluginHook,\n PluginHookFields,\n PluginHookObject,\n PluginHooks\n} from \"../types/plugin\";\nimport type {\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<TContext extends PluginContext = PluginContext>(\n value: unknown\n): 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 Record<string, unknown>)[hook]) ||\n (hook in value &&\n (isPluginHookFunction((value as Record<string, unknown>)[hook]) ||\n (hook === \"config\" &&\n isSetObject((value as Plugin<TContext>)[hook]))))\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\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\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<TContext extends PluginContext = PluginContext>(\n value: unknown\n): value is PluginConfig<TContext> {\n return (\n isSetString(value) ||\n isFunction(value) ||\n isPlugin(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 string = string\n> = HooksListItem<TContext, TField>[\"handler\"];\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 TKey extends string = string\n>(\n pluginHook: PluginHook<AnyFunction>\n): GetHookHandlerReturnType<TContext, TKey> {\n return (\n isFunction(pluginHook) ? pluginHook : pluginHook.handler\n ) as GetHookHandlerReturnType<TContext, TKey>;\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 TContext extends PluginContext = PluginContext\n>(\n keys: string\n): keys is `${TUnpluginBuilderVariant}:${keyof UnpluginOptions<TContext>[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) {\n return !PLUGIN_NON_HOOK_FIELDS.includes(keys as PluginHookFields<TContext>);\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 isDuplicate<TContext extends PluginContext = PluginContext>(\n plugin: Plugin<TContext>,\n plugins: Plugin<TContext>[]\n) {\n return (\n plugin.dedupe !== false &&\n plugins.some(\n p =>\n p.dedupe !== false &&\n ((isFunction(p.dedupe) && p.dedupe(plugin)) ||\n kebabCase(p.name) === kebabCase(plugin.name))\n )\n );\n}\n\n/**\n * Remove duplicate hooks from a list of hooks, keeping the first occurrence of each plugin.\n *\n * @param hooksList - The list of hooks to deduplicate.\n * @returns A new list of hooks with duplicates removed.\n */\nexport function dedupeHooklist<\n TContext extends PluginContext = PluginContext,\n TField extends PluginHookFields<TContext> = PluginHookFields<TContext>,\n TList extends HooksListItem<TContext, TField> = HooksListItem<\n TContext,\n TField\n >\n>(hooksList: TList[]): TList[] {\n return hooksList.reduce((ret, hook) => {\n if (\n !isDuplicate(\n hook.plugin,\n ret.map(h => h.plugin)\n )\n ) {\n ret.push(hook);\n }\n return ret;\n }, [] as TList[]);\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 HooksListItem<TContext, TField> = HooksListItem<\n TContext,\n TField\n >\n>(\n context: TContext,\n plugin: Plugin<TContext>,\n pluginHook: PluginHook<AnyFunction>,\n hooksList: TList[]\n): TList[] {\n if (\n !isDuplicate(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 GetHookHandlerReturnType<TContext, TField>;\n if (!handler) {\n return hooksList;\n }\n\n hooksList.push({\n plugin,\n handler\n } as any);\n }\n\n return hooksList;\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\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":";;;;;;;;;;;;;;AAsDA,SAAgB,SACd,OAC2B;CAC3B,OACE,YAAY,KAAK,KACjB,UAAU,SACV,YAAY,MAAM,IAAI,MACrB,YAAa,MAA2B,GAAG,KACzC,SAAS,SAAS,YAAY,MAAM,GAAG,OACz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;CACV;CAEA,OAAO;AACT;;;;;;;AAQA,SAAgB,wBAEd,QAAiD;CACjD,IAAI,eAAyB,MAAM,GACjC,OAAO;CAGT,IAAI,MAAM,QAAQ,MAAkC,GAAG;EACrD,MAAM,eAAyB,CAAC;EAChC,AAAC,OAAoC,SAAQ,SAAQ;GACnD,MAAM,UAAU,wBAAkC,IAAI;GACtD,IAAI,SACF,aAAa,KAAK,GAAG,QAAQ,KAAI,MAAK,KAAK,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC;EAErE,CAAC;EAED,OAAO,aAAa,SAAS,IAAI,eAAe;CAClD;CAEA,OAAO,CAAC,KAAK,UAAU,QAAQ,MAAM,CAAC,CAAC;AACzC"}
@@ -1 +1 @@
1
- {"version":3,"file":"logging.mjs","names":["defu"],"sources":["../../src/plugin-utils/logging.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 { getColor } from \"@storm-software/config-tools/utilities/colors\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { RequiredKeys } from \"@stryke/types/base\";\nimport { uuid } from \"@stryke/unique-id/uuid\";\nimport chalk, { ChalkInstance } from \"chalk\";\nimport { defu } from \"defu\";\nimport { DEFAULT_ENVIRONMENT } from \"../constants/environments\";\nimport {\n DEFAULT_DEVELOPMENT_LOG_LEVEL,\n DEFAULT_PRODUCTION_LOG_LEVEL,\n DEFAULT_TEST_LOG_LEVEL,\n LOG_CATEGORIES_ARRAY,\n LOG_LEVELS,\n LogCategories,\n LogLevels\n} from \"../constants/log-level\";\nimport { Mode } from \"../types/config\";\nimport { UnresolvedContext } from \"../types/context\";\nimport type {\n CustomLogger,\n CustomLoggerMessage,\n LogCategory,\n LogFn,\n LogFnMeta,\n LogFnOptions,\n Logger,\n LoggerMessage,\n LoggerOptions,\n LogLevel,\n LogLevelResolvedConfig,\n LogLevelUserConfig,\n LogMeta\n} from \"../types/logging\";\n\n/**\n * Determines if the provided log level is considered verbose (debug or trace).\n *\n * @param logLevel - The log level to check, which can be a string or an UnresolvedContext containing the log level in its config.\n * @returns True if the log level is \"debug\" or \"trace\", false otherwise.\n */\nexport function isVerbose(logLevel: string): boolean;\n\n/**\n * Determines if the provided context is considered verbose (debug or trace).\n *\n * @param context - The context to check, which contains the log level in its config.\n * @returns True if the log level is \"debug\" or \"trace\", false otherwise.\n */\nexport function isVerbose(context: UnresolvedContext): boolean;\n\n/**\n * Determines if the provided log level is considered verbose (debug or trace).\n *\n * @param logLevelOrContext - The log level to check, which can be a string or an UnresolvedContext containing the log level in its config.\n * @returns True if the log level is \"debug\" or \"trace\", false otherwise.\n */\nexport function isVerbose(\n logLevelOrContext: string | UnresolvedContext\n): boolean {\n const level = isString(logLevelOrContext)\n ? logLevelOrContext\n : logLevelOrContext.config.logLevel;\n\n return level === \"debug\" || level === \"trace\";\n}\n\n/**\n * Resolves the log level configuration based on the provided log level and mode, returning a complete LogLevelResolvedConfig object that specifies the log level for each log category.\n *\n * @param logLevel - The user-provided log level configuration, which can be a string or an object specifying log levels for each category.\n * @param mode - The current mode of the application (e.g., \"development\", \"test\", \"production\"), which determines the default log levels.\n * @returns A LogLevelResolvedConfig object specifying the log level for each log category.\n */\nexport function resolveLogLevel(\n logLevel?: LogLevelUserConfig,\n mode?: Mode\n): LogLevelResolvedConfig {\n if (logLevel === \"trace\") {\n return {\n general: \"trace\",\n fs: \"trace\",\n performance: \"trace\",\n communication: \"trace\",\n plugins: \"trace\",\n hooks: \"trace\",\n env: \"trace\",\n rpc: \"trace\",\n config: \"trace\",\n babel: \"trace\"\n };\n } else if (logLevel === \"silent\") {\n return {\n general: \"silent\",\n fs: \"silent\",\n performance: \"silent\",\n communication: \"silent\",\n plugins: \"silent\",\n hooks: \"silent\",\n env: \"silent\",\n rpc: \"silent\",\n config: \"silent\",\n babel: \"silent\"\n };\n }\n\n let defaultLogLevel: LogLevelResolvedConfig;\n if (mode === \"development\") {\n defaultLogLevel = DEFAULT_DEVELOPMENT_LOG_LEVEL;\n } else if (mode === \"test\") {\n defaultLogLevel = DEFAULT_TEST_LOG_LEVEL;\n } else {\n defaultLogLevel = DEFAULT_PRODUCTION_LOG_LEVEL;\n }\n\n if (isSetString(logLevel)) {\n return {\n general: logLevel,\n fs: defaultLogLevel.fs,\n performance: logLevel,\n communication: defaultLogLevel.communication,\n plugins: logLevel,\n hooks: logLevel,\n env: defaultLogLevel.env,\n rpc: defaultLogLevel.rpc,\n config: defaultLogLevel.config,\n babel: logLevel\n };\n } else if (isSetObject(logLevel)) {\n if (\n Object.values(logLevel).filter(level => isSetString(level)).length ===\n LOG_CATEGORIES_ARRAY.length\n ) {\n return logLevel as LogLevelResolvedConfig;\n }\n\n return defu(logLevel, defaultLogLevel) as LogLevelResolvedConfig;\n }\n\n return defaultLogLevel;\n}\n\nconst colors = [\n chalk.green,\n chalk.greenBright,\n chalk.red,\n chalk.redBright,\n chalk.cyan,\n chalk.cyanBright,\n chalk.yellow,\n chalk.yellowBright,\n chalk.magenta,\n chalk.magentaBright\n] as const;\n\nconst BRAND_COLOR = getColor(\"brand\");\n\n/**\n * Generate a consistent color based on the input text.\n *\n * @param text - The input text to generate the color from.\n * @return A hexadecimal color string.\n */\nexport const getTextColor = (text: string): ChalkInstance => {\n let code = 0;\n for (let i = 0; i < text.length; ++i) {\n code += text.charCodeAt(i);\n }\n\n return colors[code % colors.length] ?? chalk.cyanBright;\n};\n\n/**\n * Generate a consistent color based on the input text.\n *\n * @param text - The input text to generate the color from.\n * @return A hexadecimal color string.\n */\nexport const colorText = (text: string): string => {\n const title = titleCase(text);\n\n return getTextColor(title)(title);\n};\n\n/**\n * Generate a consistent color based on the input text.\n *\n * @param text - The input text to generate the color from.\n * @return A hexadecimal color string.\n */\nexport const colorBackground = (text: string): string => {\n const title = titleCase(text);\n\n return chalk.inverse(getTextColor(title)(` ${title} `));\n};\n\nexport const consoleLog = (meta: LogMeta, ...args: string[]) =>\n getLogFn(\n getLogLevel(\n meta.category === LogCategories.PERFORMANCE ? \"performance\" : meta.type\n ),\n {\n logLevel: \"all\"\n }\n )(\n `${meta.name ? chalk.bold.hex(BRAND_COLOR)(kebabCase(meta.name)) : \"\"}${meta.name ? chalk.grey(\" > \") : \"\"}${\n meta.command\n ? `${chalk.bold.hex(BRAND_COLOR)(\n kebabCase(meta.command)\n )}${chalk.grey(\" > \")}`\n : \"\"\n }${\n meta.environment && kebabCase(meta.environment) !== DEFAULT_ENVIRONMENT\n ? `${chalk.bold.hex(BRAND_COLOR)(\n kebabCase(meta.environment)\n )}${chalk.grey(\" > \")}`\n : \"\"\n }${\n meta.plugin\n ? `${chalk.bold.hex(BRAND_COLOR)(meta.plugin)}${chalk.grey(\" > \")}`\n : \"\"\n }${\n meta.source\n ? `${chalk.bold.hex(BRAND_COLOR)(\n kebabCase(meta.source)\n )}${chalk.grey(\" > \")}`\n : \"\"\n }${\n meta.category &&\n meta.category !== LogCategories.GENERAL &&\n meta.category !== LogCategories.PERFORMANCE\n ? `${colorBackground(kebabCase(meta.category))} `\n : \"\"\n }${args.join(\" \")} `.trim()\n );\n\nexport function isValidLogLevel(logLevel: LogLevel, type: LogLevel): boolean {\n if (logLevel === LogLevels.SILENT) {\n return false;\n }\n\n return LOG_LEVELS.indexOf(logLevel) >= LOG_LEVELS.indexOf(type);\n}\n\nexport function isValidLogLevelConfig(\n type: LogLevel,\n logLevel: LogLevelResolvedConfig,\n category: LogCategory = LogCategories.GENERAL\n): boolean {\n return isValidLogLevel(logLevel[category], type);\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, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.\n * @returns A logging function.\n */\nexport const createLogFn = (name: string, options: LogFnOptions): LogFn => {\n const logLevel = resolveLogLevel(options.logLevel, options.mode);\n\n return (meta: LogFnMeta | LogLevel, ...args: string[]) => {\n const logMeta = isSetObject(meta)\n ? {\n logId: uuid(),\n timestamp: Date.now(),\n category: LogCategories.GENERAL,\n ...options,\n ...meta,\n name\n }\n : {\n logId: uuid(),\n timestamp: Date.now(),\n category: LogCategories.GENERAL,\n ...options,\n type: meta,\n name\n };\n\n if (\n logMeta.$$ipc ||\n isValidLogLevelConfig(\n logMeta.type,\n logLevel,\n logMeta.category ? logMeta.category : LogCategories.GENERAL\n )\n ) {\n consoleLog(logMeta, ...args);\n }\n };\n};\n\nconst validateLogger = (\n type: LogLevel,\n name: string | undefined,\n options: LoggerOptions,\n callback: (message: LoggerMessage) => void\n) => {\n const logLevel = resolveLogLevel(options.logLevel, options.mode);\n\n return (message: string | LoggerMessage | Error) => {\n const params = isSetString(message)\n ? {\n name,\n plugin: options.plugin,\n meta: {\n type,\n name,\n category: LogCategories.GENERAL,\n logId: uuid(),\n timestamp: Date.now(),\n ...options\n },\n message\n }\n : message instanceof Error || message.error\n ? {\n name,\n plugin: options.plugin,\n message: `${\n (message instanceof Error ? message : message.error)?.message\n ? (message instanceof Error ? message : message.error)?.name\n ? `[${\n (message instanceof Error ? message : message.error)?.name\n }]: ${message.message || (message instanceof Error ? message : message.error)?.message}`\n : message.message ||\n (message instanceof Error ? message : message.error)\n ?.message\n : message.message\n ? message.message\n : JSON.stringify(message)\n }${\n (message instanceof Error ? message : message.error)?.stack\n ? `\nStack Trace: ${(message instanceof Error ? message : message.error)?.stack}`\n : \"\"\n }`,\n meta: {\n type,\n name,\n category: LogCategories.GENERAL,\n logId: uuid(),\n timestamp: Date.now(),\n ...options\n }\n }\n : {\n name,\n plugin: options.plugin,\n ...message,\n meta: {\n type,\n name,\n category: LogCategories.GENERAL,\n logId: uuid(),\n timestamp: Date.now(),\n plugin: message.plugin,\n ...options,\n ...message.meta\n }\n };\n\n if (\n params.meta.$$ipc ||\n isValidLogLevelConfig(type, logLevel, params.meta.category)\n ) {\n callback(params);\n }\n };\n};\n\nconst validateCustomLogger = (\n type: LogLevel,\n name: string | undefined,\n options: LoggerOptions,\n callback?: (message: string | LoggerMessage) => void,\n customCallback?: (message: CustomLoggerMessage) => void\n) => {\n const logLevel = resolveLogLevel(options.logLevel, options.mode);\n\n return (message: string | LoggerMessage) => {\n const params = isSetString(message)\n ? {\n name,\n plugin: options.plugin,\n meta: {\n category: LogCategories.GENERAL,\n ...options,\n type,\n name,\n logId: uuid(),\n timestamp: Date.now()\n },\n message\n }\n : {\n name,\n plugin: options.plugin,\n ...message,\n meta: {\n category: LogCategories.GENERAL,\n ...options,\n type,\n name,\n logId: uuid(),\n timestamp: Date.now(),\n plugin: message.plugin,\n ...message.meta\n }\n };\n\n if (\n params.meta.$$ipc ||\n isValidLogLevelConfig(type, logLevel, params.meta.category)\n ) {\n callback?.(params);\n customCallback?.(params);\n }\n };\n};\n\n/**\n * Create a logging function with a specific name and options.\n *\n * @param logger - The original logger to wrap with the custom logger.\n * @param secondaryLogger - The custom logger to use for logging messages, which can be used to override the default logging behavior of the original logger.\n * @returns A new logger that combines the original logger's options with the custom logger's methods, allowing for customized logging behavior while still maintaining the original logger's configuration.\n */\nexport const withLogger = (logger: Logger, secondaryLogger: Logger): Logger => {\n const options = { ...secondaryLogger.options, ...logger.options };\n\n const result = {\n options,\n error: validateLogger(\n \"error\",\n options.name,\n options,\n (message: LoggerMessage) => {\n logger.error?.(message);\n secondaryLogger.error?.(message);\n }\n ),\n warn: validateLogger(\n \"warn\",\n options.name,\n options,\n (message: LoggerMessage) => {\n logger.warn?.(message);\n secondaryLogger.warn?.(message);\n }\n ),\n info: validateLogger(\n \"info\",\n options.name,\n options,\n (message: LoggerMessage) => {\n logger.info?.(message);\n secondaryLogger.info?.(message);\n }\n ),\n debug: validateLogger(\n \"debug\",\n options.name,\n options,\n (message: LoggerMessage) => {\n logger.debug?.(message);\n secondaryLogger.debug?.(message);\n }\n ),\n trace: validateLogger(\n \"trace\",\n options.name,\n options,\n (message: LoggerMessage) => {\n logger.trace?.(message);\n secondaryLogger.trace?.(message);\n }\n )\n } as Logger;\n\n result.log = (type: LogLevel, message: string | LoggerMessage) => {\n switch (type) {\n case \"error\":\n result.error(message);\n break;\n case \"warn\":\n result.warn(message);\n break;\n case \"info\":\n result.info(message);\n break;\n case \"debug\":\n result.debug(message);\n break;\n case \"trace\":\n result.trace(message);\n break;\n case \"silent\":\n break;\n default:\n result.info(message);\n break;\n }\n };\n\n return result;\n};\n\n/**\n * Create a logging function with a specific name and options.\n *\n * @param logger - The original logger to wrap with the custom logger.\n * @param logFn - The custom logging function to use for logging messages, which can be used to override the default logging behavior of the original logger.\n * @returns A new logger that combines the original logger's options with the custom logging function, allowing for customized logging behavior while still maintaining the original logger's configuration.\n */\nexport const withLogFn = (logger: Logger, logFn: LogFn): Logger => {\n const result = {\n options: logger.options,\n error: validateLogger(\n \"error\",\n logger.options.name,\n logger.options,\n (msg: LoggerMessage) => {\n logger.error?.(msg);\n logFn(\n {\n category: LogCategories.GENERAL,\n ...logger.options,\n type: \"error\",\n logId: uuid(),\n timestamp: Date.now(),\n ...msg.meta\n },\n msg.message\n );\n }\n ),\n warn: validateLogger(\n \"warn\",\n logger.options.name,\n logger.options,\n (msg: LoggerMessage) => {\n logger.warn?.(msg);\n logFn(\n {\n category: LogCategories.GENERAL,\n ...logger.options,\n type: \"warn\",\n logId: uuid(),\n timestamp: Date.now(),\n ...msg.meta\n },\n msg.message\n );\n }\n ),\n info: validateLogger(\n \"info\",\n logger.options.name,\n logger.options,\n (msg: LoggerMessage) => {\n logger.info?.(msg);\n logFn(\n {\n category: LogCategories.GENERAL,\n ...logger.options,\n type: \"info\",\n logId: uuid(),\n timestamp: Date.now(),\n ...msg.meta\n },\n msg.message\n );\n }\n ),\n debug: validateLogger(\n \"debug\",\n logger.options.name,\n logger.options,\n (msg: LoggerMessage) => {\n logger.debug?.(msg);\n logFn(\n {\n category: LogCategories.GENERAL,\n ...logger.options,\n type: \"debug\",\n logId: uuid(),\n timestamp: Date.now(),\n ...msg.meta\n },\n msg.message\n );\n }\n ),\n trace: validateLogger(\n \"trace\",\n logger.options.name,\n logger.options,\n (msg: LoggerMessage) => {\n logger.trace?.(msg);\n logFn(\n {\n category: LogCategories.GENERAL,\n ...logger.options,\n type: \"trace\",\n logId: uuid(),\n timestamp: Date.now(),\n ...msg.meta\n },\n msg.message\n );\n }\n )\n } as Logger;\n\n result.log = (type: LogLevel, message: string | LoggerMessage) => {\n switch (type) {\n case \"error\":\n result.error(message);\n break;\n case \"warn\":\n result.warn(message);\n break;\n case \"info\":\n result.info(message);\n break;\n case \"debug\":\n result.debug(message);\n break;\n case \"trace\":\n result.trace(message);\n break;\n case \"silent\":\n break;\n default:\n result.info(message);\n break;\n }\n };\n\n return result;\n};\n\n/**\n * Create a logging function with a specific name and options.\n *\n * @param logger - The original logger to wrap with the custom logger.\n * @param customLogger - The custom logger to use for logging messages, which can be used to override the default logging behavior of the original logger.\n * @returns A new logger that combines the original logger's options with the custom logger's methods, allowing for customized logging behavior while still maintaining the original logger's configuration.\n */\nexport const withCustomLogger = (\n logger: Logger,\n customLogger: CustomLogger\n): Logger => {\n const result = {\n options: logger.options,\n error: validateCustomLogger(\n \"error\",\n logger.options.name,\n logger.options,\n logger.error.bind(logger),\n customLogger.error?.bind(customLogger)\n ),\n warn: validateCustomLogger(\n \"warn\",\n logger.options.name,\n logger.options,\n logger.warn.bind(logger),\n customLogger.warn?.bind(customLogger)\n ),\n info: validateCustomLogger(\n \"info\",\n logger.options.name,\n logger.options,\n logger.info.bind(logger),\n customLogger.info?.bind(customLogger)\n ),\n debug: validateCustomLogger(\n \"debug\",\n logger.options.name,\n logger.options,\n logger.debug.bind(logger),\n customLogger.debug?.bind(customLogger)\n ),\n trace: validateCustomLogger(\n \"trace\",\n logger.options.name,\n logger.options,\n logger.trace.bind(logger),\n customLogger.trace?.bind(customLogger)\n )\n } as Logger;\n\n result.log = (type: LogLevel, message: string | LoggerMessage) => {\n switch (type) {\n case \"error\":\n result.error(message);\n break;\n case \"warn\":\n result.warn(message);\n break;\n case \"info\":\n result.info(message);\n break;\n case \"debug\":\n result.debug(message);\n break;\n case \"trace\":\n result.trace(message);\n break;\n case \"silent\":\n break;\n default:\n result.info(message);\n break;\n }\n };\n\n return result;\n};\n\nexport const consoleLogger: LogFn = (meta: LogFnMeta, message: string) =>\n consoleLog(\n {\n type: isSetString(meta) ? meta : meta.type,\n category: LogCategories.GENERAL,\n logId: uuid(),\n timestamp: Date.now(),\n ...(isSetObject(meta) ? meta : {})\n },\n message\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, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.\n * @returns A logging function.\n */\nexport const createLogger = (\n name: string | undefined,\n options: LoggerOptions,\n callback: LogFn = consoleLogger\n): Logger => {\n const result = {\n options: { name, ...options },\n error: validateLogger(\"error\", name, { name, ...options }, data =>\n callback({ ...data.meta, type: \"error\" }, data.message)\n ),\n warn: validateLogger(\"warn\", name, { name, ...options }, data =>\n callback({ ...data.meta, type: \"warn\" }, data.message)\n ),\n info: validateLogger(\"info\", name, { name, ...options }, data =>\n callback({ ...data.meta, type: \"info\" }, data.message)\n ),\n debug: validateLogger(\"debug\", name, { name, ...options }, data =>\n callback({ ...data.meta, type: \"debug\" }, data.message)\n ),\n trace: validateLogger(\"trace\", name, { name, ...options }, data =>\n callback({ ...data.meta, type: \"trace\" }, data.message)\n )\n } as Logger;\n\n result.log = (type: LogLevel, message: string | LoggerMessage) => {\n switch (type) {\n case \"error\":\n result.error(message);\n break;\n case \"warn\":\n result.warn(message);\n break;\n case \"info\":\n result.info(message);\n break;\n case \"debug\":\n result.debug(message);\n break;\n case \"trace\":\n result.trace(message);\n break;\n case \"silent\":\n break;\n default:\n result.info(message);\n break;\n }\n };\n\n return result;\n};\n\n/**\n * Extend a logging function with a specific name, adding a colored badge to the log output.\n *\n * @param logFn - The original logging function to extend.\n * @param options - The overlay metadata to use for the badge in the log output.\n * @returns A new logging function that includes the badge in its output.\n */\nexport const extendLogFn = (logFn: LogFn, options: LogFnOptions): LogFn => {\n return (meta, ...args) =>\n options.source || options.category\n ? logFn(\n isSetObject(meta)\n ? { ...options, ...meta }\n : { ...options, type: meta },\n `${colorBackground(String(options.source || options.category))} ${args\n .filter(Boolean)\n .map(arg => String(arg).trim())\n .join(\" \")} `\n )\n : logFn(meta, ...args);\n};\n\n/**\n * Extend a logger with a specific name and options, adding a colored badge to the log output for each log message generated by the logger.\n *\n * @param logger - The original logger to extend.\n * @param options - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the extended logger.\n * @returns A new logger that includes the badge in its output for each log message.\n */\nexport const extendLogger = (\n logger: Logger,\n options: LoggerOptions\n): Logger => {\n const opts = { ...logger.options, ...options } as RequiredKeys<\n LoggerOptions,\n \"name\"\n >;\n\n const result = {\n options: opts,\n error: validateLogger(\"error\", opts.name, opts, logger.error.bind(logger)),\n warn: validateLogger(\"warn\", opts.name, opts, logger.warn.bind(logger)),\n info: validateLogger(\"info\", opts.name, opts, logger.info.bind(logger)),\n debug: validateLogger(\"debug\", opts.name, opts, logger.debug.bind(logger)),\n trace: validateLogger(\"trace\", opts.name, opts, logger.trace.bind(logger))\n } as Logger;\n\n result.log = (type: LogLevel, message: string | LoggerMessage) => {\n switch (type) {\n case \"error\":\n result.error(message);\n break;\n case \"warn\":\n result.warn(message);\n break;\n case \"info\":\n result.info(message);\n break;\n case \"debug\":\n result.debug(message);\n break;\n case \"trace\":\n result.trace(message);\n break;\n case \"silent\":\n break;\n default:\n result.info(message);\n break;\n }\n };\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA+EA,SAAgB,UACd,mBACS;CACT,MAAM,QAAQ,SAAS,iBAAiB,IACpC,oBACA,kBAAkB,OAAO;CAE7B,OAAO,UAAU,WAAW,UAAU;AACxC;;;;;;;;AASA,SAAgB,gBACd,UACA,MACwB;CACxB,IAAI,aAAa,SACf,OAAO;EACL,SAAS;EACT,IAAI;EACJ,aAAa;EACb,eAAe;EACf,SAAS;EACT,OAAO;EACP,KAAK;EACL,KAAK;EACL,QAAQ;EACR,OAAO;CACT;MACK,IAAI,aAAa,UACtB,OAAO;EACL,SAAS;EACT,IAAI;EACJ,aAAa;EACb,eAAe;EACf,SAAS;EACT,OAAO;EACP,KAAK;EACL,KAAK;EACL,QAAQ;EACR,OAAO;CACT;CAGF,IAAI;CACJ,IAAI,SAAS,eACX,kBAAkB;MACb,IAAI,SAAS,QAClB,kBAAkB;MAElB,kBAAkB;CAGpB,IAAI,YAAY,QAAQ,GACtB,OAAO;EACL,SAAS;EACT,IAAI,gBAAgB;EACpB,aAAa;EACb,eAAe,gBAAgB;EAC/B,SAAS;EACT,OAAO;EACP,KAAK,gBAAgB;EACrB,KAAK,gBAAgB;EACrB,QAAQ,gBAAgB;EACxB,OAAO;CACT;MACK,IAAI,YAAY,QAAQ,GAAG;EAChC,IACE,OAAO,OAAO,QAAQ,EAAE,QAAO,UAAS,YAAY,KAAK,CAAC,EAAE,WAC5D,qBAAqB,QAErB,OAAO;EAGT,OAAOA,OAAK,UAAU,eAAe;CACvC;CAEA,OAAO;AACT;AAEA,MAAM,SAAS;CACb,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;CACN,MAAM;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.mjs","names":["defu"],"sources":["../../src/plugin-utils/logging.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 { getColor } from \"@storm-software/config-tools/utilities/colors\";\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { titleCase } from \"@stryke/string-format/title-case\";\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport { RequiredKeys } from \"@stryke/types/base\";\nimport { uuid } from \"@stryke/unique-id/uuid\";\nimport chalk, { ChalkInstance } from \"chalk\";\nimport { defu } from \"defu\";\nimport { DEFAULT_ENVIRONMENT } from \"../constants/environments\";\nimport {\n DEFAULT_DEVELOPMENT_LOG_LEVEL,\n DEFAULT_PRODUCTION_LOG_LEVEL,\n DEFAULT_TEST_LOG_LEVEL,\n LOG_CATEGORIES_ARRAY,\n LOG_LEVELS,\n LogCategories,\n LogLevels\n} from \"../constants/log-level\";\nimport { Mode } from \"../types/config\";\nimport { UnresolvedContext } from \"../types/context\";\nimport type {\n CustomLogger,\n CustomLoggerMessage,\n LogCategory,\n LogFn,\n LogFnMeta,\n LogFnOptions,\n Logger,\n LoggerMessage,\n LoggerOptions,\n LogLevel,\n LogLevelResolvedConfig,\n LogLevelUserConfig,\n LogMeta\n} from \"../types/logging\";\n\n/**\n * Determines if the provided log level is considered verbose (debug or trace).\n *\n * @param logLevel - The log level to check, which can be a string or an UnresolvedContext containing the log level in its config.\n * @returns True if the log level is \"debug\" or \"trace\", false otherwise.\n */\nexport function isVerbose(logLevel: string): boolean;\n\n/**\n * Determines if the provided context is considered verbose (debug or trace).\n *\n * @param context - The context to check, which contains the log level in its config.\n * @returns True if the log level is \"debug\" or \"trace\", false otherwise.\n */\nexport function isVerbose(context: UnresolvedContext): boolean;\n\n/**\n * Determines if the provided log level is considered verbose (debug or trace).\n *\n * @param logLevelOrContext - The log level to check, which can be a string or an UnresolvedContext containing the log level in its config.\n * @returns True if the log level is \"debug\" or \"trace\", false otherwise.\n */\nexport function isVerbose(\n logLevelOrContext: string | UnresolvedContext\n): boolean {\n const level = isString(logLevelOrContext)\n ? logLevelOrContext\n : logLevelOrContext.config.logLevel;\n\n return level === \"debug\" || level === \"trace\";\n}\n\n/**\n * Resolves the log level configuration based on the provided log level and mode, returning a complete LogLevelResolvedConfig object that specifies the log level for each log category.\n *\n * @param logLevel - The user-provided log level configuration, which can be a string or an object specifying log levels for each category.\n * @param mode - The current mode of the application (e.g., \"development\", \"test\", \"production\"), which determines the default log levels.\n * @returns A LogLevelResolvedConfig object specifying the log level for each log category.\n */\nexport function resolveLogLevel(\n logLevel?: LogLevelUserConfig,\n mode?: Mode\n): LogLevelResolvedConfig {\n if (logLevel === \"trace\") {\n return {\n general: \"trace\",\n fs: \"trace\",\n performance: \"trace\",\n communication: \"trace\",\n plugins: \"trace\",\n hooks: \"trace\",\n env: \"trace\",\n rpc: \"trace\",\n config: \"trace\",\n babel: \"trace\"\n };\n } else if (logLevel === \"silent\") {\n return {\n general: \"silent\",\n fs: \"silent\",\n performance: \"silent\",\n communication: \"silent\",\n plugins: \"silent\",\n hooks: \"silent\",\n env: \"silent\",\n rpc: \"silent\",\n config: \"silent\",\n babel: \"silent\"\n };\n }\n\n let defaultLogLevel: LogLevelResolvedConfig;\n if (mode === \"development\") {\n defaultLogLevel = DEFAULT_DEVELOPMENT_LOG_LEVEL;\n } else if (mode === \"test\") {\n defaultLogLevel = DEFAULT_TEST_LOG_LEVEL;\n } else {\n defaultLogLevel = DEFAULT_PRODUCTION_LOG_LEVEL;\n }\n\n if (isSetString(logLevel)) {\n return {\n general: logLevel,\n fs: defaultLogLevel.fs,\n performance: logLevel,\n communication: defaultLogLevel.communication,\n plugins: logLevel,\n hooks: logLevel,\n env: defaultLogLevel.env,\n rpc: defaultLogLevel.rpc,\n config: defaultLogLevel.config,\n babel: logLevel\n };\n } else if (isSetObject(logLevel)) {\n if (\n Object.values(logLevel).filter(level => isSetString(level)).length ===\n LOG_CATEGORIES_ARRAY.length\n ) {\n return logLevel as LogLevelResolvedConfig;\n }\n\n return defu(logLevel, defaultLogLevel) as LogLevelResolvedConfig;\n }\n\n return defaultLogLevel;\n}\n\nconst colors = [\n chalk.green,\n chalk.greenBright,\n chalk.red,\n chalk.redBright,\n chalk.cyan,\n chalk.cyanBright,\n chalk.yellow,\n chalk.yellowBright,\n chalk.magenta,\n chalk.magentaBright\n] as const;\n\nconst BRAND_COLOR = getColor(\"brand\");\n\n/**\n * Generate a consistent color based on the input text.\n *\n * @param text - The input text to generate the color from.\n * @return A hexadecimal color string.\n */\nexport const getTextColor = (text: string): ChalkInstance => {\n let code = 0;\n for (let i = 0; i < text.length; ++i) {\n code += text.charCodeAt(i);\n }\n\n return colors[code % colors.length] ?? chalk.cyanBright;\n};\n\n/**\n * Generate a consistent color based on the input text.\n *\n * @param text - The input text to generate the color from.\n * @return A hexadecimal color string.\n */\nexport const colorText = (text: string): string => {\n const title = titleCase(text);\n\n return getTextColor(title)(title);\n};\n\n/**\n * Generate a consistent color based on the input text.\n *\n * @param text - The input text to generate the color from.\n * @return A hexadecimal color string.\n */\nexport const colorBackground = (text: string): string => {\n const title = titleCase(text);\n\n return chalk.inverse(getTextColor(title)(` ${title} `));\n};\n\nexport const consoleLog = (meta: LogMeta, ...args: string[]) =>\n getLogFn(\n getLogLevel(\n meta.category === LogCategories.PERFORMANCE ? \"performance\" : meta.type\n ),\n {\n logLevel: \"all\"\n }\n )(\n `${meta.name ? chalk.bold.hex(BRAND_COLOR)(kebabCase(meta.name)) : \"\"}${meta.name ? chalk.grey(\" > \") : \"\"}${\n meta.command\n ? `${chalk.bold.hex(BRAND_COLOR)(\n kebabCase(meta.command)\n )}${chalk.grey(\" > \")}`\n : \"\"\n }${\n meta.environment && kebabCase(meta.environment) !== DEFAULT_ENVIRONMENT\n ? `${chalk.bold.hex(BRAND_COLOR)(\n kebabCase(meta.environment)\n )}${chalk.grey(\" > \")}`\n : \"\"\n }${\n meta.plugin\n ? `${chalk.bold.hex(BRAND_COLOR)(meta.plugin)}${chalk.grey(\" > \")}`\n : \"\"\n }${\n meta.source\n ? `${chalk.bold.hex(BRAND_COLOR)(\n kebabCase(meta.source)\n )}${chalk.grey(\" > \")}`\n : \"\"\n }${\n meta.category &&\n meta.category !== LogCategories.GENERAL &&\n meta.category !== LogCategories.PERFORMANCE\n ? `${colorBackground(kebabCase(meta.category))} `\n : \"\"\n }${args.join(\" \")} `.trim()\n );\n\nexport function isValidLogLevel(logLevel: LogLevel, type: LogLevel): boolean {\n if (logLevel === LogLevels.SILENT) {\n return false;\n }\n\n return LOG_LEVELS.indexOf(logLevel) >= LOG_LEVELS.indexOf(type);\n}\n\nexport function isValidLogLevelConfig(\n type: LogLevel,\n logLevel: LogLevelResolvedConfig,\n category: LogCategory = LogCategories.GENERAL\n): boolean {\n return isValidLogLevel(logLevel[category], type);\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, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.\n * @returns A logging function.\n */\nexport const createLogFn = (name: string, options: LogFnOptions): LogFn => {\n const logLevel = resolveLogLevel(options.logLevel, options.mode);\n\n return (meta: LogFnMeta | LogLevel, ...args: string[]) => {\n const logMeta = isSetObject(meta)\n ? {\n logId: uuid(),\n timestamp: Date.now(),\n category: LogCategories.GENERAL,\n ...options,\n ...meta,\n name\n }\n : {\n logId: uuid(),\n timestamp: Date.now(),\n category: LogCategories.GENERAL,\n ...options,\n type: meta,\n name\n };\n\n if (\n logMeta.$$ipc ||\n isValidLogLevelConfig(\n logMeta.type,\n logLevel,\n logMeta.category ? logMeta.category : LogCategories.GENERAL\n )\n ) {\n consoleLog(logMeta, ...args);\n }\n };\n};\n\nconst validateLogger = (\n type: LogLevel,\n name: string | undefined,\n options: LoggerOptions,\n callback: (message: LoggerMessage) => void\n) => {\n const logLevel = resolveLogLevel(options.logLevel, options.mode);\n\n return (message: string | LoggerMessage | Error) => {\n const params = isSetString(message)\n ? {\n name,\n plugin: options.plugin,\n meta: {\n type,\n name,\n category: LogCategories.GENERAL,\n logId: uuid(),\n timestamp: Date.now(),\n ...options\n },\n message\n }\n : message instanceof Error || message.error\n ? {\n name,\n plugin: options.plugin,\n message: `${\n (message instanceof Error ? message : message.error)?.message\n ? (message instanceof Error ? message : message.error)?.name\n ? `[${\n (message instanceof Error ? message : message.error)?.name\n }]: ${message.message || (message instanceof Error ? message : message.error)?.message}`\n : message.message ||\n (message instanceof Error ? message : message.error)\n ?.message\n : message.message\n ? message.message\n : JSON.stringify(message)\n }${\n (message instanceof Error ? message : message.error)?.stack\n ? `\nStack Trace: ${(message instanceof Error ? message : message.error)?.stack}`\n : \"\"\n }`,\n meta: {\n type,\n name,\n category: LogCategories.GENERAL,\n logId: uuid(),\n timestamp: Date.now(),\n ...options\n }\n }\n : {\n name,\n plugin: options.plugin,\n ...message,\n meta: {\n type,\n name,\n category: LogCategories.GENERAL,\n logId: uuid(),\n timestamp: Date.now(),\n plugin: message.plugin,\n ...options,\n ...message.meta\n }\n };\n\n if (\n params.meta.$$ipc ||\n isValidLogLevelConfig(type, logLevel, params.meta.category)\n ) {\n callback(params);\n }\n };\n};\n\nconst validateCustomLogger = (\n type: LogLevel,\n name: string | undefined,\n options: LoggerOptions,\n callback?: (message: string | LoggerMessage) => void,\n customCallback?: (message: CustomLoggerMessage) => void\n) => {\n const logLevel = resolveLogLevel(options.logLevel, options.mode);\n\n return (message: string | LoggerMessage) => {\n const params = isSetString(message)\n ? {\n name,\n plugin: options.plugin,\n meta: {\n category: LogCategories.GENERAL,\n ...options,\n type,\n name,\n logId: uuid(),\n timestamp: Date.now()\n },\n message\n }\n : {\n name,\n plugin: options.plugin,\n ...message,\n meta: {\n category: LogCategories.GENERAL,\n ...options,\n type,\n name,\n logId: uuid(),\n timestamp: Date.now(),\n plugin: message.plugin,\n ...message.meta\n }\n };\n\n if (\n params.meta.$$ipc ||\n isValidLogLevelConfig(type, logLevel, params.meta.category)\n ) {\n callback?.(params);\n customCallback?.(params);\n }\n };\n};\n\n/**\n * Create a logging function with a specific name and options.\n *\n * @param logger - The original logger to wrap with the custom logger.\n * @param secondaryLogger - The custom logger to use for logging messages, which can be used to override the default logging behavior of the original logger.\n * @returns A new logger that combines the original logger's options with the custom logger's methods, allowing for customized logging behavior while still maintaining the original logger's configuration.\n */\nexport const withLogger = (logger: Logger, secondaryLogger: Logger): Logger => {\n const options = { ...secondaryLogger.options, ...logger.options };\n\n const result = {\n options,\n error: validateLogger(\n \"error\",\n options.name,\n options,\n (message: LoggerMessage) => {\n logger.error?.(message);\n secondaryLogger.error?.(message);\n }\n ),\n warn: validateLogger(\n \"warn\",\n options.name,\n options,\n (message: LoggerMessage) => {\n logger.warn?.(message);\n secondaryLogger.warn?.(message);\n }\n ),\n info: validateLogger(\n \"info\",\n options.name,\n options,\n (message: LoggerMessage) => {\n logger.info?.(message);\n secondaryLogger.info?.(message);\n }\n ),\n debug: validateLogger(\n \"debug\",\n options.name,\n options,\n (message: LoggerMessage) => {\n logger.debug?.(message);\n secondaryLogger.debug?.(message);\n }\n ),\n trace: validateLogger(\n \"trace\",\n options.name,\n options,\n (message: LoggerMessage) => {\n logger.trace?.(message);\n secondaryLogger.trace?.(message);\n }\n )\n } as Logger;\n\n result.log = (type: LogLevel, message: string | LoggerMessage) => {\n switch (type) {\n case \"error\":\n result.error(message);\n break;\n case \"warn\":\n result.warn(message);\n break;\n case \"info\":\n result.info(message);\n break;\n case \"debug\":\n result.debug(message);\n break;\n case \"trace\":\n result.trace(message);\n break;\n case \"silent\":\n break;\n default:\n result.info(message);\n break;\n }\n };\n\n return result;\n};\n\n/**\n * Create a logging function with a specific name and options.\n *\n * @param logger - The original logger to wrap with the custom logger.\n * @param logFn - The custom logging function to use for logging messages, which can be used to override the default logging behavior of the original logger.\n * @returns A new logger that combines the original logger's options with the custom logging function, allowing for customized logging behavior while still maintaining the original logger's configuration.\n */\nexport const withLogFn = (logger: Logger, logFn: LogFn): Logger => {\n const result = {\n options: logger.options,\n error: validateLogger(\n \"error\",\n logger.options.name,\n logger.options,\n (msg: LoggerMessage) => {\n logger.error?.(msg);\n logFn(\n {\n category: LogCategories.GENERAL,\n ...logger.options,\n type: \"error\",\n logId: uuid(),\n timestamp: Date.now(),\n ...msg.meta\n },\n msg.message\n );\n }\n ),\n warn: validateLogger(\n \"warn\",\n logger.options.name,\n logger.options,\n (msg: LoggerMessage) => {\n logger.warn?.(msg);\n logFn(\n {\n category: LogCategories.GENERAL,\n ...logger.options,\n type: \"warn\",\n logId: uuid(),\n timestamp: Date.now(),\n ...msg.meta\n },\n msg.message\n );\n }\n ),\n info: validateLogger(\n \"info\",\n logger.options.name,\n logger.options,\n (msg: LoggerMessage) => {\n logger.info?.(msg);\n logFn(\n {\n category: LogCategories.GENERAL,\n ...logger.options,\n type: \"info\",\n logId: uuid(),\n timestamp: Date.now(),\n ...msg.meta\n },\n msg.message\n );\n }\n ),\n debug: validateLogger(\n \"debug\",\n logger.options.name,\n logger.options,\n (msg: LoggerMessage) => {\n logger.debug?.(msg);\n logFn(\n {\n category: LogCategories.GENERAL,\n ...logger.options,\n type: \"debug\",\n logId: uuid(),\n timestamp: Date.now(),\n ...msg.meta\n },\n msg.message\n );\n }\n ),\n trace: validateLogger(\n \"trace\",\n logger.options.name,\n logger.options,\n (msg: LoggerMessage) => {\n logger.trace?.(msg);\n logFn(\n {\n category: LogCategories.GENERAL,\n ...logger.options,\n type: \"trace\",\n logId: uuid(),\n timestamp: Date.now(),\n ...msg.meta\n },\n msg.message\n );\n }\n )\n } as Logger;\n\n result.log = (type: LogLevel, message: string | LoggerMessage) => {\n switch (type) {\n case \"error\":\n result.error(message);\n break;\n case \"warn\":\n result.warn(message);\n break;\n case \"info\":\n result.info(message);\n break;\n case \"debug\":\n result.debug(message);\n break;\n case \"trace\":\n result.trace(message);\n break;\n case \"silent\":\n break;\n default:\n result.info(message);\n break;\n }\n };\n\n return result;\n};\n\n/**\n * Create a logging function with a specific name and options.\n *\n * @param logger - The original logger to wrap with the custom logger.\n * @param customLogger - The custom logger to use for logging messages, which can be used to override the default logging behavior of the original logger.\n * @returns A new logger that combines the original logger's options with the custom logger's methods, allowing for customized logging behavior while still maintaining the original logger's configuration.\n */\nexport const withCustomLogger = (\n logger: Logger,\n customLogger: CustomLogger\n): Logger => {\n const result = {\n options: logger.options,\n error: validateCustomLogger(\n \"error\",\n logger.options.name,\n logger.options,\n logger.error.bind(logger),\n customLogger.error?.bind(customLogger)\n ),\n warn: validateCustomLogger(\n \"warn\",\n logger.options.name,\n logger.options,\n logger.warn.bind(logger),\n customLogger.warn?.bind(customLogger)\n ),\n info: validateCustomLogger(\n \"info\",\n logger.options.name,\n logger.options,\n logger.info.bind(logger),\n customLogger.info?.bind(customLogger)\n ),\n debug: validateCustomLogger(\n \"debug\",\n logger.options.name,\n logger.options,\n logger.debug.bind(logger),\n customLogger.debug?.bind(customLogger)\n ),\n trace: validateCustomLogger(\n \"trace\",\n logger.options.name,\n logger.options,\n logger.trace.bind(logger),\n customLogger.trace?.bind(customLogger)\n )\n } as Logger;\n\n result.log = (type: LogLevel, message: string | LoggerMessage) => {\n switch (type) {\n case \"error\":\n result.error(message);\n break;\n case \"warn\":\n result.warn(message);\n break;\n case \"info\":\n result.info(message);\n break;\n case \"debug\":\n result.debug(message);\n break;\n case \"trace\":\n result.trace(message);\n break;\n case \"silent\":\n break;\n default:\n result.info(message);\n break;\n }\n };\n\n return result;\n};\n\nexport const consoleLogger: LogFn = (meta: LogFnMeta, message: string) =>\n consoleLog(\n {\n type: isSetString(meta) ? meta : meta.type,\n category: LogCategories.GENERAL,\n logId: uuid(),\n timestamp: Date.now(),\n ...(isSetObject(meta) ? meta : {})\n },\n message\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, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the logging function.\n * @returns A logging function.\n */\nexport const createLogger = (\n name: string | undefined,\n options: LoggerOptions,\n callback: LogFn = consoleLogger\n): Logger => {\n const result = {\n options: { name, ...options },\n error: validateLogger(\"error\", name, { name, ...options }, data =>\n callback({ ...data.meta, type: \"error\" }, data.message)\n ),\n warn: validateLogger(\"warn\", name, { name, ...options }, data =>\n callback({ ...data.meta, type: \"warn\" }, data.message)\n ),\n info: validateLogger(\"info\", name, { name, ...options }, data =>\n callback({ ...data.meta, type: \"info\" }, data.message)\n ),\n debug: validateLogger(\"debug\", name, { name, ...options }, data =>\n callback({ ...data.meta, type: \"debug\" }, data.message)\n ),\n trace: validateLogger(\"trace\", name, { name, ...options }, data =>\n callback({ ...data.meta, type: \"trace\" }, data.message)\n )\n } as Logger;\n\n result.log = (type: LogLevel, message: string | LoggerMessage) => {\n switch (type) {\n case \"error\":\n result.error(message);\n break;\n case \"warn\":\n result.warn(message);\n break;\n case \"info\":\n result.info(message);\n break;\n case \"debug\":\n result.debug(message);\n break;\n case \"trace\":\n result.trace(message);\n break;\n case \"silent\":\n break;\n default:\n result.info(message);\n break;\n }\n };\n\n return result;\n};\n\n/**\n * Extend a logging function with a specific name, adding a colored badge to the log output.\n *\n * @param logFn - The original logging function to extend.\n * @param options - The overlay metadata to use for the badge in the log output.\n * @returns A new logging function that includes the badge in its output.\n */\nexport const extendLogFn = (logFn: LogFn, options: LogFnOptions): LogFn => {\n return (meta, ...args) =>\n options.source || options.category\n ? logFn(\n isSetObject(meta)\n ? { ...options, ...meta }\n : { ...options, type: meta },\n `${colorBackground(String(options.source || options.category))} ${args\n .filter(Boolean)\n .map(arg => String(arg).trim())\n .join(\" \")} `\n )\n : logFn(meta, ...args);\n};\n\n/**\n * Extend a logger with a specific name and options, adding a colored badge to the log output for each log message generated by the logger.\n *\n * @param logger - The original logger to extend.\n * @param options - The options to configure the logging function, including the source, command, environment, plugin, log level, custom logger, and colors. These options can be used to customize the appearance and behavior of the log messages generated by the extended logger.\n * @returns A new logger that includes the badge in its output for each log message.\n */\nexport const extendLogger = (\n logger: Logger,\n options: LoggerOptions\n): Logger => {\n const opts = { ...logger.options, ...options } as RequiredKeys<\n LoggerOptions,\n \"name\"\n >;\n\n const result = {\n options: opts,\n error: validateLogger(\"error\", opts.name, opts, logger.error.bind(logger)),\n warn: validateLogger(\"warn\", opts.name, opts, logger.warn.bind(logger)),\n info: validateLogger(\"info\", opts.name, opts, logger.info.bind(logger)),\n debug: validateLogger(\"debug\", opts.name, opts, logger.debug.bind(logger)),\n trace: validateLogger(\"trace\", opts.name, opts, logger.trace.bind(logger))\n } as Logger;\n\n result.log = (type: LogLevel, message: string | LoggerMessage) => {\n switch (type) {\n case \"error\":\n result.error(message);\n break;\n case \"warn\":\n result.warn(message);\n break;\n case \"info\":\n result.info(message);\n break;\n case \"debug\":\n result.debug(message);\n break;\n case \"trace\":\n result.trace(message);\n break;\n case \"silent\":\n break;\n default:\n result.info(message);\n break;\n }\n };\n\n return result;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA+EA,SAAgB,UACd,mBACS;CACT,MAAM,QAAQ,SAAS,iBAAiB,IACpC,oBACA,kBAAkB,OAAO;CAE7B,OAAO,UAAU,WAAW,UAAU;AACxC;;;;;;;;AASA,SAAgB,gBACd,UACA,MACwB;CACxB,IAAI,aAAa,SACf,OAAO;EACL,SAAS;EACT,IAAI;EACJ,aAAa;EACb,eAAe;EACf,SAAS;E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,IACA,MAAM,MAAM,GAAG,IAAI;AAC3B;;;;;;;;AASA,MAAa,gBACX,QACA,YACW;CACX,MAAM,OAAO;EAAE,GAAG,OAAO;EAAS,GAAG;CAAQ;CAK7C,MAAM,SAAS;EACb,SAAS;EACT,OAAO,eAAe,SAAS,KAAK,MAAM,MAAM,OAAO,MAAM,KAAK,MAAM,CAAC;EACzE,MAAM,eAAe,QAAQ,KAAK,MAAM,MAAM,OAAO,KAAK,KAAK,MAAM,CAAC;EACtE,MAAM,eAAe,QAAQ,KAAK,MAAM,MAAM,OAAO,KAAK,KAAK,MAAM,CAAC;EACtE,OAAO,eAAe,SAAS,KAAK,MAAM,MAAM,OAAO,MAAM,KAAK,MAAM,CAAC;EACzE,OAAO,eAAe,SAAS,KAAK,MAAM,MAAM,OAAO,MAAM,KAAK,MAAM,CAAC;CAC3E;CAEA,OAAO,OAAO,MAAgB,YAAoC;EAChE,QAAQ,MAAR;GACE,KAAK;IACH,OAAO,MAAM,OAAO;IACpB;GACF,KAAK;IACH,OAAO,KAAK,OAAO;IACnB;GACF,KAAK;IACH,OAAO,KAAK,OAAO;IACnB;GACF,KAAK;IACH,OAAO,MAAM,OAAO;IACpB;GACF,KAAK;IACH,OAAO,MAAM,OAAO;IACpB;GACF,KAAK,UACH;GACF;IACE,OAAO,KAAK,OAAO;IACnB;EACJ;CACF;CAEA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"merge.mjs","names":[],"sources":["../../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 { getUnique } from \"@stryke/helpers/get-unique\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { isSetArray } from \"@stryke/type-checks/is-set-array\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport defu, { createDefu } from \"defu\";\nimport type {\n PartialPlugin,\n Plugin,\n PluginContext,\n ResolvedConfig\n} from \"../types\";\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 type TValue = (typeof obj)[typeof key];\n\n if (key === \"input\" && isSet(value)) {\n if (isString(obj[key]) && Array.isArray(value) && value.length === 0) {\n return true;\n }\n\n obj[key] = value;\n if (isSetArray(obj[key])) {\n obj[key] = getUnique(obj[key]) as TValue;\n }\n\n return true;\n }\n\n if (key === \"compatibilityDate\" && isSetString(value)) {\n obj[key] = value;\n return true;\n }\n\n if (\n (key === \"format\" || key === \"output.format\") &&\n (isSetString(value) || isSetArray(value))\n ) {\n obj[key] = value;\n if (isSetArray(obj[key])) {\n obj[key] = getUnique(obj[key]) as TValue;\n }\n\n return true;\n }\n\n if (!isSet(obj[key]) && isString(value)) {\n obj[key] = value;\n return true;\n }\n\n return false;\n}) as (...configs: unknown[]) => ResolvedConfig;\n"],"mappings":";;;;;;;;;AA2CA,MAAM,cAAc,YAAY,KAAK,KAAK,UAAU;CAClD,IAAI,aAAa,IAAI,IAAI,KAAK,aAAa,KAAK,GAAG;EACjD,IAAI,OAAO;GACT,GAAG,IAAI;GACP,GAAG;GACH,SAAS,OAAO,GAAG,WAAkB;IACnC,MAAM,CAAC,SAAS,WAAW,MAAM,QAAQ,IAAI,CAE1C,eAAe,IAAI,IAAI,EAAU,GAAG,MAAM,GAE1C,eAAe,KAAK,EAAU,GAAG,MAAM,CAC1C,CAAC;IAED,OAAO,WAAW,UAAU,KAAK,SAAS,OAAO,IAAI,WAAW;GAClE;EACF;EACA,OAAO;CACT;CAEA,OAAO;AACT,CAAC;;;;;;;;AASD,SAAgB,MACd,SACA,SACuD;CACvD,OAAO,YAAY,SAAS,OAAO;AAKrC;;;;;;;;;;;;;;;;;AAkBA,MAAa,cAAc,YAAY,KAAK,KAAK,UAAU;CAGzD,IAAI,QAAQ,WAAW,MAAM,KAAK,GAAG;EACnC,IAAI,SAAS,IAAI,IAAI,KAAK,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,GACjE,OAAO;EAGT,IAAI,OAAO;EACX,IAAI,WAAW,IAAI,IAAI,GACrB,IAAI,OAAO,UAAU,IAAI,IAAI;EAG/B,OAAO;CACT;CAEA,IAAI,QAAQ,uBAAuB,YAAY,KAAK,GAAG;EACrD,IAAI,OAAO;EACX,OAAO;CACT;CAEA,KACG,QAAQ,YAAY,QAAQ,qBAC5B,YAAY,KAAK,KAAK,WAAW,KAAK,IACvC;EACA,IAAI,OAAO;EACX,IAAI,WAAW,IAAI,IAAI,GACrB,IAAI,OAAO,UAAU,IAAI,IAAI;EAG/B,OAAO;CACT;CAEA,IAAI,CAAC,MAAM,IAAI,IAAI,KAAK,SAAS,KAAK,GAAG;EACvC,IAAI,OAAO;EACX,OAAO;CACT;CAEA,OAAO;AACT,CAAC"}
1
+ {"version":3,"file":"merge.mjs","names":[],"sources":["../../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 { getUnique } from \"@stryke/helpers/get-unique\";\nimport { isSet } from \"@stryke/type-checks/is-set\";\nimport { isSetArray } from \"@stryke/type-checks/is-set-array\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport defu, { createDefu } from \"defu\";\nimport type {\n PartialPlugin,\n Plugin,\n PluginContext,\n ResolvedConfig\n} from \"../types\";\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 type TValue = (typeof obj)[typeof key];\n\n if (key === \"input\" && isSet(value)) {\n if (isString(obj[key]) && Array.isArray(value) && value.length === 0) {\n return true;\n }\n\n obj[key] = value;\n if (isSetArray(obj[key])) {\n obj[key] = getUnique(obj[key]) as TValue;\n }\n\n return true;\n }\n\n if (key === \"compatibilityDate\" && isSetString(value)) {\n obj[key] = value;\n return true;\n }\n\n if (\n (key === \"format\" || key === \"output.format\") &&\n (isSetString(value) || isSetArray(value))\n ) {\n obj[key] = value;\n if (isSetArray(obj[key])) {\n obj[key] = getUnique(obj[key]) as TValue;\n }\n\n return true;\n }\n\n if (!isSet(obj[key]) && isString(value)) {\n obj[key] = value;\n return true;\n }\n\n return false;\n}) as (...configs: unknown[]) => ResolvedConfig;\n"],"mappings":";;;;;;;;;AA2CA,MAAM,cAAc,YAAY,KAAK,KAAK,UAAU;CAClD,IAAI,aAAa,IAAI,IAAI,KAAK,aAAa,KAAK,GAAG;EACjD,IAAI,OAAO;GACT,GAAG,IAAI;GACP,GAAG;GACH,SAAS,OAAO,GAAG,WAAkB;IACnC,MAAM,CAAC,SAAS,WAAW,MAAM,QAAQ,IAAI,CAE1C,eAAe,IAAI,IAAI,CAAC,CAAS,GAAG,MAAM,GAE1C,eAAe,KAAK,CAAC,CAAS,GAAG,MAAM,CAC1C,CAAC;IAED,OAAO,WAAW,UAAU,KAAK,SAAS,OAAO,IAAI,WAAW;GAClE;EACF;EACA,OAAO;CACT;CAEA,OAAO;AACT,CAAC;;;;;;;;AASD,SAAgB,MACd,SACA,SACuD;CACvD,OAAO,YAAY,SAAS,OAAO;AAKrC;;;;;;;;;;;;;;;;;AAkBA,MAAa,cAAc,YAAY,KAAK,KAAK,UAAU;CAGzD,IAAI,QAAQ,WAAW,MAAM,KAAK,GAAG;EACnC,IAAI,SAAS,IAAI,IAAI,KAAK,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,GACjE,OAAO;EAGT,IAAI,OAAO;EACX,IAAI,WAAW,IAAI,IAAI,GACrB,IAAI,OAAO,UAAU,IAAI,IAAI;EAG/B,OAAO;CACT;CAEA,IAAI,QAAQ,uBAAuB,YAAY,KAAK,GAAG;EACrD,IAAI,OAAO;EACX,OAAO;CACT;CAEA,KACG,QAAQ,YAAY,QAAQ,qBAC5B,YAAY,KAAK,KAAK,WAAW,KAAK,IACvC;EACA,IAAI,OAAO;EACX,IAAI,WAAW,IAAI,IAAI,GACrB,IAAI,OAAO,UAAU,IAAI,IAAI;EAG/B,OAAO;CACT;CAEA,IAAI,CAAC,MAAM,IAAI,IAAI,KAAK,SAAS,KAAK,GAAG;EACvC,IAAI,OAAO;EACX,OAAO;CACT;CAEA,OAAO;AACT,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"modules.mjs","names":[],"sources":["../../src/plugin-utils/modules.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 { Context } from \"../types/context\";\n\n/**\n * Determine if a module ID is a built-in Powerlines module ID.\n *\n * @param context - The Powerlines context.\n * @param moduleName - The name of the module to check.\n * @returns `true` if the module is a built-in module, otherwise `false`.\n */\nexport function isBuiltinModule(context: Context, moduleName: string): boolean {\n const prefix: string = context.config?.framework?.name || \"powerlines\";\n\n return (\n moduleName.startsWith(`${prefix.replace(/:$/, \"\")}:`) ||\n Object.keys(context.fs.metadata)\n .filter(key => context.fs.metadata[key]?.type === \"builtin\")\n .includes(moduleName)\n );\n}\n"],"mappings":";;;;;;;;AA2BA,SAAgB,gBAAgB,SAAkB,YAA6B;CAC7E,MAAM,SAAiB,QAAQ,QAAQ,WAAW,QAAQ;CAE1D,OACE,WAAW,WAAW,GAAG,OAAO,QAAQ,MAAM,EAAE,EAAE,EAAE,KACpD,OAAO,KAAK,QAAQ,GAAG,QAAQ,EAC5B,QAAO,QAAO,QAAQ,GAAG,SAAS,MAAM,SAAS,SAAS,EAC1D,SAAS,UAAU;AAE1B"}
1
+ {"version":3,"file":"modules.mjs","names":[],"sources":["../../src/plugin-utils/modules.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 { Context } from \"../types/context\";\n\n/**\n * Determine if a module ID is a built-in Powerlines module ID.\n *\n * @param context - The Powerlines context.\n * @param moduleName - The name of the module to check.\n * @returns `true` if the module is a built-in module, otherwise `false`.\n */\nexport function isBuiltinModule(context: Context, moduleName: string): boolean {\n const prefix: string = context.config?.framework?.name || \"powerlines\";\n\n return (\n moduleName.startsWith(`${prefix.replace(/:$/, \"\")}:`) ||\n Object.keys(context.fs.metadata)\n .filter(key => context.fs.metadata[key]?.type === \"builtin\")\n .includes(moduleName)\n );\n}\n"],"mappings":";;;;;;;;AA2BA,SAAgB,gBAAgB,SAAkB,YAA6B;CAC7E,MAAM,SAAiB,QAAQ,QAAQ,WAAW,QAAQ;CAE1D,OACE,WAAW,WAAW,GAAG,OAAO,QAAQ,MAAM,EAAE,EAAE,EAAE,KACpD,OAAO,KAAK,QAAQ,GAAG,QAAQ,CAAC,CAC7B,QAAO,QAAO,QAAQ,GAAG,SAAS,IAAI,EAAE,SAAS,SAAS,CAAC,CAC3D,SAAS,UAAU;AAE1B"}
@@ -1 +1 @@
1
- {"version":3,"file":"paths.mjs","names":[],"sources":["../../src/plugin-utils/paths.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 { joinPaths } from \"@stryke/path/join\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { IsUndefined } from \"@stryke/types/base\";\nimport { UnresolvedContext } from \"../types/context\";\n\n/**\n * Replaces tokens in the given path string with their corresponding values from the context.\n *\n * @remarks\n * The following tokens are supported:\n * - `{cwd}` - The current working directory.\n * - `{workspaceRoot}` - The current working directory (same as `{cwd}`).\n * - `{root}` - The root directory of the project (same as `{projectRoot}`).\n * - `{projectRoot}` - The root directory of the project (same as `{root}`).\n * - `{sourceRoot}` - The source root directory of the project (usually `{root}/src`).\n * - `{powerlinesPath}` - The directory where Powerlines is installed.\n * - `{cachePath}` - The environment's directory for cached files.\n * - `{dataPath}` - The environment's directory for data files.\n * - `{logPath}` - The environment's directory for log files.\n * - `{tempPath}` - The environment's directory for temporary files.\n * - `{configPath}` - The environment's directory for configuration files.\n * - `{output}` - The configured output directory for the project.\n * - `{outputPath}` - The configured output directory for the project.\n * - `{copy}` - The configured final/copied distribution directory for the project.\n * - `{copyPath}` - The configured final/copied distribution directory for the project.\n * - `{artifactsPath}` - The configured directory for build artifacts.\n * - `{builtinPath}` - The configured directory for generated built-in plugins.\n * - `{entryPath}` - The configured directory for generated entry files.\n *\n * @example\n * ```ts\n * const path = replacePathTokens(context, \"{root}/dist\");\n * // If context.config.root is \"/home/user/project\", this will return \"/home/user/project/dist\"\n *\n * const pathWithCopy = replacePathTokens(context, \"{copy}\");\n * // If context.config.output.copy.path is \"/home/user/project/dist-copy\", this will return \"/home/user/project/dist-copy\"\n * ```\n *\n * @param context - The context containing the values for the path tokens.\n * @param path - The path string with tokens to replace.\n * @returns The path string with tokens replaced by their corresponding values from the context.\n */\nexport function replacePathTokens(\n context: UnresolvedContext,\n path?: string\n): IsUndefined<typeof path> extends true ? undefined : string {\n if (!path) {\n return path as IsUndefined<typeof path> extends true ? undefined : string;\n }\n\n let result = path\n .replaceAll(\"{cwd}\", context.config.cwd || process.cwd())\n .replaceAll(\"{workspaceRoot}\", context.config.cwd || process.cwd())\n .replaceAll(\"{root}\", context.config.root)\n .replaceAll(\"{projectRoot}\", context.config.root)\n .replaceAll(\"{sourceRoot}\", joinPaths(context.config.root, \"src\"))\n // .replaceAll(\"{powerlinesPath}\", context.powerlinesPath)\n .replaceAll(\"{cachePath}\", context.cachePath)\n .replaceAll(\"{dataPath}\", context.dataPath)\n .replaceAll(\"{logPath}\", context.envPaths.log)\n .replaceAll(\"{tempPath}\", context.envPaths.temp)\n .replaceAll(\"{configPath}\", context.envPaths.config)\n .replaceAll(\n \"{artifactsPath}\",\n replacePath(context.artifactsPath, context.config.cwd)\n )\n .replaceAll(\n \"{builtinPath}\",\n replacePath(context.builtinsPath, context.config.cwd)\n )\n .replaceAll(\n \"{builtinsPath}\",\n replacePath(context.builtinsPath, context.config.cwd)\n )\n .replaceAll(\n \"{entryPath}\",\n replacePath(context.entryPath, context.config.cwd)\n );\n\n if (context.config.output) {\n if (isSetString(context.config.output.path)) {\n result = result\n .replaceAll(\"{outputPath}\", context.config.output.path)\n .replaceAll(\"{output}\", context.config.output.path);\n }\n if (\n context.config.output.copy &&\n isSetString(context.config.output.copy?.path)\n ) {\n result = result\n .replaceAll(\"{copyPath}\", context.config.output.copy.path)\n .replaceAll(\"{copy}\", context.config.output.copy.path);\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,kBACd,SACA,MAC4D;CAC5D,IAAI,CAAC,MACH,OAAO;CAGT,IAAI,SAAS,KACV,WAAW,SAAS,QAAQ,OAAO,OAAO,QAAQ,IAAI,CAAC,EACvD,WAAW,mBAAmB,QAAQ,OAAO,OAAO,QAAQ,IAAI,CAAC,EACjE,WAAW,UAAU,QAAQ,OAAO,IAAI,EACxC,WAAW,iBAAiB,QAAQ,OAAO,IAAI,EAC/C,WAAW,gBAAgB,UAAU,QAAQ,OAAO,MAAM,KAAK,CAAC,EAEhE,WAAW,eAAe,QAAQ,SAAS,EAC3C,WAAW,cAAc,QAAQ,QAAQ,EACzC,WAAW,aAAa,QAAQ,SAAS,GAAG,EAC5C,WAAW,cAAc,QAAQ,SAAS,IAAI,EAC9C,WAAW,gBAAgB,QAAQ,SAAS,MAAM,EAClD,WACC,mBACA,YAAY,QAAQ,eAAe,QAAQ,OAAO,GAAG,CACvD,EACC,WACC,iBACA,YAAY,QAAQ,cAAc,QAAQ,OAAO,GAAG,CACtD,EACC,WACC,kBACA,YAAY,QAAQ,cAAc,QAAQ,OAAO,GAAG,CACtD,EACC,WACC,eACA,YAAY,QAAQ,WAAW,QAAQ,OAAO,GAAG,CACnD;CAEF,IAAI,QAAQ,OAAO,QAAQ;EACzB,IAAI,YAAY,QAAQ,OAAO,OAAO,IAAI,GACxC,SAAS,OACN,WAAW,gBAAgB,QAAQ,OAAO,OAAO,IAAI,EACrD,WAAW,YAAY,QAAQ,OAAO,OAAO,IAAI;EAEtD,IACE,QAAQ,OAAO,OAAO,QACtB,YAAY,QAAQ,OAAO,OAAO,MAAM,IAAI,GAE5C,SAAS,OACN,WAAW,cAAc,QAAQ,OAAO,OAAO,KAAK,IAAI,EACxD,WAAW,UAAU,QAAQ,OAAO,OAAO,KAAK,IAAI;CAE3D;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"paths.mjs","names":[],"sources":["../../src/plugin-utils/paths.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 { joinPaths } from \"@stryke/path/join\";\nimport { replacePath } from \"@stryke/path/replace\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { IsUndefined } from \"@stryke/types/base\";\nimport { UnresolvedContext } from \"../types/context\";\n\n/**\n * Replaces tokens in the given path string with their corresponding values from the context.\n *\n * @remarks\n * The following tokens are supported:\n * - `{cwd}` - The current working directory.\n * - `{workspaceRoot}` - The current working directory (same as `{cwd}`).\n * - `{root}` - The root directory of the project (same as `{projectRoot}`).\n * - `{projectRoot}` - The root directory of the project (same as `{root}`).\n * - `{sourceRoot}` - The source root directory of the project (usually `{root}/src`).\n * - `{powerlinesPath}` - The directory where Powerlines is installed.\n * - `{cachePath}` - The environment's directory for cached files.\n * - `{dataPath}` - The environment's directory for data files.\n * - `{logPath}` - The environment's directory for log files.\n * - `{tempPath}` - The environment's directory for temporary files.\n * - `{configPath}` - The environment's directory for configuration files.\n * - `{output}` - The configured output directory for the project.\n * - `{outputPath}` - The configured output directory for the project.\n * - `{copy}` - The configured final/copied distribution directory for the project.\n * - `{copyPath}` - The configured final/copied distribution directory for the project.\n * - `{artifactsPath}` - The configured directory for build artifacts.\n * - `{builtinPath}` - The configured directory for generated built-in plugins.\n * - `{entryPath}` - The configured directory for generated entry files.\n *\n * @example\n * ```ts\n * const path = replacePathTokens(context, \"{root}/dist\");\n * // If context.config.root is \"/home/user/project\", this will return \"/home/user/project/dist\"\n *\n * const pathWithCopy = replacePathTokens(context, \"{copy}\");\n * // If context.config.output.copy.path is \"/home/user/project/dist-copy\", this will return \"/home/user/project/dist-copy\"\n * ```\n *\n * @param context - The context containing the values for the path tokens.\n * @param path - The path string with tokens to replace.\n * @returns The path string with tokens replaced by their corresponding values from the context.\n */\nexport function replacePathTokens(\n context: UnresolvedContext,\n path?: string\n): IsUndefined<typeof path> extends true ? undefined : string {\n if (!path) {\n return path as IsUndefined<typeof path> extends true ? undefined : string;\n }\n\n let result = path\n .replaceAll(\"{cwd}\", context.config.cwd || process.cwd())\n .replaceAll(\"{workspaceRoot}\", context.config.cwd || process.cwd())\n .replaceAll(\"{root}\", context.config.root)\n .replaceAll(\"{projectRoot}\", context.config.root)\n .replaceAll(\"{sourceRoot}\", joinPaths(context.config.root, \"src\"))\n // .replaceAll(\"{powerlinesPath}\", context.powerlinesPath)\n .replaceAll(\"{cachePath}\", context.cachePath)\n .replaceAll(\"{dataPath}\", context.dataPath)\n .replaceAll(\"{logPath}\", context.envPaths.log)\n .replaceAll(\"{tempPath}\", context.envPaths.temp)\n .replaceAll(\"{configPath}\", context.envPaths.config)\n .replaceAll(\n \"{artifactsPath}\",\n replacePath(context.artifactsPath, context.config.cwd)\n )\n .replaceAll(\n \"{builtinPath}\",\n replacePath(context.builtinsPath, context.config.cwd)\n )\n .replaceAll(\n \"{builtinsPath}\",\n replacePath(context.builtinsPath, context.config.cwd)\n )\n .replaceAll(\n \"{entryPath}\",\n replacePath(context.entryPath, context.config.cwd)\n );\n\n if (context.config.output) {\n if (isSetString(context.config.output.path)) {\n result = result\n .replaceAll(\"{outputPath}\", context.config.output.path)\n .replaceAll(\"{output}\", context.config.output.path);\n }\n if (\n context.config.output.copy &&\n isSetString(context.config.output.copy?.path)\n ) {\n result = result\n .replaceAll(\"{copyPath}\", context.config.output.copy.path)\n .replaceAll(\"{copy}\", context.config.output.copy.path);\n }\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,SAAgB,kBACd,SACA,MAC4D;CAC5D,IAAI,CAAC,MACH,OAAO;CAGT,IAAI,SAAS,KACV,WAAW,SAAS,QAAQ,OAAO,OAAO,QAAQ,IAAI,CAAC,CAAC,CACxD,WAAW,mBAAmB,QAAQ,OAAO,OAAO,QAAQ,IAAI,CAAC,CAAC,CAClE,WAAW,UAAU,QAAQ,OAAO,IAAI,CAAC,CACzC,WAAW,iBAAiB,QAAQ,OAAO,IAAI,CAAC,CAChD,WAAW,gBAAgB,UAAU,QAAQ,OAAO,MAAM,KAAK,CAAC,CAAC,CAEjE,WAAW,eAAe,QAAQ,SAAS,CAAC,CAC5C,WAAW,cAAc,QAAQ,QAAQ,CAAC,CAC1C,WAAW,aAAa,QAAQ,SAAS,GAAG,CAAC,CAC7C,WAAW,cAAc,QAAQ,SAAS,IAAI,CAAC,CAC/C,WAAW,gBAAgB,QAAQ,SAAS,MAAM,CAAC,CACnD,WACC,mBACA,YAAY,QAAQ,eAAe,QAAQ,OAAO,GAAG,CACvD,CAAC,CACA,WACC,iBACA,YAAY,QAAQ,cAAc,QAAQ,OAAO,GAAG,CACtD,CAAC,CACA,WACC,kBACA,YAAY,QAAQ,cAAc,QAAQ,OAAO,GAAG,CACtD,CAAC,CACA,WACC,eACA,YAAY,QAAQ,WAAW,QAAQ,OAAO,GAAG,CACnD;CAEF,IAAI,QAAQ,OAAO,QAAQ;EACzB,IAAI,YAAY,QAAQ,OAAO,OAAO,IAAI,GACxC,SAAS,OACN,WAAW,gBAAgB,QAAQ,OAAO,OAAO,IAAI,CAAC,CACtD,WAAW,YAAY,QAAQ,OAAO,OAAO,IAAI;EAEtD,IACE,QAAQ,OAAO,OAAO,QACtB,YAAY,QAAQ,OAAO,OAAO,MAAM,IAAI,GAE5C,SAAS,OACN,WAAW,cAAc,QAAQ,OAAO,OAAO,KAAK,IAAI,CAAC,CACzD,WAAW,UAAU,QAAQ,OAAO,OAAO,KAAK,IAAI;CAE3D;CAEA,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"base.mjs","names":["#isDisposed"],"sources":["../../src/storage/base.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 { appendPath } from \"@stryke/path/append\";\nimport { correctPath } from \"@stryke/path/correct-path\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { MaybePromise } from \"@stryke/types/base\";\nimport { resolve } from \"node:path\";\nimport { Context } from \"../types/context\";\nimport { StorageAdapter, StoragePreset } from \"../types/fs\";\n\nexport interface StorageAdapterOptions {\n base: string;\n isReadOnly?: boolean;\n ignore?: string | string[];\n}\n\n/**\n * Abstract base class for storage adapters, providing a template for storage operations.\n */\nexport abstract class BaseStorageAdapter<\n TOptions extends StorageAdapterOptions = StorageAdapterOptions\n> implements StorageAdapter {\n /**\n * Indicates whether the storage adapter has been disposed.\n */\n #isDisposed = false;\n\n /**\n * A name identifying the storage adapter type.\n */\n public abstract name: string;\n\n /**\n * Configuration options for the storage adapter.\n */\n public options: TOptions;\n\n /**\n * The storage preset for the adapter.\n *\n * @remarks\n * This can be used as an alternate way to identify the type of storage being used.\n */\n public readonly preset?: StoragePreset | null = null;\n\n /**\n * Constructor for the BaseStorageAdapter.\n *\n * @param context - The Powerlines context.\n * @param options - Configuration options for the storage adapter.\n */\n public constructor(\n protected context: Context,\n options: TOptions = { base: \"/\" } as TOptions\n ) {\n this.options = options;\n this.options.base = resolve(options.base);\n this.options.isReadOnly = !!options.isReadOnly;\n }\n\n /**\n * Synchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns Returns `true` if the key exists, otherwise `false`.\n */\n public abstract existsSync(key: string): boolean;\n\n /**\n * Asynchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns A promise that resolves to `true` if the key exists, otherwise `false`.\n */\n public async exists(key: string): Promise<boolean> {\n return this.existsSync(key);\n }\n\n /**\n * Synchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns The value associated with the key, or `null` if the key does not exist.\n */\n public abstract getSync(key: string): string | null;\n\n /**\n * Asynchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns A promise that resolves to the value associated with the key, or `null` if the key does not exist.\n */\n public async get(key: string): Promise<string | null> {\n return this.getSync(key);\n }\n\n /**\n * Synchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public abstract setSync(key: string, value: string): void;\n\n /**\n * Asynchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public async set(key: string, value: string): Promise<void> {\n if (!this.isReadOnly && (!this.existsSync(key) || this.overwrite)) {\n this.setSync(key, value);\n }\n }\n\n /**\n * Synchronously creates a directory at the specified path.\n *\n * @param _ - The path of the directory to create.\n */\n public mkdirSync(_: string) {}\n\n /**\n * Creates a directory at the specified path.\n *\n * @param dirPath - The path of the directory to create.\n */\n public async mkdir(dirPath: string): Promise<void> {\n return Promise.resolve(this.mkdirSync(dirPath));\n }\n\n /**\n * Synchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public abstract removeSync(key: string): void;\n\n /**\n * Asynchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public async remove(key: string): Promise<void> {\n if (!this.isReadOnly && this.overwrite) {\n this.removeSync(key);\n }\n }\n\n /**\n * Synchronously removes all entries from the storage that match the provided base path.\n *\n * @param base - The base path to clear keys from.\n */\n public clearSync(base?: string) {\n if (!this.isReadOnly && this.overwrite) {\n const keys = this.listSync(base || this.options.base);\n if (!keys.length) {\n return;\n }\n\n keys.map(key =>\n this.removeSync(\n base && !key.startsWith(base) ? joinPaths(base, key) : key\n )\n );\n }\n }\n\n /**\n * Asynchronously removes all entries from the storage that match the provided base path.\n *\n * @param base - The base path to clear keys from.\n * @returns A promise that resolves when the operation is complete.\n */\n public async clear(base?: string): Promise<void> {\n if (!this.isReadOnly && this.overwrite) {\n const keys = await this.list(base || this.options.base);\n if (!keys.length) {\n return;\n }\n\n await Promise.all(\n keys.map(async key =>\n this.remove(\n base && !key.startsWith(base) ? joinPaths(base, key) : key\n )\n )\n );\n }\n }\n\n /**\n * Lists all keys under a given base path synchronously.\n *\n * @param base - The base path to list keys from.\n * @returns An array of keys under the specified base path.\n */\n public abstract listSync(base?: string): string[];\n\n /**\n * Asynchronously lists all keys under a given base path.\n *\n * @param base - The base path to list keys from.\n * @returns A promise that resolves to an array of keys under the specified base path.\n */\n public async list(base?: string): Promise<string[]> {\n return this.listSync(base);\n }\n\n /**\n * Synchronously checks if the given key is a directory.\n *\n * @param _ - The key to check.\n * @returns `true` if the key is a directory, otherwise `false`.\n */\n public isDirectorySync(_: string): boolean {\n return false;\n }\n\n /**\n * Checks if the given key is a directory.\n *\n * @param key - The key to check.\n * @returns A promise that resolves to `true` if the key is a directory, otherwise `false`.\n */\n public async isDirectory(key: string) {\n return Promise.resolve(this.isDirectorySync(key));\n }\n\n /**\n * Synchronously checks if the given key is a file.\n *\n * @param key - The key to check.\n * @returns `true` if the key is a file, otherwise `false`.\n */\n public isFileSync(key: string): boolean {\n return this.existsSync(key) && !this.isDirectorySync(key);\n }\n\n /**\n * Checks if the given key is a file.\n *\n * @param key - The key to check.\n * @returns A promise that resolves to `true` if the key is a file, otherwise `false`.\n */\n public async isFile(key: string) {\n return Promise.resolve(this.isFileSync(key));\n }\n\n /**\n * Disposes of the storage adapter, releasing any held resources.\n *\n * @returns A promise that resolves when the disposal is complete.\n */\n public dispose(): MaybePromise<void> {\n return Promise.resolve();\n }\n\n /**\n * Async dispose method to clean up resources.\n *\n * @returns A promise that resolves when disposal is complete.\n */\n public async [Symbol.asyncDispose]() {\n return this._dispose();\n }\n\n /**\n * Determines if the storage adapter is read-only based on the provided options.\n *\n * @returns `true` if the storage adapter is read-only, otherwise `false`.\n */\n protected get isReadOnly() {\n return !!this.options.isReadOnly;\n }\n\n /**\n * Determines if the storage adapter should overwrite existing keys based on the provided options and context configuration.\n *\n * @returns `true` if the storage adapter should overwrite existing keys, otherwise `false`.\n */\n protected get overwrite() {\n return !this.isReadOnly && this.context.config.output.overwrite !== false;\n }\n\n /**\n * Resolves a given key to its full path within the storage adapter.\n *\n * @param key - The key to resolve.\n * @returns The resolved full path for the key.\n */\n protected resolve(key?: string) {\n if (!key) {\n return this.options.base;\n }\n\n if (/\\.\\.:|\\.\\.$/.test(key)) {\n throw new Error(\n `[${this.name}]: Invalid key: ${JSON.stringify(key)} provided to storage adapter.`\n );\n }\n\n return appendPath(correctPath(key).replace(/:/g, \"/\"), this.options.base);\n }\n\n /**\n * Disposes of the storage adapter, releasing any held resources.\n *\n * @returns A promise that resolves when the disposal is complete.\n */\n protected async _dispose(): Promise<void> {\n if (!this.#isDisposed) {\n await Promise.resolve(this.dispose());\n this.#isDisposed = true;\n }\n }\n}\n"],"mappings":";;;;;;;;;AAmCA,IAAsB,qBAAtB,MAE4B;CA+Bd;;;;CA3BZ,cAAc;;;;CAUd,AAAO;;;;;;;CAQP,AAAgB,SAAgC;;;;;;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UAAU,MAAM,GAAG,IAAI,GACzD,CACF,CACF;EACF;CACF;;;;;;;CAgBA,MAAa,KAAK,MAAkC;EAClD,OAAO,KAAK,SAAS,IAAI;CAC3B;;;;;;;CAQA,AAAO,gBAAgB,GAAoB;EACzC,OAAO;CACT;;;;;;;CAQA,MAAa,YAAY,KAAa;EACpC,OAAO,QAAQ,QAAQ,KAAK,gBAAgB,GAAG,CAAC;CAClD;;;;;;;CAQA,AAAO,WAAW,KAAsB;EACtC,OAAO,KAAK,WAAW,GAAG,KAAK,CAAC,KAAK,gBAAgB,GAAG;CAC1D;;;;;;;CAQA,MAAa,OAAO,KAAa;EAC/B,OAAO,QAAQ,QAAQ,KAAK,WAAW,GAAG,CAAC;CAC7C;;;;;;CAOA,AAAO,UAA8B;EACnC,OAAO,QAAQ,QAAQ;CACzB;;;;;;CAOA,OAAc,OAAO,gBAAgB;EACnC,OAAO,KAAK,SAAS;CACvB;;;;;;CAOA,IAAc,aAAa;EACzB,OAAO,CAAC,CAAC,KAAK,QAAQ;CACxB;;;;;;CAOA,IAAc,YAAY;EACxB,OAAO,CAAC,KAAK,cAAc,KAAK,QAAQ,OAAO,OAAO,cAAc;CACtE;;;;;;;CAQA,AAAU,QAAQ,KAAc;EAC9B,IAAI,CAAC,KACH,OAAO,KAAK,QAAQ;EAGtB,IAAI,cAAc,KAAK,GAAG,GACxB,MAAM,IAAI,MACR,IAAI,KAAK,KAAK,kBAAkB,KAAK,UAAU,GAAG,EAAE,8BACtD;EAGF,OAAO,WAAW,YAAY,GAAG,EAAE,QAAQ,MAAM,GAAG,GAAG,KAAK,QAAQ,IAAI;CAC1E;;;;;;CAOA,MAAgB,WAA0B;EACxC,IAAI,CAAC,KAAKA,aAAa;GACrB,MAAM,QAAQ,QAAQ,KAAK,QAAQ,CAAC;GACpC,KAAKA,cAAc;EACrB;CACF;AACF"}
1
+ {"version":3,"file":"base.mjs","names":["#isDisposed"],"sources":["../../src/storage/base.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 { appendPath } from \"@stryke/path/append\";\nimport { correctPath } from \"@stryke/path/correct-path\";\nimport { joinPaths } from \"@stryke/path/join\";\nimport { MaybePromise } from \"@stryke/types/base\";\nimport { resolve } from \"node:path\";\nimport { Context } from \"../types/context\";\nimport { StorageAdapter, StoragePreset } from \"../types/fs\";\n\nexport interface StorageAdapterOptions {\n base: string;\n isReadOnly?: boolean;\n ignore?: string | string[];\n}\n\n/**\n * Abstract base class for storage adapters, providing a template for storage operations.\n */\nexport abstract class BaseStorageAdapter<\n TOptions extends StorageAdapterOptions = StorageAdapterOptions\n> implements StorageAdapter {\n /**\n * Indicates whether the storage adapter has been disposed.\n */\n #isDisposed = false;\n\n /**\n * A name identifying the storage adapter type.\n */\n public abstract name: string;\n\n /**\n * Configuration options for the storage adapter.\n */\n public options: TOptions;\n\n /**\n * The storage preset for the adapter.\n *\n * @remarks\n * This can be used as an alternate way to identify the type of storage being used.\n */\n public readonly preset?: StoragePreset | null = null;\n\n /**\n * Constructor for the BaseStorageAdapter.\n *\n * @param context - The Powerlines context.\n * @param options - Configuration options for the storage adapter.\n */\n public constructor(\n protected context: Context,\n options: TOptions = { base: \"/\" } as TOptions\n ) {\n this.options = options;\n this.options.base = resolve(options.base);\n this.options.isReadOnly = !!options.isReadOnly;\n }\n\n /**\n * Synchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns Returns `true` if the key exists, otherwise `false`.\n */\n public abstract existsSync(key: string): boolean;\n\n /**\n * Asynchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns A promise that resolves to `true` if the key exists, otherwise `false`.\n */\n public async exists(key: string): Promise<boolean> {\n return this.existsSync(key);\n }\n\n /**\n * Synchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns The value associated with the key, or `null` if the key does not exist.\n */\n public abstract getSync(key: string): string | null;\n\n /**\n * Asynchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns A promise that resolves to the value associated with the key, or `null` if the key does not exist.\n */\n public async get(key: string): Promise<string | null> {\n return this.getSync(key);\n }\n\n /**\n * Synchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public abstract setSync(key: string, value: string): void;\n\n /**\n * Asynchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public async set(key: string, value: string): Promise<void> {\n if (!this.isReadOnly && (!this.existsSync(key) || this.overwrite)) {\n this.setSync(key, value);\n }\n }\n\n /**\n * Synchronously creates a directory at the specified path.\n *\n * @param _ - The path of the directory to create.\n */\n public mkdirSync(_: string) {}\n\n /**\n * Creates a directory at the specified path.\n *\n * @param dirPath - The path of the directory to create.\n */\n public async mkdir(dirPath: string): Promise<void> {\n return Promise.resolve(this.mkdirSync(dirPath));\n }\n\n /**\n * Synchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public abstract removeSync(key: string): void;\n\n /**\n * Asynchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public async remove(key: string): Promise<void> {\n if (!this.isReadOnly && this.overwrite) {\n this.removeSync(key);\n }\n }\n\n /**\n * Synchronously removes all entries from the storage that match the provided base path.\n *\n * @param base - The base path to clear keys from.\n */\n public clearSync(base?: string) {\n if (!this.isReadOnly && this.overwrite) {\n const keys = this.listSync(base || this.options.base);\n if (!keys.length) {\n return;\n }\n\n keys.map(key =>\n this.removeSync(\n base && !key.startsWith(base) ? joinPaths(base, key) : key\n )\n );\n }\n }\n\n /**\n * Asynchronously removes all entries from the storage that match the provided base path.\n *\n * @param base - The base path to clear keys from.\n * @returns A promise that resolves when the operation is complete.\n */\n public async clear(base?: string): Promise<void> {\n if (!this.isReadOnly && this.overwrite) {\n const keys = await this.list(base || this.options.base);\n if (!keys.length) {\n return;\n }\n\n await Promise.all(\n keys.map(async key =>\n this.remove(\n base && !key.startsWith(base) ? joinPaths(base, key) : key\n )\n )\n );\n }\n }\n\n /**\n * Lists all keys under a given base path synchronously.\n *\n * @param base - The base path to list keys from.\n * @returns An array of keys under the specified base path.\n */\n public abstract listSync(base?: string): string[];\n\n /**\n * Asynchronously lists all keys under a given base path.\n *\n * @param base - The base path to list keys from.\n * @returns A promise that resolves to an array of keys under the specified base path.\n */\n public async list(base?: string): Promise<string[]> {\n return this.listSync(base);\n }\n\n /**\n * Synchronously checks if the given key is a directory.\n *\n * @param _ - The key to check.\n * @returns `true` if the key is a directory, otherwise `false`.\n */\n public isDirectorySync(_: string): boolean {\n return false;\n }\n\n /**\n * Checks if the given key is a directory.\n *\n * @param key - The key to check.\n * @returns A promise that resolves to `true` if the key is a directory, otherwise `false`.\n */\n public async isDirectory(key: string) {\n return Promise.resolve(this.isDirectorySync(key));\n }\n\n /**\n * Synchronously checks if the given key is a file.\n *\n * @param key - The key to check.\n * @returns `true` if the key is a file, otherwise `false`.\n */\n public isFileSync(key: string): boolean {\n return this.existsSync(key) && !this.isDirectorySync(key);\n }\n\n /**\n * Checks if the given key is a file.\n *\n * @param key - The key to check.\n * @returns A promise that resolves to `true` if the key is a file, otherwise `false`.\n */\n public async isFile(key: string) {\n return Promise.resolve(this.isFileSync(key));\n }\n\n /**\n * Disposes of the storage adapter, releasing any held resources.\n *\n * @returns A promise that resolves when the disposal is complete.\n */\n public dispose(): MaybePromise<void> {\n return Promise.resolve();\n }\n\n /**\n * Async dispose method to clean up resources.\n *\n * @returns A promise that resolves when disposal is complete.\n */\n public async [Symbol.asyncDispose]() {\n return this._dispose();\n }\n\n /**\n * Determines if the storage adapter is read-only based on the provided options.\n *\n * @returns `true` if the storage adapter is read-only, otherwise `false`.\n */\n protected get isReadOnly() {\n return !!this.options.isReadOnly;\n }\n\n /**\n * Determines if the storage adapter should overwrite existing keys based on the provided options and context configuration.\n *\n * @returns `true` if the storage adapter should overwrite existing keys, otherwise `false`.\n */\n protected get overwrite() {\n return !this.isReadOnly && this.context.config.output.overwrite !== false;\n }\n\n /**\n * Resolves a given key to its full path within the storage adapter.\n *\n * @param key - The key to resolve.\n * @returns The resolved full path for the key.\n */\n protected resolve(key?: string) {\n if (!key) {\n return this.options.base;\n }\n\n if (/\\.\\.:|\\.\\.$/.test(key)) {\n throw new Error(\n `[${this.name}]: Invalid key: ${JSON.stringify(key)} provided to storage adapter.`\n );\n }\n\n return appendPath(correctPath(key).replace(/:/g, \"/\"), this.options.base);\n }\n\n /**\n * Disposes of the storage adapter, releasing any held resources.\n *\n * @returns A promise that resolves when the disposal is complete.\n */\n protected async _dispose(): Promise<void> {\n if (!this.#isDisposed) {\n await Promise.resolve(this.dispose());\n this.#isDisposed = true;\n }\n }\n}\n"],"mappings":";;;;;;;;;AAmCA,IAAsB,qBAAtB,MAE4B;CA+Bd;;;;CA3BZ,cAAc;;;;CAUd,AAAO;;;;;;;CAQP,AAAgB,SAAgC;;;;;;;CAQhD,AAAO,YACL,AAAU,SACV,UAAoB,EAAE,MAAM,IAAI,GAChC;EAFU;EAGV,KAAK,UAAU;EACf,KAAK,QAAQ,OAAO,QAAQ,QAAQ,IAAI;EACxC,KAAK,QAAQ,aAAa,CAAC,CAAC,QAAQ;CACtC;;;;;;;CAgBA,MAAa,OAAO,KAA+B;EACjD,OAAO,KAAK,WAAW,GAAG;CAC5B;;;;;;;CAgBA,MAAa,IAAI,KAAqC;EACpD,OAAO,KAAK,QAAQ,GAAG;CACzB;;;;;;;CAgBA,MAAa,IAAI,KAAa,OAA8B;EAC1D,IAAI,CAAC,KAAK,eAAe,CAAC,KAAK,WAAW,GAAG,KAAK,K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AAK,WAAW,GAAG,CAAC;CAC7C;;;;;;CAOA,AAAO,UAA8B;EACnC,OAAO,QAAQ,QAAQ;CACzB;;;;;;CAOA,OAAc,OAAO,gBAAgB;EACnC,OAAO,KAAK,SAAS;CACvB;;;;;;CAOA,IAAc,aAAa;EACzB,OAAO,CAAC,CAAC,KAAK,QAAQ;CACxB;;;;;;CAOA,IAAc,YAAY;EACxB,OAAO,CAAC,KAAK,cAAc,KAAK,QAAQ,OAAO,OAAO,cAAc;CACtE;;;;;;;CAQA,AAAU,QAAQ,KAAc;EAC9B,IAAI,CAAC,KACH,OAAO,KAAK,QAAQ;EAGtB,IAAI,cAAc,KAAK,GAAG,GACxB,MAAM,IAAI,MACR,IAAI,KAAK,KAAK,kBAAkB,KAAK,UAAU,GAAG,EAAE,8BACtD;EAGF,OAAO,WAAW,YAAY,GAAG,CAAC,CAAC,QAAQ,MAAM,GAAG,GAAG,KAAK,QAAQ,IAAI;CAC1E;;;;;;CAOA,MAAgB,WAA0B;EACxC,IAAI,CAAC,KAAKA,aAAa;GACrB,MAAM,QAAQ,QAAQ,KAAK,QAAQ,CAAC;GACpC,KAAKA,cAAc;EACrB;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"file-system.mjs","names":[],"sources":["../../src/storage/file-system.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 { exists, existsSync } from \"@stryke/fs/exists\";\nimport { createDirectory, createDirectorySync } from \"@stryke/fs/helpers\";\nimport { isDirectory, isFile } from \"@stryke/fs/is-file\";\nimport { listFiles, listFilesSync } from \"@stryke/fs/list-files\";\nimport { readFile, readFileSync } from \"@stryke/fs/read-file\";\nimport { writeFile, writeFileSync } from \"@stryke/fs/write-file\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { unlinkSync } from \"node:fs\";\nimport { unlink } from \"node:fs/promises\";\nimport { getFileHeaderWarningText } from \"../lib/utilities/file-header\";\nimport type { Context } from \"../types/context\";\nimport { BaseStorageAdapter, StorageAdapterOptions } from \"./base\";\nimport { ignoreNotfound } from \"./helpers\";\n\nexport type SetSyncOptions = Parameters<typeof writeFileSync>[2];\nexport type SetOptions = Parameters<typeof writeFile>[2];\n\n/**\n * File system storage adapter implementation.\n */\nexport class FileSystemStorageAdapter extends BaseStorageAdapter {\n /**\n * A name identifying the storage adapter type.\n */\n public name = \"file-system\";\n\n /**\n * The storage preset for the adapter.\n *\n * @remarks\n * This can be used as an alternate way to identify the type of storage being used.\n */\n public override readonly preset = \"fs\";\n\n /**\n * Constructor for the FileSystemStorageAdapter.\n *\n * @param context - The Powerlines context.\n * @param options - Configuration options for the storage adapter.\n */\n public constructor(context: Context, options?: StorageAdapterOptions) {\n super(context, options);\n }\n\n /**\n * Synchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns Returns `true` if the key exists, otherwise `false`.\n */\n public existsSync(key: string): boolean {\n return existsSync(this.resolve(key));\n }\n\n /**\n * Asynchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns A promise that resolves to `true` if the key exists, otherwise `false`.\n */\n public override async exists(key: string): Promise<boolean> {\n return exists(this.resolve(key));\n }\n\n /**\n * Synchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns The value associated with the key, or `null` if the key does not exist.\n */\n public getSync(key: string): string | null {\n return readFileSync(this.resolve(key));\n }\n\n /**\n * Asynchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns A promise that resolves to the value associated with the key, or `null` if the key does not exist.\n */\n public override async get(key: string): Promise<string | null> {\n return readFile(this.resolve(key));\n }\n\n /**\n * Synchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public setSync(key: string, value: string) {\n if (!this.isReadOnly) {\n if (this.existsSync(this.resolve(key)) && !this.overwrite) {\n const existingValue = this.getSync(this.resolve(key));\n if (\n isSetString(existingValue) &&\n existingValue.includes(\n getFileHeaderWarningText(\n true,\n this.context.config.framework?.name || \"powerlines\"\n )\n )\n ) {\n return writeFileSync(\n this.resolve(key),\n existingValue.replace(\n getFileHeaderWarningText(\n true,\n this.context.config.framework?.name || \"powerlines\"\n ),\n getFileHeaderWarningText(\n false,\n this.context.config.framework?.name || \"powerlines\"\n )\n )\n );\n }\n } else {\n return writeFileSync(this.resolve(key), value);\n }\n }\n }\n\n /**\n * Asynchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public override async set(key: string, value: string): Promise<void> {\n if (!this.isReadOnly) {\n if (this.existsSync(this.resolve(key)) && !this.overwrite) {\n const existingValue = await this.get(this.resolve(key));\n if (\n isSetString(existingValue) &&\n existingValue.includes(\n getFileHeaderWarningText(\n true,\n this.context.config.framework?.name || \"powerlines\"\n )\n )\n ) {\n return writeFile(\n this.resolve(key),\n existingValue.replace(\n getFileHeaderWarningText(\n true,\n this.context.config.framework?.name || \"powerlines\"\n ),\n getFileHeaderWarningText(\n false,\n this.context.config.framework?.name || \"powerlines\"\n )\n )\n );\n }\n } else {\n return writeFile(this.resolve(key), value);\n }\n }\n }\n\n /**\n * Synchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public removeSync(key: string) {\n if (!this.isReadOnly && this.overwrite) {\n try {\n return unlinkSync(this.resolve(key));\n } catch (err) {\n return ignoreNotfound(err);\n }\n }\n }\n\n /**\n * Asynchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public override async remove(key: string): Promise<void> {\n if (!this.isReadOnly && this.overwrite) {\n return unlink(this.resolve(key)).catch(ignoreNotfound);\n }\n }\n\n /**\n * Synchronously creates a directory at the specified path.\n *\n * @param dirPath - The path of the directory to create.\n */\n public override mkdirSync(dirPath: string) {\n createDirectorySync(this.resolve(dirPath));\n }\n\n /**\n * Creates a directory at the specified path.\n *\n * @param dirPath - The path of the directory to create.\n */\n public override async mkdir(dirPath: string): Promise<void> {\n await createDirectory(this.resolve(dirPath));\n }\n\n /**\n * Lists all keys under a given base path synchronously.\n *\n * @param base - The base path to list keys from.\n * @returns An array of keys under the specified base path.\n */\n public listSync(base?: string): string[] {\n try {\n return listFilesSync(this.resolve(base), {\n ignore: this.options.ignore\n });\n } catch (err) {\n return ignoreNotfound(err) ?? [];\n }\n }\n\n /**\n * Asynchronously lists all keys under a given base path.\n *\n * @param base - The base path to list keys from.\n * @returns A promise that resolves to an array of keys under the specified base path.\n */\n public override async list(base?: string): Promise<string[]> {\n return listFiles(this.resolve(base), {\n ignore: this.options.ignore\n })\n .catch(ignoreNotfound)\n .then(r => r || []);\n }\n\n /**\n * Synchronously checks if the given key is a directory.\n *\n * @param key - The key to check.\n * @returns `true` if the key is a directory, otherwise `false`.\n */\n public override isDirectorySync(key: string): boolean {\n return isDirectory(this.resolve(key));\n }\n\n /**\n * Synchronously checks if the given key is a file.\n *\n * @param key - The key to check.\n * @returns `true` if the key is a file, otherwise `false`.\n */\n public override isFileSync(key: string): boolean {\n return isFile(this.resolve(key));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAsCA,IAAa,2BAAb,cAA8C,mBAAmB;;;;CAI/D,AAAO,OAAO;;;;;;;CAQd,AAAyB,SAAS;;;;;;;CAQlC,AAAO,YAAY,SAAkB,SAAiC;EACpE,MAAM,SAAS,OAAO;CACxB;;;;;;;CAQA,AAAO,WAAW,KAAsB;EACtC,OAAO,WAAW,KAAK,QAAQ,GAAG,CAAC;CACrC;;;;;;;CAQA,MAAsB,OAAO,KAA+B;EAC1D,OAAO,OAAO,KAAK,QAAQ,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;;CAOA,AAAO,WAAW,KAAa;EAC7B,IAAI,CAAC,KAAK,cAAc,KAAK,WAC3B,IAAI;GACF,OAAO,WAAW,KAAK,QAAQ,GAAG,CAAC;EACrC,SAAS,KAAK;GACZ,OAAO,eAAe,GAAG;EAC3B;CAEJ;;;;;;CAOA,MAAsB,OAAO,KAA4B;EACvD,IAAI,CAAC,KAAK,cAAc,KAAK,WAC3B,OAAO,OAAO,KAAK,QAAQ,GAAG,CAAC,EAAE,MAAM,cAAc;CAEzD;;;;;;CAOA,AAAgB,UAAU,SAAiB;EACzC,oBAAoB,KAAK,QAAQ,OAAO,CAAC;CAC3C;;;;;;CAOA,MAAsB,MAAM,SAAgC;EAC1D,MAAM,gBAAgB,KAAK,QAAQ,OAAO,CAAC;CAC7C;;;;;;;CAQA,AAAO,SAAS,MAAyB;EACvC,IAAI;GACF,OAAO,cAAc,KAAK,QAAQ,IAAI,GAAG,EACvC,QAAQ,KAAK,QAAQ,OACvB,CAAC;EACH,SAAS,KAAK;GACZ,OAAO,eAAe,GAAG,KAAK,CAAC;EACjC;CACF;;;;;;;CAQA,MAAsB,KAAK,MAAkC;EAC3D,OAAO,UAAU,KAAK,QAAQ,IAAI,GAAG,EACnC,QAAQ,KAAK,QAAQ,OACvB,CAAC,EACE,MAAM,cAAc,EACpB,MAAK,MAAK,KAAK,CAAC,CAAC;CACtB;;;;;;;CAQA,AAAgB,gBAAgB,KAAsB;EACpD,OAAO,YAAY,KAAK,QAAQ,GAAG,CAAC;CACtC;;;;;;;CAQA,AAAgB,WAAW,KAAsB;EAC/C,OAAO,OAAO,KAAK,QAAQ,GAAG,CAAC;CACjC;AACF"}
1
+ {"version":3,"file":"file-system.mjs","names":[],"sources":["../../src/storage/file-system.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 { exists, existsSync } from \"@stryke/fs/exists\";\nimport { createDirectory, createDirectorySync } from \"@stryke/fs/helpers\";\nimport { isDirectory, isFile } from \"@stryke/fs/is-file\";\nimport { listFiles, listFilesSync } from \"@stryke/fs/list-files\";\nimport { readFile, readFileSync } from \"@stryke/fs/read-file\";\nimport { writeFile, writeFileSync } from \"@stryke/fs/write-file\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { unlinkSync } from \"node:fs\";\nimport { unlink } from \"node:fs/promises\";\nimport { getFileHeaderWarningText } from \"../lib/utilities/file-header\";\nimport type { Context } from \"../types/context\";\nimport { BaseStorageAdapter, StorageAdapterOptions } from \"./base\";\nimport { ignoreNotfound } from \"./helpers\";\n\nexport type SetSyncOptions = Parameters<typeof writeFileSync>[2];\nexport type SetOptions = Parameters<typeof writeFile>[2];\n\n/**\n * File system storage adapter implementation.\n */\nexport class FileSystemStorageAdapter extends BaseStorageAdapter {\n /**\n * A name identifying the storage adapter type.\n */\n public name = \"file-system\";\n\n /**\n * The storage preset for the adapter.\n *\n * @remarks\n * This can be used as an alternate way to identify the type of storage being used.\n */\n public override readonly preset = \"fs\";\n\n /**\n * Constructor for the FileSystemStorageAdapter.\n *\n * @param context - The Powerlines context.\n * @param options - Configuration options for the storage adapter.\n */\n public constructor(context: Context, options?: StorageAdapterOptions) {\n super(context, options);\n }\n\n /**\n * Synchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns Returns `true` if the key exists, otherwise `false`.\n */\n public existsSync(key: string): boolean {\n return existsSync(this.resolve(key));\n }\n\n /**\n * Asynchronously checks if a key exists in the storage.\n *\n * @param key - The key to check for existence.\n * @returns A promise that resolves to `true` if the key exists, otherwise `false`.\n */\n public override async exists(key: string): Promise<boolean> {\n return exists(this.resolve(key));\n }\n\n /**\n * Synchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns The value associated with the key, or `null` if the key does not exist.\n */\n public getSync(key: string): string | null {\n return readFileSync(this.resolve(key));\n }\n\n /**\n * Asynchronously retrieves the value associated with a given key.\n *\n * @param key - The key whose value is to be retrieved.\n * @returns A promise that resolves to the value associated with the key, or `null` if the key does not exist.\n */\n public override async get(key: string): Promise<string | null> {\n return readFile(this.resolve(key));\n }\n\n /**\n * Synchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public setSync(key: string, value: string) {\n if (!this.isReadOnly) {\n if (this.existsSync(this.resolve(key)) && !this.overwrite) {\n const existingValue = this.getSync(this.resolve(key));\n if (\n isSetString(existingValue) &&\n existingValue.includes(\n getFileHeaderWarningText(\n true,\n this.context.config.framework?.name || \"powerlines\"\n )\n )\n ) {\n return writeFileSync(\n this.resolve(key),\n existingValue.replace(\n getFileHeaderWarningText(\n true,\n this.context.config.framework?.name || \"powerlines\"\n ),\n getFileHeaderWarningText(\n false,\n this.context.config.framework?.name || \"powerlines\"\n )\n )\n );\n }\n } else {\n return writeFileSync(this.resolve(key), value);\n }\n }\n }\n\n /**\n * Asynchronously sets the value for a given key.\n *\n * @param key - The key to set the value for.\n * @param value - The value to set.\n */\n public override async set(key: string, value: string): Promise<void> {\n if (!this.isReadOnly) {\n if (this.existsSync(this.resolve(key)) && !this.overwrite) {\n const existingValue = await this.get(this.resolve(key));\n if (\n isSetString(existingValue) &&\n existingValue.includes(\n getFileHeaderWarningText(\n true,\n this.context.config.framework?.name || \"powerlines\"\n )\n )\n ) {\n return writeFile(\n this.resolve(key),\n existingValue.replace(\n getFileHeaderWarningText(\n true,\n this.context.config.framework?.name || \"powerlines\"\n ),\n getFileHeaderWarningText(\n false,\n this.context.config.framework?.name || \"powerlines\"\n )\n )\n );\n }\n } else {\n return writeFile(this.resolve(key), value);\n }\n }\n }\n\n /**\n * Synchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public removeSync(key: string) {\n if (!this.isReadOnly && this.overwrite) {\n try {\n return unlinkSync(this.resolve(key));\n } catch (err) {\n return ignoreNotfound(err);\n }\n }\n }\n\n /**\n * Asynchronously removes a key from the storage.\n *\n * @param key - The key to remove.\n */\n public override async remove(key: string): Promise<void> {\n if (!this.isReadOnly && this.overwrite) {\n return unlink(this.resolve(key)).catch(ignoreNotfound);\n }\n }\n\n /**\n * Synchronously creates a directory at the specified path.\n *\n * @param dirPath - The path of the directory to create.\n */\n public override mkdirSync(dirPath: string) {\n createDirectorySync(this.resolve(dirPath));\n }\n\n /**\n * Creates a directory at the specified path.\n *\n * @param dirPath - The path of the directory to create.\n */\n public override async mkdir(dirPath: string): Promise<void> {\n await createDirectory(this.resolve(dirPath));\n }\n\n /**\n * Lists all keys under a given base path synchronously.\n *\n * @param base - The base path to list keys from.\n * @returns An array of keys under the specified base path.\n */\n public listSync(base?: string): string[] {\n try {\n return listFilesSync(this.resolve(base), {\n ignore: this.options.ignore\n });\n } catch (err) {\n return ignoreNotfound(err) ?? [];\n }\n }\n\n /**\n * Asynchronously lists all keys under a given base path.\n *\n * @param base - The base path to list keys from.\n * @returns A promise that resolves to an array of keys under the specified base path.\n */\n public override async list(base?: string): Promise<string[]> {\n return listFiles(this.resolve(base), {\n ignore: this.options.ignore\n })\n .catch(ignoreNotfound)\n .then(r => r || []);\n }\n\n /**\n * Synchronously checks if the given key is a directory.\n *\n * @param key - The key to check.\n * @returns `true` if the key is a directory, otherwise `false`.\n */\n public override isDirectorySync(key: string): boolean {\n return isDirectory(this.resolve(key));\n }\n\n /**\n * Synchronously checks if the given key is a file.\n *\n * @param key - The key to check.\n * @returns `true` if the key is a file, otherwise `false`.\n */\n public override isFileSync(key: string): boolean {\n return isFile(this.resolve(key));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAsCA,IAAa,2BAAb,cAA8C,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