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