Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async package({bundle, bundleGraph, getInlineBundleContents}) {
let queue = new PromiseQueue({maxConcurrent: 32});
bundle.traverseAssets({
exit: asset => {
// Figure out which media types this asset was imported with.
// We only want to import the asset once, so group them all together.
let media = [];
for (let dep of bundleGraph.getIncomingDependencies(asset)) {
if (!dep.meta.media) {
// Asset was imported without a media type. Don't wrap in @media.
media.length = 0;
break;
}
media.push(dep.meta.media);
}
queue.add(() =>
asset.getCode().then((css: string) => {
name,
assetRequests,
workerFarm,
}: Opts) {
this.options = options;
this.assetRequests = [];
let {minify, hot, scopeHoist} = options;
this.cacheKey = md5FromObject({
parcelVersion: PARCEL_VERSION,
name,
options: {minify, hot, scopeHoist},
entries,
});
this.queue = new PromiseQueue();
this.runValidate = workerFarm.createHandle('runValidate');
this.handle = workerFarm.createReverseHandle(() => {
// Do nothing, this is here because there is a bug in `@parcel/workers`
});
let changes = await this.readFromCache();
if (!changes) {
this.assetGraph = new AssetGraph();
this.requestGraph = new RequestGraph();
}
this.assetGraph.initOptions({
onNodeRemoved: node => this.handleNodeRemovedFromAssetGraph(node),
onIncompleteNode: node => this.handleIncompleteNode(node),
});
return replaceReferences({
contents: generate(bundleGraph, bundle, ast, options).contents,
map: null,
});
}
if (bundle.env.outputFormat === 'esmodule') {
throw new Error(
`esmodule output is not supported without scope hoisting.`,
);
}
// For development, we just concatenate all of the code together
// rather then enabling scope hoisting, which would be too slow.
let codeQueue = new PromiseQueue({maxConcurrent: 32});
let mapQueue = new PromiseQueue({maxConcurrent: 32});
bundle.traverse(node => {
if (node.type === 'asset') {
codeQueue.add(() => node.value.getCode());
mapQueue.add(() => node.value.getMap());
}
});
let [code, maps] = await Promise.all([codeQueue.run(), mapQueue.run()]);
let assets = '';
let i = 0;
let first = true;
let map = new SourceMap();
let lineOffset = countLines(PRELUDE);
let stubsWritten = new Set();
ast = link({bundle, bundleGraph, ast, options});
return replaceReferences({
contents: generate(bundleGraph, bundle, ast, options).contents,
map: null,
});
}
if (bundle.env.outputFormat === 'esmodule') {
throw new Error(
`esmodule output is not supported without scope hoisting.`,
);
}
// For development, we just concatenate all of the code together
// rather then enabling scope hoisting, which would be too slow.
let codeQueue = new PromiseQueue({maxConcurrent: 32});
let mapQueue = new PromiseQueue({maxConcurrent: 32});
bundle.traverse(node => {
if (node.type === 'asset') {
codeQueue.add(() => node.value.getCode());
mapQueue.add(() => node.value.getMap());
}
});
let [code, maps] = await Promise.all([codeQueue.run(), mapQueue.run()]);
let assets = '';
let i = 0;
let first = true;
let map = new SourceMap();
let lineOffset = countLines(PRELUDE);
export async function concat(bundle: Bundle, bundleGraph: BundleGraph) {
let queue = new PromiseQueue({maxConcurrent: 32});
bundle.traverse((node, shouldWrap) => {
switch (node.type) {
case 'dependency':
// Mark assets that should be wrapped, based on metadata in the incoming dependency tree
if (shouldWrap || node.value.meta.shouldWrap) {
let resolved = bundleGraph.getDependencyResolution(node.value);
if (resolved) {
resolved.meta.shouldWrap = true;
}
return true;
}
break;
case 'asset':
queue.add(() => processAsset(bundle, node.value));
}
});
let configFile = await resolveConfig(fs, filepath, [
'yarn.lock',
'package-lock.json',
]);
let hasYarn = await Yarn.exists();
// If Yarn isn't available, or there is a package-lock.json file, use npm.
let configName = configFile && path.basename(configFile);
if (!hasYarn || configName === 'package-lock.json') {
return new Npm();
}
return new Yarn();
}
let queue = new PromiseQueue({maxConcurrent: 1});
let modulesInstalling: Set = new Set();
// Exported so that it may be invoked from the worker api below.
// Do not call this directly! This can result in concurrent package installations
// across multiple instances of the package manager.
export function _addToInstallQueue(
fs: FileSystem,
modules: Array,
filePath: FilePath,
options?: InstallOptions,
): Promise {
modules = validateModuleSpecifiers(modules);
// Wrap PromiseQueue and track modules that are currently installing.
// If a request comes in for a module that is currently installing, don't bother
// enqueuing it.
constructor(options: ParcelOptions) {
this.options = options;
this.queue = new PromiseQueue({maxConcurrent: 32});
}
initOptions({
onAssetRequestComplete,
onDepPathRequestComplete,
onEntryRequestComplete,
onTargetRequestComplete,
config,
options,
workerFarm
}: RequestGraphOpts) {
this.options = options;
this.queue = new PromiseQueue();
this.validationQueue = new PromiseQueue();
this.onAssetRequestComplete = onAssetRequestComplete;
this.onDepPathRequestComplete = onDepPathRequestComplete;
this.onEntryRequestComplete = onEntryRequestComplete;
this.onTargetRequestComplete = onTargetRequestComplete;
this.config = config;
this.entryResolver = new EntryResolver(this.options);
this.targetResolver = new TargetResolver(this.options);
this.resolverRunner = new ResolverRunner({
config,
options
});
this.farm = workerFarm;
const lineCounter = async (bundles: Array) => {
let set = new Set();
for (let bundle of bundles) {
bundle.traverseAssets(asset => {
let {filePath} = asset;
if (filePath != null && !filePath.startsWith(runtimesPath)) {
set.add(filePath);
}
});
}
let queue = new PromiseQueue({maxConcurrent: os.cpus().length});
let lineCount = 0;
for (let assetPath of set) {
queue
.add(() => countLinesInFile(assetPath))
.then(count => (lineCount += count));
}
await queue.run();
return lineCount;
};
initOptions({
onAssetRequestComplete,
onDepPathRequestComplete,
onEntryRequestComplete,
onTargetRequestComplete,
config,
options,
workerFarm
}: RequestGraphOpts) {
this.options = options;
this.queue = new PromiseQueue();
this.validationQueue = new PromiseQueue();
this.onAssetRequestComplete = onAssetRequestComplete;
this.onDepPathRequestComplete = onDepPathRequestComplete;
this.onEntryRequestComplete = onEntryRequestComplete;
this.onTargetRequestComplete = onTargetRequestComplete;
this.config = config;
this.entryResolver = new EntryResolver(this.options);
this.targetResolver = new TargetResolver(this.options);
this.resolverRunner = new ResolverRunner({
config,
options
});
this.farm = workerFarm;
this.runTransform = this.farm.createHandle('runTransform');