How to use the @parcel/utils.md5FromObject 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 / core / core / src / PackagerRunner.js View on Github external
let optimizers = this.config.getOptimizerNames(filePath);
    let deps = Promise.all(
      [packager, ...optimizers].map(async pkg => {
        let {pkg: resolvedPkg} = await this.options.packageManager.resolve(
          `${pkg}/package.json`,
          `${this.config.filePath}/index`,
        );

        let version = nullthrows(resolvedPkg).version;
        return [pkg, version];
      }),
    );

    // TODO: add third party configs to the cache key
    let {minify, scopeHoist, sourceMaps} = this.options;
    return md5FromObject({
      parcelVersion: PARCEL_VERSION,
      deps,
      opts: {minify, scopeHoist, sourceMaps},
      hash: bundleGraph.getHash(bundle),
    });
  }
github parcel-bundler / parcel / packages / core / core / src / Environment.js View on Github external
export function getEnvironmentHash(env: Environment) {
  // context is excluded from hash so that assets can be shared between e.g. workers and browser.
  // Different engines should be sufficient to distinguish multi-target builds.
  return md5FromObject({
    engines: env.engines,
    includeNodeModules: env.includeNodeModules,
    outputFormat: env.outputFormat,
    isLibrary: env.isLibrary,
  });
}
github parcel-bundler / parcel / packages / core / core / src / BundlerRunner.js View on Github external
async getCacheKey(assetGraph: AssetGraph) {
    let bundler = this.config.bundler;
    let {pkg} = await this.options.packageManager.resolve(
      `${bundler}/package.json`,
      `${this.config.filePath}/index`, // TODO: is this right?
    );

    let version = nullthrows(pkg).version;
    return md5FromObject({
      parcelVersion: PARCEL_VERSION,
      bundler,
      version,
      hash: assetGraph.getHash(),
    });
  }
github parcel-bundler / parcel / packages / core / core / src / Transformation.js View on Github external
assets.map(asset =>
        asset.commit(
          md5FromObject({
            impactfulOptions: this.impactfulOptions,
            configs: getImpactfulConfigInfo(configs),
          }),
        ),
      ),
github parcel-bundler / parcel / packages / core / core / src / RequestTracker.js View on Github external
generateRequestId(request: TRequest) {
    return md5FromObject({type: this.type, request});
  }
github parcel-bundler / parcel / packages / core / core / src / RequestTracker.js View on Github external
export function generateRequestId(type: string, request: mixed) {
  return md5FromObject({type, request});
}
github parcel-bundler / parcel / packages / transformers / babel / src / config.js View on Github external
message:
          'WARNING: You are using `extends` in your Babel config, which means you are losing out on some of the caching features of Parcel. Maybe try using a reusable preset instead.',
      });
      config.shouldInvalidateOnStartup();
    }

    if (dependsOnRelative || dependsOnLocal) {
      logger.verbose({
        message:
          'WARNING: It looks like you are using local Babel plugins or presets. You will need to run with the `--no-cache` option in order to pick up changes to these until their containing package versions are bumped.',
      });
    }

    if (canBeRehydrated) {
      await definePluginDependencies(config);
      config.setResultHash(md5FromObject(partialConfig.options));
    } else {
      logger.verbose({
        message:
          'WARNING: You are using `require` to configure Babel plugins or presets. This means Babel transformations cannot be cached and will run on each build. Please use strings to configure Babel instead.',
      });
      config.setResultHash(JSON.stringify(Date.now()));
      config.shouldInvalidateOnStartup();
    }
  } else {
    await buildDefaultBabelConfig(config);
  }
}
github parcel-bundler / parcel / packages / core / core / src / RequestGraph.js View on Github external
const nodeFromConfigRequest = (configRequest: ConfigRequest) => ({
  id: md5FromObject({
    filePath: configRequest.filePath,
    plugin: configRequest.plugin,
    env: configRequest.env,
    pipeline: configRequest.pipeline
  }),
  type: 'config_request',
  value: configRequest
});
github parcel-bundler / parcel / packages / core / core / src / Transformation.js View on Github external
getCacheKey(assets: Array, configs: ConfigMap): string {
    let assetsKeyInfo = assets.map(a => ({
      filePath: a.value.filePath,
      hash: a.value.hash,
    }));

    return md5FromObject({
      parcelVersion: PARCEL_VERSION,
      assets: assetsKeyInfo,
      configs: getImpactfulConfigInfo(configs),
      env: this.request.env,
      impactfulOptions: this.impactfulOptions,
    });
  }