Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} 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 = {
}
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.',
];
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',
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,