Skip to content

Commit ae6a3a6

Browse files
committed
chore: reorganize and cleanup code
1 parent 625cd4a commit ae6a3a6

File tree

8 files changed

+384
-377
lines changed

8 files changed

+384
-377
lines changed

.oxfmtrc.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,15 @@
77
"trailingComma": "es5",
88
"arrowParens": "avoid",
99
"experimentalSortPackageJson": false,
10-
"ignorePatterns": ["**/build", "**/node_modules", "CHANGELOG.md"]
10+
"ignorePatterns": ["**/build", "**/node_modules", "CHANGELOG.md"],
11+
"experimentalSortImports": {
12+
"groups": [
13+
["side-effect"],
14+
["builtin", "external", "external-type"],
15+
["internal", "internal-type"],
16+
["parent", "parent-type"],
17+
["sibling", "sibling-type"],
18+
["index", "index-type"]
19+
]
20+
}
1121
}

src/annotatePackageJson.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {
22
type DecorationOptions,
3-
ThemeColor,
3+
type Disposable,
4+
MarkdownString,
45
Range,
56
type TextEditor,
7+
ThemeColor,
68
window,
79
workspace,
8-
type Disposable,
9-
MarkdownString,
1010
} from 'vscode';
1111

12-
import { CHECK_API_URL } from './constants';
12+
import { BASE_API_URL } from './constants';
1313
import { type PackageJSONDeps, type APICheckResponseData, type DependencyRef } from './types';
1414
import { getCompatibilityList, getDetailLabel, getPlatformsList, numberFormatter } from './utils';
1515

@@ -39,6 +39,7 @@ const ENTRY_REGEXP = /^\s*"(?<name>[^"]+)"\s*:\s*"(?<version>(?:\\\\"|[^"])*)"/;
3939

4040
function getDependencyRefsFromPackageJsonText(text: string, editor: TextEditor): DependencyRef[] {
4141
const parsed = tryParsePackageJson(text);
42+
4243
if (!parsed) {
4344
return [];
4445
}
@@ -78,7 +79,10 @@ function getDependencyRefsFromPackageJsonText(text: string, editor: TextEditor):
7879
}
7980

8081
async function fetchDirectoryInfo(packagesList: string, signal: AbortSignal): Promise<APICheckResponseData | null> {
81-
const response = await fetch(`${CHECK_API_URL}?name=${encodeURIComponent(packagesList)}`, { signal });
82+
const apiUrl = new URL(`${BASE_API_URL}/library`);
83+
apiUrl.searchParams.append('name', packagesList);
84+
85+
const response = await fetch(apiUrl.href, { signal });
8286

8387
if (!response.ok) {
8488
return null;
@@ -87,11 +91,7 @@ async function fetchDirectoryInfo(packagesList: string, signal: AbortSignal): Pr
8791
return (await response.json()) as APICheckResponseData;
8892
}
8993

90-
export function createPackageJsonDependencyAnnotator(): {
91-
refreshActiveEditor: () => Promise<void>;
92-
clearActiveEditor: () => void;
93-
dispose: () => void;
94-
} {
94+
export function createPackageJsonDependencyAnnotator(): Disposable {
9595
const decorationType = window.createTextEditorDecorationType({
9696
after: {
9797
margin: '0 0 0 1rem',
@@ -236,5 +236,5 @@ export function createPackageJsonDependencyAnnotator(): {
236236

237237
scheduleRefresh(0);
238238

239-
return { refreshActiveEditor, clearActiveEditor, dispose };
239+
return { dispose };
240240
}

src/constants.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
export const BASE_API_URL = 'https://reactnative.directory/api/libraries';
2-
export const CHECK_API_URL = 'https://reactnative.directory/api/library';
1+
export const BASE_API_URL = 'https://reactnative.directory/api';
32
export const KEYWORD_REGEX = /:\w+/g;
43

54
export enum ENTRY_OPTION {

0 commit comments

Comments
 (0)