Leon4gr45 commited on
Commit
a932776
·
verified ·
1 Parent(s): c7298c5

Include updated package-lock.json (part 11)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. node_modules/resolve-pkg-maps/LICENSE +21 -0
  2. node_modules/resolve-pkg-maps/README.md +216 -0
  3. node_modules/resolve-pkg-maps/package.json +42 -0
  4. node_modules/resolve-protobuf-schema/.travis.yml +3 -0
  5. node_modules/resolve-protobuf-schema/LICENSE +21 -0
  6. node_modules/resolve-protobuf-schema/README.md +49 -0
  7. node_modules/resolve-protobuf-schema/index.js +50 -0
  8. node_modules/resolve-protobuf-schema/package.json +25 -0
  9. node_modules/resolve-protobuf-schema/test/a.proto +5 -0
  10. node_modules/resolve-protobuf-schema/test/b.proto +5 -0
  11. node_modules/resolve-protobuf-schema/test/c.proto +3 -0
  12. node_modules/resolve-protobuf-schema/test/index.js +49 -0
  13. node_modules/resolve/test/core.js +88 -0
  14. node_modules/resolve/test/default_paths.js +49 -0
  15. node_modules/resolve/test/dotdot.js +29 -0
  16. node_modules/resolve/test/dotdot/abc/index.js +2 -0
  17. node_modules/resolve/test/dotdot/index.js +1 -0
  18. node_modules/resolve/test/faulty_basedir.js +29 -0
  19. node_modules/resolve/test/filter.js +34 -0
  20. node_modules/resolve/test/filter_sync.js +33 -0
  21. node_modules/resolve/test/home_paths.js +127 -0
  22. node_modules/resolve/test/home_paths_sync.js +114 -0
  23. node_modules/resolve/test/homedir.js +112 -0
  24. node_modules/resolve/test/mock.js +353 -0
  25. node_modules/resolve/test/mock_sync.js +234 -0
  26. node_modules/resolve/test/module_dir.js +56 -0
  27. node_modules/resolve/test/module_dir/xmodules/aaa/index.js +1 -0
  28. node_modules/resolve/test/module_dir/ymodules/aaa/index.js +1 -0
  29. node_modules/resolve/test/module_dir/zmodules/bbb/main.js +1 -0
  30. node_modules/resolve/test/module_dir/zmodules/bbb/package.json +3 -0
  31. node_modules/resolve/test/node-modules-paths.js +143 -0
  32. node_modules/resolve/test/node_path.js +70 -0
  33. node_modules/resolve/test/node_path/x/aaa/index.js +1 -0
  34. node_modules/resolve/test/node_path/x/ccc/index.js +1 -0
  35. node_modules/resolve/test/node_path/y/bbb/index.js +1 -0
  36. node_modules/resolve/test/node_path/y/ccc/index.js +1 -0
  37. node_modules/resolve/test/nonstring.js +9 -0
  38. node_modules/resolve/test/pathfilter.js +75 -0
  39. node_modules/resolve/test/pathfilter/deep_ref/main.js +0 -0
  40. node_modules/resolve/test/pathfilter_sync.js +24 -0
  41. node_modules/resolve/test/precedence.js +23 -0
  42. node_modules/resolve/test/precedence/aaa.js +1 -0
  43. node_modules/resolve/test/precedence/aaa/index.js +1 -0
  44. node_modules/resolve/test/precedence/aaa/main.js +1 -0
  45. node_modules/resolve/test/precedence/bbb.js +1 -0
  46. node_modules/resolve/test/precedence/bbb/main.js +1 -0
  47. node_modules/resolve/test/resolver.js +597 -0
  48. node_modules/resolve/test/resolver/baz/doom.js +0 -0
  49. node_modules/resolve/test/resolver/baz/package.json +4 -0
  50. node_modules/resolve/test/resolver/baz/quux.js +1 -0
node_modules/resolve-pkg-maps/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) Hiroki Osame <hiroki.osame@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
node_modules/resolve-pkg-maps/README.md ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # resolve-pkg-maps
2
+
3
+ Utils to resolve `package.json` subpath & conditional [`exports`](https://nodejs.org/api/packages.html#exports)/[`imports`](https://nodejs.org/api/packages.html#imports) in resolvers.
4
+
5
+ Implements the [ESM resolution algorithm](https://nodejs.org/api/esm.html#resolver-algorithm-specification). Tested [against Node.js](/tests/) for accuracy.
6
+
7
+ <sub>Support this project by ⭐️ starring and sharing it. [Follow me](https://github.com/privatenumber) to see what other cool projects I'm working on! ❤️</sub>
8
+
9
+ ## Usage
10
+
11
+ ### Resolving `exports`
12
+
13
+ _utils/package.json_
14
+ ```json5
15
+ {
16
+ // ...
17
+ "exports": {
18
+ "./reverse": {
19
+ "require": "./file.cjs",
20
+ "default": "./file.mjs"
21
+ }
22
+ },
23
+ // ...
24
+ }
25
+ ```
26
+
27
+ ```ts
28
+ import { resolveExports } from 'resolve-pkg-maps'
29
+
30
+ const [packageName, packageSubpath] = parseRequest('utils/reverse')
31
+
32
+ const resolvedPaths: string[] = resolveExports(
33
+ getPackageJson(packageName).exports,
34
+ packageSubpath,
35
+ ['import', ...otherConditions]
36
+ )
37
+ // => ['./file.mjs']
38
+ ```
39
+
40
+ ### Resolving `imports`
41
+
42
+ _package.json_
43
+ ```json5
44
+ {
45
+ // ...
46
+ "imports": {
47
+ "#supports-color": {
48
+ "node": "./index.js",
49
+ "default": "./browser.js"
50
+ }
51
+ },
52
+ // ...
53
+ }
54
+ ```
55
+
56
+ ```ts
57
+ import { resolveImports } from 'resolve-pkg-maps'
58
+
59
+ const resolvedPaths: string[] = resolveImports(
60
+ getPackageJson('.').imports,
61
+ '#supports-color',
62
+ ['node', ...otherConditions]
63
+ )
64
+ // => ['./index.js']
65
+ ```
66
+
67
+ ## API
68
+
69
+ ### resolveExports(exports, request, conditions)
70
+
71
+ Returns: `string[]`
72
+
73
+ Resolves the `request` based on `exports` and `conditions`. Returns an array of paths (e.g. in case a fallback array is matched).
74
+
75
+ #### exports
76
+
77
+ Type:
78
+ ```ts
79
+ type Exports = PathOrMap | readonly PathOrMap[]
80
+
81
+ type PathOrMap = string | PathConditionsMap
82
+
83
+ type PathConditionsMap = {
84
+ [condition: string]: PathConditions | null
85
+ }
86
+ ```
87
+
88
+ The [`exports` property](https://nodejs.org/api/packages.html#exports) value in `package.json`.
89
+
90
+ #### request
91
+
92
+ Type: `string`
93
+
94
+ The package subpath to resolve. Assumes a normalized path is passed in (eg. [repeating slashes `//`](https://github.com/nodejs/node/issues/44316)).
95
+
96
+ It _should not_ start with `/` or `./`.
97
+
98
+ Example: if the full import path is `some-package/subpath/file`, the request is `subpath/file`.
99
+
100
+
101
+ #### conditions
102
+
103
+ Type: `readonly string[]`
104
+
105
+ An array of conditions to use when resolving the request. For reference, Node.js's default conditions are [`['node', 'import']`](https://nodejs.org/api/esm.html#:~:text=defaultConditions%20is%20the%20conditional%20environment%20name%20array%2C%20%5B%22node%22%2C%20%22import%22%5D.).
106
+
107
+ The order of this array does not matter; the order of condition keys in the export map is what matters instead.
108
+
109
+ Not all conditions in the array need to be met to resolve the request. It just needs enough to resolve to a path.
110
+
111
+ ---
112
+
113
+ ### resolveImports(imports, request, conditions)
114
+
115
+ Returns: `string[]`
116
+
117
+ Resolves the `request` based on `imports` and `conditions`. Returns an array of paths (e.g. in case a fallback array is matched).
118
+
119
+ #### imports
120
+
121
+ Type:
122
+ ```ts
123
+ type Imports = {
124
+ [condition: string]: PathOrMap | readonly PathOrMap[] | null
125
+ }
126
+
127
+ type PathOrMap = string | Imports
128
+ ```
129
+
130
+ The [`imports` property](https://nodejs.org/api/packages.html#imports) value in `package.json`.
131
+
132
+
133
+ #### request
134
+
135
+ Type: `string`
136
+
137
+ The request resolve. Assumes a normalized path is passed in (eg. [repeating slashes `//`](https://github.com/nodejs/node/issues/44316)).
138
+
139
+ > **Note:** In Node.js, imports resolutions are limited to requests prefixed with `#`. However, this package does not enforce that requirement in case you want to add custom support for non-prefixed entries.
140
+
141
+ #### conditions
142
+
143
+ Type: `readonly string[]`
144
+
145
+ An array of conditions to use when resolving the request. For reference, Node.js's default conditions are [`['node', 'import']`](https://nodejs.org/api/esm.html#:~:text=defaultConditions%20is%20the%20conditional%20environment%20name%20array%2C%20%5B%22node%22%2C%20%22import%22%5D.).
146
+
147
+ The order of this array does not matter; the order of condition keys in the import map is what matters instead.
148
+
149
+ Not all conditions in the array need to be met to resolve the request. It just needs enough to resolve to a path.
150
+
151
+ ---
152
+
153
+ ### Errors
154
+
155
+ #### `ERR_PACKAGE_PATH_NOT_EXPORTED`
156
+ - If the request is not exported by the export map
157
+
158
+ #### `ERR_PACKAGE_IMPORT_NOT_DEFINED`
159
+ - If the request is not defined by the import map
160
+
161
+ #### `ERR_INVALID_PACKAGE_CONFIG`
162
+
163
+ - If an object contains properties that are both paths and conditions (e.g. start with and without `.`)
164
+ - If an object contains numeric properties
165
+
166
+ #### `ERR_INVALID_PACKAGE_TARGET`
167
+ - If a resolved exports path is not a valid path (e.g. not relative or has protocol)
168
+ - If a resolved path includes `..` or `node_modules`
169
+ - If a resolved path is a type that cannot be parsed
170
+
171
+ ## FAQ
172
+
173
+ ### Why do the APIs return an array of paths?
174
+
175
+ `exports`/`imports` supports passing in a [fallback array](https://github.com/jkrems/proposal-pkg-exports/#:~:text=Whenever%20there%20is,to%20new%20cases.) to provide fallback paths if the previous one is invalid:
176
+
177
+ ```json5
178
+ {
179
+ "exports": {
180
+ "./feature": [
181
+ "./file.js",
182
+ "./fallback.js"
183
+ ]
184
+ }
185
+ }
186
+ ```
187
+
188
+ Node.js's implementation [picks the first valid path (without attempting to resolve it)](https://github.com/nodejs/node/issues/44282#issuecomment-1220151715) and throws an error if it can't be resolved. Node.js's fallback array is designed for [forward compatibility with features](https://github.com/jkrems/proposal-pkg-exports/#:~:text=providing%20forwards%20compatiblitiy%20for%20new%20features) (e.g. protocols) that can be immediately/inexpensively validated:
189
+
190
+ ```json5
191
+ {
192
+ "exports": {
193
+ "./core-polyfill": ["std:core-module", "./core-polyfill.js"]
194
+ }
195
+ }
196
+ ```
197
+
198
+ However, [Webpack](https://webpack.js.org/guides/package-exports/#alternatives) and [TypeScript](https://github.com/microsoft/TypeScript/blob/71e852922888337ef51a0e48416034a94a6c34d9/src/compiler/moduleSpecifiers.ts#L695) have deviated from this behavior and attempts to resolve the next path if a path cannot be resolved.
199
+
200
+ By returning an array of matched paths instead of just the first one, the user can decide which behavior to adopt.
201
+
202
+ ### How is it different from [`resolve.exports`](https://github.com/lukeed/resolve.exports)?
203
+
204
+ `resolve.exports` only resolves `exports`, whereas this package resolves both `exports` & `imports`. This comparison will only cover resolving `exports`.
205
+
206
+ - Despite it's name, `resolve.exports` handles more than just `exports`. It takes in the entire `package.json` object to handle resolving `.` and [self-references](https://nodejs.org/api/packages.html#self-referencing-a-package-using-its-name). This package only accepts `exports`/`imports` maps from `package.json` and is scoped to only resolving what's defined in the maps.
207
+
208
+ - `resolve.exports` accepts the full request (e.g. `foo/bar`), whereas this package only accepts the requested subpath (e.g. `bar`).
209
+
210
+ - `resolve.exports` only returns the first result in a fallback array. This package returns an array of results for the user to decide how to handle it.
211
+
212
+ - `resolve.exports` supports [subpath folder mapping](https://nodejs.org/docs/latest-v16.x/api/packages.html#subpath-folder-mappings) (deprecated in Node.js v16 & removed in v17) but seems to [have a bug](https://github.com/lukeed/resolve.exports/issues/7). This package does not support subpath folder mapping because Node.js has removed it in favor of using subpath patterns.
213
+
214
+ - Neither resolvers rely on a file-system
215
+
216
+ This package also addresses many of the bugs in `resolve.exports`, demonstrated in [this test](/tests/exports/compare-resolve.exports.ts).
node_modules/resolve-pkg-maps/package.json ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "resolve-pkg-maps",
3
+ "version": "1.0.0",
4
+ "description": "Resolve package.json exports & imports maps",
5
+ "keywords": [
6
+ "node.js",
7
+ "package.json",
8
+ "exports",
9
+ "imports"
10
+ ],
11
+ "license": "MIT",
12
+ "repository": "privatenumber/resolve-pkg-maps",
13
+ "funding": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1",
14
+ "author": {
15
+ "name": "Hiroki Osame",
16
+ "email": "hiroki.osame@gmail.com"
17
+ },
18
+ "type": "module",
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "main": "./dist/index.cjs",
23
+ "module": "./dist/index.mjs",
24
+ "types": "./dist/index.d.cts",
25
+ "exports": {
26
+ "require": {
27
+ "types": "./dist/index.d.cts",
28
+ "default": "./dist/index.cjs"
29
+ },
30
+ "import": {
31
+ "types": "./dist/index.d.mts",
32
+ "default": "./dist/index.mjs"
33
+ }
34
+ },
35
+ "imports": {
36
+ "#resolve-pkg-maps": {
37
+ "types": "./src/index.ts",
38
+ "development": "./src/index.ts",
39
+ "default": "./dist/index.mjs"
40
+ }
41
+ }
42
+ }
node_modules/resolve-protobuf-schema/.travis.yml ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ language: node_js
2
+ node_js:
3
+ - "0.10"
node_modules/resolve-protobuf-schema/LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Mathias Buus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
node_modules/resolve-protobuf-schema/README.md ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # resolve-protobuf-schema
2
+
3
+ Read a protobuf schema from the disk, parse it and resolve all imports
4
+
5
+ ```
6
+ npm install resolve-protobuf-schema
7
+ ```
8
+
9
+ [![build status](http://img.shields.io/travis/mafintosh/resolve-protobuf-schema.svg?style=flat)](http://travis-ci.org/mafintosh/resolve-protobuf-schema)
10
+
11
+ ## Usage
12
+
13
+ Store the following example protobuf schema in `test.proto`
14
+
15
+ ```
16
+ message Test {
17
+ optional string test = 1;
18
+ }
19
+ ```
20
+
21
+ Then run
22
+
23
+ ``` js
24
+ var resolve = require('resolve-protobuf-schema')
25
+ console.log(resolve.sync('test.proto')) // prints the parsed schema
26
+ ```
27
+
28
+ Schema imports will resolved as well
29
+
30
+ ```
31
+ import "./test.proto"
32
+
33
+ message AnotherTest {
34
+ optional string test = 1;
35
+ }
36
+ ```
37
+
38
+ ``` js
39
+ console.log(resolve.sync('./another-test.proto')) // will print a combined parsed schema
40
+ ```
41
+
42
+ ## API
43
+
44
+ * `resolve(path, cb)` read and resolve a schema
45
+ * `resolve.sync(path)` sync version of `resolve`
46
+
47
+ ## License
48
+
49
+ MIT
node_modules/resolve-protobuf-schema/index.js ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var schema = require('protocol-buffers-schema')
2
+ var fs = require('fs')
3
+ var path = require('path')
4
+
5
+ var merge = function(a, b) {
6
+ a.messages = a.messages.concat(b.messages)
7
+ a.enums = a.enums.concat(b.enums)
8
+ return a
9
+ }
10
+
11
+ var readSync = function(filename) {
12
+ if (!/\.proto$/i.test(filename) && !fs.existsSync(filename)) filename += '.proto'
13
+
14
+ var sch = schema(fs.readFileSync(filename, 'utf-8'))
15
+ var imports = [].concat(sch.imports || [])
16
+
17
+ imports.forEach(function(i) {
18
+ sch = merge(sch, readSync(path.resolve(path.dirname(filename), i)))
19
+ })
20
+
21
+ return sch
22
+ }
23
+
24
+ var read = function(filename, cb) {
25
+ fs.exists(filename, function(exists) {
26
+ if (!exists && !/\.proto$/i.test(filename)) filename += '.proto'
27
+
28
+ fs.readFile(filename, 'utf-8', function(err, proto) {
29
+ if (err) return cb(err)
30
+
31
+ var sch = schema(proto)
32
+ var imports = [].concat(sch.imports || [])
33
+
34
+ var loop = function() {
35
+ if (!imports.length) return cb(null, sch)
36
+
37
+ read(path.resolve(path.dirname(filename), imports.shift()), function(err, ch) {
38
+ if (err) return cb(err)
39
+ sch = merge(sch, ch)
40
+ loop()
41
+ })
42
+ }
43
+
44
+ loop()
45
+ })
46
+ })
47
+ }
48
+
49
+ module.exports = read
50
+ module.exports.sync = readSync
node_modules/resolve-protobuf-schema/package.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "resolve-protobuf-schema",
3
+ "version": "2.1.0",
4
+ "description": "Read a protobuf schema from the disk, parse it and resolve all imports",
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "protocol-buffers-schema": "^3.3.1"
8
+ },
9
+ "devDependencies": {
10
+ "tape": "^3.0.0"
11
+ },
12
+ "scripts": {
13
+ "test": "tape test/index.js"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/mafintosh/resolve-protobuf-schema.git"
18
+ },
19
+ "author": "Mathias Buus (@mafintosh)",
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/mafintosh/resolve-protobuf-schema/issues"
23
+ },
24
+ "homepage": "https://github.com/mafintosh/resolve-protobuf-schema"
25
+ }
node_modules/resolve-protobuf-schema/test/a.proto ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import "./b.proto";
2
+
3
+ message A {
4
+ optional string a = 1;
5
+ }
node_modules/resolve-protobuf-schema/test/b.proto ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ import "./c.proto";
2
+
3
+ message B {
4
+ optional string b = 1;
5
+ }
node_modules/resolve-protobuf-schema/test/c.proto ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ message C {
2
+ optional string c = 1;
3
+ }
node_modules/resolve-protobuf-schema/test/index.js ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var tape = require('tape')
2
+ var schema = require('../')
3
+
4
+ var test = function(name, fn) {
5
+ tape(name, function(t) {
6
+ fn(t, schema)
7
+ })
8
+ tape(name+' sync', function(t) {
9
+ fn(t, function(name, cb) {
10
+ cb(null, schema.sync(name))
11
+ })
12
+ })
13
+ }
14
+
15
+ test('c', function(t, schema) {
16
+ schema(__dirname+'/c.proto', function(err, sch) {
17
+ t.notOk(err, 'no err')
18
+ t.same(sch.messages.length, 1)
19
+ schema(__dirname+'/c', function(err, sch) {
20
+ t.notOk(err, 'no err')
21
+ t.same(sch.messages.length, 1)
22
+ t.end()
23
+ })
24
+ })
25
+ })
26
+
27
+ test('b imports c', function(t, schema) {
28
+ schema(__dirname+'/b.proto', function(err, sch) {
29
+ t.notOk(err, 'no err')
30
+ t.same(sch.messages.length, 2)
31
+ schema(__dirname+'/b', function(err, sch) {
32
+ t.notOk(err, 'no err')
33
+ t.same(sch.messages.length, 2)
34
+ t.end()
35
+ })
36
+ })
37
+ })
38
+
39
+ test('a imports b imports c', function(t, schema) {
40
+ schema(__dirname+'/a.proto', function(err, sch) {
41
+ t.notOk(err, 'no err')
42
+ t.same(sch.messages.length, 3)
43
+ schema(__dirname+'/a', function(err, sch) {
44
+ t.notOk(err, 'no err')
45
+ t.same(sch.messages.length, 3)
46
+ t.end()
47
+ })
48
+ })
49
+ })
node_modules/resolve/test/core.js ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var test = require('tape');
2
+ var keys = require('object-keys');
3
+ var semver = require('semver');
4
+
5
+ var resolve = require('../');
6
+
7
+ var brokenNode = semver.satisfies(process.version, '11.11 - 11.13');
8
+
9
+ test('core modules', function (t) {
10
+ t.test('isCore()', function (st) {
11
+ st.ok(resolve.isCore('fs'));
12
+ st.ok(resolve.isCore('net'));
13
+ st.ok(resolve.isCore('http'));
14
+
15
+ st.ok(!resolve.isCore('seq'));
16
+ st.ok(!resolve.isCore('../'));
17
+
18
+ st.ok(!resolve.isCore('toString'));
19
+
20
+ st.end();
21
+ });
22
+
23
+ t.test('core list', function (st) {
24
+ var cores = keys(resolve.core);
25
+ st.plan(cores.length);
26
+
27
+ for (var i = 0; i < cores.length; ++i) {
28
+ var mod = cores[i];
29
+ // note: this must be require, not require.resolve, due to https://github.com/nodejs/node/issues/43274
30
+ var requireFunc = function () { require(mod); }; // eslint-disable-line no-loop-func
31
+ t.comment(mod + ': ' + resolve.core[mod]);
32
+ if (resolve.core[mod]) {
33
+ st.doesNotThrow(requireFunc, mod + ' supported; requiring does not throw');
34
+ } else if (brokenNode) {
35
+ st.ok(true, 'this version of node is broken: attempting to require things that fail to resolve breaks "home_paths" tests');
36
+ } else {
37
+ st.throws(requireFunc, mod + ' not supported; requiring throws');
38
+ }
39
+ }
40
+
41
+ st.end();
42
+ });
43
+
44
+ t.test('core via repl module', { skip: !resolve.core.repl }, function (st) {
45
+ var libs = require('repl')._builtinLibs; // eslint-disable-line no-underscore-dangle
46
+ if (!libs) {
47
+ st.skip('module.builtinModules does not exist');
48
+ return st.end();
49
+ }
50
+ for (var i = 0; i < libs.length; ++i) {
51
+ var mod = libs[i];
52
+ st.ok(resolve.core[mod], mod + ' is a core module');
53
+ st.doesNotThrow(
54
+ function () { require(mod); }, // eslint-disable-line no-loop-func
55
+ 'requiring ' + mod + ' does not throw'
56
+ );
57
+ }
58
+ st.end();
59
+ });
60
+
61
+ t.test('core via builtinModules list', { skip: !resolve.core.module }, function (st) {
62
+ var libs = require('module').builtinModules;
63
+ if (!libs) {
64
+ st.skip('module.builtinModules does not exist');
65
+ return st.end();
66
+ }
67
+ var blacklist = [
68
+ '_debug_agent',
69
+ 'v8/tools/tickprocessor-driver',
70
+ 'v8/tools/SourceMap',
71
+ 'v8/tools/tickprocessor',
72
+ 'v8/tools/profile'
73
+ ];
74
+ for (var i = 0; i < libs.length; ++i) {
75
+ var mod = libs[i];
76
+ if (blacklist.indexOf(mod) === -1) {
77
+ st.ok(resolve.core[mod], mod + ' is a core module');
78
+ st.doesNotThrow(
79
+ function () { require(mod); }, // eslint-disable-line no-loop-func
80
+ 'requiring ' + mod + ' does not throw'
81
+ );
82
+ }
83
+ }
84
+ st.end();
85
+ });
86
+
87
+ t.end();
88
+ });
node_modules/resolve/test/default_paths.js ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var test = require('tape');
5
+ var mockProperty = require('mock-property');
6
+
7
+ var homedirPath = require.resolve('../lib/homedir');
8
+ var asyncPath = require.resolve('../async');
9
+ var libAsyncPath = require.resolve('../lib/async');
10
+ var syncPath = require.resolve('../sync');
11
+ var libSyncPath = require.resolve('../lib/sync');
12
+
13
+ function mockNullHomedir(t) {
14
+ t.teardown(mockProperty(require.cache, homedirPath, {
15
+ value: { id: homedirPath, filename: homedirPath, loaded: true, exports: function () { return null; } }
16
+ }));
17
+ }
18
+
19
+ test('async: null homedir does not throw', function (t) {
20
+ t.plan(2);
21
+
22
+ mockNullHomedir(t);
23
+ t.teardown(mockProperty(require.cache, asyncPath, { 'delete': true }));
24
+ t.teardown(mockProperty(require.cache, libAsyncPath, { 'delete': true }));
25
+
26
+ var resolve = require('../lib/async');
27
+
28
+ var dir = path.join(__dirname, 'resolver');
29
+
30
+ resolve('./baz', { basedir: dir }, function (err, res) {
31
+ t.error(err, 'no error');
32
+ t.equal(res, path.join(dir, 'baz', 'quux.js'), 'resolves correctly with null homedir');
33
+ });
34
+ });
35
+
36
+ test('sync: null homedir does not throw', function (t) {
37
+ mockNullHomedir(t);
38
+ t.teardown(mockProperty(require.cache, syncPath, { 'delete': true }));
39
+ t.teardown(mockProperty(require.cache, libSyncPath, { 'delete': true }));
40
+
41
+ var resolveSync = require('../lib/sync');
42
+
43
+ var dir = path.join(__dirname, 'resolver');
44
+
45
+ var res = resolveSync('./baz', { basedir: dir });
46
+ t.equal(res, path.join(dir, 'baz', 'quux.js'), 'resolves correctly with null homedir');
47
+
48
+ t.end();
49
+ });
node_modules/resolve/test/dotdot.js ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var path = require('path');
2
+ var test = require('tape');
3
+ var resolve = require('../');
4
+
5
+ test('dotdot', function (t) {
6
+ t.plan(4);
7
+ var dir = path.join(__dirname, '/dotdot/abc');
8
+
9
+ resolve('..', { basedir: dir }, function (err, res, pkg) {
10
+ t.ifError(err);
11
+ t.equal(res, path.join(__dirname, 'dotdot/index.js'));
12
+ });
13
+
14
+ resolve('.', { basedir: dir }, function (err, res, pkg) {
15
+ t.ifError(err);
16
+ t.equal(res, path.join(dir, 'index.js'));
17
+ });
18
+ });
19
+
20
+ test('dotdot sync', function (t) {
21
+ t.plan(2);
22
+ var dir = path.join(__dirname, '/dotdot/abc');
23
+
24
+ var a = resolve.sync('..', { basedir: dir });
25
+ t.equal(a, path.join(__dirname, 'dotdot/index.js'));
26
+
27
+ var b = resolve.sync('.', { basedir: dir });
28
+ t.equal(b, path.join(dir, 'index.js'));
29
+ });
node_modules/resolve/test/dotdot/abc/index.js ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ var x = require('..');
2
+ console.log(x);
node_modules/resolve/test/dotdot/index.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = 'whatever';
node_modules/resolve/test/faulty_basedir.js ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var test = require('tape');
2
+ var path = require('path');
3
+ var resolve = require('../');
4
+
5
+ test('faulty basedir must produce error in windows', { skip: process.platform !== 'win32' }, function (t) {
6
+ t.plan(1);
7
+
8
+ var resolverDir = 'C:\\a\\b\\c\\d';
9
+
10
+ resolve('tape/lib/test.js', { basedir: resolverDir }, function (err, res, pkg) {
11
+ t.equal(!!err, true);
12
+ });
13
+ });
14
+
15
+ test('non-existent basedir should not throw when preserveSymlinks is false', function (t) {
16
+ t.plan(2);
17
+
18
+ var opts = {
19
+ basedir: path.join(path.sep, 'unreal', 'path', 'that', 'does', 'not', 'exist'),
20
+ preserveSymlinks: false
21
+ };
22
+
23
+ var module = './dotdot/abc';
24
+
25
+ resolve(module, opts, function (err, res) {
26
+ t.equal(err.code, 'MODULE_NOT_FOUND');
27
+ t.equal(res, undefined);
28
+ });
29
+ });
node_modules/resolve/test/filter.js ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var path = require('path');
2
+ var test = require('tape');
3
+ var resolve = require('../');
4
+
5
+ test('filter', function (t) {
6
+ t.plan(4);
7
+ var dir = path.join(__dirname, 'resolver');
8
+ var packageFilterArgs;
9
+ resolve('./baz', {
10
+ basedir: dir,
11
+ packageFilter: function (pkg, pkgfile) {
12
+ pkg.main = 'doom'; // eslint-disable-line no-param-reassign
13
+ packageFilterArgs = [pkg, pkgfile];
14
+ return pkg;
15
+ }
16
+ }, function (err, res, pkg) {
17
+ if (err) t.fail(err);
18
+
19
+ t.equal(res, path.join(dir, 'baz/doom.js'), 'changing the package "main" works');
20
+
21
+ var packageData = packageFilterArgs[0];
22
+ t.equal(pkg, packageData, 'first packageFilter argument is "pkg"');
23
+ t.equal(packageData.main, 'doom', 'package "main" was altered');
24
+
25
+ var packageFile = packageFilterArgs[1];
26
+ t.equal(
27
+ packageFile,
28
+ path.join(dir, 'baz/package.json'),
29
+ 'second packageFilter argument is "pkgfile"'
30
+ );
31
+
32
+ t.end();
33
+ });
34
+ });
node_modules/resolve/test/filter_sync.js ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var path = require('path');
2
+ var test = require('tape');
3
+ var resolve = require('../');
4
+
5
+ test('filter', function (t) {
6
+ var dir = path.join(__dirname, 'resolver');
7
+ var packageFilterArgs;
8
+ var res = resolve.sync('./baz', {
9
+ basedir: dir,
10
+ // NOTE: in v2.x, this will be `pkg, pkgfile, dir`, but must remain "broken" here in v1.x for compatibility
11
+ packageFilter: function (pkg, /*pkgfile,*/ dir) { // eslint-disable-line spaced-comment
12
+ pkg.main = 'doom'; // eslint-disable-line no-param-reassign
13
+ packageFilterArgs = 'is 1.x' ? [pkg, dir] : [pkg, pkgfile, dir]; // eslint-disable-line no-constant-condition, no-undef
14
+ return pkg;
15
+ }
16
+ });
17
+
18
+ t.equal(res, path.join(dir, 'baz/doom.js'), 'changing the package "main" works');
19
+
20
+ var packageData = packageFilterArgs[0];
21
+ t.equal(packageData.main, 'doom', 'package "main" was altered');
22
+
23
+ if (!'is 1.x') { // eslint-disable-line no-constant-condition
24
+ var packageFile = packageFilterArgs[1];
25
+ t.equal(packageFile, path.join(dir, 'baz', 'package.json'), 'package.json path is correct');
26
+ }
27
+
28
+ var packageDir = packageFilterArgs['is 1.x' ? 1 : 2]; // eslint-disable-line no-constant-condition
29
+ // eslint-disable-next-line no-constant-condition
30
+ t.equal(packageDir, path.join(dir, 'baz'), ('is 1.x' ? 'second' : 'third') + ' packageFilter argument is "dir"');
31
+
32
+ t.end();
33
+ });
node_modules/resolve/test/home_paths.js ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var homedir = require('../lib/homedir');
5
+ var path = require('path');
6
+
7
+ var test = require('tape');
8
+ var mkdirp = require('mkdirp');
9
+ var rimraf = require('rimraf');
10
+ var mv = require('mv');
11
+ var copyDir = require('copy-dir');
12
+ var tmp = require('tmp');
13
+
14
+ var HOME = homedir();
15
+
16
+ var hnm = path.join(HOME, '.node_modules');
17
+ var hnl = path.join(HOME, '.node_libraries');
18
+
19
+ var resolve = require('../async');
20
+
21
+ function makeDir(t, dir, cb) {
22
+ mkdirp(dir, function (err) {
23
+ if (err) {
24
+ cb(err);
25
+ } else {
26
+ t.teardown(function cleanup() {
27
+ rimraf.sync(dir);
28
+ });
29
+ cb();
30
+ }
31
+ });
32
+ }
33
+
34
+ function makeTempDir(t, dir, cb) {
35
+ if (fs.existsSync(dir)) {
36
+ var tmpResult = tmp.dirSync();
37
+ t.teardown(tmpResult.removeCallback);
38
+ var backup = path.join(tmpResult.name, path.basename(dir));
39
+ mv(dir, backup, function (err) {
40
+ if (err) {
41
+ cb(err);
42
+ } else {
43
+ t.teardown(function () {
44
+ mv(backup, dir, cb);
45
+ });
46
+ makeDir(t, dir, cb);
47
+ }
48
+ });
49
+ } else {
50
+ makeDir(t, dir, cb);
51
+ }
52
+ }
53
+
54
+ test('homedir module paths', function (t) {
55
+ t.plan(7);
56
+
57
+ makeTempDir(t, hnm, function (err) {
58
+ t.error(err, 'no error with HNM temp dir');
59
+ if (err) {
60
+ return t.end();
61
+ }
62
+
63
+ var bazHNMDir = path.join(hnm, 'baz');
64
+ var dotMainDir = path.join(hnm, 'dot_main');
65
+ copyDir.sync(path.join(__dirname, 'resolver/baz'), bazHNMDir);
66
+ copyDir.sync(path.join(__dirname, 'resolver/dot_main'), dotMainDir);
67
+
68
+ var bazPkg = { name: 'baz', main: 'quux.js' };
69
+ var dotMainPkg = { main: 'index' };
70
+
71
+ var bazHNMmain = path.join(bazHNMDir, 'quux.js');
72
+ t.equal(require.resolve('baz'), bazHNMmain, 'sanity check: require.resolve finds HNM `baz`');
73
+ var dotMainMain = path.join(dotMainDir, 'index.js');
74
+ t.equal(require.resolve('dot_main'), dotMainMain, 'sanity check: require.resolve finds `dot_main`');
75
+
76
+ makeTempDir(t, hnl, function (err) {
77
+ t.error(err, 'no error with HNL temp dir');
78
+ if (err) {
79
+ return t.end();
80
+ }
81
+ var bazHNLDir = path.join(hnl, 'baz');
82
+ copyDir.sync(path.join(__dirname, 'resolver/baz'), bazHNLDir);
83
+
84
+ var dotSlashMainDir = path.join(hnl, 'dot_slash_main');
85
+ var dotSlashMainMain = path.join(dotSlashMainDir, 'index.js');
86
+ var dotSlashMainPkg = { main: 'index' };
87
+ copyDir.sync(path.join(__dirname, 'resolver/dot_slash_main'), dotSlashMainDir);
88
+
89
+ t.equal(require.resolve('baz'), bazHNMmain, 'sanity check: require.resolve finds HNM `baz`');
90
+ t.equal(require.resolve('dot_slash_main'), dotSlashMainMain, 'sanity check: require.resolve finds HNL `dot_slash_main`');
91
+
92
+ t.test('with temp dirs', function (st) {
93
+ st.plan(3);
94
+
95
+ st.test('just in `$HOME/.node_modules`', function (s2t) {
96
+ s2t.plan(3);
97
+
98
+ resolve('dot_main', function (err, res, pkg) {
99
+ s2t.error(err, 'no error resolving `dot_main`');
100
+ s2t.equal(res, dotMainMain, '`dot_main` resolves in `$HOME/.node_modules`');
101
+ s2t.deepEqual(pkg, dotMainPkg);
102
+ });
103
+ });
104
+
105
+ st.test('just in `$HOME/.node_libraries`', function (s2t) {
106
+ s2t.plan(3);
107
+
108
+ resolve('dot_slash_main', function (err, res, pkg) {
109
+ s2t.error(err, 'no error resolving `dot_slash_main`');
110
+ s2t.equal(res, dotSlashMainMain, '`dot_slash_main` resolves in `$HOME/.node_libraries`');
111
+ s2t.deepEqual(pkg, dotSlashMainPkg);
112
+ });
113
+ });
114
+
115
+ st.test('in `$HOME/.node_libraries` and `$HOME/.node_modules`', function (s2t) {
116
+ s2t.plan(3);
117
+
118
+ resolve('baz', function (err, res, pkg) {
119
+ s2t.error(err, 'no error resolving `baz`');
120
+ s2t.equal(res, bazHNMmain, '`baz` resolves in `$HOME/.node_modules` when in both');
121
+ s2t.deepEqual(pkg, bazPkg);
122
+ });
123
+ });
124
+ });
125
+ });
126
+ });
127
+ });
node_modules/resolve/test/home_paths_sync.js ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var homedir = require('../lib/homedir');
5
+ var path = require('path');
6
+
7
+ var test = require('tape');
8
+ var mkdirp = require('mkdirp');
9
+ var rimraf = require('rimraf');
10
+ var mv = require('mv');
11
+ var copyDir = require('copy-dir');
12
+ var tmp = require('tmp');
13
+
14
+ var HOME = homedir();
15
+
16
+ var hnm = path.join(HOME, '.node_modules');
17
+ var hnl = path.join(HOME, '.node_libraries');
18
+
19
+ var resolve = require('../sync');
20
+
21
+ function makeDir(t, dir, cb) {
22
+ mkdirp(dir, function (err) {
23
+ if (err) {
24
+ cb(err);
25
+ } else {
26
+ t.teardown(function cleanup() {
27
+ rimraf.sync(dir);
28
+ });
29
+ cb();
30
+ }
31
+ });
32
+ }
33
+
34
+ function makeTempDir(t, dir, cb) {
35
+ if (fs.existsSync(dir)) {
36
+ var tmpResult = tmp.dirSync();
37
+ t.teardown(tmpResult.removeCallback);
38
+ var backup = path.join(tmpResult.name, path.basename(dir));
39
+ mv(dir, backup, function (err) {
40
+ if (err) {
41
+ cb(err);
42
+ } else {
43
+ t.teardown(function () {
44
+ mv(backup, dir, cb);
45
+ });
46
+ makeDir(t, dir, cb);
47
+ }
48
+ });
49
+ } else {
50
+ makeDir(t, dir, cb);
51
+ }
52
+ }
53
+
54
+ test('homedir module paths', function (t) {
55
+ t.plan(7);
56
+
57
+ makeTempDir(t, hnm, function (err) {
58
+ t.error(err, 'no error with HNM temp dir');
59
+ if (err) {
60
+ return t.end();
61
+ }
62
+
63
+ var bazHNMDir = path.join(hnm, 'baz');
64
+ var dotMainDir = path.join(hnm, 'dot_main');
65
+ copyDir.sync(path.join(__dirname, 'resolver/baz'), bazHNMDir);
66
+ copyDir.sync(path.join(__dirname, 'resolver/dot_main'), dotMainDir);
67
+
68
+ var bazHNMmain = path.join(bazHNMDir, 'quux.js');
69
+ t.equal(require.resolve('baz'), bazHNMmain, 'sanity check: require.resolve finds HNM `baz`');
70
+ var dotMainMain = path.join(dotMainDir, 'index.js');
71
+ t.equal(require.resolve('dot_main'), dotMainMain, 'sanity check: require.resolve finds `dot_main`');
72
+
73
+ makeTempDir(t, hnl, function (err) {
74
+ t.error(err, 'no error with HNL temp dir');
75
+ if (err) {
76
+ return t.end();
77
+ }
78
+ var bazHNLDir = path.join(hnl, 'baz');
79
+ copyDir.sync(path.join(__dirname, 'resolver/baz'), bazHNLDir);
80
+
81
+ var dotSlashMainDir = path.join(hnl, 'dot_slash_main');
82
+ var dotSlashMainMain = path.join(dotSlashMainDir, 'index.js');
83
+ copyDir.sync(path.join(__dirname, 'resolver/dot_slash_main'), dotSlashMainDir);
84
+
85
+ t.equal(require.resolve('baz'), bazHNMmain, 'sanity check: require.resolve finds HNM `baz`');
86
+ t.equal(require.resolve('dot_slash_main'), dotSlashMainMain, 'sanity check: require.resolve finds HNL `dot_slash_main`');
87
+
88
+ t.test('with temp dirs', function (st) {
89
+ st.plan(3);
90
+
91
+ st.test('just in `$HOME/.node_modules`', function (s2t) {
92
+ s2t.plan(1);
93
+
94
+ var res = resolve('dot_main');
95
+ s2t.equal(res, dotMainMain, '`dot_main` resolves in `$HOME/.node_modules`');
96
+ });
97
+
98
+ st.test('just in `$HOME/.node_libraries`', function (s2t) {
99
+ s2t.plan(1);
100
+
101
+ var res = resolve('dot_slash_main');
102
+ s2t.equal(res, dotSlashMainMain, '`dot_slash_main` resolves in `$HOME/.node_libraries`');
103
+ });
104
+
105
+ st.test('in `$HOME/.node_libraries` and `$HOME/.node_modules`', function (s2t) {
106
+ s2t.plan(1);
107
+
108
+ var res = resolve('baz');
109
+ s2t.equal(res, bazHNMmain, '`baz` resolves in `$HOME/.node_modules` when in both');
110
+ });
111
+ });
112
+ });
113
+ });
114
+ });
node_modules/resolve/test/homedir.js ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 'use strict';
2
+
3
+ var os = require('os');
4
+ var test = require('tape');
5
+ var mockProperty = require('mock-property');
6
+
7
+ var envKeys = ['HOME', 'USERPROFILE', 'HOMEDRIVE', 'HOMEPATH', 'LOGNAME', 'USER', 'LNAME', 'USERNAME'];
8
+
9
+ function mockEnv(t, key, value) {
10
+ var has = key in process.env;
11
+ var orig = process.env[key];
12
+ if (arguments.length > 2) {
13
+ process.env[key] = value;
14
+ } else {
15
+ delete process.env[key];
16
+ }
17
+ t.teardown(function () {
18
+ if (has) {
19
+ process.env[key] = orig;
20
+ } else {
21
+ delete process.env[key];
22
+ }
23
+ });
24
+ }
25
+
26
+ function clearEnv(t) {
27
+ for (var i = 0; i < envKeys.length; i++) {
28
+ mockEnv(t, envKeys[i]);
29
+ }
30
+ }
31
+
32
+ function getFallback(t) {
33
+ t.teardown(mockProperty(os, 'homedir', { value: undefined }));
34
+
35
+ var homedirPath = require.resolve('../lib/homedir');
36
+ t.teardown(mockProperty(require.cache, homedirPath, { 'delete': true }));
37
+
38
+ return require('../lib/homedir');
39
+ }
40
+
41
+ test('homedir fallback', function (t) {
42
+ t.test('win32: HOMEDRIVE without HOMEPATH does not produce a false concatenation', function (st) {
43
+ clearEnv(st);
44
+ st.teardown(mockProperty(process, 'platform', { value: 'win32' }));
45
+
46
+ var homedir = getFallback(st);
47
+
48
+ mockEnv(st, 'HOMEDRIVE', 'C:');
49
+
50
+ st.equal(homedir(), null, 'returns null when only HOMEDRIVE is set');
51
+
52
+ st.end();
53
+ });
54
+
55
+ t.test('win32: HOMEPATH without HOMEDRIVE does not produce a false concatenation', function (st) {
56
+ clearEnv(st);
57
+ st.teardown(mockProperty(process, 'platform', { value: 'win32' }));
58
+
59
+ var homedir = getFallback(st);
60
+
61
+ mockEnv(st, 'HOMEPATH', '\\Users\\foo');
62
+
63
+ st.equal(homedir(), null, 'returns null when only HOMEPATH is set');
64
+
65
+ st.end();
66
+ });
67
+
68
+ t.test('win32: HOMEDRIVE + HOMEPATH both set returns concatenation', function (st) {
69
+ clearEnv(st);
70
+ st.teardown(mockProperty(process, 'platform', { value: 'win32' }));
71
+
72
+ var homedir = getFallback(st);
73
+
74
+ mockEnv(st, 'HOMEDRIVE', 'C:');
75
+ mockEnv(st, 'HOMEPATH', '\\Users\\foo');
76
+
77
+ st.equal(homedir(), 'C:\\Users\\foo', 'returns concatenated drive and path');
78
+
79
+ st.end();
80
+ });
81
+
82
+ t.test('win32: USERPROFILE takes precedence over HOMEDRIVE+HOMEPATH', function (st) {
83
+ clearEnv(st);
84
+ st.teardown(mockProperty(process, 'platform', { value: 'win32' }));
85
+
86
+ var homedir = getFallback(st);
87
+
88
+ mockEnv(st, 'USERPROFILE', 'C:\\Users\\bar');
89
+ mockEnv(st, 'HOMEDRIVE', 'C:');
90
+ mockEnv(st, 'HOMEPATH', '\\Users\\foo');
91
+
92
+ st.equal(homedir(), 'C:\\Users\\bar', 'returns USERPROFILE');
93
+
94
+ st.end();
95
+ });
96
+
97
+ t.test('win32: falls back to HOME when HOMEDRIVE/HOMEPATH are partial', function (st) {
98
+ clearEnv(st);
99
+ st.teardown(mockProperty(process, 'platform', { value: 'win32' }));
100
+
101
+ var homedir = getFallback(st);
102
+
103
+ mockEnv(st, 'HOME', 'C:\\Users\\baz');
104
+ mockEnv(st, 'HOMEDRIVE', 'C:');
105
+
106
+ st.equal(homedir(), 'C:\\Users\\baz', 'falls back to HOME');
107
+
108
+ st.end();
109
+ });
110
+
111
+ t.end();
112
+ });
node_modules/resolve/test/mock.js ADDED
@@ -0,0 +1,353 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var path = require('path');
2
+ var test = require('tape');
3
+ var resolve = require('../');
4
+
5
+ test('mock', function (t) {
6
+ t.plan(8);
7
+
8
+ var files = {};
9
+ files[path.resolve('/foo/bar/baz.js')] = 'beep';
10
+
11
+ var dirs = {};
12
+ dirs[path.resolve('/foo/bar')] = true;
13
+
14
+ function opts(basedir) {
15
+ return {
16
+ basedir: path.resolve(basedir),
17
+ isFile: function (file, cb) {
18
+ cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file)));
19
+ },
20
+ isDirectory: function (dir, cb) {
21
+ cb(null, !!dirs[path.resolve(dir)]);
22
+ },
23
+ readFile: function (file, cb) {
24
+ cb(null, files[path.resolve(file)]);
25
+ },
26
+ realpath: function (file, cb) {
27
+ cb(null, file);
28
+ }
29
+ };
30
+ }
31
+
32
+ resolve('./baz', opts('/foo/bar'), function (err, res, pkg) {
33
+ if (err) return t.fail(err);
34
+ t.equal(res, path.resolve('/foo/bar/baz.js'));
35
+ t.equal(pkg, undefined);
36
+ });
37
+
38
+ resolve('./baz.js', opts('/foo/bar'), function (err, res, pkg) {
39
+ if (err) return t.fail(err);
40
+ t.equal(res, path.resolve('/foo/bar/baz.js'));
41
+ t.equal(pkg, undefined);
42
+ });
43
+
44
+ resolve('baz', opts('/foo/bar'), function (err, res) {
45
+ t.equal(err.message, "Cannot find module 'baz' from '" + path.resolve('/foo/bar') + "'");
46
+ t.equal(err.code, 'MODULE_NOT_FOUND');
47
+ });
48
+
49
+ resolve('../baz', opts('/foo/bar'), function (err, res) {
50
+ t.equal(err.message, "Cannot find module '../baz' from '" + path.resolve('/foo/bar') + "'");
51
+ t.equal(err.code, 'MODULE_NOT_FOUND');
52
+ });
53
+ });
54
+
55
+ test('mock from package', function (t) {
56
+ t.plan(8);
57
+
58
+ var files = {};
59
+ files[path.resolve('/foo/bar/baz.js')] = 'beep';
60
+
61
+ var dirs = {};
62
+ dirs[path.resolve('/foo/bar')] = true;
63
+
64
+ function opts(basedir) {
65
+ return {
66
+ basedir: path.resolve(basedir),
67
+ isFile: function (file, cb) {
68
+ cb(null, Object.prototype.hasOwnProperty.call(files, file));
69
+ },
70
+ isDirectory: function (dir, cb) {
71
+ cb(null, !!dirs[path.resolve(dir)]);
72
+ },
73
+ 'package': { main: 'bar' },
74
+ readFile: function (file, cb) {
75
+ cb(null, files[file]);
76
+ },
77
+ realpath: function (file, cb) {
78
+ cb(null, file);
79
+ }
80
+ };
81
+ }
82
+
83
+ resolve('./baz', opts('/foo/bar'), function (err, res, pkg) {
84
+ if (err) return t.fail(err);
85
+ t.equal(res, path.resolve('/foo/bar/baz.js'));
86
+ t.equal(pkg && pkg.main, 'bar');
87
+ });
88
+
89
+ resolve('./baz.js', opts('/foo/bar'), function (err, res, pkg) {
90
+ if (err) return t.fail(err);
91
+ t.equal(res, path.resolve('/foo/bar/baz.js'));
92
+ t.equal(pkg && pkg.main, 'bar');
93
+ });
94
+
95
+ resolve('baz', opts('/foo/bar'), function (err, res) {
96
+ t.equal(err.message, "Cannot find module 'baz' from '" + path.resolve('/foo/bar') + "'");
97
+ t.equal(err.code, 'MODULE_NOT_FOUND');
98
+ });
99
+
100
+ resolve('../baz', opts('/foo/bar'), function (err, res) {
101
+ t.equal(err.message, "Cannot find module '../baz' from '" + path.resolve('/foo/bar') + "'");
102
+ t.equal(err.code, 'MODULE_NOT_FOUND');
103
+ });
104
+ });
105
+
106
+ test('mock package', function (t) {
107
+ t.plan(2);
108
+
109
+ var files = {};
110
+ files[path.resolve('/foo/node_modules/bar/baz.js')] = 'beep';
111
+ files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({
112
+ main: './baz.js'
113
+ });
114
+
115
+ var dirs = {};
116
+ dirs[path.resolve('/foo')] = true;
117
+ dirs[path.resolve('/foo/node_modules')] = true;
118
+
119
+ function opts(basedir) {
120
+ return {
121
+ basedir: path.resolve(basedir),
122
+ isFile: function (file, cb) {
123
+ cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file)));
124
+ },
125
+ isDirectory: function (dir, cb) {
126
+ cb(null, !!dirs[path.resolve(dir)]);
127
+ },
128
+ readFile: function (file, cb) {
129
+ cb(null, files[path.resolve(file)]);
130
+ },
131
+ realpath: function (file, cb) {
132
+ cb(null, file);
133
+ }
134
+ };
135
+ }
136
+
137
+ resolve('bar', opts('/foo'), function (err, res, pkg) {
138
+ if (err) return t.fail(err);
139
+ t.equal(res, path.resolve('/foo/node_modules/bar/baz.js'));
140
+ t.equal(pkg && pkg.main, './baz.js');
141
+ });
142
+ });
143
+
144
+ test('mock package from package', function (t) {
145
+ t.plan(2);
146
+
147
+ var files = {};
148
+ files[path.resolve('/foo/node_modules/bar/baz.js')] = 'beep';
149
+ files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({
150
+ main: './baz.js'
151
+ });
152
+
153
+ var dirs = {};
154
+ dirs[path.resolve('/foo')] = true;
155
+ dirs[path.resolve('/foo/node_modules')] = true;
156
+
157
+ function opts(basedir) {
158
+ return {
159
+ basedir: path.resolve(basedir),
160
+ isFile: function (file, cb) {
161
+ cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file)));
162
+ },
163
+ isDirectory: function (dir, cb) {
164
+ cb(null, !!dirs[path.resolve(dir)]);
165
+ },
166
+ 'package': { main: 'bar' },
167
+ readFile: function (file, cb) {
168
+ cb(null, files[path.resolve(file)]);
169
+ },
170
+ realpath: function (file, cb) {
171
+ cb(null, file);
172
+ }
173
+ };
174
+ }
175
+
176
+ resolve('bar', opts('/foo'), function (err, res, pkg) {
177
+ if (err) return t.fail(err);
178
+ t.equal(res, path.resolve('/foo/node_modules/bar/baz.js'));
179
+ t.equal(pkg && pkg.main, './baz.js');
180
+ });
181
+ });
182
+
183
+ test('symlinked', function (t) {
184
+ t.plan(4);
185
+
186
+ var files = {};
187
+ files[path.resolve('/foo/bar/baz.js')] = 'beep';
188
+ files[path.resolve('/foo/bar/symlinked/baz.js')] = 'beep';
189
+
190
+ var dirs = {};
191
+ dirs[path.resolve('/foo/bar')] = true;
192
+ dirs[path.resolve('/foo/bar/symlinked')] = true;
193
+
194
+ function opts(basedir) {
195
+ return {
196
+ preserveSymlinks: false,
197
+ basedir: path.resolve(basedir),
198
+ isFile: function (file, cb) {
199
+ cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file)));
200
+ },
201
+ isDirectory: function (dir, cb) {
202
+ cb(null, !!dirs[path.resolve(dir)]);
203
+ },
204
+ readFile: function (file, cb) {
205
+ cb(null, files[path.resolve(file)]);
206
+ },
207
+ realpath: function (file, cb) {
208
+ var resolved = path.resolve(file);
209
+
210
+ if (resolved.indexOf('symlinked') >= 0) {
211
+ cb(null, resolved);
212
+ return;
213
+ }
214
+
215
+ var ext = path.extname(resolved);
216
+
217
+ if (ext) {
218
+ var dir = path.dirname(resolved);
219
+ var base = path.basename(resolved);
220
+ cb(null, path.join(dir, 'symlinked', base));
221
+ } else {
222
+ cb(null, path.join(resolved, 'symlinked'));
223
+ }
224
+ }
225
+ };
226
+ }
227
+
228
+ resolve('./baz', opts('/foo/bar'), function (err, res, pkg) {
229
+ if (err) return t.fail(err);
230
+ t.equal(res, path.resolve('/foo/bar/symlinked/baz.js'));
231
+ t.equal(pkg, undefined);
232
+ });
233
+
234
+ resolve('./baz.js', opts('/foo/bar'), function (err, res, pkg) {
235
+ if (err) return t.fail(err);
236
+ t.equal(res, path.resolve('/foo/bar/symlinked/baz.js'));
237
+ t.equal(pkg, undefined);
238
+ });
239
+ });
240
+
241
+ test('readPackage', function (t) {
242
+ t.plan(4);
243
+
244
+ var files = {};
245
+ files[path.resolve('/foo/node_modules/bar/something-else.js')] = 'beep';
246
+ files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({
247
+ main: './baz.js'
248
+ });
249
+ files[path.resolve('/foo/node_modules/bar/baz.js')] = 'boop';
250
+
251
+ var dirs = {};
252
+ dirs[path.resolve('/foo')] = true;
253
+ dirs[path.resolve('/foo/node_modules')] = true;
254
+
255
+ function opts(basedir) {
256
+ return {
257
+ basedir: path.resolve(basedir),
258
+ isFile: function (file, cb) {
259
+ cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file)));
260
+ },
261
+ isDirectory: function (dir, cb) {
262
+ cb(null, !!dirs[path.resolve(dir)]);
263
+ },
264
+ 'package': { main: 'bar' },
265
+ readFile: function (file, cb) {
266
+ cb(null, files[path.resolve(file)]);
267
+ },
268
+ realpath: function (file, cb) {
269
+ cb(null, file);
270
+ }
271
+ };
272
+ }
273
+
274
+ t.test('with readFile', function (st) {
275
+ st.plan(3);
276
+
277
+ resolve('bar', opts('/foo'), function (err, res, pkg) {
278
+ st.error(err);
279
+ st.equal(res, path.resolve('/foo/node_modules/bar/baz.js'));
280
+ st.equal(pkg && pkg.main, './baz.js');
281
+ });
282
+ });
283
+
284
+ function readPackage(readFile, file, cb) {
285
+ var barPackage = path.join('bar', 'package.json');
286
+ if (file.slice(-barPackage.length) === barPackage) {
287
+ cb(null, { main: './something-else.js' });
288
+ } else {
289
+ cb(null, JSON.parse(files[path.resolve(file)]));
290
+ }
291
+ }
292
+
293
+ t.test('with readPackage', function (st) {
294
+ st.plan(3);
295
+
296
+ var options = opts('/foo');
297
+ delete options.readFile;
298
+ options.readPackage = readPackage;
299
+ resolve('bar', options, function (err, res, pkg) {
300
+ st.error(err);
301
+ st.equal(res, path.resolve('/foo/node_modules/bar/something-else.js'));
302
+ st.equal(pkg && pkg.main, './something-else.js');
303
+ });
304
+ });
305
+
306
+ t.test('with readFile and readPackage', function (st) {
307
+ st.plan(1);
308
+
309
+ var options = opts('/foo');
310
+ options.readPackage = readPackage;
311
+ resolve('bar', options, function (err) {
312
+ st.throws(function () { throw err; }, TypeError, 'errors when both readFile and readPackage are provided');
313
+ });
314
+ });
315
+
316
+ t.test('readPackage error in loadpkg does not invoke callback twice', function (st) {
317
+ st.plan(1);
318
+
319
+ var callCount = 0;
320
+ var readPackageError = new Error('read package error');
321
+
322
+ function failReadPackage(rf, file, cb) {
323
+ cb(readPackageError);
324
+ }
325
+
326
+ var relFiles = {};
327
+ relFiles[path.resolve('/foo/bar/baz.js')] = 'beep';
328
+ relFiles[path.resolve('/foo/bar/package.json')] = '{}';
329
+
330
+ var relDirs = {};
331
+ relDirs[path.resolve('/foo/bar')] = true;
332
+
333
+ resolve('./baz', {
334
+ basedir: path.resolve('/foo/bar'),
335
+ isFile: function (file, cb) {
336
+ cb(null, Object.prototype.hasOwnProperty.call(relFiles, path.resolve(file)));
337
+ },
338
+ isDirectory: function (dir, cb) {
339
+ cb(null, !!relDirs[path.resolve(dir)]);
340
+ },
341
+ readPackage: failReadPackage,
342
+ realpath: function (file, cb) {
343
+ cb(null, file);
344
+ }
345
+ }, function () {
346
+ callCount += 1;
347
+ });
348
+
349
+ setTimeout(function () {
350
+ st.equal(callCount, 1, 'callback is invoked exactly once');
351
+ }, 50);
352
+ });
353
+ });
node_modules/resolve/test/mock_sync.js ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var path = require('path');
2
+ var test = require('tape');
3
+ var resolve = require('../');
4
+
5
+ test('mock', function (t) {
6
+ t.plan(4);
7
+
8
+ var files = {};
9
+ files[path.resolve('/foo/bar/baz.js')] = 'beep';
10
+
11
+ var dirs = {};
12
+ dirs[path.resolve('/foo/bar')] = true;
13
+
14
+ function opts(basedir) {
15
+ return {
16
+ basedir: path.resolve(basedir),
17
+ isFile: function (file) {
18
+ return Object.prototype.hasOwnProperty.call(files, path.resolve(file));
19
+ },
20
+ isDirectory: function (dir) {
21
+ return !!dirs[path.resolve(dir)];
22
+ },
23
+ readFileSync: function (file) {
24
+ return files[path.resolve(file)];
25
+ },
26
+ realpathSync: function (file) {
27
+ return file;
28
+ }
29
+ };
30
+ }
31
+
32
+ t.equal(
33
+ resolve.sync('./baz', opts('/foo/bar')),
34
+ path.resolve('/foo/bar/baz.js')
35
+ );
36
+
37
+ t.equal(
38
+ resolve.sync('./baz.js', opts('/foo/bar')),
39
+ path.resolve('/foo/bar/baz.js')
40
+ );
41
+
42
+ t.throws(function () {
43
+ resolve.sync('baz', opts('/foo/bar'));
44
+ });
45
+
46
+ t.throws(function () {
47
+ resolve.sync('../baz', opts('/foo/bar'));
48
+ });
49
+ });
50
+
51
+ test('mock package', function (t) {
52
+ t.plan(1);
53
+
54
+ var files = {};
55
+ files[path.resolve('/foo/node_modules/bar/baz.js')] = 'beep';
56
+ files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({
57
+ main: './baz.js'
58
+ });
59
+
60
+ var dirs = {};
61
+ dirs[path.resolve('/foo')] = true;
62
+ dirs[path.resolve('/foo/node_modules')] = true;
63
+
64
+ function opts(basedir) {
65
+ return {
66
+ basedir: path.resolve(basedir),
67
+ isFile: function (file) {
68
+ return Object.prototype.hasOwnProperty.call(files, path.resolve(file));
69
+ },
70
+ isDirectory: function (dir) {
71
+ return !!dirs[path.resolve(dir)];
72
+ },
73
+ readFileSync: function (file) {
74
+ return files[path.resolve(file)];
75
+ },
76
+ realpathSync: function (file) {
77
+ return file;
78
+ }
79
+ };
80
+ }
81
+
82
+ t.equal(
83
+ resolve.sync('bar', opts('/foo')),
84
+ path.resolve('/foo/node_modules/bar/baz.js')
85
+ );
86
+ });
87
+
88
+ test('symlinked', function (t) {
89
+ t.plan(2);
90
+
91
+ var files = {};
92
+ files[path.resolve('/foo/bar/baz.js')] = 'beep';
93
+ files[path.resolve('/foo/bar/symlinked/baz.js')] = 'beep';
94
+
95
+ var dirs = {};
96
+ dirs[path.resolve('/foo/bar')] = true;
97
+ dirs[path.resolve('/foo/bar/symlinked')] = true;
98
+
99
+ function opts(basedir) {
100
+ return {
101
+ preserveSymlinks: false,
102
+ basedir: path.resolve(basedir),
103
+ isFile: function (file) {
104
+ return Object.prototype.hasOwnProperty.call(files, path.resolve(file));
105
+ },
106
+ isDirectory: function (dir) {
107
+ return !!dirs[path.resolve(dir)];
108
+ },
109
+ readFileSync: function (file) {
110
+ return files[path.resolve(file)];
111
+ },
112
+ realpathSync: function (file) {
113
+ var resolved = path.resolve(file);
114
+
115
+ if (resolved.indexOf('symlinked') >= 0) {
116
+ return resolved;
117
+ }
118
+
119
+ var ext = path.extname(resolved);
120
+
121
+ if (ext) {
122
+ var dir = path.dirname(resolved);
123
+ var base = path.basename(resolved);
124
+ return path.join(dir, 'symlinked', base);
125
+ }
126
+ return path.join(resolved, 'symlinked');
127
+ }
128
+ };
129
+ }
130
+
131
+ t.equal(
132
+ resolve.sync('./baz', opts('/foo/bar')),
133
+ path.resolve('/foo/bar/symlinked/baz.js')
134
+ );
135
+
136
+ t.equal(
137
+ resolve.sync('./baz.js', opts('/foo/bar')),
138
+ path.resolve('/foo/bar/symlinked/baz.js')
139
+ );
140
+ });
141
+
142
+ test('readPackageSync', function (t) {
143
+ t.plan(4);
144
+
145
+ var files = {};
146
+ files[path.resolve('/foo/node_modules/bar/something-else.js')] = 'beep';
147
+ files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({
148
+ main: './baz.js'
149
+ });
150
+ files[path.resolve('/foo/node_modules/bar/baz.js')] = 'boop';
151
+
152
+ var dirs = {};
153
+ dirs[path.resolve('/foo')] = true;
154
+ dirs[path.resolve('/foo/node_modules')] = true;
155
+
156
+ function opts(basedir, useReadPackage) {
157
+ return {
158
+ basedir: path.resolve(basedir),
159
+ isFile: function (file) {
160
+ return Object.prototype.hasOwnProperty.call(files, path.resolve(file));
161
+ },
162
+ isDirectory: function (dir) {
163
+ return !!dirs[path.resolve(dir)];
164
+ },
165
+ readFileSync: useReadPackage ? null : function (file) {
166
+ return files[path.resolve(file)];
167
+ },
168
+ realpathSync: function (file) {
169
+ return file;
170
+ }
171
+ };
172
+ }
173
+ t.test('with readFile', function (st) {
174
+ st.plan(1);
175
+
176
+ st.equal(
177
+ resolve.sync('bar', opts('/foo')),
178
+ path.resolve('/foo/node_modules/bar/baz.js')
179
+ );
180
+ });
181
+
182
+ function readPackageSync(readFileSync, file) {
183
+ if (file.indexOf(path.join('bar', 'package.json')) >= 0) {
184
+ return { main: './something-else.js' };
185
+ }
186
+ return JSON.parse(files[path.resolve(file)]);
187
+ }
188
+
189
+ t.test('with readPackage', function (st) {
190
+ st.plan(1);
191
+
192
+ var options = opts('/foo');
193
+ delete options.readFileSync;
194
+ options.readPackageSync = readPackageSync;
195
+
196
+ st.equal(
197
+ resolve.sync('bar', options),
198
+ path.resolve('/foo/node_modules/bar/something-else.js')
199
+ );
200
+ });
201
+
202
+ t.test('with readFile and readPackage', function (st) {
203
+ st.plan(1);
204
+
205
+ var options = opts('/foo');
206
+ options.readPackageSync = readPackageSync;
207
+ st.throws(
208
+ function () { resolve.sync('bar', options); },
209
+ TypeError,
210
+ 'errors when both readFile and readPackage are provided'
211
+ );
212
+ });
213
+
214
+ t.test('readPackageSync error propagates correctly', function (st) {
215
+ st.plan(1);
216
+
217
+ var readPackageError = new Error('read package error');
218
+
219
+ function failReadPackageSync() {
220
+ throw readPackageError;
221
+ }
222
+
223
+ var options = opts('/foo');
224
+ delete options.readFileSync;
225
+ options.readPackageSync = failReadPackageSync;
226
+
227
+ st.throws(
228
+ function () { resolve.sync('bar', options); },
229
+ readPackageError,
230
+ 'readPackageSync error is thrown'
231
+ );
232
+ });
233
+ });
234
+
node_modules/resolve/test/module_dir.js ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var path = require('path');
2
+ var test = require('tape');
3
+ var resolve = require('../');
4
+
5
+ test('moduleDirectory strings', function (t) {
6
+ t.plan(4);
7
+ var dir = path.join(__dirname, 'module_dir');
8
+ var xopts = {
9
+ basedir: dir,
10
+ moduleDirectory: 'xmodules'
11
+ };
12
+ resolve('aaa', xopts, function (err, res, pkg) {
13
+ t.ifError(err);
14
+ t.equal(res, path.join(dir, '/xmodules/aaa/index.js'));
15
+ });
16
+
17
+ var yopts = {
18
+ basedir: dir,
19
+ moduleDirectory: 'ymodules'
20
+ };
21
+ resolve('aaa', yopts, function (err, res, pkg) {
22
+ t.ifError(err);
23
+ t.equal(res, path.join(dir, '/ymodules/aaa/index.js'));
24
+ });
25
+ });
26
+
27
+ test('moduleDirectory array', function (t) {
28
+ t.plan(6);
29
+ var dir = path.join(__dirname, 'module_dir');
30
+ var aopts = {
31
+ basedir: dir,
32
+ moduleDirectory: ['xmodules', 'ymodules', 'zmodules']
33
+ };
34
+ resolve('aaa', aopts, function (err, res, pkg) {
35
+ t.ifError(err);
36
+ t.equal(res, path.join(dir, '/xmodules/aaa/index.js'));
37
+ });
38
+
39
+ var bopts = {
40
+ basedir: dir,
41
+ moduleDirectory: ['zmodules', 'ymodules', 'xmodules']
42
+ };
43
+ resolve('aaa', bopts, function (err, res, pkg) {
44
+ t.ifError(err);
45
+ t.equal(res, path.join(dir, '/ymodules/aaa/index.js'));
46
+ });
47
+
48
+ var copts = {
49
+ basedir: dir,
50
+ moduleDirectory: ['xmodules', 'ymodules', 'zmodules']
51
+ };
52
+ resolve('bbb', copts, function (err, res, pkg) {
53
+ t.ifError(err);
54
+ t.equal(res, path.join(dir, '/zmodules/bbb/main.js'));
55
+ });
56
+ });
node_modules/resolve/test/module_dir/xmodules/aaa/index.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = function (x) { return x * 100; };
node_modules/resolve/test/module_dir/ymodules/aaa/index.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = function (x) { return x + 100; };
node_modules/resolve/test/module_dir/zmodules/bbb/main.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = function (n) { return n * 111; };
node_modules/resolve/test/module_dir/zmodules/bbb/package.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "main": "main.js"
3
+ }
node_modules/resolve/test/node-modules-paths.js ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var test = require('tape');
2
+ var path = require('path');
3
+ var parse = path.parse || require('path-parse');
4
+ var keys = require('object-keys');
5
+
6
+ var nodeModulesPaths = require('../lib/node-modules-paths');
7
+
8
+ function verifyDirs(t, start, dirs, moduleDirectories, paths) {
9
+ var moduleDirs = [].concat(moduleDirectories || 'node_modules');
10
+ if (paths) {
11
+ for (var k = 0; k < paths.length; ++k) {
12
+ moduleDirs.push(path.basename(paths[k]));
13
+ }
14
+ }
15
+
16
+ var foundModuleDirs = {};
17
+ var uniqueDirs = {};
18
+ var parsedDirs = {};
19
+ for (var i = 0; i < dirs.length; ++i) {
20
+ var parsed = parse(dirs[i]);
21
+ if (!foundModuleDirs[parsed.base]) { foundModuleDirs[parsed.base] = 0; }
22
+ foundModuleDirs[parsed.base] += 1;
23
+ parsedDirs[parsed.dir] = true;
24
+ uniqueDirs[dirs[i]] = true;
25
+ }
26
+ t.equal(keys(parsedDirs).length >= start.split(path.sep).length, true, 'there are >= dirs than "start" has');
27
+ var foundModuleDirNames = keys(foundModuleDirs);
28
+ t.deepEqual(foundModuleDirNames, moduleDirs, 'all desired module dirs were found');
29
+ t.equal(keys(uniqueDirs).length, dirs.length, 'all dirs provided were unique');
30
+
31
+ var counts = {};
32
+ for (var j = 0; j < foundModuleDirNames.length; ++j) {
33
+ counts[foundModuleDirs[j]] = true;
34
+ }
35
+ t.equal(keys(counts).length, 1, 'all found module directories had the same count');
36
+ }
37
+
38
+ test('node-modules-paths', function (t) {
39
+ t.test('no options', function (t) {
40
+ var start = path.join(__dirname, 'resolver');
41
+ var dirs = nodeModulesPaths(start);
42
+
43
+ verifyDirs(t, start, dirs);
44
+
45
+ t.end();
46
+ });
47
+
48
+ t.test('empty options', function (t) {
49
+ var start = path.join(__dirname, 'resolver');
50
+ var dirs = nodeModulesPaths(start, {});
51
+
52
+ verifyDirs(t, start, dirs);
53
+
54
+ t.end();
55
+ });
56
+
57
+ t.test('with paths=array option', function (t) {
58
+ var start = path.join(__dirname, 'resolver');
59
+ var paths = ['a', 'b'];
60
+ var dirs = nodeModulesPaths(start, { paths: paths });
61
+
62
+ verifyDirs(t, start, dirs, null, paths);
63
+
64
+ t.end();
65
+ });
66
+
67
+ t.test('with paths=function option', function (t) {
68
+ function paths(request, absoluteStart, getNodeModulesDirs, opts) {
69
+ return getNodeModulesDirs().concat(path.join(absoluteStart, 'not node modules', request));
70
+ }
71
+
72
+ var start = path.join(__dirname, 'resolver');
73
+ var dirs = nodeModulesPaths(start, { paths: paths }, 'pkg');
74
+
75
+ verifyDirs(t, start, dirs, null, [path.join(start, 'not node modules', 'pkg')]);
76
+
77
+ t.end();
78
+ });
79
+
80
+ t.test('with paths=function skipping node modules resolution', function (t) {
81
+ function paths(request, absoluteStart, getNodeModulesDirs, opts) {
82
+ return [];
83
+ }
84
+ var start = path.join(__dirname, 'resolver');
85
+ var dirs = nodeModulesPaths(start, { paths: paths });
86
+ t.deepEqual(dirs, [], 'no node_modules was computed');
87
+ t.end();
88
+ });
89
+
90
+ t.test('with moduleDirectory option', function (t) {
91
+ var start = path.join(__dirname, 'resolver');
92
+ var moduleDirectory = 'not node modules';
93
+ var dirs = nodeModulesPaths(start, { moduleDirectory: moduleDirectory });
94
+
95
+ verifyDirs(t, start, dirs, moduleDirectory);
96
+
97
+ t.end();
98
+ });
99
+
100
+ t.test('with 1 moduleDirectory and paths options', function (t) {
101
+ var start = path.join(__dirname, 'resolver');
102
+ var paths = ['a', 'b'];
103
+ var moduleDirectory = 'not node modules';
104
+ var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectory });
105
+
106
+ verifyDirs(t, start, dirs, moduleDirectory, paths);
107
+
108
+ t.end();
109
+ });
110
+
111
+ t.test('with 1+ moduleDirectory and paths options', function (t) {
112
+ var start = path.join(__dirname, 'resolver');
113
+ var paths = ['a', 'b'];
114
+ var moduleDirectories = ['not node modules', 'other modules'];
115
+ var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories });
116
+
117
+ verifyDirs(t, start, dirs, moduleDirectories, paths);
118
+
119
+ t.end();
120
+ });
121
+
122
+ t.test('combine paths correctly on Windows', function (t) {
123
+ var start = 'C:\\Users\\username\\myProject\\src';
124
+ var paths = [];
125
+ var moduleDirectories = ['node_modules', start];
126
+ var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories });
127
+
128
+ t.equal(dirs.indexOf(path.resolve(start)) > -1, true, 'should contain start dir');
129
+
130
+ t.end();
131
+ });
132
+
133
+ t.test('combine paths correctly on non-Windows', { skip: process.platform === 'win32' }, function (t) {
134
+ var start = '/Users/username/git/myProject/src';
135
+ var paths = [];
136
+ var moduleDirectories = ['node_modules', '/Users/username/git/myProject/src'];
137
+ var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories });
138
+
139
+ t.equal(dirs.indexOf(path.resolve(start)) > -1, true, 'should contain start dir');
140
+
141
+ t.end();
142
+ });
143
+ });
node_modules/resolve/test/node_path.js ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var fs = require('fs');
2
+ var path = require('path');
3
+ var test = require('tape');
4
+ var resolve = require('../');
5
+
6
+ test('$NODE_PATH', function (t) {
7
+ t.plan(8);
8
+
9
+ function isDir(dir, cb) {
10
+ if (dir === '/node_path' || dir === 'node_path/x') {
11
+ return cb(null, true);
12
+ }
13
+ fs.stat(dir, function (err, stat) {
14
+ if (!err) {
15
+ return cb(null, stat.isDirectory());
16
+ }
17
+ if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
18
+ return cb(err);
19
+ });
20
+ }
21
+
22
+ resolve('aaa', {
23
+ paths: [
24
+ path.join(__dirname, '/node_path/x'),
25
+ path.join(__dirname, '/node_path/y')
26
+ ],
27
+ basedir: __dirname,
28
+ isDirectory: isDir
29
+ }, function (err, res) {
30
+ t.error(err);
31
+ t.equal(res, path.join(__dirname, '/node_path/x/aaa/index.js'), 'aaa resolves');
32
+ });
33
+
34
+ resolve('bbb', {
35
+ paths: [
36
+ path.join(__dirname, '/node_path/x'),
37
+ path.join(__dirname, '/node_path/y')
38
+ ],
39
+ basedir: __dirname,
40
+ isDirectory: isDir
41
+ }, function (err, res) {
42
+ t.error(err);
43
+ t.equal(res, path.join(__dirname, '/node_path/y/bbb/index.js'), 'bbb resolves');
44
+ });
45
+
46
+ resolve('ccc', {
47
+ paths: [
48
+ path.join(__dirname, '/node_path/x'),
49
+ path.join(__dirname, '/node_path/y')
50
+ ],
51
+ basedir: __dirname,
52
+ isDirectory: isDir
53
+ }, function (err, res) {
54
+ t.error(err);
55
+ t.equal(res, path.join(__dirname, '/node_path/x/ccc/index.js'), 'ccc resolves');
56
+ });
57
+
58
+ // ensure that relative paths still resolve against the regular `node_modules` correctly
59
+ resolve('tap', {
60
+ paths: [
61
+ 'node_path'
62
+ ],
63
+ basedir: path.join(__dirname, 'node_path/x'),
64
+ isDirectory: isDir
65
+ }, function (err, res) {
66
+ var root = require('tap/package.json').main; // eslint-disable-line global-require
67
+ t.error(err);
68
+ t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap', root), 'tap resolves');
69
+ });
70
+ });
node_modules/resolve/test/node_path/x/aaa/index.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = 'A';
node_modules/resolve/test/node_path/x/ccc/index.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = 'C';
node_modules/resolve/test/node_path/y/bbb/index.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = 'B';
node_modules/resolve/test/node_path/y/ccc/index.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = 'CY';
node_modules/resolve/test/nonstring.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ var test = require('tape');
2
+ var resolve = require('../');
3
+
4
+ test('nonstring', function (t) {
5
+ t.plan(1);
6
+ resolve(555, function (err, res, pkg) {
7
+ t.ok(err);
8
+ });
9
+ });
node_modules/resolve/test/pathfilter.js ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var path = require('path');
2
+ var test = require('tape');
3
+ var resolve = require('../');
4
+
5
+ var resolverDir = path.join(__dirname, '/pathfilter/deep_ref');
6
+
7
+ function pathFilterFactory(t) {
8
+ return function (pkg, x, remainder) {
9
+ t.equal(pkg.version, '1.2.3');
10
+ t.equal(x, path.join(resolverDir, 'node_modules/deep/ref'));
11
+ t.equal(remainder, 'ref');
12
+ return 'alt';
13
+ };
14
+ }
15
+
16
+ test('#62: deep module references and the pathFilter', function (t) {
17
+ t.test('deep/ref.js', function (st) {
18
+ st.plan(3);
19
+
20
+ resolve('deep/ref', { basedir: resolverDir }, function (err, res, pkg) {
21
+ if (err) st.fail(err);
22
+
23
+ st.equal(pkg.version, '1.2.3');
24
+ st.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js'));
25
+ });
26
+
27
+ var res = resolve.sync('deep/ref', { basedir: resolverDir });
28
+ st.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js'));
29
+ });
30
+
31
+ t.test('deep/deeper/ref', function (st) {
32
+ st.plan(4);
33
+
34
+ resolve(
35
+ 'deep/deeper/ref',
36
+ { basedir: resolverDir },
37
+ function (err, res, pkg) {
38
+ if (err) t.fail(err);
39
+ st.notEqual(pkg, undefined);
40
+ st.equal(pkg.version, '1.2.3');
41
+ st.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js'));
42
+ }
43
+ );
44
+
45
+ var res = resolve.sync(
46
+ 'deep/deeper/ref',
47
+ { basedir: resolverDir }
48
+ );
49
+ st.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js'));
50
+ });
51
+
52
+ t.test('deep/ref alt', function (st) {
53
+ st.plan(8);
54
+
55
+ var pathFilter = pathFilterFactory(st);
56
+
57
+ var res = resolve.sync(
58
+ 'deep/ref',
59
+ { basedir: resolverDir, pathFilter: pathFilter }
60
+ );
61
+ st.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js'));
62
+
63
+ resolve(
64
+ 'deep/ref',
65
+ { basedir: resolverDir, pathFilter: pathFilter },
66
+ function (err, res, pkg) {
67
+ if (err) st.fail(err);
68
+ st.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js'));
69
+ st.end();
70
+ }
71
+ );
72
+ });
73
+
74
+ t.end();
75
+ });
node_modules/resolve/test/pathfilter/deep_ref/main.js ADDED
File without changes
node_modules/resolve/test/pathfilter_sync.js ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var test = require('tape');
2
+ var path = require('path');
3
+ var resolve = require('../');
4
+
5
+ test('synchronous pathfilter', function (t) {
6
+ var res;
7
+ var resolverDir = __dirname + '/pathfilter/deep_ref';
8
+ function pathFilter(pkg, x, remainder) {
9
+ t.equal(pkg.version, '1.2.3');
10
+ t.equal(x, path.join(resolverDir, 'node_modules', 'deep', 'ref'));
11
+ t.equal(remainder, 'ref');
12
+ return 'alt';
13
+ }
14
+
15
+ res = resolve.sync('deep/ref', { basedir: resolverDir });
16
+ t.equal(res, path.join(resolverDir, 'node_modules', 'deep', 'ref.js'));
17
+
18
+ res = resolve.sync('deep/deeper/ref', { basedir: resolverDir });
19
+ t.equal(res, path.join(resolverDir, 'node_modules', 'deep', 'deeper', 'ref.js'));
20
+
21
+ res = resolve.sync('deep/ref', { basedir: resolverDir, pathFilter: pathFilter });
22
+ t.equal(res, path.join(resolverDir, 'node_modules', 'deep', 'alt.js'));
23
+ t.end();
24
+ });
node_modules/resolve/test/precedence.js ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var path = require('path');
2
+ var test = require('tape');
3
+ var resolve = require('../');
4
+
5
+ test('precedence', function (t) {
6
+ t.plan(3);
7
+ var dir = path.join(__dirname, 'precedence/aaa');
8
+
9
+ resolve('./', { basedir: dir }, function (err, res, pkg) {
10
+ t.ifError(err);
11
+ t.equal(res, path.join(dir, 'index.js'));
12
+ t.equal(pkg.name, 'resolve');
13
+ });
14
+ });
15
+
16
+ test('./ should not load ${dir}.js', function (t) { // eslint-disable-line no-template-curly-in-string
17
+ t.plan(1);
18
+ var dir = path.join(__dirname, 'precedence/bbb');
19
+
20
+ resolve('./', { basedir: dir }, function (err, res, pkg) {
21
+ t.ok(err);
22
+ });
23
+ });
node_modules/resolve/test/precedence/aaa.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = 'wtf';
node_modules/resolve/test/precedence/aaa/index.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = 'okok';
node_modules/resolve/test/precedence/aaa/main.js ADDED
@@ -0,0 +1 @@
 
 
1
+ console.log(require('./'));
node_modules/resolve/test/precedence/bbb.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = '>_<';
node_modules/resolve/test/precedence/bbb/main.js ADDED
@@ -0,0 +1 @@
 
 
1
+ console.log(require('./')); // should throw
node_modules/resolve/test/resolver.js ADDED
@@ -0,0 +1,597 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var path = require('path');
2
+ var fs = require('fs');
3
+ var test = require('tape');
4
+ var resolve = require('../');
5
+ var async = require('../async');
6
+
7
+ test('`./async` entry point', function (t) {
8
+ t.equal(resolve, async, '`./async` entry point is the same as `main`');
9
+ t.end();
10
+ });
11
+
12
+ test('async foo', function (t) {
13
+ t.plan(12);
14
+ var dir = path.join(__dirname, 'resolver');
15
+
16
+ resolve('./foo', { basedir: dir }, function (err, res, pkg) {
17
+ if (err) t.fail(err);
18
+ t.equal(res, path.join(dir, 'foo.js'));
19
+ t.equal(pkg && pkg.name, 'resolve');
20
+ });
21
+
22
+ resolve('./foo.js', { basedir: dir }, function (err, res, pkg) {
23
+ if (err) t.fail(err);
24
+ t.equal(res, path.join(dir, 'foo.js'));
25
+ t.equal(pkg && pkg.name, 'resolve');
26
+ });
27
+
28
+ resolve('./foo', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) {
29
+ if (err) t.fail(err);
30
+ t.equal(res, path.join(dir, 'foo.js'));
31
+ t.equal(pkg && pkg.main, 'resolver');
32
+ });
33
+
34
+ resolve('./foo.js', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) {
35
+ if (err) t.fail(err);
36
+ t.equal(res, path.join(dir, 'foo.js'));
37
+ t.equal(pkg.main, 'resolver');
38
+ });
39
+
40
+ resolve('./foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err, res) {
41
+ if (err) t.fail(err);
42
+ t.equal(res, path.join(dir, 'foo.js'));
43
+ });
44
+
45
+ resolve('foo', { basedir: dir }, function (err) {
46
+ t.equal(err.message, "Cannot find module 'foo' from '" + path.resolve(dir) + "'");
47
+ t.equal(err.code, 'MODULE_NOT_FOUND');
48
+ });
49
+
50
+ // Test that filename is reported as the "from" value when passed.
51
+ resolve('foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err) {
52
+ t.equal(err.message, "Cannot find module 'foo' from '" + path.join(dir, 'baz.js') + "'");
53
+ });
54
+ });
55
+
56
+ test('bar', function (t) {
57
+ t.plan(6);
58
+ var dir = path.join(__dirname, 'resolver');
59
+
60
+ resolve('foo', { basedir: dir + '/bar' }, function (err, res, pkg) {
61
+ if (err) t.fail(err);
62
+ t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));
63
+ t.equal(pkg, undefined);
64
+ });
65
+
66
+ resolve('foo', { basedir: dir + '/bar' }, function (err, res, pkg) {
67
+ if (err) t.fail(err);
68
+ t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));
69
+ t.equal(pkg, undefined);
70
+ });
71
+
72
+ resolve('foo', { basedir: dir + '/bar', 'package': { main: 'bar' } }, function (err, res, pkg) {
73
+ if (err) t.fail(err);
74
+ t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js'));
75
+ t.equal(pkg.main, 'bar');
76
+ });
77
+ });
78
+
79
+ test('baz', function (t) {
80
+ t.plan(4);
81
+ var dir = path.join(__dirname, 'resolver');
82
+
83
+ resolve('./baz', { basedir: dir }, function (err, res, pkg) {
84
+ if (err) t.fail(err);
85
+ t.equal(res, path.join(dir, 'baz/quux.js'));
86
+ t.equal(pkg.main, 'quux.js');
87
+ });
88
+
89
+ resolve('./baz', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) {
90
+ if (err) t.fail(err);
91
+ t.equal(res, path.join(dir, 'baz/quux.js'));
92
+ t.equal(pkg.main, 'quux.js');
93
+ });
94
+ });
95
+
96
+ test('biz', function (t) {
97
+ t.plan(24);
98
+ var dir = path.join(__dirname, 'resolver/biz/node_modules');
99
+
100
+ resolve('./grux', { basedir: dir }, function (err, res, pkg) {
101
+ if (err) t.fail(err);
102
+ t.equal(res, path.join(dir, 'grux/index.js'));
103
+ t.equal(pkg, undefined);
104
+ });
105
+
106
+ resolve('./grux', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) {
107
+ if (err) t.fail(err);
108
+ t.equal(res, path.join(dir, 'grux/index.js'));
109
+ t.equal(pkg.main, 'biz');
110
+ });
111
+
112
+ resolve('./garply', { basedir: dir }, function (err, res, pkg) {
113
+ if (err) t.fail(err);
114
+ t.equal(res, path.join(dir, 'garply/lib/index.js'));
115
+ t.equal(pkg.main, './lib');
116
+ });
117
+
118
+ resolve('./garply', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) {
119
+ if (err) t.fail(err);
120
+ t.equal(res, path.join(dir, 'garply/lib/index.js'));
121
+ t.equal(pkg.main, './lib');
122
+ });
123
+
124
+ resolve('tiv', { basedir: dir + '/grux' }, function (err, res, pkg) {
125
+ if (err) t.fail(err);
126
+ t.equal(res, path.join(dir, 'tiv/index.js'));
127
+ t.equal(pkg, undefined);
128
+ });
129
+
130
+ resolve('tiv', { basedir: dir + '/grux', 'package': { main: 'grux' } }, function (err, res, pkg) {
131
+ if (err) t.fail(err);
132
+ t.equal(res, path.join(dir, 'tiv/index.js'));
133
+ t.equal(pkg.main, 'grux');
134
+ });
135
+
136
+ resolve('tiv', { basedir: dir + '/garply' }, function (err, res, pkg) {
137
+ if (err) t.fail(err);
138
+ t.equal(res, path.join(dir, 'tiv/index.js'));
139
+ t.equal(pkg, undefined);
140
+ });
141
+
142
+ resolve('tiv', { basedir: dir + '/garply', 'package': { main: './lib' } }, function (err, res, pkg) {
143
+ if (err) t.fail(err);
144
+ t.equal(res, path.join(dir, 'tiv/index.js'));
145
+ t.equal(pkg.main, './lib');
146
+ });
147
+
148
+ resolve('grux', { basedir: dir + '/tiv' }, function (err, res, pkg) {
149
+ if (err) t.fail(err);
150
+ t.equal(res, path.join(dir, 'grux/index.js'));
151
+ t.equal(pkg, undefined);
152
+ });
153
+
154
+ resolve('grux', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) {
155
+ if (err) t.fail(err);
156
+ t.equal(res, path.join(dir, 'grux/index.js'));
157
+ t.equal(pkg.main, 'tiv');
158
+ });
159
+
160
+ resolve('garply', { basedir: dir + '/tiv' }, function (err, res, pkg) {
161
+ if (err) t.fail(err);
162
+ t.equal(res, path.join(dir, 'garply/lib/index.js'));
163
+ t.equal(pkg.main, './lib');
164
+ });
165
+
166
+ resolve('garply', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) {
167
+ if (err) t.fail(err);
168
+ t.equal(res, path.join(dir, 'garply/lib/index.js'));
169
+ t.equal(pkg.main, './lib');
170
+ });
171
+ });
172
+
173
+ test('quux', function (t) {
174
+ t.plan(2);
175
+ var dir = path.join(__dirname, 'resolver/quux');
176
+
177
+ resolve('./foo', { basedir: dir, 'package': { main: 'quux' } }, function (err, res, pkg) {
178
+ if (err) t.fail(err);
179
+ t.equal(res, path.join(dir, 'foo/index.js'));
180
+ t.equal(pkg.main, 'quux');
181
+ });
182
+ });
183
+
184
+ test('normalize', function (t) {
185
+ t.plan(2);
186
+ var dir = path.join(__dirname, 'resolver/biz/node_modules/grux');
187
+
188
+ resolve('../grux', { basedir: dir }, function (err, res, pkg) {
189
+ if (err) t.fail(err);
190
+ t.equal(res, path.join(dir, 'index.js'));
191
+ t.equal(pkg, undefined);
192
+ });
193
+ });
194
+
195
+ test('cup', function (t) {
196
+ t.plan(5);
197
+ var dir = path.join(__dirname, 'resolver');
198
+
199
+ resolve('./cup', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) {
200
+ if (err) t.fail(err);
201
+ t.equal(res, path.join(dir, 'cup.coffee'));
202
+ });
203
+
204
+ resolve('./cup.coffee', { basedir: dir }, function (err, res) {
205
+ if (err) t.fail(err);
206
+ t.equal(res, path.join(dir, 'cup.coffee'));
207
+ });
208
+
209
+ resolve('./cup', { basedir: dir, extensions: ['.js'] }, function (err, res) {
210
+ t.equal(err.message, "Cannot find module './cup' from '" + path.resolve(dir) + "'");
211
+ t.equal(err.code, 'MODULE_NOT_FOUND');
212
+ });
213
+
214
+ // Test that filename is reported as the "from" value when passed.
215
+ resolve('./cup', { basedir: dir, extensions: ['.js'], filename: path.join(dir, 'cupboard.js') }, function (err, res) {
216
+ t.equal(err.message, "Cannot find module './cup' from '" + path.join(dir, 'cupboard.js') + "'");
217
+ });
218
+ });
219
+
220
+ test('mug', function (t) {
221
+ t.plan(3);
222
+ var dir = path.join(__dirname, 'resolver');
223
+
224
+ resolve('./mug', { basedir: dir }, function (err, res) {
225
+ if (err) t.fail(err);
226
+ t.equal(res, path.join(dir, 'mug.js'));
227
+ });
228
+
229
+ resolve('./mug', { basedir: dir, extensions: ['.coffee', '.js'] }, function (err, res) {
230
+ if (err) t.fail(err);
231
+ t.equal(res, path.join(dir, '/mug.coffee'));
232
+ });
233
+
234
+ resolve('./mug', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) {
235
+ t.equal(res, path.join(dir, '/mug.js'));
236
+ });
237
+ });
238
+
239
+ test('other path', function (t) {
240
+ t.plan(6);
241
+ var resolverDir = path.join(__dirname, 'resolver');
242
+ var dir = path.join(resolverDir, 'bar');
243
+ var otherDir = path.join(resolverDir, 'other_path');
244
+
245
+ resolve('root', { basedir: dir, paths: [otherDir] }, function (err, res) {
246
+ if (err) t.fail(err);
247
+ t.equal(res, path.join(resolverDir, 'other_path/root.js'));
248
+ });
249
+
250
+ resolve('lib/other-lib', { basedir: dir, paths: [otherDir] }, function (err, res) {
251
+ if (err) t.fail(err);
252
+ t.equal(res, path.join(resolverDir, 'other_path/lib/other-lib.js'));
253
+ });
254
+
255
+ resolve('root', { basedir: dir }, function (err, res) {
256
+ t.equal(err.message, "Cannot find module 'root' from '" + path.resolve(dir) + "'");
257
+ t.equal(err.code, 'MODULE_NOT_FOUND');
258
+ });
259
+
260
+ resolve('zzz', { basedir: dir, paths: [otherDir] }, function (err, res) {
261
+ t.equal(err.message, "Cannot find module 'zzz' from '" + path.resolve(dir) + "'");
262
+ t.equal(err.code, 'MODULE_NOT_FOUND');
263
+ });
264
+ });
265
+
266
+ test('path iterator', function (t) {
267
+ t.plan(2);
268
+
269
+ var resolverDir = path.join(__dirname, 'resolver');
270
+
271
+ function exactIterator(x, start, getPackageCandidates, opts) {
272
+ return [path.join(resolverDir, x)];
273
+ }
274
+
275
+ resolve('baz', { packageIterator: exactIterator }, function (err, res, pkg) {
276
+ if (err) t.fail(err);
277
+ t.equal(res, path.join(resolverDir, 'baz/quux.js'));
278
+ t.equal(pkg && pkg.name, 'baz');
279
+ });
280
+ });
281
+
282
+ test('incorrect main', function (t) {
283
+ t.plan(1);
284
+
285
+ var resolverDir = path.join(__dirname, 'resolver');
286
+ var dir = path.join(resolverDir, 'incorrect_main');
287
+
288
+ resolve('./incorrect_main', { basedir: resolverDir }, function (err, res, pkg) {
289
+ if (err) t.fail(err);
290
+ t.equal(res, path.join(dir, 'index.js'));
291
+ });
292
+ });
293
+
294
+ test('missing index', function (t) {
295
+ t.plan(2);
296
+
297
+ var resolverDir = path.join(__dirname, 'resolver');
298
+ resolve('./missing_index', { basedir: resolverDir }, function (err, res, pkg) {
299
+ t.ok(err instanceof Error);
300
+ t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
301
+ });
302
+ });
303
+
304
+ test('missing main', function (t) {
305
+ t.plan(1);
306
+
307
+ var resolverDir = path.join(__dirname, 'resolver');
308
+
309
+ resolve('./missing_main', { basedir: resolverDir }, function (err, res, pkg) {
310
+ t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
311
+ });
312
+ });
313
+
314
+ test('null main', function (t) {
315
+ t.plan(1);
316
+
317
+ var resolverDir = path.join(__dirname, 'resolver');
318
+
319
+ resolve('./null_main', { basedir: resolverDir }, function (err, res, pkg) {
320
+ t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error has correct error code');
321
+ });
322
+ });
323
+
324
+ test('main: false', function (t) {
325
+ t.plan(2);
326
+
327
+ var basedir = path.join(__dirname, 'resolver');
328
+ var dir = path.join(basedir, 'false_main');
329
+ resolve('./false_main', { basedir: basedir }, function (err, res, pkg) {
330
+ if (err) t.fail(err);
331
+ t.equal(
332
+ res,
333
+ path.join(dir, 'index.js'),
334
+ '`"main": false`: resolves to `index.js`'
335
+ );
336
+ t.deepEqual(pkg, {
337
+ name: 'false_main',
338
+ main: false
339
+ });
340
+ });
341
+ });
342
+
343
+ test('without basedir', function (t) {
344
+ t.plan(1);
345
+
346
+ var dir = path.join(__dirname, 'resolver/without_basedir');
347
+ var tester = require(path.join(dir, 'main.js')); // eslint-disable-line global-require
348
+
349
+ tester(t, function (err, res, pkg) {
350
+ if (err) {
351
+ t.fail(err);
352
+ } else {
353
+ t.equal(res, path.join(dir, 'node_modules/mymodule.js'));
354
+ }
355
+ });
356
+ });
357
+
358
+ test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) {
359
+ t.plan(2);
360
+
361
+ var dir = path.join(__dirname, 'resolver');
362
+
363
+ resolve('./foo', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) {
364
+ if (err) t.fail(err);
365
+ t.equal(res, path.join(dir, 'same_names/foo.js'));
366
+ });
367
+
368
+ resolve('./foo/', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) {
369
+ if (err) t.fail(err);
370
+ t.equal(res, path.join(dir, 'same_names/foo/index.js'));
371
+ });
372
+ });
373
+
374
+ test('#211 - incorrectly resolves module-paths like "." when from inside a folder with a sibling file of the same name', function (t) {
375
+ t.plan(2);
376
+
377
+ var dir = path.join(__dirname, 'resolver');
378
+
379
+ resolve('./', { basedir: path.join(dir, 'same_names/foo') }, function (err, res, pkg) {
380
+ if (err) t.fail(err);
381
+ t.equal(res, path.join(dir, 'same_names/foo/index.js'));
382
+ });
383
+
384
+ resolve('.', { basedir: path.join(dir, 'same_names/foo') }, function (err, res, pkg) {
385
+ if (err) t.fail(err);
386
+ t.equal(res, path.join(dir, 'same_names/foo/index.js'));
387
+ });
388
+ });
389
+
390
+ test('async: #121 - treating an existing file as a dir when no basedir', function (t) {
391
+ var testFile = path.basename(__filename);
392
+
393
+ t.test('sanity check', function (st) {
394
+ st.plan(1);
395
+ resolve('./' + testFile, function (err, res, pkg) {
396
+ if (err) t.fail(err);
397
+ st.equal(res, __filename, 'sanity check');
398
+ });
399
+ });
400
+
401
+ t.test('with a fake directory', function (st) {
402
+ st.plan(4);
403
+
404
+ resolve('./' + testFile + '/blah', function (err, res, pkg) {
405
+ st.ok(err, 'there is an error');
406
+ st.notOk(res, 'no result');
407
+
408
+ st.equal(err && err.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve');
409
+ st.equal(
410
+ err && err.message,
411
+ 'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'',
412
+ 'can not find nonexistent module'
413
+ );
414
+ st.end();
415
+ });
416
+ });
417
+
418
+ t.end();
419
+ });
420
+
421
+ test('async dot main', function (t) {
422
+ var start = new Date();
423
+ t.plan(3);
424
+ resolve('./resolver/dot_main', function (err, ret) {
425
+ t.notOk(err);
426
+ t.equal(ret, path.join(__dirname, 'resolver/dot_main/index.js'));
427
+ t.ok(new Date() - start < 50, 'resolve.sync timedout');
428
+ t.end();
429
+ });
430
+ });
431
+
432
+ test('async dot slash main', function (t) {
433
+ var start = new Date();
434
+ t.plan(3);
435
+ resolve('./resolver/dot_slash_main', function (err, ret) {
436
+ t.notOk(err);
437
+ t.equal(ret, path.join(__dirname, 'resolver/dot_slash_main/index.js'));
438
+ t.ok(new Date() - start < 50, 'resolve.sync timedout');
439
+ t.end();
440
+ });
441
+ });
442
+
443
+ test('not a directory', function (t) {
444
+ t.plan(6);
445
+ var path = './foo';
446
+ resolve(path, { basedir: __filename }, function (err, res, pkg) {
447
+ t.ok(err, 'a non-directory errors');
448
+ t.equal(arguments.length, 1);
449
+ t.equal(res, undefined);
450
+ t.equal(pkg, undefined);
451
+
452
+ t.equal(err && err.message, 'Cannot find module \'' + path + '\' from \'' + __filename + '\'');
453
+ t.equal(err && err.code, 'MODULE_NOT_FOUND');
454
+ });
455
+ });
456
+
457
+ test('non-string "main" field in package.json', function (t) {
458
+ t.plan(5);
459
+
460
+ var dir = path.join(__dirname, 'resolver');
461
+ resolve('./invalid_main', { basedir: dir }, function (err, res, pkg) {
462
+ t.ok(err, 'errors on non-string main');
463
+ t.equal(err.message, 'package “invalid_main” `main` must be a string');
464
+ t.equal(err.code, 'INVALID_PACKAGE_MAIN');
465
+ t.equal(res, undefined, 'res is undefined');
466
+ t.equal(pkg, undefined, 'pkg is undefined');
467
+ });
468
+ });
469
+
470
+ test('non-string "main" field in package.json', function (t) {
471
+ t.plan(5);
472
+
473
+ var dir = path.join(__dirname, 'resolver');
474
+ resolve('./invalid_main', { basedir: dir }, function (err, res, pkg) {
475
+ t.ok(err, 'errors on non-string main');
476
+ t.equal(err.message, 'package “invalid_main” `main` must be a string');
477
+ t.equal(err.code, 'INVALID_PACKAGE_MAIN');
478
+ t.equal(res, undefined, 'res is undefined');
479
+ t.equal(pkg, undefined, 'pkg is undefined');
480
+ });
481
+ });
482
+
483
+ test('browser field in package.json', function (t) {
484
+ t.plan(3);
485
+
486
+ var dir = path.join(__dirname, 'resolver');
487
+ resolve(
488
+ './browser_field',
489
+ {
490
+ basedir: dir,
491
+ packageFilter: function packageFilter(pkg) {
492
+ if (pkg.browser) {
493
+ pkg.main = pkg.browser; // eslint-disable-line no-param-reassign
494
+ delete pkg.browser; // eslint-disable-line no-param-reassign
495
+ }
496
+ return pkg;
497
+ }
498
+ },
499
+ function (err, res, pkg) {
500
+ if (err) t.fail(err);
501
+ t.equal(res, path.join(dir, 'browser_field', 'b.js'));
502
+ t.equal(pkg && pkg.main, 'b');
503
+ t.equal(pkg && pkg.browser, undefined);
504
+ }
505
+ );
506
+ });
507
+
508
+ test('absolute paths', function (t) {
509
+ t.plan(4);
510
+
511
+ var extensionless = __filename.slice(0, -path.extname(__filename).length);
512
+
513
+ resolve(__filename, function (err, res) {
514
+ t.equal(
515
+ res,
516
+ __filename,
517
+ 'absolute path to this file resolves'
518
+ );
519
+ });
520
+ resolve(extensionless, function (err, res) {
521
+ t.equal(
522
+ res,
523
+ __filename,
524
+ 'extensionless absolute path to this file resolves'
525
+ );
526
+ });
527
+ resolve(__filename, { basedir: process.cwd() }, function (err, res) {
528
+ t.equal(
529
+ res,
530
+ __filename,
531
+ 'absolute path to this file with a basedir resolves'
532
+ );
533
+ });
534
+ resolve(extensionless, { basedir: process.cwd() }, function (err, res) {
535
+ t.equal(
536
+ res,
537
+ __filename,
538
+ 'extensionless absolute path to this file with a basedir resolves'
539
+ );
540
+ });
541
+ });
542
+
543
+ var malformedDir = path.join(__dirname, 'resolver/malformed_package_json');
544
+ test('malformed package.json', { skip: !fs.existsSync(malformedDir) }, function (t) {
545
+ /* eslint operator-linebreak: ["error", "before"], function-paren-newline: "off" */
546
+ t.plan(
547
+ (3 * 3) // 3 sets of 3 assertions in the final callback
548
+ + 2 // 1 readPackage call with malformed package.json
549
+ );
550
+
551
+ var basedir = malformedDir;
552
+ var expected = path.join(basedir, 'index.js');
553
+
554
+ resolve('./index.js', { basedir: basedir }, function (err, res, pkg) {
555
+ t.error(err, 'no error');
556
+ t.equal(res, expected, 'malformed package.json is silently ignored');
557
+ t.equal(pkg, undefined, 'malformed package.json gives an undefined `pkg` argument');
558
+ });
559
+
560
+ resolve(
561
+ './index.js',
562
+ {
563
+ basedir: basedir,
564
+ packageFilter: function (pkg, pkgfile, dir) {
565
+ t.fail('should not reach here');
566
+ }
567
+ },
568
+ function (err, res, pkg) {
569
+ t.error(err, 'with packageFilter: no error');
570
+ t.equal(res, expected, 'with packageFilter: malformed package.json is silently ignored');
571
+ t.equal(pkg, undefined, 'with packageFilter: malformed package.json gives an undefined `pkg` argument');
572
+ }
573
+ );
574
+
575
+ resolve(
576
+ './index.js',
577
+ {
578
+ basedir: basedir,
579
+ readPackage: function (readFile, pkgfile, cb) {
580
+ t.equal(pkgfile, path.join(basedir, 'package.json'), 'readPackageSync: `pkgfile` is package.json path');
581
+ readFile(pkgfile, function (err, result) {
582
+ try {
583
+ cb(null, JSON.parse(result));
584
+ } catch (e) {
585
+ t.ok(e instanceof SyntaxError, 'readPackage: malformed package.json parses as a syntax error');
586
+ cb(null);
587
+ }
588
+ });
589
+ }
590
+ },
591
+ function (err, res, pkg) {
592
+ t.error(err, 'with readPackage: no error');
593
+ t.equal(res, expected, 'with readPackage: malformed package.json is silently ignored');
594
+ t.equal(pkg, undefined, 'with readPackage: malformed package.json gives an undefined `pkg` argument');
595
+ }
596
+ );
597
+ });
node_modules/resolve/test/resolver/baz/doom.js ADDED
File without changes
node_modules/resolve/test/resolver/baz/package.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "name": "baz",
3
+ "main": "quux.js"
4
+ }
node_modules/resolve/test/resolver/baz/quux.js ADDED
@@ -0,0 +1 @@
 
 
1
+ module.exports = 1;