How to use the @parcel/utils.PromiseQueue function in @parcel/utils

To help you get started, we’ve selected a few @parcel/utils 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 parcel-bundler / parcel / packages / packagers / css / src / CSSPackager.js View on Github external
async package({bundle, bundleGraph, getInlineBundleContents}) {
    let queue = new PromiseQueue({maxConcurrent: 32});
    bundle.traverseAssets({
      exit: asset => {
        // Figure out which media types this asset was imported with.
        // We only want to import the asset once, so group them all together.
        let media = [];
        for (let dep of bundleGraph.getIncomingDependencies(asset)) {
          if (!dep.meta.media) {
            // Asset was imported without a media type. Don't wrap in @media.
            media.length = 0;
            break;
          }
          media.push(dep.meta.media);
        }

        queue.add(() =>
          asset.getCode().then((css: string) => {
github parcel-bundler / parcel / packages / core / core / src / AssetGraphBuilder.js View on Github external
name,
    assetRequests,
    workerFarm,
  }: Opts) {
    this.options = options;
    this.assetRequests = [];

    let {minify, hot, scopeHoist} = options;
    this.cacheKey = md5FromObject({
      parcelVersion: PARCEL_VERSION,
      name,
      options: {minify, hot, scopeHoist},
      entries,
    });

    this.queue = new PromiseQueue();

    this.runValidate = workerFarm.createHandle('runValidate');
    this.handle = workerFarm.createReverseHandle(() => {
      // Do nothing, this is here because there is a bug in `@parcel/workers`
    });

    let changes = await this.readFromCache();
    if (!changes) {
      this.assetGraph = new AssetGraph();
      this.requestGraph = new RequestGraph();
    }

    this.assetGraph.initOptions({
      onNodeRemoved: node => this.handleNodeRemovedFromAssetGraph(node),
      onIncompleteNode: node => this.handleIncompleteNode(node),
    });
github parcel-bundler / parcel / packages / packagers / js / src / JSPackager.js View on Github external
return replaceReferences({
        contents: generate(bundleGraph, bundle, ast, options).contents,
        map: null,
      });
    }

    if (bundle.env.outputFormat === 'esmodule') {
      throw new Error(
        `esmodule output is not supported without scope hoisting.`,
      );
    }

    // For development, we just concatenate all of the code together
    // rather then enabling scope hoisting, which would be too slow.
    let codeQueue = new PromiseQueue({maxConcurrent: 32});
    let mapQueue = new PromiseQueue({maxConcurrent: 32});
    bundle.traverse(node => {
      if (node.type === 'asset') {
        codeQueue.add(() => node.value.getCode());
        mapQueue.add(() => node.value.getMap());
      }
    });

    let [code, maps] = await Promise.all([codeQueue.run(), mapQueue.run()]);

    let assets = '';
    let i = 0;
    let first = true;
    let map = new SourceMap();
    let lineOffset = countLines(PRELUDE);

    let stubsWritten = new Set();
github parcel-bundler / parcel / packages / packagers / js / src / JSPackager.js View on Github external
ast = link({bundle, bundleGraph, ast, options});
      return replaceReferences({
        contents: generate(bundleGraph, bundle, ast, options).contents,
        map: null,
      });
    }

    if (bundle.env.outputFormat === 'esmodule') {
      throw new Error(
        `esmodule output is not supported without scope hoisting.`,
      );
    }

    // For development, we just concatenate all of the code together
    // rather then enabling scope hoisting, which would be too slow.
    let codeQueue = new PromiseQueue({maxConcurrent: 32});
    let mapQueue = new PromiseQueue({maxConcurrent: 32});
    bundle.traverse(node => {
      if (node.type === 'asset') {
        codeQueue.add(() => node.value.getCode());
        mapQueue.add(() => node.value.getMap());
      }
    });

    let [code, maps] = await Promise.all([codeQueue.run(), mapQueue.run()]);

    let assets = '';
    let i = 0;
    let first = true;
    let map = new SourceMap();
    let lineOffset = countLines(PRELUDE);
github parcel-bundler / parcel / packages / shared / scope-hoisting / src / concat.js View on Github external
export async function concat(bundle: Bundle, bundleGraph: BundleGraph) {
  let queue = new PromiseQueue({maxConcurrent: 32});
  bundle.traverse((node, shouldWrap) => {
    switch (node.type) {
      case 'dependency':
        // Mark assets that should be wrapped, based on metadata in the incoming dependency tree
        if (shouldWrap || node.value.meta.shouldWrap) {
          let resolved = bundleGraph.getDependencyResolution(node.value);
          if (resolved) {
            resolved.meta.shouldWrap = true;
          }
          return true;
        }
        break;
      case 'asset':
        queue.add(() => processAsset(bundle, node.value));
    }
  });
github parcel-bundler / parcel / packages / core / package-manager / src / installPackage.js View on Github external
let configFile = await resolveConfig(fs, filepath, [
    'yarn.lock',
    'package-lock.json',
  ]);
  let hasYarn = await Yarn.exists();

  // If Yarn isn't available, or there is a package-lock.json file, use npm.
  let configName = configFile && path.basename(configFile);
  if (!hasYarn || configName === 'package-lock.json') {
    return new Npm();
  }

  return new Yarn();
}

let queue = new PromiseQueue({maxConcurrent: 1});
let modulesInstalling: Set = new Set();

// Exported so that it may be invoked from the worker api below.
// Do not call this directly! This can result in concurrent package installations
// across multiple instances of the package manager.
export function _addToInstallQueue(
  fs: FileSystem,
  modules: Array,
  filePath: FilePath,
  options?: InstallOptions,
): Promise {
  modules = validateModuleSpecifiers(modules);

  // Wrap PromiseQueue and track modules that are currently installing.
  // If a request comes in for a module that is currently installing, don't bother
  // enqueuing it.
github parcel-bundler / parcel / packages / core / core / src / ConfigLoader.js View on Github external
constructor(options: ParcelOptions) {
    this.options = options;
    this.queue = new PromiseQueue({maxConcurrent: 32});
  }
github parcel-bundler / parcel / packages / core / core / src / RequestGraph.js View on Github external
initOptions({
    onAssetRequestComplete,
    onDepPathRequestComplete,
    onEntryRequestComplete,
    onTargetRequestComplete,
    config,
    options,
    workerFarm
  }: RequestGraphOpts) {
    this.options = options;
    this.queue = new PromiseQueue();
    this.validationQueue = new PromiseQueue();
    this.onAssetRequestComplete = onAssetRequestComplete;
    this.onDepPathRequestComplete = onDepPathRequestComplete;
    this.onEntryRequestComplete = onEntryRequestComplete;
    this.onTargetRequestComplete = onTargetRequestComplete;
    this.config = config;

    this.entryResolver = new EntryResolver(this.options);
    this.targetResolver = new TargetResolver(this.options);

    this.resolverRunner = new ResolverRunner({
      config,
      options
    });

    this.farm = workerFarm;
github parcel-bundler / parcel / packages / reporters / loc / src / lineCounter.js View on Github external
const lineCounter = async (bundles: Array) => {
  let set = new Set();

  for (let bundle of bundles) {
    bundle.traverseAssets(asset => {
      let {filePath} = asset;

      if (filePath != null && !filePath.startsWith(runtimesPath)) {
        set.add(filePath);
      }
    });
  }

  let queue = new PromiseQueue({maxConcurrent: os.cpus().length});
  let lineCount = 0;
  for (let assetPath of set) {
    queue
      .add(() => countLinesInFile(assetPath))
      .then(count => (lineCount += count));
  }

  await queue.run();
  return lineCount;
};
github parcel-bundler / parcel / packages / core / core / src / RequestGraph.js View on Github external
initOptions({
    onAssetRequestComplete,
    onDepPathRequestComplete,
    onEntryRequestComplete,
    onTargetRequestComplete,
    config,
    options,
    workerFarm
  }: RequestGraphOpts) {
    this.options = options;
    this.queue = new PromiseQueue();
    this.validationQueue = new PromiseQueue();
    this.onAssetRequestComplete = onAssetRequestComplete;
    this.onDepPathRequestComplete = onDepPathRequestComplete;
    this.onEntryRequestComplete = onEntryRequestComplete;
    this.onTargetRequestComplete = onTargetRequestComplete;
    this.config = config;

    this.entryResolver = new EntryResolver(this.options);
    this.targetResolver = new TargetResolver(this.options);

    this.resolverRunner = new ResolverRunner({
      config,
      options
    });

    this.farm = workerFarm;
    this.runTransform = this.farm.createHandle('runTransform');