-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
34 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
const D = require('@flecks/core/build/debug'); | ||
|
||
const debug = D('@flecks/server/build/runtime'); | ||
|
||
const Resolver = require('./resolver'); | ||
|
||
module.exports = function resolve({aliases, fallbacks}, stubs) { | ||
module.exports = function resolve(resolverConfig, stubs) { | ||
debug('installing resolution magic'); | ||
const {Module} = require('module'); | ||
const {require: Mr} = Module.prototype; | ||
const resolver = new Resolver({aliases, fallbacks, useSyncFileSystemCalls: true}); | ||
Module.prototype.require = function hackedRequire(request, options) { | ||
const resolver = new Resolver({ | ||
...resolverConfig, | ||
modules: [], | ||
useSyncFileSystemCalls: true, | ||
}); | ||
Module.prototype.require = function flecksResolutionMagic(request, options) { | ||
for (let i = 0; i < stubs.length; ++i) { | ||
if (request.startsWith(stubs[i])) { | ||
return undefined; | ||
} | ||
} | ||
try { | ||
return Mr.call(this, request, options); | ||
} | ||
catch (error) { | ||
if (!error.message.startsWith('Cannot find module')) { | ||
throw error; | ||
} | ||
const resolved = resolver.resolveSync(request); | ||
if (!resolved) { | ||
throw error; | ||
} | ||
return Mr.call(this, resolved, options); | ||
} | ||
return Mr.call(this, resolver.resolveSync(request) || request, options); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters