Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 49 lines (36 sloc) 1.479 kB
b721e72 @hiddentao Integrated Hem codebase properly. Started working on defining and imp…
authored
1 Module = require('module')
2 {join, extname, dirname, basename, resolve} = require('path')
3
4 isAbsolute = (path) -> /^\//.test(path)
5
6 # Normalize paths and remove extensions
7 # to create valid CommonJS module names
8 modulerize = (id, filename = id) ->
9 ext = extname(filename)
10 modName = join(dirname(id), basename(id, ext))
11 modName.replace('\\', '/');
12
13 modulePaths = Module._nodeModulePaths(process.cwd())
14
15 invalidDirs = ['/', '.']
16
17 repl =
18 id: 'repl'
19 filename: join(process.cwd(), 'repl')
20 paths: modulePaths
21
22 # Resolves a `require()` call. Pass in the name of the module where
23 # the call was made, and the path that was required.
24 # Returns an array of: [moduleName, scriptPath]
25 module.exports = (request, parent = repl) ->
26 [_, paths] = Module._resolveLookupPaths(request, parent)
27 filename = Module._findPath(request, paths)
28 dir = filename
29
30 throw("Cannot find module: #{request}. Have you run `npm install .` ?") unless filename
31
32 # Find package root relative to localModules folder
33 while dir not in invalidDirs and dir not in modulePaths
34 dir = dirname(dir)
5ecc327 @hiddentao Fixed issue whereby npm dependencies were being given incorrect modul…
authored
35
b721e72 @hiddentao Integrated Hem codebase properly. Started working on defining and imp…
authored
36 throw("Load path not found for #{filename}") if dir in invalidDirs
5ecc327 @hiddentao Fixed issue whereby npm dependencies were being given incorrect modul…
authored
37
38 # if it's an npm module then use module name as id
39 if dir in modulePaths
40 id = request
41 else
42 id = filename.replace("#{dir}/", '')
b721e72 @hiddentao Integrated Hem codebase properly. Started working on defining and imp…
authored
43
44 [modulerize(id, filename), filename]
45
46 module.exports.paths = (filename) ->
47 Module._nodeModulePaths(dirname(filename))
48
49 module.exports.modulerize = modulerize
Something went wrong with that request. Please try again.