wesl-link 0.6.33 → 0.6.36
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/bin/wesl-link +76 -24
- package/package.json +3 -3
package/bin/wesl-link
CHANGED
|
@@ -9754,6 +9754,81 @@ function zip(as, bs) {
|
|
|
9754
9754
|
return as.map((a, i) => [a, bs[i]]);
|
|
9755
9755
|
}
|
|
9756
9756
|
|
|
9757
|
+
//#endregion
|
|
9758
|
+
//#region ../wesl-tooling/src/PackageNameUtils.ts
|
|
9759
|
+
/** Generate npm package name variations from sanitized WESL identifier.
|
|
9760
|
+
*
|
|
9761
|
+
* Uses double-underscore encoding to distinguish scoped vs unscoped packages:
|
|
9762
|
+
* - Has __ → scoped package (try @scope/pkg variants)
|
|
9763
|
+
* - No __ → unscoped package (try pkg variants)
|
|
9764
|
+
*
|
|
9765
|
+
* Examples:
|
|
9766
|
+
* "lygia__shader_utils" → ["@lygia/shader_utils", "@lygia/shader-utils"]
|
|
9767
|
+
* "random_wgsl" → ["random_wgsl", "random-wgsl"]
|
|
9768
|
+
*/
|
|
9769
|
+
function* npmNameVariations(sanitizedPath) {
|
|
9770
|
+
const [pkg, sub] = breakAt(sanitizedPath, "/");
|
|
9771
|
+
let pkgName = pkg;
|
|
9772
|
+
let scopePrefix = "";
|
|
9773
|
+
if (pkg.includes("__")) {
|
|
9774
|
+
const [scope, ...rest] = pkg.split("__");
|
|
9775
|
+
pkgName = rest.join("__");
|
|
9776
|
+
scopePrefix = `@${scope}/`;
|
|
9777
|
+
}
|
|
9778
|
+
yield `${scopePrefix}${pkgName}${sub}`;
|
|
9779
|
+
yield `${scopePrefix}${pkgName.replaceAll("_", "-")}${sub}`;
|
|
9780
|
+
}
|
|
9781
|
+
/** Break string at first occurrence of delimiter.
|
|
9782
|
+
* @returns [before, after] where after includes the delimiter */
|
|
9783
|
+
function breakAt(str, delimiter) {
|
|
9784
|
+
const index = str.indexOf(delimiter);
|
|
9785
|
+
if (index === -1) return [str, ""];
|
|
9786
|
+
return [str.slice(0, index), str.slice(index)];
|
|
9787
|
+
}
|
|
9788
|
+
|
|
9789
|
+
//#endregion
|
|
9790
|
+
//#region ../wesl-tooling/src/NpmResolver.ts
|
|
9791
|
+
/** Find longest resolvable npm subpath from WESL module path segments.
|
|
9792
|
+
*
|
|
9793
|
+
* A WESL statement containing a WESL module path like 'import foo__bar::baz::elem;' references
|
|
9794
|
+
* an npm package, an export within that package, a module within the WeslBundle,
|
|
9795
|
+
* and an element within the WESL module.
|
|
9796
|
+
* This function returns the npm package and export portion from the module path.
|
|
9797
|
+
* The return value is usable to dynamically import the corresponding weslBundle.js file.
|
|
9798
|
+
*
|
|
9799
|
+
* Translation from a WESL module path to an npm package path involves:
|
|
9800
|
+
* - Mapping WESL package names to their npm counterparts (e.g., 'foo__bar' -> '@foo/bar')
|
|
9801
|
+
* - Probing to find the longest valid export subpath within the package
|
|
9802
|
+
* - package.json allows export subpaths, so 'mypkg::gpu' could be 'mypkg/gpu' or just 'mypkg' in npm
|
|
9803
|
+
* - Probing to handle variations in package naming
|
|
9804
|
+
* - foo_bar could be foo-bar in npm
|
|
9805
|
+
*
|
|
9806
|
+
* Note that the resolution is based on package.json.
|
|
9807
|
+
* The resolved file itself may not exist yet. (e.g. dist/weslBundle.js may not have been built yet)
|
|
9808
|
+
*
|
|
9809
|
+
* @param mPath - Module path segments
|
|
9810
|
+
* @param importerURL - Base URL for resolution (e.g., 'file:///path/to/project/')
|
|
9811
|
+
* @returns Longest resolvable subpath (e.g., 'foo/bar/baz' or 'foo')
|
|
9812
|
+
*/
|
|
9813
|
+
function npmResolveWESL(mPath, importerURL) {
|
|
9814
|
+
for (const subPath of exportSubpaths(mPath)) for (const npmPath of npmNameVariations(subPath)) if (tryResolve(npmPath, importerURL)) return npmPath;
|
|
9815
|
+
}
|
|
9816
|
+
/** Try Node.js module resolution.
|
|
9817
|
+
* @return undefined if unresolvable. */
|
|
9818
|
+
function tryResolve(path$2, importerURL) {
|
|
9819
|
+
try {
|
|
9820
|
+
return resolve(path$2, importerURL);
|
|
9821
|
+
} catch {
|
|
9822
|
+
return;
|
|
9823
|
+
}
|
|
9824
|
+
}
|
|
9825
|
+
/** Yield possible export subpaths from module path, longest first.
|
|
9826
|
+
* Drops the last segment (element name) and iterates down. */
|
|
9827
|
+
function* exportSubpaths(mPath) {
|
|
9828
|
+
const longest = mPath.length - 1;
|
|
9829
|
+
for (let i = longest; i >= 0; i--) yield mPath.slice(0, i).join("/");
|
|
9830
|
+
}
|
|
9831
|
+
|
|
9757
9832
|
//#endregion
|
|
9758
9833
|
//#region ../wesl-tooling/src/ParseDependencies.ts
|
|
9759
9834
|
/**
|
|
@@ -9786,32 +9861,9 @@ function parseDependencies(weslSrc, projectDir) {
|
|
|
9786
9861
|
const pkgRefs = unbound.filter((modulePath) => modulePath.length > 1 && modulePath[0] !== "constants");
|
|
9787
9862
|
if (pkgRefs.length === 0) return [];
|
|
9788
9863
|
const projectURL = projectDirURL(projectDir);
|
|
9789
|
-
const deps = filterMap(pkgRefs, (mPath) =>
|
|
9864
|
+
const deps = filterMap(pkgRefs, (mPath) => npmResolveWESL(mPath, projectURL));
|
|
9790
9865
|
return [...new Set(deps)];
|
|
9791
9866
|
}
|
|
9792
|
-
/** Find longest resolvable npm subpath from module path segments.
|
|
9793
|
-
*
|
|
9794
|
-
* @param mPath - Module path segments (e.g., ['foo', 'bar', 'baz', 'elem'])
|
|
9795
|
-
* @param importerURL - Base URL for resolution (e.g., 'file:///path/to/project/')
|
|
9796
|
-
* @returns Longest resolvable subpath (e.g., 'foo/bar/baz' or 'foo')
|
|
9797
|
-
*/
|
|
9798
|
-
function unboundToDependency(mPath, importerURL) {
|
|
9799
|
-
return [...exportSubpaths(mPath)].find((subPath) => tryResolve(subPath, importerURL));
|
|
9800
|
-
}
|
|
9801
|
-
/** Try Node.js module resolution; returns undefined if unresolvable. */
|
|
9802
|
-
function tryResolve(path$2, importerURL) {
|
|
9803
|
-
try {
|
|
9804
|
-
return resolve(path$2, importerURL);
|
|
9805
|
-
} catch {
|
|
9806
|
-
return;
|
|
9807
|
-
}
|
|
9808
|
-
}
|
|
9809
|
-
/** Yield possible export subpaths from module path, longest first.
|
|
9810
|
-
* Drops the last segment (element name) and iterates down. */
|
|
9811
|
-
function* exportSubpaths(mPath) {
|
|
9812
|
-
const longest = mPath.length - 1;
|
|
9813
|
-
for (let i = longest; i >= 0; i--) yield mPath.slice(0, i).join("/");
|
|
9814
|
-
}
|
|
9815
9867
|
/**
|
|
9816
9868
|
* Load WeslBundle instances referenced by WESL sources.
|
|
9817
9869
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wesl-link",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.36",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": "bin/wesl-link",
|
|
6
6
|
"files": [
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"import-meta-resolve": "^4.1.0",
|
|
13
13
|
"yargs": "^18.0.0",
|
|
14
|
-
"mini-parse": "0.6.
|
|
15
|
-
"wesl": "0.6.
|
|
14
|
+
"mini-parse": "0.6.36",
|
|
15
|
+
"wesl": "0.6.36"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"wesl-tooling": "x"
|