@@ -19,13 +19,13 @@ let s:CORE_MODULES = ["_debugger", "_http_agent", "_http_client",
19
19
"
20
20
" require(a:name) from module at path a:from
21
21
" 1. If a:name is a core module,
22
- " a. return the core module
23
- " b. STOP
22
+ " a. return the core module
23
+ " b. STOP
24
24
" 2. If a:name begins with '/'
25
- " a. set a:from to be the filesystem root
25
+ " a. set a:from to be the filesystem root
26
26
" 3. If a:name begins with './' or '/' or '../'
27
- " a. LOAD_AS_FILE(a:from + a:name)
28
- " b. LOAD_AS_DIRECTORY(a:from + a:name)
27
+ " a. LOAD_AS_FILE(a:from + a:name)
28
+ " b. LOAD_AS_DIRECTORY(a:from + a:name)
29
29
" 4. LOAD_NODE_MODULES(a:name, dirname(a:from))
30
30
" 5. THROW "not found"
31
31
function ! node#lib#find (name, from)
@@ -36,24 +36,24 @@ function! node#lib#find(name, from)
36
36
return s: CORE_URL_PREFIX ." /" . l: version ." /" . l: dir ." /" . a: name ." .js"
37
37
endif
38
38
39
- let request = s: getModulePath (a: name , a: from )
40
- if ! empty (request)
41
- let asFile = s: loadAsFile (request)
42
- if ! empty (asFile) | return asFile | endif
39
+ let request = s: getModulePath (a: name , a: from )
40
+ if ! empty (request)
41
+ let asFile = s: loadAsFile (request)
42
+ if ! empty (asFile) | return asFile | endif
43
43
44
- let asDirectory = s: loadAsDirectory (request)
45
- if ! empty (asDirectory) | return asDirectory | endif
46
- endif
44
+ let asDirectory = s: loadAsDirectory (request)
45
+ if ! empty (asDirectory) | return asDirectory | endif
46
+ endif
47
47
48
- let asNodeModule = s: loadNodeModules (a: name , s: dirname (a: from ))
48
+ let asNodeModule = s: loadNodeModules (a: name , s: dirname (a: from ))
49
49
if ! empty (asNodeModule) | return asNodeModule | endif
50
50
endfunction
51
51
52
52
" LOAD_AS_FILE(X)
53
- " 1. If X is a file, load X as JavaScript text. STOP
54
- " 2. If X.js is a file, load X.js as JavaScript text. STOP
55
- " 3. If X.json is a file, parse X.json to a JavaScript Object. STOP
56
- " 4. If X.node is a file, load X.node as binary addon. STOP
53
+ " 1. If X is a file, load X as JavaScript text. STOP
54
+ " 2. If X.js is a file, load X.js as JavaScript text. STOP
55
+ " 3. If X.json is a file, parse X.json to a JavaScript Object. STOP
56
+ " 4. If X.node is a file, load X.node as binary addon. STOP
57
57
function ! s: loadAsFile (path )
58
58
if a: path !~# ' \v/(\.\.?/?)?$'
59
59
let path_with_suffix = s: resolveSuffix (a: path )
@@ -62,19 +62,19 @@ function! s:loadAsFile(path)
62
62
endfunction
63
63
64
64
" LOAD_INDEX(X)
65
- " 1. If X/index.js is a file, load X/index.js as JavaScript text. STOP
65
+ " 1. If X/index.js is a file, load X/index.js as JavaScript text. STOP
66
66
" 2. If X/index.json is a file, parse X/index.json to a JavaScript object. STOP
67
- " 3. If X/index.node is a file, load X/index.node as binary addon. STOP
67
+ " 3. If X/index.node is a file, load X/index.node as binary addon. STOP
68
68
function ! s: loadIndex (path )
69
69
return s: resolveSuffix (a: path . " /index" )
70
70
endfunction
71
71
72
72
" LOAD_AS_DIRECTORY(X)
73
73
" 1. If X/package.json is a file,
74
- " a. Parse X/package.json, and look for "main" field.
75
- " b. let M = X + (json main field)
76
- " c. LOAD_AS_FILE(M)
77
- " d. LOAD_INDEX(M)
74
+ " a. Parse X/package.json, and look for "main" field.
75
+ " b. let M = X + (json main field)
76
+ " c. LOAD_AS_FILE(M)
77
+ " d. LOAD_INDEX(M)
78
78
" 2. LOAD_INDEX(X)
79
79
function ! s: loadAsDirectory (path )
80
80
" Node.js checks for package.json in every directory, not just the
@@ -89,10 +89,10 @@ function! s:loadAsDirectory(path)
89
89
90
90
if ! empty (main) && main != " "
91
91
let path = a: path . " /" . main
92
- let asFile = s: loadAsFile (path )
92
+ let asFile = s: loadAsFile (path )
93
93
if ! empty (asFile) | return asFile | endif
94
94
95
- let asIndex = s: loadIndex (path )
95
+ let asIndex = s: loadIndex (path )
96
96
if ! empty (asIndex) | return asIndex | endif
97
97
endif
98
98
endif
@@ -103,54 +103,54 @@ endfunction
103
103
" LOAD_NODE_MODULES(X, START)
104
104
" 1. let DIRS=NODE_MODULES_PATHS(START)
105
105
" 2. for each DIR in DIRS:
106
- " a. LOAD_AS_FILE(DIR/X)
107
- " b. LOAD_AS_DIRECTORY(DIR/X)
106
+ " a. LOAD_AS_FILE(DIR/X)
107
+ " b. LOAD_AS_DIRECTORY(DIR/X)
108
108
function ! s: loadNodeModules (x , start )
109
- let dirs = s: nodeModulePaths (a: start )
110
- for dir in dirs
109
+ let dirs = s: nodeModulePaths (a: start )
110
+ for dir in dirs
111
111
let path = dir . " /" . a: x
112
- let asFile = s: loadAsFile (path )
112
+ let asFile = s: loadAsFile (path )
113
113
if ! empty (asFile) | return asFile | endif
114
114
115
- let asDirectory = s: loadAsDirectory (path )
115
+ let asDirectory = s: loadAsDirectory (path )
116
116
if ! empty (asDirectory) | return asDirectory | endif
117
- endfor
117
+ endfor
118
118
endfunction
119
119
120
120
" NODE_MODULES_PATHS(START)
121
121
" 1. let PARTS = path split(START)
122
122
" 2. let I = count of PARTS - 1
123
123
" 3. let DIRS = []
124
124
" 4. while I >= 0,
125
- " a. if PARTS[I] = "node_modules" CONTINUE
126
- " b. DIR = path join(PARTS[0 .. I] + "node_modules")
127
- " c. DIRS = DIRS + DIR
128
- " d. let I = I - 1
125
+ " a. if PARTS[I] = "node_modules" CONTINUE
126
+ " b. DIR = path join(PARTS[0 .. I] + "node_modules")
127
+ " c. DIRS = DIRS + DIR
128
+ " d. let I = I - 1
129
129
" 5. return DIRS
130
130
function ! s: nodeModulePaths (start )
131
- let parts = split (a: start , ' /' )
132
-
133
- " We want to keep the leading slash of an absolute path
134
- if a: start = ~# s: ABSPATH
135
- let parts[0 ] = ' /' . parts[0 ]
136
- endif
137
-
138
- let i = len (parts) - 1
139
- let dirs = []
140
- while i >= 0
141
- if parts[i ] == ' node_modules' | continue | endif
142
- let dir = join (parts[0 :i ] + [' node_modules' ], ' /' )
143
- let dirs += [dir ]
144
- let i = i - 1
145
- endwhile
146
-
147
- " Add support for NODE_PATH
148
- let NODE_PATH = $NODE_PATH
149
- if ! empty (NODE_PATH)
150
- let dirs += [NODE_PATH]
151
- endif
152
-
153
- return dirs
131
+ let parts = split (a: start , ' /' )
132
+
133
+ " We want to keep the leading slash of an absolute path
134
+ if a: start = ~# s: ABSPATH
135
+ let parts[0 ] = ' /' . parts[0 ]
136
+ endif
137
+
138
+ let i = len (parts) - 1
139
+ let dirs = []
140
+ while i >= 0
141
+ if parts[i ] == ' node_modules' | continue | endif
142
+ let dir = join (parts[0 :i ] + [' node_modules' ], ' /' )
143
+ let dirs += [dir ]
144
+ let i = i - 1
145
+ endwhile
146
+
147
+ " Add support for NODE_PATH
148
+ let NODE_PATH = $NODE_PATH
149
+ if ! empty (NODE_PATH)
150
+ let dirs += [NODE_PATH]
151
+ endif
152
+
153
+ return dirs
154
154
endfunction
155
155
156
156
function ! s: getModulePath (name, from)
@@ -159,11 +159,11 @@ function! s:getModulePath(name, from)
159
159
elseif a: name = ~# s: RELPATH
160
160
let dir = isdirectory (a: from ) ? a: from : s: dirname (a: from )
161
161
return dir . " /" . a: name
162
- endif
162
+ endif
163
163
endfunction
164
164
165
165
function ! s: dirname (path )
166
- return fnamemodify (a: path , ' :h' )
166
+ return fnamemodify (a: path , ' :h' )
167
167
endfunction
168
168
169
169
function ! node#lib#version ()
0 commit comments