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

publish supersim on npm #174

Closed
roninjin10 opened this issue Sep 25, 2024 · 3 comments
Closed

publish supersim on npm #174

roninjin10 opened this issue Sep 25, 2024 · 3 comments

Comments

@roninjin10
Copy link

Feature

Publish the binaries on NPM

Why?

Publishing on NPM would allow users to use supersim with npx

npx supersim

Install with NPM

npm i --global supersim

Or list supersim as a subdependency in a package.json. This is my use case. I'm making a testing library called tevm test soon and I would like to enable interop support with supersim.

How

Adding a go binary to npm is straightforward. You need a package.json

{
  "name": "supersim",
  "version": "1.0.0",
  "description": "Example package.json",
  "bin": {
    "supersim": "./bin/supersim"
  },
  "scripts": {
    "postinstall": "node install.js"
  },
  "author": "Your Name",
  "license": "MIT"
}

And then you need a simple postinstall script. This install script simply downloads the correct binary based on the platform to bin/supersim.

// Detect platform and architecture
const platform = os.platform();
const arch = os.arch();
let fileName = '';

if (platform === 'darwin' && arch === 'arm64') fileName = 'supersim_Darwin_arm64.tar.gz';
else if (platform === 'darwin' && arch === 'x64') fileName = 'supersim_Darwin_x86_64.tar.gz';
else if (platform === 'linux' && arch === 'arm64') fileName = 'supersim_Linux_arm64.tar.gz';
else if (platform === 'linux' && arch === 'x64') fileName = 'supersim_Linux_x86_64.tar.gz';
else if (platform === 'win32' && arch === 'arm64') fileName = 'supersim_Windows_arm64.zip';
else if (platform === 'win32' && arch === 'x64') fileName = 'supersim_Windows_x86_64.zip';
else {
  console.error('Unsupported platform/architecture');
  process.exit(1);
}

const downloadUrl = `https://github.com/ethereum-optimism/supersim/releases/download/0.1.0-alpha.12/${fileName}`;
const outputPath = path.join(__dirname, 'bin', fileName);

// Create bin directory if it doesn't exist
if (!fs.existsSync(path.join(__dirname, 'bin'))) fs.mkdirSync(path.join(__dirname, 'bin'));

// Download the binary
https.get(downloadUrl, (response) => {
  const file = fs.createWriteStream(outputPath);
  response.pipe(file);
  file.on('finish', () => {
    file.close(() => {
      console.log(`Downloaded ${fileName}`);
      const extractCmd = fileName.endsWith('.tar.gz') ? `tar -xzf ${outputPath} -C ./bin` : `unzip ${outputPath} -d ./bin`;
      exec(extractCmd, (err) => {
        if (err) console.error('Extraction error:', err);
        else console.log('Extraction complete.');
      });
    });
  });
}).on('error', (err) => {
  console.error(`Download error: ${err.message}`);
  process.exit(1);
});
@nitaliano
Copy link
Contributor

I think this is a good idea we can add this package in the ecosystem repo. We'll let you know when we publish it.

@nitaliano
Copy link
Contributor

nitaliano commented Oct 1, 2024

@roninjin10
Copy link
Author

Wow that was fast!
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants