diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c896682b..e7c02de8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ## __WORK IN PROGRESS__ --> +## __WORK IN PROGRESS__ - Kiera +* (foxriver76) provide method `getAdapterScopedPackageIdentifier` for adapters + ## 6.0.8 (2024-07-13) - Kiera * (foxriver76) fixed problem with Sentry plugin diff --git a/README.md b/README.md index 6a4aa2c3b..86a927646 100644 --- a/README.md +++ b/README.md @@ -260,6 +260,13 @@ const installedNodeModules = await adapter.listInstalledNodeModules(); adapter.log.info(`Installed modules are: ${installedNodeModules.join(', ')}`); ``` +To get the adapter scoped package identifier you can use: + +```typescript +// e.g. @iobroker-javascript.0/axios +const packageIdentifier = adapter.getAdapterScopedPackageIdentifier('axios'); +``` + ### Per host `adapter` objects **Feature status:** New in 6.0.0 diff --git a/packages/adapter/src/lib/adapter/adapter.ts b/packages/adapter/src/lib/adapter/adapter.ts index bee06b279..89535c0fa 100644 --- a/packages/adapter/src/lib/adapter/adapter.ts +++ b/packages/adapter/src/lib/adapter/adapter.ts @@ -1246,6 +1246,15 @@ export class AdapterClass extends EventEmitter { this._init(); } + /** + * Get the adapter scoped package identifier of a node module + * + * @param moduleName name of the node module + */ + getAdapterScopedPackageIdentifier(moduleName: string): string { + return getAdapterScopedPackageIdentifier({ moduleName, namespace: this.namespace }); + } + installNodeModule(moduleName: string, options: InstallNodeModuleOptions): Promise; /** diff --git a/packages/controller/test/lib/testAdapterHelpers.ts b/packages/controller/test/lib/testAdapterHelpers.ts index ab9247343..bf3ff7b3d 100644 --- a/packages/controller/test/lib/testAdapterHelpers.ts +++ b/packages/controller/test/lib/testAdapterHelpers.ts @@ -598,4 +598,12 @@ export function register(it: Mocha.TestFunction, expect: Chai.ExpectStatic, cont }); }); } + + it(context.name + ' ' + context.adapterShortName + ' getAdapterScopedPackageIdentifier', () => { + const nonOrgaPacket = context.adapter.getAdapterScopedPackageIdentifier('axios'); + const orgaPacket = context.adapter.getAdapterScopedPackageIdentifier('@iobroker/adapter-react-v5'); + + expect(nonOrgaPacket).to.be.equal('@iobroker-test.0/axios'); + expect(orgaPacket).to.be.equal('@iobroker-test.0/iobroker-adapter-react-v5'); + }); }