(parsed: Script)
| 48 | }; |
| 49 | |
| 50 | const readScript = (parsed: Script) => { |
| 51 | for (const statement of parsed.commands) { |
| 52 | if (statement.command.type === 'Function') definedFunctions.add(statement.command.name.value); |
| 53 | } |
| 54 | |
| 55 | for (const statement of parsed.commands) { |
| 56 | for (const command of walkCommands(statement.command)) { |
| 57 | const name = command.name?.value; |
| 58 | const word = command.name && readWord(command.name); |
| 59 | const prefix = command.prefix.map(assignment => { |
| 60 | const value = assignment.value && readWord(assignment.value); |
| 61 | return value && value !== assignment.value |
| 62 | ? { ...assignment, value, text: `${assignment.name}=${value.text}` } |
| 63 | : assignment; |
| 64 | }); |
| 65 | const words = command.suffix.map(readWord); |
| 66 | if (!name || !word || definedFunctions.has(name)) continue; |
| 67 | |
| 68 | const binary = extractBinary(name); |
| 69 | const isPackageCommand = isPackageManager(binary); |
| 70 | const isExplicit = isPackageCommand || name.startsWith('./') || isRelativeNodeModulesBin(name); |
| 71 | const isLocal = hasLocalBinPath && !command.prefix.some(assignment => assignment.name === 'PATH'); |
| 72 | const isWrapperCommand = !isPackageCommand && isWrapper(binary); |
| 73 | if (!isExplicit && !isLocal && !isWrapperCommand && binary !== 'node' && binary !== 'find') continue; |
| 74 | |
| 75 | let commandInputs: Input[]; |
| 76 | if (isWrapperCommand || binary === 'find') { |
| 77 | const fromScript = (script: string): Input[] => { |
| 78 | inputs.push(...getInputsFromMiseScript(script, options, isLocal)); |
| 79 | return []; |
| 80 | }; |
| 81 | const fromArgs: FromArgs = args => fromScript(toScript(args)); |
| 82 | commandInputs = getDependenciesFromCommand( |
| 83 | { ...command, name: word, prefix, suffix: words }, |
| 84 | { ...options, fromArgs } |
| 85 | ); |
| 86 | } else { |
| 87 | commandInputs = options.getInputsFromScripts( |
| 88 | [...prefix.map(assignment => assignment.text), word.text, ...words.map(word => word.text)].join(' '), |
| 89 | { cwd: options.cwd, manifest: options.manifest } |
| 90 | ); |
| 91 | } |
| 92 | |
| 93 | if (!isExplicit && !isLocal && binary !== 'node' && binary !== 'find') continue; |
| 94 | if (isWrapperCommand && spawningBinaries.includes(binary)) { |
| 95 | commandInputs.push(...getInputsFromNodeOptions(prefix)); |
| 96 | } |
| 97 | |
| 98 | const binaryInput = commandInputs.find(input => isBinary(input) && input.specifier === binary); |
| 99 | if (!isExplicit && isLocal && binaryInput) binaryInput.optional = true; |
| 100 | for (const input of commandInputs) { |
| 101 | if (!input.specifier || input.specifier.includes(SCRIPT_INTERPOLATION)) continue; |
| 102 | if (!isExplicit && !isLocal && input === binaryInput) continue; |
| 103 | inputs.push(input); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | }; |
no test coverage detected