wesl-tooling 0.6.17 → 0.6.18
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/package.json +2 -2
- package/src/LoadProject.ts +71 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wesl-tooling",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.18",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"src"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dependent_package": "x"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"wesl": "^0.7.
|
|
23
|
+
"wesl": "^0.7.5"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
26
|
"test": "cross-env FORCE_COLOR=1 vitest",
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
+
import { sanitizePackageName, type WeslBundle } from "wesl";
|
|
4
|
+
import { loadModules } from "./LoadModules.ts";
|
|
5
|
+
import { findWeslToml } from "./LoadWeslToml.ts";
|
|
6
|
+
import { dependencyBundles } from "./ParseDependencies.ts";
|
|
7
|
+
import { resolveProjectDir } from "./ResolveProjectDir.ts";
|
|
8
|
+
import { readPackageJson } from "./Version.ts";
|
|
9
|
+
|
|
10
|
+
export interface ProjectInfo {
|
|
11
|
+
weslSrc: Record<string, string>;
|
|
12
|
+
rootModuleName: string;
|
|
13
|
+
packageName: string;
|
|
14
|
+
libs: WeslBundle[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface LoadProjectOptions {
|
|
18
|
+
/** Libraries provided at runtime, don't resolve from npm (e.g., ["test"]) */
|
|
19
|
+
virtualLibs?: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Load everything needed to link a shader file.
|
|
24
|
+
*
|
|
25
|
+
* Discovers the project root, loads wesl.toml config, reads all shader modules,
|
|
26
|
+
* and resolves external library dependencies from npm.
|
|
27
|
+
*
|
|
28
|
+
* @returns ProjectInfo with sources, libs, and module paths, or null if not in a project.
|
|
29
|
+
*/
|
|
30
|
+
export async function loadProject(
|
|
31
|
+
filePath: string,
|
|
32
|
+
opts: LoadProjectOptions = {},
|
|
33
|
+
): Promise<ProjectInfo | null> {
|
|
34
|
+
const { virtualLibs = [] } = opts;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
const projectDir = fileURLToPath(await resolveProjectDir(filePath));
|
|
38
|
+
const tomlInfo = await findWeslToml(projectDir);
|
|
39
|
+
const packageName = await getPackageName(projectDir);
|
|
40
|
+
const weslSrc = await loadModules(projectDir);
|
|
41
|
+
const rawLibs = await dependencyBundles(
|
|
42
|
+
weslSrc,
|
|
43
|
+
projectDir,
|
|
44
|
+
packageName,
|
|
45
|
+
false,
|
|
46
|
+
virtualLibs,
|
|
47
|
+
);
|
|
48
|
+
const libs = rawLibs.filter(Boolean);
|
|
49
|
+
|
|
50
|
+
const shaderRootAbs = path.resolve(projectDir, tomlInfo.resolvedRoot);
|
|
51
|
+
// path.relative returns backslashes on Windows, normalize to forward slashes
|
|
52
|
+
const rootModuleName = path
|
|
53
|
+
.relative(shaderRootAbs, filePath)
|
|
54
|
+
.replace(/\\/g, "/");
|
|
55
|
+
|
|
56
|
+
return { weslSrc, rootModuleName, packageName, libs };
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Read package name from package.json, sanitized for WESL identifiers. */
|
|
63
|
+
export async function getPackageName(projectDir: string): Promise<string> {
|
|
64
|
+
try {
|
|
65
|
+
const projectUrl = pathToFileURL(projectDir).href;
|
|
66
|
+
const pkg = await readPackageJson(projectUrl);
|
|
67
|
+
return sanitizePackageName(pkg.name as string);
|
|
68
|
+
} catch {
|
|
69
|
+
return path.basename(projectDir);
|
|
70
|
+
}
|
|
71
|
+
}
|