@resourcexjs/core 2.16.0 → 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
@@ -1,11 +1,15 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __returnValue = (v) => v;
3
+ function __exportSetter(name, newValue) {
4
+ this[name] = __returnValue.bind(null, newValue);
5
+ }
2
6
  var __export = (target, all) => {
3
7
  for (var name in all)
4
8
  __defProp(target, name, {
5
9
  get: all[name],
6
10
  enumerable: true,
7
11
  configurable: true,
8
- set: (newValue) => all[name] = () => newValue
12
+ set: __exportSetter.bind(all, name)
9
13
  });
10
14
  };
11
15
 
@@ -15133,6 +15137,37 @@ async function loadResource(source, config2) {
15133
15137
  }
15134
15138
  return loader.load(source);
15135
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
+ }
15136
15171
  // src/loader/SourceLoaderChain.ts
15137
15172
  class SourceLoaderChain {
15138
15173
  loaders = [];
@@ -15141,6 +15176,7 @@ class SourceLoaderChain {
15141
15176
  const chain = new SourceLoaderChain;
15142
15177
  chain.loaders.push(new FolderSourceLoader);
15143
15178
  chain.loaders.push(new GitHubSourceLoader);
15179
+ chain.loaders.push(new NpmSourceLoader);
15144
15180
  return chain;
15145
15181
  }
15146
15182
  register(loader) {
@@ -15960,4 +15996,4 @@ export {
15960
15996
  CASRegistry
15961
15997
  };
15962
15998
 
15963
- //# debugId=0BF8A796080AFBD664756E2164756E21
15999
+ //# debugId=8B42B108D3A1492364756E2164756E21