How to use p-map-series - 10 common examples

To help you get started, we’ve selected a few p-map-series 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 / scope / extensions / install-extensions.js View on Github external
await env.create();
    try {
      const isolatedComponent = await env.isolateComponent(concreteId, isolateOpts);
      if (!dontPrintEnvMsg) {
        // eslint-disable-next-line no-console
        logger.console.debug(chalk.bold.green(`successfully installed the ${concreteId.toString()} ${id.type}`));
      }
      return isolatedComponent;
    } catch (e) {
      if (e instanceof ComponentNotFound) {
        e.dependentId = dependentId ? dependentId.toString() : null;
      }
      throw e;
    }
  };
  return pMapSeries(nonExistingEnvsIds, importEnv);
}
github teambit / bit / src / scope / global-scope.js View on Github external
// Destroying environment to make sure there is no left over
      await env.destroyIfExist();
      await env.create();
      try {
        await env.isolateComponent(concreteId, isolateOpts);
        if (!dontPrintEnvMsg) {
          console.log(chalk.bold.green(`successfully installed the ${concreteId.toString()} ${id.type}`));
        }
      } catch (e) {
        if (e instanceof ComponentNotFound) {
          e.dependentId = dependentId ? dependentId.toString() : '';
        }
        throw e;
      }
    };
    await pMapSeries(nonExistingExtIds, importExtension);
    return res;
  }
}
github teambit / bit / src / scope / component-ops / remove-model-components.js View on Github external
async remove(): Promise {
    const { missingComponents, foundComponents } = await this.scope.filterFoundAndMissingComponents(this.bitIds);
    const dependentBits = await this.scope.findDependentBits(foundComponents);
    if (R.isEmpty(dependentBits) || this.force) {
      // do not run this in parallel (promise.all), otherwise, it may throw an error when
      // trying to delete the same file at the same time (happens when removing a component with
      // a dependency and the dependency itself)
      const removedComponents = await pMapSeries(foundComponents, bitId => this._removeSingle(bitId));
      await this.scope.objects.persist();
      const ids = new BitIds(...removedComponents.map(x => x.bitId));
      const removedDependencies = new BitIds(...R.flatten(removedComponents.map(x => x.removedDependencies)));
      return new RemovedObjects({ removedComponentIds: ids, missingComponents, removedDependencies });
    }
    // some of the components have dependents, don't remove them
    return new RemovedObjects({ missingComponents, dependentBits });
  }
github teambit / bit / src / extensions / extension-hook.js View on Github external
export async function triggerComponentsHook(
  hookName: string,
  components: ComponentType[] | ConsumerComponent[],
  args: ?Object
) {
  if (!components || !Array.isArray(components)) {
    throw TypeError('triggerComponentsHook expects to get an array of components as the second parameter');
  }
  const componentsType = getComponentsType(components);
  // don't use Promise.all(), the order is important. (the order/priority is not implemented yet)
  return pMapSeries(componentsType, componentType => runHookFromComponentType(componentType, hookName, args));
}
github teambit / bit / src / scope / scope.ts View on Github external
// Make sure to not start the loader if there are no components to build
    if (components && components.length) {
      loader.start(BEFORE_RUNNING_BUILD);
      if (components.length > 1) loader.stopAndPersist({ text: `${BEFORE_RUNNING_BUILD}...` });
    }
    const build = async (component: Component) => {
      if (component.compiler) loader.start(`building component - ${component.id}`);
      await component.build({ scope: this, consumer, noCache, verbose, dontPrintEnvMsg });
      const buildResults = await component.dists.writeDists(component, consumer, false);
      if (component.compiler) loader.succeed();
      return { component: component.id.toString(), buildResults };
    };
    const writeLinks = async (component: Component) => component.dists.writeDistsLinks(component, consumer);

    const buildResults = await pMapSeries(components, build);
    await pMapSeries(components, writeLinks);
    return buildResults;
  }
github teambit / bit / src / consumer / versions-ops / merge-version / merge-snaps.ts View on Github external
snapMessage: string;
}) {
  const componentWithConflict = allComponentsStatus.find(
    component => component.mergeResults && component.mergeResults.hasConflicts
  );
  if (componentWithConflict && !mergeStrategy) {
    mergeStrategy = await getMergeStrategyInteractive();
  }
  // @ts-ignore AUTO-ADDED-AFTER-MIGRATION-PLEASE-FIX!
  const failedComponents: FailedComponents[] = allComponentsStatus
    .filter(componentStatus => componentStatus.failureMessage)
    .map(componentStatus => ({ id: componentStatus.id, failureMessage: componentStatus.failureMessage }));
  const succeededComponents = allComponentsStatus.filter(componentStatus => !componentStatus.failureMessage);
  // do not use Promise.all for applyVersion. otherwise, it'll write all components in parallel,
  // which can be an issue when some components are also dependencies of others
  const componentsResults = await pMapSeries(succeededComponents, ({ componentFromFS, id, mergeResults }) => {
    return applyVersion({
      consumer,
      componentFromFS,
      id,
      mergeResults,
      mergeStrategy,
      remoteHead: new Ref(id.version),
      remoteName: remoteName || componentFromFS.scope,
      laneId,
      localLane
    });
  });

  if (localLane) consumer.scope.objects.add(localLane);

  await consumer.scope.objects.persist(); // persist anyway, it localLane is null it should save all master heads
github teambit / bit / src / scope / component-ops / scope-components-importer.ts View on Github external
componentsToComponentsObjects(
    components: Array,
    clientVersion: string | null | undefined
  ): Promise {
    return pMapSeries(components, component => component.toObjects(this.scope.objects, clientVersion));
  }
github teambit / bit / src / scope / component-ops / scope-components-importer.ts View on Github external
async importMany(ids: BitIds, cache = true, persist = true): Promise {
    logger.debugAndAddBreadCrumb('ScopeComponentsImporter', 'importMany: {ids}', { ids: ids.toString() });
    const idsWithoutNils = removeNils(ids);
    if (R.isEmpty(idsWithoutNils)) return Promise.resolve([]);

    const [locals, externals] = R.partition(id => id.isLocal(this.scope.name), idsWithoutNils);

    const localDefs = await this.sources.getMany(locals);
    const versionDeps = await pMapSeries(localDefs, def => {
      if (!def.component) throw new ComponentNotFound(def.id.toString());
      return this.componentToVersionDependencies(def.component, def.id);
    });
    logger.debugAndAddBreadCrumb(
      'ScopeComponentsImporter',
      'importMany: successfully fetched local components and their dependencies. Going to fetch externals'
    );
    const remotes = await getScopeRemotes(this.scope);
    const externalDeps = await this._getExternalMany(externals, remotes, cache, persist);
    return versionDeps.concat(externalDeps);
  }
github teambit / bit / src / consumer / consumer.ts View on Github external
saveDependenciesAsComponents?: boolean
  ): Promise {
    const scopeComponentsImporter = ScopeComponentsImporter.getInstance(this.scope);
    const versionDependenciesArr: VersionDependencies[] = withAllVersions
      ? await scopeComponentsImporter.importManyWithAllVersions(ids, false)
      : await scopeComponentsImporter.importMany(ids);
    const shouldDependenciesSavedAsComponents = await this.shouldDependenciesSavedAsComponents(
      versionDependenciesArr.map(v => v.component.id),
      saveDependenciesAsComponents
    );
    const manipulateDirData = await getManipulateDirWhenImportingComponents(
      this.bitMap,
      versionDependenciesArr,
      this.scope.objects
    );
    const componentWithDependencies = await pMapSeries(versionDependenciesArr, versionDependencies =>
      versionDependencies.toConsumer(this.scope.objects, manipulateDirData)
    );
    componentWithDependencies.forEach(componentWithDeps => {
      const shouldSavedAsComponents = shouldDependenciesSavedAsComponents.find(c =>
        c.id.isEqual(componentWithDeps.component.id)
      );
      if (!shouldSavedAsComponents) {
        throw new Error(`saveDependenciesAsComponents is missing for ${componentWithDeps.component.id.toString()}`);
      }
      componentWithDeps.component.dependenciesSavedAsComponents = shouldSavedAsComponents.saveDependenciesAsComponents;
    });
    return componentWithDependencies;
  }
github teambit / bit / src / scope / component-ops / export-scope-components.ts View on Github external
codemod: boolean;
  defaultScope: string | null | undefined;
}): Promise<{ exported: BitIds; updatedLocally: BitIds }> {
  logger.debugAndAddBreadCrumb('scope.exportMany', 'ids: {ids}', { ids: ids.toString() });
  enrichContextFromGlobal(context);
  if (includeDependencies) {
    const dependenciesIds = await getDependenciesImportIfNeeded();
    ids.push(...dependenciesIds);
    ids = BitIds.uniqFromArray(ids);
  }
  const remotes: Remotes = await getScopeRemotes(scope);
  if (remoteName) {
    return exportIntoRemote(remoteName, ids);
  }
  const groupedByScope = await sortAndGroupByScope();
  const results = await pMapSeries(groupedByScope, result => exportIntoRemote(result.scopeName, result.ids));
  return {
    exported: BitIds.uniqFromArray(R.flatten(results.map(r => r.exported))),
    updatedLocally: BitIds.uniqFromArray(R.flatten(results.map(r => r.updatedLocally)))
  };

  async function exportIntoRemote(
    remoteNameStr: string,
    bitIds: BitIds
  ): Promise<{ exported: BitIds; updatedLocally: BitIds }> {
    const remote: Remote = await remotes.resolve(remoteNameStr, scope);
    const componentObjects = await pMapSeries(bitIds, id => scope.sources.getObjects(id));
    const idsToChangeLocally = BitIds.fromArray(
      bitIds.filter(id => !id.scope || id.scope === remoteNameStr || changeLocallyAlthoughRemoteIsDifferent)
    );
    const componentsAndObjects = [];
    const manyObjectsP = componentObjects.map(async (componentObject: ComponentObjects) => {

p-map-series

Map over promises serially

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis

Popular p-map-series functions