How to use the @parcel/diagnostic function in @parcel/diagnostic

To help you get started, we’ve selected a few @parcel/diagnostic 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 / workers / src / Worker.js View on Github external
if (message.type === 'request') {
      this.emit('request', message);
    } else if (message.type === 'response') {
      let idx = message.idx;
      if (idx == null) {
        return;
      }

      let call = this.calls.get(idx);
      if (!call) {
        // Return for unknown calls, these might accur if a third party process uses workers
        return;
      }

      if (message.contentType === 'error') {
        call.reject(new ThrowableDiagnostic({diagnostic: message.content}));
      } else {
        call.resolve(message.content);
      }

      this.calls.delete(idx);
      this.emit('response', message);
    }
  }
github parcel-bundler / parcel / packages / core / core / src / TargetResolver.js View on Github external
engines: descriptor.engines,
              context: descriptor.context,
              isLibrary: descriptor.isLibrary,
              includeNodeModules: descriptor.includeNodeModules,
              outputFormat: descriptor.outputFormat,
            }),
            sourceMap: descriptor.sourceMap,
          };
        });
      }

      if (this.options.serve) {
        // In serve mode, we only support a single browser target. If the user
        // provided more than one, or the matching target is not a browser, throw.
        if (targets.length > 1) {
          throw new ThrowableDiagnostic({
            diagnostic: {
              message: `More than one target is not supported in serve mode`,
              origin: '@parcel/core',
            },
          });
        }
        if (targets[0].env.context !== 'browser') {
          throw new ThrowableDiagnostic({
            diagnostic: {
              message: `Only browser targets are supported in serve mode`,
              origin: '@parcel/core',
            },
          });
        }
      }
    } else {
github parcel-bundler / parcel / packages / core / workers / src / WorkerFarm.js View on Github external
}

      try {
        // $FlowFixMe
        result = responseFromContent(await mod[method](...args));
      } catch (e) {
        result = errorResponseFromError(e);
      }
    }

    if (awaitResponse) {
      if (worker) {
        worker.send(result);
      } else {
        if (result.contentType === 'error') {
          throw new ThrowableDiagnostic({diagnostic: result.content});
        }
        return result.content;
      }
    }
  }
github parcel-bundler / parcel / packages / core / core / src / TargetResolver.js View on Github external
key: `/${t}`,
              type: 'value',
            })),
          ),
        },
      });
    }
  }

  if (diagnostics.length > 0) {
    // Only add hints to the last diagnostic so it isn't duplicated on each one
    diagnostics[diagnostics.length - 1].hints = [
      'Try removing the duplicate targets, or changing the destination paths.',
    ];

    throw new ThrowableDiagnostic({
      diagnostic: diagnostics,
    });
  }
}
github parcel-bundler / parcel / packages / core / core / src / PackagerRunner.js View on Github external
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 / ResolverRunner.js View on Github external
if (result && result.isExcluded) {
          return null;
        }

        if (result && result.filePath) {
          return {
            filePath: result.filePath,
            sideEffects: result.sideEffects,
            code: result.code,
            env: dependency.env,
            pipeline: pipeline ?? dependency.pipeline
          };
        }
      } catch (e) {
        throw new ThrowableDiagnostic({
          diagnostic: errorToDiagnostic(e, resolver.name)
        });
      }
    }

    if (dep.isOptional) {
      return null;
    }

    let dir = dependency.sourcePath
      ? path.dirname(dependency.sourcePath)
      : '';

    let err: any = await this.getThrowableDiagnostic(
      dependency,
      `Cannot find module '${dependency.moduleSpecifier}' from '${dir}'`
github parcel-bundler / parcel / packages / core / core / src / Transformation.js View on Github external
}

        try {
          let transformerResults = await runTransformer(
            pipeline,
            asset,
            transformer.plugin,
            transformer.name,
            transformer.config,
          );

          for (let result of transformerResults) {
            resultingAssets.push(asset.createChildAsset(result));
          }
        } catch (e) {
          throw new ThrowableDiagnostic({
            diagnostic: errorToDiagnostic(e, transformer.name),
          });
        }
      }
      inputAssets = resultingAssets;
    }

    finalAssets = finalAssets.concat(resultingAssets);

    return Promise.all(
      finalAssets.map(asset =>
        finalize(nullthrows(asset), nullthrows(pipeline.generate)),
      ),
    );
  }
github parcel-bundler / parcel / packages / core / core / src / PackagerRunner.js View on Github external
bundleGraph: BundleGraphType,
        ) => {
          if (!bundle.isInline) {
            throw new Error(
              'Bundle is not inline and unable to retrieve contents',
            );
          }

          return this.getBundleResult(
            bundleToInternalBundle(bundle),
            bundleGraphToInternalBundleGraph(bundleGraph),
          );
        },
      });
    } catch (e) {
      throw new ThrowableDiagnostic({
        diagnostic: errorToDiagnostic(e, packager.name),
      });
    }
  }

@parcel/diagnostic

MIT
Latest version published 2 months ago

Package Health Score

89 / 100
Full package analysis

Similar packages