Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function report(event: ReporterEvent) {
if (event.bundle == null) {
bus.emit('reporterEvent', event);
} else {
// Convert any public api bundles to their internal equivalents for
// easy serialization
bus.emit('reporterEvent', {
...event,
bundle: bundleToInternalBundle(event.bundle),
});
}
}
export function report(event: ReporterEvent) {
if (event.bundle == null) {
bus.emit('reporterEvent', event);
} else {
// Convert any public api bundles to their internal equivalents for
// easy serialization
bus.emit('reporterEvent', {
...event,
bundle: bundleToInternalBundle(event.bundle),
});
}
}
if (this.options.watch) {
this.watcher = new Watcher();
// Wait for ready event for reliable testing on watcher
if (process.env.NODE_ENV === 'test' && !this.watcher.ready) {
await new Promise(resolve => this.watcher.once('ready', resolve));
}
this.watcher.on('change', this.onChange.bind(this));
}
if (this.options.hmr) {
this.hmr = new HMRServer();
this.options.hmrPort = await this.hmr.start(this.options);
}
this.farm = WorkerFarm.getShared(this.options, {
workerPath: require.resolve('./worker')
});
}
constructor(id: number, handleFn: HandleFunction) {
// TODO Make this not a subclass
// $FlowFixMe
super();
this.id = id;
this.handleFn = handleFn;
handleFn('_registerWorker', [
WorkerFarm.getWorkerApi().createReverseHandle(event => {
switch (event.type) {
case 'writeFile':
this.files.set(event.path, event.entry);
break;
case 'unlink':
this.files.delete(event.path);
this.dirs.delete(event.path);
this.symlinks.delete(event.path);
break;
case 'mkdir':
this.dirs.set(event.path, new Directory());
break;
case 'symlink':
this.symlinks.set(event.path, event.target);
break;
}
if (align === 'right') {
return pad + text;
}
return text + pad;
}
// Count visible characters in a string
function stringWidth(string) {
return countBreaks(stripAnsi('' + string));
}
// If we are in a worker, make a proxy class which will
// send the logger calls to the main process via IPC.
// These are handled in WorkerFarm and directed to handleMessage above.
if (WorkerFarm.isWorker()) {
class LoggerProxy {}
for (let method of Object.getOwnPropertyNames(Logger.prototype)) {
LoggerProxy.prototype[method] = (...args) => {
WorkerFarm.callMaster(
{
location: __filename,
method,
args
},
false
);
};
}
module.exports = new LoggerProxy();
} else {
constructor(opts: Opts) {
this.config = opts.config;
this.options = opts.options;
this.pluginOptions = new PluginOptions(this.options);
logger.onLog(event => this.report(event));
// Convert any internal bundles back to their public equivalents as reporting
// is public api
bus.on('reporterEvent', event => {
if (event.bundle == null) {
this.report(event);
} else {
this.report({
...event,
bundle: new NamedBundle(
event.bundle,
event.bundleGraph,
this.options,
),
});
}
});
if (this.options.patchConsole) {
patchConsole();
module.exports = async function(...args) {
// Ensure that this function is always called on the master process so we
// don't call multiple installs in parallel.
if (WorkerFarm.isWorker()) {
await WorkerFarm.callMaster({
location: __filename,
args,
});
return;
}
queue.add(...args);
return queue.run();
};
module.exports = async function(...args) {
// Ensure that this function is always called on the master process so we
// don't call multiple installs in parallel.
if (WorkerFarm.isWorker()) {
await WorkerFarm.callMaster({
location: __filename,
args,
});
return;
}
queue.add(...args);
return queue.run();
};
export function createWorkerFarm(options: $Shape = {}) {
return new WorkerFarm({
...options,
workerPath: require.resolve('./worker'),
});
}
const fs = require('@parcel/fs');
const Resolver = require('./Resolver');
const Parser = require('./Parser');
const WorkerFarm = require('@parcel/workers').default;
const Path = require('path');
const Bundle = require('./Bundle');
const Watcher = require('@parcel/watcher').default;
const FSCache = require('./FSCache');
const HMRServer = require('./HMRServer');
const Server = require('./Server');
const {EventEmitter} = require('events');
const logger = require('@parcel/logger');
const PackagerRegistry = require('./packagers');
const localRequire = require('./utils/localRequire');
const config = require('./utils/config');
const loadEnv = require('./utils/env');
const PromiseQueue = require('./utils/PromiseQueue');
const installPackage = require('./utils/installPackage');
const bundleReport = require('./utils/bundleReport');
const prettifyTime = require('./utils/prettifyTime');