Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion worklenz-backend/src/shared/private-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,29 @@ const noopAppSumoMigrationService: IAppSumoMigrationService = {
}),
};

let hasLoggedMissingPrivateExtensions = false;

const isMissingPrivateExtension = (error: unknown, modulePath: string): boolean => {
if (!(error instanceof Error)) return false;

const moduleNotFoundError = error as NodeJS.ErrnoException;
return moduleNotFoundError.code === "MODULE_NOT_FOUND" && error.message.includes(`'${modulePath}'`);
};

function load<T>(modulePath: string, exportName: string, fallback: T): T {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const mod = require(modulePath);
return (mod[exportName] as T) ?? fallback;
} catch (error) {
log_error(`private-extensions: ${modulePath} not present, using no-op (${(error as Error).message})`);
if (isMissingPrivateExtension(error, modulePath)) {
if (!hasLoggedMissingPrivateExtensions) {
console.info("Optional AppSumo extensions are unavailable; AppSumo-specific features are disabled.");
hasLoggedMissingPrivateExtensions = true;
}
} else {
log_error(error);
}
return fallback;
}
}
Expand Down
Loading