Closed lgarron closed 8 months ago
@FiloSottile: Apologies for the omnibus PR. I've tried to keep with the existing project conventions where possible, but if you're interested in a subset of changes I'd be happy to break it apart.
I've tested that the resulting build works in node
, bun
, and browsers in a real-world project I'm working on.
Hm, I'm sorry, there seems to be an issue with this that only happens in CI but which I can't reproduce locally:
RUN v0.34.1 /home/runner/work/age.ts/age.ts ✓ tests/index.test.ts ([10](https://github.com/lgarron/age.ts/actions/runs/6741408249/job/18325959492#step:7:11) tests) 59ms ✓ tests/testkit.test.ts (109 tests) [11](https://github.com/lgarron/age.ts/actions/runs/6741408249/job/18325959492#step:7:12)7ms ✓ tests/property.test.ts (4 tests) 262ms ❯ tests/format.test.ts (6 tests | 4 failed) 30ms ❯ tests/format.test.ts > parseHeader > should parse a well formatted header → Cannot read properties of undefined (reading '_malloc') ❯ tests/format.test.ts > parseHeader > should reencode to the original header → Cannot read properties of undefined (reading '_malloc') ❯ tests/format.test.ts > decodeBase64 > should parse a valid base64 string → Cannot read properties of undefined (reading '_malloc') ❯ tests/format.test.ts > decodeBase64 > should parse a valid base64 string with spare bits → Cannot read properties of undefined (reading '_malloc') ✓ tests/hkdf.test.ts (3 tests) 23ms ⎯⎯⎯⎯⎯⎯⎯ Failed Tests 4 ⎯⎯⎯⎯⎯⎯⎯ FAIL tests/format.test.ts > parseHeader > should parse a well formatted header TypeError: Cannot read properties of undefined (reading '_malloc') ❯ v node_modules/libsodium-wrappers-sumo/dist/modules-sumo/libsodium-wrappers.js:1:17642 ❯ new u node_modules/libsodium-wrappers-sumo/dist/modules-sumo/libsodium-wrappers.js:1:17556 ❯ Object.e.from_base64 node_modules/libsodium-wrappers-sumo/dist/modules-sumo/libsodium-wrappers.js:1:80870 ❯ decodeBase64 lib/format.ts:3:51 1| import { sodium } from "./sodium.js"; 2| 3| export const decodeBase64 = (s: string) => sodium.from_base64(s, sodiu… | ^ 4| export const encodeBase64 = (s: Uint8Array) => sodium.to_base64(s, sod… 5| ❯ parseNextStanza lib/format.ts:78:22 ❯ Module.parseHeader lib/format.ts:116:21 ❯ tests/format.test.ts:14:19 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/4]⎯ FAIL tests/format.test.ts > parseHeader > should reencode to the original header Test Files 1 failed | 4 passed (5) TypeError: Cannot read properties of undefined (reading '_malloc') Tests 4 failed | [12](https://github.com/lgarron/age.ts/actions/runs/6741408249/job/18325959492#step:7:13)8 passed (132) ❯ v node_modules/libsodium-wrappers-sumo/dist/modules-sumo/libsodium-wrappers.js:1:17642 Start at 04:52:56 ❯ new u node_modules/libsodium-wrappers-sumo/dist/modules-sumo/libsodium-wrappers.js:1:17556 Duration 1.15s (transform 163ms, setup 0ms, collect 1.02s, tests 491ms, environment 1ms, prepare 605ms) ❯ Object.e.from_base64 node_modules/libsodium-wrappers-sumo/dist/modules-sumo/libsodium-wrappers.js:1:80870 ❯ decodeBase64 lib/format.ts:3:51 1| import { sodium } from "./sodium.js"; 2| 3| export const decodeBase64 = (s: string) => sodium.from_base64(s, sodiu… | ^ 4| export const encodeBase64 = (s: Uint8Array) => sodium.to_base64(s, sod… 5| ❯ parseNextStanza lib/format.ts:78:22 ❯ Module.parseHeader lib/format.ts:116:21 ❯ tests/format.test.ts:22:19 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/4]⎯ FAIL tests/format.test.ts > decodeBase64 > should parse a valid base64 string TypeError: Cannot read properties of undefined (reading '_malloc') ❯ v node_modules/libsodium-wrappers-sumo/dist/modules-sumo/libsodium-wrappers.js:1:17642 ❯ new u node_modules/libsodium-wrappers-sumo/dist/modules-sumo/libsodium-wrappers.js:1:17556 ❯ Object.e.from_base64 node_modules/libsodium-wrappers-sumo/dist/modules-sumo/libsodium-wrappers.js:1:80870 ❯ Module.decodeBase64 lib/format.ts:3:51 1| import { sodium } from "./sodium.js"; 2| 3| export const decodeBase64 = (s: string) => sodium.from_base64(s, sodiu… | ^ 4| export const encodeBase64 = (s: Uint8Array) => sodium.to_base64(s, sod… 5| ❯ tests/format.test.ts:31:26 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/4]⎯ FAIL tests/format.test.ts > decodeBase64 > should parse a valid base64 string with spare bits TypeError: Cannot read properties of undefined (reading '_malloc') ❯ v node_modules/libsodium-wrappers-sumo/dist/modules-sumo/libsodium-wrappers.js:1:[17](https://github.com/lgarron/age.ts/actions/runs/6741408249/job/18325959492#step:7:18)642 ❯ new u node_modules/libsodium-wrappers-sumo/dist/modules-sumo/libsodium-wrappers.js:1:17556 ❯ Object.e.from_base64 node_modules/libsodium-wrappers-sumo/dist/modules-sumo/libsodium-wrappers.js:1:80870 ❯ Module.decodeBase64 lib/format.ts:3:51 1| import { sodium } from "./sodium.js"; 2| 3| export const decodeBase64 = (s: string) => sodium.from_base64(s, sodiu… | ^ 4| export const encodeBase64 = (s: Uint8Array) => sodium.to_base64(s, sod… 5| ❯ tests/format.test.ts:34:26 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/4]⎯ Error: Process completed with exit code 1.
I don't yet know if that's due to code changes in this PR, or just from trying to run libsodium-wrappers-sumo
in the GitHub Actions runners.
Thank you! I had a few of these changes staged but got stuck on trying to write a test for esbuild compatibility. It looks like partially due to libsodium choices the esbuild bundle runs in the browser but not in node, so to test it I'll have to run puppeteer or something like that.
Got it!
The tests needed the same initialization conventions as well: https://github.com/lgarron/age.ts/commit/efadd20d4b8b895f56994a337655903123ed02fc
(But I still really wish top-level await were ready for use in libraries, that would make this all much simpler.)
That said, running in Puppeteer would probably still be smart.
Closing in favor of #14. Thanks again!
sodium
object in a single place and use the object across the project. This simplifies the import semantics and enables compatibility withnode
andbun
: https://github.com/FiloSottile/age.ts/issues/9tests/readme-examples
and test them in CI usingbun
.npm run clean
tsconfig.json
to avoid warnings:"module": "nodenext"
to avoid: "Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.ts" (from TypeScript)."include"
to the"lib"
folder so that the top-level await lines intests/readme-examples
don't show errors.