npq 3.11.4 → 3.11.6
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/bin/npq-hero.js +11 -1
- package/bin/npq.js +11 -1
- package/lib/cli.js +4 -1
- package/lib/helpers/cliPrompt.js +10 -0
- package/lib/marshalls/age.marshall.js +5 -3
- package/lib/marshalls/baseMarshall.js +15 -8
- package/package.json +2 -1
package/bin/npq-hero.js
CHANGED
|
@@ -100,8 +100,18 @@ marshall
|
|
|
100
100
|
}
|
|
101
101
|
})
|
|
102
102
|
.catch((error) => {
|
|
103
|
+
// Ensure errorCode is always a number
|
|
104
|
+
let errorCode = -1
|
|
105
|
+
if (typeof error.code === 'number') {
|
|
106
|
+
errorCode = error.code
|
|
107
|
+
} else if (error.code === 'ABORT_ERR') {
|
|
108
|
+
errorCode = 1
|
|
109
|
+
} else if (error.code === 'USER_ABORT') {
|
|
110
|
+
errorCode = error.exitCode || 1
|
|
111
|
+
}
|
|
112
|
+
|
|
103
113
|
CliParser.exit({
|
|
104
|
-
errorCode
|
|
114
|
+
errorCode,
|
|
105
115
|
message: error.message || 'An error occurred',
|
|
106
116
|
spinner
|
|
107
117
|
})
|
package/bin/npq.js
CHANGED
|
@@ -126,8 +126,18 @@ Promise.resolve()
|
|
|
126
126
|
}
|
|
127
127
|
})
|
|
128
128
|
.catch((error) => {
|
|
129
|
+
// Ensure errorCode is always a number
|
|
130
|
+
let errorCode = -1
|
|
131
|
+
if (typeof error.code === 'number') {
|
|
132
|
+
errorCode = error.code
|
|
133
|
+
} else if (error.code === 'ABORT_ERR') {
|
|
134
|
+
errorCode = 1
|
|
135
|
+
} else if (error.code === 'USER_ABORT') {
|
|
136
|
+
errorCode = error.exitCode || 1
|
|
137
|
+
}
|
|
138
|
+
|
|
129
139
|
CliParser.exit({
|
|
130
|
-
errorCode
|
|
140
|
+
errorCode,
|
|
131
141
|
message: error.message || 'An error occurred',
|
|
132
142
|
spinner
|
|
133
143
|
})
|
package/lib/cli.js
CHANGED
|
@@ -11,10 +11,13 @@ class CliParser {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
if (message) {
|
|
14
|
+
console.error('\n')
|
|
14
15
|
console.error(message)
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
// Ensure errorCode is always a number
|
|
19
|
+
const exitCode = typeof errorCode === 'number' ? errorCode : -1
|
|
20
|
+
process.exit(exitCode)
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
static _extractPackagesFromPositionals(positionals, earlyExitNoInstall = false) {
|
package/lib/helpers/cliPrompt.js
CHANGED
|
@@ -54,6 +54,16 @@ async function prompt(options = {}) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
return { [name]: result }
|
|
57
|
+
} catch (error) {
|
|
58
|
+
// Handle Ctrl+C gracefully - user cancelled the operation
|
|
59
|
+
if (error.code === 'ABORT_ERR') {
|
|
60
|
+
// Throw a specific error that can be caught and handled by the caller
|
|
61
|
+
const abortError = new Error('Operation aborted by user')
|
|
62
|
+
abortError.code = 'USER_ABORT'
|
|
63
|
+
abortError.exitCode = 1
|
|
64
|
+
throw abortError
|
|
65
|
+
}
|
|
66
|
+
throw error
|
|
57
67
|
} finally {
|
|
58
68
|
rl.close()
|
|
59
69
|
}
|
|
@@ -28,8 +28,9 @@ class Marshall extends BaseMarshall {
|
|
|
28
28
|
|
|
29
29
|
const pkgCreatedDate = data.time.created
|
|
30
30
|
const dateDiff = Date.now() - Date.parse(pkgCreatedDate)
|
|
31
|
+
const thresholdMs = PACKAGE_AGE_THRESHOLD * 24 * 60 * 60 * 1000
|
|
31
32
|
|
|
32
|
-
if (dateDiff <
|
|
33
|
+
if (dateDiff < thresholdMs) {
|
|
33
34
|
throw new Error(
|
|
34
35
|
`Detected a newly published package (created < ${PACKAGE_AGE_THRESHOLD} days) act carefully`
|
|
35
36
|
)
|
|
@@ -46,8 +47,9 @@ class Marshall extends BaseMarshall {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
const versionReleaseDate = data.time[packageVersion]
|
|
49
|
-
const versionDateDiff =
|
|
50
|
+
const versionDateDiff = Date.now() - Date.parse(versionReleaseDate)
|
|
50
51
|
const versionDateDiffInDays = Math.round(versionDateDiff / (1000 * 60 * 60 * 24))
|
|
52
|
+
const unmaintainedThresholdMs = PACKAGE_AGE_UNMAINTAINED_RISK * 24 * 60 * 60 * 1000
|
|
51
53
|
|
|
52
54
|
let timeAgoText = 'days'
|
|
53
55
|
let timeAgoNumber = versionDateDiffInDays
|
|
@@ -57,7 +59,7 @@ class Marshall extends BaseMarshall {
|
|
|
57
59
|
timeAgoNumber = Math.floor(versionDateDiffInDays / 365)
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
if (
|
|
62
|
+
if (versionDateDiff >= unmaintainedThresholdMs) {
|
|
61
63
|
throw new Warning(`Detected an old package (created ${timeAgoNumber} ${timeAgoText} ago)`)
|
|
62
64
|
}
|
|
63
65
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
+
const semver = require('semver')
|
|
3
4
|
const util = require('node:util')
|
|
4
5
|
const Warning = require('../helpers/warning')
|
|
5
6
|
const { marshallCategories } = require('./constants')
|
|
@@ -76,20 +77,26 @@ class BaseMarshall {
|
|
|
76
77
|
* @param {Object} packageData - Optional package data to avoid re-fetching
|
|
77
78
|
* @returns {Promise<string|null>} - The resolved semver version or null if not found
|
|
78
79
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
|
|
81
|
+
async resolvePackageVersion(packageName, versionSpec, packageData) {
|
|
82
|
+
if (typeof versionSpec !== 'string' || versionSpec.trim() === '') return null
|
|
81
83
|
const data = packageData || (await this.packageRepoUtils.getPackageInfo(packageName))
|
|
82
84
|
|
|
83
|
-
if (!data
|
|
84
|
-
return null
|
|
85
|
-
}
|
|
85
|
+
if (!data) return null
|
|
86
86
|
|
|
87
|
-
//
|
|
88
|
-
if (
|
|
87
|
+
// Handle dist-tags first
|
|
88
|
+
if (data['dist-tags'] && data['dist-tags'][versionSpec]) {
|
|
89
89
|
return data['dist-tags'][versionSpec]
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
//
|
|
92
|
+
// Handle semver ranges and exact versions using all available versions
|
|
93
|
+
if (data.versions) {
|
|
94
|
+
const availableVersions = Object.keys(data.versions)
|
|
95
|
+
const resolved = semver.maxSatisfying(availableVersions, versionSpec)
|
|
96
|
+
if (resolved) return resolved
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Fallback for simple parsing if range resolution fails
|
|
93
100
|
const parsed = this.packageRepoUtils.parsePackageVersion(versionSpec)
|
|
94
101
|
return parsed ? parsed.version : null
|
|
95
102
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npq",
|
|
3
|
-
"version": "3.11.
|
|
3
|
+
"version": "3.11.6",
|
|
4
4
|
"description": "marshall your npm/npm package installs with high quality and class 🎖",
|
|
5
5
|
"bin": {
|
|
6
6
|
"npq": "./bin/npq.js",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"fastest-levenshtein": "^1.0.16",
|
|
47
|
+
"lodash": "^4.17.21",
|
|
47
48
|
"npm-package-arg": "^13.0.0",
|
|
48
49
|
"pacote": "^21.0.0",
|
|
49
50
|
"semver": "^7.7.2"
|