@resourcexjs/core 2.16.1 → 2.17.1

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/dist/index.d.ts CHANGED
@@ -548,7 +548,8 @@ declare function loadResource(source: string, config?: LoadResourceConfig): Prom
548
548
  * Loading order:
549
549
  * 1. FolderSourceLoader (local directories)
550
550
  * 2. GitHubSourceLoader (GitHub URLs)
551
- * 3. Custom loaders (registered in order)
551
+ * 3. NpmSourceLoader (npm: prefixed packages)
552
+ * 4. Custom loaders (registered in order)
552
553
  */
553
554
  declare class SourceLoaderChain {
554
555
  private readonly loaders;
package/dist/index.js CHANGED
@@ -15137,6 +15137,38 @@ async function loadResource(source, config2) {
15137
15137
  }
15138
15138
  return loader.load(source);
15139
15139
  }
15140
+ // src/loader/NpmSourceLoader.ts
15141
+ import { dirname, join as join3 } from "node:path";
15142
+ import { fileURLToPath, pathToFileURL } from "node:url";
15143
+ var NPM_PREFIX = "npm:";
15144
+
15145
+ class NpmSourceLoader {
15146
+ folder = new FolderSourceLoader;
15147
+ canLoad(source) {
15148
+ return source.startsWith(NPM_PREFIX);
15149
+ }
15150
+ async load(source) {
15151
+ if (!this.canLoad(source)) {
15152
+ throw new ResourceXError(`Not an npm source: ${source}`);
15153
+ }
15154
+ const packageName = source.slice(NPM_PREFIX.length);
15155
+ if (!packageName) {
15156
+ throw new ResourceXError(`Empty package name in npm source: ${source}`);
15157
+ }
15158
+ const packageDir = this.resolvePackageDir(packageName);
15159
+ const rxs = await this.folder.load(packageDir);
15160
+ return { source, files: rxs.files };
15161
+ }
15162
+ resolvePackageDir(packageName) {
15163
+ const parent = pathToFileURL(join3(process.cwd(), "noop.js")).href;
15164
+ try {
15165
+ const url2 = import.meta.resolve(`${packageName}/package.json`, parent);
15166
+ return dirname(fileURLToPath(url2));
15167
+ } catch {
15168
+ throw new ResourceXError(`Cannot resolve npm package: ${packageName}`);
15169
+ }
15170
+ }
15171
+ }
15140
15172
  // src/loader/SourceLoaderChain.ts
15141
15173
  class SourceLoaderChain {
15142
15174
  loaders = [];
@@ -15145,6 +15177,7 @@ class SourceLoaderChain {
15145
15177
  const chain = new SourceLoaderChain;
15146
15178
  chain.loaders.push(new FolderSourceLoader);
15147
15179
  chain.loaders.push(new GitHubSourceLoader);
15180
+ chain.loaders.push(new NpmSourceLoader);
15148
15181
  return chain;
15149
15182
  }
15150
15183
  register(loader) {
@@ -15445,7 +15478,7 @@ class CASRegistry {
15445
15478
  }
15446
15479
  // src/registry/registries/LinkedRegistry.ts
15447
15480
  import { lstat, mkdir, readdir as readdir3, readlink, rm, symlink } from "node:fs/promises";
15448
- import { join as join3, resolve as resolvePath } from "node:path";
15481
+ import { join as join4, resolve as resolvePath } from "node:path";
15449
15482
  class LinkedRegistry {
15450
15483
  basePath;
15451
15484
  constructor(basePath) {
@@ -15454,11 +15487,11 @@ class LinkedRegistry {
15454
15487
  buildLinkPath(rxi) {
15455
15488
  const registry2 = rxi.registry ?? "localhost";
15456
15489
  const tag = rxi.tag ?? "latest";
15457
- let linkPath = join3(this.basePath, registry2);
15490
+ let linkPath = join4(this.basePath, registry2);
15458
15491
  if (rxi.path) {
15459
- linkPath = join3(linkPath, rxi.path);
15492
+ linkPath = join4(linkPath, rxi.path);
15460
15493
  }
15461
- return join3(linkPath, rxi.name, tag);
15494
+ return join4(linkPath, rxi.name, tag);
15462
15495
  }
15463
15496
  async isSymlink(path) {
15464
15497
  try {
@@ -15520,7 +15553,7 @@ class LinkedRegistry {
15520
15553
  await rm(linkPath, { recursive: true });
15521
15554
  }
15522
15555
  } catch {}
15523
- const parentPath = join3(linkPath, "..");
15556
+ const parentPath = join4(linkPath, "..");
15524
15557
  await mkdir(parentPath, { recursive: true });
15525
15558
  const absolutePath = resolvePath(devPath);
15526
15559
  await symlink(absolutePath, linkPath);
@@ -15537,7 +15570,7 @@ class LinkedRegistry {
15537
15570
  return;
15538
15571
  }
15539
15572
  for (const entry of entries) {
15540
- const fullPath = join3(dirPath, entry);
15573
+ const fullPath = join4(dirPath, entry);
15541
15574
  const relPath = relativePath ? `${relativePath}/${entry}` : entry;
15542
15575
  try {
15543
15576
  const stats = await lstat(fullPath);
@@ -15964,4 +15997,4 @@ export {
15964
15997
  CASRegistry
15965
15998
  };
15966
15999
 
15967
- //# debugId=00B289BE17187B1064756E2164756E21
16000
+ //# debugId=F11283FBFC6D53D064756E2164756E21