Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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),
});
}
}
}
}
throw new Error(
`Destination name ${name} extension does not match bundle type "${bundle.type}"`,
);
}
let target = nullthrows(internalBundle.target);
internalBundle.filePath = path.join(
target.distDir,
normalizeSeparators(name),
);
internalBundle.name = name;
return;
}
} catch (e) {
throw new ThrowableDiagnostic({
diagnostic: errorToDiagnostic(e, namer.name),
});
}
}
throw new Error('Unable to name bundle');
}
}
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}'`
);
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;
}
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)),
),
);
}
function messagesToDiagnostic(
messages: Array,
): Diagnostic | Array {
if (messages.length === 1 && messages[0] instanceof Error) {
let error: Error = messages[0];
let diagnostic = errorToDiagnostic(error);
if (Array.isArray(diagnostic)) {
return diagnostic.map(d => {
return {
...d,
skipFormatting: true,
};
});
} else {
return {
...diagnostic,
skipFormatting: true,
};
}
} else {
return {
if (validatorResult) {
let {warnings, errors} = validatorResult;
if (errors.length > 0) {
throw new ThrowableDiagnostic({
diagnostic: errors,
});
}
if (warnings.length > 0) {
logger.warn(warnings);
}
}
} catch (e) {
throw new ThrowableDiagnostic({
diagnostic: errorToDiagnostic(e, validator.name),
});
}
}
}