MCPcopy
hub / github.com/toeverything/AFFiNE / runCommand

Method runCommand

tools/cli/src/run.ts:167–205  ·  view source on GitHub ↗
(pkg: Package, args: string[])

Source from the content-addressed store, hash-verified

165 }
166
167 async runCommand(pkg: Package, args: string[]) {
168 const { args: extractedArgs, envs } = this.extractEnvs(args);
169 args = extractedArgs;
170
171 const bin = args[0] === 'yarn' ? args[1] : args[0];
172 const loader =
173 pkg.name === '@affine/server' ? serverRuntimeLoader : tsxRuntimeLoader;
174 const hasKnownLoader =
175 process.env.NODE_OPTIONS?.includes('tsx') ||
176 process.env.NODE_OPTIONS?.includes(tsxRuntimeLoader) ||
177 process.env.NODE_OPTIONS?.includes(serverRuntimeLoader);
178
179 // very simple test for auto ts/mjs scripts
180 const isLoaderRequired =
181 !ignoreLoaderScripts.some(ignore => new RegExp(ignore).test(bin)) ||
182 hasKnownLoader ||
183 process.env.NODE_OPTIONS?.includes(loader);
184
185 let NODE_OPTIONS = process.env.NODE_OPTIONS
186 ? [process.env.NODE_OPTIONS]
187 : [];
188
189 if (isLoaderRequired) {
190 NODE_OPTIONS.push(`--import=${loader}`);
191 }
192
193 if (args[0] !== 'yarn') {
194 // add 'yarn' to the command so we can bypass bin execution to it
195 args.unshift('yarn');
196 }
197
198 await execAsync(pkg.name, args, {
199 cwd: pkg.path.value,
200 env: {
201 ...envs,
202 NODE_OPTIONS: NODE_OPTIONS.join(' '),
203 },
204 });
205 }
206
207 private extractEnvs(args: string[]): {
208 args: string[];

Callers 2

runMethod · 0.95
runScriptMethod · 0.95

Calls 6

extractEnvsMethod · 0.95
execAsyncFunction · 0.90
testMethod · 0.80
pushMethod · 0.65
includesMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected