How to use the execa.node function in execa

To help you get started, we’ve selected a few execa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github teambit / bit / src / specs-runner / specs-runner.js View on Github external
};
  // Don't use ternary condition since if we put it as undefined
  // It will pass to the fork as "undefined" (string) instad of not passing it at all
  // __ids__: ids ? ids.join() : undefined,
  if (ids) {
    baseEnv.__ids__ = ids.join();
  }
  // Merge process.env from the main process
  const env = Object.assign({}, process.env, baseEnv);
  try {
    const workerPath = path.join(__dirname, 'worker.js');
    // if (process.pkg) {
    //   const entryPoint = process.argv[1];
    //   workerPath = path.join(entryPoint, '../../dist/specs-runner/worker.js');
    // }
    const child = execa.node(workerPath, args, { env });
    const result = await pEvent(child, 'message');
    const childResult = await child;
    if (!result) {
      return null;
    }

    const deserializedResults = deserializeResults(result);
    if (!deserializedResults) return null;
    if (childResult.all) {
      deserializedResults.childOutput = childResult.all;
    }
    if (deserializedResults.type === 'error') {
      if (deserializedResults.error instanceof Error) {
        throw deserializedResults.error;
      }
      throw new Error(deserializedResults.error);
github teambit / bit / src / specs-runner / specs-runner.ts View on Github external
};
  // Don't use ternary condition since if we put it as undefined
  // It will pass to the fork as "undefined" (string) instad of not passing it at all
  // __ids__: ids ? ids.join() : undefined,
  if (ids) {
    // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
    baseEnv.__ids__ = ids.join();
  }
  // Merge process.env from the main process
  const env = Object.assign({}, process.env, baseEnv);
  const workerPath = path.join(__dirname, 'worker.js');
  // if (process.pkg) {
  //   const entryPoint = process.argv[1];
  //   workerPath = path.join(entryPoint, '../../dist/specs-runner/worker.js');
  // }
  const child = execa.node(workerPath, args, { env, nodeOptions: ['--no-warnings'] });
  const result = await pEvent(child, 'message');
  const childResult = await child;
  if (!result) {
    return null;
  }

  const deserializedResults = deserializeResults(result);
  if (!deserializedResults) return null;
  if (childResult.all) {
    deserializedResults.childOutput = childResult.all;
  }
  if (deserializedResults.type === 'error') {
    if (deserializedResults.error instanceof Error) {
      throw deserializedResults.error;
    }
    throw new Error(deserializedResults.error);
github chalk / chalk / test / level.js View on Github external
test('disable colors if they are not supported', async t => {
	const {stdout} = await execa.node(path.join(__dirname, '_fixture'));
	t.is(stdout, 'testout testerr');
});
github dherault / serverless-offline / tests / integration / _testHelpers / setupTeardown.js View on Github external
export async function setup(options) {
  const { args = [], servicePath } = options

  if (RUN_TEST_AGAINST_AWS) {
    return
  }

  serverlessProcess = node(serverlessPath, ['offline', 'start', ...args], {
    cwd: servicePath,
  })

  await new Promise((res) => {
    serverlessProcess.stdout.on('data', (data) => {
      if (String(data).includes('[HTTP] server ready')) {
        res()
      }
    })
  })
}
github adonisjs / assembler / src / HttpServer / index.ts View on Github external
public start () {
    if (this.isConnected) {
      throw new Error('Http server is already connected. Call restart instead')
    }

    this.logger.info(this.childProcess ? 're-starting http server' : 'starting http server')
    this.childProcess = execa.node(this.sourceFile, [], {
      buffer: false,
      stdio: 'inherit',
      cwd: this.projectRoot,
      env: {
        FORCE_COLOR: 'true',
      },
      nodeOptions: this.nodeArgs,
    })

    this.childProcess.on('close', (code, signal) => this.emit('close', { code, signal }))
    this.childProcess.on('exit', (code, signal) => this.emit('exit', { code, signal }))
  }
github adonisjs / adonis-cli / src / Services / HttpServer.ts View on Github external
public start () {
    if (this.isConnected) {
      throw new Error('Http server is already connected. Call restart instead')
    }

    this._httpServer = execa.node(this._sourceFile, [], {
      buffer: false,
      cwd: this._projectRoot,
      env: getChildProcessEnvVariables(this._projectRoot),
      nodeOptions: this._nodeArgs,
    })

    /**
     * Pipe the output
     */
    this._httpServer.stdout!.pipe(process.stdout)
    this._httpServer.stderr!.pipe(process.stderr)
  }
github swissquote / crafty / packages / integration / utils.js View on Github external
async function run(args, cwd, commandOptions) {
  const options = Object.assign(
    {
      cwd,
      reject: false,
      all: true
    },
    commandOptions || {}
  );

  options.env = Object.assign({ TESTING_CRAFTY: "true" }, options.env || {});

  const ret = await execa.node(
    require.resolve("@swissquote/crafty/src/bin"),
    args,
    options
  );

  return {
    status: ret.exitCode,
    stdall: ret.all ? `\n${snapshotizeOutput(ret.all.toString("utf8"))}\n` : ""
  };
}
github adonisjs / assembler / src / Manifest / index.ts View on Github external
public async generate () {
    try {
      const response = await execa.node('ace', ['generate:manifest'], {
        buffer: true,
        cwd: this.appRoot,
        env: {
          FORCE_COLOR: 'true',
        },
      })

      /**
       * Print warning when `stderr` exists
       */
      if (response.stderr) {
        this.logger.warn(WARN_MESSAGE)
        return
      }

      /**