wesl-plugin 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.
@@ -9712,6 +9712,81 @@ async function findWeslToml(projectDir, specifiedToml) {
9712
9712
  };
9713
9713
  }
9714
9714
 
9715
+ //#endregion
9716
+ //#region ../wesl-tooling/src/PackageNameUtils.ts
9717
+ /** Generate npm package name variations from sanitized WESL identifier.
9718
+ *
9719
+ * Uses double-underscore encoding to distinguish scoped vs unscoped packages:
9720
+ * - Has __ → scoped package (try @scope/pkg variants)
9721
+ * - No __ → unscoped package (try pkg variants)
9722
+ *
9723
+ * Examples:
9724
+ * "lygia__shader_utils" → ["@lygia/shader_utils", "@lygia/shader-utils"]
9725
+ * "random_wgsl" → ["random_wgsl", "random-wgsl"]
9726
+ */
9727
+ function* npmNameVariations(sanitizedPath) {
9728
+ const [pkg, sub] = breakAt(sanitizedPath, "/");
9729
+ let pkgName = pkg;
9730
+ let scopePrefix = "";
9731
+ if (pkg.includes("__")) {
9732
+ const [scope, ...rest] = pkg.split("__");
9733
+ pkgName = rest.join("__");
9734
+ scopePrefix = `@${scope}/`;
9735
+ }
9736
+ yield `${scopePrefix}${pkgName}${sub}`;
9737
+ yield `${scopePrefix}${pkgName.replaceAll("_", "-")}${sub}`;
9738
+ }
9739
+ /** Break string at first occurrence of delimiter.
9740
+ * @returns [before, after] where after includes the delimiter */
9741
+ function breakAt(str, delimiter) {
9742
+ const index = str.indexOf(delimiter);
9743
+ if (index === -1) return [str, ""];
9744
+ return [str.slice(0, index), str.slice(index)];
9745
+ }
9746
+
9747
+ //#endregion
9748
+ //#region ../wesl-tooling/src/NpmResolver.ts
9749
+ /** Find longest resolvable npm subpath from WESL module path segments.
9750
+ *
9751
+ * A WESL statement containing a WESL module path like 'import foo__bar::baz::elem;' references
9752
+ * an npm package, an export within that package, a module within the WeslBundle,
9753
+ * and an element within the WESL module.
9754
+ * This function returns the npm package and export portion from the module path.
9755
+ * The return value is usable to dynamically import the corresponding weslBundle.js file.
9756
+ *
9757
+ * Translation from a WESL module path to an npm package path involves:
9758
+ * - Mapping WESL package names to their npm counterparts (e.g., 'foo__bar' -> '@foo/bar')
9759
+ * - Probing to find the longest valid export subpath within the package
9760
+ * - package.json allows export subpaths, so 'mypkg::gpu' could be 'mypkg/gpu' or just 'mypkg' in npm
9761
+ * - Probing to handle variations in package naming
9762
+ * - foo_bar could be foo-bar in npm
9763
+ *
9764
+ * Note that the resolution is based on package.json.
9765
+ * The resolved file itself may not exist yet. (e.g. dist/weslBundle.js may not have been built yet)
9766
+ *
9767
+ * @param mPath - Module path segments
9768
+ * @param importerURL - Base URL for resolution (e.g., 'file:///path/to/project/')
9769
+ * @returns Longest resolvable subpath (e.g., 'foo/bar/baz' or 'foo')
9770
+ */
9771
+ function npmResolveWESL(mPath, importerURL) {
9772
+ for (const subPath of exportSubpaths(mPath)) for (const npmPath of npmNameVariations(subPath)) if (tryResolve(npmPath, importerURL)) return npmPath;
9773
+ }
9774
+ /** Try Node.js module resolution.
9775
+ * @return undefined if unresolvable. */
9776
+ function tryResolve(path$2, importerURL) {
9777
+ try {
9778
+ return resolve(path$2, importerURL);
9779
+ } catch {
9780
+ return;
9781
+ }
9782
+ }
9783
+ /** Yield possible export subpaths from module path, longest first.
9784
+ * Drops the last segment (element name) and iterates down. */
9785
+ function* exportSubpaths(mPath) {
9786
+ const longest = mPath.length - 1;
9787
+ for (let i = longest; i >= 0; i--) yield mPath.slice(0, i).join("/");
9788
+ }
9789
+
9715
9790
  //#endregion
9716
9791
  //#region ../wesl-tooling/src/ParseDependencies.ts
9717
9792
  /**
@@ -9744,32 +9819,9 @@ function parseDependencies(weslSrc, projectDir) {
9744
9819
  const pkgRefs = unbound.filter((modulePath) => modulePath.length > 1 && modulePath[0] !== "constants");
9745
9820
  if (pkgRefs.length === 0) return [];
9746
9821
  const projectURL = projectDirURL(projectDir);
9747
- const deps = filterMap(pkgRefs, (mPath) => unboundToDependency(mPath, projectURL));
9822
+ const deps = filterMap(pkgRefs, (mPath) => npmResolveWESL(mPath, projectURL));
9748
9823
  return [...new Set(deps)];
9749
9824
  }
9750
- /** Find longest resolvable npm subpath from module path segments.
9751
- *
9752
- * @param mPath - Module path segments (e.g., ['foo', 'bar', 'baz', 'elem'])
9753
- * @param importerURL - Base URL for resolution (e.g., 'file:///path/to/project/')
9754
- * @returns Longest resolvable subpath (e.g., 'foo/bar/baz' or 'foo')
9755
- */
9756
- function unboundToDependency(mPath, importerURL) {
9757
- return [...exportSubpaths(mPath)].find((subPath) => tryResolve(subPath, importerURL));
9758
- }
9759
- /** Try Node.js module resolution; returns undefined if unresolvable. */
9760
- function tryResolve(path$2, importerURL) {
9761
- try {
9762
- return resolve(path$2, importerURL);
9763
- } catch {
9764
- return;
9765
- }
9766
- }
9767
- /** Yield possible export subpaths from module path, longest first.
9768
- * Drops the last segment (element name) and iterates down. */
9769
- function* exportSubpaths(mPath) {
9770
- const longest = mPath.length - 1;
9771
- for (let i = longest; i >= 0; i--) yield mPath.slice(0, i).join("/");
9772
- }
9773
9825
  /** Normalize project directory to file:// URL with trailing slash. */
9774
9826
  function projectDirURL(projectDir) {
9775
9827
  if (projectDir.startsWith("file://")) return projectDir.endsWith("/") ? projectDir : `${projectDir}/`;
@@ -1,4 +1,4 @@
1
- import { t as WeslPlugin_default } from "../WeslPlugin-C5v2QWgI.js";
1
+ import { t as WeslPlugin_default } from "../WeslPlugin-D0IEnDmK.js";
2
2
  import "../import-meta-resolve-CUFqnZwT.js";
3
3
 
4
4
  //#region src/plugins/astro.ts
@@ -1,4 +1,4 @@
1
- import { n as weslPlugin } from "../WeslPlugin-C5v2QWgI.js";
1
+ import { n as weslPlugin } from "../WeslPlugin-D0IEnDmK.js";
2
2
  import "../import-meta-resolve-CUFqnZwT.js";
3
3
  import { createEsbuildPlugin } from "unplugin";
4
4
 
@@ -1,4 +1,4 @@
1
- import { n as weslPlugin } from "../WeslPlugin-C5v2QWgI.js";
1
+ import { n as weslPlugin } from "../WeslPlugin-D0IEnDmK.js";
2
2
  import "../import-meta-resolve-CUFqnZwT.js";
3
3
  import { createFarmPlugin } from "unplugin";
4
4
 
@@ -1,7 +1,7 @@
1
- import "../WeslPlugin-C5v2QWgI.js";
1
+ import "../WeslPlugin-D0IEnDmK.js";
2
2
  import "../import-meta-resolve-CUFqnZwT.js";
3
- import { t as vite_default } from "../vite-DIETRAJZ.js";
4
- import { t as webpack_default } from "../webpack-CKpSvDUR.js";
3
+ import { t as vite_default } from "../vite-CccajS5p.js";
4
+ import { t as webpack_default } from "../webpack-Duvcn8o1.js";
5
5
  import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
6
6
  import "@nuxt/schema";
7
7
 
@@ -1,4 +1,4 @@
1
- import { n as weslPlugin } from "../WeslPlugin-C5v2QWgI.js";
1
+ import { n as weslPlugin } from "../WeslPlugin-D0IEnDmK.js";
2
2
  import "../import-meta-resolve-CUFqnZwT.js";
3
3
  import { createRollupPlugin } from "unplugin";
4
4
 
@@ -1,4 +1,4 @@
1
- import { n as weslPlugin } from "../WeslPlugin-C5v2QWgI.js";
1
+ import { n as weslPlugin } from "../WeslPlugin-D0IEnDmK.js";
2
2
  import "../import-meta-resolve-CUFqnZwT.js";
3
3
  import { createRspackPlugin } from "unplugin";
4
4
 
@@ -1,5 +1,5 @@
1
- import "../WeslPlugin-C5v2QWgI.js";
1
+ import "../WeslPlugin-D0IEnDmK.js";
2
2
  import "../import-meta-resolve-CUFqnZwT.js";
3
- import { t as vite_default } from "../vite-DIETRAJZ.js";
3
+ import { t as vite_default } from "../vite-CccajS5p.js";
4
4
 
5
5
  export { vite_default as default };
@@ -1,5 +1,5 @@
1
- import "../WeslPlugin-C5v2QWgI.js";
1
+ import "../WeslPlugin-D0IEnDmK.js";
2
2
  import "../import-meta-resolve-CUFqnZwT.js";
3
- import { t as webpack_default } from "../webpack-CKpSvDUR.js";
3
+ import { t as webpack_default } from "../webpack-Duvcn8o1.js";
4
4
 
5
5
  export { webpack_default as default };
@@ -1,4 +1,4 @@
1
- import { n as weslPlugin } from "./WeslPlugin-C5v2QWgI.js";
1
+ import { n as weslPlugin } from "./WeslPlugin-D0IEnDmK.js";
2
2
  import { createVitePlugin } from "unplugin";
3
3
 
4
4
  //#region src/plugins/vite.ts
@@ -1,4 +1,4 @@
1
- import { n as weslPlugin } from "./WeslPlugin-C5v2QWgI.js";
1
+ import { n as weslPlugin } from "./WeslPlugin-D0IEnDmK.js";
2
2
  import { createWebpackPlugin } from "unplugin";
3
3
 
4
4
  //#region src/plugins/webpack.ts
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wesl-plugin",
3
3
  "description": "",
4
- "version": "0.6.33",
4
+ "version": "0.6.36",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "src",
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "unplugin": "^2.3.5",
28
- "wesl": "0.6.33"
28
+ "wesl": "0.6.36"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@nuxt/kit": "^3.17.6",