@bobfrankston/npmglobalize 1.0.93 → 1.0.95

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.
Files changed (2) hide show
  1. package/lib.js +26 -18
  2. package/package.json +1 -1
package/lib.js CHANGED
@@ -1595,26 +1595,24 @@ export function getToolVersion() {
1595
1595
  return 'unknown';
1596
1596
  }
1597
1597
  }
1598
- /** Offer to add a bin field if missing — returns true if bin was added or already existed */
1598
+ /** Offer to add a bin field if missing — returns true if bin was added, false to skip/abort */
1599
1599
  async function offerAddBin(cwd, pkg) {
1600
1600
  if (pkg.bin)
1601
1601
  return true;
1602
1602
  // Determine likely entry point
1603
1603
  const mainFile = pkg.main || 'index.js';
1604
1604
  const cmdName = (pkg.name || path.basename(cwd)).replace(/^@[^/]+\//, '');
1605
- console.log(colors.yellow('No bin field — this package won\'t install as a CLI command.'));
1606
- const choice = await promptChoice(`Add bin field to make it a CLI tool?\n 1) Yes, use "${cmdName}" → "${mainFile}" (default)\n 2) No, install as library link\n 3) Abort\nChoice:`, ['1', '2', '3', '']);
1607
- if (choice === '3')
1608
- return false;
1609
- if (choice === '2') {
1610
- console.log(colors.dim('Installing as library link (no bin)...'));
1605
+ console.log(colors.yellow('No bin field — this is a library, not a CLI tool.'));
1606
+ console.log(colors.yellow('Libraries should not be installed globally. Use npm install <name> in projects instead.'));
1607
+ const choice = await promptChoice(`Add bin field to make it a CLI tool?\n 1) Yes, use "${cmdName}" → "${mainFile}"\n 2) Skip global install (default)\nChoice:`, ['1', '2', '']);
1608
+ if (choice === '1') {
1609
+ pkg.bin = { [cmdName]: mainFile };
1610
+ writePackageJson(cwd, pkg);
1611
+ console.log(colors.green(`✓ Added bin: { "${cmdName}": "${mainFile}" }`));
1611
1612
  return true;
1612
1613
  }
1613
- // choice is '1' or '' (default)
1614
- pkg.bin = { [cmdName]: mainFile };
1615
- writePackageJson(cwd, pkg);
1616
- console.log(colors.green(`✓ Added bin: { "${cmdName}": "${mainFile}" }`));
1617
- return true;
1614
+ // choice is '2' or '' (default) — skip
1615
+ return false;
1618
1616
  }
1619
1617
  /** Perform local-only install (npm install -g .) — extracted for reuse from git-init prompts */
1620
1618
  async function doLocalInstall(cwd, options) {
@@ -1626,8 +1624,11 @@ async function doLocalInstall(cwd, options) {
1626
1624
  console.log(colors.dim('Skipping transform/publish — installing with file: deps as-is'));
1627
1625
  if (!pkg.bin) {
1628
1626
  const proceed = await offerAddBin(cwd, pkg);
1629
- if (!proceed)
1630
- return false;
1627
+ if (!proceed) {
1628
+ console.log(colors.yellow('Skipping global install — library packages should not be installed globally.'));
1629
+ console.log(colors.yellow(`To use in projects: npm install ${pkgName}`));
1630
+ return true;
1631
+ }
1631
1632
  }
1632
1633
  if (dryRun) {
1633
1634
  console.log(' [dry-run] Would run: npm install -g .');
@@ -1729,8 +1730,11 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
1729
1730
  console.log(colors.dim('Skipping transform/publish — installing with file: deps as-is'));
1730
1731
  if (!pkg.bin) {
1731
1732
  const proceed = await offerAddBin(cwd, pkg);
1732
- if (!proceed)
1733
- return false;
1733
+ if (!proceed) {
1734
+ console.log(colors.yellow('Skipping global install — library packages should not be installed globally.'));
1735
+ console.log(colors.yellow(`To use in projects: npm install ${pkgName}`));
1736
+ return true;
1737
+ }
1734
1738
  }
1735
1739
  if (dryRun) {
1736
1740
  console.log(' [dry-run] Would run: npm install -g .');
@@ -2044,8 +2048,8 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
2044
2048
  console.log(colors.yellow('Continuing with --force despite errors...'));
2045
2049
  }
2046
2050
  // Check npm visibility and current publication status
2047
- const currentAccess = checkNpmAccess(pkg.name);
2048
- const isScoped = pkg.name.startsWith('@');
2051
+ let currentAccess = checkNpmAccess(pkg.name);
2052
+ let isScoped = pkg.name.startsWith('@');
2049
2053
  // Check if public intent was explicitly declared anywhere:
2050
2054
  // CLI (--npm public), config file (.globalize.json5), or package.json publishConfig
2051
2055
  const npmVisibilityExplicitlySet = 'npmVisibility' in options
@@ -2102,6 +2106,8 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
2102
2106
  const normalizedScope = scope.startsWith('@') ? scope : `@${scope}`;
2103
2107
  const newName = `${normalizedScope}/${pkg.name}`;
2104
2108
  pkg.name = newName;
2109
+ isScoped = true;
2110
+ currentAccess = checkNpmAccess(newName);
2105
2111
  writePackageJson(cwd, pkg);
2106
2112
  console.log(colors.green(`✓ Renamed package to ${newName}`));
2107
2113
  // Save scope to .userconfig if not already there
@@ -2185,6 +2191,8 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
2185
2191
  const normalizedScope = scope.startsWith('@') ? scope : `@${scope}`;
2186
2192
  const newName = `${normalizedScope}/${pkg.name}`;
2187
2193
  pkg.name = newName;
2194
+ isScoped = true;
2195
+ currentAccess = checkNpmAccess(newName);
2188
2196
  writePackageJson(cwd, pkg);
2189
2197
  console.log(colors.green(`✓ Renamed package to ${newName}`));
2190
2198
  if (!ucfg.scope) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/npmglobalize",
3
- "version": "1.0.93",
3
+ "version": "1.0.95",
4
4
  "description": "Transform file: dependencies to npm versions for publishing",
5
5
  "main": "index.js",
6
6
  "type": "module",