Skip to content

Commit

Permalink
Fix JS build, hopefully for 32-bit as well, see #707
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed May 26, 2024
1 parent d4342bd commit 07e76e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 4 additions & 3 deletions bindings/js/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ compile:
build:
node-gyp configure
prebuildify --napi --strip
rm -rf go.*

publish:
publish: build
sed -i.bak -e "s/{VERSION}/${VERSION}/" package.json
rm package.json.bak
npm publish --access=public
mv package.json.bak package.json

clean:
rm -rf minify.a
rm -rf build
rm -rf prebuilds
rm -rf go.*

test:
test: build
npm test

.PHONY: all compile build publish clean test
Expand Down
10 changes: 7 additions & 3 deletions bindings/js/minify.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func init() {
minifyConfig(nil, nil, 0)
}

func goBytes(str *C.char, length, capacity C.longlong) []byte {
return (*[1 << 28]byte)(unsafe.Pointer(str))[:length:capacity]
}

func goStringArray(carr **C.char, length C.longlong) []string {
if length == 0 {
return []string{}
Expand Down Expand Up @@ -119,9 +123,9 @@ func minifyConfig(ckeys **C.char, cvals **C.char, length C.longlong) *C.char {

//export minifyString
func minifyString(cmediatype, cinput *C.char, input_length C.longlong, coutput *C.char, output_length *C.longlong) *C.char {
mediatype := C.GoString(cmediatype) // copy
input := C.GoBytes(unsafe.Pointer(cinput), C.int(input_length))
output := C.GoBytes(unsafe.Pointer(coutput), C.int(input_length))
mediatype := C.GoString(cmediatype) // copy
input := goBytes(cinput, input_length, input_length+1) // +1 for NULL byte we will use in parser
output := goBytes(coutput, input_length, input_length)

out := buffer.NewStaticWriter(output[:0])
if err := m.Minify(mediatype, out, buffer.NewReader(input)); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions bindings/js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 07e76e6

Please sign in to comment.