Skip to content

Commit

Permalink
Merge 'npm packaging for node and web' from Elijah Morgan
Browse files Browse the repository at this point in the history
Add web support to npm package.
**Still a WIP need to do some cleanup still**
I assumed it is better to keep the server code and web code together in
the same package (bigger download number). It took quite a bit of
experimentation but the ultimate experience is
node - commonjs
```js
const { Database } = require("limbo-wasm/node");
```
web - module
```js
const worker = new Worker(new URL('limbo-wasm/web/limbo-worker.js', import.meta.url), { type: 'module' });
```
Like I said this took a lot of experimentation on my part as this is my
first time trying to create an npm package let alone that mixes commonjs
and modules.
The structure is an npm workspace with two sub packages (web and node).
```
node
├── dist
│   ├── README.md
│   ├── index.d.ts
│   ├── index.js
│   ├── index_bg.wasm
│   ├── index_bg.wasm.d.ts
│   └── snippets
│       └── limbo-wasm-d1562e55b90f5289
│           └── node
│               └── src
│                   └── vfs.js
├── package.json
└── src
    └── vfs.js
web
├── dist
│   ├── README.md
│   ├── index.d.ts
│   ├── index.js
│   ├── index_bg.wasm
│   ├── index_bg.wasm.d.ts
│   └── snippets
│       └── limbo-wasm-d1562e55b90f5289
│           └── web
│               └── src
│                   └── web-vfs.js
├── html
│   ├── index.html
│   ├── limbo-opfs-test.html
│   └── limbo-test.html
├── node_modules
├── package.json
├── playwright.config.js
├── src
│   ├── limbo-worker.js
│   ├── opfs-interface.js
│   ├── opfs-sync-proxy.js
│   ├── opfs-worker.js
│   ├── opfs.js
│   └── web-vfs.js
├── test
│   ├── helpers.js
│   ├── limbo.test.js
│   ├── opfs.test.js
│   └── setup.js
└── vite.config.js
```
The output of wasm-pack gets put in <web/node>dist
JS code moves into <web/node>src/
Tests move under web/test
The npm package looks like (you can see I need to cleanup some of the
stuff that gets included).
```
-rw-r--r--  0 0      0         195 Oct 26  1985 package/web/html/index.html
-rw-r--r--  0 0      0        2733 Oct 26  1985 package/web/html/limbo-opfs-test.html
-rw-r--r--  0 0      0         162 Oct 26  1985 package/web/html/limbo-test.html
-rw-r--r--  0 0      0         632 Oct 26  1985 package/web/test/helpers.js
-rw-r--r--  0 0      0       18128 Oct 26  1985 package/node/dist/index.js
-rw-r--r--  0 0      0       21732 Oct 26  1985 package/web/dist/index.js
-rw-r--r--  0 0      0        1836 Oct 26  1985 package/web/src/limbo-worker.js
-rw-r--r--  0 0      0        2108 Oct 26  1985 package/web/test/limbo.test.js
-rw-r--r--  0 0      0        1764 Oct 26  1985 package/web/src/opfs-interface.js
-rw-r--r--  0 0      0        3409 Oct 26  1985 package/web/src/opfs-sync-proxy.js
-rw-r--r--  0 0      0        1430 Oct 26  1985 package/web/src/opfs-worker.js
-rw-r--r--  0 0      0        3976 Oct 26  1985 package/web/src/opfs.js
-rw-r--r--  0 0      0        4502 Oct 26  1985 package/web/test/opfs.test.js
-rw-r--r--  0 0      0         269 Oct 26  1985 package/web/playwright.config.js
-rw-r--r--  0 0      0           0 Oct 26  1985 package/web/test/setup.js
-rw-r--r--  0 0      0         519 Oct 26  1985 package/node/dist/snippets/limbo-wasm-d1562e55b90f5289/node/src/vfs.js
-rw-r--r--  0 0      0         519 Oct 26  1985 package/node/src/vfs.js
-rw-r--r--  0 0      0         608 Oct 26  1985 package/web/vite.config.js
-rw-r--r--  0 0      0         435 Oct 26  1985 package/web/dist/snippets/limbo-wasm-d1562e55b90f5289/web/src/web-vfs.js
-rw-r--r--  0 0      0         435 Oct 26  1985 package/web/src/web-vfs.js
-rw-r--r--  0 0      0         146 Oct 26  1985 package/web/node_modules/.vite/deps/_metadata.json
-rw-r--r--  0 0      0         309 Oct 26  1985 package/node/package.json
-rw-r--r--  0 0      0         671 Oct 26  1985 package/package.json
-rw-r--r--  0 0      0          23 Oct 26  1985 package/web/node_modules/.vite/deps/package.json
-rw-r--r--  0 0      0         602 Oct 26  1985 package/web/package.json
-rw-r--r--  0 0      0         153 Oct 26  1985 package/web/node_modules/.vite/vitest/results.json
-rw-r--r--  0 0      0        1296 Oct 26  1985 package/node/dist/README.md
-rw-r--r--  0 0      0        1296 Oct 26  1985 package/README.md
-rw-r--r--  0 0      0        1296 Oct 26  1985 package/web/dist/README.md
-rw-r--r--  0 0      0        1217 Oct 26  1985 package/node/dist/index_bg.wasm.d.ts
-rw-r--r--  0 0      0        1217 Oct 26  1985 package/web/dist/index_bg.wasm.d.ts
-rw-r--r--  0 0      0         449 Oct 26  1985 package/node/dist/index.d.ts
-rw-r--r--  0 0      0        2554 Oct 26  1985 package/web/dist/index.d.ts
-rw-r--r--  0 0      0     2215065 Oct 26  1985 package/node/dist/index_bg.wasm
-rw-r--r--  0 0      0     2213889 Oct 26  1985 package/web/dist/index_bg.wasm
```
resolves #624

Closes #657
  • Loading branch information
penberg committed Jan 19, 2025
2 parents ef1e0ae + 74ddc42 commit 466bc8b
Show file tree
Hide file tree
Showing 32 changed files with 4,949 additions and 1,423 deletions.
3 changes: 3 additions & 0 deletions bindings/wasm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules/
*.wasm
**/dist/
limbo-wasm*tgz
claude.md
4 changes: 4 additions & 0 deletions bindings/wasm/examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { Database } from 'limbo-wasm';

const db = new Database('hello.db');

db.exec('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');

db.exec('INSERT INTO users (name) VALUES (\'Alice\')');

const stmt = db.prepare('SELECT * FROM users');

const users = stmt.all();
Expand Down
2 changes: 1 addition & 1 deletion bindings/wasm/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"dependencies": {
"better-sqlite3": "^11.5.0",
"drizzle-orm": "^0.36.3",
"limbo-wasm": "../pkg"
"limbo-wasm": "^0.0.12"
}
}
Loading

0 comments on commit 466bc8b

Please sign in to comment.