Skip to content

Commit c89fa62

Browse files
committed
feat: add command to open npmx.dev in browser
1 parent 4c39071 commit c89fa62

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@
7676
"description": "Show warnings for packages with known vulnerabilities"
7777
}
7878
}
79-
}
79+
},
80+
"commands": [
81+
{
82+
"command": "npmx.openInBrowser",
83+
"title": "Open npmx.dev in external browser",
84+
"category": "npmx"
85+
}
86+
]
8087
},
8188
"scripts": {
8289
"dev": "tsdown --watch",

src/constants.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ export const VERSION_TRIGGER_CHARACTERS = ['.', '^', '~', ...Array.from({ length
88

99
export const CACHE_TTL_ONE_DAY = 1000 * 60 * 60 * 24
1010

11+
export const NPMX_DEV = 'https://npmx.dev'
12+
1113
export const NPM_REGISTRY = 'https://registry.npmjs.org'
12-
export const NPMX_DEV_API = 'https://npmx.dev/api'
14+
export const NPMX_DEV_API = `${NPMX_DEV}/api`

src/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import {
2+
NPMX_DEV,
23
PACKAGE_JSON_BASENAME,
34
PACKAGE_JSON_PATTERN,
45
PNPM_WORKSPACE_BASENAME,
56
PNPM_WORKSPACE_PATTERN,
67
VERSION_TRIGGER_CHARACTERS,
78
} from '#constants'
8-
import { defineExtension, watchEffect } from 'reactive-vscode'
9-
import { Disposable, languages } from 'vscode'
9+
import { defineExtension, useCommands, watchEffect } from 'reactive-vscode'
10+
import { Disposable, env, languages, Uri } from 'vscode'
1011
import { PackageJsonExtractor } from './extractors/package-json'
1112
import { PnpmWorkspaceYamlExtractor } from './extractors/pnpm-workspace-yaml'
12-
import { displayName, version } from './generated-meta'
13+
import { commands, displayName, version } from './generated-meta'
1314
import { VersionCompletionItemProvider } from './providers/completion-item/version'
1415
import { registerDiagnosticCollection } from './providers/diagnostics'
1516
import { NpmxHoverProvider } from './providers/hover/npmx'
@@ -63,4 +64,10 @@ export const { activate, deactivate } = defineExtension(() => {
6364
[PACKAGE_JSON_BASENAME]: packageJsonExtractor,
6465
[PNPM_WORKSPACE_BASENAME]: pnpmWorkspaceYamlExtractor,
6566
})
67+
68+
useCommands({
69+
[commands.openInBrowser]: () => {
70+
env.openExternal(Uri.parse(NPMX_DEV))
71+
},
72+
})
6673
})

0 commit comments

Comments
 (0)