@stryke/fs 0.33.83 → 0.33.84

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 (204) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/_virtual/_rolldown/runtime.cjs +0 -14
  3. package/dist/buffer.cjs +0 -12
  4. package/dist/buffer.mjs +1 -8
  5. package/dist/buffer.mjs.map +1 -1
  6. package/dist/chmod-x.cjs +0 -14
  7. package/dist/chmod-x.mjs +1 -10
  8. package/dist/chmod-x.mjs.map +1 -1
  9. package/dist/command-exists.cjs +1 -11
  10. package/dist/command-exists.mjs +1 -6
  11. package/dist/command-exists.mjs.map +1 -1
  12. package/dist/compress.cjs +1 -8
  13. package/dist/compress.mjs +1 -3
  14. package/dist/compress.mjs.map +1 -1
  15. package/dist/constants.cjs +0 -13
  16. package/dist/constants.mjs +1 -8
  17. package/dist/copy-file.cjs +1 -13
  18. package/dist/copy-file.mjs +1 -8
  19. package/dist/copy-file.mjs.map +1 -1
  20. package/dist/exists.cjs +1 -11
  21. package/dist/exists.mjs +1 -6
  22. package/dist/exists.mjs.map +1 -1
  23. package/dist/get-parent-path.cjs +1 -8
  24. package/dist/get-parent-path.mjs +1 -3
  25. package/dist/get-parent-path.mjs.map +1 -1
  26. package/dist/get-workspace-root.cjs +0 -16
  27. package/dist/get-workspace-root.mjs +1 -12
  28. package/dist/get-workspace-root.mjs.map +1 -1
  29. package/dist/helpers.cjs +0 -14
  30. package/dist/helpers.mjs +1 -10
  31. package/dist/helpers.mjs.map +1 -1
  32. package/dist/index.cjs +0 -111
  33. package/dist/index.mjs +1 -107
  34. package/dist/install.cjs +0 -10
  35. package/dist/install.mjs +1 -6
  36. package/dist/install.mjs.map +1 -1
  37. package/dist/is-file.cjs +1 -13
  38. package/dist/is-file.mjs +1 -8
  39. package/dist/is-file.mjs.map +1 -1
  40. package/dist/json.cjs +0 -12
  41. package/dist/json.mjs +1 -8
  42. package/dist/json.mjs.map +1 -1
  43. package/dist/list-files.cjs +1 -15
  44. package/dist/list-files.mjs +1 -10
  45. package/dist/list-files.mjs.map +1 -1
  46. package/dist/package-fns.cjs +1 -16
  47. package/dist/package-fns.mjs +1 -11
  48. package/dist/package-fns.mjs.map +1 -1
  49. package/dist/read-file.cjs +1 -13
  50. package/dist/read-file.mjs +1 -8
  51. package/dist/read-file.mjs.map +1 -1
  52. package/dist/registry.cjs +0 -13
  53. package/dist/registry.mjs +1 -9
  54. package/dist/registry.mjs.map +1 -1
  55. package/dist/remove-file.cjs +1 -11
  56. package/dist/remove-file.mjs +1 -6
  57. package/dist/remove-file.mjs.map +1 -1
  58. package/dist/resolve.cjs +1 -20
  59. package/dist/resolve.mjs +1 -15
  60. package/dist/resolve.mjs.map +1 -1
  61. package/dist/semver-fns.cjs +1 -20
  62. package/dist/semver-fns.mjs +1 -15
  63. package/dist/semver-fns.mjs.map +1 -1
  64. package/dist/toml.cjs +0 -12
  65. package/dist/toml.mjs +1 -8
  66. package/dist/toml.mjs.map +1 -1
  67. package/dist/tsconfig.cjs +1 -8
  68. package/dist/tsconfig.mjs +1 -3
  69. package/dist/tsconfig.mjs.map +1 -1
  70. package/dist/write-file.cjs +1 -11
  71. package/dist/write-file.mjs +1 -6
  72. package/dist/write-file.mjs.map +1 -1
  73. package/dist/yaml.cjs +1 -11
  74. package/dist/yaml.mjs +1 -6
  75. package/dist/yaml.mjs.map +1 -1
  76. package/package.json +9 -109
  77. package/dist/_virtual/_rolldown/runtime.mjs +0 -18
  78. package/dist/buffer.test.cjs +0 -13
  79. package/dist/buffer.test.d.cts +0 -1
  80. package/dist/buffer.test.d.mts +0 -1
  81. package/dist/buffer.test.mjs +0 -14
  82. package/dist/buffer.test.mjs.map +0 -1
  83. package/dist/chmod-x.test.cjs +0 -13
  84. package/dist/chmod-x.test.d.cts +0 -1
  85. package/dist/chmod-x.test.d.mts +0 -1
  86. package/dist/chmod-x.test.mjs +0 -14
  87. package/dist/chmod-x.test.mjs.map +0 -1
  88. package/dist/command-exists.test.cjs +0 -13
  89. package/dist/command-exists.test.d.cts +0 -1
  90. package/dist/command-exists.test.d.mts +0 -1
  91. package/dist/command-exists.test.mjs +0 -14
  92. package/dist/command-exists.test.mjs.map +0 -1
  93. package/dist/compress.test.cjs +0 -13
  94. package/dist/compress.test.d.cts +0 -1
  95. package/dist/compress.test.d.mts +0 -1
  96. package/dist/compress.test.mjs +0 -14
  97. package/dist/compress.test.mjs.map +0 -1
  98. package/dist/constants.mjs.map +0 -1
  99. package/dist/constants.test.cjs +0 -13
  100. package/dist/constants.test.d.cts +0 -1
  101. package/dist/constants.test.d.mts +0 -1
  102. package/dist/constants.test.mjs +0 -14
  103. package/dist/constants.test.mjs.map +0 -1
  104. package/dist/copy-file.test.cjs +0 -13
  105. package/dist/copy-file.test.d.cts +0 -1
  106. package/dist/copy-file.test.d.mts +0 -1
  107. package/dist/copy-file.test.mjs +0 -14
  108. package/dist/copy-file.test.mjs.map +0 -1
  109. package/dist/exists.test.cjs +0 -13
  110. package/dist/exists.test.d.cts +0 -1
  111. package/dist/exists.test.d.mts +0 -1
  112. package/dist/exists.test.mjs +0 -14
  113. package/dist/exists.test.mjs.map +0 -1
  114. package/dist/get-parent-path.test.cjs +0 -13
  115. package/dist/get-parent-path.test.d.cts +0 -1
  116. package/dist/get-parent-path.test.d.mts +0 -1
  117. package/dist/get-parent-path.test.mjs +0 -14
  118. package/dist/get-parent-path.test.mjs.map +0 -1
  119. package/dist/get-workspace-root.test.cjs +0 -13
  120. package/dist/get-workspace-root.test.d.cts +0 -1
  121. package/dist/get-workspace-root.test.d.mts +0 -1
  122. package/dist/get-workspace-root.test.mjs +0 -14
  123. package/dist/get-workspace-root.test.mjs.map +0 -1
  124. package/dist/helpers.test.cjs +0 -13
  125. package/dist/helpers.test.d.cts +0 -1
  126. package/dist/helpers.test.d.mts +0 -1
  127. package/dist/helpers.test.mjs +0 -14
  128. package/dist/helpers.test.mjs.map +0 -1
  129. package/dist/index.mjs.map +0 -1
  130. package/dist/index.test.cjs +0 -13
  131. package/dist/index.test.d.cts +0 -1
  132. package/dist/index.test.d.mts +0 -1
  133. package/dist/index.test.mjs +0 -14
  134. package/dist/index.test.mjs.map +0 -1
  135. package/dist/install.test.cjs +0 -13
  136. package/dist/install.test.d.cts +0 -1
  137. package/dist/install.test.d.mts +0 -1
  138. package/dist/install.test.mjs +0 -14
  139. package/dist/install.test.mjs.map +0 -1
  140. package/dist/is-file.test.cjs +0 -13
  141. package/dist/is-file.test.d.cts +0 -1
  142. package/dist/is-file.test.d.mts +0 -1
  143. package/dist/is-file.test.mjs +0 -14
  144. package/dist/is-file.test.mjs.map +0 -1
  145. package/dist/json.test.cjs +0 -13
  146. package/dist/json.test.d.cts +0 -1
  147. package/dist/json.test.d.mts +0 -1
  148. package/dist/json.test.mjs +0 -14
  149. package/dist/json.test.mjs.map +0 -1
  150. package/dist/list-files.test.cjs +0 -13
  151. package/dist/list-files.test.d.cts +0 -1
  152. package/dist/list-files.test.d.mts +0 -1
  153. package/dist/list-files.test.mjs +0 -14
  154. package/dist/list-files.test.mjs.map +0 -1
  155. package/dist/package-fns.test.cjs +0 -13
  156. package/dist/package-fns.test.d.cts +0 -1
  157. package/dist/package-fns.test.d.mts +0 -1
  158. package/dist/package-fns.test.mjs +0 -14
  159. package/dist/package-fns.test.mjs.map +0 -1
  160. package/dist/read-file.test.cjs +0 -13
  161. package/dist/read-file.test.d.cts +0 -1
  162. package/dist/read-file.test.d.mts +0 -1
  163. package/dist/read-file.test.mjs +0 -14
  164. package/dist/read-file.test.mjs.map +0 -1
  165. package/dist/registry.test.cjs +0 -13
  166. package/dist/registry.test.d.cts +0 -1
  167. package/dist/registry.test.d.mts +0 -1
  168. package/dist/registry.test.mjs +0 -14
  169. package/dist/registry.test.mjs.map +0 -1
  170. package/dist/remove-file.test.cjs +0 -13
  171. package/dist/remove-file.test.d.cts +0 -1
  172. package/dist/remove-file.test.d.mts +0 -1
  173. package/dist/remove-file.test.mjs +0 -14
  174. package/dist/remove-file.test.mjs.map +0 -1
  175. package/dist/resolve.test.cjs +0 -13
  176. package/dist/resolve.test.d.cts +0 -1
  177. package/dist/resolve.test.d.mts +0 -1
  178. package/dist/resolve.test.mjs +0 -14
  179. package/dist/resolve.test.mjs.map +0 -1
  180. package/dist/semver-fns.test.cjs +0 -13
  181. package/dist/semver-fns.test.d.cts +0 -1
  182. package/dist/semver-fns.test.d.mts +0 -1
  183. package/dist/semver-fns.test.mjs +0 -14
  184. package/dist/semver-fns.test.mjs.map +0 -1
  185. package/dist/toml.test.cjs +0 -13
  186. package/dist/toml.test.d.cts +0 -1
  187. package/dist/toml.test.d.mts +0 -1
  188. package/dist/toml.test.mjs +0 -14
  189. package/dist/toml.test.mjs.map +0 -1
  190. package/dist/tsconfig.test.cjs +0 -13
  191. package/dist/tsconfig.test.d.cts +0 -1
  192. package/dist/tsconfig.test.d.mts +0 -1
  193. package/dist/tsconfig.test.mjs +0 -14
  194. package/dist/tsconfig.test.mjs.map +0 -1
  195. package/dist/write-file.test.cjs +0 -13
  196. package/dist/write-file.test.d.cts +0 -1
  197. package/dist/write-file.test.d.mts +0 -1
  198. package/dist/write-file.test.mjs +0 -14
  199. package/dist/write-file.test.mjs.map +0 -1
  200. package/dist/yaml.test.cjs +0 -13
  201. package/dist/yaml.test.d.cts +0 -1
  202. package/dist/yaml.test.d.mts +0 -1
  203. package/dist/yaml.test.mjs +0 -14
  204. package/dist/yaml.test.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"list-files.mjs","names":[],"sources":["../src/list-files.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { hasFileExtension, joinPaths } from \"@stryke/path\";\nimport { isString } from \"@stryke/type-checks\";\nimport type { AssetGlob } from \"@stryke/types/file\";\nimport defu from \"defu\";\nimport type { GlobOptions, GlobOptionsWithFileTypesTrue, Path } from \"glob\";\nimport { glob } from \"glob\";\n\nexport type ListOptions = GlobOptions;\nexport type InferListReturnType<TOptions extends GlobOptions> =\n TOptions[\"withFileTypes\"] extends true ? Path[] : string[];\n\nconst DEFAULT_OPTIONS: ListOptions = {\n dot: true\n};\n\n/**\n * Determines whether a string contains glob \"magic\" characters.\n *\n * @remarks\n * This includes wildcards (`*`, `?`), character classes (`[...]`),\n * extglob groups (`!(...)`, `+(...)`, etc.), and brace expansion\n * (`{option1,option2}`). When any of these are present the value should be\n * treated as an existing glob pattern instead of a plain path.\n *\n * @param value - The string to inspect\n * @returns `true` if the string contains glob magic characters\n */\nfunction isGlobPattern(value: string): boolean {\n return /[*?[\\]{}()!+@]/.test(value);\n}\n\n/**\n * A files and directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport async function list<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n): Promise<InferListReturnType<TOptions>> {\n return glob(\n isString(filesGlob)\n ? isGlobPattern(filesGlob) || hasFileExtension(filesGlob)\n ? filesGlob\n : joinPaths(filesGlob, \"**/*\")\n : filesGlob.input\n ? joinPaths(filesGlob.input, filesGlob.glob)\n : filesGlob.glob,\n defu(\n isString(filesGlob)\n ? {}\n : { dot: filesGlob.dot, ignore: filesGlob.ignore },\n options ?? {},\n DEFAULT_OPTIONS\n )\n ) as Promise<InferListReturnType<TOptions>>;\n}\n\n/**\n * A synchronous files and directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport function listSync<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n): InferListReturnType<TOptions> {\n return glob.sync(\n isString(filesGlob)\n ? isGlobPattern(filesGlob) || hasFileExtension(filesGlob)\n ? filesGlob\n : joinPaths(filesGlob, \"**/*\")\n : filesGlob.input\n ? joinPaths(filesGlob.input, filesGlob.glob)\n : filesGlob.glob,\n defu(\n isString(filesGlob)\n ? {}\n : { dot: filesGlob.dot, ignore: filesGlob.ignore },\n options ?? {},\n DEFAULT_OPTIONS\n )\n ) as InferListReturnType<TOptions>;\n}\n\n/**\n * A file listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport async function listFiles<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = (\n await list(\n filesGlob,\n defu(\n { withFileTypes: true },\n options ?? {}\n ) as GlobOptionsWithFileTypesTrue\n )\n ).filter(ret => ret.isFile());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n\n/**\n * A synchronous file listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport function listFilesSync<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = listSync(\n filesGlob,\n defu({ withFileTypes: true }, options ?? {}) as GlobOptionsWithFileTypesTrue\n ).filter(ret => ret.isFile());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n\n/**\n * A directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport async function listDirectories<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = (\n await list(\n filesGlob,\n defu(\n { withFileTypes: true },\n options ?? {}\n ) as GlobOptionsWithFileTypesTrue\n )\n ).filter(ret => ret.isDirectory());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n\n/**\n * A synchronous directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport function listDirectoriesSync<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = listSync(\n filesGlob,\n defu({ withFileTypes: true }, options ?? {}) as GlobOptionsWithFileTypesTrue\n ).filter(ret => ret.isDirectory());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n"],"mappings":";;;;;;;;;;;;;;;AA6BA,MAAM,kBAA+B,EACnC,KAAK,MACN;;;;;;;;;;;;;AAcD,SAAS,cAAc,OAAwB;AAC7C,QAAO,iBAAiB,KAAK,MAAM;;;;;;;;AASrC,eAAsB,KACpB,WACA,SACwC;AACxC,QAAO,KACL,SAAS,UAAU,GACf,cAAc,UAAU,IAAI,iBAAiB,UAAU,GACrD,YACA,UAAU,WAAW,OAAO,GAC9B,UAAU,QACR,UAAU,UAAU,OAAO,UAAU,KAAK,GAC1C,UAAU,MAChB,KACE,SAAS,UAAU,GACf,EAAE,GACF;EAAE,KAAK,UAAU;EAAK,QAAQ,UAAU;EAAQ,EACpD,WAAW,EAAE,EACb,gBACD,CACF;;;;;;;;AASH,SAAgB,SACd,WACA,SAC+B;AAC/B,QAAO,KAAK,KACV,SAAS,UAAU,GACf,cAAc,UAAU,IAAI,iBAAiB,UAAU,GACrD,YACA,UAAU,WAAW,OAAO,GAC9B,UAAU,QACR,UAAU,UAAU,OAAO,UAAU,KAAK,GAC1C,UAAU,MAChB,KACE,SAAS,UAAU,GACf,EAAE,GACF;EAAE,KAAK,UAAU;EAAK,QAAQ,UAAU;EAAQ,EACpD,WAAW,EAAE,EACb,gBACD,CACF;;;;;;;;AASH,eAAsB,UACpB,WACA,SACA;CACA,MAAM,UACJ,MAAM,KACJ,WACA,KACE,EAAE,eAAe,MAAM,EACvB,WAAW,EAAE,CACd,CACF,EACD,QAAO,QAAO,IAAI,QAAQ,CAAC;AAC7B,KAAI,CAAC,SAAS,cACZ,QAAO,OAAO,KAAI,SAAQ,KAAK,UAAU,CAAC;AAG5C,QAAO;;;;;;;;AAST,SAAgB,cACd,WACA,SACA;CACA,MAAM,SAAS,SACb,WACA,KAAK,EAAE,eAAe,MAAM,EAAE,WAAW,EAAE,CAAC,CAC7C,CAAC,QAAO,QAAO,IAAI,QAAQ,CAAC;AAC7B,KAAI,CAAC,SAAS,cACZ,QAAO,OAAO,KAAI,SAAQ,KAAK,UAAU,CAAC;AAG5C,QAAO;;;;;;;;AAST,eAAsB,gBACpB,WACA,SACA;CACA,MAAM,UACJ,MAAM,KACJ,WACA,KACE,EAAE,eAAe,MAAM,EACvB,WAAW,EAAE,CACd,CACF,EACD,QAAO,QAAO,IAAI,aAAa,CAAC;AAClC,KAAI,CAAC,SAAS,cACZ,QAAO,OAAO,KAAI,SAAQ,KAAK,UAAU,CAAC;AAG5C,QAAO;;;;;;;;AAST,SAAgB,oBACd,WACA,SACA;CACA,MAAM,SAAS,SACb,WACA,KAAK,EAAE,eAAe,MAAM,EAAE,WAAW,EAAE,CAAC,CAC7C,CAAC,QAAO,QAAO,IAAI,aAAa,CAAC;AAClC,KAAI,CAAC,SAAS,cACZ,QAAO,OAAO,KAAI,SAAQ,KAAK,UAAU,CAAC;AAG5C,QAAO"}
1
+ {"version":3,"file":"list-files.mjs","names":[],"sources":["../src/list-files.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { hasFileExtension, joinPaths } from \"@stryke/path\";\nimport { isString } from \"@stryke/type-checks\";\nimport type { AssetGlob } from \"@stryke/types/file\";\nimport defu from \"defu\";\nimport type { GlobOptions, GlobOptionsWithFileTypesTrue, Path } from \"glob\";\nimport { glob } from \"glob\";\n\nexport type ListOptions = GlobOptions;\nexport type InferListReturnType<TOptions extends GlobOptions> =\n TOptions[\"withFileTypes\"] extends true ? Path[] : string[];\n\nconst DEFAULT_OPTIONS: ListOptions = {\n dot: true\n};\n\n/**\n * Determines whether a string contains glob \"magic\" characters.\n *\n * @remarks\n * This includes wildcards (`*`, `?`), character classes (`[...]`),\n * extglob groups (`!(...)`, `+(...)`, etc.), and brace expansion\n * (`{option1,option2}`). When any of these are present the value should be\n * treated as an existing glob pattern instead of a plain path.\n *\n * @param value - The string to inspect\n * @returns `true` if the string contains glob magic characters\n */\nfunction isGlobPattern(value: string): boolean {\n return /[*?[\\]{}()!+@]/.test(value);\n}\n\n/**\n * A files and directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport async function list<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n): Promise<InferListReturnType<TOptions>> {\n return glob(\n isString(filesGlob)\n ? isGlobPattern(filesGlob) || hasFileExtension(filesGlob)\n ? filesGlob\n : joinPaths(filesGlob, \"**/*\")\n : filesGlob.input\n ? joinPaths(filesGlob.input, filesGlob.glob)\n : filesGlob.glob,\n defu(\n isString(filesGlob)\n ? {}\n : { dot: filesGlob.dot, ignore: filesGlob.ignore },\n options ?? {},\n DEFAULT_OPTIONS\n )\n ) as Promise<InferListReturnType<TOptions>>;\n}\n\n/**\n * A synchronous files and directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport function listSync<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n): InferListReturnType<TOptions> {\n return glob.sync(\n isString(filesGlob)\n ? isGlobPattern(filesGlob) || hasFileExtension(filesGlob)\n ? filesGlob\n : joinPaths(filesGlob, \"**/*\")\n : filesGlob.input\n ? joinPaths(filesGlob.input, filesGlob.glob)\n : filesGlob.glob,\n defu(\n isString(filesGlob)\n ? {}\n : { dot: filesGlob.dot, ignore: filesGlob.ignore },\n options ?? {},\n DEFAULT_OPTIONS\n )\n ) as InferListReturnType<TOptions>;\n}\n\n/**\n * A file listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport async function listFiles<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = (\n await list(\n filesGlob,\n defu(\n { withFileTypes: true },\n options ?? {}\n ) as GlobOptionsWithFileTypesTrue\n )\n ).filter(ret => ret.isFile());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n\n/**\n * A synchronous file listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport function listFilesSync<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = listSync(\n filesGlob,\n defu({ withFileTypes: true }, options ?? {}) as GlobOptionsWithFileTypesTrue\n ).filter(ret => ret.isFile());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n\n/**\n * A directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport async function listDirectories<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = (\n await list(\n filesGlob,\n defu(\n { withFileTypes: true },\n options ?? {}\n ) as GlobOptionsWithFileTypesTrue\n )\n ).filter(ret => ret.isDirectory());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n\n/**\n * A synchronous directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport function listDirectoriesSync<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = listSync(\n filesGlob,\n defu({ withFileTypes: true }, options ?? {}) as GlobOptionsWithFileTypesTrue\n ).filter(ret => ret.isDirectory());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n"],"mappings":";;;;;;AA6BA,MAAM,kBAA+B,EACnC,KAAK,MACN;;;;;;;;;;;;;AAcD,SAAS,cAAc,OAAwB;AAC7C,QAAO,iBAAiB,KAAK,MAAM;;;;;;;;AASrC,eAAsB,KACpB,WACA,SACwC;AACxC,QAAO,KACL,SAAS,UAAU,GACf,cAAc,UAAU,IAAI,iBAAiB,UAAU,GACrD,YACA,UAAU,WAAW,OAAO,GAC9B,UAAU,QACR,UAAU,UAAU,OAAO,UAAU,KAAK,GAC1C,UAAU,MAChB,KACE,SAAS,UAAU,GACf,EAAE,GACF;EAAE,KAAK,UAAU;EAAK,QAAQ,UAAU;EAAQ,EACpD,WAAW,EAAE,EACb,gBACD,CACF;;;;;;;;AASH,SAAgB,SACd,WACA,SAC+B;AAC/B,QAAO,KAAK,KACV,SAAS,UAAU,GACf,cAAc,UAAU,IAAI,iBAAiB,UAAU,GACrD,YACA,UAAU,WAAW,OAAO,GAC9B,UAAU,QACR,UAAU,UAAU,OAAO,UAAU,KAAK,GAC1C,UAAU,MAChB,KACE,SAAS,UAAU,GACf,EAAE,GACF;EAAE,KAAK,UAAU;EAAK,QAAQ,UAAU;EAAQ,EACpD,WAAW,EAAE,EACb,gBACD,CACF;;;;;;;;AASH,eAAsB,UACpB,WACA,SACA;CACA,MAAM,UACJ,MAAM,KACJ,WACA,KACE,EAAE,eAAe,MAAM,EACvB,WAAW,EAAE,CACd,CACF,EACD,QAAO,QAAO,IAAI,QAAQ,CAAC;AAC7B,KAAI,CAAC,SAAS,cACZ,QAAO,OAAO,KAAI,SAAQ,KAAK,UAAU,CAAC;AAG5C,QAAO;;;;;;;;AAST,SAAgB,cACd,WACA,SACA;CACA,MAAM,SAAS,SACb,WACA,KAAK,EAAE,eAAe,MAAM,EAAE,WAAW,EAAE,CAAC,CAC7C,CAAC,QAAO,QAAO,IAAI,QAAQ,CAAC;AAC7B,KAAI,CAAC,SAAS,cACZ,QAAO,OAAO,KAAI,SAAQ,KAAK,UAAU,CAAC;AAG5C,QAAO;;;;;;;;AAST,eAAsB,gBACpB,WACA,SACA;CACA,MAAM,UACJ,MAAM,KACJ,WACA,KACE,EAAE,eAAe,MAAM,EACvB,WAAW,EAAE,CACd,CACF,EACD,QAAO,QAAO,IAAI,aAAa,CAAC;AAClC,KAAI,CAAC,SAAS,cACZ,QAAO,OAAO,KAAI,SAAQ,KAAK,UAAU,CAAC;AAG5C,QAAO;;;;;;;;AAST,SAAgB,oBACd,WACA,SACA;CACA,MAAM,SAAS,SACb,WACA,KAAK,EAAE,eAAe,MAAM,EAAE,WAAW,EAAE,CAAC,CAC7C,CAAC,QAAO,QAAO,IAAI,aAAa,CAAC;AAClC,KAAI,CAAC,SAAS,cACZ,QAAO,OAAO,KAAI,SAAQ,KAAK,UAAU,CAAC;AAG5C,QAAO"}
@@ -13,15 +13,6 @@ let _stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
13
13
  let semver = require("semver");
14
14
 
15
15
  //#region src/package-fns.ts
16
- var package_fns_exports = /* @__PURE__ */ require_runtime.__exportAll({
17
- doesPackageMatch: () => doesPackageMatch,
18
- getPackageInfo: () => getPackageInfo,
19
- getPackageListing: () => getPackageListing,
20
- getPackageManager: () => getPackageManager,
21
- isPackageExists: () => isPackageExists,
22
- isPackageListed: () => isPackageListed,
23
- loadPackageJson: () => loadPackageJson
24
- });
25
16
  /**
26
17
  * Get the package manager used in the project
27
18
  *
@@ -155,10 +146,4 @@ exports.getPackageListing = getPackageListing;
155
146
  exports.getPackageManager = getPackageManager;
156
147
  exports.isPackageExists = isPackageExists;
157
148
  exports.isPackageListed = isPackageListed;
158
- exports.loadPackageJson = loadPackageJson;
159
- Object.defineProperty(exports, 'package_fns_exports', {
160
- enumerable: true,
161
- get: function () {
162
- return package_fns_exports;
163
- }
164
- });
149
+ exports.loadPackageJson = loadPackageJson;
@@ -1,4 +1,3 @@
1
- import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
2
1
  import { exists } from "./exists.mjs";
3
2
  import { getParentPath } from "./get-parent-path.mjs";
4
3
  import { getWorkspaceRoot } from "./get-workspace-root.mjs";
@@ -12,15 +11,6 @@ import { isString } from "@stryke/type-checks/is-string";
12
11
  import { subset } from "semver";
13
12
 
14
13
  //#region src/package-fns.ts
15
- var package_fns_exports = /* @__PURE__ */ __exportAll({
16
- doesPackageMatch: () => doesPackageMatch,
17
- getPackageInfo: () => getPackageInfo,
18
- getPackageListing: () => getPackageListing,
19
- getPackageManager: () => getPackageManager,
20
- isPackageExists: () => isPackageExists,
21
- isPackageListed: () => isPackageListed,
22
- loadPackageJson: () => loadPackageJson
23
- });
24
14
  /**
25
15
  * Get the package manager used in the project
26
16
  *
@@ -148,5 +138,5 @@ function isPackageExists(name, options = {}) {
148
138
  }
149
139
 
150
140
  //#endregion
151
- export { doesPackageMatch, getPackageInfo, getPackageListing, getPackageManager, isPackageExists, isPackageListed, loadPackageJson, package_fns_exports };
141
+ export { doesPackageMatch, getPackageInfo, getPackageListing, getPackageManager, isPackageExists, isPackageListed, loadPackageJson };
152
142
  //# sourceMappingURL=package-fns.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"package-fns.mjs","names":[],"sources":["../src/package-fns.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { findFileName, findFilePath } from \"@stryke/path/file-path-fns\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { getPackageName } from \"@stryke/string-format/package\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport type { PackageJson } from \"@stryke/types/package-json\";\nimport type { PackageManager } from \"@stryke/types/package-manager\";\nimport { existsSync } from \"node:fs\";\nimport type { Range } from \"semver\";\nimport { subset } from \"semver\";\nimport { exists } from \"./exists\";\nimport { getParentPath } from \"./get-parent-path\";\nimport { getWorkspaceRoot } from \"./get-workspace-root\";\nimport { readJsonFile } from \"./json\";\nimport type { ResolveOptions } from \"./resolve\";\nimport { resolvePackage } from \"./resolve\";\n\n/**\n * Get the package manager used in the project\n *\n * @param dir - The path to the project\n * @returns The package manager used in the project\n */\nexport function getPackageManager(dir = getWorkspaceRoot()): PackageManager {\n const lockFile = getParentPath(\n [\"package-lock.json\", \"yarn.lock\", \"pnpm-lock.yaml\", \"bun.lock\"],\n dir,\n {\n includeNameInResults: true\n }\n );\n\n if (!lockFile) {\n // default use pnpm\n return \"pnpm\";\n }\n\n switch (findFileName(lockFile)) {\n case \"yarn.lock\": {\n return \"yarn\";\n }\n case \"pnpm-lock.yaml\": {\n return \"pnpm\";\n }\n case \"bun.lock\": {\n return \"bun\";\n }\n default: {\n return \"npm\";\n }\n }\n}\n\n// Much of the below code comes from https://github.com/antfu-collective/local-pkg with some modifications\n\nasync function searchPackageJson(dir: string) {\n let packageJsonPath;\n\n while (true) {\n if (!dir) {\n return;\n }\n const newDir = findFilePath(dir);\n\n if (newDir === dir) {\n return;\n }\n\n dir = newDir;\n packageJsonPath = joinPaths(dir, \"package.json\");\n\n if (await exists(packageJsonPath)) {\n break;\n }\n }\n\n return packageJsonPath;\n}\n\nasync function getPackageJsonPath(name: string, options: ResolveOptions = {}) {\n const entry = await resolvePackage(name, options);\n if (!entry) {\n return;\n }\n\n return searchPackageJson(entry);\n}\n\n/**\n * Get package info\n *\n * @param name - The name of the package\n * @param options - The options to use when resolving the package\n * @returns The package info\n */\nexport async function getPackageInfo(\n name: string,\n options: ResolveOptions = {}\n) {\n const packageJsonPath = await getPackageJsonPath(name, options);\n if (!packageJsonPath) {\n return;\n }\n\n const packageJson = await readJsonFile<PackageJson>(packageJsonPath);\n\n return {\n name,\n version: packageJson.version,\n rootPath: findFilePath(packageJsonPath),\n packageJsonPath,\n packageJson\n };\n}\n\n/**\n * Get the package info from the package.json file\n *\n * @param cwd - The current working directory\n * @returns The package info\n */\nexport async function loadPackageJson(\n cwd = getWorkspaceRoot()\n): Promise<PackageJson | null> {\n const path = getParentPath(\"package.json\", cwd, {\n skipCwd: false,\n includeNameInResults: true\n });\n if (!path || !existsSync(path)) {\n return null;\n }\n\n return readJsonFile<PackageJson>(path);\n}\n\nexport interface PackageExistsOptions {\n /**\n * The current working directory\n */\n cwd?: string;\n}\n\nexport interface PackageMatchesOptions extends PackageExistsOptions {\n /**\n * The version range of the package to check\n */\n version?: string | Range;\n}\n\n/**\n * Check if a package is listed in the package.json file\n *\n * @param name - The name of the package\n * @param cwd - The current working directory\n * @returns An indicator specifying if the package is listed\n */\nexport async function isPackageListed(\n name: string,\n cwd?: string\n): Promise<boolean>;\n\n/**\n * Check if a package is listed in the package.json file\n *\n * @param name - The name of the package\n * @param options - The options to use when checking if the package is listed\n * @returns An indicator specifying if the package is listed\n */\nexport async function isPackageListed(\n name: string,\n options?: PackageExistsOptions\n): Promise<boolean>;\n\n/**\n * Check if a package is listed in the package.json file\n *\n * @param name - The name of the package\n * @param cwdOrOptions - The current working directory or options to use when checking if the package is listed\n * @returns An indicator specifying if the package is listed\n */\nexport async function isPackageListed(\n name: string,\n cwdOrOptions?: string | PackageExistsOptions\n): Promise<boolean> {\n const packageName = getPackageName(name);\n const cwd = isString(cwdOrOptions) ? cwdOrOptions : cwdOrOptions?.cwd;\n\n const packageJson = await loadPackageJson(cwd);\n if (!packageJson) {\n return false;\n }\n\n return Boolean(\n (packageJson.dependencies &&\n packageName in packageJson.dependencies &&\n packageJson.dependencies[packageName]) ||\n (packageJson.devDependencies &&\n packageName in packageJson.devDependencies &&\n packageJson.devDependencies[packageName])\n );\n}\n\nexport interface GetPackageListingReturn {\n version: string;\n type: \"dependencies\" | \"devDependencies\";\n}\n\n/**\n * Return the package version and dependency type listed in the package.json file\n *\n * @param name - The name of the package\n * @param cwdOrOptions - The current working directory or options to use when checking if the package is listed\n * @returns The version and type of the package if listed, otherwise undefined\n */\nexport async function getPackageListing(\n name: string,\n cwdOrOptions?: string | PackageExistsOptions\n): Promise<GetPackageListingReturn | undefined> {\n const packageName = getPackageName(name);\n const cwd = isString(cwdOrOptions) ? cwdOrOptions : cwdOrOptions?.cwd;\n\n const packageJson = await loadPackageJson(cwd);\n if (!packageJson) {\n return undefined;\n }\n\n const version =\n packageJson.dependencies && packageName in packageJson.dependencies\n ? packageJson.dependencies[packageName]\n : packageJson.devDependencies &&\n packageName in packageJson.devDependencies\n ? packageJson.devDependencies[packageName]\n : undefined;\n const type =\n (packageJson.dependencies && packageName in packageJson.dependencies\n ? \"dependencies\"\n : packageJson.devDependencies &&\n packageName in packageJson.devDependencies\n ? \"devDependencies\"\n : undefined) || undefined;\n\n return version && type\n ? {\n version,\n type\n }\n : undefined;\n}\n\n/**\n * Check if a package version matches a specific version range\n *\n * @param name - The name of the package\n * @param version - The version to check against\n * @param cwd - The current working directory\n * @returns An indicator specifying if the package version matches the range\n */\nexport async function doesPackageMatch(\n name: string,\n version: string,\n cwd?: string\n): Promise<boolean> {\n const pkg = await getPackageListing(name, { cwd });\n if (!pkg) {\n return false;\n }\n\n return (\n pkg.version.startsWith(\"catalog:\") ||\n pkg.version.startsWith(\"workspace:\") ||\n subset(pkg.version, version)\n );\n}\n\n/**\n * Check if a package exists\n *\n * @param name - The name of the package\n * @param options - The options to use when resolving the package\n * @returns An indicator specifying if the package exists\n */\nexport function isPackageExists(name: string, options: ResolveOptions = {}) {\n return Boolean(resolvePackage(name, options));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,kBAAkB,MAAM,kBAAkB,EAAkB;CAC1E,MAAM,WAAW,cACf;EAAC;EAAqB;EAAa;EAAkB;EAAW,EAChE,KACA,EACE,sBAAsB,MACvB,CACF;AAED,KAAI,CAAC,SAEH,QAAO;AAGT,SAAQ,aAAa,SAAS,EAA9B;EACE,KAAK,YACH,QAAO;EAET,KAAK,iBACH,QAAO;EAET,KAAK,WACH,QAAO;EAET,QACE,QAAO;;;AAOb,eAAe,kBAAkB,KAAa;CAC5C,IAAI;AAEJ,QAAO,MAAM;AACX,MAAI,CAAC,IACH;EAEF,MAAM,SAAS,aAAa,IAAI;AAEhC,MAAI,WAAW,IACb;AAGF,QAAM;AACN,oBAAkB,UAAU,KAAK,eAAe;AAEhD,MAAI,MAAM,OAAO,gBAAgB,CAC/B;;AAIJ,QAAO;;AAGT,eAAe,mBAAmB,MAAc,UAA0B,EAAE,EAAE;CAC5E,MAAM,QAAQ,MAAM,eAAe,MAAM,QAAQ;AACjD,KAAI,CAAC,MACH;AAGF,QAAO,kBAAkB,MAAM;;;;;;;;;AAUjC,eAAsB,eACpB,MACA,UAA0B,EAAE,EAC5B;CACA,MAAM,kBAAkB,MAAM,mBAAmB,MAAM,QAAQ;AAC/D,KAAI,CAAC,gBACH;CAGF,MAAM,cAAc,MAAM,aAA0B,gBAAgB;AAEpE,QAAO;EACL;EACA,SAAS,YAAY;EACrB,UAAU,aAAa,gBAAgB;EACvC;EACA;EACD;;;;;;;;AASH,eAAsB,gBACpB,MAAM,kBAAkB,EACK;CAC7B,MAAM,OAAO,cAAc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[],"sources":["../src/package-fns.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { findFileName, findFilePath } from \"@stryke/path/file-path-fns\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { getPackageName } from \"@stryke/string-format/package\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport type { PackageJson } from \"@stryke/types/package-json\";\nimport type { PackageManager } from \"@stryke/types/package-manager\";\nimport { existsSync } from \"node:fs\";\nimport type { Range } from \"semver\";\nimport { subset } from \"semver\";\nimport { exists } from \"./exists\";\nimport { getParentPath } from \"./get-parent-path\";\nimport { getWorkspaceRoot } from \"./get-workspace-root\";\nimport { readJsonFile } from \"./json\";\nimport type { ResolveOptions } from \"./resolve\";\nimport { resolvePackage } from \"./resolve\";\n\n/**\n * Get the package manager used in the project\n *\n * @param dir - The path to the project\n * @returns The package manager used in the project\n */\nexport function getPackageManager(dir = getWorkspaceRoot()): PackageManager {\n const lockFile = getParentPath(\n [\"package-lock.json\", \"yarn.lock\", \"pnpm-lock.yaml\", \"bun.lock\"],\n dir,\n {\n includeNameInResults: true\n }\n );\n\n if (!lockFile) {\n // default use pnpm\n return \"pnpm\";\n }\n\n switch (findFileName(lockFile)) {\n case \"yarn.lock\": {\n return \"yarn\";\n }\n case \"pnpm-lock.yaml\": {\n return \"pnpm\";\n }\n case \"bun.lock\": {\n return \"bun\";\n }\n default: {\n return \"npm\";\n }\n }\n}\n\n// Much of the below code comes from https://github.com/antfu-collective/local-pkg with some modifications\n\nasync function searchPackageJson(dir: string) {\n let packageJsonPath;\n\n while (true) {\n if (!dir) {\n return;\n }\n const newDir = findFilePath(dir);\n\n if (newDir === dir) {\n return;\n }\n\n dir = newDir;\n packageJsonPath = joinPaths(dir, \"package.json\");\n\n if (await exists(packageJsonPath)) {\n break;\n }\n }\n\n return packageJsonPath;\n}\n\nasync function getPackageJsonPath(name: string, options: ResolveOptions = {}) {\n const entry = await resolvePackage(name, options);\n if (!entry) {\n return;\n }\n\n return searchPackageJson(entry);\n}\n\n/**\n * Get package info\n *\n * @param name - The name of the package\n * @param options - The options to use when resolving the package\n * @returns The package info\n */\nexport async function getPackageInfo(\n name: string,\n options: ResolveOptions = {}\n) {\n const packageJsonPath = await getPackageJsonPath(name, options);\n if (!packageJsonPath) {\n return;\n }\n\n const packageJson = await readJsonFile<PackageJson>(packageJsonPath);\n\n return {\n name,\n version: packageJson.version,\n rootPath: findFilePath(packageJsonPath),\n packageJsonPath,\n packageJson\n };\n}\n\n/**\n * Get the package info from the package.json file\n *\n * @param cwd - The current working directory\n * @returns The package info\n */\nexport async function loadPackageJson(\n cwd = getWorkspaceRoot()\n): Promise<PackageJson | null> {\n const path = getParentPath(\"package.json\", cwd, {\n skipCwd: false,\n includeNameInResults: true\n });\n if (!path || !existsSync(path)) {\n return null;\n }\n\n return readJsonFile<PackageJson>(path);\n}\n\nexport interface PackageExistsOptions {\n /**\n * The current working directory\n */\n cwd?: string;\n}\n\nexport interface PackageMatchesOptions extends PackageExistsOptions {\n /**\n * The version range of the package to check\n */\n version?: string | Range;\n}\n\n/**\n * Check if a package is listed in the package.json file\n *\n * @param name - The name of the package\n * @param cwd - The current working directory\n * @returns An indicator specifying if the package is listed\n */\nexport async function isPackageListed(\n name: string,\n cwd?: string\n): Promise<boolean>;\n\n/**\n * Check if a package is listed in the package.json file\n *\n * @param name - The name of the package\n * @param options - The options to use when checking if the package is listed\n * @returns An indicator specifying if the package is listed\n */\nexport async function isPackageListed(\n name: string,\n options?: PackageExistsOptions\n): Promise<boolean>;\n\n/**\n * Check if a package is listed in the package.json file\n *\n * @param name - The name of the package\n * @param cwdOrOptions - The current working directory or options to use when checking if the package is listed\n * @returns An indicator specifying if the package is listed\n */\nexport async function isPackageListed(\n name: string,\n cwdOrOptions?: string | PackageExistsOptions\n): Promise<boolean> {\n const packageName = getPackageName(name);\n const cwd = isString(cwdOrOptions) ? cwdOrOptions : cwdOrOptions?.cwd;\n\n const packageJson = await loadPackageJson(cwd);\n if (!packageJson) {\n return false;\n }\n\n return Boolean(\n (packageJson.dependencies &&\n packageName in packageJson.dependencies &&\n packageJson.dependencies[packageName]) ||\n (packageJson.devDependencies &&\n packageName in packageJson.devDependencies &&\n packageJson.devDependencies[packageName])\n );\n}\n\nexport interface GetPackageListingReturn {\n version: string;\n type: \"dependencies\" | \"devDependencies\";\n}\n\n/**\n * Return the package version and dependency type listed in the package.json file\n *\n * @param name - The name of the package\n * @param cwdOrOptions - The current working directory or options to use when checking if the package is listed\n * @returns The version and type of the package if listed, otherwise undefined\n */\nexport async function getPackageListing(\n name: string,\n cwdOrOptions?: string | PackageExistsOptions\n): Promise<GetPackageListingReturn | undefined> {\n const packageName = getPackageName(name);\n const cwd = isString(cwdOrOptions) ? cwdOrOptions : cwdOrOptions?.cwd;\n\n const packageJson = await loadPackageJson(cwd);\n if (!packageJson) {\n return undefined;\n }\n\n const version =\n packageJson.dependencies && packageName in packageJson.dependencies\n ? packageJson.dependencies[packageName]\n : packageJson.devDependencies &&\n packageName in packageJson.devDependencies\n ? packageJson.devDependencies[packageName]\n : undefined;\n const type =\n (packageJson.dependencies && packageName in packageJson.dependencies\n ? \"dependencies\"\n : packageJson.devDependencies &&\n packageName in packageJson.devDependencies\n ? \"devDependencies\"\n : undefined) || undefined;\n\n return version && type\n ? {\n version,\n type\n }\n : undefined;\n}\n\n/**\n * Check if a package version matches a specific version range\n *\n * @param name - The name of the package\n * @param version - The version to check against\n * @param cwd - The current working directory\n * @returns An indicator specifying if the package version matches the range\n */\nexport async function doesPackageMatch(\n name: string,\n version: string,\n cwd?: string\n): Promise<boolean> {\n const pkg = await getPackageListing(name, { cwd });\n if (!pkg) {\n return false;\n }\n\n return (\n pkg.version.startsWith(\"catalog:\") ||\n pkg.version.startsWith(\"workspace:\") ||\n subset(pkg.version, version)\n );\n}\n\n/**\n * Check if a package exists\n *\n * @param name - The name of the package\n * @param options - The options to use when resolving the package\n * @returns An indicator specifying if the package exists\n */\nexport function isPackageExists(name: string, options: ResolveOptions = {}) {\n return Boolean(resolvePackage(name, options));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,kBAAkB,MAAM,kBAAkB,EAAkB;CAC1E,MAAM,WAAW,cACf;EAAC;EAAqB;EAAa;EAAkB;EAAW,EAChE,KACA,EACE,sBAAsB,MACvB,CACF;AAED,KAAI,CAAC,SAEH,QAAO;AAGT,SAAQ,aAAa,SAAS,EAA9B;EACE,KAAK,YACH,QAAO;EAET,KAAK,iBACH,QAAO;EAET,KAAK,WACH,QAAO;EAET,QACE,QAAO;;;AAOb,eAAe,kBAAkB,KAAa;CAC5C,IAAI;AAEJ,QAAO,MAAM;AACX,MAAI,CAAC,IACH;EAEF,MAAM,SAAS,aAAa,IAAI;AAEhC,MAAI,WAAW,IACb;AAGF,QAAM;AACN,oBAAkB,UAAU,KAAK,eAAe;AAEhD,MAAI,MAAM,OAAO,gBAAgB,CAC/B;;AAIJ,QAAO;;AAGT,eAAe,mBAAmB,MAAc,UAA0B,EAAE,EAAE;CAC5E,MAAM,QAAQ,MAAM,eAAe,MAAM,QAAQ;AACjD,KAAI,CAAC,MACH;AAGF,QAAO,kBAAkB,MAAM;;;;;;;;;AAUjC,eAAsB,eACpB,MACA,UAA0B,EAAE,EAC5B;CACA,MAAM,kBAAkB,MAAM,mBAAmB,MAAM,QAAQ;AAC/D,KAAI,CAAC,gBACH;CAGF,MAAM,cAAc,MAAM,aAA0B,gBAAgB;AAEpE,QAAO;EACL;EACA,SAAS,YAAY;EACrB,UAAU,aAAa,gBAAgB;E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,EAAE;AAC1E,QAAO,QAAQ,eAAe,MAAM,QAAQ,CAAC"}
@@ -4,12 +4,6 @@ let node_fs = require("node:fs");
4
4
  let node_fs_promises = require("node:fs/promises");
5
5
 
6
6
  //#region src/read-file.ts
7
- var read_file_exports = /* @__PURE__ */ require_runtime.__exportAll({
8
- readFile: () => readFile,
9
- readFileIfExisting: () => readFileIfExisting,
10
- readFileIfExistingSync: () => readFileIfExistingSync,
11
- readFileSync: () => readFileSync
12
- });
13
7
  /**
14
8
  * Read the given content to the given file path
15
9
  *
@@ -51,10 +45,4 @@ async function readFileIfExisting(path) {
51
45
  exports.readFile = readFile;
52
46
  exports.readFileIfExisting = readFileIfExisting;
53
47
  exports.readFileIfExistingSync = readFileIfExistingSync;
54
- exports.readFileSync = readFileSync;
55
- Object.defineProperty(exports, 'read_file_exports', {
56
- enumerable: true,
57
- get: function () {
58
- return read_file_exports;
59
- }
60
- });
48
+ exports.readFileSync = readFileSync;
@@ -1,14 +1,7 @@
1
- import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
2
1
  import { existsSync, readFileSync as readFileSync$1 } from "node:fs";
3
2
  import { readFile as readFile$1 } from "node:fs/promises";
4
3
 
5
4
  //#region src/read-file.ts
6
- var read_file_exports = /* @__PURE__ */ __exportAll({
7
- readFile: () => readFile,
8
- readFileIfExisting: () => readFileIfExisting,
9
- readFileIfExistingSync: () => readFileIfExistingSync,
10
- readFileSync: () => readFileSync
11
- });
12
5
  /**
13
6
  * Read the given content to the given file path
14
7
  *
@@ -47,5 +40,5 @@ async function readFileIfExisting(path) {
47
40
  }
48
41
 
49
42
  //#endregion
50
- export { readFile, readFileIfExisting, readFileIfExistingSync, readFileSync, read_file_exports };
43
+ export { readFile, readFileIfExisting, readFileIfExistingSync, readFileSync };
51
44
  //# sourceMappingURL=read-file.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"read-file.mjs","names":["readFileSyncFs","readFileFs"],"sources":["../src/read-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { existsSync, readFileSync as readFileSyncFs } from \"node:fs\";\nimport { readFile as readFileFs } from \"node:fs/promises\";\n\n/**\n * Read the given content to the given file path\n *\n * @param filePath - The file path to write to\n */\nexport const readFileSync = (filePath: string): string => {\n if (!filePath) {\n throw new Error(\"No file path provided to read data\");\n }\n\n return readFileSyncFs(filePath, { encoding: \"utf8\" });\n};\n\n/**\n * Read the given content to the given file path\n *\n * @param filePath - The file path to read to\n */\nexport const readFile = async (filePath: string): Promise<string> => {\n if (!filePath) {\n throw new Error(\"No file path provided to read data\");\n }\n\n return readFileFs(filePath, { encoding: \"utf8\" });\n};\n\n/**\n * Reads a file if it exists, otherwise returns an empty string.\n *\n * @param path - The path to the file to read.\n * @returns The content of the file if it exists, otherwise an empty string.\n */\nexport function readFileIfExistingSync(path: string) {\n return existsSync(path) ? readFileSync(path) : \"\";\n}\n\n/**\n * Reads a file if it exists, otherwise returns an empty string.\n *\n * @param path - The path to the file to read.\n * @returns The content of the file if it exists, otherwise an empty string.\n */\nexport async function readFileIfExisting(path: string) {\n return existsSync(path) ? readFile(path) : \"\";\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA0BA,MAAa,gBAAgB,aAA6B;AACxD,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,qCAAqC;AAGvD,QAAOA,eAAe,UAAU,EAAE,UAAU,QAAQ,CAAC;;;;;;;AAQvD,MAAa,WAAW,OAAO,aAAsC;AACnE,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,qCAAqC;AAGvD,QAAOC,WAAW,UAAU,EAAE,UAAU,QAAQ,CAAC;;;;;;;;AASnD,SAAgB,uBAAuB,MAAc;AACnD,QAAO,WAAW,KAAK,GAAG,aAAa,KAAK,GAAG;;;;;;;;AASjD,eAAsB,mBAAmB,MAAc;AACrD,QAAO,WAAW,KAAK,GAAG,SAAS,KAAK,GAAG"}
1
+ {"version":3,"file":"read-file.mjs","names":["readFileSyncFs","readFileFs"],"sources":["../src/read-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { existsSync, readFileSync as readFileSyncFs } from \"node:fs\";\nimport { readFile as readFileFs } from \"node:fs/promises\";\n\n/**\n * Read the given content to the given file path\n *\n * @param filePath - The file path to write to\n */\nexport const readFileSync = (filePath: string): string => {\n if (!filePath) {\n throw new Error(\"No file path provided to read data\");\n }\n\n return readFileSyncFs(filePath, { encoding: \"utf8\" });\n};\n\n/**\n * Read the given content to the given file path\n *\n * @param filePath - The file path to read to\n */\nexport const readFile = async (filePath: string): Promise<string> => {\n if (!filePath) {\n throw new Error(\"No file path provided to read data\");\n }\n\n return readFileFs(filePath, { encoding: \"utf8\" });\n};\n\n/**\n * Reads a file if it exists, otherwise returns an empty string.\n *\n * @param path - The path to the file to read.\n * @returns The content of the file if it exists, otherwise an empty string.\n */\nexport function readFileIfExistingSync(path: string) {\n return existsSync(path) ? readFileSync(path) : \"\";\n}\n\n/**\n * Reads a file if it exists, otherwise returns an empty string.\n *\n * @param path - The path to the file to read.\n * @returns The content of the file if it exists, otherwise an empty string.\n */\nexport async function readFileIfExisting(path: string) {\n return existsSync(path) ? readFile(path) : \"\";\n}\n"],"mappings":";;;;;;;;;AA0BA,MAAa,gBAAgB,aAA6B;AACxD,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,qCAAqC;AAGvD,QAAOA,eAAe,UAAU,EAAE,UAAU,QAAQ,CAAC;;;;;;;AAQvD,MAAa,WAAW,OAAO,aAAsC;AACnE,KAAI,CAAC,SACH,OAAM,IAAI,MAAM,qCAAqC;AAGvD,QAAOC,WAAW,UAAU,EAAE,UAAU,QAAQ,CAAC;;;;;;;;AASnD,SAAgB,uBAAuB,MAAc;AACnD,QAAO,WAAW,KAAK,GAAG,aAAa,KAAK,GAAG;;;;;;;;AASjD,eAAsB,mBAAmB,MAAc;AACrD,QAAO,WAAW,KAAK,GAAG,SAAS,KAAK,GAAG"}
package/dist/registry.cjs CHANGED
@@ -6,13 +6,6 @@ let _antfu_install_pkg = require("@antfu/install-pkg");
6
6
  let node_util = require("node:util");
7
7
 
8
8
  //#region src/registry.ts
9
- var registry_exports = /* @__PURE__ */ require_runtime.__exportAll({
10
- formatNodeOptions: () => formatNodeOptions,
11
- getFormattedNodeOptionsWithoutInspect: () => getFormattedNodeOptionsWithoutInspect,
12
- getParsedNodeOptionsWithoutInspect: () => getParsedNodeOptionsWithoutInspect,
13
- getRegistry: () => getRegistry,
14
- tokenizeArgs: () => tokenizeArgs
15
- });
16
9
  const parseNodeArgs = (args) => {
17
10
  const { values, tokens } = (0, node_util.parseArgs)({
18
11
  args,
@@ -147,10 +140,4 @@ exports.formatNodeOptions = formatNodeOptions;
147
140
  exports.getFormattedNodeOptionsWithoutInspect = getFormattedNodeOptionsWithoutInspect;
148
141
  exports.getParsedNodeOptionsWithoutInspect = getParsedNodeOptionsWithoutInspect;
149
142
  exports.getRegistry = getRegistry;
150
- Object.defineProperty(exports, 'registry_exports', {
151
- enumerable: true,
152
- get: function () {
153
- return registry_exports;
154
- }
155
- });
156
143
  exports.tokenizeArgs = tokenizeArgs;
package/dist/registry.mjs CHANGED
@@ -1,17 +1,9 @@
1
- import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
2
1
  import { getWorkspaceRoot } from "./get-workspace-root.mjs";
3
2
  import { execSync } from "node:child_process";
4
3
  import { detectPackageManager } from "@antfu/install-pkg";
5
4
  import { parseArgs } from "node:util";
6
5
 
7
6
  //#region src/registry.ts
8
- var registry_exports = /* @__PURE__ */ __exportAll({
9
- formatNodeOptions: () => formatNodeOptions,
10
- getFormattedNodeOptionsWithoutInspect: () => getFormattedNodeOptionsWithoutInspect,
11
- getParsedNodeOptionsWithoutInspect: () => getParsedNodeOptionsWithoutInspect,
12
- getRegistry: () => getRegistry,
13
- tokenizeArgs: () => tokenizeArgs
14
- });
15
7
  const parseNodeArgs = (args) => {
16
8
  const { values, tokens } = parseArgs({
17
9
  args,
@@ -142,5 +134,5 @@ async function getRegistry(baseDir) {
142
134
  }
143
135
 
144
136
  //#endregion
145
- export { formatNodeOptions, getFormattedNodeOptionsWithoutInspect, getParsedNodeOptionsWithoutInspect, getRegistry, registry_exports, tokenizeArgs };
137
+ export { formatNodeOptions, getFormattedNodeOptionsWithoutInspect, getParsedNodeOptionsWithoutInspect, getRegistry, tokenizeArgs };
146
138
  //# sourceMappingURL=registry.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.mjs","names":[],"sources":["../src/registry.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { detectPackageManager } from \"@antfu/install-pkg\";\nimport { execSync } from \"node:child_process\";\nimport { parseArgs } from \"node:util\";\nimport { getWorkspaceRoot } from \"./get-workspace-root\";\n\nexport interface NodeOptionsToken {\n kind: \"option\";\n index: number;\n name: string;\n rawName: string;\n value: undefined;\n inlineValue: undefined;\n}\n\nconst parseNodeArgs = (args: string[]) => {\n const { values, tokens } = parseArgs({ args, strict: false, tokens: true });\n\n // For the `NODE_OPTIONS`, we support arguments with values without the `=`\n // sign. We need to parse them manually.\n let orphan: NodeOptionsToken | null | undefined = null;\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i]!;\n\n if (token.kind === \"option-terminator\") {\n break;\n }\n\n // When we encounter an option, if it's value is undefined, we should check\n // to see if the following tokens are positional parameters. If they are,\n // then the option is orphaned, and we can assign it.\n if (token.kind === \"option\") {\n orphan = typeof token.value === \"undefined\" ? token : null;\n continue;\n }\n\n // If the token isn't a positional one, then we can't assign it to the found\n // orphaned option.\n if (token.kind !== \"positional\") {\n orphan = null;\n continue;\n }\n\n // If we don't have an orphan, then we can skip this token.\n if (!orphan) {\n continue;\n }\n\n // If the token is a positional one, and it has a value, so add it to the\n // values object. If it already exists, append it with a space.\n if (orphan.name in values && typeof values[orphan.name] === \"string\") {\n values[orphan.name] += ` ${token.value}`;\n } else {\n values[orphan.name] = token.value;\n }\n }\n\n return values;\n};\n\n/**\n * Tokenizes the arguments string into an array of strings, supporting quoted\n * values and escaped characters.\n * Converted from: https://github.com/nodejs/node/blob/c29d53c5cfc63c5a876084e788d70c9e87bed880/src/node_options.cc#L1401\n *\n * @param input - The arguments string to be tokenized.\n * @returns An array of strings with the tokenized arguments.\n */\nexport const tokenizeArgs = (input: string): string[] => {\n const args: string[] = [];\n let isInString = false;\n let willStartNewArg = true;\n\n for (let i = 0; i < input.length; i++) {\n let char = input[i]!;\n\n // Skip any escaped characters in strings.\n if (char === \"\\\\\" && isInString) {\n // Ensure we don't have an escape character at the end.\n if (input.length === i + 1) {\n throw new Error(\"Invalid escape character at the end.\");\n }\n\n // Skip the next character.\n char = input[++i]!;\n }\n // If we find a space outside of a string, we should start a new argument.\n else if (char === \" \" && !isInString) {\n willStartNewArg = true;\n continue;\n }\n\n // If we find a quote, we should toggle the string flag.\n else if (char === '\"') {\n isInString = !isInString;\n continue;\n }\n\n // If we're starting a new argument, we should add it to the array.\n if (willStartNewArg) {\n args.push(char);\n willStartNewArg = false;\n }\n // Otherwise, add it to the last argument.\n else {\n args[args.length - 1] += char;\n }\n }\n\n if (isInString) {\n throw new Error(\"Unterminated string\");\n }\n\n return args;\n};\n\n/**\n * Get the node options from the environment variable `NODE_OPTIONS` and returns\n * them as an array of strings.\n *\n * @returns An array of strings with the node options.\n */\nconst getNodeOptionsArgs = () => {\n if (!process.env.NODE_OPTIONS) return [];\n\n return tokenizeArgs(process.env.NODE_OPTIONS);\n};\n\n/**\n * Stringify the arguments to be used in a command line. It will ignore any\n * argument that has a value of `undefined`.\n *\n * @param args - The arguments to be stringified.\n * @returns A string with the arguments.\n */\nexport function formatNodeOptions(\n args: Record<string, string | boolean | undefined>\n): string {\n return Object.entries(args)\n .map(([key, value]) => {\n if (value === true) {\n return `--${key}`;\n }\n\n if (value) {\n return `--${key}=${\n // Values with spaces need to be quoted. We use JSON.stringify to\n // also escape any nested quotes.\n value.includes(\" \") && !value.startsWith('\"')\n ? JSON.stringify(value)\n : value\n }`;\n }\n\n return null;\n })\n .filter(arg => arg !== null)\n .join(\" \");\n}\n\n/**\n * Get the node options from the `NODE_OPTIONS` environment variable and parse\n * them into an object without the inspect options.\n *\n * @returns An object with the parsed node options.\n */\nexport function getParsedNodeOptionsWithoutInspect() {\n const args = getNodeOptionsArgs();\n if (args.length === 0) return {};\n\n const parsed = parseNodeArgs(args);\n\n // Remove inspect options.\n delete parsed.inspect;\n delete parsed[\"inspect-brk\"];\n delete parsed.inspect_brk;\n\n return parsed;\n}\n\n/**\n * Get the node options from the `NODE_OPTIONS` environment variable and format\n * them into a string without the inspect options.\n *\n * @returns A string with the formatted node options.\n */\nexport function getFormattedNodeOptionsWithoutInspect() {\n const args = getParsedNodeOptionsWithoutInspect();\n if (Object.keys(args).length === 0) return \"\";\n\n return formatNodeOptions(args);\n}\n\n/**\n * Returns the package registry using the user's package manager. The URL will have a trailing slash.\n *\n * @param baseDir - The base directory to detect the package manager from.\n * @returns The package registry URL with a trailing slash.\n * @throws Will throw an error if the package manager cannot be detected or if the registry cannot be retrieved.\n */\nexport async function getRegistry(baseDir?: string) {\n const workspaceRoot = getWorkspaceRoot(baseDir);\n const pkgManager = await detectPackageManager(workspaceRoot);\n\n // Since `npm config` command fails in npm workspace to prevent workspace config conflicts,\n // add `--no-workspaces` flag to run under the context of the root project only.\n // Safe for non-workspace projects as it's equivalent to default `--workspaces=false`.\n // x-ref: https://github.com/vercel/next.js/issues/47121#issuecomment-1499044345\n // x-ref: https://github.com/npm/statusboard/issues/371#issue-920669998\n const resolvedFlags = pkgManager === \"npm\" ? \"--no-workspaces\" : \"\";\n let registry = `https://registry.npmjs.org/`;\n\n try {\n const output = execSync(\n `${pkgManager} config get registry ${resolvedFlags}`,\n {\n env: {\n ...process.env,\n NODE_OPTIONS: getFormattedNodeOptionsWithoutInspect()\n }\n }\n )\n .toString()\n .trim();\n\n if (output.startsWith(\"http\")) {\n registry = output.endsWith(\"/\") ? output : `${output}/`;\n }\n } catch (err) {\n throw new Error(`Failed to get registry from \"${pkgManager}\".`, {\n cause: err\n });\n }\n\n return registry;\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,MAAM,iBAAiB,SAAmB;CACxC,MAAM,EAAE,QAAQ,WAAW,UAAU;EAAE;EAAM,QAAQ;EAAO,QAAQ;EAAM,CAAC;CAI3E,IAAI,SAA8C;AAClD,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,MAAM,QAAQ,OAAO;AAErB,MAAI,MAAM,SAAS,oBACjB;AAMF,MAAI,MAAM,SAAS,UAAU;AAC3B,YAAS,OAAO,MAAM,UAAU,cAAc,QAAQ;AACtD;;AAKF,MAAI,MAAM,SAAS,c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,KAAK,WAAW,EAAG,QAAO,EAAE;CAEhC,MAAM,SAAS,cAAc,KAAK;AAGlC,QAAO,OAAO;AACd,QAAO,OAAO;AACd,QAAO,OAAO;AAEd,QAAO;;;;;;;;AAST,SAAgB,wCAAwC;CACtD,MAAM,OAAO,oCAAoC;AACjD,KAAI,OAAO,KAAK,KAAK,CAAC,WAAW,EAAG,QAAO;AAE3C,QAAO,kBAAkB,KAAK;;;;;;;;;AAUhC,eAAsB,YAAY,SAAkB;CAElD,MAAM,aAAa,MAAM,qBADH,iBAAiB,QACoB,CAAC;CAO5D,MAAM,gBAAgB,eAAe,QAAQ,oBAAoB;CACjE,IAAI,WAAW;AAEf,KAAI;EACF,MAAM,SAAS,SACb,GAAG,WAAW,uBAAuB,iBACrC,EACE,KAAK;GACH,GAAG,QAAQ;GACX,cAAc,uCAAuC;GACtD,EACF,CACF,CACE,UAAU,CACV,MAAM;AAET,MAAI,OAAO,WAAW,OAAO,CAC3B,YAAW,OAAO,SAAS,IAAI,GAAG,SAAS,GAAG,OAAO;UAEhD,KAAK;AACZ,QAAM,IAAI,MAAM,gCAAgC,WAAW,KAAK,EAC9D,OAAO,KACR,CAAC;;AAGJ,QAAO"}
1
+ {"version":3,"file":"registry.mjs","names":[],"sources":["../src/registry.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { detectPackageManager } from \"@antfu/install-pkg\";\nimport { execSync } from \"node:child_process\";\nimport { parseArgs } from \"node:util\";\nimport { getWorkspaceRoot } from \"./get-workspace-root\";\n\nexport interface NodeOptionsToken {\n kind: \"option\";\n index: number;\n name: string;\n rawName: string;\n value: undefined;\n inlineValue: undefined;\n}\n\nconst parseNodeArgs = (args: string[]) => {\n const { values, tokens } = parseArgs({ args, strict: false, tokens: true });\n\n // For the `NODE_OPTIONS`, we support arguments with values without the `=`\n // sign. We need to parse them manually.\n let orphan: NodeOptionsToken | null | undefined = null;\n for (let i = 0; i < tokens.length; i++) {\n const token = tokens[i]!;\n\n if (token.kind === \"option-terminator\") {\n break;\n }\n\n // When we encounter an option, if it's value is undefined, we should check\n // to see if the following tokens are positional parameters. If they are,\n // then the option is orphaned, and we can assign it.\n if (token.kind === \"option\") {\n orphan = typeof token.value === \"undefined\" ? token : null;\n continue;\n }\n\n // If the token isn't a positional one, then we can't assign it to the found\n // orphaned option.\n if (token.kind !== \"positional\") {\n orphan = null;\n continue;\n }\n\n // If we don't have an orphan, then we can skip this token.\n if (!orphan) {\n continue;\n }\n\n // If the token is a positional one, and it has a value, so add it to the\n // values object. If it already exists, append it with a space.\n if (orphan.name in values && typeof values[orphan.name] === \"string\") {\n values[orphan.name] += ` ${token.value}`;\n } else {\n values[orphan.name] = token.value;\n }\n }\n\n return values;\n};\n\n/**\n * Tokenizes the arguments string into an array of strings, supporting quoted\n * values and escaped characters.\n * Converted from: https://github.com/nodejs/node/blob/c29d53c5cfc63c5a876084e788d70c9e87bed880/src/node_options.cc#L1401\n *\n * @param input - The arguments string to be tokenized.\n * @returns An array of strings with the tokenized arguments.\n */\nexport const tokenizeArgs = (input: string): string[] => {\n const args: string[] = [];\n let isInString = false;\n let willStartNewArg = true;\n\n for (let i = 0; i < input.length; i++) {\n let char = input[i]!;\n\n // Skip any escaped characters in strings.\n if (char === \"\\\\\" && isInString) {\n // Ensure we don't have an escape character at the end.\n if (input.length === i + 1) {\n throw new Error(\"Invalid escape character at the end.\");\n }\n\n // Skip the next character.\n char = input[++i]!;\n }\n // If we find a space outside of a string, we should start a new argument.\n else if (char === \" \" && !isInString) {\n willStartNewArg = true;\n continue;\n }\n\n // If we find a quote, we should toggle the string flag.\n else if (char === '\"') {\n isInString = !isInString;\n continue;\n }\n\n // If we're starting a new argument, we should add it to the array.\n if (willStartNewArg) {\n args.push(char);\n willStartNewArg = false;\n }\n // Otherwise, add it to the last argument.\n else {\n args[args.length - 1] += char;\n }\n }\n\n if (isInString) {\n throw new Error(\"Unterminated string\");\n }\n\n return args;\n};\n\n/**\n * Get the node options from the environment variable `NODE_OPTIONS` and returns\n * them as an array of strings.\n *\n * @returns An array of strings with the node options.\n */\nconst getNodeOptionsArgs = () => {\n if (!process.env.NODE_OPTIONS) return [];\n\n return tokenizeArgs(process.env.NODE_OPTIONS);\n};\n\n/**\n * Stringify the arguments to be used in a command line. It will ignore any\n * argument that has a value of `undefined`.\n *\n * @param args - The arguments to be stringified.\n * @returns A string with the arguments.\n */\nexport function formatNodeOptions(\n args: Record<string, string | boolean | undefined>\n): string {\n return Object.entries(args)\n .map(([key, value]) => {\n if (value === true) {\n return `--${key}`;\n }\n\n if (value) {\n return `--${key}=${\n // Values with spaces need to be quoted. We use JSON.stringify to\n // also escape any nested quotes.\n value.includes(\" \") && !value.startsWith('\"')\n ? JSON.stringify(value)\n : value\n }`;\n }\n\n return null;\n })\n .filter(arg => arg !== null)\n .join(\" \");\n}\n\n/**\n * Get the node options from the `NODE_OPTIONS` environment variable and parse\n * them into an object without the inspect options.\n *\n * @returns An object with the parsed node options.\n */\nexport function getParsedNodeOptionsWithoutInspect() {\n const args = getNodeOptionsArgs();\n if (args.length === 0) return {};\n\n const parsed = parseNodeArgs(args);\n\n // Remove inspect options.\n delete parsed.inspect;\n delete parsed[\"inspect-brk\"];\n delete parsed.inspect_brk;\n\n return parsed;\n}\n\n/**\n * Get the node options from the `NODE_OPTIONS` environment variable and format\n * them into a string without the inspect options.\n *\n * @returns A string with the formatted node options.\n */\nexport function getFormattedNodeOptionsWithoutInspect() {\n const args = getParsedNodeOptionsWithoutInspect();\n if (Object.keys(args).length === 0) return \"\";\n\n return formatNodeOptions(args);\n}\n\n/**\n * Returns the package registry using the user's package manager. The URL will have a trailing slash.\n *\n * @param baseDir - The base directory to detect the package manager from.\n * @returns The package registry URL with a trailing slash.\n * @throws Will throw an error if the package manager cannot be detected or if the registry cannot be retrieved.\n */\nexport async function getRegistry(baseDir?: string) {\n const workspaceRoot = getWorkspaceRoot(baseDir);\n const pkgManager = await detectPackageManager(workspaceRoot);\n\n // Since `npm config` command fails in npm workspace to prevent workspace config conflicts,\n // add `--no-workspaces` flag to run under the context of the root project only.\n // Safe for non-workspace projects as it's equivalent to default `--workspaces=false`.\n // x-ref: https://github.com/vercel/next.js/issues/47121#issuecomment-1499044345\n // x-ref: https://github.com/npm/statusboard/issues/371#issue-920669998\n const resolvedFlags = pkgManager === \"npm\" ? \"--no-workspaces\" : \"\";\n let registry = `https://registry.npmjs.org/`;\n\n try {\n const output = execSync(\n `${pkgManager} config get registry ${resolvedFlags}`,\n {\n env: {\n ...process.env,\n NODE_OPTIONS: getFormattedNodeOptionsWithoutInspect()\n }\n }\n )\n .toString()\n .trim();\n\n if (output.startsWith(\"http\")) {\n registry = output.endsWith(\"/\") ? output : `${output}/`;\n }\n } catch (err) {\n throw new Error(`Failed to get registry from \"${pkgManager}\".`, {\n cause: err\n });\n }\n\n return registry;\n}\n"],"mappings":";;;;;;AAgCA,MAAM,iBAAiB,SAAmB;CACxC,MAAM,EAAE,QAAQ,WAAW,UAAU;EAAE;EAAM,QAAQ;EAAO,QAAQ;EAAM,CAAC;CAI3E,IAAI,SAA8C;AAClD,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;EACtC,MAAM,QAAQ,OAAO;AAErB,MAAI,MAAM,SAAS,oBACjB;AAMF,MAAI,MAAM,SAAS,UAAU;AAC3B,YAAS,OAAO,MAAM,UAAU,cAAc,QAAQ;AACtD;;AAKF,MAAI,MAAM,SAAS,cAAc;AAC/B,YAAS;AACT;;AAIF,MAAI,CAAC,OACH;AAKF,MAAI,OAAO,QAA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,QAAO,OAAO;AACd,QAAO,OAAO;AACd,QAAO,OAAO;AAEd,QAAO;;;;;;;;AAST,SAAgB,wCAAwC;CACtD,MAAM,OAAO,oCAAoC;AACjD,KAAI,OAAO,KAAK,KAAK,CAAC,WAAW,EAAG,QAAO;AAE3C,QAAO,kBAAkB,KAAK;;;;;;;;;AAUhC,eAAsB,YAAY,SAAkB;CAElD,MAAM,aAAa,MAAM,qBADH,iBAAiB,QACoB,CAAC;CAO5D,MAAM,gBAAgB,eAAe,QAAQ,oBAAoB;CACjE,IAAI,WAAW;AAEf,KAAI;EACF,MAAM,SAAS,SACb,GAAG,WAAW,uBAAuB,iBACrC,EACE,KAAK;GACH,GAAG,QAAQ;GACX,cAAc,uCAAuC;GACtD,EACF,CACF,CACE,UAAU,CACV,MAAM;AAET,MAAI,OAAO,WAAW,OAAO,CAC3B,YAAW,OAAO,SAAS,IAAI,GAAG,SAAS,GAAG,OAAO;UAEhD,KAAK;AACZ,QAAM,IAAI,MAAM,gCAAgC,WAAW,KAAK,EAC9D,OAAO,KACR,CAAC;;AAGJ,QAAO"}
@@ -4,10 +4,6 @@ let node_fs = require("node:fs");
4
4
  let node_fs_promises = require("node:fs/promises");
5
5
 
6
6
  //#region src/remove-file.ts
7
- var remove_file_exports = /* @__PURE__ */ require_runtime.__exportAll({
8
- removeFile: () => removeFile,
9
- removeFileSync: () => removeFileSync
10
- });
11
7
  /**
12
8
  * Remove the given content to the given file path
13
9
  *
@@ -29,10 +25,4 @@ const removeFile = async (filePath) => {
29
25
 
30
26
  //#endregion
31
27
  exports.removeFile = removeFile;
32
- exports.removeFileSync = removeFileSync;
33
- Object.defineProperty(exports, 'remove_file_exports', {
34
- enumerable: true,
35
- get: function () {
36
- return remove_file_exports;
37
- }
38
- });
28
+ exports.removeFileSync = removeFileSync;
@@ -1,12 +1,7 @@
1
- import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
2
1
  import { existsSync, rmSync } from "node:fs";
3
2
  import { rm } from "node:fs/promises";
4
3
 
5
4
  //#region src/remove-file.ts
6
- var remove_file_exports = /* @__PURE__ */ __exportAll({
7
- removeFile: () => removeFile,
8
- removeFileSync: () => removeFileSync
9
- });
10
5
  /**
11
6
  * Remove the given content to the given file path
12
7
  *
@@ -27,5 +22,5 @@ const removeFile = async (filePath) => {
27
22
  };
28
23
 
29
24
  //#endregion
30
- export { removeFile, removeFileSync, remove_file_exports };
25
+ export { removeFile, removeFileSync };
31
26
  //# sourceMappingURL=remove-file.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"remove-file.mjs","names":[],"sources":["../src/remove-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { existsSync, rmSync } from \"node:fs\";\nimport { rm } from \"node:fs/promises\";\n\n/**\n * Remove the given content to the given file path\n *\n * @param filePath - The file path to remove to\n */\nexport const removeFileSync = (filePath: string): void => {\n if (!filePath || !existsSync(filePath)) {\n return;\n }\n\n rmSync(filePath);\n};\n\n/**\n * Remove the given content to the given file path\n *\n * @param filePath - The file path to read to\n */\nexport const removeFile = async (filePath: string): Promise<void> => {\n if (!filePath || !existsSync(filePath)) {\n return;\n }\n\n return rm(filePath);\n};\n"],"mappings":";;;;;;;;;;;;;;AA0BA,MAAa,kBAAkB,aAA2B;AACxD,KAAI,CAAC,YAAY,CAAC,WAAW,SAAS,CACpC;AAGF,QAAO,SAAS;;;;;;;AAQlB,MAAa,aAAa,OAAO,aAAoC;AACnE,KAAI,CAAC,YAAY,CAAC,WAAW,SAAS,CACpC;AAGF,QAAO,GAAG,SAAS"}
1
+ {"version":3,"file":"remove-file.mjs","names":[],"sources":["../src/remove-file.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { existsSync, rmSync } from \"node:fs\";\nimport { rm } from \"node:fs/promises\";\n\n/**\n * Remove the given content to the given file path\n *\n * @param filePath - The file path to remove to\n */\nexport const removeFileSync = (filePath: string): void => {\n if (!filePath || !existsSync(filePath)) {\n return;\n }\n\n rmSync(filePath);\n};\n\n/**\n * Remove the given content to the given file path\n *\n * @param filePath - The file path to read to\n */\nexport const removeFile = async (filePath: string): Promise<void> => {\n if (!filePath || !existsSync(filePath)) {\n return;\n }\n\n return rm(filePath);\n};\n"],"mappings":";;;;;;;;;AA0BA,MAAa,kBAAkB,aAA2B;AACxD,KAAI,CAAC,YAAY,CAAC,WAAW,SAAS,CACpC;AAGF,QAAO,SAAS;;;;;;;AAQlB,MAAa,aAAa,OAAO,aAAoC;AACnE,KAAI,CAAC,YAAY,CAAC,WAAW,SAAS,CACpC;AAGF,QAAO,GAAG,SAAS"}
package/dist/resolve.cjs CHANGED
@@ -12,19 +12,6 @@ let _stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
12
12
  let _stryke_path_is_type = require("@stryke/path/is-type");
13
13
 
14
14
  //#region src/resolve.ts
15
- var resolve_exports = /* @__PURE__ */ require_runtime.__exportAll({
16
- DEFAULT_EXTENSIONS: () => DEFAULT_EXTENSIONS,
17
- getNodeModulesPaths: () => getNodeModulesPaths,
18
- getResolutionCombinations: () => getResolutionCombinations,
19
- getResolutionPaths: () => getResolutionPaths,
20
- importModule: () => importModule,
21
- resolve: () => resolve,
22
- resolvePackage: () => resolvePackage,
23
- resolvePackageSync: () => resolvePackageSync,
24
- resolveSafe: () => resolveSafe,
25
- resolveSafeSync: () => resolveSafeSync,
26
- resolveSync: () => resolveSync
27
- });
28
15
  const DEFAULT_EXTENSIONS = [
29
16
  "js",
30
17
  "jsx",
@@ -249,10 +236,4 @@ exports.resolvePackage = resolvePackage;
249
236
  exports.resolvePackageSync = resolvePackageSync;
250
237
  exports.resolveSafe = resolveSafe;
251
238
  exports.resolveSafeSync = resolveSafeSync;
252
- exports.resolveSync = resolveSync;
253
- Object.defineProperty(exports, 'resolve_exports', {
254
- enumerable: true,
255
- get: function () {
256
- return resolve_exports;
257
- }
258
- });
239
+ exports.resolveSync = resolveSync;
package/dist/resolve.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
2
1
  import { existsSync } from "./exists.mjs";
3
2
  import { getWorkspaceRoot } from "./get-workspace-root.mjs";
4
3
  import { appendExtension } from "@stryke/path";
@@ -11,19 +10,6 @@ import { getUnique } from "@stryke/helpers/get-unique";
11
10
  import { isAbsolutePath, isNpmScopedPackage } from "@stryke/path/is-type";
12
11
 
13
12
  //#region src/resolve.ts
14
- var resolve_exports = /* @__PURE__ */ __exportAll({
15
- DEFAULT_EXTENSIONS: () => DEFAULT_EXTENSIONS,
16
- getNodeModulesPaths: () => getNodeModulesPaths,
17
- getResolutionCombinations: () => getResolutionCombinations,
18
- getResolutionPaths: () => getResolutionPaths,
19
- importModule: () => importModule,
20
- resolve: () => resolve,
21
- resolvePackage: () => resolvePackage,
22
- resolvePackageSync: () => resolvePackageSync,
23
- resolveSafe: () => resolveSafe,
24
- resolveSafeSync: () => resolveSafeSync,
25
- resolveSync: () => resolveSync
26
- });
27
13
  const DEFAULT_EXTENSIONS = [
28
14
  "js",
29
15
  "jsx",
@@ -238,5 +224,5 @@ function resolvePackageSync(name, options = {}) {
238
224
  }
239
225
 
240
226
  //#endregion
241
- export { DEFAULT_EXTENSIONS, getNodeModulesPaths, getResolutionCombinations, getResolutionPaths, importModule, resolve, resolvePackage, resolvePackageSync, resolveSafe, resolveSafeSync, resolveSync, resolve_exports };
227
+ export { DEFAULT_EXTENSIONS, getNodeModulesPaths, getResolutionCombinations, getResolutionPaths, importModule, resolve, resolvePackage, resolvePackageSync, resolveSafe, resolveSafeSync, resolveSync };
242
228
  //# sourceMappingURL=resolve.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolve.mjs","names":["findFolderName","joinPaths","hasFileExtension","findFilePath"],"sources":["../src/resolve.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\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 { appendExtension } from \"@stryke/path\";\nimport { correctPath, toAbsolutePath } from \"@stryke/path/correct-path\";\nimport { cwd } from \"@stryke/path/cwd\";\nimport {\n findFileName,\n findFilePath,\n findFolderName,\n hasFileExtension\n} from \"@stryke/path/file-path-fns\";\nimport { isAbsolutePath, isNpmScopedPackage } from \"@stryke/path/is-type\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { interopDefault, resolvePath, resolvePathSync } from \"mlly\";\nimport { existsSync } from \"./exists\";\nimport { getWorkspaceRoot } from \"./get-workspace-root\";\n\nexport const DEFAULT_EXTENSIONS = [\n \"js\",\n \"jsx\",\n \"mjs\",\n \"cjs\",\n \"ts\",\n \"tsx\",\n \"mts\",\n \"cts\",\n \"json\",\n \"jsonc\",\n \"json5\",\n \"node\"\n];\n\nexport interface ResolveOptions {\n /**\n * Paths to resolve the package from\n */\n paths?: string[];\n\n /**\n * File extensions to consider when resolving the module\n *\n * @remarks\n * Extensions can be provided with or without the leading dot. The resolver utilities will handle both cases.\n *\n * @defaultValue [\"js\", \"jsx\", \"mjs\", \"cjs\", \"ts\", \"tsx\", \"mts\", \"cts\", \"json\", \"jsonc\", \"json5\", \"node\", \"wasm\"]\n */\n extensions?: string[];\n\n /**\n * Conditions to consider when resolving package exports.\n */\n conditions?: string[];\n}\n\n/**\n * Get the resolution paths based on the provided paths, current working directory, and workspace root.\n *\n * @param paths - An array of paths to include in the resolution.\n * @returns An array of unique, corrected resolution paths.\n */\nexport function getResolutionPaths(paths: string[] = []) {\n let resolutionPaths = paths;\n if (!resolutionPaths.includes(cwd())) {\n resolutionPaths.push(cwd());\n }\n\n const workspaceRoot = getWorkspaceRoot();\n if (!resolutionPaths.includes(workspaceRoot)) {\n resolutionPaths.push(workspaceRoot);\n }\n\n resolutionPaths = getUnique(\n resolutionPaths\n .filter(Boolean)\n .map(path => correctPath(path))\n .reduce((ret, path, _, arr) => {\n ret.push(path);\n if (!isAbsolutePath(path)) {\n ret.push(toAbsolutePath(path, cwd()));\n ret.push(toAbsolutePath(path, workspaceRoot));\n\n arr.forEach(existing => {\n ret.push(toAbsolutePath(path, existing));\n });\n }\n\n return ret;\n }, [] as string[])\n );\n\n return resolutionPaths;\n}\n\n/**\n * Get the node_modules resolution paths based on the provided paths.\n *\n * @param paths - An array of paths to include in the resolution.\n * @returns An array of unique, corrected node_modules resolution paths.\n */\nexport function getNodeModulesPaths(paths: string[] = []) {\n return getUnique(\n paths.reduce((ret, path) => {\n if (findFolderName(path) === \"node_modules\") {\n ret.push(correctPath(path));\n }\n\n if (existsSync(joinPaths(path, \"node_modules\"))) {\n ret.push(correctPath(joinPaths(path, \"node_modules\")));\n }\n\n return ret;\n }, [] as string[])\n );\n}\n\nexport interface ResolutionCombinationOptions extends ResolveOptions {\n /**\n * Whether to include additional paths (like node_modules) in the resolution combinations. If set to false, only the provided paths will be used for generating combinations. This can be useful for scenarios where you want to limit the resolution to specific directories without considering the default node_modules paths.\n *\n * @defaultValue true\n */\n useAdditionalPaths?: boolean;\n}\n\n/**\n * Get all combinations of resolution paths for a given path and options.\n *\n * @param path - The base path to combine with resolution paths.\n * @param options - The options containing resolution paths.\n * @returns An array of unique, corrected resolution paths.\n */\nexport function getResolutionCombinations(\n path: string,\n options: ResolutionCombinationOptions = {}\n) {\n let paths = options.useAdditionalPaths\n ? getResolutionPaths(options.paths)\n : (options.paths ?? []);\n if (isNpmScopedPackage(path)) {\n paths = getNodeModulesPaths(paths);\n } else {\n paths.push(...getNodeModulesPaths(paths));\n }\n\n let combinations = paths.map(base => joinPaths(base, path));\n if (findFileName(path, { withExtension: false }) !== \"index\") {\n combinations = combinations.reduce((ret, combination) => {\n ret.push(combination);\n ret.push(joinPaths(combination, \"index\"));\n\n return ret;\n }, [] as string[]);\n }\n\n if (!hasFileExtension(path)) {\n const extensions = options.extensions ?? DEFAULT_EXTENSIONS;\n\n combinations = combinations.reduce((ret, combination) => {\n ret.push(combination);\n extensions.forEach(ext => {\n ret.push(appendExtension(combination, ext));\n });\n\n return ret;\n }, [] as string[]);\n\n combinations.push(\n ...extensions\n .map(ext =>\n getResolutionCombinations(appendExtension(path, ext), options)\n )\n .flat()\n );\n }\n\n paths.map(p => {\n if (hasFileExtension(p)) {\n combinations.push(\n ...getResolutionCombinations(path, {\n ...options,\n useAdditionalPaths: false,\n paths: [findFilePath(p)]\n })\n );\n }\n });\n\n return getUnique(combinations.filter(Boolean)).map(p => correctPath(p));\n}\n\n/**\n * Resolve the path to a specified module\n *\n * @param path - The path to the module\n * @param options - The options to use when resolving the module\n * @returns A promise for the path to the module\n */\nexport async function resolve(\n path: string,\n options: ResolveOptions = {}\n): Promise<string> {\n let paths = getResolutionPaths(options.paths);\n if (isNpmScopedPackage(path)) {\n paths = getNodeModulesPaths(paths);\n } else {\n paths.push(...getNodeModulesPaths(paths));\n }\n\n let result: string | undefined;\n let error: Error | undefined;\n\n try {\n result = await resolvePath(path, {\n url: paths,\n extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n conditions: options.conditions\n });\n } catch (err) {\n error = err as Error;\n }\n\n // if (!result) {\n // for (let i = 0; i < paths.length && !result; i++) {\n // try {\n // result = await resolvePath(replacePath(path, paths[i]), {\n // url: paths,\n // extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n // conditions: options.conditions\n // });\n // } catch (err) {\n // error = err as Error;\n // }\n // }\n // }\n\n if (!result) {\n throw new Error(\n `Unable to resolve module \"${\n path\n }\". The following import paths were tried: \\n${paths.join(\"\\n\")}`,\n {\n cause: error\n }\n );\n }\n\n return correctPath(result);\n}\n\n/**\n * Resolve the path to a specified module\n *\n * @param path - The path to the module\n * @param options - The options to use when resolving the module\n * @returns The path to the module or undefined\n */\nexport function resolveSync(path: string, options: ResolveOptions = {}) {\n let paths = getResolutionPaths(options.paths);\n if (isNpmScopedPackage(path)) {\n paths = getNodeModulesPaths(paths);\n } else {\n paths.push(...getNodeModulesPaths(paths));\n }\n\n let result!: string;\n let error: Error | undefined;\n\n try {\n result = resolvePathSync(path, {\n url: paths,\n extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n conditions: options.conditions\n });\n } catch (err) {\n error = err as Error;\n }\n\n // if (!result) {\n // for (let i = 0; i < paths.length && !result; i++) {\n // try {\n // result = resolvePathSync(replacePath(path, paths[i]), {\n // url: paths,\n // extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n // conditions: options.conditions\n // });\n // } catch (err) {\n // error = err as Error;\n // }\n // }\n // }\n\n // if (!result && findFileName(path, { withExtension: false }) !== \"index\") {\n // try {\n // result = resolveSync(joinPaths(path, \"index\"), {\n // ...options,\n // paths\n // });\n // if (result) {\n // // Remove the previously added index file from the path\n // result = findFilePath(result);\n // }\n // } catch (err) {\n // error = err as Error;\n // }\n // }\n\n if (!result) {\n throw new Error(\n `Unable to resolve module \"${\n path\n }\". The following import paths were tried: \\n${paths.join(\"\\n\")}`,\n {\n cause: error\n }\n );\n }\n\n return correctPath(result);\n}\n\n/**\n * Resolve the path to a specified module with error handling\n *\n * @param name - The name of the module\n * @param options - The options to use when resolving the module\n * @returns A promise for the path to the module\n */\nexport async function resolveSafe(name: string, options: ResolveOptions = {}) {\n try {\n return await resolve(name, options);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Resolve the path to a specified module with error handling\n *\n * @param name - The name of the module\n * @param options - The options to use when resolving the module\n * @returns The path to the module or undefined\n */\nexport function resolveSafeSync(name: string, options: ResolveOptions = {}) {\n try {\n return resolveSync(name, options);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Import a module from a specified path\n *\n * @param path - The path to the module\n * @returns The module\n */\nexport async function importModule<T = any>(path: string): Promise<T> {\n const i = await import(path);\n\n if (i) {\n return interopDefault(i);\n }\n\n return i;\n}\n\n/**\n * Resolve the path to a specified package asynchronously\n *\n * @remarks\n * This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.\n *\n * @param name - The name of the module\n * @returns A promise for the module or undefined\n */\nexport async function resolvePackage(\n name: string,\n options: ResolveOptions = {}\n) {\n let result = await resolveSafe(joinPaths(name, \"package.json\"), options);\n if (!result) {\n result = await resolveSafe(joinPaths(name, \"index.js\"), options);\n if (!result) {\n result = await resolveSafe(name, options);\n }\n }\n\n return result ? findFilePath(result) : undefined;\n}\n\n/**\n * Resolve the path to a specified package synchronously\n *\n * @remarks\n * This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.\n *\n * @param name - The name of the module\n * @param options - The options to use when resolving the module\n * @returns The module or undefined\n */\nexport function resolvePackageSync(name: string, options: ResolveOptions = {}) {\n let result = resolveSafeSync(joinPaths(name, \"package.json\"), options);\n if (!result) {\n result = resolveSafeSync(joinPaths(name, \"index.js\"), options);\n if (!result) {\n result = resolveSafeSync(name, options);\n }\n }\n\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AAChE,MAAI,CAAC,OACH,UAAS,MAAM,YAAY,MAAM,QAAQ;;AAI7C,QAAO,SAASE,eAAa,OAAO,GAAG;;;;;;;;;;;;AAazC,SAAgB,mBAAmB,MAAc,UAA0B,EAAE,EAAE;CAC7E,IAAI,SAAS,gBAAgBF,YAAU,MAAM,eAAe,EAAE,QAAQ;AACtE,KAAI,CAAC,QAAQ;AACX,WAAS,gBAAgBA,YAAU,MAAM,WAAW,EAAE,QAAQ;AAC9D,MAAI,CAAC,OACH,UAAS,gBAAgB,MAAM,QAAQ;;AAI3C,QAAO,SAASE,eAAa,OAAO,GAAG"}
1
+ {"version":3,"file":"resolve.mjs","names":["findFolderName","joinPaths","hasFileExtension","findFilePath"],"sources":["../src/resolve.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\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/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\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 { appendExtension } from \"@stryke/path\";\nimport { correctPath, toAbsolutePath } from \"@stryke/path/correct-path\";\nimport { cwd } from \"@stryke/path/cwd\";\nimport {\n findFileName,\n findFilePath,\n findFolderName,\n hasFileExtension\n} from \"@stryke/path/file-path-fns\";\nimport { isAbsolutePath, isNpmScopedPackage } from \"@stryke/path/is-type\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { interopDefault, resolvePath, resolvePathSync } from \"mlly\";\nimport { existsSync } from \"./exists\";\nimport { getWorkspaceRoot } from \"./get-workspace-root\";\n\nexport const DEFAULT_EXTENSIONS = [\n \"js\",\n \"jsx\",\n \"mjs\",\n \"cjs\",\n \"ts\",\n \"tsx\",\n \"mts\",\n \"cts\",\n \"json\",\n \"jsonc\",\n \"json5\",\n \"node\"\n];\n\nexport interface ResolveOptions {\n /**\n * Paths to resolve the package from\n */\n paths?: string[];\n\n /**\n * File extensions to consider when resolving the module\n *\n * @remarks\n * Extensions can be provided with or without the leading dot. The resolver utilities will handle both cases.\n *\n * @defaultValue [\"js\", \"jsx\", \"mjs\", \"cjs\", \"ts\", \"tsx\", \"mts\", \"cts\", \"json\", \"jsonc\", \"json5\", \"node\", \"wasm\"]\n */\n extensions?: string[];\n\n /**\n * Conditions to consider when resolving package exports.\n */\n conditions?: string[];\n}\n\n/**\n * Get the resolution paths based on the provided paths, current working directory, and workspace root.\n *\n * @param paths - An array of paths to include in the resolution.\n * @returns An array of unique, corrected resolution paths.\n */\nexport function getResolutionPaths(paths: string[] = []) {\n let resolutionPaths = paths;\n if (!resolutionPaths.includes(cwd())) {\n resolutionPaths.push(cwd());\n }\n\n const workspaceRoot = getWorkspaceRoot();\n if (!resolutionPaths.includes(workspaceRoot)) {\n resolutionPaths.push(workspaceRoot);\n }\n\n resolutionPaths = getUnique(\n resolutionPaths\n .filter(Boolean)\n .map(path => correctPath(path))\n .reduce((ret, path, _, arr) => {\n ret.push(path);\n if (!isAbsolutePath(path)) {\n ret.push(toAbsolutePath(path, cwd()));\n ret.push(toAbsolutePath(path, workspaceRoot));\n\n arr.forEach(existing => {\n ret.push(toAbsolutePath(path, existing));\n });\n }\n\n return ret;\n }, [] as string[])\n );\n\n return resolutionPaths;\n}\n\n/**\n * Get the node_modules resolution paths based on the provided paths.\n *\n * @param paths - An array of paths to include in the resolution.\n * @returns An array of unique, corrected node_modules resolution paths.\n */\nexport function getNodeModulesPaths(paths: string[] = []) {\n return getUnique(\n paths.reduce((ret, path) => {\n if (findFolderName(path) === \"node_modules\") {\n ret.push(correctPath(path));\n }\n\n if (existsSync(joinPaths(path, \"node_modules\"))) {\n ret.push(correctPath(joinPaths(path, \"node_modules\")));\n }\n\n return ret;\n }, [] as string[])\n );\n}\n\nexport interface ResolutionCombinationOptions extends ResolveOptions {\n /**\n * Whether to include additional paths (like node_modules) in the resolution combinations. If set to false, only the provided paths will be used for generating combinations. This can be useful for scenarios where you want to limit the resolution to specific directories without considering the default node_modules paths.\n *\n * @defaultValue true\n */\n useAdditionalPaths?: boolean;\n}\n\n/**\n * Get all combinations of resolution paths for a given path and options.\n *\n * @param path - The base path to combine with resolution paths.\n * @param options - The options containing resolution paths.\n * @returns An array of unique, corrected resolution paths.\n */\nexport function getResolutionCombinations(\n path: string,\n options: ResolutionCombinationOptions = {}\n) {\n let paths = options.useAdditionalPaths\n ? getResolutionPaths(options.paths)\n : (options.paths ?? []);\n if (isNpmScopedPackage(path)) {\n paths = getNodeModulesPaths(paths);\n } else {\n paths.push(...getNodeModulesPaths(paths));\n }\n\n let combinations = paths.map(base => joinPaths(base, path));\n if (findFileName(path, { withExtension: false }) !== \"index\") {\n combinations = combinations.reduce((ret, combination) => {\n ret.push(combination);\n ret.push(joinPaths(combination, \"index\"));\n\n return ret;\n }, [] as string[]);\n }\n\n if (!hasFileExtension(path)) {\n const extensions = options.extensions ?? DEFAULT_EXTENSIONS;\n\n combinations = combinations.reduce((ret, combination) => {\n ret.push(combination);\n extensions.forEach(ext => {\n ret.push(appendExtension(combination, ext));\n });\n\n return ret;\n }, [] as string[]);\n\n combinations.push(\n ...extensions\n .map(ext =>\n getResolutionCombinations(appendExtension(path, ext), options)\n )\n .flat()\n );\n }\n\n paths.map(p => {\n if (hasFileExtension(p)) {\n combinations.push(\n ...getResolutionCombinations(path, {\n ...options,\n useAdditionalPaths: false,\n paths: [findFilePath(p)]\n })\n );\n }\n });\n\n return getUnique(combinations.filter(Boolean)).map(p => correctPath(p));\n}\n\n/**\n * Resolve the path to a specified module\n *\n * @param path - The path to the module\n * @param options - The options to use when resolving the module\n * @returns A promise for the path to the module\n */\nexport async function resolve(\n path: string,\n options: ResolveOptions = {}\n): Promise<string> {\n let paths = getResolutionPaths(options.paths);\n if (isNpmScopedPackage(path)) {\n paths = getNodeModulesPaths(paths);\n } else {\n paths.push(...getNodeModulesPaths(paths));\n }\n\n let result: string | undefined;\n let error: Error | undefined;\n\n try {\n result = await resolvePath(path, {\n url: paths,\n extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n conditions: options.conditions\n });\n } catch (err) {\n error = err as Error;\n }\n\n // if (!result) {\n // for (let i = 0; i < paths.length && !result; i++) {\n // try {\n // result = await resolvePath(replacePath(path, paths[i]), {\n // url: paths,\n // extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n // conditions: options.conditions\n // });\n // } catch (err) {\n // error = err as Error;\n // }\n // }\n // }\n\n if (!result) {\n throw new Error(\n `Unable to resolve module \"${\n path\n }\". The following import paths were tried: \\n${paths.join(\"\\n\")}`,\n {\n cause: error\n }\n );\n }\n\n return correctPath(result);\n}\n\n/**\n * Resolve the path to a specified module\n *\n * @param path - The path to the module\n * @param options - The options to use when resolving the module\n * @returns The path to the module or undefined\n */\nexport function resolveSync(path: string, options: ResolveOptions = {}) {\n let paths = getResolutionPaths(options.paths);\n if (isNpmScopedPackage(path)) {\n paths = getNodeModulesPaths(paths);\n } else {\n paths.push(...getNodeModulesPaths(paths));\n }\n\n let result!: string;\n let error: Error | undefined;\n\n try {\n result = resolvePathSync(path, {\n url: paths,\n extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n conditions: options.conditions\n });\n } catch (err) {\n error = err as Error;\n }\n\n // if (!result) {\n // for (let i = 0; i < paths.length && !result; i++) {\n // try {\n // result = resolvePathSync(replacePath(path, paths[i]), {\n // url: paths,\n // extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n // conditions: options.conditions\n // });\n // } catch (err) {\n // error = err as Error;\n // }\n // }\n // }\n\n // if (!result && findFileName(path, { withExtension: false }) !== \"index\") {\n // try {\n // result = resolveSync(joinPaths(path, \"index\"), {\n // ...options,\n // paths\n // });\n // if (result) {\n // // Remove the previously added index file from the path\n // result = findFilePath(result);\n // }\n // } catch (err) {\n // error = err as Error;\n // }\n // }\n\n if (!result) {\n throw new Error(\n `Unable to resolve module \"${\n path\n }\". The following import paths were tried: \\n${paths.join(\"\\n\")}`,\n {\n cause: error\n }\n );\n }\n\n return correctPath(result);\n}\n\n/**\n * Resolve the path to a specified module with error handling\n *\n * @param name - The name of the module\n * @param options - The options to use when resolving the module\n * @returns A promise for the path to the module\n */\nexport async function resolveSafe(name: string, options: ResolveOptions = {}) {\n try {\n return await resolve(name, options);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Resolve the path to a specified module with error handling\n *\n * @param name - The name of the module\n * @param options - The options to use when resolving the module\n * @returns The path to the module or undefined\n */\nexport function resolveSafeSync(name: string, options: ResolveOptions = {}) {\n try {\n return resolveSync(name, options);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Import a module from a specified path\n *\n * @param path - The path to the module\n * @returns The module\n */\nexport async function importModule<T = any>(path: string): Promise<T> {\n const i = await import(path);\n\n if (i) {\n return interopDefault(i);\n }\n\n return i;\n}\n\n/**\n * Resolve the path to a specified package asynchronously\n *\n * @remarks\n * This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.\n *\n * @param name - The name of the module\n * @returns A promise for the module or undefined\n */\nexport async function resolvePackage(\n name: string,\n options: ResolveOptions = {}\n) {\n let result = await resolveSafe(joinPaths(name, \"package.json\"), options);\n if (!result) {\n result = await resolveSafe(joinPaths(name, \"index.js\"), options);\n if (!result) {\n result = await resolveSafe(name, options);\n }\n }\n\n return result ? findFilePath(result) : undefined;\n}\n\n/**\n * Resolve the path to a specified package synchronously\n *\n * @remarks\n * This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.\n *\n * @param name - The name of the module\n * @param options - The options to use when resolving the module\n * @returns The module or undefined\n */\nexport function resolvePackageSync(name: string, options: ResolveOptions = {}) {\n let result = resolveSafeSync(joinPaths(name, \"package.json\"), options);\n if (!result) {\n result = resolveSafeSync(joinPaths(name, \"index.js\"), options);\n if (!result) {\n result = resolveSafeSync(name, options);\n }\n }\n\n return result ? findFilePath(result) : undefined;\n}\n"],"mappings":";;;;;;;;;;;;AAkCA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;AA8BD,SAAgB,mBAAmB,QAAkB,EAAE,EAAE;CACvD,IAAI,kBAAkB;AACtB,KAAI,CAAC,gBAAgB,SAAS,KAAK,CAAC,CAClC,iBAAgB,KAAK,KAAK,CAAC;CAG7B,MAAM,gBAAgB,kBAAkB;AACxC,KAAI,CAAC,gBAAgB,SAAS,cAAc,CAC1C,iBAAgB,KAAK,cAAc;AAGrC,mBAAkB,UAChB,gBACG,OAAO,QAAQ,CACf,KAAI,SAAQ,YAAY,KAAK,CAAC,CAC9B,QAAQ,KAAK,MAAM,GAAG,QAAQ;AAC7B,MAAI,KAAK,KAAK;AACd,MAAI,CAAC,eAAe,KAAK,EAAE;AACzB,OAAI,KAAK,eAAe,MAAM,KAAK,CAAC,CAAC;AACrC,OAAI,KAAK,eAAe,MAAM,cAAc,CAAC;AAE7C,OAAI,SAAQ,aAAY;AACtB,QAAI,KAAK,eAAe,MAAM,SAAS,CAAC;KACxC;;AAGJ,SAAO;IACN,EAAE,CAAa,CACrB;AAED,QAAO;;;;;;;;AAST,SAAgB,oBAAoB,QAAkB,EAAE,EAAE;AACxD,QAAO,UACL,MAAM,QAAQ,KAAK,SAAS;AAC1B,MAAIA,iBAAe,KAAK,KAAK,eAC3B,KAAI,KAAK,YAAY,KAAK,CAAC;AAG7B,MAAI,WAAWC,YAAU,MAAM,eAAe,CAAC,CAC7C,KAAI,KAAK,YAAYA,YAAU,MAAM,eAAe,CAAC,CAAC;AAGxD,SAAO;IACN,EAAE,CAAa,CACnB;;;;;;;;;AAmBH,SAAgB,0BACd,MACA,UAAwC,EAAE,EAC1C;CACA,IAAI,QAAQ,QAAQ,qBAChB,mBAAmB,QAAQ,MAAM,G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AAYA,YAAU,MAAM,WAAW,EAAE,QAAQ;AAChE,MAAI,CAAC,OACH,UAAS,MAAM,YAAY,MAAM,QAAQ;;AAI7C,QAAO,SAASE,eAAa,OAAO,GAAG;;;;;;;;;;;;AAazC,SAAgB,mBAAmB,MAAc,UAA0B,EAAE,EAAE;CAC7E,IAAI,SAAS,gBAAgBF,YAAU,MAAM,eAAe,EAAE,QAAQ;AACtE,KAAI,CAAC,QAAQ;AACX,WAAS,gBAAgBA,YAAU,MAAM,WAAW,EAAE,QAAQ;AAC9D,MAAI,CAAC,OACH,UAAS,gBAAgB,MAAM,QAAQ;;AAI3C,QAAO,SAASE,eAAa,OAAO,GAAG"}
@@ -5,19 +5,6 @@ let semver = require("semver");
5
5
  let _stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
6
6
 
7
7
  //#region src/semver-fns.ts
8
- var semver_fns_exports = /* @__PURE__ */ require_runtime.__exportAll({
9
- RELEASE_TYPES: () => RELEASE_TYPES,
10
- coerceVersion: () => coerceVersion,
11
- deriveNewSemverVersion: () => deriveNewSemverVersion,
12
- isRange: () => isRange,
13
- isRelativeVersionKeyword: () => isRelativeVersionKeyword,
14
- isSemver: () => isSemver,
15
- isValidRange: () => isValidRange,
16
- isValidSemver: () => isValidSemver,
17
- isValidVersion: () => isValidVersion,
18
- parseVersion: () => parseVersion,
19
- satisfiesVersion: () => satisfiesVersion
20
- });
21
8
  const RELEASE_TYPES = [
22
9
  "major",
23
10
  "premajor",
@@ -151,10 +138,4 @@ exports.isValidRange = isValidRange;
151
138
  exports.isValidSemver = isValidSemver;
152
139
  exports.isValidVersion = isValidVersion;
153
140
  exports.parseVersion = parseVersion;
154
- exports.satisfiesVersion = satisfiesVersion;
155
- Object.defineProperty(exports, 'semver_fns_exports', {
156
- enumerable: true,
157
- get: function () {
158
- return semver_fns_exports;
159
- }
160
- });
141
+ exports.satisfiesVersion = satisfiesVersion;
@@ -1,22 +1,8 @@
1
- import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
2
1
  import { isString } from "@stryke/type-checks/is-string";
3
2
  import { coerce, inc, parse, satisfies, valid, validRange } from "semver";
4
3
  import { isObject } from "@stryke/type-checks/is-object";
5
4
 
6
5
  //#region src/semver-fns.ts
7
- var semver_fns_exports = /* @__PURE__ */ __exportAll({
8
- RELEASE_TYPES: () => RELEASE_TYPES,
9
- coerceVersion: () => coerceVersion,
10
- deriveNewSemverVersion: () => deriveNewSemverVersion,
11
- isRange: () => isRange,
12
- isRelativeVersionKeyword: () => isRelativeVersionKeyword,
13
- isSemver: () => isSemver,
14
- isValidRange: () => isValidRange,
15
- isValidSemver: () => isValidSemver,
16
- isValidVersion: () => isValidVersion,
17
- parseVersion: () => parseVersion,
18
- satisfiesVersion: () => satisfiesVersion
19
- });
20
6
  const RELEASE_TYPES = [
21
7
  "major",
22
8
  "premajor",
@@ -140,5 +126,5 @@ const deriveNewSemverVersion = (currentSemverVersion, semverSpecifier, preid) =>
140
126
  };
141
127
 
142
128
  //#endregion
143
- export { RELEASE_TYPES, coerceVersion, deriveNewSemverVersion, isRange, isRelativeVersionKeyword, isSemver, isValidRange, isValidSemver, isValidVersion, parseVersion, satisfiesVersion, semver_fns_exports };
129
+ export { RELEASE_TYPES, coerceVersion, deriveNewSemverVersion, isRange, isRelativeVersionKeyword, isSemver, isValidRange, isValidSemver, isValidVersion, parseVersion, satisfiesVersion };
144
130
  //# sourceMappingURL=semver-fns.mjs.map