@bobfrankston/npmglobalize 1.0.133 → 1.0.135
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/lib.js +52 -79
- package/package.json +1 -1
package/lib.js
CHANGED
|
@@ -1894,6 +1894,15 @@ function ensureGitignore(cwd) {
|
|
|
1894
1894
|
fs.writeFileSync(gitignorePath, content);
|
|
1895
1895
|
console.log(colors.green(' ✓ .gitignore updated'));
|
|
1896
1896
|
}
|
|
1897
|
+
// Untrack node_modules if already committed to git
|
|
1898
|
+
const nmTracked = spawnSafe('git', ['ls-files', 'node_modules/'], {
|
|
1899
|
+
cwd, encoding: 'utf-8', stdio: 'pipe', shell: true
|
|
1900
|
+
});
|
|
1901
|
+
if (nmTracked.status === 0 && nmTracked.stdout?.trim()) {
|
|
1902
|
+
console.log(colors.yellow(' Untracking node_modules from git...'));
|
|
1903
|
+
runCommand('git', ['rm', '-r', '--cached', 'node_modules/'], { cwd, silent: true });
|
|
1904
|
+
gitCommit('Untrack node_modules', cwd);
|
|
1905
|
+
}
|
|
1897
1906
|
}
|
|
1898
1907
|
/** Ensure .npmignore exists with recommended patterns */
|
|
1899
1908
|
function ensureNpmignore(cwd) {
|
|
@@ -2064,94 +2073,51 @@ export async function initGit(cwd, visibility, dryRun) {
|
|
|
2064
2073
|
/** Main globalize function */
|
|
2065
2074
|
/** Run npm audit and optionally fix vulnerabilities */
|
|
2066
2075
|
export function runNpmAudit(cwd, fix = false, verbose = false) {
|
|
2067
|
-
console.log('');
|
|
2068
|
-
console.log(colors.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'));
|
|
2069
|
-
console.log(colors.yellow('🔒 npm audit'));
|
|
2070
|
-
console.log(colors.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'));
|
|
2071
2076
|
if (fix) {
|
|
2072
|
-
|
|
2073
|
-
const fixResult = runCommand('npm', ['audit', 'fix'], { cwd, silent: false });
|
|
2074
|
-
if (!fixResult.success) {
|
|
2075
|
-
console.log(colors.yellow('⚠ Some vulnerabilities could not be automatically fixed'));
|
|
2076
|
-
}
|
|
2077
|
-
else {
|
|
2078
|
-
console.log(colors.green('✓ Audit fixes applied'));
|
|
2079
|
-
}
|
|
2077
|
+
runCommand('npm', ['audit', 'fix'], { cwd, silent: true });
|
|
2080
2078
|
}
|
|
2081
|
-
//
|
|
2079
|
+
// Check remaining vulnerabilities
|
|
2082
2080
|
const auditResult = spawnSafe('npm', ['audit', '--json'], {
|
|
2083
|
-
cwd,
|
|
2084
|
-
encoding: 'utf-8',
|
|
2085
|
-
stdio: 'pipe',
|
|
2086
|
-
shell: true // Required on Windows to find npm.cmd
|
|
2081
|
+
cwd, encoding: 'utf-8', stdio: 'pipe', shell: true
|
|
2087
2082
|
});
|
|
2088
2083
|
let hasVulnerabilities = false;
|
|
2089
2084
|
let report = '';
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
parts.push(`${info} info`);
|
|
2114
|
-
console.log('');
|
|
2115
|
-
console.log(colors.yellow(`Vulnerabilities: ${parts.join(', ')}`));
|
|
2116
|
-
if (verbose && Object.keys(vulnerabilities).length > 0) {
|
|
2117
|
-
console.log('');
|
|
2118
|
-
console.log('Details:');
|
|
2119
|
-
for (const [pkg, data] of Object.entries(vulnerabilities)) {
|
|
2120
|
-
const vulnData = data;
|
|
2121
|
-
const severity = vulnData.severity || 'unknown';
|
|
2122
|
-
const severityColor = severity === 'critical' || severity === 'high' ? colors.red :
|
|
2123
|
-
severity === 'moderate' ? colors.yellow : (s) => s;
|
|
2124
|
-
console.log(` ${severityColor(severity)}: ${pkg}`);
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
if (!fix) {
|
|
2128
|
-
console.log('');
|
|
2129
|
-
console.log(colors.yellow('Run with --fix to automatically fix vulnerabilities'));
|
|
2130
|
-
}
|
|
2085
|
+
try {
|
|
2086
|
+
const auditData = JSON.parse(auditResult.stdout || '{}');
|
|
2087
|
+
const m = auditData.metadata?.vulnerabilities || {};
|
|
2088
|
+
const critical = m.critical || 0;
|
|
2089
|
+
const high = m.high || 0;
|
|
2090
|
+
const moderate = m.moderate || 0;
|
|
2091
|
+
const low = m.low || 0;
|
|
2092
|
+
const total = critical + high + moderate + low + (m.info || 0);
|
|
2093
|
+
if (total > 0) {
|
|
2094
|
+
hasVulnerabilities = true;
|
|
2095
|
+
const parts = [];
|
|
2096
|
+
if (critical > 0)
|
|
2097
|
+
parts.push(colors.red(`${critical} critical`));
|
|
2098
|
+
if (high > 0)
|
|
2099
|
+
parts.push(colors.red(`${high} high`));
|
|
2100
|
+
if (moderate > 0)
|
|
2101
|
+
parts.push(colors.yellow(`${moderate} moderate`));
|
|
2102
|
+
if (low > 0)
|
|
2103
|
+
parts.push(`${low} low`);
|
|
2104
|
+
report = `${total} vulnerabilities`;
|
|
2105
|
+
// Only show if high/critical remain after fix
|
|
2106
|
+
if (critical > 0 || high > 0) {
|
|
2107
|
+
console.log(colors.red(` Audit: ${parts.join(', ')}`));
|
|
2131
2108
|
}
|
|
2132
|
-
else {
|
|
2133
|
-
console.log(colors.
|
|
2134
|
-
report = 'No vulnerabilities';
|
|
2109
|
+
else if (verbose) {
|
|
2110
|
+
console.log(colors.dim(` Audit: ${parts.join(', ')}`));
|
|
2135
2111
|
}
|
|
2136
2112
|
}
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
console.log('Running text audit...');
|
|
2140
|
-
const textResult = runCommand('npm', ['audit'], { cwd, silent: false });
|
|
2141
|
-
report = 'Audit completed (see output above)';
|
|
2113
|
+
else {
|
|
2114
|
+
report = 'No vulnerabilities';
|
|
2142
2115
|
}
|
|
2143
2116
|
}
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
report = 'No vulnerabilities';
|
|
2117
|
+
catch {
|
|
2118
|
+
report = 'Audit check failed';
|
|
2147
2119
|
}
|
|
2148
|
-
|
|
2149
|
-
console.log('');
|
|
2150
|
-
return {
|
|
2151
|
-
success: true,
|
|
2152
|
-
report,
|
|
2153
|
-
hasVulnerabilities
|
|
2154
|
-
};
|
|
2120
|
+
return { success: true, report, hasVulnerabilities };
|
|
2155
2121
|
}
|
|
2156
2122
|
/** Get the version of npmglobalize itself */
|
|
2157
2123
|
export function getToolVersion() {
|
|
@@ -2229,7 +2195,7 @@ async function doLocalInstall(cwd, options) {
|
|
|
2229
2195
|
}
|
|
2230
2196
|
export async function globalize(cwd, options = {}, configOptions = {}) {
|
|
2231
2197
|
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
|
|
2232
|
-
forcePublish = false, fix =
|
|
2198
|
+
forcePublish = false, fix = true, fixTags = false, rebase = false, show = false, local = false, freeze = false } = options;
|
|
2233
2199
|
// Show tool version only for recursive dep calls (CLI already prints it at startup)
|
|
2234
2200
|
const toolVersion = getToolVersion();
|
|
2235
2201
|
if (!options._fromWorkspace && !options._fromCli) {
|
|
@@ -3637,8 +3603,15 @@ export async function globalize(cwd, options = {}, configOptions = {}) {
|
|
|
3637
3603
|
}
|
|
3638
3604
|
}
|
|
3639
3605
|
else if (error.message?.includes('not clean') || error.message?.includes('working directory')) {
|
|
3640
|
-
//
|
|
3641
|
-
|
|
3606
|
+
// Show what's dirty
|
|
3607
|
+
const dirtyCheck = spawnSafe('git', ['status', '--porcelain'], {
|
|
3608
|
+
cwd, encoding: 'utf-8', stdio: 'pipe', shell: true
|
|
3609
|
+
});
|
|
3610
|
+
if (dirtyCheck.stdout?.trim()) {
|
|
3611
|
+
console.log(colors.dim(' Dirty files: ' + dirtyCheck.stdout.trim().split('\n').join(', ')));
|
|
3612
|
+
}
|
|
3613
|
+
// Commit stray changes and retry
|
|
3614
|
+
console.log(colors.yellow(' Committing stray changes and retrying...'));
|
|
3642
3615
|
const addRes = runCommand('git', ['add', '-A'], { cwd, silent: true });
|
|
3643
3616
|
if (addRes.success) {
|
|
3644
3617
|
const commitRes = gitCommit('Pre-version cleanup', cwd);
|