Skip to content

Commit

Permalink
Use HTTPS for editing core modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
moll committed Apr 27, 2018
1 parent 5d013f0 commit 7e26a31
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
Thanks, [Jacky Alciné](https://jacky.wtf), for the help!
- Resolves symlinks in paths before editing a file.
Shows correct paths when using the relative symlink trick in `node_modules` (`ln -s .. node_modules/root`) and using `gf` on `require("root/lib/foo")`.
- Uses the HTTPS variant of <https://rawgit.com> to download Node core module source files.
This previously used HTTP because my Vim v7's Netrw didn't seem to handle HTTPS URLs. If that's still the case for you, set `g:node_repository_url`:

```vim
let node_repository_url = "http://raw.githack.com/nodejs/node"
```

## 0.8.1 (Apr 15, 2014)
- Updates the URL from which Node.vim downloads Node core module source files.
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ autocmd User Node
\ endif
```

#### Viewing Node.js core modules
Open Vim in the directory of a Node.js project and use `:Nedit` with the name of the core module:
```vim
:Nedit http
```

This downloads a single file from the Node.js repository for your Node version through <https://rawgit.com>. If you'd like to change the base URL, set `g:node_repository_url`:

```vim
let node_repository_url = "https://example.com/nodejs/node"
```


License
-------
Expand Down
5 changes: 3 additions & 2 deletions autoload/node/lib.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let s:RELPATH = '\v^\.\.?(/|$)'
let s:MODULE = '\v^(/|\.\.?(/|$))@!'

" Damn Netrw can't handle HTTPS at all. It's 2013! Insecure bastard!
let s:CORE_URL_PREFIX = "http://rawgit.com/nodejs/node"
let s:CORE_URL_PREFIX = "https://rawgit.com/nodejs/node"
let s:CORE_MODULES = ["_debugger", "_http_agent", "_http_client",
\ "_http_common", "_http_incoming", "_http_outgoing", "_http_server",
\ "_linklist", "_stream_duplex", "_stream_passthrough", "_stream_readable",
Expand All @@ -19,7 +19,8 @@ function! node#lib#find(name, from)
let l:version = node#lib#version()
let l:version = empty(l:version) ? "master" : "v" . l:version
let l:dir = a:name == "node" ? "src" : "lib"
return s:CORE_URL_PREFIX ."/". l:version ."/". l:dir ."/". a:name .".js"
let l:url = get(g:, "node_repository_url", s:CORE_URL_PREFIX)
return l:url ."/". l:version ."/". l:dir ."/". a:name .".js"
endif

let l:path = s:resolve(s:absolutize(a:name, a:from))
Expand Down
8 changes: 4 additions & 4 deletions test/autoload/lib_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def find(name)
it "must return URL for core module for current Node version" do
set_node_version "0.13.37"
$vim.edit File.join(@dir, "index.js")
url = "http://rawgit.com/nodejs/node/v0.13.37/lib/assert.js"
url = "https://rawgit.com/nodejs/node/v0.13.37/lib/assert.js"
find("assert").must_equal url
end

Expand All @@ -273,14 +273,14 @@ def find(name)
File.chmod 0755, File.join(@dir, "node")
$vim.edit File.join(@dir, "index.js")
$vim.command(%(let $PATH = "#@dir:" . $PATH))
url = "http://rawgit.com/nodejs/node/master/lib/assert.js"
url = "https://rawgit.com/nodejs/node/master/lib/assert.js"
find("assert").must_equal url
end

it "must return URL for node.js for current Node version" do
set_node_version "0.13.37"
$vim.edit File.join(@dir, "index.js")
url = "http://rawgit.com/nodejs/node/v0.13.37/src/node.js"
url = "https://rawgit.com/nodejs/node/v0.13.37/src/node.js"
find("node").must_equal url
end

Expand All @@ -289,7 +289,7 @@ def find(name)
File.chmod 0755, File.join(@dir, "node")
$vim.edit File.join(@dir, "index.js")
$vim.command(%(let $PATH = "#@dir:" . $PATH))
url = "http://rawgit.com/nodejs/node/master/src/node.js"
url = "https://rawgit.com/nodejs/node/master/src/node.js"
find("node").must_equal url
end
end
Expand Down

0 comments on commit 7e26a31

Please sign in to comment.