balena-cli/patches/all/oclif+3.17.2.dev.patch
Otavio Jacobi f9f41eef4b Removes signing patches
Change-type: patch
2024-03-11 10:53:54 -03:00

149 lines
7.6 KiB
Diff

diff --git a/node_modules/oclif/lib/commands/pack/win.js b/node_modules/oclif/lib/commands/pack/win.js
index c0926bd..e4f645c 100644
--- a/node_modules/oclif/lib/commands/pack/win.js
+++ b/node_modules/oclif/lib/commands/pack/win.js
@@ -59,6 +59,12 @@ InstallDir "\$PROGRAMFILES${arch === 'x64' ? '64' : ''}\\${config.dirname}"
${customization}
Section "${config.name} CLI \${VERSION}"
+ ; First remove any old client files.
+ ; (Remnants of old versions were causing CLI errors)
+ ; Initially tried running the Uninstall.exe, but was
+ ; unable to make script wait for completion (despite using _?)
+ DetailPrint "Removing files from previous version."
+ RMDir /r "$INSTDIR\\client"
SetOutPath $INSTDIR
File /r bin
File /r client
diff --git a/node_modules/oclif/lib/tarballs/build.js b/node_modules/oclif/lib/tarballs/build.js
index 384ea4b..72ad66f 100644
--- a/node_modules/oclif/lib/tarballs/build.js
+++ b/node_modules/oclif/lib/tarballs/build.js
@@ -21,7 +21,8 @@ const pack = async (from, to) => {
await exec(`tar cfJ ${to} ${(path.basename(from))}`, { cwd }));
};
async function build(c, options = {}) {
- const { xz, config } = c;
+ const { xz, config, tmp } = c;
+ console.error(`[debug] oclif c.root="${c.root}" c.workspace()="${c.workspace()}"`);
const packCLI = async () => {
const { stdout } = await exec('npm pack --unsafe-perm', { cwd: c.root });
return path.join(c.root, stdout.trim().split('\n').pop());
@@ -30,7 +31,9 @@ async function build(c, options = {}) {
await fs.emptyDir(c.workspace());
const tarballNewLocation = path.join(c.workspace(), path.basename(tarball));
await fs.move(tarball, tarballNewLocation);
- await exec(`tar -xzf "${tarballNewLocation}"`, { cwd: c.workspace() });
+ let tarCmd = `tar -xzf "${tarballNewLocation}"`;
+ if (process.platform === 'win32') tarCmd += ' --force-local';
+ await exec(tarCmd, { cwd: c.workspace() });
await Promise.all((await fs.promises.readdir(path.join(c.workspace(), 'package'), { withFileTypes: true }))
.map(i => fs.move(path.join(c.workspace(), 'package', i.name), path.join(c.workspace(), i.name))));
await Promise.all([
@@ -38,6 +41,13 @@ async function build(c, options = {}) {
fs.promises.rm(path.join(c.workspace(), path.basename(tarball)), { recursive: true }),
fs.remove(path.join(c.workspace(), 'bin', 'run.cmd')),
]);
+ // rename the original balena-cli ./bin/balena entry point for oclif compatibility
+ await fs.move(path.join(c.workspace(), 'bin', 'balena'), path.join(c.workspace(), 'bin', 'run'));
+ // The oclif installers are a production installation, while the source
+ // `bin` folder may contain a `.fast-boot.json` file of a dev installation.
+ // This has previously led to issues preventing the CLI from starting, so
+ // delete `.fast-boot.json` (if any) from the destination folder.
+ await fs.promises.rm(path.join(c.workspace(), 'bin', '.fast-boot.json'));
};
const updatePJSON = async () => {
const pjsonPath = path.join(c.workspace(), 'package.json');
@@ -49,35 +59,20 @@ async function build(c, options = {}) {
await fs.writeJSON(pjsonPath, pjson, { spaces: 2 });
};
const addDependencies = async () => {
- const yarnRoot = findYarnWorkspaceRoot(c.root) || c.root;
- if (fs.existsSync(path.join(yarnRoot, 'yarn.lock'))) {
- await fs.copy(path.join(yarnRoot, 'yarn.lock'), path.join(c.workspace(), 'yarn.lock'));
- const yarnVersion = (await exec('yarn -v')).stdout.charAt(0);
- if (yarnVersion === '1') {
- await exec('yarn --no-progress --production --non-interactive', { cwd: c.workspace() });
- }
- else if (yarnVersion === '2') {
- throw new Error('Yarn 2 is not supported yet. Try using Yarn 1, or Yarn 3');
- }
- else {
- try {
- await exec('yarn workspaces focus --production', { cwd: c.workspace() });
- }
- catch (error) {
- if (error instanceof Error && error.message.includes('Command not found')) {
- throw new Error('Missing workspace tools. Run `yarn plugin import workspace-tools`.');
- }
- throw error;
- }
- }
- }
- else {
- const lockpath = fs.existsSync(path.join(c.root, 'package-lock.json')) ?
- path.join(c.root, 'package-lock.json') :
- path.join(c.root, 'npm-shrinkwrap.json');
- await fs.copy(lockpath, path.join(c.workspace(), path.basename(lockpath)));
- await exec('npm install --production', { cwd: c.workspace() });
+ const ws = c.workspace();
+ exec(`cd ${ws}`);
+ console.error(`[debug] oclif copying node_modules to "${ws}"`)
+ const source = path.join(c.root, 'node_modules');
+ if (process.platform === 'win32') {
+ await exec(`xcopy "${source}" "${ws}\\node_modules" /S /E /B /I /K /Q /Y`);
+ } else {
+ // use the shell's `cp` on macOS in order to preserve extended
+ // file attributes containing `codesign` digital signatures
+ await exec(`cp -pR "${source}" "${ws}"`);
}
+ console.error(`[debug] oclif running "npm prune --production" in "${ws}"`);
+ await exec('npm prune --production', { cwd: c.workspace() });
+ console.error(`[debug] oclif done`);
};
const pretarball = async () => {
const pjson = await fs.readJSON(path.join(c.workspace(), 'package.json'));
@@ -115,7 +110,8 @@ async function build(c, options = {}) {
output: path.join(workspace, 'bin', 'node'),
platform: target.platform,
arch: target.arch,
- tmp: path.join(config.root, 'tmp'),
+ tmp,
+ projectRootPath: c.root
});
if (options.pack === false)
return;
@@ -158,6 +154,7 @@ async function build(c, options = {}) {
await fs.writeJSON(manifestFilepath, manifest, { spaces: 2 });
};
(0, log_1.log)(`gathering workspace for ${config.bin} to ${c.workspace()}`);
+ console.error(`[debug] ${options.tarball}`);
await extractCLI(options.tarball ? options.tarball : await packCLI());
await updatePJSON();
await addDependencies();
diff --git a/node_modules/oclif/lib/tarballs/config.js b/node_modules/oclif/lib/tarballs/config.js
index 216759d..cab0e6e 100644
--- a/node_modules/oclif/lib/tarballs/config.js
+++ b/node_modules/oclif/lib/tarballs/config.js
@@ -25,7 +25,10 @@ async function gitSha(cwd, options = {}) {
}
exports.gitSha = gitSha;
async function Tmp(config) {
- const tmp = path.join(config.root, 'tmp');
+ const tmp = process.env.BUILD_TMP
+ ? path.join(process.env.BUILD_TMP, 'oclif')
+ : path.join(config.root, 'tmp');
+ console.error(`[debug] oclif tmp="${tmp}"`);
await fs.promises.mkdir(tmp, { recursive: true });
return tmp;
}
@@ -62,7 +65,7 @@ async function buildConfig(root, options = {}) {
s3Config: updateConfig.s3,
nodeVersion,
workspace(target) {
- const base = path.join(config.root, 'tmp');
+ const base = tmp;
if (target && target.platform)
return path.join(base, [target.platform, target.arch].join('-'), (0, upload_util_1.templateShortKey)('baseDir', { bin: config.bin }));
return path.join(base, (0, upload_util_1.templateShortKey)('baseDir', { bin: config.bin }));