@resourcexjs/core 2.16.1 → 2.17.0

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,37 @@ async function loadResource(source, config2) {
15137
15137
  }
15138
15138
  return loader.load(source);
15139
15139
  }
15140
+ // src/loader/NpmSourceLoader.ts
15141
+ import { dirname } from "node:path";
15142
+ import { fileURLToPath } 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
+ try {
15164
+ const url2 = import.meta.resolve(`${packageName}/package.json`);
15165
+ return dirname(fileURLToPath(url2));
15166
+ } catch {
15167
+ throw new ResourceXError(`Cannot resolve npm package: ${packageName}`);
15168
+ }
15169
+ }
15170
+ }
15140
15171
  // src/loader/SourceLoaderChain.ts
15141
15172
  class SourceLoaderChain {
15142
15173
  loaders = [];
@@ -15145,6 +15176,7 @@ class SourceLoaderChain {
15145
15176
  const chain = new SourceLoaderChain;
15146
15177
  chain.loaders.push(new FolderSourceLoader);
15147
15178
  chain.loaders.push(new GitHubSourceLoader);
15179
+ chain.loaders.push(new NpmSourceLoader);
15148
15180
  return chain;
15149
15181
  }
15150
15182
  register(loader) {
@@ -15964,4 +15996,4 @@ export {
15964
15996
  CASRegistry
15965
15997
  };
15966
15998
 
15967
- //# debugId=00B289BE17187B1064756E2164756E21
15999
+ //# debugId=8B42B108D3A1492364756E2164756E21