@eslint-react/shared 1.20.1-next.1 → 1.20.1

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.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ESLintUtils } from '@typescript-eslint/utils';
2
+ import { E } from '@eslint-react/tools';
2
3
 
3
4
  /**
4
5
  * The NPM scope for this project.
@@ -51,7 +52,7 @@ declare const REACT_BUILD_IN_HOOKS: readonly ["use", "useActionState", "useCallb
51
52
  */
52
53
  declare const createRuleForPlugin: (pluginName: string) => <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, unknown>>) => ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
53
54
 
54
- declare function getReactVersion(at?: string, fallback?: string): string;
55
+ declare function getReactVersion(at?: string): E.Either<string, unknown>;
55
56
 
56
57
  /**
57
58
  * Schema with pipe type.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ESLintUtils } from '@typescript-eslint/utils';
2
+ import { E } from '@eslint-react/tools';
2
3
 
3
4
  /**
4
5
  * The NPM scope for this project.
@@ -51,7 +52,7 @@ declare const REACT_BUILD_IN_HOOKS: readonly ["use", "useActionState", "useCallb
51
52
  */
52
53
  declare const createRuleForPlugin: (pluginName: string) => <Options extends readonly unknown[], MessageIds extends string>({ meta, name, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<Options, MessageIds, unknown>>) => ESLintUtils.RuleModule<MessageIds, Options, unknown, ESLintUtils.RuleListener>;
53
54
 
54
- declare function getReactVersion(at?: string, fallback?: string): string;
55
+ declare function getReactVersion(at?: string): E.Either<string, unknown>;
55
56
 
56
57
  /**
57
58
  * Schema with pipe type.
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var utils = require('@typescript-eslint/utils');
4
- var module$1 = require('module');
5
4
  var tools = require('@eslint-react/tools');
6
- var pm = require('picomatch');
7
5
  var tsPattern = require('ts-pattern');
6
+ var module$1 = require('module');
7
+ var pm = require('picomatch');
8
8
 
9
9
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
10
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -219,18 +219,24 @@ var getDocsUrl = (pluginName) => (ruleName) => {
219
219
  return `${WEBSITE_URL}/docs/rules/${pluginName}-${ruleName}`;
220
220
  };
221
221
  var createRuleForPlugin = (pluginName) => utils.ESLintUtils.RuleCreator(getDocsUrl(pluginName));
222
- function getReactVersion(at = (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)), fallback = "19.0.0") {
222
+ function tryRequire(id, at = (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))) {
223
223
  const _require = module__default.default.createRequire(at);
224
224
  try {
225
- const version = _require("react")?.version;
226
- if (typeof version !== "string") throw new Error("Failed to read version from 'react' package");
227
- return version;
225
+ return tools.E.right(_require(id));
228
226
  } catch {
229
- console.warn(`Failed to detect React version from dependencies. Using fallback: ${fallback}`);
230
- return fallback;
227
+ return tools.E.left(new Error(`Module '${id}' not found`));
231
228
  }
232
229
  }
233
230
 
231
+ // src/get-react-version.ts
232
+ function getReactVersion(at = (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))) {
233
+ return tools.F.pipe(
234
+ tryRequire("react", at),
235
+ tools.E.filterOrLeft(tsPattern.isMatching({ version: tsPattern.P.string }), tools.F.identity),
236
+ tools.E.map((mod) => mod.version)
237
+ );
238
+ }
239
+
234
240
  // ../../node_modules/.pnpm/valibot@1.0.0-beta.9_typescript@5.7.2/node_modules/valibot/dist/index.js
235
241
  var store;
236
242
  function getGlobalConfig(config2) {
@@ -1374,7 +1380,7 @@ var normalizeSettings = createMemoizedFunction((settings) => {
1374
1380
  if (!/^[\w-]+$/u.test(name)) return acc;
1375
1381
  return acc.set(name, as);
1376
1382
  }, /* @__PURE__ */ new Map()),
1377
- version: tsPattern.match(settings.version).with(tsPattern.P.union(tsPattern.P.nullish, "", "detect"), () => getReactVersion()).otherwise(tools.F.identity)
1383
+ version: tsPattern.match(settings.version).with(tsPattern.P.union(tsPattern.P.nullish, "", "detect"), () => tools.E.getOrElse(getReactVersion(), tools.F.constant("19.0.0"))).otherwise(tools.F.identity)
1378
1384
  };
1379
1385
  }, { isEqual: shallowEqual });
1380
1386
  var defineSettings = tools.F.identity;
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ESLintUtils } from '@typescript-eslint/utils';
2
+ import { F, E } from '@eslint-react/tools';
3
+ import { isMatching, P, match } from 'ts-pattern';
2
4
  import module from 'node:module';
3
- import { F } from '@eslint-react/tools';
4
5
  import pm from 'picomatch';
5
- import { match, P } from 'ts-pattern';
6
6
 
7
7
  // src/constants.ts
8
8
  var NPM_SCOPE = "@eslint-react";
@@ -211,18 +211,24 @@ var getDocsUrl = (pluginName) => (ruleName) => {
211
211
  return `${WEBSITE_URL}/docs/rules/${pluginName}-${ruleName}`;
212
212
  };
213
213
  var createRuleForPlugin = (pluginName) => ESLintUtils.RuleCreator(getDocsUrl(pluginName));
214
- function getReactVersion(at = import.meta.url, fallback = "19.0.0") {
214
+ function tryRequire(id, at = import.meta.url) {
215
215
  const _require = module.createRequire(at);
216
216
  try {
217
- const version = _require("react")?.version;
218
- if (typeof version !== "string") throw new Error("Failed to read version from 'react' package");
219
- return version;
217
+ return E.right(_require(id));
220
218
  } catch {
221
- console.warn(`Failed to detect React version from dependencies. Using fallback: ${fallback}`);
222
- return fallback;
219
+ return E.left(new Error(`Module '${id}' not found`));
223
220
  }
224
221
  }
225
222
 
223
+ // src/get-react-version.ts
224
+ function getReactVersion(at = import.meta.url) {
225
+ return F.pipe(
226
+ tryRequire("react", at),
227
+ E.filterOrLeft(isMatching({ version: P.string }), F.identity),
228
+ E.map((mod) => mod.version)
229
+ );
230
+ }
231
+
226
232
  // ../../node_modules/.pnpm/valibot@1.0.0-beta.9_typescript@5.7.2/node_modules/valibot/dist/index.js
227
233
  var store;
228
234
  function getGlobalConfig(config2) {
@@ -1366,7 +1372,7 @@ var normalizeSettings = createMemoizedFunction((settings) => {
1366
1372
  if (!/^[\w-]+$/u.test(name)) return acc;
1367
1373
  return acc.set(name, as);
1368
1374
  }, /* @__PURE__ */ new Map()),
1369
- version: match(settings.version).with(P.union(P.nullish, "", "detect"), () => getReactVersion()).otherwise(F.identity)
1375
+ version: match(settings.version).with(P.union(P.nullish, "", "detect"), () => E.getOrElse(getReactVersion(), F.constant("19.0.0"))).otherwise(F.identity)
1370
1376
  };
1371
1377
  }, { isEqual: shallowEqual });
1372
1378
  var defineSettings = F.identity;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/shared",
3
- "version": "1.20.1-next.1",
3
+ "version": "1.20.1",
4
4
  "description": "ESLint React's Shared constants and functions.",
5
5
  "homepage": "https://github.com/rel1cx/eslint-react",
6
6
  "bugs": {
@@ -38,7 +38,7 @@
38
38
  "@typescript-eslint/utils": "^8.18.1",
39
39
  "picomatch": "^4.0.2",
40
40
  "ts-pattern": "^5.6.0",
41
- "@eslint-react/tools": "1.20.1-next.1"
41
+ "@eslint-react/tools": "1.20.1"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/picomatch": "^3.0.1",