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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@sonarly/sourcemap-uploader

v1.0.2

Published

CLI tool to upload sourcemaps to Sonarly for JavaScript error deobfuscation

Readme

@sonarly/sourcemap-uploader

Upload JavaScript sourcemaps to Sonarly for error deobfuscation in session replays.

Installation

npm install @sonarly/sourcemap-uploader --save-dev

Quick Start

CLI Usage

npx @sonarly/sourcemap-uploader \
  -k YOUR_API_KEY \
  -p YOUR_PROJECT_KEY \
  -m ./dist/assets \
  -u https://myapp.com/assets

Package.json Integration

Add to your package.json:

{
  "scripts": {
    "build": "vite build",
    "postbuild": "sourcemap-uploader -k $SONARLY_API_KEY -p $SONARLY_PROJECT_KEY -m dist/assets -u https://myapp.com/assets"
  }
}

Environment Variables

Instead of CLI arguments, you can use environment variables:

export SONARLY_API_KEY=sk_your_api_key
export SONARLY_PROJECT_KEY=your_project_key
export SONARLY_SERVER=https://sonarly.dev
export PUBLIC_URL=https://myapp.com/assets

npx @sonarly/sourcemap-uploader -m ./dist/assets

CLI Options

| Option | Env Variable | Description | |--------|--------------|-------------| | -k, --api-key | SONARLY_API_KEY | Your Sonarly API key (required) | | -p, --project-key | SONARLY_PROJECT_KEY | Your Sonarly project key (required) | | -s, --server | SONARLY_SERVER | Sonarly server URL (default: https://sonarly.dev) | | -m, --sourcemaps-dir | - | Directory containing .js and .map files (required) | | -u, --public-url | PUBLIC_URL | Public URL where JS files are served (required) | | -v, --verbose | - | Enable verbose logging | | -d, --delete | - | Delete .map files after upload |

Programmatic Usage

const uploadSourcemaps = require('@sonarly/sourcemap-uploader');
const fs = require('fs');

const sourcemaps = [
  {
    js_file_url: 'https://myapp.com/assets/main.abc123.js',
    body: JSON.parse(fs.readFileSync('./dist/assets/main.abc123.js.map', 'utf8'))
  },
  {
    js_file_url: 'https://myapp.com/assets/vendor.def456.js',
    body: JSON.parse(fs.readFileSync('./dist/assets/vendor.def456.js.map', 'utf8'))
  }
];

uploadSourcemaps(
  'sk_your_api_key',
  'your_project_key',
  sourcemaps,
  'https://sonarly.dev'
)
  .then((uploadedUrls) => {
    console.log('Uploaded:', uploadedUrls);
  })
  .catch((error) => {
    console.error('Failed:', error);
  });

Framework Examples

Vite

// vite.config.js
import { defineConfig } from 'vite';
import { exec } from 'child_process';
import { promisify } from 'util';

const execAsync = promisify(exec);

export default defineConfig({
  build: {
    sourcemap: true, // Required!
  },
  plugins: [
    {
      name: 'upload-sourcemaps',
      async closeBundle() {
        if (process.env.NODE_ENV === 'production') {
          await execAsync('npx @sonarly/sourcemap-uploader -m dist/assets -u https://myapp.com/assets');
        }
      }
    }
  ]
});

Create React App

{
  "scripts": {
    "build": "GENERATE_SOURCEMAP=true react-scripts build && npm run upload-sourcemaps",
    "upload-sourcemaps": "sourcemap-uploader -m build/static/js -u https://myapp.com/static/js"
  }
}

Next.js

// next.config.js
module.exports = {
  productionBrowserSourceMaps: true,
  // Add a postbuild script in package.json
};

Getting Your API Key

  1. Go to your Sonarly dashboard
  2. Navigate to Settings → API Keys
  3. Create a new API key with "sourcemaps" permission

Security

  • Never commit your API key to version control
  • Use environment variables or CI/CD secrets
  • Consider using -d flag to delete .map files after upload (prevents exposing source code)

Troubleshooting

"Authorization rejected"

  • Check your API key is correct
  • Ensure the API key has "sourcemaps" permission
  • Verify the project key matches your project

"Server Error"

  • Check the server URL is correct
  • Ensure your network can reach the Sonarly server
  • Use -v flag to see detailed error messages

"No sourcemap files found"

  • Ensure your build generates .map files
  • Check the directory path is correct
  • Vite: Set build.sourcemap: true
  • CRA: Set GENERATE_SOURCEMAP=true

License

MIT