Skip to content

Commit eca350d

Browse files
authored
[fix]: another fix for GH dependencies by adapters (#2803)
* prepare changelog for beta * allow to install github urls too * add to docs * fix the validation log * trim output from npm view * fix linter * listInstalledNodeModules now returns correct name also for GitHub dependencies * request module name as determining package json is not trivial in all cases
1 parent e65a97e commit eca350d

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
## __WORK IN PROGRESS__
55
-->
66

7-
## 6.0.3 (2024-06-12) - Kiera
7+
## __WORK IN PROGRESS__ - Kiera
88

99
**Breaking changes**
1010
* Support for Node.js 16 is dropped!

packages/adapter/src/lib/adapter/utils.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import {
1010
import { SUPPORTED_FEATURES, type SupportedFeature } from '@/lib/adapter/constants.js';
1111
import path from 'node:path';
1212
import fs from 'fs-extra';
13-
import { createRequire } from 'node:module';
14-
15-
// eslint-disable-next-line unicorn/prefer-module
16-
const require = createRequire(import.meta.url || 'file://' + __filename);
1713

1814
interface EncryptArrayOptions {
1915
/** The objects whose values should be en/decrypted */
@@ -118,15 +114,20 @@ export async function listInstalledNodeModules(namespace: string): Promise<strin
118114
};
119115
const dependencies: string[] = [];
120116

121-
for (const dependency of Object.keys(packJson.dependencies)) {
117+
for (const [dependency, versionInfo] of Object.entries(packJson.dependencies)) {
122118
if (!dependency.startsWith(`@${appNameLowerCase}-${namespace}/`)) {
123119
continue;
124120
}
125121

126-
const packPath = require.resolve(`${dependency}/package.json`);
127-
const packJson = await fs.readJson(packPath);
122+
let realDependencyName: string;
123+
// remove npm: and version after last @
124+
if (versionInfo.startsWith('npm:')) {
125+
realDependencyName = versionInfo.substring(4, versionInfo.lastIndexOf('@'));
126+
} else {
127+
realDependencyName = await requestModuleNameByUrl(versionInfo);
128+
}
128129

129-
dependencies.push(packJson.name);
130+
dependencies.push(realDependencyName);
130131
}
131132

132133
return dependencies;

packages/common-db/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Common DB class for ioBroker
2-
The Library contains the common utils of ioBroker which use the DB directly and thus cannot be required by the DB itself (cirular dependencies).
3-
It makes sense to place methods here too, which require typings from the database if they are surely not used by the database.
2+
The Library contains the common utils for the ioBroker controller which can be used by db classes too, as they do not rely on the db (circular dependencies).
43

54
## License
65
MIT

packages/common/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Common class for ioBroker
2-
The Library contains the common utils for the ioBroker controller.
2+
The Library contains the common utils of ioBroker which use the DB directly and thus cannot be required by the DB itself (cirular dependencies).
3+
It makes sense to place methods here too, which require typings from the database if they are surely not used by the database.
34

45
## License
56
MIT

0 commit comments

Comments
 (0)