How to use @adeira/js - 10 common examples

To help you get started, we’ve selected a few @adeira/js 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 kiwicom / monorepo-shipit / src / phases / createCheckCorruptedRepoPhase.js View on Github external
return () => {
    const repo = new RepoGit(repoPath);

    // We should eventually nuke the repo and clone it again. But we do not
    // store the repos in CI yet so it's not necessary. Also, be careful not
    // to nuke monorepo in CI.
    invariant(repo.isCorrupted() === false, `Repo located in '${repoPath}' is corrupted.`);
  };
}
github kiwicom / monorepo-shipit / bin / importit.js View on Github external
// @flow strict-local

import { invariant } from '@adeira/js';

import iterateConfigs from '../src/iterateConfigs';
import createClonePhase from '../src/phases/createClonePhase';
import createCheckCorruptedRepoPhase from '../src/phases/createCheckCorruptedRepoPhase';
import createCleanPhase from '../src/phases/createCleanPhase';
import createImportSyncPhase from '../src/phases/createImportSyncPhase';

// TODO: check we can actually import this package (whether we have config for it)
// yarn monorepo-babel-node src/core/monorepo-shipit/bin/importit.js git@github.com:kiwicom/fetch.git 1

const argv = process.argv.splice(2); // TODO: better CLI
invariant(argv.length === 2, 'Importit expects two arguments: git URL and PR number.');

const exportedRepoURL = argv[0]; // git@github.com:kiwicom/fetch.git
const pullRequestNumber = argv[1];

const gitRegex = /^git@github.com:(?.+)\.git$/;
invariant(
  gitRegex.test(exportedRepoURL),
  'We currently support imports only from GitHub.com - please open an issue to add additional services.',
);

const match = exportedRepoURL.match(gitRegex);
const packageName = match?.groups?.packageName;
invariant(packageName != null, 'Cannot figure out package name from: %s', exportedRepoURL);

iterateConfigs(config => {
  if (config.exportedRepoURL === exportedRepoURL) {
github kiwicom / monorepo-utils / src / glob.js View on Github external
function validateInputs(globPattern: GlobPattern, options?: GlobOptions): void {
  // Only forward slashes must be used, but we cannot disallow backslash since
  // escaping is still allowed. See: https://github.com/isaacs/node-glob#windows
  invariant(
    !isWindowsPath(globPattern),
    `Your glob patterns looks like absolute Windows path but this is not allowed. Glob doesn't accept paths but glob patterns instead. Invalid pattern: ${globPattern}`,
  );

  invariant(
    isValidRoot(globPattern, options),
    `Your glob pattern starts from root but you didn't define any root in glob options. Invalid pattern: ${globPattern}`,
  );
}
github kiwicom / monorepo-shipit / src / filters / moveDirectoriesReverse.js View on Github external
export default function moveDirectoriesReverse(
  changeset: Changeset,
  mapping: Map,
): Changeset {
  const reversedMapping = new Map();
  for (const [src, dest] of mapping.entries()) {
    invariant(
      !reversedMapping.has(dest),
      'It is not possible to reverse mapping with duplicate destinations.',
    );
    reversedMapping.set(dest, src);
  }
  // subdirectories (most specific) should go first
  return moveDirectories(changeset, new Map([...reversedMapping].sort().reverse()));
}
github kiwicom / monorepo-utils / src / glob.js View on Github external
function validateInputs(globPattern: GlobPattern, options?: GlobOptions): void {
  // Only forward slashes must be used, but we cannot disallow backslash since
  // escaping is still allowed. See: https://github.com/isaacs/node-glob#windows
  invariant(
    !isWindowsPath(globPattern),
    `Your glob patterns looks like absolute Windows path but this is not allowed. Glob doesn't accept paths but glob patterns instead. Invalid pattern: ${globPattern}`,
  );

  invariant(
    isValidRoot(globPattern, options),
    `Your glob pattern starts from root but you didn't define any root in glob options. Invalid pattern: ${globPattern}`,
  );
}
github kiwicom / monorepo-shipit / src / parsePatch.js View on Github external
}

    if (minusLines <= 0 && plusLines <= 0) {
      continue;
    }

    if (leftmost === '+') {
      --plusLines;
    } else if (leftmost === '-') {
      --minusLines;
    } else if (leftmost === ' ' || leftmost === '') {
      // context goes from both
      --plusLines;
      --minusLines;
    } else {
      invariant(false, "Can't parse hunk line %s: %s", lineNumber, line);
    }
    contents += `${line}\n`;
  }

  if (contents !== '') {
    yield contents;
  }
}
github kiwicom / monorepo-utils / src / TestsRunner.js View on Github external
function _runJestTimezoneVariants(config, ciNode: CINode) {
  if (ciNode.total > 1) {
    const index = ciNode.index - 1;
    const timezones = [
      'UTC',
      'Asia/Tokyo', // +9
      'America/Lima', // -5
    ];

    invariant(
      timezones[index] !== undefined,
      `CI node with index ${ciNode.index} is not supported.`,
    );

    _runJest(config, timezones[index]);
  } else {
    _runJest(config, 'UTC');
  }
}
github adeira / relay-example / src / Polling / index.js View on Github external
export default function Polling() {
  const [abTestEnabled, setAbTest] = useState(false);

  // If we add the polling config on server, the server also keeps polling, which is unnecessary
  const cacheConfig = isBrowser()
    ? { poll: 1000 } // 1 second
    : {};

  useInterval(() => {
    // Please note: this 'useInterval' hook is not used for the polling but for A/B test.
    setAbTest(Math.random() >= 0.5);
  }, 2500);

  function renderPollingResponse({ currency }: PollingQueryResponse) {
    if (!currency) {
      return null;
    }

    const { code, rate, format } = currency;
    const now = new Date().toString();
github adeira / relay-example / src / Hotels / SSRQueryRenderer.js View on Github external
export default function SSRQueryRenderer(props: Props) {
  // We have to re-create the environment here with initialized store for SSR.
  const environment = createRelayEnvironment(props.ssrData);

  if (!isBrowser() && props.ssrData != null) {
    // When we get here on the server, we have already fetched data
    // Using the QueryRenderer will dispatch a new request to BE from the server, so just return
    // The data from the store instead.
    const data = getDataFromRequest(
      { query: props.query, variables: props.variables },
      environment,
    );

    return (
      
        {data != null ? props.onResponse(data) : <div>loading...</div>}
      
    );
  }

  return (
github kiwicom / monorepo-shipit / src / RepoGit.js View on Github external
parseDiffHunk = (hunk: string) =&gt; {
    const [head, tail] = splitHead(hunk, '\n');
    const match = head.match(/^diff --git [ab]\/(?:.*?) [ab]\/(?

@adeira/js

Useful JS functions used in Adeira ecosystem

MIT
Latest version published 3 years ago

Package Health Score

46 / 100
Full package analysis

Similar packages