Skip to content

Commit

Permalink
feat: refactore get source project name
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe LAWSON <philippe.lawson@montreal.ca>
  • Loading branch information
Philippe LAWSON committed Jun 5, 2024
1 parent 7082898 commit d51fa6f
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/config/configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,23 @@ export class Configs {
*/
private _cacheDuration: number = constants.default.cacheDuration;

private readonly _sourceProjectName = (): string => {
const sourcePackageJson = require(`${constants.appRoot}/package.json`);
return sourcePackageJson?.name ? sourcePackageJson.name : '';
};
/**
* When this library is used as a dependency in a project, the source project name will be the property name in the package.json of this project
*
* @private
* @type {string}
* @memberof Configs
*/
private readonly _sourceProjectName: string;

private _loggerCreator: (name: string) => ILogger;
private _correlationIdProvider: () => string;

constructor() {
this.libRoot = path.normalize(__dirname + '/../../..');
this.isWindows = os.platform() === 'win32';
const sourcePackageJson = require(`${constants.appRoot}/package.json`);
this._sourceProjectName = sourcePackageJson?.name ? sourcePackageJson.name : '';
}

/**
Expand Down Expand Up @@ -134,8 +140,14 @@ export class Configs {
this._correlationIdProvider = correlationIdProvider;
}

public getSourceProjectName() {
return this._sourceProjectName();
/**
* Get the source project name where this library is imported
*
* @return {*} {string}
* @memberof Configs
*/
public getSourceProjectName(): string {
return this._sourceProjectName;
}

/**
Expand Down

0 comments on commit d51fa6f

Please sign in to comment.