Skip to content

Commit 8568fbd

Browse files
committed
Return a buffer
1 parent 0485c45 commit 8568fbd

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ mod printer;
1818
mod traits;
1919
mod macros;
2020

21-
use napi::{CallContext, JsObject, JsUndefined};
21+
use napi::{CallContext, JsObject, JsBuffer};
2222
use serde::{Deserialize, Serialize};
2323
use cssparser::{Parser, ParserInput, RuleListParser};
2424
use crate::traits::ToCss;
@@ -35,7 +35,7 @@ struct Config {
3535
}
3636

3737
#[js_function(1)]
38-
fn transform(ctx: CallContext) -> napi::Result<JsUndefined> {
38+
fn transform(ctx: CallContext) -> napi::Result<JsBuffer> {
3939
let opts = ctx.get::<JsObject>(0)?;
4040
let config: Config = ctx.env.from_js_value(opts)?;
4141

@@ -46,9 +46,8 @@ fn transform(ctx: CallContext) -> napi::Result<JsUndefined> {
4646
// }
4747

4848
let res = compile(code, true);
49-
println!("{}", res);
5049

51-
ctx.env.get_undefined()
50+
Ok(ctx.env.create_buffer_with_data(res.into_bytes())?.into_raw())
5251
}
5352

5453
fn compile(code: &str, minify: bool) -> String {

test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const css = require('./native');
22

33
css.transform({
4+
5+
let res = css.transform({
46
filename: __filename,
57
code: Buffer.from(`
68
@@ -103,4 +105,6 @@ css.transform({
103105
background: green;
104106
}
105107
}
106-
`)})
108+
`)});
109+
110+
console.log(res.toString());

0 commit comments

Comments
 (0)