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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@3xpo/pkgmetatool

v0.1.9

Published

No Package Description Yet

Downloads

15

Readme

@3xpo/pkgmetatool

Simple tool for managing package metadata.

Installation

pnpm i -D @3xpo/pkgmetatool

Usage

This is an example of usage within nx:

#!/usr/bin/env node

import { processPackage } from '@3xpo/pkgmetatool';
import fs from 'fs';
import path from 'path';
import process from 'process';
import { execSync } from 'child_process';

const monorepoRoot = process.cwd();

const packages = execSync('nx exec -- pwd')
  .toString()
  .split('\n')
  .map(x => x.trim())
  .filter(x => x.length > 0 && fs.existsSync(x))
  .map(x => path.relative(monorepoRoot, x));

packages.forEach(pkg => {
  const pkgPath = path.join(monorepoRoot, pkg, 'package.json');
  const pkgJson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
  fs.writeFileSync(
    pkgPath,
    JSON.stringify(
      processPackage(
        // the inputted package.json object:
        pkgJson,
        // the options object:
        {
          path: pkg, // this will set the repository's relative path properly
          license: 'MIT', // this will ensure that this license is used if there is no license field
          author: 'Expo', // this will ensure that this author is used if there is no author field
          repository: 'https://codeberg.org/Expo/example-repo.git', // this will ensure that this repository is used
          bugs: {
            url: 'AUTO', // this will ensure that the bugs.url field is set to the repository's issues page - only works on codeberg; specify a url elsewhere
            email: '[email protected]', // this will ensure that the bugs.email field is set to this email
          },
          ensureExports: true, // this will ensure that the exports field is present and is in the correct order
          fallbackTypings: true, // this will ensure that the typings field is set to the value of the types field if it is missing, and vice-versa
          sort: true, // this will ensure that the package.json keys are sorted - if you want to specify a custom sorting array, pass it here
        },
      ),
      null,
      2,
    ) + '\n',
  );
});

This is an example of usage within a non-monorepo project:

import { processPackage } from '@3xpo/pkgmetatool';
import fs from 'fs';

const pkgPath = 'path/to/package.json';
const pkgJson = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
fs.writeFileSync(
  pkgPath,
  JSON.stringify(
    processPackage(
      // the inputted package.json object:
      pkgJson,
      // the above options object would go here, with `path` omitted
      {},
    ),
    null,
    2,
  ) + '\n',
);