Skip to content

Commit

Permalink
Handle uBO aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
chrmod committed Dec 10, 2024
1 parent 0cb4770 commit 4171bf6
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 190 deletions.
20 changes: 20 additions & 0 deletions .github/workflow/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Tests

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: jdx/mise-action@v2
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Test
run: npm run test
6 changes: 3 additions & 3 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ ${scriptlets
return `
scriptlets['${scriptlet.name}'] = {
aliases: ${JSON.stringify(scriptlet.aliases || [])},
${scriptlet.world ? `world: '${scriptlet.world}',` : '' }
requiresTrust: ${scriptlet.requiresTrust || false},
func: function (...args) {
const scriptletGlobals = {};
${deps.map((dep) => dep.toString()).join('\n')}
${scriptlet.fn.toString()};
${scriptlet.fn.name}(...args);
},
aliases: ${JSON.stringify(scriptlet.aliases || [])},
${scriptlet.world ? `world: '${scriptlet.world}',` : '' }
requiresTrust: ${scriptlet.requiresTrust || false},
};
`;
})
Expand Down
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
import scriptlets from './ubo.js';
import SCRIPTLETS from './ubo.js';

const scriptlets = {};

for (const [name, scriptlet] of Object.entries(SCRIPTLETS)) {
scriptlets[name] = scriptlet;
for (const alias of scriptlet.aliases) {
scriptlets[alias] = scriptlet;
}
}

export default scriptlets;
19 changes: 16 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import test from "node:test";
import { test, suite } from "node:test";
import assert from "node:assert";
import scriptlets from "./index.js";

Expand All @@ -9,7 +9,20 @@ test("default export is an object", () => {
test("each scriptlet has basic properties", () => {
for (const [name, scriptlet] of Object.entries(scriptlets)) {
assert(name.length > 0, `${name} - name is too short`);
assert(scriptlet.func instanceof Function, `${name} - func is not have a Function`);
assert(scriptlet.aliases instanceof Array, `${name} - aliases is not an Array`);
assert(
scriptlet.func instanceof Function,
`${name} - func is not have a Function`
);
assert(
scriptlet.aliases instanceof Array,
`${name} - aliases is not an Array`
);
}
});

suite("uBO", () => {
test("handles aliases", () => {
assert(scriptlets["set-constant.js"]);
assert.strictEqual(scriptlets["set-constant.js"], scriptlets["set.js"]);
});
});
Loading

0 comments on commit 4171bf6

Please sign in to comment.