@react-analyzer/shared 0.0.6 → 0.0.8

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.ts CHANGED
@@ -3,15 +3,35 @@ import { ReportDescriptor } from "tsl";
3
3
 
4
4
  //#region src/_id.d.ts
5
5
  /**
6
- * @internal
7
- */
8
- declare const getId: () => string;
6
+ * A generator for unique ids.
7
+ */
8
+ declare class IdGenerator {
9
+ private n;
10
+ private prefix;
11
+ /**
12
+ * @param prefix Optional. A prefix of generated ids.
13
+ */
14
+ constructor(prefix?: string);
15
+ /**
16
+ * Generates an id.
17
+ * @returns A generated id.
18
+ */
19
+ next(): string;
20
+ }
9
21
  //#endregion
10
- //#region src/_require.d.ts
11
- /**
12
- * @internal
13
- */
14
- declare const _require: NodeJS.Require;
22
+ //#region src/analyzer-options.d.ts
23
+ interface AnalyzerOptions {
24
+ version: string;
25
+ }
26
+ declare const DEFAULT_ANALYZER_OPTIONS: {
27
+ readonly version: "19.2.0";
28
+ };
29
+ declare function getAnalyzerOptions(): AnalyzerOptions;
30
+ //#endregion
31
+ //#region src/command-line-options.d.ts
32
+ declare function getCommandLineOptions(): {
33
+ project?: string;
34
+ };
15
35
  //#endregion
16
36
  //#region src/constants.d.ts
17
37
  /**
@@ -96,21 +116,7 @@ declare const RE_COMPONENT_NAME_LOOSE: RegExp;
96
116
  */
97
117
  declare const RE_HOOK_NAME: RegExp;
98
118
  //#endregion
99
- //#region src/get-analyzer-options.d.ts
100
- interface AnalyzerOptions {
101
- version: string;
102
- }
103
- declare const DEFAULT_ANALYZER_OPTIONS: {
104
- readonly version: "19.1.0";
105
- };
106
- declare function getAnalyzerOptions(): AnalyzerOptions;
107
- //#endregion
108
- //#region src/get-command-line-options.d.ts
109
- declare function getCommandLineOptions(): {
110
- project?: string;
111
- };
112
- //#endregion
113
- //#region src/get-react-version.d.ts
119
+ //#region src/react-version.d.ts
114
120
  declare function getReactVersion(fallback: string): string;
115
121
  //#endregion
116
122
  //#region src/regexp.d.ts
@@ -138,4 +144,4 @@ interface Context {
138
144
  }
139
145
  declare function report(ctx: Context, descriptor: unit | null | ReportDescriptor): void;
140
146
  //#endregion
141
- export { AnalyzerOptions, DEFAULT_ANALYZER_OPTIONS, GITHUB_URL, NPM_SCOPE, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_CAMEL_CASE, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_CONSTANT_CASE, RE_HOOK_NAME, RE_HTML_TAG, RE_JAVASCRIPT_PROTOCOL, RE_JS_EXT, RE_JS_IDENTIFIER, RE_KEBAB_CASE, RE_PASCAL_CASE, RE_REGEXP_STR, RE_SNAKE_CASE, RE_TS_EXT, WEBSITE_URL, _require, getAnalyzerOptions, getCommandLineOptions, getId, getReactVersion, isRegExp, report, toRegExp };
147
+ export { AnalyzerOptions, DEFAULT_ANALYZER_OPTIONS, GITHUB_URL, IdGenerator, NPM_SCOPE, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_CAMEL_CASE, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_CONSTANT_CASE, RE_HOOK_NAME, RE_HTML_TAG, RE_JAVASCRIPT_PROTOCOL, RE_JS_EXT, RE_JS_IDENTIFIER, RE_KEBAB_CASE, RE_PASCAL_CASE, RE_REGEXP_STR, RE_SNAKE_CASE, RE_TS_EXT, WEBSITE_URL, getAnalyzerOptions, getCommandLineOptions, getReactVersion, isRegExp, report, toRegExp };
package/dist/index.js CHANGED
@@ -1,23 +1,55 @@
1
1
  import module from "node:module";
2
- import path from "node:path";
3
2
  import { identity, unit } from "@let/eff";
4
3
  import { getTsconfig } from "get-tsconfig";
5
4
  import { P, match } from "ts-pattern";
6
5
  import { parseArgs } from "node:util";
6
+ import path from "node:path";
7
7
 
8
8
  //#region src/_id.ts
9
- let id = 0n;
10
9
  /**
11
- * @internal
12
- */
13
- const getId = () => (id++).toString();
10
+ * A generator for unique ids.
11
+ */
12
+ var IdGenerator = class {
13
+ n;
14
+ prefix;
15
+ /**
16
+ * @param prefix Optional. A prefix of generated ids.
17
+ */
18
+ constructor(prefix = "id_") {
19
+ this.prefix = prefix;
20
+ this.n = 0n;
21
+ }
22
+ /**
23
+ * Generates an id.
24
+ * @returns A generated id.
25
+ */
26
+ next() {
27
+ this.n = 1n + this.n;
28
+ return this.prefix + this.n.toString(16);
29
+ }
30
+ };
14
31
 
15
32
  //#endregion
16
- //#region src/_require.ts
17
- /**
18
- * @internal
19
- */
20
- const _require = module.createRequire(process.cwd() + path.sep);
33
+ //#region src/command-line-options.ts
34
+ function getCommandLineOptions() {
35
+ const { values } = parseArgs({ options: { project: {
36
+ type: "string",
37
+ short: "p"
38
+ } } });
39
+ return values;
40
+ }
41
+
42
+ //#endregion
43
+ //#region src/analyzer-options.ts
44
+ const DEFAULT_ANALYZER_OPTIONS = { version: "19.2.0" };
45
+ function getAnalyzerOptions() {
46
+ const { project = "tsconfig.json" } = getCommandLineOptions();
47
+ const options = getTsconfig(project)?.config["react"];
48
+ return {
49
+ ...DEFAULT_ANALYZER_OPTIONS,
50
+ ...match(options).with({ version: P.string }, identity).otherwise(() => ({}))
51
+ };
52
+ }
21
53
 
22
54
  //#endregion
23
55
  //#region src/constants.ts
@@ -104,29 +136,8 @@ const RE_COMPONENT_NAME_LOOSE = /^_?[A-Z]/u;
104
136
  const RE_HOOK_NAME = /^use/u;
105
137
 
106
138
  //#endregion
107
- //#region src/get-command-line-options.ts
108
- function getCommandLineOptions() {
109
- const { values } = parseArgs({ options: { project: {
110
- type: "string",
111
- short: "p"
112
- } } });
113
- return values;
114
- }
115
-
116
- //#endregion
117
- //#region src/get-analyzer-options.ts
118
- const DEFAULT_ANALYZER_OPTIONS = { version: "19.1.0" };
119
- function getAnalyzerOptions() {
120
- const { project = "tsconfig.json" } = getCommandLineOptions();
121
- const options = getTsconfig(project)?.config["react"];
122
- return {
123
- ...DEFAULT_ANALYZER_OPTIONS,
124
- ...match(options).with({ version: P.string }, identity).otherwise(() => ({}))
125
- };
126
- }
127
-
128
- //#endregion
129
- //#region src/get-react-version.ts
139
+ //#region src/react-version.ts
140
+ const _require = module.createRequire(process.cwd() + path.sep);
130
141
  function getReactVersion(fallback) {
131
142
  try {
132
143
  return match(_require("react")).with({ version: P.select(P.string) }, identity).otherwise(() => fallback);
@@ -167,4 +178,4 @@ function report(ctx, descriptor) {
167
178
  }
168
179
 
169
180
  //#endregion
170
- export { DEFAULT_ANALYZER_OPTIONS, GITHUB_URL, NPM_SCOPE, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_CAMEL_CASE, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_CONSTANT_CASE, RE_HOOK_NAME, RE_HTML_TAG, RE_JAVASCRIPT_PROTOCOL, RE_JS_EXT, RE_JS_IDENTIFIER, RE_KEBAB_CASE, RE_PASCAL_CASE, RE_REGEXP_STR, RE_SNAKE_CASE, RE_TS_EXT, WEBSITE_URL, _require, getAnalyzerOptions, getCommandLineOptions, getId, getReactVersion, isRegExp, report, toRegExp };
181
+ export { DEFAULT_ANALYZER_OPTIONS, GITHUB_URL, IdGenerator, NPM_SCOPE, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_CAMEL_CASE, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_CONSTANT_CASE, RE_HOOK_NAME, RE_HTML_TAG, RE_JAVASCRIPT_PROTOCOL, RE_JS_EXT, RE_JS_IDENTIFIER, RE_KEBAB_CASE, RE_PASCAL_CASE, RE_REGEXP_STR, RE_SNAKE_CASE, RE_TS_EXT, WEBSITE_URL, getAnalyzerOptions, getCommandLineOptions, getReactVersion, isRegExp, report, toRegExp };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-analyzer/shared",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "React Analyzer Shared constants and functions.",
5
5
  "homepage": "https://github.com/Rel1cx/react-analyzer",
6
6
  "bugs": {
@@ -32,10 +32,10 @@
32
32
  "ts-pattern": "^5.9.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@tsconfig/node24": "^24.0.3",
36
- "@types/node": "^25.0.3",
37
- "tsdown": "^0.18.3",
38
- "type-fest": "^5.3.1",
35
+ "@tsconfig/node24": "^24.0.4",
36
+ "@types/node": "^25.0.9",
37
+ "tsdown": "^0.20.0-beta.4",
38
+ "type-fest": "^5.4.1",
39
39
  "@local/configs": "0.0.0"
40
40
  },
41
41
  "engines": {