Skip to content

Commit e0023a2

Browse files
committed
Add npm packaging
1 parent 5821ef0 commit e0023a2

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

wasm/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.sass
22
*.css
33
*.css.map
4+
pkg/

wasm/Makefile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,19 @@ build:
1111

1212
clean:
1313
$(MAKE) -C .. $(MAKE_OPTS) clean-all
14+
rf -f pkg/
1415

1516
wasi_polyfill.wasm: wasi_polyfill.wat
1617
$(WABT)/bin/wat2wasm wasi_polyfill.wat -o wasi_polyfill.wasm
1718

18-
.PHONY: build clean
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"
28+
29+
.PHONY: build clean pack

wasm/README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ To rebuild `wasi_polyfill.wasm`: `make wasi_polyfill.wasm`
1212
Examples:
1313

1414
```
15-
node run.js -v
16-
node run.js $PWD/test.sass
17-
node run.js $PWD/test.sass $PWD/test.css
15+
node cli.js -v
16+
node cli.js $PWD/test.sass
17+
node cli.js $PWD/test.sass $PWD/test.css
1818
```
1919

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

22+
# wasi-sdk prerequisite
2223

24+
Clone, build and install the [wask-sdk](https://github.com/CraneStation/wasi-sdk), e.g. `make PREFIX=~/bin wasi-sdk/ LLVM_PROJ_DIR=~/Work/llvm-project/`
25+
26+
Note: used `bdaa39ea6ca4` commit of llvm-project, older versions (e.g. LLVM 8 used by wasi-sdk) when used causing the "std::__2::random_device::random_device" error.

wasm/run.js renamed to wasm/cli.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
#!/usr/bin/env node
12
const wp = require('./wasi_polyfill.js');
23
const fs = require('fs');
4+
const path = require('path');
35

46
async function init() {
57
const host = new wp.createWasiHost();
68
const { instance: wrapper } = await WebAssembly.instantiate(
7-
fs.readFileSync("wasi_polyfill.wasm"),
9+
fs.readFileSync(path.join(__dirname, "wasi_polyfill.wasm")),
810
{"wasi_polyfill": host}
911
);
12+
const wasmPath = path.join(__dirname, "../sassc/bin/sassc.wasm");
1013
const { instance: sassc } = await WebAssembly.instantiate(
11-
fs.readFileSync("../sassc/bin/sassc.wasm"),
14+
fs.readFileSync(wasmPath),
1215
{"wasi_unstable": wrapper.exports}
1316
);
14-
host.args = ["../sassc/bin/sassc.wasm", ...process.argv.slice(2)];
17+
host.args = [wasmPath, ...process.argv.slice(2)];
1518
host.memory = sassc.exports.memory;
1619
return sassc.exports;
1720
}

wasm/package.json.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "sassc-wasi",
3+
"version": "0.1.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"bin": {
10+
"sassc-wasi": "./wasm/cli.js"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "git+https://github.com/yurydelendik/libsass.git"
15+
},
16+
"author": "",
17+
"license": "ISC",
18+
"homepage": "https://github.com/yurydelendik/libsass/tree/wasi/wasm"
19+
}

0 commit comments

Comments
 (0)