@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 CHANGED
@@ -1 +1,3 @@
1
1
  # Axium Core
2
+
3
+ Axium Core is the shared library of types, schemas, and utilities for the Axium ecosystem.
@@ -1,5 +1,4 @@
1
1
  import type { PackageVersionInfo } from '../packages.js';
2
- export declare function locatePackage(specifier: string, loadedBy: string): string;
3
2
  export declare function setPackageCacheTTL(seconds: number): void;
4
3
  /**
5
4
  * @param name Package name
@@ -1,26 +1,10 @@
1
1
  import * as fs from 'node:fs';
2
- import { dirname, join, resolve } from 'node:path/posix';
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 = locatePackage(specifier, from);
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))
@@ -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 = locatePackage(specifier, loadedBy);
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axium/core",
3
- "version": "0.19.0",
3
+ "version": "0.19.2",
4
4
  "author": "James Prevett <axium@jamespre.dev>",
5
5
  "funding": {
6
6
  "type": "individual",