refactor: mind the potential hotness

This commit is contained in:
cha0s 2022-03-10 14:24:47 -06:00
parent 068c02dbfc
commit 15f452ca1e
2 changed files with 7 additions and 7 deletions

View File

@ -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;
}
}

View File

@ -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]) {',