@powerlines/core 0.13.16 → 0.13.17

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.
@@ -1 +1 @@
1
- {"version":3,"file":"write-file.mjs","names":["writeFileBase"],"sources":["../../../src/lib/utilities/write-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { writeFile as writeFileBase } from \"@stryke/fs/write-file\";\nimport { format, resolveConfig } from \"prettier\";\nimport type { LogFn } from \"../../types/config\";\n\n/**\n * Writes and formats a file to the file system\n *\n * @param log - The logging function to use for logging errors\n * @param filepath - The file path to write the file\n * @param content - The content to write to the file\n * @param skipFormat - Should the plugin skip formatting the `content` string with Prettier\n */\nexport async function writeFile(\n log: LogFn,\n filepath: string,\n content: string,\n skipFormat = false\n) {\n try {\n if (skipFormat) {\n await writeFileBase(filepath, content);\n } else {\n const config = await resolveConfig(filepath);\n const formatted = await format(content, {\n ...(config ?? {}),\n filepath\n });\n\n await writeFileBase(filepath, formatted || \"\");\n }\n } catch (error) {\n log(\n LogLevelLabel.ERROR,\n `Failed to write file ${filepath} to disk \\n${(error as Error)?.message ? (error as Error).message : \"\"}`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA+BA,eAAsB,UACpB,KACA,UACA,SACA,aAAa,OACb;AACA,KAAI;AACF,MAAI,WACF,OAAMA,YAAc,UAAU,QAAQ;MAQtC,OAAMA,YAAc,UALF,MAAM,OAAO,SAAS;GACtC,GAFa,MAAM,cAAc,SAAS,IAE5B,EAAE;GAChB;GACD,CAAC,IAEyC,GAAG;UAEzC,OAAO;AACd,MACE,cAAc,OACd,wBAAwB,SAAS,aAAc,OAAiB,UAAW,MAAgB,UAAU,KACtG"}
1
+ {"version":3,"file":"write-file.mjs","names":["writeFileBase"],"sources":["../../../src/lib/utilities/write-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { writeFile as writeFileBase } from \"@stryke/fs/write-file\";\nimport { format, resolveConfig } from \"prettier\";\nimport type { LogFn } from \"../../types/config\";\n\n/**\n * Writes and formats a file to the file system\n *\n * @param log - The logging function to use for logging errors\n * @param filepath - The file path to write the file\n * @param content - The content to write to the file\n * @param skipFormat - Should the plugin skip formatting the `content` string with Prettier\n */\nexport async function writeFile(\n log: LogFn,\n filepath: string,\n content: string,\n skipFormat = false\n) {\n try {\n if (skipFormat) {\n await writeFileBase(filepath, content);\n } else {\n const config = await resolveConfig(filepath);\n const formatted = await format(content, {\n ...(config ?? {}),\n filepath\n });\n\n await writeFileBase(filepath, formatted || \"\");\n }\n } catch (error) {\n log(\n LogLevelLabel.ERROR,\n `Failed to write file ${filepath} to disk \\n${(error as Error)?.message ? (error as Error).message : \"\"}`\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;AA+BA,eAAsB,UACpB,KACA,UACA,SACA,aAAa,OACb;AACA,KAAI;AACF,MAAI,WACF,OAAMA,YAAc,UAAU,QAAQ;MAQtC,OAAMA,YAAc,UAAU,MALN,OAAO,SAAS;GACtC,GAAI,MAFe,cAAc,SAAS,IAE5B,EAAE;GAChB;GACD,CAAC,IAEyC,GAAG;UAEzC,OAAO;AACd,MACE,cAAc,OACd,wBAAwB,SAAS,aAAc,OAAiB,UAAW,MAAgB,UAAU,KACtG"}
@@ -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;AACnD,KAAI,WAAW,OAAO,EAAE;AACtB,MAAI,WAAW,UAAU,CACvB,QAAO,OAAO,YAAiB;GAC7B,MAAM,eAAe,QAAQ,MAAM,QAAQ,QAAQ,OAAO,QAAQ,CAAC,CAAC;GACpE,MAAM,kBAAkB,QACtB,MAAM,QAAQ,QAAQ,UAAU,QAAQ,CAAC,CAC1C;AAED,UAAO,aACJ,KAAI,MAAK,gBAAgB,KAAI,MAAK,MAAM,GAAG,EAAE,CAAqB,CAAC,CACnE,MAAM;;AAIb,SAAO,OAAO,YAAiB;AAG7B,UAFe,QAAQ,MAAM,QAAQ,QAAQ,OAAO,QAAQ,CAAC,CAAC,CAEhD,KAAI,MAAK,MAAM,GAAG,UAAU,CAAqB;;YAExD,WAAW,UAAU,CAC9B,QAAO,OAAO,YAAiB;AAG7B,SAFe,QAAQ,MAAM,QAAQ,QAAQ,UAAU,QAAQ,CAAC,CAAC,CAG9D,KAAI,MAAK,QAAQ,OAAO,CAAC,KAAI,MAAK,MAAM,GAAG,EAAE,CAAqB,CAAC,CACnE,MAAM;;AAIb,QAAO,QAAQ,OAAO,CAAC,KAAI,MAAK,MAAM,GAAG,UAAU,CAAqB"}
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;AACnD,KAAI,WAAW,OAAO,EAAE;AACtB,MAAI,WAAW,UAAU,CACvB,QAAO,OAAO,YAAiB;GAC7B,MAAM,eAAe,QAAQ,MAAM,QAAQ,QAAQ,OAAO,QAAQ,CAAC,CAAC;GACpE,MAAM,kBAAkB,QACtB,MAAM,QAAQ,QAAQ,UAAU,QAAQ,CAAC,CAC1C;AAED,UAAO,aACJ,KAAI,MAAK,gBAAgB,KAAI,MAAK,MAAM,GAAG,EAAE,CAAqB,CAAC,CACnE,MAAM;;AAIb,SAAO,OAAO,YAAiB;AAG7B,UAFe,QAAQ,MAAM,QAAQ,QAAQ,OAAO,QAAQ,CAAC,CAEhD,CAAC,KAAI,MAAK,MAAM,GAAG,UAAU,CAAqB;;YAExD,WAAW,UAAU,CAC9B,QAAO,OAAO,YAAiB;AAG7B,SAFe,QAAQ,MAAM,QAAQ,QAAQ,UAAU,QAAQ,CAAC,CAEnD,CACV,KAAI,MAAK,QAAQ,OAAO,CAAC,KAAI,MAAK,MAAM,GAAG,EAAE,CAAqB,CAAC,CACnE,MAAM;;AAIb,QAAO,QAAQ,OAAO,CAAC,KAAI,MAAK,MAAM,GAAG,UAAU,CAAqB"}
@@ -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 { 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\";\n\nconst BACKSLASH_REGEX = /\\\\/g;\nfunction normalize(path: string): string {\n return 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 normalizeFilter(filter: StringFilter): NormalizedStringFilter {\n if (typeof filter === \"string\" || filter instanceof RegExp) {\n return {\n include: [filter]\n };\n }\n if (Array.isArray(filter)) {\n return {\n include: filter\n };\n }\n return {\n exclude: filter.exclude ? toArray(filter.exclude) : undefined,\n include: filter.include ? toArray(filter.include) : 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":";;;;;;AA6BA,MAAM,kBAAkB;AACxB,SAAS,UAAU,MAAsB;AACvC,QAAO,KAAK,QAAQ,iBAAiB,IAAI;;AAG3C,SAAS,iBAAiB,MAAc,KAAa;AACnD,KAAI,KAAK,WAAW,KAAK,IAAI,eAAe,KAAK,CAC/C,QAAO,UAAU,KAAK;AAKxB,QAAO,UAFU,QAAQ,KAAK,KAAK,CAET;;AAG5B,SAAgB,kBAAkB,SAAuC;AACvE,KAAI,mBAAmB,OACrB,SAAQ,OAAe;EACrB,MAAM,eAAe,UAAU,GAAG;EAClC,MAAM,SAAS,QAAQ,KAAK,aAAa;AACzC,UAAQ,YAAY;AACpB,SAAO;;CAKX,MAAM,UAAU,UADH,iBAAiB,SADlB,QAAQ,KAAK,CACkB,EACX,EAAE,KAAK,MAAM,CAAC;AAE9C,SAAQ,OAAe;AAGrB,SAAO,QAFc,UAAU,GAAG,CAEN;;;AAIhC,SAAgB,oBAAoB,SAAuC;AACzE,KAAI,mBAAmB,OACrB,SAAQ,SAAiB;EACvB,MAAM,SAAS,QAAQ,KAAK,KAAK;AACjC,UAAQ,YAAY;AACpB,SAAO;;AAGX,SAAQ,SAAiB,KAAK,SAAS,QAAQ;;AAGjD,SAAgB,aACd,SACA,SAC0B;AAC1B,KAAI,CAAC,WAAW,CAAC,QACf;AAGF,SAAO,UAAS;AACd,MAAI,SAAS,MAAK,WAAU,OAAO,MAAM,CAAC,CACxC,QAAO;AAET,MAAI,SAAS,MAAK,WAAU,OAAO,MAAM,CAAC,CACxC,QAAO;AAET,SAAO,EAAE,WAAW,QAAQ,SAAS;;;AAIzC,SAAgB,gBAAgB,QAA8C;AAC5E,KAAI,OAAO,WAAW,YAAY,kBAAkB,OAClD,QAAO,EACL,SAAS,CAAC,OAAO,EAClB;AAEH,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,EACL,SAAS,QACV;AAEH,QAAO;EACL,SAAS,OAAO,UAAU,QAAQ,OAAO,QAAQ,GAAG;EACpD,SAAS,OAAO,UAAU,QAAQ,OAAO,QAAQ,GAAG;EACrD;;AAGH,SAAgB,eACd,QAC0B;AAC1B,KAAI,CAAC,OAAQ;CACb,MAAM,EAAE,SAAS,YAAY,gBAAgB,OAAO;CACpD,MAAM,gBAAgB,SAAS,IAAI,kBAAkB;CACrD,MAAM,gBAAgB,SAAS,IAAI,kBAAkB;AAErD,QAAO,aAAa,eAAe,cAAc;;AAGnD,SAAgB,iBACd,QAC0B;AAC1B,KAAI,CAAC,OAAQ;CACb,MAAM,EAAE,SAAS,YAAY,gBAAgB,OAAO;CACpD,MAAM,gBAAgB,SAAS,IAAI,oBAAoB;CACvD,MAAM,gBAAgB,SAAS,IAAI,oBAAoB;AAEvD,QAAO,aAAa,eAAe,cAAc;;AAGnD,SAAgB,kBACd,QAC0B;CAC1B,MAAM,iBAAiB,eAAe,OAAO;AAE7C,QAAO,kBAAiB,OAAM,CAAC,CAAC,eAAe,GAAG,GAAG;;AAGvD,SAAgB,yBACd,UACA,YACiC;AACjC,KAAI,CAAC,YAAY,CAAC,WAAY;CAC9B,MAAM,mBAAmB,eAAe,SAAS;CACjD,MAAM,qBAAqB,iBAAiB,WAAW;AAEvD,SAAQ,IAAI,SAAS;EACnB,IAAI,WAAW;AACf,MAAI,iBACF,cAAa,iBAAiB,GAAG;AAEnC,MAAI,CAAC,SACH,QAAO;AAGT,MAAI,mBACF,cAAa,mBAAmB,KAAK;AAEvC,SAAO"}
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 { 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\";\n\nconst BACKSLASH_REGEX = /\\\\/g;\nfunction normalize(path: string): string {\n return 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 normalizeFilter(filter: StringFilter): NormalizedStringFilter {\n if (typeof filter === \"string\" || filter instanceof RegExp) {\n return {\n include: [filter]\n };\n }\n if (Array.isArray(filter)) {\n return {\n include: filter\n };\n }\n return {\n exclude: filter.exclude ? toArray(filter.exclude) : undefined,\n include: filter.include ? toArray(filter.include) : 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":";;;;;;AA6BA,MAAM,kBAAkB;AACxB,SAAS,UAAU,MAAsB;AACvC,QAAO,KAAK,QAAQ,iBAAiB,IAAI;;AAG3C,SAAS,iBAAiB,MAAc,KAAa;AACnD,KAAI,KAAK,WAAW,KAAK,IAAI,eAAe,KAAK,CAC/C,QAAO,UAAU,KAAK;AAKxB,QAAO,UAFU,QAAQ,KAAK,KAEL,CAAC;;AAG5B,SAAgB,kBAAkB,SAAuC;AACvE,KAAI,mBAAmB,OACrB,SAAQ,OAAe;EACrB,MAAM,eAAe,UAAU,GAAG;EAClC,MAAM,SAAS,QAAQ,KAAK,aAAa;AACzC,UAAQ,YAAY;AACpB,SAAO;;CAKX,MAAM,UAAU,UADH,iBAAiB,SADlB,QAAQ,KACsB,CACZ,EAAE,EAAE,KAAK,MAAM,CAAC;AAE9C,SAAQ,OAAe;AAGrB,SAAO,QAFc,UAAU,GAEJ,CAAC;;;AAIhC,SAAgB,oBAAoB,SAAuC;AACzE,KAAI,mBAAmB,OACrB,SAAQ,SAAiB;EACvB,MAAM,SAAS,QAAQ,KAAK,KAAK;AACjC,UAAQ,YAAY;AACpB,SAAO;;AAGX,SAAQ,SAAiB,KAAK,SAAS,QAAQ;;AAGjD,SAAgB,aACd,SACA,SAC0B;AAC1B,KAAI,CAAC,WAAW,CAAC,QACf;AAGF,SAAO,UAAS;AACd,MAAI,SAAS,MAAK,WAAU,OAAO,MAAM,CAAC,CACxC,QAAO;AAET,MAAI,SAAS,MAAK,WAAU,OAAO,MAAM,CAAC,CACxC,QAAO;AAET,SAAO,EAAE,WAAW,QAAQ,SAAS;;;AAIzC,SAAgB,gBAAgB,QAA8C;AAC5E,KAAI,OAAO,WAAW,YAAY,kBAAkB,OAClD,QAAO,EACL,SAAS,CAAC,OAAO,EAClB;AAEH,KAAI,MAAM,QAAQ,OAAO,CACvB,QAAO,EACL,SAAS,QACV;AAEH,QAAO;EACL,SAAS,OAAO,UAAU,QAAQ,OAAO,QAAQ,GAAG;EACpD,SAAS,OAAO,UAAU,QAAQ,OAAO,QAAQ,GAAG;EACrD;;AAGH,SAAgB,eACd,QAC0B;AAC1B,KAAI,CAAC,OAAQ;CACb,MAAM,EAAE,SAAS,YAAY,gBAAgB,OAAO;CACpD,MAAM,gBAAgB,SAAS,IAAI,kBAAkB;CACrD,MAAM,gBAAgB,SAAS,IAAI,kBAAkB;AAErD,QAAO,aAAa,eAAe,cAAc;;AAGnD,SAAgB,iBACd,QAC0B;AAC1B,KAAI,CAAC,OAAQ;CACb,MAAM,EAAE,SAAS,YAAY,gBAAgB,OAAO;CACpD,MAAM,gBAAgB,SAAS,IAAI,oBAAoB;CACvD,MAAM,gBAAgB,SAAS,IAAI,oBAAoB;AAEvD,QAAO,aAAa,eAAe,cAAc;;AAGnD,SAAgB,kBACd,QAC0B;CAC1B,MAAM,iBAAiB,eAAe,OAAO;AAE7C,QAAO,kBAAiB,OAAM,CAAC,CAAC,eAAe,GAAG,GAAG;;AAGvD,SAAgB,yBACd,UACA,YACiC;AACjC,KAAI,CAAC,YAAY,CAAC,WAAY;CAC9B,MAAM,mBAAmB,eAAe,SAAS;CACjD,MAAM,qBAAqB,iBAAiB,WAAW;AAEvD,SAAQ,IAAI,SAAS;EACnB,IAAI,WAAW;AACf,MAAI,iBACF,cAAa,iBAAiB,GAAG;AAEnC,MAAI,CAAC,SACH,QAAO;AAGT,MAAI,mBACF,cAAa,mBAAmB,KAAK;AAEvC,SAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/core",
3
- "version": "0.13.16",
3
+ "version": "0.13.17",
4
4
  "private": false,
5
5
  "description": "An internal core package for Powerlines - please use the `powerlines` package for public usage.",
6
6
  "homepage": "https://stormsoftware.com",
@@ -523,9 +523,9 @@
523
523
  "@types/node": "^25.6.0",
524
524
  "@types/semver": "^7.7.1",
525
525
  "prettier-plugin-organize-imports": "^4.3.0",
526
- "tsdown": "^0.21.9",
526
+ "tsdown": "^0.21.10",
527
527
  "typescript": "^6.0.3"
528
528
  },
529
529
  "publishConfig": { "access": "public" },
530
- "gitHead": "b8e574852b96620685f9805724ba8fc1b3acbd17"
530
+ "gitHead": "d1efec5f9dce59e05c091b222a91b6b8ba5885d7"
531
531
  }