wesl-plugin 0.6.65 → 0.6.67
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/{import-meta-resolve-CfcdqZRe.mjs → StaticExtension-BvgvwnkI.mjs} +72 -2
- package/dist/{WeslPlugin-CXZB9o3p.mjs → WeslPlugin-C1pAE34o.mjs} +12 -5
- package/dist/pluginIndex.mjs +1 -73
- package/dist/plugins/astro.mjs +2 -1
- package/dist/plugins/esbuild.d.mts +2 -2
- package/dist/plugins/esbuild.mjs +2 -1
- package/dist/plugins/farm.d.mts +1 -1
- package/dist/plugins/farm.mjs +2 -1
- package/dist/plugins/nuxt.mjs +2 -1
- package/dist/plugins/rollup.d.mts +1 -1
- package/dist/plugins/rollup.mjs +2 -1
- package/dist/plugins/rspack.d.mts +1 -1
- package/dist/plugins/rspack.mjs +2 -1
- package/dist/plugins/vite.d.mts +1 -1
- package/dist/plugins/vite.mjs +2 -1
- package/dist/plugins/webpack.d.mts +1 -1
- package/dist/plugins/webpack.mjs +2 -1
- package/package.json +2 -2
- package/src/WeslPlugin.ts +12 -5
|
@@ -1,12 +1,48 @@
|
|
|
1
1
|
import { builtinModules } from "node:module";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { link, noSuffix } from "wesl";
|
|
4
|
+
import url, { URL as URL$1, fileURLToPath, pathToFileURL } from "node:url";
|
|
4
5
|
import assert from "node:assert";
|
|
5
6
|
import fs, { realpathSync, statSync } from "node:fs";
|
|
6
7
|
import process from "node:process";
|
|
7
8
|
import v8 from "node:v8";
|
|
8
9
|
import { format, inspect } from "node:util";
|
|
9
10
|
|
|
11
|
+
//#region src/extensions/LinkExtension.ts
|
|
12
|
+
const linkBuildExtension = {
|
|
13
|
+
extensionName: "link",
|
|
14
|
+
emitFn: emitLinkJs
|
|
15
|
+
};
|
|
16
|
+
/** Emit a JavaScript LinkParams structure, ready for linking at runtime. */
|
|
17
|
+
async function emitLinkJs(baseId, api) {
|
|
18
|
+
const { resolvedRoot, tomlDir } = await api.weslToml();
|
|
19
|
+
const weslSrc = await api.weslSrc();
|
|
20
|
+
const rootModuleName = noSuffix(await api.weslMain(baseId));
|
|
21
|
+
const debugWeslRoot = path.relative(tomlDir, resolvedRoot).replaceAll(path.sep, "/");
|
|
22
|
+
const autoDeps = await api.weslDependencies();
|
|
23
|
+
const sanitizedDeps = autoDeps.map((dep) => dep.replaceAll("/", "_"));
|
|
24
|
+
const bundleImports = autoDeps.map((p, i) => `import ${sanitizedDeps[i]} from "${p}";`).join("\n");
|
|
25
|
+
const paramsName = `link${path.basename(rootModuleName).replace(/\W/g, "_")}Config`;
|
|
26
|
+
const linkParams = {
|
|
27
|
+
rootModuleName,
|
|
28
|
+
weslSrc,
|
|
29
|
+
debugWeslRoot
|
|
30
|
+
};
|
|
31
|
+
const libsStr = `libs: [${sanitizedDeps.join(", ")}]`;
|
|
32
|
+
return `
|
|
33
|
+
${bundleImports}
|
|
34
|
+
export const ${paramsName} = ${`{
|
|
35
|
+
${serializeFields(linkParams)},
|
|
36
|
+
${libsStr},
|
|
37
|
+
}`};
|
|
38
|
+
export default ${paramsName};
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
function serializeFields(record) {
|
|
42
|
+
return Object.entries(record).map(([k, v]) => ` ${k}: ${JSON.stringify(v, null, 2)}`).join(",\n");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
10
46
|
//#region ../../node_modules/.pnpm/import-meta-resolve@4.1.0/node_modules/import-meta-resolve/lib/errors.js
|
|
11
47
|
/**
|
|
12
48
|
* @typedef ErrnoExceptionFields
|
|
@@ -1264,4 +1300,38 @@ function resolve(specifier, parent) {
|
|
|
1264
1300
|
}
|
|
1265
1301
|
|
|
1266
1302
|
//#endregion
|
|
1267
|
-
|
|
1303
|
+
//#region src/extensions/StaticExtension.ts
|
|
1304
|
+
/**
|
|
1305
|
+
* a wesl-js ?static build extension that statically links from the root file
|
|
1306
|
+
* and emits a JavaScript file containing the linked wgsl string.
|
|
1307
|
+
*
|
|
1308
|
+
* use it like this:
|
|
1309
|
+
* import wgsl from "./shaders/app.wesl?static";
|
|
1310
|
+
*
|
|
1311
|
+
* or with conditions, like this:
|
|
1312
|
+
* import wgsl from "../shaders/foo/app.wesl MOBILE=true FUN SAFE=false ?static";
|
|
1313
|
+
*/
|
|
1314
|
+
const staticBuildExtension = {
|
|
1315
|
+
extensionName: "static",
|
|
1316
|
+
emitFn: emitStaticJs
|
|
1317
|
+
};
|
|
1318
|
+
/** Emit a JavaScript file containing the wgsl string */
|
|
1319
|
+
async function emitStaticJs(baseId, api, conditions) {
|
|
1320
|
+
const { resolvedRoot, tomlDir } = await api.weslToml();
|
|
1321
|
+
const parentModule = url.pathToFileURL(path.join(tomlDir, "wesl.toml")).toString();
|
|
1322
|
+
const futureLibs = (await api.weslDependencies()).map((d) => resolve(d, parentModule)).map((f) => import(f));
|
|
1323
|
+
const libs = (await Promise.all(futureLibs)).map((m) => m.default);
|
|
1324
|
+
return `
|
|
1325
|
+
export const wgsl = \`${(await link({
|
|
1326
|
+
weslSrc: await api.weslSrc(),
|
|
1327
|
+
rootModuleName: noSuffix(await api.weslMain(baseId)),
|
|
1328
|
+
debugWeslRoot: path.relative(tomlDir, resolvedRoot).replaceAll(path.sep, "/"),
|
|
1329
|
+
libs,
|
|
1330
|
+
conditions
|
|
1331
|
+
})).dest}\`;
|
|
1332
|
+
export default wgsl;
|
|
1333
|
+
`;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
//#endregion
|
|
1337
|
+
export { resolve as n, linkBuildExtension as r, staticBuildExtension as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as resolve, r as linkBuildExtension, t as staticBuildExtension } from "./StaticExtension-BvgvwnkI.mjs";
|
|
2
2
|
import path, { posix, win32 } from "node:path";
|
|
3
3
|
import { RecordResolver, WeslParseError, filterMap, findUnboundIdents, npmNameVariations } from "wesl";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -9921,18 +9921,25 @@ function toUnixPath(p) {
|
|
|
9921
9921
|
* 1. `import "./shaders/bar.wesl?reflect"` - produces a javascript file for binding struct reflection
|
|
9922
9922
|
* 2. `import "./shaders/bar.wesl?link"` - produces a javascript file for preconstructed link functions
|
|
9923
9923
|
*/
|
|
9924
|
+
const builtinExtensions = [staticBuildExtension, linkBuildExtension];
|
|
9924
9925
|
function weslPlugin(options, meta) {
|
|
9926
|
+
const o = options ?? {};
|
|
9927
|
+
const extensions = [...builtinExtensions, ...o.extensions ?? []];
|
|
9928
|
+
const opts = {
|
|
9929
|
+
...o,
|
|
9930
|
+
extensions
|
|
9931
|
+
};
|
|
9925
9932
|
const cache = {};
|
|
9926
9933
|
const context = {
|
|
9927
9934
|
cache,
|
|
9928
9935
|
meta,
|
|
9929
|
-
options
|
|
9936
|
+
options: opts
|
|
9930
9937
|
};
|
|
9931
|
-
const log =
|
|
9932
|
-
log("init", { extensions:
|
|
9938
|
+
const log = opts.debug ? debugLog : noopLog;
|
|
9939
|
+
log("init", { extensions: opts.extensions.map((e) => e.extensionName) });
|
|
9933
9940
|
return {
|
|
9934
9941
|
name: "wesl-plugin",
|
|
9935
|
-
resolveId: buildResolver(
|
|
9942
|
+
resolveId: buildResolver(opts, context, log),
|
|
9936
9943
|
load: buildLoader(context, log),
|
|
9937
9944
|
watchChange(id, _change) {
|
|
9938
9945
|
log("watchChange", { id });
|
package/dist/pluginIndex.mjs
CHANGED
|
@@ -1,75 +1,3 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { link, noSuffix } from "wesl";
|
|
4
|
-
import url from "node:url";
|
|
1
|
+
import { r as linkBuildExtension, t as staticBuildExtension } from "./StaticExtension-BvgvwnkI.mjs";
|
|
5
2
|
|
|
6
|
-
//#region src/extensions/LinkExtension.ts
|
|
7
|
-
const linkBuildExtension = {
|
|
8
|
-
extensionName: "link",
|
|
9
|
-
emitFn: emitLinkJs
|
|
10
|
-
};
|
|
11
|
-
/** Emit a JavaScript LinkParams structure, ready for linking at runtime. */
|
|
12
|
-
async function emitLinkJs(baseId, api) {
|
|
13
|
-
const { resolvedRoot, tomlDir } = await api.weslToml();
|
|
14
|
-
const weslSrc = await api.weslSrc();
|
|
15
|
-
const rootModuleName = noSuffix(await api.weslMain(baseId));
|
|
16
|
-
const debugWeslRoot = path.relative(tomlDir, resolvedRoot).replaceAll(path.sep, "/");
|
|
17
|
-
const autoDeps = await api.weslDependencies();
|
|
18
|
-
const sanitizedDeps = autoDeps.map((dep) => dep.replaceAll("/", "_"));
|
|
19
|
-
const bundleImports = autoDeps.map((p, i) => `import ${sanitizedDeps[i]} from "${p}";`).join("\n");
|
|
20
|
-
const paramsName = `link${path.basename(rootModuleName).replace(/\W/g, "_")}Config`;
|
|
21
|
-
const linkParams = {
|
|
22
|
-
rootModuleName,
|
|
23
|
-
weslSrc,
|
|
24
|
-
debugWeslRoot
|
|
25
|
-
};
|
|
26
|
-
const libsStr = `libs: [${sanitizedDeps.join(", ")}]`;
|
|
27
|
-
return `
|
|
28
|
-
${bundleImports}
|
|
29
|
-
export const ${paramsName} = ${`{
|
|
30
|
-
${serializeFields(linkParams)},
|
|
31
|
-
${libsStr},
|
|
32
|
-
}`};
|
|
33
|
-
export default ${paramsName};
|
|
34
|
-
`;
|
|
35
|
-
}
|
|
36
|
-
function serializeFields(record) {
|
|
37
|
-
return Object.entries(record).map(([k, v]) => ` ${k}: ${JSON.stringify(v, null, 2)}`).join(",\n");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/extensions/StaticExtension.ts
|
|
42
|
-
/**
|
|
43
|
-
* a wesl-js ?static build extension that statically links from the root file
|
|
44
|
-
* and emits a JavaScript file containing the linked wgsl string.
|
|
45
|
-
*
|
|
46
|
-
* use it like this:
|
|
47
|
-
* import wgsl from "./shaders/app.wesl?static";
|
|
48
|
-
*
|
|
49
|
-
* or with conditions, like this:
|
|
50
|
-
* import wgsl from "../shaders/foo/app.wesl MOBILE=true FUN SAFE=false ?static";
|
|
51
|
-
*/
|
|
52
|
-
const staticBuildExtension = {
|
|
53
|
-
extensionName: "static",
|
|
54
|
-
emitFn: emitStaticJs
|
|
55
|
-
};
|
|
56
|
-
/** Emit a JavaScript file containing the wgsl string */
|
|
57
|
-
async function emitStaticJs(baseId, api, conditions) {
|
|
58
|
-
const { resolvedRoot, tomlDir } = await api.weslToml();
|
|
59
|
-
const parentModule = url.pathToFileURL(path.join(tomlDir, "wesl.toml")).toString();
|
|
60
|
-
const futureLibs = (await api.weslDependencies()).map((d) => resolve(d, parentModule)).map((f) => import(f));
|
|
61
|
-
const libs = (await Promise.all(futureLibs)).map((m) => m.default);
|
|
62
|
-
return `
|
|
63
|
-
export const wgsl = \`${(await link({
|
|
64
|
-
weslSrc: await api.weslSrc(),
|
|
65
|
-
rootModuleName: noSuffix(await api.weslMain(baseId)),
|
|
66
|
-
debugWeslRoot: path.relative(tomlDir, resolvedRoot).replaceAll(path.sep, "/"),
|
|
67
|
-
libs,
|
|
68
|
-
conditions
|
|
69
|
-
})).dest}\`;
|
|
70
|
-
export default wgsl;
|
|
71
|
-
`;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
//#endregion
|
|
75
3
|
export { linkBuildExtension, staticBuildExtension };
|
package/dist/plugins/astro.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "../PluginExtension-N4JBtncl.mjs";
|
|
2
2
|
import { t as WeslPluginOptions } from "../WeslPluginOptions-DHLy1_Dm.mjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as esbuild0 from "esbuild";
|
|
4
4
|
|
|
5
5
|
//#region src/plugins/esbuild.d.ts
|
|
6
|
-
declare const _default: (options
|
|
6
|
+
declare const _default: (options?: WeslPluginOptions | undefined) => esbuild0.Plugin;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { _default as default };
|
package/dist/plugins/esbuild.mjs
CHANGED
package/dist/plugins/farm.d.mts
CHANGED
|
@@ -3,6 +3,6 @@ import { t as WeslPluginOptions } from "../WeslPluginOptions-DHLy1_Dm.mjs";
|
|
|
3
3
|
import * as _farmfe_core0 from "@farmfe/core";
|
|
4
4
|
|
|
5
5
|
//#region src/plugins/farm.d.ts
|
|
6
|
-
declare const _default: (options
|
|
6
|
+
declare const _default: (options?: WeslPluginOptions | undefined) => _farmfe_core0.JsPlugin;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { _default as default };
|
package/dist/plugins/farm.mjs
CHANGED
package/dist/plugins/nuxt.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import "../WeslPlugin-
|
|
1
|
+
import "../WeslPlugin-C1pAE34o.mjs";
|
|
2
|
+
import "../StaticExtension-BvgvwnkI.mjs";
|
|
2
3
|
import vite_default from "./vite.mjs";
|
|
3
4
|
import webpack_default from "./webpack.mjs";
|
|
4
5
|
import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
|
|
@@ -3,6 +3,6 @@ import { t as WeslPluginOptions } from "../WeslPluginOptions-DHLy1_Dm.mjs";
|
|
|
3
3
|
import * as rollup0 from "rollup";
|
|
4
4
|
|
|
5
5
|
//#region src/plugins/rollup.d.ts
|
|
6
|
-
declare const _default: (options
|
|
6
|
+
declare const _default: (options?: WeslPluginOptions | undefined) => rollup0.Plugin<any> | rollup0.Plugin<any>[];
|
|
7
7
|
//#endregion
|
|
8
8
|
export { _default as default };
|
package/dist/plugins/rollup.mjs
CHANGED
|
@@ -2,6 +2,6 @@ import "../PluginExtension-N4JBtncl.mjs";
|
|
|
2
2
|
import { t as WeslPluginOptions } from "../WeslPluginOptions-DHLy1_Dm.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/plugins/rspack.d.ts
|
|
5
|
-
declare const _default: (options
|
|
5
|
+
declare const _default: (options?: WeslPluginOptions | undefined) => RspackPluginInstance;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { _default as default };
|
package/dist/plugins/rspack.mjs
CHANGED
package/dist/plugins/vite.d.mts
CHANGED
|
@@ -3,6 +3,6 @@ import { t as WeslPluginOptions } from "../WeslPluginOptions-DHLy1_Dm.mjs";
|
|
|
3
3
|
import * as vite0 from "vite";
|
|
4
4
|
|
|
5
5
|
//#region src/plugins/vite.d.ts
|
|
6
|
-
declare const _default: (options
|
|
6
|
+
declare const _default: (options?: WeslPluginOptions | undefined) => vite0.Plugin<any> | vite0.Plugin<any>[];
|
|
7
7
|
//#endregion
|
|
8
8
|
export { _default as default };
|
package/dist/plugins/vite.mjs
CHANGED
|
@@ -3,6 +3,6 @@ import { t as WeslPluginOptions } from "../WeslPluginOptions-DHLy1_Dm.mjs";
|
|
|
3
3
|
import * as webpack0 from "webpack";
|
|
4
4
|
|
|
5
5
|
//#region src/plugins/webpack.d.ts
|
|
6
|
-
declare const _default: (options
|
|
6
|
+
declare const _default: (options?: WeslPluginOptions | undefined) => webpack0.WebpackPluginInstance;
|
|
7
7
|
//#endregion
|
|
8
8
|
export { _default as default };
|
package/dist/plugins/webpack.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wesl-plugin",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.67",
|
|
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.7.
|
|
28
|
+
"wesl": "0.7.19"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@nuxt/kit": "^3.17.6",
|
package/src/WeslPlugin.ts
CHANGED
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
} from "unplugin";
|
|
12
12
|
import type { Conditions, RecordResolver } from "wesl";
|
|
13
13
|
import type { WeslToml, WeslTomlInfo } from "wesl-tooling";
|
|
14
|
+
import { linkBuildExtension } from "./extensions/LinkExtension.ts";
|
|
15
|
+
import { staticBuildExtension } from "./extensions/StaticExtension.ts";
|
|
14
16
|
import { buildApi } from "./PluginApi.ts";
|
|
15
17
|
import type { PluginExtension } from "./PluginExtension.ts";
|
|
16
18
|
import type { WeslPluginOptions } from "./WeslPluginOptions.ts";
|
|
@@ -62,19 +64,24 @@ type DebugLog = (msg: string, data?: Record<string, unknown>) => void;
|
|
|
62
64
|
* 1. `import "./shaders/bar.wesl?reflect"` - produces a javascript file for binding struct reflection
|
|
63
65
|
* 2. `import "./shaders/bar.wesl?link"` - produces a javascript file for preconstructed link functions
|
|
64
66
|
*/
|
|
67
|
+
const builtinExtensions = [staticBuildExtension, linkBuildExtension];
|
|
68
|
+
|
|
65
69
|
export function weslPlugin(
|
|
66
|
-
options: WeslPluginOptions,
|
|
70
|
+
options: WeslPluginOptions | undefined,
|
|
67
71
|
meta: UnpluginContextMeta,
|
|
68
72
|
): UnpluginOptions {
|
|
73
|
+
const o = options ?? {};
|
|
74
|
+
const extensions = [...builtinExtensions, ...(o.extensions ?? [])];
|
|
75
|
+
const opts = { ...o, extensions };
|
|
69
76
|
const cache: PluginCache = {};
|
|
70
|
-
const context: PluginContext = { cache, meta, options };
|
|
71
|
-
const log =
|
|
77
|
+
const context: PluginContext = { cache, meta, options: opts };
|
|
78
|
+
const log = opts.debug ? debugLog : noopLog;
|
|
72
79
|
|
|
73
|
-
log("init", { extensions:
|
|
80
|
+
log("init", { extensions: opts.extensions.map(e => e.extensionName) });
|
|
74
81
|
|
|
75
82
|
return {
|
|
76
83
|
name: "wesl-plugin",
|
|
77
|
-
resolveId: buildResolver(
|
|
84
|
+
resolveId: buildResolver(opts, context, log),
|
|
78
85
|
load: buildLoader(context, log),
|
|
79
86
|
watchChange(id, _change) {
|
|
80
87
|
log("watchChange", { id });
|