wesl-packager 0.6.6 → 0.6.9
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/README.md +3 -9
- package/bin/wesl-packager +13 -30
- package/package.json +4 -8
package/README.md
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# WESL-Packager
|
|
2
2
|
|
|
3
3
|
A command tool to bundle WGSL/WESL files into an npm package.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Create a bundled package in the `dist` directory
|
|
8
|
-
from sources in the `src/shaders` directory.
|
|
9
|
-
|
|
10
|
-
```sh
|
|
11
|
-
npx wesl-packager --rootDir src/shaders --outDir dist
|
|
12
|
-
```
|
|
5
|
+
See [Publishing Packages](https://wesl-lang.dev/docs/Publishing-Packages#wesl-packager-options)
|
|
6
|
+
for documentation on how to use `wesl-packager`.
|
|
13
7
|
|
|
14
8
|
### Development
|
|
15
9
|
|
package/bin/wesl-packager
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { exit } from "node:process";
|
|
3
3
|
import { hideBin } from "yargs/helpers";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { loadModules, parseDependencies, versionFromPackageJson, zip } from "wesl-tooling";
|
|
4
6
|
import yargs from "yargs";
|
|
5
7
|
import fs, { mkdir } from "node:fs/promises";
|
|
6
|
-
import path from "node:path";
|
|
7
8
|
import { Biome, Distribution } from "@biomejs/js-api";
|
|
8
|
-
import { glob } from "glob";
|
|
9
9
|
import { noSuffix } from "wesl";
|
|
10
|
-
import { parseDependencies } from "wesl-tooling";
|
|
11
10
|
|
|
12
11
|
//#region \0raw:/Users/lee/wesl-js/tools/packages/wesl/src/WeslBundle.ts
|
|
13
12
|
var WeslBundle_default = "export interface WeslBundle {\n /** name of the package, e.g. random_wgsl */\n name: string;\n\n /** wesl edition of the code e.g. unstable_2025_1 */\n edition: string;\n\n /** map of wesl/wgsl modules:\n * keys are file paths, relative to package root (e.g. \"./lib.wgsl\")\n * values are wgsl/wesl code strings\n */\n modules: Record<string, string>;\n\n /** packages referenced by this package */\n dependencies?: WeslBundle[];\n}\n";
|
|
@@ -17,12 +16,8 @@ var WeslBundle_default = "export interface WeslBundle {\n /** name of the packa
|
|
|
17
16
|
const biome = await setupBiome();
|
|
18
17
|
/** write weslBundle .js and .d.ts files for this shader */
|
|
19
18
|
async function packageWgsl(args) {
|
|
20
|
-
const { projectDir, outDir, multiBundle } = args;
|
|
21
|
-
const modules = await loadModules(
|
|
22
|
-
if (Object.entries(modules).length === 0) {
|
|
23
|
-
console.error("no WGSL/WESL files found in", args.src);
|
|
24
|
-
throw new Error("no WGSL/WESL files found");
|
|
25
|
-
}
|
|
19
|
+
const { projectDir, outDir, multiBundle, baseDir, src } = args;
|
|
20
|
+
const modules = await loadModules(projectDir, baseDir, src);
|
|
26
21
|
const pkgJsonPath = path.join(projectDir, "package.json");
|
|
27
22
|
const { name } = await loadPackageFields(pkgJsonPath);
|
|
28
23
|
const edition = "unstable_2025_1";
|
|
@@ -120,19 +115,6 @@ function bundleToJsString(bundle, dependencies) {
|
|
|
120
115
|
return result;
|
|
121
116
|
} else return jsonString;
|
|
122
117
|
}
|
|
123
|
-
/** load the wesl/wgsl shader sources */
|
|
124
|
-
async function loadModules(args) {
|
|
125
|
-
const { rootDir } = args;
|
|
126
|
-
const shaderFiles = await glob(`${args.src}`, { ignore: "node_modules/**" });
|
|
127
|
-
const promisedSrcs = shaderFiles.map((f) => fs.readFile(f, { encoding: "utf8" }));
|
|
128
|
-
const src = await Promise.all(promisedSrcs);
|
|
129
|
-
const relativePaths = shaderFiles.map((p) => path.relative(rootDir, p));
|
|
130
|
-
const moduleEntries = zip(relativePaths, src);
|
|
131
|
-
return Object.fromEntries(moduleEntries);
|
|
132
|
-
}
|
|
133
|
-
function zip(as, bs) {
|
|
134
|
-
return as.map((a, i) => [a, bs[i]]);
|
|
135
|
-
}
|
|
136
118
|
/** parse and extract fields from package.json that we care about
|
|
137
119
|
* (the name of the package) */
|
|
138
120
|
async function loadPackageFields(pkgJsonPath) {
|
|
@@ -163,15 +145,22 @@ async function packagerCli(rawArgs$1) {
|
|
|
163
145
|
await packageWgsl(cliArgs);
|
|
164
146
|
}
|
|
165
147
|
async function parseArgs(args) {
|
|
166
|
-
const
|
|
148
|
+
const projectDir = path.join(import.meta.url, "..");
|
|
149
|
+
const appVersion = await versionFromPackageJson(projectDir);
|
|
167
150
|
return yargs(args).command("$0", "create an npm package from WGSL/WESL files").version(appVersion).option("src", {
|
|
168
151
|
type: "string",
|
|
169
152
|
default: "./shaders/*.w[eg]sl",
|
|
170
153
|
describe: "WGSL/WESL files to bundle in the package (glob syntax)"
|
|
171
154
|
}).option("rootDir", {
|
|
155
|
+
deprecated: true,
|
|
156
|
+
type: "string",
|
|
157
|
+
default: "./shaders",
|
|
158
|
+
describe: "use --baseDir instead"
|
|
159
|
+
}).option("baseDir", {
|
|
160
|
+
deprecated: true,
|
|
172
161
|
type: "string",
|
|
173
162
|
default: "./shaders",
|
|
174
|
-
describe: "
|
|
163
|
+
describe: "root directory for shaders"
|
|
175
164
|
}).option("projectDir", {
|
|
176
165
|
type: "string",
|
|
177
166
|
default: ".",
|
|
@@ -194,12 +183,6 @@ async function parseArgs(args) {
|
|
|
194
183
|
describe: "where to put bundled output files (relative to projectDir)"
|
|
195
184
|
}).help().parse();
|
|
196
185
|
}
|
|
197
|
-
async function versionFromPackageJson() {
|
|
198
|
-
const pkgJsonPath = new URL("../package.json", import.meta.url);
|
|
199
|
-
const pkgModule = await import(pkgJsonPath.href, { with: { type: "json" } });
|
|
200
|
-
const version = pkgModule.default.version;
|
|
201
|
-
return version;
|
|
202
|
-
}
|
|
203
186
|
|
|
204
187
|
//#endregion
|
|
205
188
|
//#region src/main.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wesl-packager",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"bin"
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"glob": "^11.0.2",
|
|
13
13
|
"import-meta-resolve": "^4.1.0",
|
|
14
14
|
"yargs": "^17.7.2",
|
|
15
|
-
"wesl": "0.6.
|
|
16
|
-
"wesl-tooling": "0.6.
|
|
15
|
+
"wesl": "0.6.9",
|
|
16
|
+
"wesl-tooling": "0.6.9"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/diff": "^8.0.0",
|
|
@@ -26,13 +26,9 @@
|
|
|
26
26
|
"tsdown": "^0.11.12"
|
|
27
27
|
},
|
|
28
28
|
"scripts": {
|
|
29
|
-
"echo": "echo",
|
|
30
29
|
"build": "tsdown",
|
|
31
30
|
"build:watch": "tsdown --watch",
|
|
32
|
-
"
|
|
33
|
-
"lint": "eslint src",
|
|
34
|
-
"organize": "organize-imports-cli tsconfig.json",
|
|
35
|
-
"typecheck": "tsc",
|
|
31
|
+
"typecheck": "tsgo",
|
|
36
32
|
"test": "FORCE_COLOR=1 vitest",
|
|
37
33
|
"test:once": "vitest run"
|
|
38
34
|
}
|