Skip to content

Commit

Permalink
provide method getAdapterScopedPackageIdentifier on adapter level (#2845
Browse files Browse the repository at this point in the history
)

- javascripts needs it, see ioBroker/ioBroker.javascript#1642
  • Loading branch information
foxriver76 authored Jul 20, 2024
1 parent 88217f1 commit 12a17e8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions packages/adapter/src/lib/adapter/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandResult>;

/**
Expand Down
8 changes: 8 additions & 0 deletions packages/controller/test/lib/testAdapterHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
}

0 comments on commit 12a17e8

Please sign in to comment.