@bobfrankston/npmglobalize 1.0.81 → 1.0.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -19
- package/cli.js +24 -35
- package/lib.d.ts +2 -0
- package/lib.js +10 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -224,29 +224,36 @@ Publishing requires being on a branch so commits and tags can be properly tracke
|
|
|
224
224
|
|
|
225
225
|
## Command Reference
|
|
226
226
|
|
|
227
|
+
<!-- NOTE: Keep this in sync with the --help output in cli.ts printHelp().
|
|
228
|
+
The README expands on options with examples and context;
|
|
229
|
+
cli.ts is the concise quick-reference. Update both when adding/changing flags. -->
|
|
230
|
+
|
|
227
231
|
### Release Options
|
|
228
232
|
```
|
|
229
|
-
--patch
|
|
230
|
-
--minor
|
|
231
|
-
--major
|
|
232
|
-
--nopublish, -np
|
|
233
|
-
--cleanup
|
|
233
|
+
--patch Bump patch version (default)
|
|
234
|
+
--minor Bump minor version
|
|
235
|
+
--major Bump major version
|
|
236
|
+
--nopublish, -np Just transform, don't publish
|
|
237
|
+
--cleanup Restore file: dependencies from backup
|
|
238
|
+
-m, --message <msg> Custom commit message (forces release even without changes)
|
|
234
239
|
```
|
|
235
240
|
|
|
236
241
|
### Dependency Options
|
|
237
242
|
```
|
|
238
|
-
--update-deps
|
|
239
|
-
--update-major
|
|
240
|
-
--no-publish-deps, -npd
|
|
241
|
-
--force-publish
|
|
242
|
-
--fix
|
|
243
|
-
--no-fix
|
|
243
|
+
--update-deps, -ud Update package.json to latest versions (safe: minor/patch)
|
|
244
|
+
--update-major Allow major version updates (breaking changes)
|
|
245
|
+
--no-publish-deps, -npd Skip auto-publishing file: dependencies
|
|
246
|
+
--force-publish Republish dependencies even if version exists
|
|
247
|
+
--fix Run npm audit fix after transformation
|
|
248
|
+
--no-fix Don't run npm audit
|
|
244
249
|
```
|
|
245
250
|
|
|
246
251
|
### Install Options
|
|
247
252
|
```
|
|
248
|
-
--install, -i Install globally after publish (
|
|
253
|
+
--install, -i Install globally after publish (from registry)
|
|
254
|
+
--link Install globally via symlink (npm install -g .)
|
|
249
255
|
--wsl Also install in WSL
|
|
256
|
+
--once Don't persist flags to .globalize.json5
|
|
250
257
|
```
|
|
251
258
|
|
|
252
259
|
### Mode Options
|
|
@@ -258,14 +265,23 @@ Publishing requires being on a branch so commits and tags can be properly tracke
|
|
|
258
265
|
### Git/npm Visibility
|
|
259
266
|
```
|
|
260
267
|
--git private Make git repo private (default)
|
|
261
|
-
--git public Make git repo public
|
|
262
|
-
--npm private Mark package private (skip publish) (default)
|
|
268
|
+
--git public Make git repo public (requires confirmation)
|
|
269
|
+
--npm private Mark npm package private (skip publish) (default)
|
|
263
270
|
--npm public Publish to npm
|
|
264
271
|
```
|
|
265
272
|
|
|
273
|
+
### Workspace Options
|
|
274
|
+
```
|
|
275
|
+
-w, --workspace <pkg> Filter to specific package (repeatable)
|
|
276
|
+
--no-workspace Disable workspace mode at a workspace root
|
|
277
|
+
--continue-on-error Continue if a package fails in workspace mode
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
Workspace mode is auto-detected when run from a root with `"private": true` and a `workspaces` field.
|
|
281
|
+
|
|
266
282
|
### Other Options
|
|
267
283
|
```
|
|
268
|
-
--init Initialize git/npm if needed (creates .gitignore, .npmignore,
|
|
284
|
+
--init Initialize git/npm if needed (creates .gitignore, .npmignore,
|
|
269
285
|
.gitattributes, and configures git for LF line endings)
|
|
270
286
|
--force Continue despite git errors
|
|
271
287
|
--dry-run Preview what would happen
|
|
@@ -273,13 +289,41 @@ Publishing requires being on a branch so commits and tags can be properly tracke
|
|
|
273
289
|
--verbose Show detailed output
|
|
274
290
|
--conform Update .gitignore/.npmignore/.gitattributes to best practices
|
|
275
291
|
and configure git for LF line endings (fixes existing repos)
|
|
276
|
-
--asis Skip ignore file checks
|
|
292
|
+
--asis Skip ignore file checks (or set "asis": true in .globalize.json5)
|
|
277
293
|
--fix-tags Automatically fix version/tag mismatches
|
|
278
294
|
--rebase Automatically rebase if local is behind remote
|
|
279
|
-
--
|
|
280
|
-
--
|
|
295
|
+
--show Show package.json dependency changes
|
|
296
|
+
--package, -pkg Update package.json scripts to use npmglobalize (see below)
|
|
297
|
+
-h, --help Show help
|
|
298
|
+
-v, --version Show version
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
## Using in package.json
|
|
302
|
+
|
|
303
|
+
You can wire npmglobalize into your package.json `scripts` so that `npm run release` handles publishing:
|
|
304
|
+
|
|
305
|
+
```json
|
|
306
|
+
{
|
|
307
|
+
"scripts": {
|
|
308
|
+
"release": "npmglobalize"
|
|
309
|
+
}
|
|
310
|
+
}
|
|
281
311
|
```
|
|
282
312
|
|
|
313
|
+
The `--package` (`-pkg`) flag does this automatically — it adds a `release` script (renaming any existing `release`/`installer` scripts to `old-release`/`old-installer`):
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
npmglobalize --package # Sets up "release": "npmglobalize" in package.json
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
After that, publishing is just:
|
|
320
|
+
```bash
|
|
321
|
+
npm run release # Same as running npmglobalize directly
|
|
322
|
+
npm run release -- --minor # Pass flags through
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
You can also combine it with `.globalize.json5` for persistent options so `npm run release` always uses your preferred settings (install, visibility, etc.).
|
|
326
|
+
|
|
283
327
|
## Configuration File
|
|
284
328
|
|
|
285
329
|
Settings can be saved in `.globalize.json5`:
|
|
@@ -375,12 +419,21 @@ npmglobalize -np --update-deps
|
|
|
375
419
|
# Force republish all dependencies
|
|
376
420
|
npmglobalize --force-publish --update-major
|
|
377
421
|
|
|
378
|
-
# Release + install on Windows and WSL
|
|
422
|
+
# Release + install on Windows and WSL (from registry)
|
|
379
423
|
npmglobalize --install --wsl
|
|
380
424
|
|
|
425
|
+
# Release + link on Windows and WSL (symlink)
|
|
426
|
+
npmglobalize --link --wsl
|
|
427
|
+
|
|
381
428
|
# Restore original file: references
|
|
382
429
|
npmglobalize --cleanup
|
|
383
430
|
|
|
431
|
+
# Initialize new git repo + release
|
|
432
|
+
npmglobalize --init
|
|
433
|
+
|
|
434
|
+
# Migrate package.json scripts to use npmglobalize
|
|
435
|
+
npmglobalize --package
|
|
436
|
+
|
|
384
437
|
# Preview what would happen
|
|
385
438
|
npmglobalize --dry-run --verbose
|
|
386
439
|
```
|
package/cli.js
CHANGED
|
@@ -295,6 +295,10 @@ function parseArgs(args) {
|
|
|
295
295
|
return options;
|
|
296
296
|
}
|
|
297
297
|
export async function main() {
|
|
298
|
+
// Show version at the very start
|
|
299
|
+
const ownPkgPath = path.join(__dirname, 'package.json');
|
|
300
|
+
const ownPkg = JSON.parse(fs.readFileSync(ownPkgPath, 'utf-8'));
|
|
301
|
+
console.log(styleText('cyan', `npmglobalize v${ownPkg.version}`));
|
|
298
302
|
const args = process.argv.slice(2);
|
|
299
303
|
const cliOptions = parseArgs(args);
|
|
300
304
|
if (cliOptions.help) {
|
|
@@ -302,9 +306,7 @@ export async function main() {
|
|
|
302
306
|
process.exit(0);
|
|
303
307
|
}
|
|
304
308
|
if (cliOptions.version) {
|
|
305
|
-
|
|
306
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
|
|
307
|
-
console.log(pkg.version);
|
|
309
|
+
// Already printed above, just exit
|
|
308
310
|
process.exit(0);
|
|
309
311
|
}
|
|
310
312
|
if (cliOptions.error) {
|
|
@@ -325,48 +327,35 @@ export async function main() {
|
|
|
325
327
|
process.exit(1);
|
|
326
328
|
}
|
|
327
329
|
}
|
|
328
|
-
//
|
|
329
|
-
if (!cliOptions.
|
|
330
|
-
let
|
|
330
|
+
// Build the target project if it has a build script and tsconfig (not noEmit)
|
|
331
|
+
if (!cliOptions.cleanup) {
|
|
332
|
+
let shouldBuild = false;
|
|
331
333
|
try {
|
|
332
334
|
const tsconfigPath = path.join(cwd, 'tsconfig.json');
|
|
333
335
|
const content = fs.readFileSync(tsconfigPath, 'utf-8');
|
|
334
336
|
const tsconfig = JSON5.parse(content);
|
|
335
|
-
|
|
337
|
+
shouldBuild = tsconfig.compilerOptions?.noEmit !== true;
|
|
336
338
|
}
|
|
337
339
|
catch (error) {
|
|
338
|
-
// No tsconfig
|
|
339
|
-
noEmit = true;
|
|
340
|
+
// No tsconfig — skip build
|
|
340
341
|
}
|
|
341
|
-
if (
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
342
|
+
if (shouldBuild) {
|
|
343
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf-8'));
|
|
344
|
+
if (pkg.scripts?.build) {
|
|
345
|
+
const { execSync } = await import('child_process');
|
|
346
|
+
try {
|
|
347
|
+
console.log(`Building ${cwd}...`);
|
|
348
|
+
execSync('npm run build', { cwd, stdio: 'inherit' });
|
|
349
|
+
console.log(styleText('green', '✓ Build succeeded'));
|
|
350
|
+
}
|
|
351
|
+
catch (error) {
|
|
352
|
+
console.error(styleText('red', `Build failed in ${cwd}`));
|
|
353
|
+
if (!cliOptions.force) {
|
|
354
|
+
process.exit(1);
|
|
353
355
|
}
|
|
356
|
+
console.log(styleText('yellow', 'Continuing with --force...'));
|
|
354
357
|
}
|
|
355
358
|
}
|
|
356
|
-
if (outOfSync.length > 0) {
|
|
357
|
-
console.error('\n' + styleText('red', '❌ Build check failed:'));
|
|
358
|
-
console.error(styleText('red', ` ${outOfSync.length} file(s) need compilation in ${cwd}:`));
|
|
359
|
-
outOfSync.forEach(f => {
|
|
360
|
-
const tsPath = path.join(cwd, f);
|
|
361
|
-
const jsPath = path.join(cwd, f.replace('.ts', '.js'));
|
|
362
|
-
const fmt = (d) => d.toLocaleString();
|
|
363
|
-
console.error(styleText('red', ` - ${f}`));
|
|
364
|
-
console.error(styleText('red', ` .ts: ${fmt(fs.statSync(tsPath).mtime)} .js: ${fmt(fs.statSync(jsPath).mtime)}`));
|
|
365
|
-
});
|
|
366
|
-
console.error('\n' + styleText('yellow', ' Please run: tsc'));
|
|
367
|
-
console.error(styleText('yellow', ' Or use --force to skip this check') + '\n');
|
|
368
|
-
process.exit(1);
|
|
369
|
-
}
|
|
370
359
|
}
|
|
371
360
|
}
|
|
372
361
|
// Handle --package: update scripts in target package.json
|
package/lib.d.ts
CHANGED
|
@@ -73,6 +73,8 @@ export interface GlobalizeOptions {
|
|
|
73
73
|
once?: boolean;
|
|
74
74
|
/** Internal: signals this call is from workspace orchestrator */
|
|
75
75
|
_fromWorkspace?: boolean;
|
|
76
|
+
/** Internal: signals this call is from CLI (version already printed) */
|
|
77
|
+
_fromCli?: boolean;
|
|
76
78
|
}
|
|
77
79
|
/** Result from a single package in workspace mode */
|
|
78
80
|
interface WorkspacePackageResult {
|
package/lib.js
CHANGED
|
@@ -23,6 +23,7 @@ const colors = {
|
|
|
23
23
|
yellow: (text) => styleText('yellow', text),
|
|
24
24
|
green: (text) => styleText('green', text),
|
|
25
25
|
italic: (text) => styleText('italic', text),
|
|
26
|
+
blue: (text) => styleText('blue', text),
|
|
26
27
|
dim: (text) => styleText('dim', text),
|
|
27
28
|
};
|
|
28
29
|
/**
|
|
@@ -541,6 +542,7 @@ export function transformDeps(pkg, baseDir, verbose = false, forcePublish = fals
|
|
|
541
542
|
for (const [name, value] of Object.entries(pkg[key])) {
|
|
542
543
|
if (isFileRef(value)) {
|
|
543
544
|
const targetPath = resolveFilePath(value, baseDir);
|
|
545
|
+
console.log(colors.blue(` + ${name} → ${value}`));
|
|
544
546
|
try {
|
|
545
547
|
const targetPkg = readPackageJson(targetPath);
|
|
546
548
|
const targetVersion = targetPkg.version;
|
|
@@ -744,9 +746,8 @@ function waitForNpmVersion(pkgName, version, maxWaitMs = 60000) {
|
|
|
744
746
|
export function runCommand(cmd, args, options = {}) {
|
|
745
747
|
const { silent = false, cwd } = options;
|
|
746
748
|
try {
|
|
747
|
-
//
|
|
748
|
-
|
|
749
|
-
const needsShell = cmd === 'npm' || cmd === 'npm.cmd';
|
|
749
|
+
// Use shell:true for npm/gh commands which need it on Windows
|
|
750
|
+
const needsShell = cmd === 'npm' || cmd === 'npm.cmd' || cmd === 'gh';
|
|
750
751
|
// Debug: log the command being executed
|
|
751
752
|
if (!silent) {
|
|
752
753
|
console.log(colors.dim(`[DEBUG] Running: ${cmd} ${args.join(' ')}`));
|
|
@@ -803,13 +804,13 @@ function getGitHubRepo(pkg) {
|
|
|
803
804
|
}
|
|
804
805
|
/** Run a command and throw on failure */
|
|
805
806
|
export function runCommandOrThrow(cmd, args, options = {}) {
|
|
806
|
-
|
|
807
|
-
const captureOptions = { ...options, silent: true };
|
|
807
|
+
const needsShell = cmd === 'npm' || cmd === 'npm.cmd' || cmd === 'gh';
|
|
808
808
|
const result = spawnSync(cmd, args, {
|
|
809
809
|
encoding: 'utf-8',
|
|
810
810
|
stdio: 'pipe',
|
|
811
|
-
cwd:
|
|
812
|
-
|
|
811
|
+
cwd: options.cwd,
|
|
812
|
+
env: process.env,
|
|
813
|
+
shell: needsShell
|
|
813
814
|
});
|
|
814
815
|
const stdout = result.stdout || '';
|
|
815
816
|
const stderr = result.stderr || '';
|
|
@@ -1419,9 +1420,9 @@ export function getToolVersion() {
|
|
|
1419
1420
|
export async function globalize(cwd, options = {}, configOptions = {}) {
|
|
1420
1421
|
const { bump = 'patch', noPublish = false, cleanup = false, install = false, link = false, wsl = false, force = false, files = true, dryRun = false, quiet = true, verbose = false, init = false, gitVisibility = 'private', npmVisibility = 'private', message, conform = false, asis = false, updateDeps = false, updateMajor = false, publishDeps = true, // Default to publishing deps for safety
|
|
1421
1422
|
forcePublish = false, fix = false, fixTags = false, rebase = false, show = false } = options;
|
|
1422
|
-
// Show tool version (
|
|
1423
|
+
// Show tool version only for recursive dep calls (CLI already prints it at startup)
|
|
1423
1424
|
const toolVersion = getToolVersion();
|
|
1424
|
-
if (!options._fromWorkspace) {
|
|
1425
|
+
if (!options._fromWorkspace && !options._fromCli) {
|
|
1425
1426
|
console.log(colors.italic(`npmglobalize v${toolVersion}`));
|
|
1426
1427
|
}
|
|
1427
1428
|
// Show settings from .globalize.json5 if any
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bobfrankston/npmglobalize",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.83",
|
|
4
4
|
"description": "Transform file: dependencies to npm versions for publishing",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc",
|
|
12
12
|
"watch": "tsc -w",
|
|
13
|
-
"
|
|
13
|
+
"prepare": "npm run build",
|
|
14
14
|
"check-links": "node check-links.js"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|