npmaargh 1.0.1 → 1.0.2

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/index.js +26 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -64,13 +64,29 @@ Flags:
64
64
 
65
65
  /* -------------------------------------------------------------------------- */
66
66
 
67
+ let subject = path.basename(wd);
68
+ try {
69
+ const manifestPath = path.resolve(wd, "package.json");
70
+ const manifestRaw = await readFile(manifestPath);
71
+ const manifest = JSON.parse(manifestRaw);
72
+ subject = manifest.name || subject;
73
+ } catch { }
74
+
75
+ let version = "";
76
+ try {
77
+ const { stdout } = await exec("git rev-parse --short HEAD", { cwd: wd });
78
+ version = `@${stdout.trim()}`;
79
+ } catch { }
80
+
81
+ /* -------------------------------------------------------------------------- */
82
+
67
83
  const npmListCache = new Map();
68
84
  async function npmList(subject) {
69
85
  if (!npmListCache.has(subject)) {
70
86
  async function fetch() {
71
87
  const { stdout } = await exec(`npm list ${subject} --json`, { cwd: wd });
72
88
  const list = JSON.parse(stdout);
73
- list.version ||= "1.0.0";
89
+ list.version = version.substring(1) || list.version || "1.0.0";
74
90
  return list;
75
91
  }
76
92
 
@@ -117,7 +133,7 @@ function prerelease(version) {
117
133
  /* -------------------------------------------------------------------------- */
118
134
 
119
135
  console.info("=== npm audit assistant ===");
120
- console.info(`I'm here to help audit '${path.basename(target)}'.`);
136
+ console.info(`I'm here to help audit '${subject}${version}'.`);
121
137
  console.info("");
122
138
 
123
139
  console.info("=== setup ===");
@@ -133,7 +149,8 @@ try {
133
149
  try {
134
150
  await exec("npm install --ignore-scripts", { cwd: wd });
135
151
  } catch (error) {
136
- stdout.write("\rFailed to (re)install dependencies:", error);
152
+ stdout.write(`\rFailed to (re)install dependencies:\n`);
153
+ console.info(error);
137
154
  exit(1);
138
155
  }
139
156
  }
@@ -147,7 +164,7 @@ stdout.write("Obtaining audit report...");
147
164
  let npmAuditReport;
148
165
  try {
149
166
  await exec("npm audit --json", { cwd: wd });
150
- stdout.write("\rNothing to audit. ");
167
+ stdout.write("\rNothing to audit. \n");
151
168
  exit(0);
152
169
  } catch (error) {
153
170
  npmAuditReport = JSON.parse(error.stdout);
@@ -155,7 +172,8 @@ try {
155
172
 
156
173
  const reportVersion = npmAuditReport.auditReportVersion;
157
174
  if (reportVersion !== 2) {
158
- stdout.write("\rUnknown audit report version:", reportVersion);
175
+ stdout.write(`\rUnknown audit report version: ${reportVersion}\n`);
176
+ exit(1);
159
177
  }
160
178
 
161
179
  stdout.write("\rObtained audit report. \n");
@@ -191,7 +209,7 @@ stdout.write("\rAnalyzed audit report. \n");
191
209
 
192
210
  /* -------------------------------------------------------------------------- */
193
211
 
194
- const SELF = `<${path.basename(target)}>`;
212
+ const SELF = `<${subject}>`;
195
213
 
196
214
  class Nothing {
197
215
  toString() {
@@ -484,6 +502,8 @@ function pruneNoops(result) {
484
502
  }
485
503
 
486
504
  function print(result, gutter, level) {
505
+ result.name = result.name.replace(SELF, subject);
506
+
487
507
  if (!level) {
488
508
  function depth(obj, lvl) {
489
509
  const length = obj.name.length + obj.version.length + lvl;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "npmaargh",
3
3
  "description": "The npm audit assistant",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "repository": {
7
7
  "type": "git",