How to use the @parcel/logger.PluginLogger function in @parcel/logger

To help you get started, we’ve selected a few @parcel/logger 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 / Transformation.js View on Github external
async function runTransformer(
  pipeline: Pipeline,
  asset: InternalAsset,
  transformer: Transformer,
  transformerName: string,
  preloadedConfig: ?Config,
): Promise> {
  const logger = new PluginLogger({origin: transformerName});

  const resolve = async (from: FilePath, to: string): Promise => {
    return nullthrows(
      await pipeline.resolverRunner.resolve(
        createDependency({
          env: asset.value.env,
          moduleSpecifier: to,
          sourcePath: from,
        }),
      ),
    ).filePath;
  };

  // Load config for the transformer.
  let config = preloadedConfig;
  if (transformer.getConfig) {
github parcel-bundler / parcel / packages / core / core / src / ReporterRunner.js View on Github external
async report(event: ReporterEvent) {
    let reporters = await this.config.getReporters();

    for (let reporter of reporters) {
      try {
        await reporter.plugin.report({
          event,
          options: this.pluginOptions,
          logger: new PluginLogger({origin: reporter.name}),
        });
      } catch (e) {
        throw new ThrowableDiagnostic({
          diagnostic: errorToDiagnostic(e, reporter.name),
        });
      }
    }
  }
}
github parcel-bundler / parcel / packages / core / core / src / PackagerRunner.js View on Github external
bundle,
    });

    let packager = await this.config.getPackager(bundle.filePath);
    try {
      return await packager.plugin.package({
        bundle,
        bundleGraph: new BundleGraph(bundleGraph, this.options),
        getSourceMapReference: map => {
          return bundle.isInline ||
            (bundle.target.sourceMap && bundle.target.sourceMap.inline)
            ? this.generateSourceMap(bundleToInternalBundle(bundle), map)
            : path.basename(bundle.filePath) + '.map';
        },
        options: this.pluginOptions,
        logger: new PluginLogger({origin: packager.name}),
        getInlineBundleContents: (
          bundle: BundleType,
          bundleGraph: BundleGraphType,
        ) => {
          if (!bundle.isInline) {
            throw new Error(
              'Bundle is not inline and unable to retrieve contents',
            );
          }

          return this.getBundleResult(
            bundleToInternalBundle(bundle),
            bundleGraphToInternalBundleGraph(bundleGraph),
          );
        },
      });
github parcel-bundler / parcel / packages / core / core / src / PackagerRunner.js View on Github external
report({
      type: 'buildProgress',
      phase: 'optimizing',
      bundle,
    });

    let optimized = {contents, map};
    for (let optimizer of optimizers) {
      try {
        optimized = await optimizer.plugin.optimize({
          bundle,
          contents: optimized.contents,
          map: optimized.map,
          options: this.pluginOptions,
          logger: new PluginLogger({origin: optimizer.name}),
        });
      } catch (e) {
        throw new ThrowableDiagnostic({
          diagnostic: errorToDiagnostic(e, optimizer.name),
        });
      }
    }

    return optimized;
  }
github parcel-bundler / parcel / packages / core / core / src / Validation.js View on Github external
},
      env: this.request.env,
    };

    let config = await this.configLoader.load(configRequest);
    nullthrows(config.result);
    let parcelConfig = new ParcelConfig(
      config.result,
      this.options.packageManager,
    );

    let validators = await parcelConfig.getValidators(this.request.filePath);
    let pluginOptions = new PluginOptions(this.options);

    for (let validator of validators) {
      let validatorLogger = new PluginLogger({origin: validator.name});
      try {
        let config = null;
        if (validator.plugin.getConfig) {
          config = await validator.plugin.getConfig({
            asset: new Asset(asset),
            options: pluginOptions,
            logger: validatorLogger,
            resolveConfig: (configNames: Array) =>
              resolveConfig(
                this.options.inputFS,
                asset.value.filePath,
                configNames,
              ),
          });
        }
github parcel-bundler / parcel / packages / core / core / src / ConfigLoader.js View on Github external
let config = createConfig({
      isSource,
      searchPath: filePath,
      env,
    });
    invariant(typeof parcelConfigPath === 'string');
    let pluginInstance = await loadPlugin(
      this.options.packageManager,
      nullthrows(plugin),
      parcelConfigPath,
    );
    if (pluginInstance.loadConfig != null) {
      await pluginInstance.loadConfig({
        config: new Config(config, this.options),
        options: this.options,
        logger: new PluginLogger({origin: nullthrows(plugin)}),
      });
    }

    return config;
  }
}