refactor: mind the potential hotness
This commit is contained in:
parent
068c02dbfc
commit
15f452ca1e
|
@ -152,18 +152,18 @@ export default class ServerFlecks extends Flecks {
|
|||
}
|
||||
// Stub server-unfriendly modules.
|
||||
const stubs = this.stubs(['server'], rcs);
|
||||
if (stubs.length > 0) {
|
||||
if (Object.keys(stubs).length > 0) {
|
||||
debug('stubbing: %O', stubs);
|
||||
}
|
||||
// Do we need to get up in `require()`'s guts?
|
||||
if (
|
||||
Object.keys(aliases).length > 0
|
||||
|| stubs.length > 0
|
||||
|| Object.keys(stubs).length > 0
|
||||
) {
|
||||
const {Module} = R('module');
|
||||
const {require: Mr} = Module.prototype;
|
||||
Module.prototype.require = function hackedRequire(request, options) {
|
||||
if (-1 !== stubs.indexOf(request)) {
|
||||
if (stubs[request]) {
|
||||
return undefined;
|
||||
}
|
||||
if (aliases[request]) {
|
||||
|
@ -603,7 +603,7 @@ export default class ServerFlecks extends Flecks {
|
|||
});
|
||||
}
|
||||
}
|
||||
return Object.keys(stubs);
|
||||
return stubs;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -94,9 +94,9 @@ module.exports = (async () => {
|
|||
}
|
||||
// Stub out non-server-friendly modules on the server.
|
||||
const stubs = flecks.stubs();
|
||||
if (stubs.length > 0) {
|
||||
if (Object.keys(stubs).length > 0) {
|
||||
config.use.unshift(({config}) => {
|
||||
stubs.forEach((path) => {
|
||||
Object.keys(stubs).forEach((path) => {
|
||||
config.resolve.alias
|
||||
.set(path, '@flecks/core/empty');
|
||||
});
|
||||
|
@ -111,7 +111,7 @@ module.exports = (async () => {
|
|||
'const {Module} = require("module");',
|
||||
'const {require: Mr} = Module.prototype;',
|
||||
'Module.prototype.require = function hackedRequire(request, options) {',
|
||||
' if (-1 !== stubs.indexOf(request)) {',
|
||||
' if (stubs[request]) {',
|
||||
' return undefined;',
|
||||
' }',
|
||||
' if (aliases[request]) {',
|
||||
|
|
Loading…
Reference in New Issue
Block a user