@bobfrankston/npmglobalize 1.0.82 → 1.0.84
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/cli.js +38 -36
- package/lib.d.ts +2 -0
- package/lib.js +4 -2
- package/package.json +2 -2
package/cli.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* npmglobalize CLI - Transform file: dependencies to npm versions for publishing
|
|
4
4
|
*/
|
|
5
|
-
import { globalize, globalizeWorkspace, readConfig, readPackageJson, writeConfig, writePackageJson } from './lib.js';
|
|
5
|
+
import { globalize, globalizeWorkspace, readConfig, readPackageJson, writeConfig, writePackageJson, confirm } from './lib.js';
|
|
6
6
|
import fs from 'fs';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { styleText } from 'util';
|
|
@@ -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,47 +327,46 @@ 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 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
|
-
const
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}
|
|
342
|
+
if (shouldBuild) {
|
|
343
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf-8'));
|
|
344
|
+
if (!pkg.scripts?.build) {
|
|
345
|
+
// TypeScript project without a build script — offer to add one
|
|
346
|
+
console.log(styleText('yellow', `TypeScript project has no "build" script in ${cwd}`));
|
|
347
|
+
const addIt = await confirm('Add "build": "tsc" to package.json?', true);
|
|
348
|
+
if (addIt) {
|
|
349
|
+
if (!pkg.scripts)
|
|
350
|
+
pkg.scripts = {};
|
|
351
|
+
pkg.scripts.build = 'tsc';
|
|
352
|
+
writePackageJson(cwd, pkg);
|
|
353
|
+
console.log(styleText('green', '✓ Added "build": "tsc" to package.json'));
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
|
-
if (
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
console.error(styleText('red', `
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
356
|
+
if (pkg.scripts?.build) {
|
|
357
|
+
const { execSync } = await import('child_process');
|
|
358
|
+
try {
|
|
359
|
+
console.log(`Building ${cwd}...`);
|
|
360
|
+
execSync('npm run build', { cwd, stdio: 'inherit' });
|
|
361
|
+
console.log(styleText('green', '✓ Build succeeded'));
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
console.error(styleText('red', `Build failed in ${cwd}`));
|
|
365
|
+
if (!cliOptions.force) {
|
|
366
|
+
process.exit(1);
|
|
367
|
+
}
|
|
368
|
+
console.log(styleText('yellow', 'Continuing with --force...'));
|
|
369
|
+
}
|
|
369
370
|
}
|
|
370
371
|
}
|
|
371
372
|
}
|
|
@@ -414,6 +415,7 @@ export async function main() {
|
|
|
414
415
|
}
|
|
415
416
|
}
|
|
416
417
|
}
|
|
418
|
+
options._fromCli = true;
|
|
417
419
|
const success = await globalize(cwd, options, configOptions);
|
|
418
420
|
process.exit(success ? 0 : 1);
|
|
419
421
|
}
|
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 (
|
|
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.
|
|
3
|
+
"version": "1.0.84",
|
|
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": [
|