Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Es Modules for the build and examples + Update most dependencies #126

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Use pupeteer to run in the browser
const puppeteer = require("puppeteer");
import puppeteer from "puppeteer";

// Require rollup to compile our browser.js
const rollup = require("rollup");
const { nodeResolve } = require("@rollup/plugin-node-resolve");
// Import rollup to compile our browser.js
import { rollup } from "rollup";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import desm from "desm";

// Get some native node libs, in order to host a static server
const path = require("path");
const fs = require("fs");
const http = require("http");
import path from "path";
import fs from "fs";
import http from "http";

const __dirname = desm(import.meta.url);

// Host a static server of the local directory
// https://nodejs.org/en/knowledge/HTTP/servers/how-to-serve-static-files/
Expand All @@ -28,16 +31,16 @@ http

(async () => {
// Create a rollup bundle and get our compiled browser.js as a string
const bundle = await rollup.rollup({
input: "./browser.js",
const bundle = await rollup({
input: `${__dirname}/browser.mjs`,
plugins: [nodeResolve()]
});
const { output } = await bundle.generate({
format: "iife"
});
const browserQuickstartJs = output[0].code;

// Launch the pupeteer browser and page
console.log("Launching the pupeteer browser and page...");
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("http://localhost:8000/browser.html");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ const asyncTask = async () => {
asBindInstance.exports.myExportedFunctionThatTakesAString("Hello World!");
console.log(response); // AsBind: Hello World!
};
asyncTask();
asyncTask().catch(e => {
throw e;
});
File renamed without changes.
17 changes: 17 additions & 0 deletions examples/quickstart/nodejs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// We need to import the direct as-bind.cjs.js for Node applications.
// This is because the default "main" key in the `package.json`,
// is the as-bind transform script
import AsBind from "as-bind/dist/as-bind.cjs.js";
import fs from "fs";

const wasm = fs.readFileSync("./path-to-my-wasm.wasm");

const asyncTask = async () => {
const asBindInstance = await AsBind.instantiate(wasm);

// You can now use your wasm / as-bind instance!
const response =
asBindInstance.exports.myExportedFunctionThatTakesAString("Hello World!");
console.log(response); // AsBind: Hello World!
};
asyncTask();
124 changes: 0 additions & 124 deletions examples/quickstart/package-lock.json

This file was deleted.

6 changes: 3 additions & 3 deletions examples/quickstart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"name": "as-bind-quickstart",
"version": "0.0.1",
"description": "Project that tests the README QuickStart examples to ensure that the README works. This depends on node modules from the root package.json",
"main": "index.js",
"scripts": {
"build": "asc your-entryfile.ts --exportRuntime --transform as-bind -b path-to-my-wasm.wasm",
"test": "npm run build && npm run test:node && npm run test:browser",
"test:node": "node nodejs.js",
"test:browser": "node browser-puppeteer.js"
"test:node": "node nodejs.mjs",
"test:node:cjs": "node nodejs.cjs",
"test:browser": "node browser-puppeteer.mjs"
},
"author": "Aaron Turner",
"license": "MIT",
Expand Down
Binary file modified examples/quickstart/path-to-my-wasm.wasm
Binary file not shown.
81 changes: 81 additions & 0 deletions examples/quickstart/pnpm-lock.yaml

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

Loading