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