Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Unload any orphaned assets
this.unloadOrphanedAssets();
let buildTime = Date.now() - startTime;
let time = prettifyTime(buildTime);
logger.success(`Built in ${time}.`);
if (!this.watcher) {
bundleReport(this.mainBundle, this.options.detailedReport);
}
this.emit('bundled', this.mainBundle);
return this.mainBundle;
} catch (err) {
this.error = err;
logger.error(err);
this.emit('buildError', err);
if (this.hmr) {
this.hmr.emitError(err);
}
if (this.options.throwErrors && !this.hmr) {
throw err;
} else if (!this.options.watch || !initialised) {
await this.stop();
process.exit(1);
}
} finally {
this.pending = false;
this.emit('buildEnd');
// Unload any orphaned assets
this.unloadOrphanedAssets();
let buildTime = Date.now() - startTime;
let time = prettifyTime(buildTime);
logger.success(`Built in ${time}.`);
if (!this.watcher) {
bundleReport(this.mainBundle, this.options.detailedReport);
}
this.emit('bundled', this.mainBundle);
return this.mainBundle;
} catch (err) {
this.error = err;
logger.error(err);
this.emit('buildError', err);
if (this.hmr) {
this.hmr.emitError(err);
}
if (process.env.NODE_ENV === 'production') {
process.exitCode = 1;
} else if (process.env.NODE_ENV === 'test' && !this.hmr) {
throw err;
}
} finally {
this.pending = false;
this.emit('buildEnd');
// If not in watch mode, stop the worker farm so we don't keep the process running.
async handleUnlink(path) {
try {
const isUnlinked = this.unlinked.has(path);
if (!isUnlinked) {
this.unlinked.add(path);
}
} catch (error) {
logger.error(error);
}
}
this.server.once('error', err => {
logger.error(new Error(serverErrors(err, this.options.port)));
reject(err);
});
async write(filename, data) {
try {
await this.ensureDirExists();
await this.writeDepMtimes(data);
await fs.writeFile(this.getCacheFile(filename), JSON.stringify(data));
this.invalidated.delete(filename);
} catch (err) {
logger.error(`Error writing to cache: ${err.message}`);
}
}
.on('error', e => {
logger.error(e, '@parcel/package-manager');
})
.on('data', (message: YarnStdOutMessage) => {
async loadConfig() {
try {
const asset = new Asset(path.resolve(this.options.rootDir, this.name), this.options);
const config = await asset.getConfig(this.configFiles, {
packageKey: this.packageKey
});
if (config) {
return typeof config === "function" ? config() : config;
}
return {};
} catch (error) {
logger.error(error);
}
}
handleBuildStart() {
try {
const sourcePattern = path.join(this.options.eleventyDist, "**/*");
const sourceFiles = glob.sync(sourcePattern);
for (let file of this.unlinked) {
const shouldDelete = sourceFiles.indexOf(file) === -1;
const exists = fs.existsSync(file);
if (shouldDelete && exists) {
this._delete(file);
}
}
} catch (error) {
logger.error(error);
}
}
async set(key: string, value: mixed) {
try {
let blobPath = this._getCachePath(key);
let data = serialize(value);
await this.fs.writeFile(blobPath, data);
return key;
} catch (err) {
logger.error(err, '@parcel/cache');
}
}
}