balena CI integration: Patch @oclif/dev-cli to install 7zip on demand

Change-type: patch
Signed-off-by: Paulo Castro <paulo@balena.io>
This commit is contained in:
Paulo Castro 2019-06-03 16:02:32 +01:00
parent 751749325f
commit b5c4348de1
3 changed files with 124 additions and 28 deletions

View File

@ -36,7 +36,7 @@ index a9d4276..75c2f8b 100644
exports.default = PackWin;
const scripts = {
diff --git a/node_modules/@oclif/dev-cli/lib/tarballs/build.js b/node_modules/@oclif/dev-cli/lib/tarballs/build.js
index 3e613e0..4ed799c 100644
index 3e613e0..393516c 100644
--- a/node_modules/@oclif/dev-cli/lib/tarballs/build.js
+++ b/node_modules/@oclif/dev-cli/lib/tarballs/build.js
@@ -19,6 +19,9 @@ const pack = async (from, to) => {
@ -49,7 +49,7 @@ index 3e613e0..4ed799c 100644
const packCLI = async () => {
const stdout = await qq.x.stdout('npm', ['pack', '--unsafe-perm'], { cwd: c.root });
return path.join(c.root, stdout.split('\n').pop());
@@ -34,6 +37,21 @@ async function build(c, options = {}) {
@@ -34,6 +37,28 @@ async function build(c, options = {}) {
await qq.mv(f, '.');
await qq.rm('package', tarball, 'bin/run.cmd');
};
@ -64,14 +64,34 @@ index 3e613e0..4ed799c 100644
+ ];
+ for (const source of sources) {
+ console.log(`cp "${source}" -> "${ws}"`);
+ await qq.cp(path.join(c.root, source), ws);
+ try {
+ await qq.cp(path.join(c.root, source), ws);
+ } catch (err) {
+ // OK if package-lock.json doesn't exist
+ if (source !== 'package-lock.json') {
+ throw err;
+ }
+ }
+ }
+ await qq.rm('bin/run.cmd');
+ }
const updatePJSON = async () => {
qq.cd(c.workspace());
const pjson = await qq.readJSON('package.json');
@@ -124,7 +142,8 @@ async function build(c, options = {}) {
@@ -55,7 +80,11 @@ async function build(c, options = {}) {
if (!await qq.exists(lockpath)) {
lockpath = qq.join(c.root, 'npm-shrinkwrap.json');
}
- await qq.cp(lockpath, '.');
+ try {
+ await qq.cp(lockpath, '.');
+ } catch (err) {
+ console.log('WARNING: found neiter package-lock.json nor npm-shrinkwrap.json')
+ }
await qq.x('npm install --production');
}
};
@@ -124,7 +153,8 @@ async function build(c, options = {}) {
await qq.writeJSON(c.dist(config.s3Key('manifest')), manifest);
};
log_1.log(`gathering workspace for ${config.bin} to ${c.workspace()}`);
@ -82,22 +102,76 @@ index 3e613e0..4ed799c 100644
await addDependencies();
await bin_1.writeBinScripts({ config, baseWorkspace: c.workspace(), nodeVersion: c.nodeVersion });
diff --git a/node_modules/@oclif/dev-cli/lib/tarballs/node.js b/node_modules/@oclif/dev-cli/lib/tarballs/node.js
index 343eb00..7df1815 100644
index 343eb00..865d5a5 100644
--- a/node_modules/@oclif/dev-cli/lib/tarballs/node.js
+++ b/node_modules/@oclif/dev-cli/lib/tarballs/node.js
@@ -1,9 +1,11 @@
@@ -1,19 +1,45 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const errors_1 = require("@oclif/errors");
+const { isMSYS2 } = require('execa');
+const { isMSYS2 } = require('qqjs');
const path = require("path");
const qq = require("qqjs");
const log_1 = require("../log");
-async function checkFor7Zip() {
- try {
- await qq.x('7z', { stdio: [0, null, 2] });
+const { fixPath } = require("../util");
async function checkFor7Zip() {
try {
await qq.x('7z', { stdio: [0, null, 2] });
@@ -40,7 +42,8 @@ async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) {
+let try_install_7zip = true;
+async function checkFor7Zip(projectRootPath) {
+ let zPaths = [
+ fixPath(path.join(projectRootPath, 'node_modules', '7zip', '7zip-lite', '7z.exe')),
+ '7z',
+ ];
+ let foundPath = '';
+ for (const zPath of zPaths) {
+ try {
+ console.log(`probing 7zip at "${zPath}"...`);
+ await qq.x(zPath, { stdio: [0, null, 2] });
+ foundPath = zPath;
+ break;
+ }
+ catch (err) {}
}
- catch (err) {
- if (err.code === 127)
- errors_1.error('install 7-zip to package windows tarball');
- else
- throw err;
+ if (foundPath) {
+ console.log(`found 7zip at "${foundPath}"`);
+ } else if (try_install_7zip) {
+ try_install_7zip = false;
+ console.log(`attempting "npm install 7zip"...`);
+ qq.pushd(projectRootPath);
+ try {
+ await qq.x('npm', ['install', '--no-save', '7zip']);
+ } catch (err) {
+ errors_1.error('install 7-zip to package windows tarball', true);
+ } finally {
+ qq.popd();
+ }
+ return checkFor7Zip(projectRootPath);
+ } else {
+ errors_1.error('install 7-zip to package windows tarball', true);
}
+ return foundPath;
}
async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) {
if (arch === 'arm')
@@ -21,8 +47,9 @@ async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) {
let nodeBase = `node-v${nodeVersion}-${platform}-${arch}`;
let tarball = path.join(tmp, 'node', `${nodeBase}.tar.xz`);
let url = `https://nodejs.org/dist/v${nodeVersion}/${nodeBase}.tar.xz`;
- if (platform === 'win32') {
- await checkFor7Zip();
+ let zPath = '';
+ if (platform === 'win32') {
+ zPath = await checkFor7Zip(path.join(tmp, '..'));
nodeBase = `node-v${nodeVersion}-win-${arch}`;
tarball = path.join(tmp, 'node', `${nodeBase}.7z`);
url = `https://nodejs.org/dist/v${nodeVersion}/${nodeBase}.7z`;
@@ -40,7 +67,8 @@ async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) {
const basedir = path.dirname(tarball);
await qq.mkdirp(basedir);
await qq.download(url, tarball);
@ -107,32 +181,34 @@ index 343eb00..7df1815 100644
};
const extract = async () => {
log_1.log(`extracting ${nodeBase}`);
@@ -50,7 +53,7 @@ async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) {
@@ -50,7 +78,7 @@ async function fetchNodeBinary({ nodeVersion, output, platform, arch, tmp }) {
await qq.mkdirp(path.dirname(cache));
if (platform === 'win32') {
qq.pushd(nodeTmp);
- await qq.x(`7z x -bd -y ${tarball} > /dev/null`);
+ await qq.x(`7z x -bd -y ${fixPath(tarball)} > /dev/null`);
+ await qq.x(`"${zPath}" x -bd -y ${fixPath(tarball)} > /dev/null`);
await qq.mv([nodeBase, 'node.exe'], cache);
qq.popd();
}
diff --git a/node_modules/@oclif/dev-cli/lib/util.js b/node_modules/@oclif/dev-cli/lib/util.js
index 17368b4..7766d88 100644
index 17368b4..9d3fcf9 100644
--- a/node_modules/@oclif/dev-cli/lib/util.js
+++ b/node_modules/@oclif/dev-cli/lib/util.js
@@ -1,5 +1,6 @@
@@ -1,6 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+const { isCygwin, isMinGW, isMSYS2 } = require('execa');
const _ = require("lodash");
+const { isCygwin, isMinGW, isMSYS2 } = require('qqjs');
function castArray(input) {
if (input === undefined)
@@ -40,3 +41,16 @@ function sortBy(arr, fn) {
return [];
@@ -40,3 +41,17 @@ function sortBy(arr, fn) {
}
exports.sortBy = sortBy;
exports.template = (context) => (t) => _.template(t || '')(context);
+
+function fixPath(badPath) {
+ console.log(`fixPath MSYSTEM=${process.env.MSYSTEM} OSTYPE=${process.env.OSTYPE} isMSYS2=${isMSYS2} isMingGW=${isMinGW} isCygwin=${isCygwin}`);
+ // 'c:\myfolder' -> '/c/myfolder' or '/cygdrive/c/myfolder'
+ let fixed = badPath.replace(/\\/g, '/');
+ if (isMSYS2 || isMinGW) {

View File

@ -1,30 +1,26 @@
diff --git a/node_modules/qqjs/node_modules/execa/index.js b/node_modules/qqjs/node_modules/execa/index.js
index 06f3969..6251e17 100644
index 06f3969..7ab1b66 100644
--- a/node_modules/qqjs/node_modules/execa/index.js
+++ b/node_modules/qqjs/node_modules/execa/index.js
@@ -14,6 +14,21 @@ const stdio = require('./lib/stdio');
@@ -14,6 +14,17 @@ const stdio = require('./lib/stdio');
const TEN_MEGABYTES = 1000 * 1000 * 10;
+// OSTYPE is 'msys' for MSYS 1.0 and for MSYS2, or 'cygwin' for Cygwin
+// but note that OSTYPE is not "exported" by default, so run: export OSTYPE=$OSTYPE
+// MSYSTEM is 'MINGW32' for MSYS 1.0, 'MSYS' for MSYS2, and undefined for Cygwin
+const isCygwin = process.env.OSTYPE === 'cygwin'
+const isMinGW = process.env.MSYSTEM && process.env.MSYSTEM.startsWith('MINGW')
+const isMSYS2 = process.env.MSYSTEM && process.env.MSYSTEM.startsWith('MSYS')
+
+exports.isCygwin = isCygwin
+exports.isMinGW = isMinGW
+exports.isMSYS2 = isMSYS2
+const isCygwin = process.env.OSTYPE === 'cygwin';
+const isMinGW = process.env.MSYSTEM && process.env.MSYSTEM.startsWith('MINGW');
+const isMSYS2 = process.env.MSYSTEM && process.env.MSYSTEM.startsWith('MSYS');
+
+console.log(`[patched execa] detected "${
+ isCygwin ? 'Cygwin' : isMinGW ? 'MinGW' : isMSYS2 ? 'MSYS2' : 'standard'
+}" environment (MSYSTEM="${process.env.MSYSTEM}")`)
+}" environment (MSYSTEM="${process.env.MSYSTEM}")`);
+
function handleArgs(cmd, args, opts) {
let parsed;
@@ -104,13 +119,21 @@ function handleShell(fn, cmd, opts) {
@@ -104,13 +115,21 @@ function handleShell(fn, cmd, opts) {
opts = Object.assign({}, opts);
@ -47,3 +43,11 @@ index 06f3969..6251e17 100644
if (opts.shell) {
file = opts.shell;
delete opts.shell;
@@ -364,3 +383,7 @@ module.exports.sync = (cmd, args, opts) => {
module.exports.shellSync = (cmd, opts) => handleShell(module.exports.sync, cmd, opts);
module.exports.spawn = util.deprecate(module.exports, 'execa.spawn() is deprecated. Use execa() instead.');
+
+module.exports.isCygwin = isCygwin;
+module.exports.isMinGW = isMinGW;
+module.exports.isMSYS2 = isMSYS2;

16
patches/qqjs+0.3.10.patch Normal file
View File

@ -0,0 +1,16 @@
diff --git a/node_modules/qqjs/lib/exec.js b/node_modules/qqjs/lib/exec.js
index 835f565..84bb5be 100644
--- a/node_modules/qqjs/lib/exec.js
+++ b/node_modules/qqjs/lib/exec.js
@@ -5,6 +5,11 @@ const m = {
m: {},
get execa() { return this.m.execa = this.m.execa || require('execa'); },
};
+const { isCygwin, isMinGW, isMSYS2 } = require('execa');
+exports.isCygwin = isCygwin;
+exports.isMinGW = isMinGW;
+exports.isMSYS2 = isMSYS2;
+console.log(`qqjs exec.js MSYSTEM=${process.env.MSYSTEM} OSTYPE=${process.env.OSTYPE} isMSYS2=${isMSYS2} isMingGW=${isMinGW} isCygwin=${isCygwin}`);
/**
* easy access to process.env
*/