Workaround balena-dev/oclif compatibility issues

Change-type: patch
Signed-off-by: Scott Lowe <scott@balena.io>
This commit is contained in:
Scott Lowe 2020-10-02 16:17:16 +02:00
parent 8a808e25d0
commit c85acbd90b

View File

@ -1,7 +1,7 @@
#!/usr/bin/env node #!/usr/bin/env node
// **************************************************************************** // ****************************************************************************
// THIS IS FOR DEV PERROSES ONLY AND WILL NOT BE PART OF THE PUBLISHED PACKAGE // THIS IS FOR DEV PURPOSES ONLY AND WILL NOT BE PART OF THE PUBLISHED PACKAGE
// Before opening a PR you should build and test your changes using bin/balena // Before opening a PR you should build and test your changes using bin/balena
// **************************************************************************** // ****************************************************************************
@ -9,6 +9,18 @@
// operations otherwise, if the pool runs out. // operations otherwise, if the pool runs out.
process.env.UV_THREADPOOL_SIZE = '64'; process.env.UV_THREADPOOL_SIZE = '64';
// Allow balena-dev to work with oclif by temporarily
// pointing oclif config options to lib/ instead of build/
modifyOclifPaths();
// Undo changes on exit
process.on('exit', function() {
modifyOclifPaths(true);
});
// Undo changes in case of ctrl-v
process.on('SIGINT', function() {
modifyOclifPaths(true);
});
// Use fast-boot to cache require lookups, speeding up startup // Use fast-boot to cache require lookups, speeding up startup
require('fast-boot2').start({ require('fast-boot2').start({
cacheScope: __dirname + '/..', cacheScope: __dirname + '/..',
@ -30,3 +42,24 @@ require('ts-node').register({
transpileOnly: true, transpileOnly: true,
}); });
require('../lib/app').run(); require('../lib/app').run();
// Modify package.json oclif paths from build/ -> lib/, or vice versa
function modifyOclifPaths(revert) {
const fs = require('fs');
const path = './package.json';
const packageJson = fs.readFileSync(path, 'utf8');
const packageObj = JSON.parse(packageJson);
if(!packageObj.oclif) { return; }
let oclifSectionText = JSON.stringify(packageObj.oclif);
if(!revert) {
oclifSectionText = oclifSectionText.replace(/build/g, 'lib')
} else {
oclifSectionText = oclifSectionText.replace(/lib/g, 'build')
}
packageObj.oclif = JSON.parse(oclifSectionText);
fs.writeFileSync(path, `${JSON.stringify(packageObj, null, 2)}\n`, 'utf8');
}