How to use the @bazel/worker.debug function in @bazel/worker

To help you get started, we’ve selected a few @bazel/worker 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 bazelbuild / rules_sass / sass / sass_wrapper.js View on Github external
* It can also be invoked with an argument file to run once and exit.
 */
"use strict";

const {debug, runAsWorker, runWorkerLoop} = require('@bazel/worker');
const sass = require('sass');
const fs = require('fs');

const args = process.argv.slice(2);
if (runAsWorker(args)) {
  debug('Starting Sass compiler persistent worker...');
  runWorkerLoop(args => sass.cli_pkg_main_0_(args));
  // Note: intentionally don't process.exit() here, because runWorkerLoop
  // is waiting for async callbacks from node.
} else {
  debug('Running a single build...');
  if (args.length === 0) throw new Error('Not enough arguments');
  if (args.length !== 1) {
    throw new Error('Expected one argument: path to flagfile');
  }

  // Bazel worker protocol expects the only arg to be @.
  // When we are running a single build, we remove the @ prefix and read the list 
  // of actual arguments line by line.
  const configFile = args[0].replace(/^@+/, '');
  const configContent = fs.readFileSync(configFile, 'utf8').trim();
  sass.cli_pkg_main_0_(configContent.split('\n'));
}

process.exitCode = 0;
github bazelbuild / rules_sass / sass / sass_wrapper.js View on Github external
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
 * 
 * A Sass compiler wrapper that supports bazel persistent worker protocol.
 *
 * Bazel can spawn a persistent worker process that handles multiple invocations.
 * It can also be invoked with an argument file to run once and exit.
 */
"use strict";

const {debug, runAsWorker, runWorkerLoop} = require('@bazel/worker');
const sass = require('sass');
const fs = require('fs');

const args = process.argv.slice(2);
if (runAsWorker(args)) {
  debug('Starting Sass compiler persistent worker...');
  runWorkerLoop(args => sass.cli_pkg_main_0_(args));
  // Note: intentionally don't process.exit() here, because runWorkerLoop
  // is waiting for async callbacks from node.
} else {
  debug('Running a single build...');
  if (args.length === 0) throw new Error('Not enough arguments');
  if (args.length !== 1) {
    throw new Error('Expected one argument: path to flagfile');
  }

  // Bazel worker protocol expects the only arg to be @.
  // When we are running a single build, we remove the @ prefix and read the list 
  // of actual arguments line by line.
  const configFile = args[0].replace(/^@+/, '');
  const configContent = fs.readFileSync(configFile, 'utf8').trim();
  sass.cli_pkg_main_0_(configContent.split('\n'));

@bazel/worker

Adapt Node programs to run as a Bazel worker

Apache-2.0
Latest version published 2 years ago

Package Health Score

75 / 100
Full package analysis

Popular @bazel/worker functions