How to use metro-cache - 6 common examples

To help you get started, we’ve selected a few metro-cache 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 facebook / metro / packages / metro / src / DeltaBundler / Worker.js View on Github external
function getTransformer(
  projectRoot: string,
  {transformerPath, transformerConfig}: TransformerConfig,
): Transformer {
  const transformerKey = stableHash([
    projectRoot,
    transformerPath,
    transformerConfig,
  ]).toString('hex');

  if (transformers[transformerKey]) {
    return transformers[transformerKey];
  }

  // eslint-disable-next-line lint/flow-no-fixme
  // $FlowFixMe Transforming fixed types to generic types during refactor.
  const Transformer = require(transformerPath);
  transformers[transformerKey] = new Transformer(
    projectRoot,
    transformerConfig,
  );
github facebook / metro / packages / metro / src / DeltaBundler / Transformer.js View on Github external
platform,
      type,
      ...extra
    } = transformerOptions;

    for (const key in extra) {
      if (hasOwnProperty.call(extra, key)) {
        throw new Error(
          'Extra keys detected: ' + Object.keys(extra).join(', '),
        );
      }
    }

    const localPath = path.relative(this._config.projectRoot, filePath);

    const partialKey = stableHash([
      // This is the hash related to the global Bundler config.
      this._baseHash,

      // Path.
      localPath,

      customTransformOptions,
      dev,
      experimentalImportSupport,
      hot,
      inlinePlatform,
      inlineRequires,
      minify,
      unstable_disableES6Transforms,
      platform,
      type,
github facebook / metro / packages / metro / src / DeltaBundler / Transformer.js View on Github external
constructor(config: ConfigT, getSha1Fn: string => string) {
    this._config = config;

    this._config.watchFolders.forEach(verifyRootExists);
    this._cache = new Cache(config.cacheStores);
    this._getSha1 = getSha1Fn;

    // Remove the transformer config params that we don't want to pass to the
    // transformer. We should change the config object and move them away so we
    // can treat the transformer config params as opaque.
    const {
      getTransformOptions: _getTransformOptions,
      postMinifyProcess: _postMinifyProcess,
      transformVariants: _transformVariants,
      workerPath: _workerPath,
      ...transformerConfig
    } = this._config.transformer;

    const transformerOptions: TransformerConfig = {
      transformerPath: this._config.transformerPath,
      transformerConfig,
github godaddy / ekke / api / metro / configure.js View on Github external
async function configure(flags) {
  const reactNativePath = path.dirname(require.resolve('react-native/package.json'));
  const config = await loadConfig();
  const custom = {
    resolver: {},
    serializer: {},
    transformer: {},
    cacheStores: [
      new FileStore({
        root: flags['cache-location']
      })
    ]
  };

  //
  // We need to create a fake package name that we will point to the root
  // of the users directory so we can resolve their requires and test files
  // without having to rely on `package.json` based resolve due to poor
  // handling of absolute and relative paths.
  //
  // See: https://github.com/facebook/react-native/issues/3099
  //
  const fake = 'ekke-ekke-ekke-ekke';

  //
github facebook / metro / packages / metro / src / DeltaBundler / Transformer.js View on Github external
} = this._config.transformer;

    const transformerOptions: TransformerConfig = {
      transformerPath: this._config.transformerPath,
      transformerConfig,
    };

    this._workerFarm = new WorkerFarm(config, transformerOptions);

    const globalCacheKey = getTransformCacheKey({
      cacheVersion: this._config.cacheVersion,
      projectRoot: this._config.projectRoot,
      transformerConfig: transformerOptions,
    });

    this._baseHash = stableHash([globalCacheKey]).toString('binary');
  }
github facebook / metro / packages / metro / src / JSTransformer / worker.js View on Github external
require.resolve('../lib/getMinifier'),
      require.resolve('./worker/inline-plugin'),
      require.resolve('./worker/import-export-plugin'),
      require.resolve('./worker/normalizePseudoglobals'),
      require.resolve('../ModuleGraph/worker/optimizeDependencies'),
      require.resolve('../ModuleGraph/worker/generateImportNames'),
    ]);

    const babelTransformer = require(babelTransformerPath);
    const babelTransformerKey = babelTransformer.getCacheKey
      ? babelTransformer.getCacheKey()
      : '';

    return [
      filesKey,
      stableHash(config).toString('hex'),
      babelTransformerKey,
    ].join('$');
  }
}

metro-cache

🚇 Cache layers for Metro.

MIT
Latest version published 28 days ago

Package Health Score

92 / 100
Full package analysis

Similar packages