Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle uBO aliases #1

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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: 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 || [])},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is more readable when aliases are next to the name

${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
Loading