@kubb/core 5.0.0-alpha.7 → 5.0.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import "./chunk--u3MIqq1.js";
2
- import mod from "node:module";
2
+ import { definePrinter, isOperationNode, isSchemaNode } from "@kubb/ast";
3
+ import path, { basename, dirname, extname, join, posix, relative, resolve } from "node:path";
3
4
  import { EventEmitter } from "node:events";
4
5
  import { parseArgs, styleText } from "node:util";
5
6
  import { readFileSync } from "node:fs";
6
7
  import { access, mkdir, readFile, readdir, rm, writeFile } from "node:fs/promises";
7
- import path, { basename, dirname, extname, join, posix, relative, resolve } from "node:path";
8
- import { definePrinter, isOperationNode, isSchemaNode } from "@kubb/ast";
9
8
  import { createFabric } from "@kubb/react-fabric";
10
9
  import { typescriptParser } from "@kubb/react-fabric/parsers";
11
10
  import { fsPlugin } from "@kubb/react-fabric/plugins";
@@ -13,11 +12,9 @@ import { performance } from "node:perf_hooks";
13
12
  import { deflateSync } from "fflate";
14
13
  import { x } from "tinyexec";
15
14
  import { version } from "node:process";
16
- import os from "node:os";
17
- import { pathToFileURL } from "node:url";
15
+ import { sortBy } from "remeda";
18
16
  import * as pkg from "empathic/package";
19
17
  import { coerce, satisfies } from "semver";
20
- import { sortBy } from "remeda";
21
18
  //#region ../../internals/utils/dist/index.js
22
19
  /** Thrown when a plugin's configuration or input fails validation. */
23
20
  var ValidationPluginError = class extends Error {};
@@ -134,6 +131,21 @@ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
134
131
  } : {}));
135
132
  return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
136
133
  }
134
+ /**
135
+ * Converts `text` to PascalCase.
136
+ * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
137
+ *
138
+ * @example
139
+ * pascalCase('hello-world') // 'HelloWorld'
140
+ * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
141
+ */
142
+ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
143
+ if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
144
+ prefix,
145
+ suffix
146
+ }) : camelCase(part));
147
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
148
+ }
137
149
  /** Returns a `CLIAdapter` with type inference. Pass a different adapter to `createCLI` to swap the CLI engine. */
138
150
  function defineCLIAdapter(adapter) {
139
151
  return adapter;
@@ -383,14 +395,6 @@ async function exists(path) {
383
395
  if (typeof Bun !== "undefined") return Bun.file(path).exists();
384
396
  return access(path).then(() => true, () => false);
385
397
  }
386
- /**
387
- * Reads the file at `path` as a UTF-8 string.
388
- * Uses `Bun.file().text()` when running under Bun, `fs.readFile` otherwise.
389
- */
390
- async function read(path) {
391
- if (typeof Bun !== "undefined") return Bun.file(path).text();
392
- return readFile(path, { encoding: "utf8" });
393
- }
394
398
  /** Synchronous counterpart of `read`. */
395
399
  function readSync(path) {
396
400
  return readFileSync(path, { encoding: "utf8" });
@@ -453,7 +457,7 @@ function isPromiseRejectedResult(result) {
453
457
  * JavaScript and Java reserved words.
454
458
  * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
455
459
  */
456
- const reservedWords = [
460
+ const reservedWords = new Set([
457
461
  "abstract",
458
462
  "arguments",
459
463
  "boolean",
@@ -535,14 +539,14 @@ const reservedWords = [
535
539
  "toString",
536
540
  "undefined",
537
541
  "valueOf"
538
- ];
542
+ ]);
539
543
  /**
540
544
  * Prefixes a word with `_` when it is a reserved JavaScript/Java identifier
541
545
  * or starts with a digit.
542
546
  */
543
547
  function transformReservedWord(word) {
544
548
  const firstChar = word.charCodeAt(0);
545
- if (word && (reservedWords.includes(word) || firstChar >= 48 && firstChar <= 57)) return `_${word}`;
549
+ if (word && (reservedWords.has(word) || firstChar >= 48 && firstChar <= 57)) return `_${word}`;
546
550
  return word;
547
551
  }
548
552
  /**
@@ -674,7 +678,6 @@ const DEFAULT_STUDIO_URL = "https://studio.kubb.dev";
674
678
  const BARREL_FILENAME = "index.ts";
675
679
  const DEFAULT_BANNER = "simple";
676
680
  const DEFAULT_EXTENSION = { ".ts": ".ts" };
677
- const PATH_SEPARATORS = ["/", "\\"];
678
681
  const logLevel = {
679
682
  silent: Number.NEGATIVE_INFINITY,
680
683
  error: 0,
@@ -1337,19 +1340,12 @@ var PluginDriver = class {
1337
1340
  }
1338
1341
  };
1339
1342
  //#endregion
1340
- //#region src/defineStorage.ts
1343
+ //#region src/createStorage.ts
1341
1344
  /**
1342
- * Wraps a storage builder so the `options` argument is optional, following the
1343
- * same factory pattern as `definePlugin`, `defineLogger`, and `defineAdapter`.
1344
- *
1345
- * The builder receives the resolved options object and must return a
1346
- * `DefineStorage`-compatible object that includes a `name` string.
1345
+ * Creates a storage factory. Call the returned function with optional options to get the storage instance.
1347
1346
  *
1348
1347
  * @example
1349
- * ```ts
1350
- * import { defineStorage } from '@kubb/core'
1351
- *
1352
- * export const memoryStorage = defineStorage((_options) => {
1348
+ * export const memoryStorage = createStorage(() => {
1353
1349
  * const store = new Map<string, string>()
1354
1350
  * return {
1355
1351
  * name: 'memory',
@@ -1357,13 +1353,15 @@ var PluginDriver = class {
1357
1353
  * async getItem(key) { return store.get(key) ?? null },
1358
1354
  * async setItem(key, value) { store.set(key, value) },
1359
1355
  * async removeItem(key) { store.delete(key) },
1360
- * async getKeys() { return [...store.keys()] },
1361
- * async clear() { store.clear() },
1356
+ * async getKeys(base) {
1357
+ * const keys = [...store.keys()]
1358
+ * return base ? keys.filter((k) => k.startsWith(base)) : keys
1359
+ * },
1360
+ * async clear(base) { if (!base) store.clear() },
1362
1361
  * }
1363
1362
  * })
1364
- * ```
1365
1363
  */
1366
- function defineStorage(build) {
1364
+ function createStorage(build) {
1367
1365
  return (options) => build(options ?? {});
1368
1366
  }
1369
1367
  //#endregion
@@ -1391,7 +1389,7 @@ function defineStorage(build) {
1391
1389
  * })
1392
1390
  * ```
1393
1391
  */
1394
- const fsStorage = defineStorage(() => ({
1392
+ const fsStorage = createStorage(() => ({
1395
1393
  name: "fs",
1396
1394
  async hasItem(key) {
1397
1395
  try {
@@ -1439,7 +1437,7 @@ const fsStorage = defineStorage(() => ({
1439
1437
  }));
1440
1438
  //#endregion
1441
1439
  //#region package.json
1442
- var version$1 = "5.0.0-alpha.7";
1440
+ var version$1 = "5.0.0-alpha.9";
1443
1441
  //#endregion
1444
1442
  //#region src/utils/diagnostics.ts
1445
1443
  /**
@@ -1752,23 +1750,44 @@ function inputToAdapterSource(config) {
1752
1750
  };
1753
1751
  }
1754
1752
  //#endregion
1755
- //#region src/defineAdapter.ts
1753
+ //#region src/createAdapter.ts
1756
1754
  /**
1757
- * Wraps an adapter builder to make the options parameter optional.
1755
+ * Creates an adapter factory. Call the returned function with optional options to get the adapter instance.
1758
1756
  *
1759
1757
  * @example
1760
- * ```ts
1761
- * export const adapterOas = defineAdapter<OasAdapter>((options) => {
1762
- * const { validate = true, dateType = 'string' } = options
1758
+ * export const myAdapter = createAdapter<MyAdapter>((options) => {
1763
1759
  * return {
1764
- * name: adapterOasName,
1765
- * options: { validate, dateType, ... },
1766
- * parse(source) { ... },
1760
+ * name: 'my-adapter',
1761
+ * options,
1762
+ * async parse(source) { ... },
1767
1763
  * }
1768
1764
  * })
1769
- * ```
1765
+ *
1766
+ * // instantiate
1767
+ * const adapter = myAdapter({ validate: true })
1768
+ */
1769
+ function createAdapter(build) {
1770
+ return (options) => build(options ?? {});
1771
+ }
1772
+ //#endregion
1773
+ //#region src/createPlugin.ts
1774
+ /**
1775
+ * Creates a plugin factory. Call the returned function with optional options to get the plugin instance.
1776
+ *
1777
+ * @example
1778
+ * export const myPlugin = createPlugin<MyPlugin>((options) => {
1779
+ * return {
1780
+ * name: 'my-plugin',
1781
+ * options,
1782
+ * resolvePath(baseName) { ... },
1783
+ * resolveName(name, type) { ... },
1784
+ * }
1785
+ * })
1786
+ *
1787
+ * // instantiate
1788
+ * const plugin = myPlugin({ output: { path: 'src/gen' } })
1770
1789
  */
1771
- function defineAdapter(build) {
1790
+ function createPlugin(build) {
1772
1791
  return (options) => build(options ?? {});
1773
1792
  }
1774
1793
  //#endregion
@@ -1803,100 +1822,106 @@ function defineGenerator(generator) {
1803
1822
  }
1804
1823
  //#endregion
1805
1824
  //#region src/defineLogger.ts
1825
+ /**
1826
+ * Wraps a logger definition into a typed {@link Logger}.
1827
+ *
1828
+ * @example
1829
+ * export const myLogger = defineLogger({
1830
+ * name: 'my-logger',
1831
+ * install(context, options) {
1832
+ * context.on('info', (message) => console.log('ℹ', message))
1833
+ * context.on('error', (error) => console.error('✗', error.message))
1834
+ * },
1835
+ * })
1836
+ */
1806
1837
  function defineLogger(logger) {
1807
- return { ...logger };
1838
+ return logger;
1808
1839
  }
1809
1840
  //#endregion
1810
- //#region src/definePlugin.ts
1841
+ //#region src/defineResolver.ts
1811
1842
  /**
1812
- * Wraps a plugin builder to make the options parameter optional.
1843
+ * Checks if an operation matches a pattern for a given filter type (`tag`, `operationId`, `path`, `method`).
1813
1844
  */
1814
- function definePlugin(build) {
1815
- return (options) => build(options ?? {});
1845
+ function matchesOperationPattern(node, type, pattern) {
1846
+ switch (type) {
1847
+ case "tag": return node.tags.some((tag) => !!tag.match(pattern));
1848
+ case "operationId": return !!node.operationId.match(pattern);
1849
+ case "path": return !!node.path.match(pattern);
1850
+ case "method": return !!node.method.toLowerCase().match(pattern);
1851
+ default: return false;
1852
+ }
1816
1853
  }
1817
- //#endregion
1818
- //#region src/PackageManager.ts
1819
- var PackageManager = class PackageManager {
1820
- static #cache = {};
1821
- #cwd;
1822
- constructor(workspace) {
1823
- if (workspace) this.#cwd = workspace;
1824
- }
1825
- set workspace(workspace) {
1826
- this.#cwd = workspace;
1827
- }
1828
- get workspace() {
1829
- return this.#cwd;
1830
- }
1831
- normalizeDirectory(directory) {
1832
- const lastChar = directory[directory.length - 1];
1833
- if (lastChar && !PATH_SEPARATORS.includes(lastChar)) return `${directory}/`;
1834
- return directory;
1835
- }
1836
- getLocation(path) {
1837
- let location = path;
1838
- if (this.#cwd) location = mod.createRequire(this.normalizeDirectory(this.#cwd)).resolve(path);
1839
- return location;
1840
- }
1841
- async import(path) {
1842
- let location = this.getLocation(path);
1843
- if (os.platform() === "win32") location = pathToFileURL(location).href;
1844
- const module = await import(location);
1845
- return module?.default ?? module;
1846
- }
1847
- async getPackageJSON() {
1848
- const pkgPath = pkg.up({ cwd: this.#cwd });
1849
- if (!pkgPath) return;
1850
- const json = await read(pkgPath);
1851
- return JSON.parse(json);
1852
- }
1853
- getPackageJSONSync() {
1854
- const pkgPath = pkg.up({ cwd: this.#cwd });
1855
- if (!pkgPath) return;
1856
- const json = readSync(pkgPath);
1857
- return JSON.parse(json);
1858
- }
1859
- static setVersion(dependency, version) {
1860
- PackageManager.#cache[dependency] = version;
1861
- }
1862
- #match(packageJSON, dependency) {
1863
- const dependencies = {
1864
- ...packageJSON.dependencies || {},
1865
- ...packageJSON.devDependencies || {}
1854
+ /**
1855
+ * Checks if a schema matches a pattern for a given filter type (`schemaName`).
1856
+ * Returns `null` when the filter type doesn't apply to schemas.
1857
+ */
1858
+ function matchesSchemaPattern(node, type, pattern) {
1859
+ switch (type) {
1860
+ case "schemaName": return node.name ? !!node.name.match(pattern) : false;
1861
+ default: return null;
1862
+ }
1863
+ }
1864
+ /**
1865
+ * Default name resolver — `camelCase` for most types, `PascalCase` for `type`.
1866
+ */
1867
+ function defaultResolver(name, type) {
1868
+ let resolvedName = camelCase(name);
1869
+ if (type === "file" || type === "function") resolvedName = camelCase(name, { isFile: type === "file" });
1870
+ if (type === "type") resolvedName = pascalCase(name);
1871
+ return resolvedName;
1872
+ }
1873
+ /**
1874
+ * Default option resolver — applies include/exclude filters and merges any matching override options.
1875
+ * Returns `null` when the node is filtered out.
1876
+ */
1877
+ function defaultResolveOptions(node, { options, exclude = [], include, override = [] }) {
1878
+ if (isOperationNode(node)) {
1879
+ if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
1880
+ if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
1881
+ const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options;
1882
+ return {
1883
+ ...options,
1884
+ ...overrideOptions
1866
1885
  };
1867
- if (typeof dependency === "string" && dependencies[dependency]) return dependencies[dependency];
1868
- const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
1869
- return matchedDependency ? dependencies[matchedDependency] : void 0;
1870
- }
1871
- async getVersion(dependency) {
1872
- if (typeof dependency === "string" && PackageManager.#cache[dependency]) return PackageManager.#cache[dependency];
1873
- const packageJSON = await this.getPackageJSON();
1874
- if (!packageJSON) return;
1875
- return this.#match(packageJSON, dependency);
1876
- }
1877
- getVersionSync(dependency) {
1878
- if (typeof dependency === "string" && PackageManager.#cache[dependency]) return PackageManager.#cache[dependency];
1879
- const packageJSON = this.getPackageJSONSync();
1880
- if (!packageJSON) return;
1881
- return this.#match(packageJSON, dependency);
1882
- }
1883
- async isValid(dependency, version) {
1884
- const packageVersion = await this.getVersion(dependency);
1885
- if (!packageVersion) return false;
1886
- if (packageVersion === version) return true;
1887
- const semVer = coerce(packageVersion);
1888
- if (!semVer) return false;
1889
- return satisfies(semVer, version);
1890
- }
1891
- isValidSync(dependency, version) {
1892
- const packageVersion = this.getVersionSync(dependency);
1893
- if (!packageVersion) return false;
1894
- if (packageVersion === version) return true;
1895
- const semVer = coerce(packageVersion);
1896
- if (!semVer) return false;
1897
- return satisfies(semVer, version);
1898
1886
  }
1899
- };
1887
+ if (isSchemaNode(node)) {
1888
+ if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) return null;
1889
+ if (include) {
1890
+ const applicable = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern)).filter((r) => r !== null);
1891
+ if (applicable.length > 0 && !applicable.includes(true)) return null;
1892
+ }
1893
+ const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options;
1894
+ return {
1895
+ ...options,
1896
+ ...overrideOptions
1897
+ };
1898
+ }
1899
+ return options;
1900
+ }
1901
+ /**
1902
+ * Defines a resolver for a plugin, with built-in defaults for name casing and include/exclude/override filtering.
1903
+ * Override `default` or `resolveOptions` in the builder to customize the behavior.
1904
+ *
1905
+ * @example
1906
+ * export const resolver = defineResolver<PluginTs>(() => ({
1907
+ * resolveName(name) {
1908
+ * return this.default(name, 'function')
1909
+ * },
1910
+ * resolveTypedName(name) {
1911
+ * return this.default(name, 'type')
1912
+ * },
1913
+ * resolveParamName(node, param) {
1914
+ * return this.resolveName(`${node.operationId} ${param.in} ${param.name}`)
1915
+ * },
1916
+ * }))
1917
+ */
1918
+ function defineResolver(build) {
1919
+ return {
1920
+ default: defaultResolver,
1921
+ resolveOptions: defaultResolveOptions,
1922
+ ...build()
1923
+ };
1924
+ }
1900
1925
  //#endregion
1901
1926
  //#region src/storages/memoryStorage.ts
1902
1927
  /**
@@ -1916,7 +1941,7 @@ var PackageManager = class PackageManager {
1916
1941
  * })
1917
1942
  * ```
1918
1943
  */
1919
- const memoryStorage = defineStorage(() => {
1944
+ const memoryStorage = createStorage(() => {
1920
1945
  const store = /* @__PURE__ */ new Map();
1921
1946
  return {
1922
1947
  name: "memory",
@@ -2062,11 +2087,12 @@ async function isFormatterAvailable(formatter) {
2062
2087
  * ```
2063
2088
  */
2064
2089
  async function detectFormatter() {
2065
- for (const formatter of [
2090
+ const formatterNames = new Set([
2066
2091
  "biome",
2067
2092
  "oxfmt",
2068
2093
  "prettier"
2069
- ]) if (await isFormatterAvailable(formatter)) return formatter;
2094
+ ]);
2095
+ for (const formatter of formatterNames) if (await isFormatterAvailable(formatter)) return formatter;
2070
2096
  }
2071
2097
  //#endregion
2072
2098
  //#region src/utils/TreeNode.ts
@@ -2258,35 +2284,13 @@ async function getBarrelFiles(files, { type, meta = {}, root, output }) {
2258
2284
  });
2259
2285
  }
2260
2286
  //#endregion
2261
- //#region src/utils/getPlugins.ts
2262
- function isJSONPlugins(plugins) {
2263
- return Array.isArray(plugins) && plugins.some((plugin) => Array.isArray(plugin) && typeof plugin[0] === "string");
2264
- }
2265
- function isObjectPlugins(plugins) {
2266
- return plugins instanceof Object && !Array.isArray(plugins);
2267
- }
2268
- function getPlugins(plugins) {
2269
- if (isObjectPlugins(plugins)) throw new Error("Object plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
2270
- if (isJSONPlugins(plugins)) throw new Error("JSON plugins are not supported anymore, best to use http://kubb.dev/getting-started/configure#json");
2271
- return Promise.resolve(plugins);
2272
- }
2273
- //#endregion
2274
2287
  //#region src/utils/getConfigs.ts
2275
2288
  /**
2276
2289
  * Converting UserConfig to Config Array without a change in the object beside the JSON convert.
2277
2290
  */
2278
2291
  async function getConfigs(config, args) {
2279
- let userConfigs = await (typeof config === "function" ? Promise.resolve(config(args)) : Promise.resolve(config));
2280
- if (!Array.isArray(userConfigs)) userConfigs = [userConfigs];
2281
- const results = [];
2282
- for (const item of userConfigs) {
2283
- const plugins = item.plugins ? await getPlugins(item.plugins) : void 0;
2284
- results.push({
2285
- ...item,
2286
- plugins
2287
- });
2288
- }
2289
- return results;
2292
+ const resolved = await (typeof config === "function" ? config(args) : config);
2293
+ return (Array.isArray(resolved) ? resolved : [resolved]).map((item) => ({ ...item }));
2290
2294
  }
2291
2295
  //#endregion
2292
2296
  //#region src/utils/linters.ts
@@ -2299,68 +2303,42 @@ async function isLinterAvailable(linter) {
2299
2303
  }
2300
2304
  }
2301
2305
  async function detectLinter() {
2302
- for (const linter of [
2306
+ const linterNames = new Set([
2303
2307
  "biome",
2304
2308
  "oxlint",
2305
2309
  "eslint"
2306
- ]) if (await isLinterAvailable(linter)) return linter;
2310
+ ]);
2311
+ for (const linter of linterNames) if (await isLinterAvailable(linter)) return linter;
2307
2312
  }
2308
2313
  //#endregion
2309
- //#region src/utils/resolveOptions.ts
2310
- function matchesOperationPattern(node, type, pattern) {
2311
- switch (type) {
2312
- case "tag": return node.tags.some((tag) => !!tag.match(pattern));
2313
- case "operationId": return !!node.operationId.match(pattern);
2314
- case "path": return !!node.path.match(pattern);
2315
- case "method": return !!node.method.toLowerCase().match(pattern);
2316
- default: return false;
2317
- }
2318
- }
2319
- function matchesSchemaPattern(node, type, pattern) {
2320
- switch (type) {
2321
- case "schemaName": return node.name ? !!node.name.match(pattern) : false;
2322
- default: return null;
2323
- }
2324
- }
2325
- /**
2326
- * Resolves the effective plugin options for a given AST node by applying
2327
- * `exclude`, `include`, and `override` rules from the plugin configuration.
2328
- *
2329
- * Returns `null` when the node is excluded or not matched by `include`.
2330
- * Returns the merged options (base options merged with any matching `override`) otherwise.
2331
- *
2332
- * Supported filter types for `OperationNode`: `tag`, `operationId`, `path`, `method`.
2333
- * Supported filter types for `SchemaNode`: `schemaName`.
2334
- *
2335
- * @example
2336
- * const resolved = resolveOptions(operationNode, { options, exclude, include, override })
2337
- * if (!resolved) return // excluded
2338
- */
2339
- function resolveOptions(node, { options, exclude = [], include, override = [] }) {
2340
- if (isOperationNode(node)) {
2341
- if (exclude.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
2342
- if (include && !include.some(({ type, pattern }) => matchesOperationPattern(node, type, pattern))) return null;
2343
- const overrideOptions = override.find(({ type, pattern }) => matchesOperationPattern(node, type, pattern))?.options;
2344
- return {
2345
- ...options,
2346
- ...overrideOptions
2347
- };
2348
- }
2349
- if (isSchemaNode(node)) {
2350
- if (exclude.some(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)) return null;
2351
- if (include) {
2352
- const applicable = include.map(({ type, pattern }) => matchesSchemaPattern(node, type, pattern)).filter((r) => r !== null);
2353
- if (applicable.length > 0 && !applicable.includes(true)) return null;
2354
- }
2355
- const overrideOptions = override.find(({ type, pattern }) => matchesSchemaPattern(node, type, pattern) === true)?.options;
2356
- return {
2357
- ...options,
2358
- ...overrideOptions
2359
- };
2360
- }
2361
- return options;
2314
+ //#region src/utils/packageJSON.ts
2315
+ function getPackageJSONSync(cwd) {
2316
+ const pkgPath = pkg.up({ cwd });
2317
+ if (!pkgPath) return;
2318
+ return JSON.parse(readSync(pkgPath));
2319
+ }
2320
+ function match(packageJSON, dependency) {
2321
+ const dependencies = {
2322
+ ...packageJSON.dependencies || {},
2323
+ ...packageJSON.devDependencies || {}
2324
+ };
2325
+ if (typeof dependency === "string" && dependencies[dependency]) return dependencies[dependency];
2326
+ const matched = Object.keys(dependencies).find((dep) => dep.match(dependency));
2327
+ return matched ? dependencies[matched] : void 0;
2328
+ }
2329
+ function getVersionSync(dependency, cwd) {
2330
+ const packageJSON = getPackageJSONSync(cwd);
2331
+ return packageJSON ? match(packageJSON, dependency) : void 0;
2332
+ }
2333
+ function satisfiesDependency(dependency, version, cwd) {
2334
+ const packageVersion = getVersionSync(dependency, cwd);
2335
+ if (!packageVersion) return false;
2336
+ if (packageVersion === version) return true;
2337
+ const semVer = coerce(packageVersion);
2338
+ if (!semVer) return false;
2339
+ return satisfies(semVer, version);
2362
2340
  }
2363
2341
  //#endregion
2364
- export { AsyncEventEmitter, FunctionParams, PackageManager, PluginDriver, URLPath, build, build as default, defineAdapter, defineConfig, defineGenerator, defineLogger, definePlugin, definePrinter, defineStorage, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, memoryStorage, resolveOptions, safeBuild, setup };
2342
+ export { FunctionParams, PluginDriver, build, build as default, createAdapter, createPlugin, createStorage, defaultResolveOptions, defineConfig, defineGenerator, defineLogger, definePrinter, defineResolver, detectFormatter, detectLinter, formatters, fsStorage, getBarrelFiles, getConfigs, getMode, isInputPath, linters, logLevel, memoryStorage, safeBuild, satisfiesDependency, setup };
2365
2343
 
2366
2344
  //# sourceMappingURL=index.js.map