Skip to content

Commit

Permalink
preparePackageCacheBundle: output errors to log file
Browse files Browse the repository at this point in the history
  • Loading branch information
Cykelero committed Jun 28, 2022
1 parent e0ef63d commit d5dcecb
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions source/preparePackageCacheBundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
const autopromise = require('./autopromise');
const path = require('path');
const fs = autopromise(require('fs'));
const readline = require('readline');

const rimraf = require('rimraf');
const crossSpawn = require('cross-spawn');
Expand Down Expand Up @@ -33,6 +34,17 @@ async function doesItemExist(path) {
return fs.lstat(path).then(() => true, () => false);
}

function logError(message) {
console.error(message);

errorLogStream.write(
new Date().toISOString()
+ ' '
+ message
+ '\n'
);
}

// // Installation process
function parsePackageList(rawPackageList) {
return rawPackageList.reduce((result, packageString) => {
Expand Down Expand Up @@ -123,14 +135,26 @@ async function generatePackageFile() {
}

async function runNpmInstall() {
const installProcess = crossSpawn('npm', ['install'], {cwd: bundlePath});
// Run `npm install`
const installProcess = crossSpawn('npm', ['install'], { cwd: bundlePath });

return new Promise(resolve => {
// Log any errors
const stderrReadline = readline.createInterface({
input: installProcess.stderr,
terminal: false
});

stderrReadline.on('line', errorData => {
logError(errorData.toString());
});

// Wait for exit
return new Promise((resolve, reject) => {
installProcess.on('exit', code => {
if (code === 0) {
resolve();
} else {
throw Error('`npm install` failed.');
reject(Error('`npm install` failed (code ' + code + ').'));
}
});
});
Expand Down Expand Up @@ -182,13 +206,15 @@ async function isPulseOld() {
}

// Run
const errorLogStream = require('fs').createWriteStream(__dirname + '/../preparePackageCacheBundle.errors.log', { flags: 'a' });

const packageList = process.argv.slice(2);
packages = parsePackageList(packageList);

bundlePath = PackageCache._bundlePathForList(packageList);

prepareBundle()
.catch(error => {
console.error(error.message);
logError(error.message);
process.exit(1);
});

0 comments on commit d5dcecb

Please sign in to comment.