diff --git a/bin/run.sh b/bin/run.sh index 4f0b8f83a..0709b5d4e 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -29,6 +29,14 @@ fi # Prepare the environment bin/installDeps.sh "$@" || exit 1 +## Create the admin ui +if [ -z "$NODE_ENV" ] || [ "$NODE_ENV" = "development" ]; then + log "Creating the admin UI..." + (cd ../admin && pnpm run build) +else + log "Cannot create the admin UI in production mode" +fi + # Move to the node folder and start log "Starting Etherpad..." diff --git a/src/node/server.ts b/src/node/server.ts index 4c9d16833..13d35a226 100755 --- a/src/node/server.ts +++ b/src/node/server.ts @@ -1,7 +1,5 @@ #!/usr/bin/env node -'use strict'; - /** * This module is started with src/bin/run.sh. It sets up a Express HTTP and a Socket.IO Server. * Static file Requests are answered directly from this module, Socket.IO messages are passed @@ -26,8 +24,6 @@ import {PluginType} from "./types/Plugin"; import {ErrorCaused} from "./types/ErrorCaused"; -import {PromiseHooks} from "node:v8"; - import log4js from 'log4js'; import {checkForMigration} from "../static/js/pluginfw/installer"; diff --git a/src/static/js/pluginfw/installer.ts b/src/static/js/pluginfw/installer.ts index 875b3e80c..ee3b54592 100644 --- a/src/static/js/pluginfw/installer.ts +++ b/src/static/js/pluginfw/installer.ts @@ -22,7 +22,13 @@ const logger = log4js.getLogger('plugins'); export const pluginInstallPath = path.join(settings.root, 'src','plugin_packages'); export const manager = new PluginManager({ - pluginsPath: pluginInstallPath + pluginsPath: pluginInstallPath, + hostRequire: require, + requireCoreModules: true, + sandbox: { + env: process.env, + global: global + } }); export const installedPluginsPath = path.join(settings.root, 'var/installed_plugins.json'); @@ -77,6 +83,27 @@ const migratePluginsFromNodeModules = async () => { export const checkForMigration = async () => { logger.info('check installed plugins for migration'); + const files = await fs.readdir(pluginInstallPath); + + const node_modules = path.join(findEtherpadRoot(),'src', 'node_modules'); + /* + * Check if the plugin is already installed in node_modules + * If not, create a symlink to node_modules + * This is necessary as + * 1. Live Plugin Manager does not support loading plugins from the directory so that node can access them normally + * 2. Plugins can't be directly installed to node_modules otherwise upgrading Etherpad will remove them + */ + for (let file of files){ + const moduleName = path.basename(file); + try { + await fs.access(path.join(node_modules, moduleName), fs.constants.F_OK); + logger.debug(`plugin ${moduleName} already exists in node_modules`); + } catch (err) { + // Create symlink to node_modules + logger.debug(`create symlink for ${file} to ${path.join(node_modules,moduleName)}`) + await fs.symlink(path.join(pluginInstallPath,file), path.join(node_modules,moduleName), 'dir') + } + } try { await fs.access(installedPluginsPath, fs.constants.F_OK);