Skip to content

Commit a9262b1

Browse files
committed
Remove wasi_polyfill files.
1 parent f89b2b5 commit a9262b1

File tree

9 files changed

+45
-574
lines changed

9 files changed

+45
-574
lines changed

wasm/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
*.css
33
*.css.map
44
pkg/
5+
node_modules/
6+
package-lock.json

wasm/Makefile

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,5 @@ build:
1111

1212
clean:
1313
$(MAKE) -C .. $(MAKE_OPTS) clean-all
14-
rf -f pkg/
15-
16-
wasi_polyfill.wasm: wasi_polyfill.wat
17-
$(WABT)/bin/wat2wasm wasi_polyfill.wat -o wasi_polyfill.wasm
18-
19-
pack: wasi_polyfill.wasm build
20-
mkdir -p pkg
21-
cp package.json.in pkg/package.json
22-
touch pkg/index.js
23-
mkdir -p pkg/sassc/bin
24-
cp ../sassc/bin/sassc.wasm pkg/sassc/bin/
25-
mkdir -p pkg/wasm
26-
cp cli.js wasi_polyfill.js wasi_polyfill.wasm pkg/wasm/
27-
echo "cd pkg && npm publish"
2814

2915
.PHONY: build clean pack

wasm/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ To build `../sassc/bin/sassc.wasm`:
55
* Clone https://github.com/yurydelendik/sassc into parent (libsass) folder
66
* Run `make`
77

8-
To rebuild `wasi_polyfill.wasm`: `make wasi_polyfill.wasm`
9-
108
# Running
119

10+
Prerequisites:
11+
* node v12 (e.g. via `nvm use 12`).
12+
* install "node-wasi" dependency via `npm i` in the "wasm" directory.
13+
1214
Examples:
1315

1416
```
15-
node cli.js -v
16-
node cli.js $PWD/test.sass
17-
node cli.js $PWD/test.sass $PWD/test.css
17+
node --experimental-wasm-bigint cli.js -v
18+
node --experimental-wasm-bigint cli.js $PWD/test.sass
19+
node --experimental-wasm-bigint cli.js $PWD/test.sass $PWD/test.css
1820
```
1921

2022
Note: Use full path for the file names and only in the current dir (hence `$PWD/` prefix).

wasm/cli.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
1-
#!/usr/bin/env node
2-
const wp = require('./wasi_polyfill.js');
1+
#!/usr/bin/env node --experimental-wasm-bigint
2+
3+
'use strict';
4+
35
const fs = require('fs');
46
const path = require('path');
7+
const WASI = require('wasi');
8+
9+
const wasmPath = path.join(__dirname, "../sassc/bin/sassc.wasm");
10+
const bin = fs.readFileSync(wasmPath);
11+
12+
const mod = new WebAssembly.Module(bin);
13+
14+
const wasi = new WASI({
15+
preopenDirectories: { [process.cwd()]: process.cwd() },
16+
env: process.env,
17+
args: [wasmPath, ...process.argv.slice(2)],
18+
});
19+
const instance = new WebAssembly.Instance(mod, {
20+
wasi_unstable: wasi.exports,
21+
});
522

6-
async function init() {
7-
const host = new wp.createWasiHost();
8-
const { instance: wrapper } = await WebAssembly.instantiate(
9-
fs.readFileSync(path.join(__dirname, "wasi_polyfill.wasm")),
10-
{"wasi_polyfill": host}
11-
);
12-
const wasmPath = path.join(__dirname, "../sassc/bin/sassc.wasm");
13-
const { instance: sassc } = await WebAssembly.instantiate(
14-
fs.readFileSync(wasmPath),
15-
{"wasi_unstable": wrapper.exports}
16-
);
17-
host.args = [wasmPath, ...process.argv.slice(2)];
18-
host.env = [`PWD=${process.cwd()}`];
19-
host.memory = sassc.exports.memory;
20-
return sassc.exports;
21-
}
23+
wasi.setMemory(instance.exports.memory);
2224

23-
init().then(sassc => {
24-
try {
25-
sassc._start();
26-
} catch (e) {
27-
if (e.message != "proc_exit") throw e;
28-
}
29-
}, console.error);
25+
instance.exports._start();

wasm/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "sassc-wasi-cli",
3+
"version": "1.0.0",
4+
"description": "To build `../sassc/bin/sassc.wasm`:",
5+
"main": "cli.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"devDependencies": {
13+
"wasi": "github:devsnek/node-wasi#785df3a0"
14+
}
15+
}

wasm/package.json.in

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

0 commit comments

Comments
 (0)