(
pkg: Package,
scriptName: string,
args: string[],
opts: RunScriptOptions = {}
)
| 103 | } |
| 104 | |
| 105 | async runScript( |
| 106 | pkg: Package, |
| 107 | scriptName: string, |
| 108 | args: string[], |
| 109 | opts: RunScriptOptions = {} |
| 110 | ) { |
| 111 | const rawScript = pkg.scripts[scriptName]; |
| 112 | |
| 113 | if (!rawScript) { |
| 114 | if (opts.ignoreIfNotFound) { |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | throw new Error(`Script ${scriptName} not found in ${pkg.name}`); |
| 119 | } |
| 120 | |
| 121 | const rawArgs = [...rawScript.split(' '), ...args]; |
| 122 | |
| 123 | const { args: extractedArgs, envs } = this.extractEnvs(rawArgs); |
| 124 | |
| 125 | args = extractedArgs; |
| 126 | |
| 127 | if (opts.includeDependencies) { |
| 128 | const depsRun = Promise.all( |
| 129 | pkg.deps.map(dep => { |
| 130 | return this.runScript( |
| 131 | pkg.workspace.getPackage(dep.name), |
| 132 | scriptName, |
| 133 | [], |
| 134 | { |
| 135 | ...opts, |
| 136 | ignoreIfNotFound: true, |
| 137 | } |
| 138 | ); |
| 139 | }) |
| 140 | ); |
| 141 | |
| 142 | if (opts.waitDependencies) { |
| 143 | await depsRun; |
| 144 | } else { |
| 145 | depsRun.catch(e => { |
| 146 | this.logger.error(e); |
| 147 | }); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | const isAFFiNECommand = args[0] === 'affine'; |
| 152 | if (isAFFiNECommand) { |
| 153 | // remove 'affine' from 'affine xxx' command |
| 154 | args.shift(); |
| 155 | args.push('-p', pkg.name); |
| 156 | |
| 157 | process.env = { |
| 158 | ...process.env, |
| 159 | ...envs, |
| 160 | }; |
| 161 | await this.cli.run(args); |
| 162 | } else { |
no test coverage detected