@vorplex/compiler 0.0.23 → 0.0.25

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.
@@ -18,20 +18,20 @@ export interface PackageFile {
18
18
  path?: string;
19
19
  content: string;
20
20
  }
21
- export declare const JsDelivrCacheStore: {
22
- readonly PackageVersion: "package-version";
23
- readonly Data: "data";
24
- readonly PackageJson: "package-json";
25
- readonly FilePath: "file-path";
26
- readonly File: "file";
27
- readonly ImportFilePath: "import-filePath";
21
+ export type JsDelivrStorageDefinition = {
22
+ cache: {
23
+ 'package-version': string;
24
+ data: JsDelivrData;
25
+ 'file-path': string;
26
+ file: PackageFile;
27
+ 'package-json': PackageJson;
28
+ };
28
29
  };
29
- export type JsDelivrCacheStore = typeof JsDelivrCacheStore[keyof typeof JsDelivrCacheStore];
30
30
  export declare class JsDelivr {
31
31
  static readonly url: "https://cdn.jsdelivr.net/npm";
32
32
  static readonly dataUrl: "https://data.jsdelivr.com/v1/packages/npm";
33
33
  static readonly resolveUrl: "https://data.jsdelivr.com/v1/package/resolve/npm";
34
- static cache: StorageProvider<'js-delivr', JsDelivrCacheStore>;
34
+ static cache: StorageProvider<JsDelivrStorageDefinition>;
35
35
  static resolveVersion(name: string, semanticVersion?: string): Promise<string>;
36
36
  static getPackageVersions(name: string): Promise<string[]>;
37
37
  static getData(name: string, semanticVersion: string): Promise<JsDelivrData>;
@@ -1,12 +1,4 @@
1
1
  import { $Path, $String, InMemoryStorage } from '@vorplex/core';
2
- export const JsDelivrCacheStore = {
3
- PackageVersion: 'package-version',
4
- Data: 'data',
5
- PackageJson: 'package-json',
6
- FilePath: 'file-path',
7
- File: 'file',
8
- ImportFilePath: 'import-filePath'
9
- };
10
2
  export class JsDelivr {
11
3
  static url = 'https://cdn.jsdelivr.net/npm';
12
4
  static dataUrl = 'https://data.jsdelivr.com/v1/packages/npm';
@@ -15,7 +7,7 @@ export class JsDelivr {
15
7
  static async resolveVersion(name, semanticVersion) {
16
8
  semanticVersion ??= 'latest';
17
9
  const key = `${name}@${semanticVersion}`;
18
- const cached = await this.cache.get('js-delivr', JsDelivrCacheStore.PackageVersion, key);
10
+ const cached = await this.cache.get('cache', 'package-version', key);
19
11
  if (cached)
20
12
  return cached;
21
13
  const url = $Path.join(this.resolveUrl, `${name}@${semanticVersion}`);
@@ -23,7 +15,7 @@ export class JsDelivr {
23
15
  if (!response.ok)
24
16
  throw new Error(`Failed to fetch package (${name}) version (${semanticVersion}). ${response.statusText}`);
25
17
  const data = (await response.json());
26
- await this.cache.set('js-delivr', JsDelivrCacheStore.PackageVersion, key, data.version);
18
+ await this.cache.set('cache', 'package-version', key, data.version);
27
19
  return data.version;
28
20
  }
29
21
  static async getPackageVersions(name) {
@@ -37,7 +29,7 @@ export class JsDelivr {
37
29
  static async getData(name, semanticVersion) {
38
30
  const version = await this.resolveVersion(name, semanticVersion);
39
31
  const key = `${name}@${version}`;
40
- const cached = await this.cache.get('js-delivr', JsDelivrCacheStore.Data, key);
32
+ const cached = await this.cache.get('cache', 'data', key);
41
33
  if (cached)
42
34
  return cached;
43
35
  const url = $Path.join(this.dataUrl, `${name}@${version}`);
@@ -45,7 +37,7 @@ export class JsDelivr {
45
37
  if (!response.ok)
46
38
  throw new Error(`Failed to fetch package (${name}) metadata. ${response.statusText}`);
47
39
  const data = await response.json();
48
- await this.cache.set('js-delivr', JsDelivrCacheStore.Data, key, data);
40
+ await this.cache.set('cache', 'data', key, data);
49
41
  return data;
50
42
  }
51
43
  static async getFilePaths(name, semanticVersion, regex) {
@@ -68,7 +60,7 @@ export class JsDelivr {
68
60
  static async resolveFilePath(name, semanticVersion, path) {
69
61
  const version = await this.resolveVersion(name, semanticVersion);
70
62
  const key = `${name}@${version}:${path}`;
71
- const cached = await this.cache.get('js-delivr', JsDelivrCacheStore.FilePath, key);
63
+ const cached = await this.cache.get('cache', 'file-path', key);
72
64
  if (cached)
73
65
  return cached;
74
66
  const paths = await this.getFilePaths(name, version, new RegExp('^' + $String.sanitizeForRegex($Path.absolute(path)) + '(?:\\.js|/index.js)?$'));
@@ -83,7 +75,7 @@ export class JsDelivr {
83
75
  }
84
76
  const resolved = paths.sort((a, b) => getPathPriority(b) - getPathPriority(a))[0];
85
77
  if (resolved)
86
- await this.cache.set('js-delivr', JsDelivrCacheStore.FilePath, key, resolved);
78
+ await this.cache.set('cache', 'file-path', key, resolved);
87
79
  return resolved;
88
80
  }
89
81
  static async getFile(name, semanticVersion, path) {
@@ -92,7 +84,7 @@ export class JsDelivr {
92
84
  if (path && !resolvedPath)
93
85
  throw new Error(`Failed to resolve path (${path}) from package (${name}) version (${semanticVersion}). Not Found.`);
94
86
  const key = `${name}@${resolvedVersion}:${resolvedPath ?? ''}`;
95
- const cached = await this.cache.get('js-delivr', JsDelivrCacheStore.File, key);
87
+ const cached = await this.cache.get('cache', 'file', key);
96
88
  if (cached)
97
89
  return cached;
98
90
  const url = $Path.join(this.url, `${name}@${resolvedVersion}`, resolvedPath);
@@ -107,18 +99,18 @@ export class JsDelivr {
107
99
  path: resolvedPath,
108
100
  content: await response.text(),
109
101
  };
110
- await this.cache.set('js-delivr', JsDelivrCacheStore.File, key, file);
102
+ await this.cache.set('cache', 'file', key, file);
111
103
  return file;
112
104
  }
113
105
  static async getPackageJson(name, semanticVersion) {
114
106
  const version = await this.resolveVersion(name, semanticVersion);
115
107
  const key = `${name}@${version}`;
116
- const cached = await this.cache.get('js-delivr', JsDelivrCacheStore.PackageJson, key);
108
+ const cached = await this.cache.get('cache', 'package-json', key);
117
109
  if (cached)
118
110
  return cached;
119
111
  const { content } = await this.getFile(name, semanticVersion, 'package.json');
120
112
  const packageJson = JSON.parse(content);
121
- await this.cache.set('js-delivr', JsDelivrCacheStore.PackageJson, key, packageJson);
113
+ await this.cache.set('cache', 'package-json', key, packageJson);
122
114
  return packageJson;
123
115
  }
124
116
  static parseUrl(url) {
@@ -127,7 +119,7 @@ export class JsDelivr {
127
119
  static async resolveImportFilePath(packageName, semanticVersion, subpath) {
128
120
  const version = await this.resolveVersion(packageName, semanticVersion);
129
121
  const key = `${packageName}@${version}:${subpath ?? ''}`;
130
- const cached = await this.cache.get('js-delivr', JsDelivrCacheStore.ImportFilePath, key);
122
+ const cached = await this.cache.get('cache', 'file-path', key);
131
123
  if (cached)
132
124
  return cached;
133
125
  const packageJson = await this.getPackageJson(packageName, version);
@@ -184,25 +176,25 @@ export class JsDelivr {
184
176
  const exports = await resolveExports(packageJson.exports);
185
177
  if (!subpath && exports['.']) {
186
178
  const result = $Path.absolute(exports['.']);
187
- await this.cache.set('js-delivr', JsDelivrCacheStore.ImportFilePath, key, result);
179
+ await this.cache.set('cache', 'file-path', key, result);
188
180
  return result;
189
181
  }
190
182
  if (subpath && exports[$Path.relative(subpath)]) {
191
183
  const result = $Path.absolute(exports[$Path.relative(subpath)]);
192
- await this.cache.set('js-delivr', JsDelivrCacheStore.ImportFilePath, key, result);
184
+ await this.cache.set('cache', 'file-path', key, result);
193
185
  return result;
194
186
  }
195
187
  }
196
188
  if (subpath) {
197
189
  const file = await this.resolveFilePath(packageName, version, subpath);
198
190
  if (file) {
199
- await this.cache.set('js-delivr', JsDelivrCacheStore.ImportFilePath, key, file);
191
+ await this.cache.set('cache', 'file-path', key, file);
200
192
  return file;
201
193
  }
202
194
  }
203
195
  else {
204
196
  const result = $Path.absolute(packageJson.module || packageJson.main || 'index.js');
205
- await this.cache.set('js-delivr', JsDelivrCacheStore.ImportFilePath, key, result);
197
+ await this.cache.set('cache', 'file-path', key, result);
206
198
  return result;
207
199
  }
208
200
  throw new Error(`Failed to resolve file path for import (${packageName}${subpath ? `/${subpath}` : ''}@${semanticVersion})`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vorplex/compiler",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -15,11 +15,11 @@
15
15
  "types": "./dist/index.d.ts",
16
16
  "main": "./dist/index.js",
17
17
  "dependencies": {
18
+ "@vorplex/core": "0.0.25",
19
+ "semver": "7.7.3",
18
20
  "esbuild-wasm": "0.25.12",
19
21
  "tslib": "2.8.1",
20
22
  "typescript": "5.9.3",
21
- "@vorplex/core": "0.0.23",
22
- "semver": "7.7.3",
23
23
  "yaml": "2.8.2"
24
24
  },
25
25
  "devDependencies": {