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

@halqor/makedist

v0.2.1

Published

A tool for creating distributable packages

Downloads

5

Readme

Makedist

Makedist helps developers and administrators prepare a package containing their source code or distributable binary.

It's written in JavaScript but is intended for (eventually) helping to package anything.

Currently on JavaScript projects with package.json are supported.

Installation

To install Makedist:

npm install -g @halqor/makedist

Usage

To package a NodeJS project with only production dependencies:

cd project_dir
makedist

When successful, the output is a single line with the path to the output file. For example:

makedist/package.tgz

Change source directory

Instead of looking for package.json in the current directory, you can look in another directory:

makedist --src /path/to/project_dir

Change output directory

Instead of creating an output directory ./makedist, you can choose any other location instead:

makedist --out /tmp/makedist

Change package file name

Instead of creating an output file package.tgz in the output directory, you can name it whatever you like:

makedist --name example.tgz

Select preset

The files and packageInfo options aren't available directly via the command line, but there are a few presets you can select for these.

For example:

makedist --preset script
makedist --preset library
makedist --preset website

library

Sets the dependencies option to true (unless you override it with --no-dependencies).

Includes dependencies, type, main, and engines top-level properties from package.json.

script

Sets the dependencies option to true (unless you override it with --no-dependencies).

Includes dependencies, type, bin, and engines top-level properties from package.json.

website

Sets the dependencies option to false (unless you override it with --dependencies).

Does not include additional top-level properties from package.json.

Show verbose messages

If you need to see more details about what is happening, use the verbose flag:

makedist --verbose
makedist -v

Configuration

When an option can be defined in multiple places, the following priority order is used:

  1. Command line arguments (override configuration)
  2. Export from makedist.config.mjs or makedist.config.cjs (can actually read makedist from package.json and then override it)
  3. Content of package.json in the 'makedist' section
  4. Built-in defaults (package name is 'package', output directory is 'makedist')

However, not all settings can be defined in all these places.

The following options can ONLY be set via the command line:

  • --src
  • --verbose or -v

The following options can ONLY be set via the configuration file:

  • files (which files to copy into the package; overrides the top-level files section from package.json)
  • packageInfo (which top-level attributes of package.json to copy into the package)

makedist.config.js

Makedist looks for a file named makedist.config.mjs or makedist.config.cjs or makedist.config.js in the source directory, in that order. Only the first one found is imported.

If you use makedist.config.js, the content can be ESM or CommonJS, and MUST match your project settings in package.json (default is CommonJS if not specified).

The file should export the configuration settings that should be set.

You can export static values, or you can run some JavaScript code before exporting.

Here is an example makedist.config.mjs that sets a static package name:

const name = 'makedist';
export { name };

Here is the same functionality but in 'makedist.config.cjs`:

const name = 'makedist';
module.exports = { name };

Here is an example makedist.config.mjs that sets a dynamic package name based on the name and version fields in package.json:

import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

const thisFilePath = fileURLToPath(import.meta.url);
const packageJsonFile = path.resolve(path.dirname(thisFilePath), 'package.json');
const packageJsonFileContent = fs.readFileSync(packageJsonFile, 'utf-8');
const pkg = JSON.parse(packageJsonFileContent);

let packageName = pkg.name ?? 'unknown';
if (pkg.name.indexOf('/') > -1) {
    [, packageName] = pkg.name.split('/');
}
let packageVersion = pkg.version ?? '0.0.0';

const name = `${packageName}-${packageVersion}`;

export { name };

Here is the same functionality but in makedist.config.cjs:

const fs = require('fs');
const path = require('path');

const packageJsonFile = path.resolve(path.dirname(__filename), 'package.json');
const packageJsonFileContent = fs.readFileSync(packageJsonFile, 'utf-8');
const pkg = JSON.parse(packageJsonFileContent);

let packageName = pkg.name ?? 'unknown';
if (pkg.name.indexOf('/') > -1) {
    [, packageName] = pkg.name.split('/');
}
let packageVersion = pkg.version ?? '0.0.0';

const name = `${packageName}-${packageVersion}`;

module.exports = { name };

package.json

Here is an example package.json that sets a static package name:

{
    "name": "@halqor/makedist",
    "version": "0.1.2",
    "makedist": {
        "name": "makedist-0.1.2"
    }
}

Project types

NodeJS

By default, makedist will create a makedist/package directory containing a copy of each file and directory mentioned in the files section of package.json, and also a makedist/package/node_modules directory containing only the packages mentioned in the dependencies section of package.json (and not in the devDependencies), then it will create an output file makedist/package.tgz with the content of the makedist/package directory.