gowm 1.0.6 โ 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +242 -312
- package/composables/useWasm.js +95 -37
- package/hooks/useWasm.js +71 -6
- package/package.json +19 -17
- package/src/browser.js +66 -59
- package/types/index.d.ts +370 -18
- package/CHANGELOG.md +0 -0
- package/src/loader-backup-original.js +0 -210
- package/src/loader-enhanced.js +0 -209
- package/src/loader-fixed-complete.js +0 -209
package/README.md
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
# GoWM - Go
|
|
1
|
+
# GoWM - Go WebAssembly Manager
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
<img src="./logo.png" alt="GoWM Logo" width="200" />
|
|
5
5
|
|
|
6
|
-
<p><strong>GoWM</strong> simplifies the integration of Go WebAssembly modules into your JavaScript projects.</p>
|
|
6
|
+
<p><strong>GoWM</strong> simplifies the integration of Go WebAssembly modules into your JavaScript projects with support for GitHub repositories, React hooks, and Vue composables.</p>
|
|
7
|
+
|
|
8
|
+
<p>
|
|
9
|
+
<a href="https://www.npmjs.com/package/gowm"><img src="https://img.shields.io/npm/v/gowm.svg" alt="npm version"></a>
|
|
10
|
+
<a href="https://github.com/benoitpetit/gowm/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/gowm.svg" alt="license"></a>
|
|
11
|
+
<a href="https://www.npmjs.com/package/gowm"><img src="https://img.shields.io/npm/dm/gowm.svg" alt="downloads"></a>
|
|
12
|
+
</p>
|
|
7
13
|
</div>
|
|
8
14
|
|
|
9
15
|
## โจ Features
|
|
10
16
|
|
|
11
|
-
- ๐ **Unified
|
|
12
|
-
- ๐ง **Node.js and browser
|
|
13
|
-
- โ๏ธ **Built-in
|
|
14
|
-
- ๐ **Vue
|
|
15
|
-
- ๐ฆ **GitHub
|
|
16
|
-
- ๐ท๏ธ **
|
|
17
|
-
- ๐ก๏ธ **Robust error handling
|
|
18
|
-
- ๐งน **Automatic
|
|
19
|
-
- ๐ **Statistics
|
|
20
|
-
- ๐ **
|
|
21
|
-
- ๐ฏ **Singleton API
|
|
17
|
+
- ๐ **Unified Interface** - Load Go WASM modules from local files or GitHub repositories
|
|
18
|
+
- ๐ง **Cross-Platform** - Full support for Node.js and browser environments
|
|
19
|
+
- โ๏ธ **React Integration** - Built-in hooks (`useWasm`, `useWasmFromGitHub`)
|
|
20
|
+
- ๐ **Vue 3 Support** - Reactive composables with automatic cleanup
|
|
21
|
+
- ๐ฆ **GitHub Direct Loading** - Load WASM modules directly from GitHub repositories
|
|
22
|
+
- ๐ท๏ธ **Version Control** - Support for branches, tags, and specific commits
|
|
23
|
+
- ๐ก๏ธ **Error Handling** - Robust error handling and automatic retries
|
|
24
|
+
- ๐งน **Memory Management** - Automatic resource cleanup and memory management
|
|
25
|
+
- ๐ **Module Statistics** - Built-in monitoring and performance metrics
|
|
26
|
+
- ๐ **Flexible Calls** - Both synchronous and asynchronous function calls
|
|
27
|
+
- ๐ฏ **Multiple APIs** - Singleton API and class-based approach
|
|
22
28
|
|
|
23
29
|
## ๐ฅ Installation
|
|
24
30
|
|
|
@@ -26,42 +32,44 @@
|
|
|
26
32
|
npm install gowm
|
|
27
33
|
# or
|
|
28
34
|
yarn add gowm
|
|
35
|
+
# or
|
|
36
|
+
pnpm add gowm
|
|
29
37
|
```
|
|
30
38
|
|
|
31
39
|
## ๐ Quick Start
|
|
32
40
|
|
|
33
|
-
### Node.js
|
|
41
|
+
### Basic Usage (Node.js)
|
|
34
42
|
|
|
35
43
|
```javascript
|
|
36
44
|
const { load, loadFromGitHub } = require('gowm');
|
|
37
45
|
|
|
38
46
|
async function example() {
|
|
39
47
|
try {
|
|
40
|
-
// Load
|
|
41
|
-
const
|
|
48
|
+
// Load from local file
|
|
49
|
+
const localWasm = await load('./math.wasm', { name: 'math' });
|
|
42
50
|
|
|
43
|
-
//
|
|
44
|
-
const
|
|
51
|
+
// Load directly from GitHub repository
|
|
52
|
+
const githubWasm = await loadFromGitHub('awesome-org/wasm-math', {
|
|
45
53
|
name: 'github-math',
|
|
46
54
|
branch: 'main'
|
|
47
55
|
});
|
|
48
56
|
|
|
49
57
|
// Call functions
|
|
50
|
-
const result =
|
|
51
|
-
console.log('5 + 3 =', result);
|
|
58
|
+
const result = localWasm.call('add', 5, 3);
|
|
59
|
+
console.log('5 + 3 =', result); // 8
|
|
52
60
|
|
|
53
|
-
// Async
|
|
54
|
-
const asyncResult = await
|
|
55
|
-
console.log('4 * 7 =', asyncResult);
|
|
61
|
+
// Async calls
|
|
62
|
+
const asyncResult = await githubWasm.callAsync('multiply', 4, 7);
|
|
63
|
+
console.log('4 * 7 =', asyncResult); // 28
|
|
56
64
|
|
|
57
|
-
// Check
|
|
58
|
-
if (
|
|
59
|
-
console.log('
|
|
65
|
+
// Check available functions
|
|
66
|
+
if (localWasm.hasFunction('subtract')) {
|
|
67
|
+
console.log('subtract function is available');
|
|
60
68
|
}
|
|
61
69
|
|
|
62
|
-
// Get statistics
|
|
63
|
-
const stats =
|
|
64
|
-
console.log('
|
|
70
|
+
// Get module statistics
|
|
71
|
+
const stats = localWasm.getStats();
|
|
72
|
+
console.log('Available functions:', stats.functions);
|
|
65
73
|
|
|
66
74
|
} catch (error) {
|
|
67
75
|
console.error('Error:', error);
|
|
@@ -71,7 +79,7 @@ async function example() {
|
|
|
71
79
|
example();
|
|
72
80
|
```
|
|
73
81
|
|
|
74
|
-
### React
|
|
82
|
+
### React Integration
|
|
75
83
|
|
|
76
84
|
```jsx
|
|
77
85
|
import React, { useState } from 'react';
|
|
@@ -90,7 +98,7 @@ function CalculatorComponent() {
|
|
|
90
98
|
const sum = await wasm.callAsync('add', 10, 20);
|
|
91
99
|
setResult(sum);
|
|
92
100
|
} catch (err) {
|
|
93
|
-
console.error('Calculation
|
|
101
|
+
console.error('Calculation failed:', err);
|
|
94
102
|
}
|
|
95
103
|
}
|
|
96
104
|
};
|
|
@@ -107,18 +115,18 @@ function CalculatorComponent() {
|
|
|
107
115
|
}
|
|
108
116
|
```
|
|
109
117
|
|
|
110
|
-
### Vue
|
|
118
|
+
### Vue 3 Integration
|
|
111
119
|
|
|
112
120
|
```vue
|
|
113
121
|
<template>
|
|
114
122
|
<div class="calculator">
|
|
115
123
|
<div v-if="loading">Loading WASM module from GitHub...</div>
|
|
116
|
-
<div v-else-if="error">Error: {{ error.message }}</div>
|
|
124
|
+
<div v-else-if="error" class="error">Error: {{ error.message }}</div>
|
|
117
125
|
<div v-else>
|
|
118
126
|
<input v-model.number="num1" type="number" placeholder="First number" />
|
|
119
127
|
<input v-model.number="num2" type="number" placeholder="Second number" />
|
|
120
128
|
<button @click="calculate">Calculate {{ num1 }} + {{ num2 }}</button>
|
|
121
|
-
<div v-if="result !== null">Result: {{ result }}</div>
|
|
129
|
+
<div v-if="result !== null" class="result">Result: {{ result }}</div>
|
|
122
130
|
</div>
|
|
123
131
|
</div>
|
|
124
132
|
</template>
|
|
@@ -156,17 +164,18 @@ export default {
|
|
|
156
164
|
</script>
|
|
157
165
|
```
|
|
158
166
|
|
|
159
|
-
|
|
167
|
+
## ๐ GitHub Repository Loading
|
|
168
|
+
|
|
169
|
+
GoWM excels at loading WASM modules directly from GitHub repositories with intelligent file discovery:
|
|
160
170
|
|
|
161
171
|
```javascript
|
|
162
172
|
const { loadFromGitHub } = require('gowm');
|
|
163
173
|
|
|
164
|
-
async function
|
|
165
|
-
|
|
166
|
-
// Basic loading - tries common filenames automatically
|
|
174
|
+
async function examples() {
|
|
175
|
+
// Basic loading - automatic file discovery
|
|
167
176
|
const math = await loadFromGitHub('awesome-org/wasm-math');
|
|
168
177
|
|
|
169
|
-
|
|
178
|
+
// Advanced loading with specific options
|
|
170
179
|
const imageProcessor = await loadFromGitHub('image-corp/wasm-image', {
|
|
171
180
|
branch: 'develop', // Use develop branch
|
|
172
181
|
path: 'dist', // Look in dist folder
|
|
@@ -185,31 +194,36 @@ async function useGitHubLibrary() {
|
|
|
185
194
|
'https://github.com/org/repo',
|
|
186
195
|
{ filename: 'module.wasm' }
|
|
187
196
|
);
|
|
188
|
-
|
|
189
|
-
const result = math.call('add', 10, 20);
|
|
190
|
-
console.log('Result:', result);
|
|
191
|
-
} catch (error) {
|
|
192
|
-
console.error('GitHub loading error:', error);
|
|
193
|
-
}
|
|
194
197
|
}
|
|
195
198
|
```
|
|
196
199
|
|
|
200
|
+
### Automatic File Discovery
|
|
201
|
+
|
|
202
|
+
GoWM automatically searches for WASM files in common locations:
|
|
203
|
+
|
|
204
|
+
- **Root directory**: `main.wasm`, `index.wasm`, `{repo-name}.wasm`
|
|
205
|
+
- **Common folders**: `wasm/`, `dist/`, `build/`
|
|
206
|
+
- **GitHub releases**: Searches release assets for WASM files
|
|
207
|
+
- **Custom paths**: Respects your specified path and filename
|
|
208
|
+
|
|
197
209
|
## ๐ API Reference
|
|
198
210
|
|
|
199
|
-
###
|
|
211
|
+
### Core Functions
|
|
200
212
|
|
|
201
|
-
|
|
213
|
+
#### `load(wasmPath, options)`
|
|
214
|
+
|
|
215
|
+
Loads a WASM module from a local file or URL.
|
|
202
216
|
|
|
203
217
|
**Parameters:**
|
|
204
|
-
- `wasmPath` (string): Path to the .wasm file
|
|
218
|
+
- `wasmPath` (string): Path to the .wasm file or URL
|
|
205
219
|
- `options` (object, optional):
|
|
206
|
-
- `name` (string): Module
|
|
220
|
+
- `name` (string): Module identifier (default: 'default')
|
|
207
221
|
- `goRuntimePath` (string): Custom path to wasm_exec.js
|
|
208
222
|
- `preInit` (boolean): Pre-initialize the module (default: true)
|
|
209
223
|
|
|
210
224
|
**Returns:** Promise<WasmBridge>
|
|
211
225
|
|
|
212
|
-
|
|
226
|
+
#### `loadFromGitHub(githubRepo, options)`
|
|
213
227
|
|
|
214
228
|
Loads a WASM module from a GitHub repository with automatic file resolution.
|
|
215
229
|
|
|
@@ -224,14 +238,9 @@ Loads a WASM module from a GitHub repository with automatic file resolution.
|
|
|
224
238
|
- `goRuntimePath` (string): Custom path to wasm_exec.js
|
|
225
239
|
- `preInit` (boolean): Pre-initialize the module (default: true)
|
|
226
240
|
|
|
227
|
-
**Automatic resolution:** Tries multiple common locations:
|
|
228
|
-
- `main.wasm`, `index.wasm`, `{repo-name}.wasm`
|
|
229
|
-
- `wasm/`, `dist/`, `build/` directories
|
|
230
|
-
- GitHub releases (if available)
|
|
231
|
-
|
|
232
241
|
**Returns:** Promise<WasmBridge>
|
|
233
242
|
|
|
234
|
-
|
|
243
|
+
#### `get(name)`
|
|
235
244
|
|
|
236
245
|
Retrieves an already loaded module by name.
|
|
237
246
|
|
|
@@ -240,338 +249,259 @@ Retrieves an already loaded module by name.
|
|
|
240
249
|
|
|
241
250
|
**Returns:** WasmBridge | null
|
|
242
251
|
|
|
243
|
-
###
|
|
244
|
-
|
|
245
|
-
- `listModules()`: List all loaded modules
|
|
246
|
-
- `getStats()`: Get statistics for all modules
|
|
247
|
-
- `unload(name)`: Unload a specific module
|
|
248
|
-
- `unloadAll()`: Unload all modules
|
|
249
|
-
- `isLoaded(name)`: Check if a module is loaded
|
|
250
|
-
- `getTotalMemoryUsage()`: Get total memory usage across all modules
|
|
251
|
-
|
|
252
|
-
### WasmBridge
|
|
252
|
+
### WasmBridge Methods
|
|
253
253
|
|
|
254
|
-
|
|
254
|
+
#### `call(funcName, ...args)`
|
|
255
255
|
|
|
256
|
-
|
|
256
|
+
Calls a WASM function synchronously.
|
|
257
257
|
|
|
258
|
-
|
|
259
|
-
- `
|
|
260
|
-
-
|
|
261
|
-
- `getAvailableFunctions()`: Get list of available functions
|
|
262
|
-
- `registerCallback(name, callback)`: Register a JavaScript callback accessible from Go
|
|
263
|
-
- `unregisterCallback(name)`: Remove a JavaScript callback
|
|
264
|
-
- `createBuffer(data)`: Create a buffer for data transfer (Float64Array, Uint8Array, string)
|
|
265
|
-
- `getStats()`: Get module statistics (functions, callbacks, memory)
|
|
258
|
+
**Parameters:**
|
|
259
|
+
- `funcName` (string): Name of the function to call
|
|
260
|
+
- `...args`: Function arguments
|
|
266
261
|
|
|
267
|
-
|
|
262
|
+
**Returns:** Function result
|
|
268
263
|
|
|
269
|
-
####
|
|
264
|
+
#### `callAsync(funcName, ...args)`
|
|
270
265
|
|
|
271
|
-
|
|
266
|
+
Calls a WASM function asynchronously.
|
|
272
267
|
|
|
273
268
|
**Parameters:**
|
|
274
|
-
- `
|
|
275
|
-
-
|
|
269
|
+
- `funcName` (string): Name of the function to call
|
|
270
|
+
- `...args`: Function arguments
|
|
276
271
|
|
|
277
|
-
**Returns:**
|
|
278
|
-
```javascript
|
|
279
|
-
{
|
|
280
|
-
wasm: Ref<WasmBridge | null>,
|
|
281
|
-
loading: Ref<boolean>,
|
|
282
|
-
error: Ref<Error | null>,
|
|
283
|
-
reload: () => void
|
|
284
|
-
}
|
|
285
|
-
```
|
|
272
|
+
**Returns:** Promise<Function result>
|
|
286
273
|
|
|
287
|
-
####
|
|
274
|
+
#### `hasFunction(funcName)`
|
|
288
275
|
|
|
289
|
-
|
|
276
|
+
Checks if a function exists in the WASM module.
|
|
290
277
|
|
|
291
278
|
**Parameters:**
|
|
292
|
-
- `
|
|
293
|
-
- `options` (object|Ref<object>, optional): GitHub loading options
|
|
279
|
+
- `funcName` (string): Function name to check
|
|
294
280
|
|
|
295
|
-
**Returns:**
|
|
281
|
+
**Returns:** boolean
|
|
296
282
|
|
|
297
|
-
####
|
|
283
|
+
#### `getAvailableFunctions()`
|
|
298
284
|
|
|
299
|
-
|
|
285
|
+
Gets a list of all available functions in the module.
|
|
300
286
|
|
|
301
|
-
**
|
|
302
|
-
- `modules` (Array|Ref<Array>): Array of module configurations
|
|
287
|
+
**Returns:** string[]
|
|
303
288
|
|
|
304
|
-
|
|
305
|
-
```javascript
|
|
306
|
-
{
|
|
307
|
-
name: string, // Required: Module name
|
|
308
|
-
path?: string, // Optional: Local file path
|
|
309
|
-
github?: string, // Optional: GitHub repository
|
|
310
|
-
options?: LoadOptions // Optional: Loading options
|
|
311
|
-
}
|
|
312
|
-
```
|
|
289
|
+
#### `getStats()`
|
|
313
290
|
|
|
314
|
-
|
|
291
|
+
Gets module statistics and information.
|
|
315
292
|
|
|
316
|
-
|
|
293
|
+
**Returns:** Object with statistics
|
|
317
294
|
|
|
318
|
-
|
|
319
|
-
- `githubRepos` (Array|Ref<Array>): Array of GitHub repository configurations
|
|
295
|
+
#### `cleanup()`
|
|
320
296
|
|
|
321
|
-
|
|
322
|
-
```javascript
|
|
323
|
-
{
|
|
324
|
-
name: string, // Required: Module name
|
|
325
|
-
repo: string, // Required: GitHub repository
|
|
326
|
-
branch?: string, // Optional: Git branch
|
|
327
|
-
tag?: string, // Optional: Git tag
|
|
328
|
-
path?: string, // Optional: Path in repository
|
|
329
|
-
filename?: string, // Optional: Specific filename
|
|
330
|
-
options?: GitHubLoadOptions // Optional: Additional options
|
|
331
|
-
}
|
|
332
|
-
```
|
|
297
|
+
Manually clean up module resources.
|
|
333
298
|
|
|
334
|
-
**Returns:**
|
|
335
|
-
```javascript
|
|
336
|
-
{
|
|
337
|
-
modules: Ref<Record<string, WasmBridge>>,
|
|
338
|
-
loading: Ref<boolean>, // Global loading state
|
|
339
|
-
errors: Ref<Record<string, Error>>, // Errors by module
|
|
340
|
-
reload: () => void
|
|
341
|
-
}
|
|
342
|
-
```
|
|
299
|
+
**Returns:** void
|
|
343
300
|
|
|
344
|
-
###
|
|
301
|
+
### Utility Functions
|
|
345
302
|
|
|
346
|
-
|
|
303
|
+
- `listModules()`: List all loaded modules
|
|
304
|
+
- `getStats()`: Get statistics for all modules
|
|
305
|
+
- `unload(name)`: Unload a specific module
|
|
306
|
+
- `unloadAll()`: Unload all modules
|
|
307
|
+
- `isLoaded(name)`: Check if a module is loaded
|
|
308
|
+
- `getTotalMemoryUsage()`: Get total memory usage
|
|
347
309
|
|
|
348
|
-
|
|
310
|
+
## โ๏ธ React Hooks
|
|
349
311
|
|
|
350
|
-
|
|
351
|
-
- `wasmPath` (string): Path to the .wasm file
|
|
352
|
-
- `options` (object, optional): Loading options
|
|
312
|
+
### `useWasm(wasmPath, options)`
|
|
353
313
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
314
|
+
Hook for loading local WASM modules.
|
|
315
|
+
|
|
316
|
+
```jsx
|
|
317
|
+
import { useWasm } from 'gowm/hooks/useWasm';
|
|
318
|
+
|
|
319
|
+
function MyComponent() {
|
|
320
|
+
const { wasm, loading, error } = useWasm('./my-module.wasm', {
|
|
321
|
+
name: 'myModule'
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
// Use wasm when loaded
|
|
360
325
|
}
|
|
361
326
|
```
|
|
362
327
|
|
|
363
|
-
|
|
328
|
+
### `useWasmFromGitHub(githubRepo, options)`
|
|
364
329
|
|
|
365
|
-
|
|
330
|
+
Hook for loading WASM modules from GitHub.
|
|
366
331
|
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
- `options` (object, optional): GitHub loading options
|
|
332
|
+
```jsx
|
|
333
|
+
import { useWasmFromGitHub } from 'gowm/hooks/useWasm';
|
|
370
334
|
|
|
371
|
-
|
|
335
|
+
function MyComponent() {
|
|
336
|
+
const { wasm, loading, error } = useWasmFromGitHub('org/repo', {
|
|
337
|
+
branch: 'main',
|
|
338
|
+
name: 'myModule'
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
```
|
|
372
342
|
|
|
373
|
-
|
|
343
|
+
### `useMultipleWasmFromGitHub(githubRepos, options)`
|
|
374
344
|
|
|
375
|
-
|
|
345
|
+
Hook for loading multiple WASM modules from GitHub.
|
|
376
346
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
- `options` (object, optional): Global loading options
|
|
347
|
+
```jsx
|
|
348
|
+
import { useMultipleWasmFromGitHub } from 'gowm/hooks/useWasm';
|
|
380
349
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
{
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
errors: Record<string, Error>,
|
|
387
|
-
reload: () => void
|
|
350
|
+
function MyComponent() {
|
|
351
|
+
const { modules, loading, errors, reload } = useMultipleWasmFromGitHub([
|
|
352
|
+
{ name: 'math', repo: 'org/math-wasm' },
|
|
353
|
+
{ name: 'image', repo: 'org/image-wasm', branch: 'dev' }
|
|
354
|
+
]);
|
|
388
355
|
}
|
|
389
356
|
```
|
|
390
357
|
|
|
391
|
-
##
|
|
358
|
+
## ๐ Vue 3 Composables
|
|
392
359
|
|
|
393
|
-
###
|
|
360
|
+
### `useWasm(wasmPath, options)`
|
|
394
361
|
|
|
395
|
-
|
|
396
|
-
package main
|
|
362
|
+
Composable for loading local WASM modules.
|
|
397
363
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
func add(this js.Value, p []js.Value) interface{} {
|
|
403
|
-
if len(p) != 2 {
|
|
404
|
-
return js.ValueOf("Error: two arguments required")
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
a := p[0].Float()
|
|
408
|
-
b := p[1].Float()
|
|
409
|
-
return js.ValueOf(a + b)
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
func multiply(this js.Value, p []js.Value) interface{} {
|
|
413
|
-
if len(p) != 2 {
|
|
414
|
-
return js.ValueOf("Error: two arguments required")
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
a := p[0].Float()
|
|
418
|
-
b := p[1].Float()
|
|
419
|
-
return js.ValueOf(a * b)
|
|
420
|
-
}
|
|
364
|
+
```vue
|
|
365
|
+
<script>
|
|
366
|
+
import { useWasm } from 'gowm/composables/useWasm';
|
|
421
367
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
js.Global().Set("multiply", js.FuncOf(multiply))
|
|
428
|
-
|
|
429
|
-
// Signal readiness
|
|
430
|
-
js.Global().Set("__gowm_ready", js.ValueOf(true))
|
|
431
|
-
|
|
432
|
-
<-c
|
|
368
|
+
export default {
|
|
369
|
+
setup() {
|
|
370
|
+
const { wasm, loading, error, reload } = useWasm('./my-module.wasm');
|
|
371
|
+
return { wasm, loading, error, reload };
|
|
372
|
+
}
|
|
433
373
|
}
|
|
374
|
+
</script>
|
|
434
375
|
```
|
|
435
376
|
|
|
436
|
-
###
|
|
377
|
+
### `useWasmFromGitHub(githubRepo, options)`
|
|
437
378
|
|
|
438
|
-
|
|
439
|
-
# Build WASM
|
|
440
|
-
GOOS=js GOARCH=wasm go build -o main.wasm main.go
|
|
441
|
-
|
|
442
|
-
# Create GitHub repository structure
|
|
443
|
-
mkdir my-wasm-lib
|
|
444
|
-
cd my-wasm-lib
|
|
445
|
-
cp main.wasm .
|
|
446
|
-
cp $(go env GOROOT)/misc/wasm/wasm_exec.js .
|
|
447
|
-
|
|
448
|
-
# Push to GitHub
|
|
449
|
-
git init
|
|
450
|
-
git add .
|
|
451
|
-
git commit -m "Initial WASM module"
|
|
452
|
-
git remote add origin https://github.com/username/my-wasm-lib.git
|
|
453
|
-
git push -u origin main
|
|
454
|
-
|
|
455
|
-
# Create a release (optional)
|
|
456
|
-
git tag v1.0.0
|
|
457
|
-
git push --tags
|
|
458
|
-
```
|
|
379
|
+
Composable for loading WASM modules from GitHub.
|
|
459
380
|
|
|
460
|
-
|
|
381
|
+
```vue
|
|
382
|
+
<script>
|
|
383
|
+
import { useWasmFromGitHub } from 'gowm/composables/useWasm';
|
|
461
384
|
|
|
385
|
+
export default {
|
|
386
|
+
setup() {
|
|
387
|
+
const { wasm, loading, error } = useWasmFromGitHub('org/repo', {
|
|
388
|
+
tag: 'v1.0.0'
|
|
389
|
+
});
|
|
390
|
+
return { wasm, loading, error };
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
</script>
|
|
462
394
|
```
|
|
463
|
-
examples/
|
|
464
|
-
โโโ math-wasm/ # Go math library example
|
|
465
|
-
โโโ image-wasm/ # Image processing example
|
|
466
|
-
โโโ basic-usage.js # Basic Node.js usage
|
|
467
|
-
โโโ advanced-usage.js # Advanced features demo
|
|
468
|
-
โโโ github-usage.js # GitHub loading examples
|
|
469
|
-
โโโ react-calculator.jsx # React example
|
|
470
|
-
โโโ vue-calculator.vue # Vue.js example
|
|
471
|
-
โโโ browser-demo.html # Browser demo
|
|
472
|
-
|
|
473
|
-
src/
|
|
474
|
-
โโโ index.js # Main entry point
|
|
475
|
-
โโโ loader.js # WASM module loader
|
|
476
|
-
โโโ bridge.js # WASM-JavaScript bridge
|
|
477
|
-
โโโ browser.js # Browser-specific code
|
|
478
|
-
โโโ loader-browser.js # Browser loader
|
|
479
|
-
|
|
480
|
-
composables/
|
|
481
|
-
โโโ useWasm.js # Vue 3 composables
|
|
482
|
-
|
|
483
|
-
hooks/
|
|
484
|
-
โโโ useWasm.js # React hooks
|
|
485
|
-
|
|
486
|
-
types/
|
|
487
|
-
โโโ index.d.ts # TypeScript definitions
|
|
488
|
-
```
|
|
489
|
-
|
|
490
|
-
## ๐งช Testing
|
|
491
|
-
|
|
492
|
-
```bash
|
|
493
|
-
# Run all tests
|
|
494
|
-
npm test
|
|
495
395
|
|
|
496
|
-
|
|
497
|
-
npm run test:basic
|
|
498
|
-
npm run test:advanced
|
|
499
|
-
npm run test:wasm
|
|
500
|
-
npm run test:image
|
|
396
|
+
### `useMultipleWasm(modules)`
|
|
501
397
|
|
|
502
|
-
|
|
503
|
-
node examples/github-usage.js
|
|
398
|
+
Composable for loading multiple WASM modules.
|
|
504
399
|
|
|
505
|
-
|
|
506
|
-
|
|
400
|
+
```vue
|
|
401
|
+
<script>
|
|
402
|
+
import { useMultipleWasm } from 'gowm/composables/useWasm';
|
|
507
403
|
|
|
508
|
-
|
|
509
|
-
|
|
404
|
+
export default {
|
|
405
|
+
setup() {
|
|
406
|
+
const { modules, loading, errors } = useMultipleWasm([
|
|
407
|
+
{ name: 'local', path: './local.wasm' },
|
|
408
|
+
{ name: 'github', github: 'org/repo' }
|
|
409
|
+
]);
|
|
410
|
+
return { modules, loading, errors };
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
</script>
|
|
510
414
|
```
|
|
511
415
|
|
|
512
|
-
##
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
416
|
+
## ๐ Browser Usage
|
|
417
|
+
|
|
418
|
+
For browser environments, use the ES6 module version:
|
|
419
|
+
|
|
420
|
+
```html
|
|
421
|
+
<!DOCTYPE html>
|
|
422
|
+
<html>
|
|
423
|
+
<head>
|
|
424
|
+
<script type="module">
|
|
425
|
+
import { loadFromGitHub } from './node_modules/gowm/src/browser.js';
|
|
426
|
+
|
|
427
|
+
async function init() {
|
|
428
|
+
const wasm = await loadFromGitHub('org/wasm-module');
|
|
429
|
+
const result = wasm.call('myFunction', 42);
|
|
430
|
+
console.log(result);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
init();
|
|
434
|
+
</script>
|
|
435
|
+
</head>
|
|
436
|
+
<body>
|
|
437
|
+
<h1>GoWM Browser Example</h1>
|
|
438
|
+
</body>
|
|
439
|
+
</html>
|
|
440
|
+
```
|
|
520
441
|
|
|
521
|
-
##
|
|
442
|
+
## ๐ Migration from Deprecated Features
|
|
522
443
|
|
|
523
|
-
|
|
444
|
+
### NPM Package Loading (Deprecated)
|
|
524
445
|
|
|
525
|
-
|
|
526
|
-
- `GitHubLoadOptions`: GitHub-specific loading options
|
|
527
|
-
- `WasmBridge`: Main bridge interface
|
|
528
|
-
- `ModuleStats`: Statistics interface
|
|
529
|
-
- `UseWasmResult`: Hook return types
|
|
530
|
-
- `VueWasmResult`: Composable return types
|
|
531
|
-
- `GitHubRepoConfig`: GitHub repository configuration
|
|
446
|
+
**โ ๏ธ IMPORTANT:** NPM package loading is deprecated and will be removed in future versions. Please migrate to GitHub repository loading for better reliability and performance.
|
|
532
447
|
|
|
533
|
-
|
|
448
|
+
**Old way (deprecated):**
|
|
449
|
+
```javascript
|
|
450
|
+
// โ Deprecated - will be removed
|
|
451
|
+
const math = await loadFromNPM('my-wasm-package');
|
|
452
|
+
```
|
|
534
453
|
|
|
454
|
+
**New way (recommended):**
|
|
535
455
|
```javascript
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
const result = math.call('add', 5, 3);
|
|
539
|
-
} catch (error) {
|
|
540
|
-
console.error('WASM call error:', error.message);
|
|
541
|
-
}
|
|
456
|
+
// โ
Recommended approach
|
|
457
|
+
const math = await loadFromGitHub('myorg/my-wasm-package');
|
|
542
458
|
```
|
|
543
459
|
|
|
544
|
-
|
|
460
|
+
### Migration Benefits
|
|
545
461
|
|
|
546
|
-
|
|
462
|
+
- **Better reliability**: Direct access to source repositories
|
|
463
|
+
- **Version control**: Use specific branches, tags, or commits
|
|
464
|
+
- **Faster loading**: No NPM registry overhead
|
|
465
|
+
- **Always up-to-date**: Access latest releases immediately
|
|
466
|
+
- **Better caching**: Browser and CDN optimization
|
|
547
467
|
|
|
548
|
-
|
|
549
|
-
// โ Old (deprecated)
|
|
550
|
-
const math = await loadFromNPM('my-wasm-math');
|
|
468
|
+
## ๐ Examples
|
|
551
469
|
|
|
552
|
-
|
|
553
|
-
const math = await loadFromGitHub('myorg/wasm-math');
|
|
554
|
-
```
|
|
470
|
+
Check out the `/examples` directory for comprehensive examples:
|
|
555
471
|
|
|
556
|
-
|
|
472
|
+
- **Node.js examples**: Basic and advanced usage
|
|
473
|
+
- **React examples**: Complete React applications
|
|
474
|
+
- **Vue examples**: Vue 3 application templates
|
|
475
|
+
- **Browser examples**: Vanilla JavaScript implementations
|
|
476
|
+
- **Framework examples**: Integration with popular frameworks
|
|
557
477
|
|
|
558
|
-
|
|
559
|
-
- โ
**Branch and tag support** - Use specific versions
|
|
560
|
-
- โ
**Custom file paths** - Flexible repository structure
|
|
561
|
-
- โ
**Release asset support** - Load from GitHub releases
|
|
562
|
-
- โ
**Automatic file discovery** - Smart filename detection
|
|
563
|
-
- โ
**Version control integration** - Direct Git integration
|
|
478
|
+
## ๐ค Contributing
|
|
564
479
|
|
|
565
|
-
|
|
480
|
+
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
566
481
|
|
|
567
|
-
|
|
482
|
+
### Development Setup
|
|
568
483
|
|
|
569
|
-
|
|
484
|
+
```bash
|
|
485
|
+
git clone https://github.com/benoitpetit/gowm.git
|
|
486
|
+
cd gowm
|
|
487
|
+
npm install
|
|
488
|
+
npm test
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
## ๐ License
|
|
570
492
|
|
|
571
|
-
|
|
493
|
+
MIT License - see the [LICENSE](LICENSE) file for details.
|
|
572
494
|
|
|
573
495
|
## ๐ Links
|
|
574
496
|
|
|
575
|
-
- [GitHub Repository](https://github.com/benoitpetit/gowm)
|
|
576
497
|
- [NPM Package](https://www.npmjs.com/package/gowm)
|
|
577
|
-
- [
|
|
498
|
+
- [GitHub Repository](https://github.com/benoitpetit/gowm)
|
|
499
|
+
- [Documentation](https://github.com/benoitpetit/gowm/blob/main/README.md)
|
|
500
|
+
- [Examples](https://github.com/benoitpetit/gowm/tree/main/examples)
|
|
501
|
+
|
|
502
|
+
---
|
|
503
|
+
|
|
504
|
+
<div align="center">
|
|
505
|
+
<p>Made with โค๏ธ by <a href="https://github.com/benoitpetit">@devbyben</a></p>
|
|
506
|
+
<p>โญ Star us on GitHub if this project helped you!</p>
|
|
507
|
+
</div>
|