Skip to content

Commit

Permalink
Fixes for extension config loading (issue bpatrik#847)
Browse files Browse the repository at this point in the history
* Actually add/remove extensions from `Config.Extensions.extensions`
* Fix the file path where `ExtensionConfigTemplateLoader` looks for extensions
* Prevent the first `loadSync()` call from creating a `config.json` file
  Works around bpatrik/typeconfig#27
  • Loading branch information
mblythe86 committed Apr 12, 2024
1 parent 8c86dcb commit b04dc60
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/backend/model/extension/ExtensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {SQLConnection} from '../database/SQLConnection';
import {ExtensionObject} from './ExtensionObject';
import {ExtensionDecoratorObject} from './ExtensionDecorator';
import * as util from 'util';
import {ServerExtensionsEntryConfig} from '../../../common/config/private/subconfigs/ServerExtensionsConfig';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const exec = util.promisify(require('child_process').exec);

Expand Down Expand Up @@ -79,6 +80,14 @@ export class ExtensionManager implements IObjectManager {
);
extList.sort();

// delete not existing extensions
Config.Extensions.extensions = Config.Extensions.extensions.filter(ec => extList.indexOf(ec.path) !== -1);


// Add new extensions
const ePaths = Config.Extensions.extensions.map(ec => ec.path);
extList.filter(ep => ePaths.indexOf(ep) === -1).forEach(ep =>
Config.Extensions.extensions.push(new ServerExtensionsEntryConfig(ep)));

Logger.debug(LOG_TAG, 'Extensions found: ', JSON.stringify(Config.Extensions.extensions.map(ec => ec.path)));
}
Expand Down
6 changes: 5 additions & 1 deletion src/common/config/private/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import * as path from 'path';

const pre = ConfigClassBuilder.attachPrivateInterface(new PrivateConfigClass());
try {
//NOTE: can possibly remove this saveIfNotExist hack if typeconfig issue #27 is fixed
const origSaveIfNotExist = (pre.__options as any).saveIfNotExist;
(pre.__options as any).saveIfNotExist = false;
pre.loadSync();
(pre.__options as any).saveIfNotExist = origSaveIfNotExist;
} catch (e) { /* empty */ }
ExtensionConfigTemplateLoader.Instance.init(path.join(__dirname, '/../../../../', pre.Extensions.folder));
ExtensionConfigTemplateLoader.Instance.init(pre.Extensions.folder);

export const Config = ExtensionConfigWrapper.originalSync(true);

0 comments on commit b04dc60

Please sign in to comment.