Skip to content

Commit

Permalink
fix bad require
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Sep 3, 2023
1 parent e88e6ad commit a00cc94
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/lib/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports.builtinPlugins = null

const filterKeys = (keys) => {
if (process.platform === 'browser') keys = keys.filter(k => k !== './external.js')
keys = keys.filter(k => k !== './index.js' && k !== 'index.js')
return keys
}

module.exports.initPlugins = () => {
if (process.platform === 'browser') {
const isWebpack = !!require.context
if (isWebpack) {
const pluginsMap = require.context('./', false, /^(?!.*(?:external.js$)).*\.js$/)
module.exports.builtinPlugins = filterKeys(pluginsMap.keys()).map(k => pluginsMap(k))
} else {
// esbuild custom plugin
const files = require(/* webpackIgnore: true */ 'esbuild-import-glob(path:.,skipFiles:index.js,external.js)')
module.exports.builtinPlugins = Object.values(files)
}
} else {
// todo use browser field or bundle like valtio does: https://github.com/webpack/webpack/issues/8826#issuecomment-671402668
const requireIndex = require('../requireindex')
const path = require('path')

const _plugins = requireIndex(path.join(__dirname, './'))
module.exports.builtinPlugins = filterKeys(Object.keys(_plugins)).map(k => _plugins[k])
}
}
2 changes: 1 addition & 1 deletion src/lib/plugins/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports.server = async function (serv, { version, worldFolder, generation
generation.options.version = version
serv.emit('seed', generation.options.seed)
// ignore
const generationModule = generations[generation.name] ? generations[generation.name] : global['require'](generation.name)
const generationModule = generations[generation.name] ? generations[generation.name] : require(generation.name)
serv.overworld = new World(generationModule(generation.options), regionFolder === undefined ? null : new Anvil(regionFolder))
serv.netherworld = new World(generations.nether(generation.options))
// serv.endworld = new World(generations["end"]({}));
Expand Down

0 comments on commit a00cc94

Please sign in to comment.