Skip to content

Commit 820bd28

Browse files
committed
feat: add setting to control package.json annotations
1 parent ae6a3a6 commit 820bd28

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
],
2828
"main": "./build/index.js",
2929
"contributes": {
30+
"configuration": {
31+
"type": "object",
32+
"title": "React Native Directory",
33+
"properties": {
34+
"reactNativeDirectory.enablePackageJsonAnnotations": {
35+
"type": "boolean",
36+
"default": true,
37+
"markdownDescription": "Automatically annotate `package.json` dependencies with metadata from React Native Directory.",
38+
"scope": "window"
39+
}
40+
}
41+
},
3042
"commands": [
3143
{
3244
"command": "extension.showQuickPick",

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export const BASE_API_URL = 'https://reactnative.directory/api';
22
export const KEYWORD_REGEX = /:\w+/g;
3+
export const CONFIG_KEY = 'reactNativeDirectory';
34

45
export enum ENTRY_OPTION {
56
INSTALL = 'Install package in the current workspace',

src/extension.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { commands, type ExtensionContext, workspace } from 'vscode';
1+
import { commands, type Disposable, type ExtensionContext, workspace } from 'vscode';
22

33
import { createPackageJsonDependencyAnnotator } from './annotatePackageJson';
4+
import { CONFIG_KEY } from './constants';
45
import { createSearchQuickPickHandler } from './createSearchQuickPickHandler';
56
import { detectPackageManager } from './detectPackageManager';
67

@@ -14,7 +15,42 @@ export async function activate(context: ExtensionContext) {
1415
: manager;
1516

1617
context.subscriptions.push(
17-
commands.registerCommand('extension.showQuickPick', createSearchQuickPickHandler(preferredManager, workspacePath)),
18-
createPackageJsonDependencyAnnotator()
18+
commands.registerCommand('extension.showQuickPick', createSearchQuickPickHandler(preferredManager, workspacePath))
1919
);
20+
21+
const annotatePackageJson =
22+
workspace.getConfiguration(CONFIG_KEY).get<boolean>('enablePackageJsonAnnotations') ?? true;
23+
24+
let annotatorDisposable: Disposable | undefined;
25+
26+
function enableAnnotator() {
27+
if (!annotatorDisposable) {
28+
annotatorDisposable = createPackageJsonDependencyAnnotator();
29+
context.subscriptions.push(annotatorDisposable);
30+
}
31+
}
32+
33+
function disableAnnotator() {
34+
if (annotatorDisposable) {
35+
annotatorDisposable.dispose();
36+
annotatorDisposable = undefined;
37+
}
38+
}
39+
40+
if (annotatePackageJson) {
41+
enableAnnotator();
42+
}
43+
44+
const configChangeDisposable = workspace.onDidChangeConfiguration(event => {
45+
if (event.affectsConfiguration(`${CONFIG_KEY}.enablePackageJsonAnnotations`)) {
46+
const enabled = workspace.getConfiguration(CONFIG_KEY).get<boolean>('enablePackageJsonAnnotations') ?? true;
47+
if (enabled) {
48+
enableAnnotator();
49+
} else {
50+
disableAnnotator();
51+
}
52+
}
53+
});
54+
55+
context.subscriptions.push(configChangeDisposable);
2056
}

0 commit comments

Comments
 (0)