This guide explains how to package the PackDev library and install it locally for development and testing purposes using either npm or Yarn package managers.
- Node.js >= 16.0.0
- npm (comes with Node.js) OR Yarn package manager
The scripts automatically detect your preferred package manager:
- If
yarn.lockexists → uses Yarn - If
package-lock.jsonexists → uses npm - Fallback: checks which command is available
To build and package the library in one command:
With npm:
npm run packWith Yarn:
yarn packThis will:
- Build the TypeScript source code to JavaScript
- Create a tarball (
.tgzfile) - Display installation instructions for both package managers
If you prefer to run the steps manually:
With npm:
# Build the library
npm run build
# Create the package tarball
npm packWith Yarn:
# Build the library
yarn build
# Create the package tarball
yarn packWe provide two pack scripts:
- Node.js script (recommended):
npm run pack/yarn pack - Bash script (Unix/Linux/macOS):
npm run pack:bash/yarn pack:bash
The Node.js script is cross-platform, automatically detects your package manager, and provides colored output with detailed instructions for both npm and Yarn.
The generated tarball includes:
dist/- Compiled JavaScript and TypeScript declaration filespackage.json- Package metadataREADME.md- Project documentationLICENSE- License file (if present)
Files excluded from the package (as defined in .npmignore or package.json files field):
src/- TypeScript source filesnode_modules/- Dependenciestest/- Test files- Development configuration files
After running npm run pack or yarn pack, you'll get a file like packdev-1.0.0.tgz.
In another project with npm:
# Copy the tarball to your project directory first
npm install ./packdev-1.0.0.tgz
# Using absolute path
npm install /path/to/packdev/packdev-1.0.0.tgzIn another project with Yarn:
# Copy the tarball to your project directory first
yarn add file:./packdev-1.0.0.tgz
# Using absolute path
yarn add file:/path/to/packdev/packdev-1.0.0.tgzYou can install directly from the project directory without creating a tarball:
With npm:
npm install /path/to/packdevWith Yarn:
yarn add file:/path/to/packdevTo install the CLI tool globally:
With npm:
# From tarball
npm install -g ./packdev-1.0.0.tgz
# From directory
npm install -g /path/to/packdevWith Yarn:
# From tarball
yarn global add file:./packdev-1.0.0.tgz
# From directory
yarn global add file:/path/to/packdevAfter global installation, you can use the CLI from anywhere:
packdev --helpIn a project where you've installed packdev locally:
With npm:
# Test the CLI
npx packdev --help
# Or if installed globally
packdev --helpWith Yarn:
# Test the CLI
yarn packdev --help
# Or if installed globally
packdev --helpCreate a test file to verify the library can be imported:
// test-import.js
const packdev = require('packdev');
console.log('Successfully imported packdev');Run the test:
node test-import.jsWith npm:
npm uninstall packdevWith Yarn:
yarn remove packdevWith npm:
npm uninstall -g packdevWith Yarn:
yarn global remove packdev-
Permission Errors on Global Install
With npm:
# Use sudo on Unix/Linux/macOS (not recommended) sudo npm install -g ./packdev-1.0.0.tgz # Better: Configure npm to use a different directory npm config set prefix ~/.npm-global # Add ~/.npm-global/bin to your PATH
With Yarn:
# Yarn typically handles global installs better yarn global add file:./packdev-1.0.0.tgz # Check global directory yarn global dir
-
Build Errors
With npm:
# Clean and rebuild npm run clean npm run buildWith Yarn:
# Clean and rebuild yarn clean yarn build -
Package Not Found After Installation
- Verify the tarball was created successfully
- Check that the
mainfield inpackage.jsonpoints to the correct file - Ensure the
dist/directory contains the compiled files
Before installation, you can inspect the tarball contents:
# List contents without extracting
tar -tzf packdev-1.0.0.tgz
# Extract to temporary directory for inspection
mkdir temp-extract
tar -xzf packdev-1.0.0.tgz -C temp-extract
ls -la temp-extract/package/For active development with frequent testing:
- Make changes to the source code
- Test locally with
npm run devoryarn dev - Build and pack with
npm run packoryarn pack - Install in test project from tarball
- Test the installation
- Repeat as needed
You can set up a test project that automatically uses the latest build:
With npm:
# In your test project
npm install file:../path/to/packdev
# This will use the built version and update when you rebuildWith Yarn:
# In your test project
yarn add file:../path/to/packdev
# This will use the built version and update when you rebuildWhen ready to publish to the public npm registry:
With npm:
# Login to npm (one time setup)
npm login
# Publish (make sure to update version in package.json first)
npm publish
# Or for scoped packages
npm publish --access public
# Dry run first to see what would be published
npm publish --dry-runWith Yarn:
# Login to npm registry (Yarn uses npm registry)
yarn login
# Publish (make sure to update version in package.json first)
yarn publish
# Or for scoped packages
yarn publish --access publicRemember to:
- Update the version number in
package.json - Update the
CHANGELOG.mdor release notes - Test thoroughly before publishing
- Consider using dry-run first to see what would be published