Skip to content
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
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ jobs:
name: Test
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true

- uses: actions/setup-node@v4
with:
node-version: 22.14.0

- run: npm install
- run: npm test
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "uwasi",
"version": "1.4.0",
"description": "Micro modularized WASI runtime for JavaScript",
"main": "lib/cjs/index.js",
"module": "lib/esm/index.js",
"browser": {
"./lib/esm/platforms/crypto.js": "./lib/esm/platforms/crypto.browser.js"
"exports": {
".": {
"import": "./lib/esm/index.js",
"require": "./lib/cjs/index.js"
}
},
"scripts": {
"build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
Expand Down
3 changes: 1 addition & 2 deletions src/features/random.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { WASIAbi } from "../abi.js";
import { WASIFeatureProvider } from "../options.js";
import { defaultRandomFillSync } from "../platforms/crypto.js";

/**
* Create a feature provider that provides `random_get` with `crypto` APIs as backend by default.
Expand All @@ -10,7 +9,7 @@ export function useRandom(
randomFillSync?: (buffer: Uint8Array) => void;
} = {},
): WASIFeatureProvider {
const randomFillSync = useOptions.randomFillSync || defaultRandomFillSync;
const randomFillSync = useOptions.randomFillSync || crypto.getRandomValues;
return (options, abi, memoryView) => {
return {
random_get: (bufferOffset: number, length: number) => {
Expand Down
6 changes: 0 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ export class WASI {
const featureName = useFeature.name || "Unknown feature";
const imports = useFeature(options, abi, this.view.bind(this));
for (const key in imports) {
if (key in this.wasiImport) {
const previousProvider = importProviders[key] || "Unknown feature";
throw new Error(
`Import conflict: Function '${key}' is already provided by '${previousProvider}' and is being redefined by '${featureName}'`,
);
}
importProviders[key] = featureName;
}
this.wasiImport = { ...this.wasiImport, ...imports };
Expand Down
3 changes: 0 additions & 3 deletions src/platforms/crypto.browser.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/platforms/crypto.ts

This file was deleted.

6 changes: 5 additions & 1 deletion test/wasi.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import fs from "fs/promises";
import fsSync from "fs";
import path from "path";
import { useAll, WASI, MemoryFileSystem } from "../lib/esm/index.js";
import { useAll, WASI, MemoryFileSystem, useRandom } from "../lib/esm/index.js";
import { describe, it } from "node:test";
import assert from "node:assert";
import * as crypto from "crypto";

/**
* @typedef {{ exit_code?: number, args?: string[], env?: Record<string, string>, dirs?: string[] }} TestCaseConfig
Expand Down Expand Up @@ -125,6 +126,9 @@ async function runTest(testCase) {
},
},
}),
useRandom({
randomFillSync: crypto.randomFillSync,
}),
],
});

Expand Down