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

Can't install node-sdl using bun. But can run a script using bun if I install with npm #9220

Closed
pedroth opened this issue Mar 3, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@pedroth
Copy link

pedroth commented Mar 3, 2024

What version of Bun is running?

1.0.28+705638470

What platform is your computer?

Linux 6.5.0-21-generic x86_64 x86_64

What steps can reproduce the bug?

package.json:

{
  "name": "sdl",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@kmamal/sdl": "^0.10.2"
  }
}
// index.js
import sdl from '@kmamal/sdl'

// Setup
const window = sdl.video.createWindow({ title: "Canvas" })
// window.setFullscreen(true);
const { pixelWidth: width, pixelHeight: height } = window
const buffer = Buffer.alloc(width * height * 4).fill(0);

const play = async ({ time, oldT }) => {
    const newT = new Date().getTime();
    const dt = (newT - oldT) * 1e-3;
    console.log(`FPS:${Math.floor(1 / dt)}`);
    for (let n = 0; n < buffer.length; n += 4) {
        const i = Math.floor(n / (4 * width));
        const j = Math.floor((n / 4) % width);
        const x = j;
        const y = height - 1 - i;
        const px = x / width;
        const py = y / height;
        buffer[n] = Math.min(255, ((px * time) % 1) * 255);
        buffer[n + 1] = Math.min(255, ((py * time) % 1) * 255);
        buffer[n + 2] = 0;
        buffer[n + 3] = 255;
    }
    window.render(width, height, width * 4, 'rgba32', buffer);
    setTimeout(() => play({
        oldT: newT,
        time: time + dt,
    }));
}
setTimeout(() => play({ oldT: new Date().getTime(), time: 0 }))

Then just run bun i and bun index.js

What is the expected behavior?

It should run index.js

What do you see instead?

error: Cannot find module "../../dist/sdl.node" from "/home/pedroth/Desktop/test/sdl/node_modules/@kmamal/sdl/src/javascript/bindings.js"

Additional information

If I install it with npm (running npm i) and then run bun index.js, it will run!

@pedroth pedroth added the bug Something isn't working label Mar 3, 2024
@dylan-conway
Copy link
Member

Bun install won't run lifecycle scripts unless they are in trustedDependencies or the default trusted dependencies list. Adding @kmamal/sdl to trustedDependencies and installing again fixes this issue. https://bun.sh/docs/install/lifecycle#trusteddependencies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants