Skip to content

Commit d7bbdc2

Browse files
authored
Handle uBO aliases (#1)
2 parents 0cb4770 + 29c825e commit d7bbdc2

File tree

5 files changed

+231
-190
lines changed

5 files changed

+231
-190
lines changed

.github/workflows/tests.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: jdx/mise-action@v2
15+
- name: Build
16+
run: npm run build
17+
- name: Test
18+
run: npm run test

build.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ ${scriptlets
6161
6262
return `
6363
scriptlets['${scriptlet.name}'] = {
64+
aliases: ${JSON.stringify(scriptlet.aliases || [])},
65+
${scriptlet.world ? `world: '${scriptlet.world}',` : '' }
66+
requiresTrust: ${scriptlet.requiresTrust || false},
6467
func: function (...args) {
6568
const scriptletGlobals = {};
6669
${deps.map((dep) => dep.toString()).join('\n')}
6770
${scriptlet.fn.toString()};
6871
${scriptlet.fn.name}(...args);
6972
},
70-
aliases: ${JSON.stringify(scriptlet.aliases || [])},
71-
${scriptlet.world ? `world: '${scriptlet.world}',` : '' }
72-
requiresTrust: ${scriptlet.requiresTrust || false},
7373
};
7474
`;
7575
})

index.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
import scriptlets from './ubo.js';
1+
import SCRIPTLETS from './ubo.js';
2+
3+
const scriptlets = {};
4+
5+
for (const [name, scriptlet] of Object.entries(SCRIPTLETS)) {
6+
scriptlets[name] = scriptlet;
7+
for (const alias of scriptlet.aliases) {
8+
scriptlets[alias] = scriptlet;
9+
}
10+
}
11+
212
export default scriptlets;

test.js

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import test from "node:test";
1+
import { test, suite } from "node:test";
22
import assert from "node:assert";
33
import scriptlets from "./index.js";
44

@@ -9,7 +9,20 @@ test("default export is an object", () => {
99
test("each scriptlet has basic properties", () => {
1010
for (const [name, scriptlet] of Object.entries(scriptlets)) {
1111
assert(name.length > 0, `${name} - name is too short`);
12-
assert(scriptlet.func instanceof Function, `${name} - func is not have a Function`);
13-
assert(scriptlet.aliases instanceof Array, `${name} - aliases is not an Array`);
12+
assert(
13+
scriptlet.func instanceof Function,
14+
`${name} - func is not have a Function`
15+
);
16+
assert(
17+
scriptlet.aliases instanceof Array,
18+
`${name} - aliases is not an Array`
19+
);
1420
}
1521
});
22+
23+
suite("uBO", () => {
24+
test("handles aliases", () => {
25+
assert(scriptlets["set-constant.js"]);
26+
assert.strictEqual(scriptlets["set-constant.js"], scriptlets["set.js"]);
27+
});
28+
});

0 commit comments

Comments
 (0)