npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pretty-print-json-go-wasm

v0.1.19

Published

**NOTE**: testing with stackblitz: https://stackblitz.com/edit/stackblitz-starters-wa3lmu

Downloads

6

Readme

Attempting to make a WASM component and publish to NPM

NOTE: testing with stackblitz: https://stackblitz.com/edit/stackblitz-starters-wa3lmu

  • created this folder: mkdir pretty-print-go-wasm

  • created go.mod:

$ cd pretty-print-go-wasm
$ go mod init github.com/mandolyte/pretty-print-go-wasm
go: creating new go.mod: module github.com/mandolyte/pretty-print-go-wasm
$ cat go.mod
module github.com/mandolyte/pretty-print-go-wasm

go 1.20
$
  • created main.go in src folder(just copied from the webassembly-part-1 folder)

  • compiled to wasm:

$ GOOS=js GOARCH=wasm go build -o main.wasm
  • copied the go wasm-exec.js file in src (comes with go install; see tutorial)

  • created the "wrapper" Javascript code in src/index.js

  • created package.json with what I think will be needed

  • run "npm install"; had some warnings, but seemed to work.

  • run "npm publish":

$ npm publish

> [email protected] prepublishOnly
> rm -fr ./dist & babel ./src --out-dir ./dist -s inline

Successfully compiled 2 files with Babel (193ms).
npm notice 
npm notice 📦  [email protected]
npm notice === Tarball Contents === 
npm notice 762B README.md   
npm notice 634B package.json
npm notice === Tarball Details === 
npm notice name:          pretty-print-json-go-wasm               
npm notice version:       0.1.0                                   
npm notice filename:      pretty-print-json-go-wasm-0.1.0.tgz     
npm notice package size:  794 B                                   
npm notice unpacked size: 1.4 kB                                  
npm notice shasum:        020dd10fa465358de6957de021f5f4e1c37bc055
npm notice integrity:     sha512-asCbTFB4vTluK[...]XpqqOtZrjONrw==
npm notice total files:   2                                       
npm notice 
npm notice Publishing to https://registry.npmjs.org/
+ [email protected]
$ 
  • Link: https://www.npmjs.com/package/pretty-print-json-go-wasm

Trials and Tribulations

2023-07-23

Since the NPM component is unable to locate the WASM file within itself, I changed the code to retrieve from a known location. In this case, from the component's repo location. And then using a raw github fetch to acquire the WASM file. That does not work, error is:

TypeError: Failed to execute 'compile' on 'WebAssembly': Incorrect response MIME type. Expected 'application/wasm'.

Here is a discussion of the issue: https://github.com/orgs/community/discussions/22863

Using tiny go

Link: https://tinygo.org/docs/guides/webassembly/wasm/

Command:

tinygo build -o wasm.wasm -target wasm ./main.go

Results:

  • go wasm size was 2788448
  • tinygo size was 900648

With this I was able to upload the WASM into my Stackblitz project.

Have tried to locate it in:

  • ./pages/main.wasm - did not work
  • main.wasm - did not work
  • /main.wasm - did not work
  • /public/main.wasm - found it, but returned this error:
TypeError: WebAssembly.instantiate(): Import #0 module="env" error: module is not an object or function