From 97791ad51347c72c85227e01f058f4d47757f8c7 Mon Sep 17 00:00:00 2001 From: Rodrigo Espinosa de los Monteros <1084688+RodEsp@users.noreply.github.com> Date: Thu, 30 Sep 2021 12:11:38 -0400 Subject: [PATCH] feat: use npm postinstall script to install sf --- bin/run-sf | 15 --------------- package.json | 14 ++++++-------- scripts/include-sf.js | 15 ++++++++++----- 3 files changed, 16 insertions(+), 28 deletions(-) delete mode 100755 bin/run-sf diff --git a/bin/run-sf b/bin/run-sf deleted file mode 100755 index 6923a483..00000000 --- a/bin/run-sf +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env node - -const cp = require('child_process'); -const path = require('path'); - -function trimUntil(fsPath, part) { - const parts = fsPath.split(path.sep); - const partIndex = parts.findIndex((p) => part === p); - if (partIndex === -1) return fsPath; - return parts.slice(0, partIndex + 1).join(path.sep); -} - -const modulePath = require.resolve('@salesforce/cli'); -const sfPath = path.join(trimUntil(modulePath, 'cli'), 'bin', 'run'); -cp.spawn(sfPath, process.argv.slice(2), { stdio: 'inherit', shell: true }); diff --git a/package.json b/package.json index 86eacc59..9cb84198 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,7 @@ "homepage": "https://github.com/salesforcecli/sfdx-cli/", "repository": "salesforcecli/sfdx-cli", "bin": { - "sfdx": "bin/run", - "sf": "bin/run-sf" + "sfdx": "bin/run" }, "engines": { "node": ">=10" @@ -90,7 +89,6 @@ } }, "pinnedDependencies": [ - "@salesforce/cli", "@salesforce/plugin-alias", "@salesforce/plugin-apex", "@salesforce/plugin-auth", @@ -119,7 +117,6 @@ "@oclif/plugin-update": "1.5.0", "@oclif/plugin-warn-if-update-available": "^1.7.0", "@oclif/plugin-which": "^1.0.3", - "@salesforce/cli": "1.0.5", "@salesforce/kit": "^1.5.13", "@salesforce/lazy-require": "^0.4.0", "@salesforce/plugin-alias": "1.1.21", @@ -204,24 +201,25 @@ "lint": "eslint \"src/**/*.ts\"", "oclif-artifacts": "oclif manifest", "pack:deb": "oclif pack:deb", - "pack:docker:slim": "./scripts/docker-publish-slim.js", "pack:docker:full": "./scripts/docker-publish-full.js", + "pack:docker:slim": "./scripts/docker-publish-slim.js", "pack:macos": "oclif pack:macos", - "pretarball": "sf-release cli:tarballs:prepare && ./scripts/include-sf.js", "pack:tarballs": "oclif pack:tarballs", "pack:verify": "sf-release cli:tarballs:verify", "pack:win": "oclif pack:win", + "postinstall": "npm install @salesforce/cli -g", "postpack": "rm -f oclif.manifest.json", "posttest": "yarn test:deprecation-policy ", "prepack": "yarn compile && yarn lint && yarn oclif-artifacts", "prepare": "yarn compile && yarn lint", - "promote": "oclif promote", + "pretarball": "sf-release cli:tarballs:prepare && ./scripts/include-sf.js", "promote-dist-tags": "./scripts/promote-dist-tags", "promote-docker": "./scripts/docker-promote.js", + "promote": "oclif promote", "snapshot-generate": "HOME=./ ./bin/run snapshot:generate", - "test": "mocha --recursive \"test/**/*.ts\" && nyc --report lcov --report cobertura mocha -t 240000 --require source-map-support/register --recursive \"dist/**/*.test.js\"", "test-smoke-unix": "./tmp/sfdx/bin/sfdx version && ./tmp/sfdx/bin/sfdx help && ./tmp/sfdx/bin/sfdx plugins --core", "test:deprecation-policy": "set HOME=./ ./bin/run snapshot:compare", + "test": "mocha --recursive \"test/**/*.ts\" && nyc --report lcov --report cobertura mocha -t 240000 --require source-map-support/register --recursive \"dist/**/*.test.js\"", "trogdor": "yarn clean-all && yarn && yarn compile && yarn uts", "upload:deb": "oclif upload:deb", "upload:macos": "oclif upload:macos", diff --git a/scripts/include-sf.js b/scripts/include-sf.js index 1958dc6a..7e3c23d2 100755 --- a/scripts/include-sf.js +++ b/scripts/include-sf.js @@ -4,14 +4,15 @@ const path = require('path'); const shelljs = require('shelljs'); const fs = require('fs'); -const sfUnixPath = 'node_modules/@salesforce/cli/bin/run'; +const sfGlobalPath = path.join(shelljs.exec('npm list -g --depth 0 | head -1'), 'node_modules', '@salesforce', 'cli'); + +// Copy sf to the bin/cli dir of sfdx +shelljs.mv('-f', sfGlobalPath, path.join(process.cwd(), 'bin', 'sf-cli')); + +const sfUnixPath = 'bin/sf-cli/bin/run'; const sfBin = path.join('bin', 'sf'); const sfdxBin = path.join('bin', 'sfdx'); -const sfWinPath = 'node_modules\\@salesforce\\cli\\bin\\run'; -const sfCmd = path.join('bin', 'sf.cmd'); -const sfdxCmd = path.join('bin', 'sfdx.cmd'); - console.log(`---- Including SF ----`); console.log(` Updating ${sfdxBin} with references to sf`); const binContents = fs @@ -24,6 +25,10 @@ console.log(` Writing ${sfBin}`); fs.writeFileSync(sfBin, binContents); shelljs.chmod('+x', sfBin); +const sfWinPath = 'bin\\sf-cli\\bin\\run'; +const sfCmd = path.join('bin', 'sf.cmd'); +const sfdxCmd = path.join('bin', 'sfdx.cmd'); + console.log(` Updating ${sfCmd} with references to sf`); const cmdContents = fs .readFileSync(sfdxCmd, 'UTF-8')