| 147 | } |
| 148 | |
| 149 | async #list (path, { workspace } = {}) { |
| 150 | const { scripts = {}, name, _id } = await pkgJson.normalize(path).then(p => p.content) |
| 151 | const scriptEntries = Object.entries(scripts) |
| 152 | |
| 153 | if (this.npm.silent) { |
| 154 | return |
| 155 | } |
| 156 | |
| 157 | if (this.npm.config.get('json')) { |
| 158 | output.buffer(workspace ? { [workspace]: scripts } : scripts) |
| 159 | return |
| 160 | } |
| 161 | |
| 162 | if (!scriptEntries.length) { |
| 163 | return |
| 164 | } |
| 165 | |
| 166 | if (this.npm.config.get('parseable')) { |
| 167 | output.standard(scriptEntries |
| 168 | .map((s) => (workspace ? [workspace, ...s] : s).join(':')) |
| 169 | .join('\n') |
| 170 | .trim()) |
| 171 | return |
| 172 | } |
| 173 | |
| 174 | const cmdList = [ |
| 175 | 'prepare', 'prepublishOnly', |
| 176 | 'prepack', 'postpack', |
| 177 | 'dependencies', |
| 178 | 'preinstall', 'install', 'postinstall', |
| 179 | 'prepublish', 'publish', 'postpublish', |
| 180 | 'prerestart', 'restart', 'postrestart', |
| 181 | 'prestart', 'start', 'poststart', |
| 182 | 'prestop', 'stop', 'poststop', |
| 183 | 'pretest', 'test', 'posttest', |
| 184 | 'preuninstall', 'uninstall', 'postuninstall', |
| 185 | 'preversion', 'version', 'postversion', |
| 186 | ] |
| 187 | const [cmds, runScripts] = scriptEntries.reduce((acc, s) => { |
| 188 | acc[cmdList.includes(s[0]) ? 0 : 1].push(s) |
| 189 | return acc |
| 190 | }, [[], []]) |
| 191 | |
| 192 | const { reset, bold, cyan, dim, blue } = this.npm.chalk |
| 193 | const pkgId = `in ${cyan(_id || name)}` |
| 194 | const title = (t) => reset(bold(t)) |
| 195 | |
| 196 | if (cmds.length) { |
| 197 | output.standard(`${title('Lifecycle scripts')} included ${pkgId}:`) |
| 198 | for (const [k, v] of cmds) { |
| 199 | output.standard(` ${k}`) |
| 200 | output.standard(` ${dim(v)}`) |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | if (runScripts.length) { |
| 205 | const via = `via \`${blue('npm run')}\`:` |
| 206 | if (!cmds.length) { |