wesl-fetch 0.0.11 → 0.0.13
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.js +7 -12
- package/package.json +2 -2
- package/src/PackageLoader.ts +14 -7
- package/tsdown.config.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { gunzipSync } from "fflate";
|
|
|
2
2
|
import { parseTar } from "nanotar";
|
|
3
3
|
import { RecordResolver, fileToModulePath, findUnboundIdents, modulePartsToRelativePath, npmNameVariations, parseSrcModule, partition } from "wesl";
|
|
4
4
|
import { resolve } from "resolve.exports";
|
|
5
|
-
|
|
6
5
|
//#region src/BundleHydrator.ts
|
|
7
6
|
const importPattern = /import\s+(?:\*\s+as\s+)?(\w+)\s+from\s+["']([^"']+)["']/g;
|
|
8
7
|
const nestedBundlePattern = /package\/dist\/(.+)\/weslBundle\.js$/;
|
|
@@ -79,7 +78,6 @@ async function hydrateBundle(path, registry, hydrated, fetcher) {
|
|
|
79
78
|
Object.assign(placeholder, bundle);
|
|
80
79
|
return placeholder;
|
|
81
80
|
}
|
|
82
|
-
|
|
83
81
|
//#endregion
|
|
84
82
|
//#region src/BundleLoader.ts
|
|
85
83
|
/** Fetch and extract tgz file, returning tar entries (cached). */
|
|
@@ -173,7 +171,6 @@ function extractPackageName(bundleContent) {
|
|
|
173
171
|
if (!nameMatch) throw new Error("Could not extract package name from bundle");
|
|
174
172
|
return nameMatch[1];
|
|
175
173
|
}
|
|
176
|
-
|
|
177
174
|
//#endregion
|
|
178
175
|
//#region src/FetchingResolver.ts
|
|
179
176
|
/** Resolver with sync interface for findUnboundIdents and async API for fetching. */
|
|
@@ -257,7 +254,6 @@ async function fetchWithExtensions(baseUrl) {
|
|
|
257
254
|
if (response.ok) return response.text();
|
|
258
255
|
} catch {}
|
|
259
256
|
}
|
|
260
|
-
|
|
261
257
|
//#endregion
|
|
262
258
|
//#region src/HttpPackageLoader.ts
|
|
263
259
|
const packageJsonCache = /* @__PURE__ */ new Map();
|
|
@@ -396,7 +392,6 @@ async function fetchBundleFile(pkgName, bundlePath, packageBase) {
|
|
|
396
392
|
function normalizeUrl(url) {
|
|
397
393
|
return url.replace(/([^:])\/+/g, "$1/");
|
|
398
394
|
}
|
|
399
|
-
|
|
400
395
|
//#endregion
|
|
401
396
|
//#region src/PackageLoader.ts
|
|
402
397
|
const virtualModules = ["constants", "env"];
|
|
@@ -405,7 +400,8 @@ async function fetchDependencies(rootModuleSource, options) {
|
|
|
405
400
|
const shaderRoot = options?.shaderRoot ?? "/shaders";
|
|
406
401
|
const currentPath = options?.currentPath;
|
|
407
402
|
const existingSources = options?.existingSources;
|
|
408
|
-
const
|
|
403
|
+
const fetchLibs = options?.fetchLibs ?? true;
|
|
404
|
+
const fetchSources = options?.fetchSources ?? true;
|
|
409
405
|
const rootModuleName = currentPath ? urlToModulePath(currentPath, shaderRoot) : "package::main";
|
|
410
406
|
const resolver = new FetchingResolver({
|
|
411
407
|
...existingSources,
|
|
@@ -421,12 +417,12 @@ async function fetchDependencies(rootModuleSource, options) {
|
|
|
421
417
|
const unresolved = getNonVirtualUnresolved(resolver, fetched);
|
|
422
418
|
if (unresolved.length === 0) break;
|
|
423
419
|
const [internal, external] = partition(unresolved, isInternal);
|
|
424
|
-
await Promise.all(internal.map((p) => resolver.resolveModuleAsync(p)));
|
|
425
|
-
|
|
426
|
-
|
|
420
|
+
if (fetchSources) await Promise.all(internal.map((p) => resolver.resolveModuleAsync(p)));
|
|
421
|
+
else for (const p of internal) fetched.add(p);
|
|
422
|
+
if (fetchLibs) {
|
|
427
423
|
const newLibs = await fetchExternalBundles(external, fetched);
|
|
428
424
|
libs.push(...newLibs);
|
|
429
|
-
}
|
|
425
|
+
} else for (const p of external) fetched.add(p.split("::")[0]);
|
|
430
426
|
}
|
|
431
427
|
return {
|
|
432
428
|
libs,
|
|
@@ -502,6 +498,5 @@ async function fetchOnePackage(pkgId, loaded) {
|
|
|
502
498
|
} catch {}
|
|
503
499
|
throw new Error(`Package not found: ${pkgId}`);
|
|
504
500
|
}
|
|
505
|
-
|
|
506
501
|
//#endregion
|
|
507
|
-
export { FetchingResolver, bundleRegistry, clearHttpCache, fetchBundleFilesFromNpm, fetchDependencies, fetchPackagesByName, fetchPackagesFromHttp, hydrateBundleRegistry, loadBundlesFromFiles, loadBundlesFromTgz, loadBundlesWithPackageName, loadShaderFromUrl };
|
|
502
|
+
export { FetchingResolver, bundleRegistry, clearHttpCache, fetchBundleFilesFromNpm, fetchDependencies, fetchPackagesByName, fetchPackagesFromHttp, hydrateBundleRegistry, loadBundlesFromFiles, loadBundlesFromTgz, loadBundlesWithPackageName, loadShaderFromUrl };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wesl-fetch",
|
|
3
3
|
"description": "Browser-based HTTP fetching for WESL packages from npm",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.13",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": "github:wgsl-tooling-wg/wesl-js",
|
|
7
7
|
"exports": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"fflate": "^0.8.2",
|
|
12
12
|
"nanotar": "^0.2.0",
|
|
13
13
|
"resolve.exports": "^2.0.3",
|
|
14
|
-
"wesl": "0.7.
|
|
14
|
+
"wesl": "0.7.25"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
17
|
"build": "tsdown",
|
package/src/PackageLoader.ts
CHANGED
|
@@ -47,8 +47,10 @@ export interface FetchOptions {
|
|
|
47
47
|
currentPath?: string;
|
|
48
48
|
/** Pre-existing sources to include. */
|
|
49
49
|
existingSources?: Record<string, string>;
|
|
50
|
-
/**
|
|
51
|
-
|
|
50
|
+
/** Fetch library packages from npm (default: true). */
|
|
51
|
+
fetchLibs?: boolean;
|
|
52
|
+
/** Fetch local .wesl source files via HTTP (default: true). */
|
|
53
|
+
fetchSources?: boolean;
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
const virtualModules = ["constants", "env"];
|
|
@@ -61,7 +63,8 @@ export async function fetchDependencies(
|
|
|
61
63
|
const shaderRoot = options?.shaderRoot ?? "/shaders";
|
|
62
64
|
const currentPath = options?.currentPath;
|
|
63
65
|
const existingSources = options?.existingSources;
|
|
64
|
-
const
|
|
66
|
+
const fetchLibs = options?.fetchLibs ?? true;
|
|
67
|
+
const fetchSources = options?.fetchSources ?? true;
|
|
65
68
|
|
|
66
69
|
const rootModuleName = currentPath
|
|
67
70
|
? urlToModulePath(currentPath, shaderRoot)
|
|
@@ -84,13 +87,17 @@ export async function fetchDependencies(
|
|
|
84
87
|
if (unresolved.length === 0) break;
|
|
85
88
|
|
|
86
89
|
const [internal, external] = partition(unresolved, isInternal);
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (skipExternal) {
|
|
90
|
-
for (const p of external) fetched.add(p.split("::")[0]);
|
|
90
|
+
if (fetchSources) {
|
|
91
|
+
await Promise.all(internal.map(p => resolver.resolveModuleAsync(p)));
|
|
91
92
|
} else {
|
|
93
|
+
for (const p of internal) fetched.add(p);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (fetchLibs) {
|
|
92
97
|
const newLibs = await fetchExternalBundles(external, fetched);
|
|
93
98
|
libs.push(...newLibs);
|
|
99
|
+
} else {
|
|
100
|
+
for (const p of external) fetched.add(p.split("::")[0]);
|
|
94
101
|
}
|
|
95
102
|
}
|
|
96
103
|
|
package/tsdown.config.ts
CHANGED