@bobfrankston/npmglobalize
v1.0.70
Published
Transform file: dependencies to npm versions for publishing
Maintainers
Readme
npmglobalize
Transform file: dependencies to npm versions for publishing.
Overview
npmglobalize automates the workflow of publishing npm packages that use local file: references during development. It converts those references to proper npm versions, publishes everything in dependency order, and optionally restores the local references afterward.
Installation
npm install -g @bobfrankston/npmglobalizeBasic Usage
cd your-package
npmglobalize # Transform + publish (patch version)
npmglobalize --minor # Bump minor version
npmglobalize --major # Bump major version
# Or run from anywhere with a path
npmglobalize y:\path\to\your-packageKey Features
🔗 Automatic Dependency Publishing (Default)
By default, npmglobalize ensures all file: dependencies are published before converting them:
npmglobalize # Auto-publishes file: deps in correct orderIf you have:
lxtest
├── file:../lxlan-node
│ └── file:../lxland
└── file:../lxlandIt automatically:
- Publishes
lxland(root dependency) - Publishes
lxlan-node(depends on lxlan) - Converts and publishes
lxtest
Settings Propagation (Default Behavior):
When publishing file: dependencies, these settings are automatically inherited:
--update-deps/--update-major(update dependencies)--fix(run npm audit fix)--conform(fix .gitignore/.npmignore/.gitattributes and git config)--verbose/--quiet--force/--files
⚠️ Visibility Settings (Smart Inheritance):
--npmVisibilityis only inherited by NEW repositories (never published to npm before)- Existing repositories keep their current npm visibility (public/private) unchanged
--gitVisibilityis inherited by all dependencies
This ensures you can safely set --npmVisibility private as a default for new packages without accidentally changing the visibility of your existing published packages.
Why This Matters: Once a package is published to npm (public or private), changing its visibility later requires careful consideration. This smart inheritance protects your existing packages while making new ones default to safe settings.
Example - safely publish with new packages private by default:
npmglobalize --npmVisibility private
# ✓ Existing npm packages: keep their current visibility
# ✓ New packages (never published): default to private (safe!)
# ✓ Regular npm dependencies (express, etc.): unchangedExample with configuration file (recommended):
# In main package: create .globalize.json5 with "npmVisibility": "private"
npmglobalize
# ✓ Existing repos: publish with their current npm visibility
# ✓ Brand new repos: inherit private settingSkip auto-publishing (use with caution):
npmglobalize -npd # --no-publish-depsForce republish all file: dependencies even if versions exist:
npmglobalize --force-publish📦 Dependency Updates
Safe updates (minor/patch only, respects semver):
npmglobalize --update-depsexpress ^4.18.0→^4.21.0✓lodash ^4.17.0→^4.17.21✓- Won't update to
express ^5.0.0(breaking change)
Include major updates (breaking changes):
npmglobalize --update-major- Updates to latest including major versions
- Shows "(MAJOR)" indicator for breaking changes
Note: The --update-deps flag propagates to all file: dependencies, so one command updates your entire dependency tree.
🔒 Security Auditing
Check vulnerabilities:
npmglobalize # Shows audit at endAuto-fix vulnerabilities:
npmglobalize --fix # Runs npm audit fixDisable audit:
npmglobalize --no-fix🔄 File Reference Management
Default behavior (restore file: references after publish):
npmglobalize # Converts file: → npm, publishes, then restores file:Keep npm references permanently:
npmglobalize --nofiles # Don't restore file: referencesJust transform without publishing:
npmglobalize -np # --nopublish (formerly --apply)Restore from backup:
npmglobalize --cleanup # Restore original file: references🔧 Git Integration & Error Recovery
Automatic tag conflict resolution:
npmglobalize --fix-tags # Auto-fix version/tag mismatchesWhen a previous publish fails, git tags may conflict with package.json version. The --fix-tags option (or automatic detection) will clean up these conflicts.
Automatic rebase when local is behind remote:
npmglobalize --rebase # Auto-rebase if behind remoteFor single-developer projects, this safely pulls remote changes before publishing.
Note: This tool is designed for single-developer, single-branch workflows where automatic rebase and tag cleanup are safe operations.
📂 Git Repository Setup
When initializing a new repository with --init, npmglobalize automatically sets up:
File structure (per programming.md standards):
.gitignore- Node.js best practices (node_modules, secrets, certificates, etc.).npmignore- Publishing filters (excludes .git, tests, source files, etc.).gitattributes- Forces LF line endings for all text files
Git configuration (ensures cross-platform compatibility):
git config core.autocrlf false # Disable CRLF conversion
git config core.eol lf # Force LF line endingsThis ensures consistent line endings across Windows, macOS, and Linux, preventing "modified file" issues caused by line ending differences.
🔍 Understanding "Detached HEAD" Error
What is Detached HEAD?
Your git repository is not currently on a branch (like master or main). This happens when you:
- Check out a specific commit:
git checkout abc123 - Check out a tag:
git checkout v1.0.0 - Have some git operations leave you in this state
Why does it matter? Publishing requires being on a branch so commits and tags can be properly tracked in your repository history.
Common scenarios:
Just fixing files with
--conform:npmglobalize --conform # ✓ Files get fixed, then exits with helpful messageThe files are already updated! You don't need to run it again.
Want to publish (have commits to keep):
git checkout -B master # Moves master branch to current commit (merges) npmglobalize # Now works normallyThe
-Bflag moves your branch pointer to include the detached commits.Want to publish (no commits made, safe to discard):
git checkout master # Just switch back to branch npmglobalize # Now works normallyForce publish anyway (not recommended):
npmglobalize --force # Proceeds despite detached HEADWarning: Commits may be hard to track later.
Command Reference
Release Options
--patch Bump patch version (default: 1.0.0 → 1.0.1)
--minor Bump minor version (1.0.0 → 1.1.0)
--major Bump major version (1.0.0 → 2.0.0)
--nopublish, -np Just transform, don't publish
--cleanup Restore file: dependencies from backupDependency Options
--update-deps Update package.json to latest versions (safe: minor/patch)
--update-major Allow major version updates (breaking changes)
--no-publish-deps, -npd Skip auto-publishing file: dependencies
--force-publish Republish dependencies even if version exists
--fix Run npm audit fix after transformation
--no-fix Don't run npm auditInstall Options
--install, -i Install globally after publish (Windows)
--wsl Also install in WSLMode Options
--files Keep file: paths after publish (default)
--nofiles Keep npm versions permanentlyGit/npm Visibility
--git private Make git repo private (default)
--git public Make git repo public
--npm private Mark package private (skip publish) (default)
--npm public Publish to npmOther Options
--init Initialize git/npm if needed (creates .gitignore, .npmignore,
.gitattributes, and configures git for LF line endings)
--force Continue despite git errors
--dry-run Preview what would happen
--quiet Suppress npm warnings (default)
--verbose Show detailed output
--conform Update .gitignore/.npmignore/.gitattributes to best practices
and configure git for LF line endings (fixes existing repos)
--asis Skip ignore file checks
--fix-tags Automatically fix version/tag mismatches
--rebase Automatically rebase if local is behind remote
--help, -h Show help
--version, -v Show versionConfiguration File
Settings can be saved in .globalize.json5:
{
// npmglobalize configuration (JSON5 format)
"bump": "patch", // Version bump type
"install": true, // Auto-install globally
"wsl": false, // Also install in WSL
"fix": true, // Auto-run npm audit fix
"verbose": false, // Show detailed output
"gitVisibility": "private",
"npmVisibility": "public"
}Configuration persists across runs. CLI flags override config file.
Common Workflows
Standard Release
npmglobalize --install # Publish + install globallyRelease with Dependency Chain
cd my-app # Has file: deps
npmglobalize # Publishes all deps automaticallySafe Dependency Updates
npmglobalize --update-deps # Update to latest safe versionsSecurity Fixes
npmglobalize --fix # Fix vulnerabilities + releaseForce Update Everything
npmglobalize --force-publish --update-majorPreview Changes
npmglobalize --dry-run # See what would happenHow It Works
- Validates package.json and git status
- Updates dependencies (if
--update-deps) - Publishes file: dependencies (if needed)
- Backs up original file: references to
.dependencies - Converts
file:→ npm version references - Commits changes
- Bumps version (using npm version)
- Publishes to npm
- Pushes to git
- Installs globally (if
--install) - Restores file: references (if
--files, default) - Runs audit (shows security status)
Version Checking
When publishing file: dependencies, checks if each version exists on npm:
- ✅ Exists → Skip, use existing version
- ❌ Missing → Publish it first
- 🔄 Force → Use
--force-publishto republish
Examples
# Basic release
npmglobalize
# Run on a different project
npmglobalize y:\dev\myproject
# Auto-fix tag conflicts and rebase
npmglobalize --fix-tags --rebase
# Release with updates and security fixes
npmglobalize --update-deps --fix
# Just update package.json, don't publish
npmglobalize -np --update-deps
# Force republish all dependencies
npmglobalize --force-publish --update-major
# Release + install on Windows and WSL
npmglobalize --install --wsl
# Restore original file: references
npmglobalize --cleanup
# Preview what would happen
npmglobalize --dry-run --verboseAuthentication
Requires npm authentication:
npm loginCheck authentication:
npm whoamiDevelopment
Build Check
npmglobalize includes automatic build verification to ensure TypeScript files are compiled before execution. This prevents runtime errors from outdated JavaScript files.
How it works:
- When you run
npmglobalize, it automatically checks if.jsfiles are newer than their.tssources - If
.jsfiles are missing or outdated, execution stops with an error - The check is skipped if
noEmit: trueis set intsconfig.json
Building the project:
npm run build # Compile TypeScript files
npm run watch # Watch mode for development
npm run check # Manually verify build statusBypassing the check:
npmglobalize --force # Skip build check (not recommended)Error example:
❌ Error: TypeScript files not compiled
cli.js is older than cli.ts
Please run: npm run build
Or use --force to skip this checkThis ensures you never accidentally run outdated code when the TypeScript source has changed.
License
MIT
