Skip to content

Commit c175764

Browse files
Merge pull request #10 from andrewmd5/bundler-fixes
Bundler fixes
2 parents bc3cd7d + ef23878 commit c175764

File tree

7 files changed

+16
-22
lines changed

7 files changed

+16
-22
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ jobs:
1111
name: Test
1212
runs-on: ubuntu-20.04
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
with:
1616
submodules: true
17+
18+
- uses: actions/setup-node@v4
19+
with:
20+
node-version: 22.14.0
1721

1822
- run: npm install
1923
- run: npm test

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"name": "uwasi",
33
"version": "1.4.0",
44
"description": "Micro modularized WASI runtime for JavaScript",
5-
"main": "lib/cjs/index.js",
6-
"module": "lib/esm/index.js",
7-
"browser": {
8-
"./lib/esm/platforms/crypto.js": "./lib/esm/platforms/crypto.browser.js"
5+
"exports": {
6+
".": {
7+
"import": "./lib/esm/index.js",
8+
"require": "./lib/cjs/index.js"
9+
}
910
},
1011
"scripts": {
1112
"build": "tsc -p tsconfig.esm.json && tsc -p tsconfig.cjs.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",

src/features/random.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { WASIAbi } from "../abi.js";
22
import { WASIFeatureProvider } from "../options.js";
3-
import { defaultRandomFillSync } from "../platforms/crypto.js";
43

54
/**
65
* Create a feature provider that provides `random_get` with `crypto` APIs as backend by default.
@@ -10,7 +9,7 @@ export function useRandom(
109
randomFillSync?: (buffer: Uint8Array) => void;
1110
} = {},
1211
): WASIFeatureProvider {
13-
const randomFillSync = useOptions.randomFillSync || defaultRandomFillSync;
12+
const randomFillSync = useOptions.randomFillSync || crypto.getRandomValues;
1413
return (options, abi, memoryView) => {
1514
return {
1615
random_get: (bufferOffset: number, length: number) => {

src/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ export class WASI {
3535
const featureName = useFeature.name || "Unknown feature";
3636
const imports = useFeature(options, abi, this.view.bind(this));
3737
for (const key in imports) {
38-
if (key in this.wasiImport) {
39-
const previousProvider = importProviders[key] || "Unknown feature";
40-
throw new Error(
41-
`Import conflict: Function '${key}' is already provided by '${previousProvider}' and is being redefined by '${featureName}'`,
42-
);
43-
}
4438
importProviders[key] = featureName;
4539
}
4640
this.wasiImport = { ...this.wasiImport, ...imports };

src/platforms/crypto.browser.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/platforms/crypto.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/wasi.test.mjs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import fs from "fs/promises";
33
import fsSync from "fs";
44
import path from "path";
5-
import { useAll, WASI, MemoryFileSystem } from "../lib/esm/index.js";
5+
import { useAll, WASI, MemoryFileSystem, useRandom } from "../lib/esm/index.js";
66
import { describe, it } from "node:test";
77
import assert from "node:assert";
8+
import * as crypto from "crypto";
89

910
/**
1011
* @typedef {{ exit_code?: number, args?: string[], env?: Record<string, string>, dirs?: string[] }} TestCaseConfig
@@ -125,6 +126,9 @@ async function runTest(testCase) {
125126
},
126127
},
127128
}),
129+
useRandom({
130+
randomFillSync: crypto.randomFillSync,
131+
}),
128132
],
129133
});
130134

0 commit comments

Comments
 (0)