wesl-plugin 0.6.0-pre5 → 0.6.0-pre7

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.
@@ -2,19 +2,21 @@ import { WeslJsPlugin, ParsedRegistry } from 'wesl';
2
2
 
3
3
  /** loaded (or synthesized) info from .toml */
4
4
  interface WeslToml {
5
- /** glob search strings to find .wesl/.wgsl files. Relative to the toml directory! */
5
+ /** glob search strings to find .wesl/.wgsl files. Relative to the toml directory. */
6
6
  weslFiles: string[];
7
- /** base directory for wesl files. Relative to the toml directory! */
7
+ /** base directory for wesl files. Relative to the toml directory. */
8
8
  weslRoot: string;
9
+ /** names of directly referenced wesl shader packages (e.g. npm package names) */
10
+ dependencies?: string[];
9
11
  }
10
12
  interface WeslTomlInfo {
11
13
  /** The path to the toml file, relative to the cwd */
12
14
  tomlFile: string;
13
- /** The path to the directory that contains the toml. Relative to the cwd. Paths inside the toml are relative to this. */
15
+ /** The path to the directory that contains the toml.
16
+ * Relative to the cwd. Paths inside the toml are relative to this. */
14
17
  tomlDir: string;
15
- /**
16
- * The wesl root, relative to the cwd. This lets us correctly do `path.resolve(resolvedWeslRoot, someShaderFile)`
17
- */
18
+ /** The wesl root, relative to the cwd.
19
+ * This lets us correctly do `path.resolve(resolvedWeslRoot, someShaderFile)` */
18
20
  resolvedWeslRoot: string;
19
21
  /** The underlying toml file */
20
22
  toml: WeslToml;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  weslPlugin
3
- } from "./chunk-WRYP67OK.js";
3
+ } from "./chunk-ZDLLLCLM.js";
4
4
 
5
5
  // src/plugins/vite.ts
6
6
  import { createVitePlugin } from "unplugin";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  weslPlugin
3
- } from "./chunk-WRYP67OK.js";
3
+ } from "./chunk-ZDLLLCLM.js";
4
4
 
5
5
  // src/plugins/webpack.ts
6
6
  import { createWebpackPlugin } from "unplugin";
@@ -6700,7 +6700,6 @@ async function getRegistry(context, unpluginCtx) {
6700
6700
  const fullPaths = Object.keys(loaded).map(
6701
6701
  (p) => path2.resolve(resolvedWeslRoot, p)
6702
6702
  );
6703
- fullPaths.forEach((f) => unpluginCtx.addWatchFile(f));
6704
6703
  if (context.meta.watchMode) {
6705
6704
  fullPaths.forEach((f) => {
6706
6705
  chokidar.watch(f).on("change", () => {
@@ -6730,6 +6729,7 @@ async function loadWesl(context, unpluginCtx) {
6730
6729
  (g) => glob(g, { cwd: tomlDir, absolute: true })
6731
6730
  );
6732
6731
  const files = (await Promise.all(futureFiles)).flat();
6732
+ files.forEach((f) => unpluginCtx.addWatchFile(f));
6733
6733
  return await loadFiles(files, resolvedWeslRoot);
6734
6734
  }
6735
6735
  async function loadFiles(files, weslRoot) {
@@ -1,5 +1,5 @@
1
- import { P as PluginExtension } from './PluginExtension-BPBKs2pN.js';
2
- export { E as ExtensionEmitFn, a as PluginExtensionApi } from './PluginExtension-BPBKs2pN.js';
1
+ import { P as PluginExtension } from './PluginExtension-egUuLQCG.js';
2
+ export { E as ExtensionEmitFn, a as PluginExtensionApi } from './PluginExtension-egUuLQCG.js';
3
3
  import 'wesl';
4
4
 
5
5
  declare const linkBuildPlugin: PluginExtension;
@@ -2,40 +2,40 @@ import "./chunk-JSBRDJBE.js";
2
2
 
3
3
  // src/LinkExtension.ts
4
4
  import path from "node:path";
5
- import { noSuffix, packageReferences } from "wesl";
5
+ import { noSuffix } from "wesl";
6
6
  var linkBuildPlugin = {
7
7
  extensionName: "link",
8
8
  emitFn: emitLinkJs
9
9
  };
10
10
  async function emitLinkJs(baseId, api) {
11
- const { resolvedWeslRoot } = await api.weslToml();
11
+ const { resolvedWeslRoot, toml } = await api.weslToml();
12
+ const { dependencies = [] } = toml;
12
13
  const debugWeslRoot = resolvedWeslRoot.replaceAll(path.sep, "/");
13
14
  const weslSrc = await api.weslSrc();
14
15
  const rootModule = await api.weslMain(baseId);
15
16
  const rootModuleName = noSuffix(rootModule);
16
17
  const rootName = path.basename(rootModuleName);
17
- const packages = scanForPackages(weslSrc);
18
- const bundleImports = packages.map((p) => `import ${p} from "${p}";`).join("\n");
18
+ const bundleImports = dependencies.map((p) => `import ${p} from "${p}";`).join("\n");
19
19
  const paramsName = `link${rootName}Config`;
20
- const linkSettings = JSON.stringify(
21
- {
22
- rootModuleName,
23
- weslSrc,
24
- debugWeslRoot,
25
- dependencies: packages
26
- },
27
- null,
28
- 2
29
- );
20
+ const linkParams = {
21
+ rootModuleName,
22
+ weslSrc,
23
+ debugWeslRoot
24
+ };
25
+ const libsStr = `libs: [${dependencies.join(", ")}]`;
26
+ const linkParamsStr = `{
27
+ ${serializeFields(linkParams)},
28
+ ${libsStr},
29
+ }`;
30
30
  const src = `
31
31
  ${bundleImports}
32
- export const ${paramsName} = ${linkSettings};
32
+ export const ${paramsName} = ${linkParamsStr};
33
33
  export default ${paramsName};
34
34
  `;
35
35
  return src;
36
36
  }
37
- function scanForPackages(weslSrc) {
38
- return Object.values(weslSrc).flatMap(packageReferences);
37
+ function serializeFields(record) {
38
+ return Object.entries(record).map(([k, v]) => ` ${k}: ${JSON.stringify(v, null, 2)}`).join(",\n");
39
39
  }
40
40
  export {
41
41
  linkBuildPlugin
@@ -1,5 +1,5 @@
1
- import { W as WeslPluginOptions } from '../weslPluginOptions-BBX99ilB.js';
2
- import '../PluginExtension-BPBKs2pN.js';
1
+ import { W as WeslPluginOptions } from '../weslPluginOptions-Om3wryHY.js';
2
+ import '../PluginExtension-egUuLQCG.js';
3
3
  import 'wesl';
4
4
 
5
5
  declare const _default: (options: WeslPluginOptions) => any;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  weslPlugin_default
3
- } from "../chunk-WRYP67OK.js";
3
+ } from "../chunk-ZDLLLCLM.js";
4
4
  import "../chunk-JSBRDJBE.js";
5
5
 
6
6
  // src/plugins/astro.ts
@@ -1,6 +1,6 @@
1
1
  import * as esbuild from 'esbuild';
2
- import { W as WeslPluginOptions } from '../weslPluginOptions-BBX99ilB.js';
3
- import '../PluginExtension-BPBKs2pN.js';
2
+ import { W as WeslPluginOptions } from '../weslPluginOptions-Om3wryHY.js';
3
+ import '../PluginExtension-egUuLQCG.js';
4
4
  import 'wesl';
5
5
 
6
6
  declare const _default: (options?: WeslPluginOptions | undefined) => esbuild.Plugin;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  weslPlugin
3
- } from "../chunk-WRYP67OK.js";
3
+ } from "../chunk-ZDLLLCLM.js";
4
4
  import "../chunk-JSBRDJBE.js";
5
5
 
6
6
  // src/plugins/esbuild.ts
@@ -1,6 +1,6 @@
1
1
  import * as _farmfe_core from '@farmfe/core';
2
- import { W as WeslPluginOptions } from '../weslPluginOptions-BBX99ilB.js';
3
- import '../PluginExtension-BPBKs2pN.js';
2
+ import { W as WeslPluginOptions } from '../weslPluginOptions-Om3wryHY.js';
3
+ import '../PluginExtension-egUuLQCG.js';
4
4
  import 'wesl';
5
5
 
6
6
  declare const _default: (options?: WeslPluginOptions | undefined) => _farmfe_core.JsPlugin;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  weslPlugin
3
- } from "../chunk-WRYP67OK.js";
3
+ } from "../chunk-ZDLLLCLM.js";
4
4
  import "../chunk-JSBRDJBE.js";
5
5
 
6
6
  // src/plugins/farm.ts
@@ -1,6 +1,6 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { W as WeslPluginOptions } from '../weslPluginOptions-BBX99ilB.js';
3
- import '../PluginExtension-BPBKs2pN.js';
2
+ import { W as WeslPluginOptions } from '../weslPluginOptions-Om3wryHY.js';
3
+ import '../PluginExtension-egUuLQCG.js';
4
4
  import 'wesl';
5
5
 
6
6
  interface ModuleOptions extends WeslPluginOptions {
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  webpack_default
3
- } from "../chunk-USWZ2CIV.js";
3
+ } from "../chunk-NFFZEA4R.js";
4
4
  import {
5
5
  vite_default
6
- } from "../chunk-ZJBZ62NB.js";
7
- import "../chunk-WRYP67OK.js";
6
+ } from "../chunk-MAE4GAHG.js";
7
+ import "../chunk-ZDLLLCLM.js";
8
8
  import "../chunk-JSBRDJBE.js";
9
9
 
10
10
  // src/plugins/nuxt.ts
@@ -1,6 +1,6 @@
1
1
  import * as rollup from 'rollup';
2
- import { W as WeslPluginOptions } from '../weslPluginOptions-BBX99ilB.js';
3
- import '../PluginExtension-BPBKs2pN.js';
2
+ import { W as WeslPluginOptions } from '../weslPluginOptions-Om3wryHY.js';
3
+ import '../PluginExtension-egUuLQCG.js';
4
4
  import 'wesl';
5
5
 
6
6
  declare const _default: (options?: WeslPluginOptions | undefined) => rollup.Plugin<any> | rollup.Plugin<any>[];
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  weslPlugin
3
- } from "../chunk-WRYP67OK.js";
3
+ } from "../chunk-ZDLLLCLM.js";
4
4
  import "../chunk-JSBRDJBE.js";
5
5
 
6
6
  // src/plugins/rollup.ts
@@ -1,5 +1,5 @@
1
- import { W as WeslPluginOptions } from '../weslPluginOptions-BBX99ilB.js';
2
- import '../PluginExtension-BPBKs2pN.js';
1
+ import { W as WeslPluginOptions } from '../weslPluginOptions-Om3wryHY.js';
2
+ import '../PluginExtension-egUuLQCG.js';
3
3
  import 'wesl';
4
4
 
5
5
  declare const _default: (options?: WeslPluginOptions | undefined) => RspackPluginInstance;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  weslPlugin
3
- } from "../chunk-WRYP67OK.js";
3
+ } from "../chunk-ZDLLLCLM.js";
4
4
  import "../chunk-JSBRDJBE.js";
5
5
 
6
6
  // src/plugins/rspack.ts
@@ -1,6 +1,6 @@
1
1
  import * as vite from 'vite';
2
- import { W as WeslPluginOptions } from '../weslPluginOptions-BBX99ilB.js';
3
- import '../PluginExtension-BPBKs2pN.js';
2
+ import { W as WeslPluginOptions } from '../weslPluginOptions-Om3wryHY.js';
3
+ import '../PluginExtension-egUuLQCG.js';
4
4
  import 'wesl';
5
5
 
6
6
  declare const _default: (options?: WeslPluginOptions | undefined) => vite.Plugin<any> | vite.Plugin<any>[];
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  vite_default
3
- } from "../chunk-ZJBZ62NB.js";
4
- import "../chunk-WRYP67OK.js";
3
+ } from "../chunk-MAE4GAHG.js";
4
+ import "../chunk-ZDLLLCLM.js";
5
5
  import "../chunk-JSBRDJBE.js";
6
6
  export {
7
7
  vite_default as default
@@ -1,6 +1,6 @@
1
1
  import * as webpack from 'webpack';
2
- import { W as WeslPluginOptions } from '../weslPluginOptions-BBX99ilB.js';
3
- import '../PluginExtension-BPBKs2pN.js';
2
+ import { W as WeslPluginOptions } from '../weslPluginOptions-Om3wryHY.js';
3
+ import '../PluginExtension-egUuLQCG.js';
4
4
  import 'wesl';
5
5
 
6
6
  declare const _default: (options?: WeslPluginOptions | undefined) => webpack.WebpackPluginInstance;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  webpack_default
3
- } from "../chunk-USWZ2CIV.js";
4
- import "../chunk-WRYP67OK.js";
3
+ } from "../chunk-NFFZEA4R.js";
4
+ import "../chunk-ZDLLLCLM.js";
5
5
  import "../chunk-JSBRDJBE.js";
6
6
  export {
7
7
  webpack_default as default
@@ -1,4 +1,4 @@
1
- import { P as PluginExtension } from './PluginExtension-BPBKs2pN.js';
1
+ import { P as PluginExtension } from './PluginExtension-egUuLQCG.js';
2
2
 
3
3
  interface WeslPluginOptions {
4
4
  weslToml?: string;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "wesl-plugin",
3
3
  "type": "module",
4
- "version": "0.6.0-pre5",
4
+ "version": "0.6.0-pre7",
5
5
  "dependencies": {
6
6
  "chokidar": "^4.0.3",
7
7
  "toml": "^3.0.0",
8
8
  "unplugin": "^2.1.2",
9
- "wesl": "0.6.0-pre5"
9
+ "wesl": "0.6.0-pre7"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@nuxt/kit": "^3.15.2",
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import { noSuffix, packageReferences } from "wesl";
2
+ import { LinkParams, noSuffix } from "wesl";
3
3
  import { PluginExtension, PluginExtensionApi } from "./PluginExtension.ts";
4
4
 
5
5
  export const linkBuildPlugin: PluginExtension = {
@@ -12,40 +12,43 @@ async function emitLinkJs(
12
12
  baseId: string,
13
13
  api: PluginExtensionApi,
14
14
  ): Promise<string> {
15
- const { resolvedWeslRoot } = await api.weslToml();
15
+ const { resolvedWeslRoot, toml } = await api.weslToml();
16
+ const { dependencies = [] } = toml;
16
17
  const debugWeslRoot = resolvedWeslRoot.replaceAll(path.sep, "/");
17
18
  const weslSrc = await api.weslSrc();
18
19
  const rootModule = await api.weslMain(baseId);
19
20
  const rootModuleName = noSuffix(rootModule);
20
21
  const rootName = path.basename(rootModuleName);
21
- const packages = scanForPackages(weslSrc);
22
22
 
23
- const bundleImports = packages
23
+ const bundleImports = dependencies
24
24
  .map(p => `import ${p} from "${p}";`)
25
25
  .join("\n");
26
26
 
27
27
  const paramsName = `link${rootName}Config`;
28
28
 
29
- const linkSettings = JSON.stringify(
30
- {
31
- rootModuleName,
32
- weslSrc,
33
- debugWeslRoot,
34
- dependencies: packages,
35
- },
36
- null,
37
- 2,
38
- );
29
+ const linkParams: LinkParams = {
30
+ rootModuleName,
31
+ weslSrc,
32
+ debugWeslRoot,
33
+ };
34
+
35
+ const libsStr = `libs: [${dependencies.join(", ")}]`;
36
+ const linkParamsStr = `{
37
+ ${serializeFields(linkParams)},
38
+ ${libsStr},
39
+ }`;
39
40
 
40
41
  const src = `
41
42
  ${bundleImports}
42
- export const ${paramsName} = ${linkSettings};
43
+ export const ${paramsName} = ${linkParamsStr};
43
44
  export default ${paramsName};
44
45
  `;
45
46
 
46
47
  return src;
47
48
  }
48
49
 
49
- function scanForPackages(weslSrc: Record<string, string>): string[] {
50
- return Object.values(weslSrc).flatMap(packageReferences);
50
+ function serializeFields(record: Record<string, any>) {
51
+ return Object.entries(record)
52
+ .map(([k, v]) => ` ${k}: ${JSON.stringify(v, null, 2)}`)
53
+ .join(",\n");
51
54
  }
@@ -1,7 +1,7 @@
1
1
  /** @hidden */
2
2
  declare module "*?link" {
3
- const linkConfig: LinkConfig;
4
- export default linkConfig;
3
+ const linkParams: LinkParams;
4
+ export default linkParams;
5
5
  }
6
6
 
7
7
  /** @hidden */ // TODO move to separate package
package/src/weslPlugin.ts CHANGED
@@ -24,22 +24,26 @@ import type { WeslPluginOptions } from "./weslPluginOptions.js";
24
24
 
25
25
  /** loaded (or synthesized) info from .toml */
26
26
  export interface WeslToml {
27
- /** glob search strings to find .wesl/.wgsl files. Relative to the toml directory! */
27
+ /** glob search strings to find .wesl/.wgsl files. Relative to the toml directory. */
28
28
  weslFiles: string[];
29
29
 
30
- /** base directory for wesl files. Relative to the toml directory! */
30
+ /** base directory for wesl files. Relative to the toml directory. */
31
31
  weslRoot: string;
32
+
33
+ /** names of directly referenced wesl shader packages (e.g. npm package names) */
34
+ dependencies?: string[];
32
35
  }
33
36
 
34
37
  export interface WeslTomlInfo {
35
38
  /** The path to the toml file, relative to the cwd */
36
39
  tomlFile: string;
37
- /** The path to the directory that contains the toml. Relative to the cwd. Paths inside the toml are relative to this. */
40
+
41
+ /** The path to the directory that contains the toml.
42
+ * Relative to the cwd. Paths inside the toml are relative to this. */
38
43
  tomlDir: string;
39
44
 
40
- /**
41
- * The wesl root, relative to the cwd. This lets us correctly do `path.resolve(resolvedWeslRoot, someShaderFile)`
42
- */
45
+ /** The wesl root, relative to the cwd.
46
+ * This lets us correctly do `path.resolve(resolvedWeslRoot, someShaderFile)` */
43
47
  resolvedWeslRoot: string;
44
48
 
45
49
  /** The underlying toml file */
@@ -242,9 +246,6 @@ async function getRegistry(
242
246
  path.resolve(resolvedWeslRoot, p),
243
247
  );
244
248
 
245
- // trigger rebuild on shader file change
246
- fullPaths.forEach(f => unpluginCtx.addWatchFile(f));
247
-
248
249
  // trigger clearing cache on shader file change
249
250
  if (context.meta.watchMode) {
250
251
  fullPaths.forEach(f => {
@@ -292,7 +293,10 @@ async function loadWesl(
292
293
  glob(g, { cwd: tomlDir, absolute: true }),
293
294
  );
294
295
  const files = (await Promise.all(futureFiles)).flat();
295
- // dlog({ files, weslRoot, tomlDir, globs });
296
+
297
+ // trigger rebuild on shader file change
298
+ files.forEach(f => unpluginCtx.addWatchFile(f));
299
+
296
300
  return await loadFiles(files, resolvedWeslRoot);
297
301
  }
298
302