How to use the @parcel/diagnostic.generateJSONCodeHighlights 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 / core / src / TargetResolver.js View on Github external
} else {
        if (typeof distPath !== 'string') {
          let contents: string =
            typeof pkgContents === 'string'
              ? pkgContents
              : // $FlowFixMe
                JSON.stringify(pkgContents, null, '\t');
          throw new ThrowableDiagnostic({
            diagnostic: {
              message: `Invalid distPath for target "${targetName}"`,
              origin: '@parcel/core',
              language: 'json',
              filePath: pkgFilePath || undefined,
              codeFrame: {
                code: contents,
                codeHighlights: generateJSONCodeHighlights(contents, [
                  {
                    key: `/${targetName}`,
                    type: 'value',
                    message: 'Expected type string',
                  },
                ]),
              },
            },
          });
        }
        distDir = path.resolve(pkgDir, path.dirname(distPath));
        distEntry = path.basename(distPath);

        invariant(typeof pkgFilePath === 'string');
        invariant(pkgMap != null);
        loc = {
github parcel-bundler / parcel / packages / core / core / src / TargetResolver.js View on Github external
}

  let diagnostics: Array = [];
  for (let [targetPath, targetNames] of targetsByPath) {
    if (targetNames.length > 1 && pkgContents && pkgFilePath) {
      diagnostics.push({
        message: `Multiple targets have the same destination path "${path.relative(
          path.dirname(pkgFilePath),
          targetPath,
        )}"`,
        origin: '@parcel/core',
        language: 'json',
        filePath: pkgFilePath || undefined,
        codeFrame: {
          code: pkgContents,
          codeHighlights: generateJSONCodeHighlights(
            pkgContents,
            targetNames.map(t => ({
              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.',
    ];
github parcel-bundler / parcel / packages / core / utils / src / schema.js View on Github external
message = `Missing property ${prop}`;
        }
      } else if (e.type === 'type') {
        if (e.prettyType != null) {
          message = `Expected ${e.prettyType}`;
        } else {
          message = `Expected type ${e.expectedTypes.join(', ')}`;
        }
      } else {
        message = e.message;
      }
      return {key: e.dataPath, type: e.dataType, message};
    });
    let codeFrame = {
      code: dataContentsString,
      codeHighlights: generateJSONCodeHighlights(
        dataContentsString,
        keys.map(({key, type, message}) => ({
          key: prependKey + key,
          type: type,
          message
        }))
      )
    };

    throw new ThrowableDiagnostic({
      diagnostic: {
        message,
        origin,
        // $FlowFixMe should be a sketchy string check
        filePath: dataContentsPath || undefined,
        language: 'json',
github parcel-bundler / parcel / packages / core / core / src / TargetResolver.js View on Github external
targets = Object.entries(optionTargets).map(([name, _descriptor]) => {
          let {distDir, ...descriptor} = parseDescriptor(
            name,
            _descriptor,
            null,
            {targets: optionTargets},
          );
          if (!distDir) {
            let optionTargetsString = JSON.stringify(optionTargets, null, '\t');
            throw new ThrowableDiagnostic({
              diagnostic: {
                message: `Missing distDir for target "${name}"`,
                origin: '@parcel/core',
                codeFrame: {
                  code: optionTargetsString,
                  codeHighlights: generateJSONCodeHighlights(
                    optionTargetsString,
                    [
                      {
                        key: `/${name}`,
                        type: 'value',
                      },
                    ],
                  ),
                },
              },
            });
          }
          return {
            name,
            distDir: path.resolve(this.fs.cwd(), distDir),
            publicUrl: descriptor.publicUrl,

@parcel/diagnostic

Types and utilities for printing source-code located errors, warning and information messages.

MIT
Latest version published 5 days ago

Package Health Score

89 / 100
Full package analysis

Similar packages