Skip to content

Commit b741190

Browse files
committed
first commit
0 parents  commit b741190

15 files changed

+3810
-0
lines changed

.eslintrc.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"env": {
3+
"browser": false,
4+
"commonjs": true,
5+
"es6": true,
6+
"node": true
7+
},
8+
"parserOptions": {
9+
"ecmaFeatures": {
10+
"jsx": true
11+
},
12+
"sourceType": "module"
13+
},
14+
"rules": {
15+
"no-const-assign": "warn",
16+
"no-this-before-super": "warn",
17+
"no-undef": "warn",
18+
"no-unreachable": "warn",
19+
"no-unused-vars": "warn",
20+
"constructor-super": "warn",
21+
"valid-typeof": "warn"
22+
}
23+
}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.vscode-test/
3+
.vsix

.vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"dbaeumer.vscode-eslint"
6+
]
7+
}

.vscode/launch.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// A launch configuration that launches the extension inside a new window
2+
{
3+
"version": "0.1.0",
4+
"configurations": [
5+
{
6+
"name": "Launch Extension",
7+
"type": "extensionHost",
8+
"request": "launch",
9+
"runtimeExecutable": "${execPath}",
10+
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
11+
"stopOnEntry": false
12+
},
13+
{
14+
"name": "Launch Tests",
15+
"type": "extensionHost",
16+
"request": "launch",
17+
"runtimeExecutable": "${execPath}",
18+
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/test" ],
19+
"stopOnEntry": false
20+
}
21+
]
22+
}

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
}

.vscodeignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.vscode/**
2+
.vscode-test/**
3+
test/**
4+
.gitignore
5+
jsconfig.json
6+
vsc-extension-quickstart.md
7+
.eslintrc.json

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Change Log
2+
All notable changes to the "npm-dependency-links" extension will be documented in this file.
3+
4+
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
5+
6+
## [Unreleased]
7+
- Initial release

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# npm-dependency-links README
2+
3+
Links the depedencies in your package.json to their npmjs.com profile.
4+
5+
## Features
6+
7+
Visit the npmjs.com profile of your dependencies by simply `CMD/Ctrl+click` on the package name in your package.json.
8+
9+
## Requirements
10+
11+
Visual Studio Code > 1.17.0

extension.js

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const { languages, Uri, DocumentLink, Range } = require('vscode');
2+
const path = require('path');
3+
4+
exports.activate = function (context) {
5+
const disposable = languages.registerDocumentLinkProvider(['javascript', { language: 'json', pattern: '**/package.json' }], {
6+
provideDocumentLinks(document, token) {
7+
const { fileName } = document;
8+
9+
// Check why pattern is not working
10+
if (path.basename(fileName) !== 'package.json') {
11+
return;
12+
}
13+
14+
const pkg = JSON.parse(document.getText());
15+
const { dependencies = {}, devDependencies = {}, optionalDependencies = {}} = pkg;
16+
17+
const links = [];
18+
let lineIndex = 0;
19+
20+
function extractLink(line, package, version) {
21+
if (line.text.match(package, version)) {
22+
const startCharacter = line.text.indexOf(package);
23+
const endCaracter = startCharacter + package.length;
24+
const linkRange = new Range(lineIndex, startCharacter, lineIndex, endCaracter);
25+
const linkUri = Uri.parse(`https://www.npmjs.com/package/${package}`);
26+
links.push(new DocumentLink(linkRange, linkUri));
27+
}
28+
}
29+
30+
while (lineIndex < document.lineCount) {
31+
const line = document.lineAt(lineIndex);
32+
33+
[
34+
...Object.entries(dependencies),
35+
...Object.entries(devDependencies),
36+
...Object.entries(optionalDependencies)
37+
].forEach(([package, version]) => {
38+
extractLink(line, package, version);
39+
});
40+
41+
lineIndex += 1;
42+
}
43+
44+
return links;
45+
}
46+
});
47+
48+
context.subscriptions.push(disposable)
49+
};
50+
51+
exports.deactivate = function () {
52+
};

jsconfig.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es6",
5+
"lib": [
6+
"es6"
7+
]
8+
},
9+
"exclude": [
10+
"node_modules"
11+
]
12+
}

0 commit comments

Comments
 (0)