How to use p-locate - 2 common examples

To help you get started, we’ve selected a few p-locate 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 webiny / webiny-js / packages-utils / webiny-semantic-release / src / plugins / analyzeCommits / getLastRelease.js View on Github external
return async tagFormat => {
        // Generate a regex to parse tags formatted with `tagFormat`
        // by replacing the `version` variable in the template by `(.+)`.
        // The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
        // so it's guaranteed to no be present in the `tagFormat`.
        const tagRegexp = escapeRegExp(template(tagFormat)({ version: " " })).replace(" ", "(.+)");
        const tags = (await git.tags())
            .map(tag => {
                return { gitTag: tag, version: (tag.match(tagRegexp) || new Array(2))[1] };
            })
            .filter(tag => tag.version && semver.valid(semver.clean(tag.version)))
            .sort((a, b) => semver.rcompare(a.version, b.version));

        if (tags.length > 0) {
            const { gitTag, version } = await pLocate(tags, tag => git.isRefInHistory(tag.gitTag), {
                concurrency: 1,
                preserveOrder: true
            });
            logger.log("Found git tag %s associated with version %s", gitTag, version);

            return { gitHead: await git.tagHead(gitTag), gitTag, version };
        }

        logger.log("No git tag version found");
        return {};
    };
};
github tunnckoCore / opensource / web / pkg.tunnckocore.com / api / index.js View on Github external
await ky
          .get(`${JSDELIVR}${pathname}/${srcPath}`)
          .then(() => {
            res.send(`${JSDELIVR}${pathname}/${srcPath}`, 301);
          })
          .catch(() => {
            res.send(
              `Not found source path given in the "${field}" of package.json`,
              404,
            );
          });
        return;
      }
    }

    const result = await pLocate(
      ['src/index.ts', 'src/index.js', 'index.ts', 'index.js'].map((fp) =>
        ky
          .get(`${JSDELIVR}${pathname}/${fp}`)
          .then(async (x) => ({ file: fp, value: await x.text() }))
          .catch(() => {}),
      ),
      (val) => {
        if (typeof val === 'undefined') {
          return false;
        }
        return true;
      },
    );

    if (result) {
      console.log('found', `${JSDELIVR}${pathname}/${result.file}`);

p-locate

Get the first fulfilled promise that satisfies the provided testing function

MIT
Latest version published 3 years ago

Package Health Score

70 / 100
Full package analysis

Popular p-locate functions