@bobfrankston/npmglobalize 1.0.82 → 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.
Files changed (4) hide show
  1. package/cli.js +24 -35
  2. package/lib.d.ts +2 -0
  3. package/lib.js +4 -2
  4. package/package.json +2 -2
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
- const pkgPath = path.join(__dirname, 'package.json');
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
- // Check if TypeScript files in target project are compiled
329
- if (!cliOptions.force) {
330
- let noEmit = false;
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
- noEmit = tsconfig.compilerOptions?.noEmit === true;
337
+ shouldBuild = tsconfig.compilerOptions?.noEmit !== true;
336
338
  }
337
339
  catch (error) {
338
- // No tsconfig or can't parse — skip check
339
- noEmit = true;
340
+ // No tsconfig — skip build
340
341
  }
341
- if (!noEmit) {
342
- const outOfSync = [];
343
- const jsFiles = fs.readdirSync(cwd).filter(f => f.endsWith('.js') && !f.endsWith('.min.js'));
344
- for (const jsFile of jsFiles) {
345
- const tsFile = jsFile.replace(/\.js$/, '.ts');
346
- const tsPath = path.join(cwd, tsFile);
347
- const jsPath = path.join(cwd, jsFile);
348
- if (fs.existsSync(tsPath)) {
349
- const tsStat = fs.statSync(tsPath);
350
- const jsStat = fs.statSync(jsPath);
351
- if (jsStat.mtime < tsStat.mtime) {
352
- outOfSync.push(tsFile);
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;
@@ -1418,9 +1420,9 @@ export function getToolVersion() {
1418
1420
  export async function globalize(cwd, options = {}, configOptions = {}) {
1419
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
1420
1422
  forcePublish = false, fix = false, fixTags = false, rebase = false, show = false } = options;
1421
- // Show tool version (skip when called from workspace orchestrator)
1423
+ // Show tool version only for recursive dep calls (CLI already prints it at startup)
1422
1424
  const toolVersion = getToolVersion();
1423
- if (!options._fromWorkspace) {
1425
+ if (!options._fromWorkspace && !options._fromCli) {
1424
1426
  console.log(colors.italic(`npmglobalize v${toolVersion}`));
1425
1427
  }
1426
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.82",
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
- "prepublishOnly": "npm run build",
13
+ "prepare": "npm run build",
14
14
  "check-links": "node check-links.js"
15
15
  },
16
16
  "keywords": [