| 19 | // semver. npm-package-arg handles dotted and scoped names; fall back to the |
| 20 | // raw string as the name if it can't be parsed. |
| 21 | const parsePositional = (arg) => { |
| 22 | let parsed |
| 23 | try { |
| 24 | parsed = npa(arg) |
| 25 | } catch { |
| 26 | return { name: arg, range: null } |
| 27 | } |
| 28 | const name = parsed.name || arg |
| 29 | if (parsed.type === 'version' || parsed.type === 'range') { |
| 30 | const spec = parsed.fetchSpec |
| 31 | const range = (!spec || spec === '*' || parsed.rawSpec === '' || parsed.rawSpec === '*') |
| 32 | ? null |
| 33 | : spec |
| 34 | return { name, range } |
| 35 | } |
| 36 | return { name, range: null } |
| 37 | } |
| 38 | |
| 39 | // Shared implementation for `npm approve-scripts`, `npm deny-scripts`, and the `npm install-scripts` namespace. |
| 40 | // `npm install-scripts` dispatches to `runMode('approve' | 'deny' | 'list', ...)`. |