GeezerVison is showing github.com — doc: use ESM syntax for WASI example · nodejs/node@707b973
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: .eslintrc.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,6 +57,7 @@ module.exports = { |
57 | 57 | 'doc/api/module.md', |
58 | 58 | 'doc/api/modules.md', |
59 | 59 | 'doc/api/packages.md', |
| 60 | + 'doc/api/wasi.md', |
60 | 61 | 'test/es-module/test-esm-type-flag.js', |
61 | 62 | 'test/es-module/test-esm-type-flag-alias.js', |
62 | 63 | '*.mjs', |
|
Collapse file
Copy file name to clipboardExpand all lines: doc/api/wasi.md +6-8Lines changed: 6 additions & 8 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -11,9 +11,9 @@ specification. WASI gives sandboxed WebAssembly applications access to the |
11 | 11 | underlying operating system via a collection of POSIX-like functions. |
12 | 12 |
|
13 | 13 | ```js |
14 | | -'use strict'; |
15 | | -const fs = require('fs'); |
16 | | -const { WASI } = require('wasi'); |
| 14 | +import fs from 'fs'; |
| 15 | +import { WASI } from 'wasi'; |
| 16 | + |
17 | 17 | const wasi = new WASI({ |
18 | 18 | args: process.argv, |
19 | 19 | env: process.env, |
@@ -23,12 +23,10 @@ const wasi = new WASI({ |
23 | 23 | }); |
24 | 24 | const importObject = { wasi_snapshot_preview1: wasi.wasiImport }; |
25 | 25 |
|
26 | | -(async () => { |
27 | | - const wasm = await WebAssembly.compile(fs.readFileSync('./demo.wasm')); |
28 | | - const instance = await WebAssembly.instantiate(wasm, importObject); |
| 26 | +const wasm = await WebAssembly.compile(fs.readFileSync('./demo.wasm')); |
| 27 | +const instance = await WebAssembly.instantiate(wasm, importObject); |
29 | 28 |
|
30 | | - wasi.start(instance); |
31 | | -})(); |
| 29 | +wasi.start(instance); |
32 | 30 | ``` |
33 | 31 |
|
34 | 32 | To run the above example, create a new WebAssembly text format file named |
|