@axium/core 0.19.0 → 0.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/node/packages.d.ts +0 -1
- package/dist/node/packages.js +4 -18
- package/dist/node/plugins.js +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/node/packages.d.ts
CHANGED
package/dist/node/packages.js
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { findPackageJSON } from 'node:module';
|
|
4
3
|
import { lt as ltVersion } from 'semver';
|
|
5
4
|
import { warn } from '../io.js';
|
|
6
5
|
function isRelative(specifier) {
|
|
7
6
|
return specifier[0] == '/' || ['.', '..'].includes(specifier.split('/')[0]);
|
|
8
7
|
}
|
|
9
|
-
export function locatePackage(specifier, loadedBy) {
|
|
10
|
-
if (isRelative(specifier)) {
|
|
11
|
-
const path = resolve(dirname(loadedBy), specifier);
|
|
12
|
-
const stats = fs.statSync(path);
|
|
13
|
-
if (stats.isFile())
|
|
14
|
-
return path;
|
|
15
|
-
if (!stats.isDirectory())
|
|
16
|
-
throw new Error('Can not resolve package path: ' + path);
|
|
17
|
-
return join(path, 'package.json');
|
|
18
|
-
}
|
|
19
|
-
let packageDir = dirname(fileURLToPath(import.meta.resolve(specifier)));
|
|
20
|
-
for (; !fs.existsSync(join(packageDir, 'package.json')); packageDir = dirname(packageDir))
|
|
21
|
-
;
|
|
22
|
-
return join(packageDir, 'package.json');
|
|
23
|
-
}
|
|
24
8
|
let cacheTTL = 1000 * 60 * 60;
|
|
25
9
|
export function setPackageCacheTTL(seconds) {
|
|
26
10
|
cacheTTL = seconds * 1000;
|
|
@@ -31,7 +15,9 @@ const cache = new Map();
|
|
|
31
15
|
* @param version The current/installed version
|
|
32
16
|
*/
|
|
33
17
|
export async function getVersionInfo(specifier, from = import.meta.filename) {
|
|
34
|
-
const path =
|
|
18
|
+
const path = findPackageJSON(specifier, import.meta.resolve(specifier, from));
|
|
19
|
+
if (!path)
|
|
20
|
+
throw new Error(`Cannot find package.json for package ${specifier} (from ${from})`);
|
|
35
21
|
const { version, name } = JSON.parse(fs.readFileSync(path, 'utf8'));
|
|
36
22
|
const info = { name, version, latest: null };
|
|
37
23
|
if (isRelative(specifier))
|
package/dist/node/plugins.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as io from '@axium/core/node/io';
|
|
2
2
|
import { Plugin, plugins } from '@axium/core/plugins';
|
|
3
3
|
import * as fs from 'node:fs';
|
|
4
|
+
import { findPackageJSON } from 'node:module';
|
|
4
5
|
import { dirname, resolve } from 'node:path/posix';
|
|
5
6
|
import { styleText } from 'node:util';
|
|
6
7
|
import { _throw } from 'utilium';
|
|
7
8
|
import { apps } from '../apps.js';
|
|
8
|
-
import { locatePackage } from './packages.js';
|
|
9
9
|
export function* pluginText(plugin) {
|
|
10
10
|
yield styleText('whiteBright', plugin.name);
|
|
11
11
|
yield `Version: ${plugin.version}`;
|
|
@@ -21,7 +21,9 @@ export function* pluginText(plugin) {
|
|
|
21
21
|
}
|
|
22
22
|
export async function loadPlugin(mode, specifier, loadedBy, safeMode = false) {
|
|
23
23
|
try {
|
|
24
|
-
const path =
|
|
24
|
+
const path = findPackageJSON(specifier, import.meta.resolve(specifier, loadedBy));
|
|
25
|
+
if (!path)
|
|
26
|
+
throw new Error(`Cannot find package.json for package ${specifier} (from ${loadedBy})`);
|
|
25
27
|
io.debug(`Loading plugin at ${path} (from ${loadedBy})`);
|
|
26
28
|
let imported;
|
|
27
29
|
try {
|