diff --git a/install/action.yml b/install/action.yml index e2f225d1..b3f982ed 100644 --- a/install/action.yml +++ b/install/action.yml @@ -5,12 +5,16 @@ runs: using: node12 main: main.js inputs: + directory: + description: |- + If present, the action will execute from this directory + required: false tool_versions: - description: + description: |- If present, this value will be written to the .tool-versions file. required: false before_install: - description: + description: |- Bash script to run after plugins are installed but before `asdf install`. eg, to install npm keyring required: false diff --git a/install/main.js b/install/main.js index 11004f09..a733b7d8 100644 --- a/install/main.js +++ b/install/main.js @@ -296,9 +296,37 @@ var require_core = __commonJS((exports2) => { exports2.getState = getState; }); -// node_modules/@actions/io/lib/io-util.js +// node_modules/@actions/exec/node_modules/@actions/io/lib/io-util.js var require_io_util = __commonJS((exports2) => { "use strict"; + var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + Object.defineProperty(o, k2, {enumerable: true, get: function() { + return m[k]; + }}); + } : function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + o[k2] = m[k]; + }); + var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", {enumerable: true, value: v}); + } : function(o, v) { + o["default"] = v; + }); + var __importStar = exports2 && exports2.__importStar || function(mod) { + if (mod && mod.__esModule) + return mod; + var result = {}; + if (mod != null) { + for (var k in mod) + if (k !== "default" && Object.hasOwnProperty.call(mod, k)) + __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; + }; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function(resolve) { @@ -328,9 +356,9 @@ var require_io_util = __commonJS((exports2) => { }; var _a; Object.defineProperty(exports2, "__esModule", {value: true}); - var assert_1 = require("assert"); - var fs2 = require("fs"); - var path2 = require("path"); + exports2.getCmdPath = exports2.tryGetExecutablePath = exports2.isRooted = exports2.isDirectory = exports2.exists = exports2.IS_WINDOWS = exports2.unlink = exports2.symlink = exports2.stat = exports2.rmdir = exports2.rename = exports2.readlink = exports2.readdir = exports2.mkdir = exports2.lstat = exports2.copyFile = exports2.chmod = void 0; + var fs2 = __importStar(require("fs")); + var path2 = __importStar(require("path")); _a = fs2.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; exports2.IS_WINDOWS = process.platform === "win32"; function exists(fsPath) { @@ -365,37 +393,6 @@ var require_io_util = __commonJS((exports2) => { return p.startsWith("/"); } exports2.isRooted = isRooted; - function mkdirP(fsPath, maxDepth = 1e3, depth = 1) { - return __awaiter(this, void 0, void 0, function* () { - assert_1.ok(fsPath, "a path argument must be provided"); - fsPath = path2.resolve(fsPath); - if (depth >= maxDepth) - return exports2.mkdir(fsPath); - try { - yield exports2.mkdir(fsPath); - return; - } catch (err) { - switch (err.code) { - case "ENOENT": { - yield mkdirP(path2.dirname(fsPath), maxDepth, depth + 1); - yield exports2.mkdir(fsPath); - return; - } - default: { - let stats; - try { - stats = yield exports2.stat(fsPath); - } catch (err2) { - throw err; - } - if (!stats.isDirectory()) - throw err; - } - } - } - }); - } - exports2.mkdirP = mkdirP; function tryGetExecutablePath(filePath, extensions) { return __awaiter(this, void 0, void 0, function* () { let stats = void 0; @@ -466,11 +463,44 @@ var require_io_util = __commonJS((exports2) => { function isUnixExecutable(stats) { return (stats.mode & 1) > 0 || (stats.mode & 8) > 0 && stats.gid === process.getgid() || (stats.mode & 64) > 0 && stats.uid === process.getuid(); } + function getCmdPath() { + var _a2; + return (_a2 = process.env["COMSPEC"]) !== null && _a2 !== void 0 ? _a2 : `cmd.exe`; + } + exports2.getCmdPath = getCmdPath; }); -// node_modules/@actions/io/lib/io.js +// node_modules/@actions/exec/node_modules/@actions/io/lib/io.js var require_io = __commonJS((exports2) => { "use strict"; + var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + Object.defineProperty(o, k2, {enumerable: true, get: function() { + return m[k]; + }}); + } : function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + o[k2] = m[k]; + }); + var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", {enumerable: true, value: v}); + } : function(o, v) { + o["default"] = v; + }); + var __importStar = exports2 && exports2.__importStar || function(mod) { + if (mod && mod.__esModule) + return mod; + var result = {}; + if (mod != null) { + for (var k in mod) + if (k !== "default" && Object.hasOwnProperty.call(mod, k)) + __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; + }; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function(resolve) { @@ -499,19 +529,22 @@ var require_io = __commonJS((exports2) => { }); }; Object.defineProperty(exports2, "__esModule", {value: true}); - var childProcess = require("child_process"); - var path2 = require("path"); + exports2.findInPath = exports2.which = exports2.mkdirP = exports2.rmRF = exports2.mv = exports2.cp = void 0; + var assert_1 = require("assert"); + var childProcess = __importStar(require("child_process")); + var path2 = __importStar(require("path")); var util_1 = require("util"); - var ioUtil = require_io_util(); + var ioUtil = __importStar(require_io_util()); var exec7 = util_1.promisify(childProcess.exec); + var execFile = util_1.promisify(childProcess.execFile); function cp(source, dest, options = {}) { return __awaiter(this, void 0, void 0, function* () { - const {force, recursive} = readCopyOptions(options); + const {force, recursive, copySourceDirectory} = readCopyOptions(options); const destStat = (yield ioUtil.exists(dest)) ? yield ioUtil.stat(dest) : null; if (destStat && destStat.isFile() && !force) { return; } - const newDest = destStat && destStat.isDirectory() ? path2.join(dest, path2.basename(source)) : dest; + const newDest = destStat && destStat.isDirectory() && copySourceDirectory ? path2.join(dest, path2.basename(source)) : dest; if (!(yield ioUtil.exists(source))) { throw new Error(`no such file or directory: ${source}`); } @@ -555,11 +588,19 @@ var require_io = __commonJS((exports2) => { function rmRF(inputPath) { return __awaiter(this, void 0, void 0, function* () { if (ioUtil.IS_WINDOWS) { + if (/[*"<>|]/.test(inputPath)) { + throw new Error('File path must not contain `*`, `"`, `<`, `>` or `|` on Windows'); + } try { + const cmdPath = ioUtil.getCmdPath(); if (yield ioUtil.isDirectory(inputPath, true)) { - yield exec7(`rd /s /q "${inputPath}"`); + yield exec7(`${cmdPath} /s /c "rd /s /q "%inputPath%""`, { + env: {inputPath} + }); } else { - yield exec7(`del /f /a "${inputPath}"`); + yield exec7(`${cmdPath} /s /c "del /f /a "%inputPath%""`, { + env: {inputPath} + }); } } catch (err) { if (err.code !== "ENOENT") @@ -581,7 +622,7 @@ var require_io = __commonJS((exports2) => { return; } if (isDir) { - yield exec7(`rm -rf "${inputPath}"`); + yield execFile(`rm`, [`-rf`, `${inputPath}`]); } else { yield ioUtil.unlink(inputPath); } @@ -591,7 +632,8 @@ var require_io = __commonJS((exports2) => { exports2.rmRF = rmRF; function mkdirP(fsPath) { return __awaiter(this, void 0, void 0, function* () { - yield ioUtil.mkdirP(fsPath); + assert_1.ok(fsPath, "a path argument must be provided"); + yield ioUtil.mkdir(fsPath, {recursive: true}); }); } exports2.mkdirP = mkdirP; @@ -609,51 +651,63 @@ var require_io = __commonJS((exports2) => { throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`); } } + return result; } - try { - const extensions = []; - if (ioUtil.IS_WINDOWS && process.env.PATHEXT) { - for (const extension of process.env.PATHEXT.split(path2.delimiter)) { - if (extension) { - extensions.push(extension); - } - } - } - if (ioUtil.isRooted(tool)) { - const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions); - if (filePath) { - return filePath; + const matches = yield findInPath(tool); + if (matches && matches.length > 0) { + return matches[0]; + } + return ""; + }); + } + exports2.which = which2; + function findInPath(tool) { + return __awaiter(this, void 0, void 0, function* () { + if (!tool) { + throw new Error("parameter 'tool' is required"); + } + const extensions = []; + if (ioUtil.IS_WINDOWS && process.env["PATHEXT"]) { + for (const extension of process.env["PATHEXT"].split(path2.delimiter)) { + if (extension) { + extensions.push(extension); } - return ""; } - if (tool.includes("/") || ioUtil.IS_WINDOWS && tool.includes("\\")) { - return ""; + } + if (ioUtil.isRooted(tool)) { + const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions); + if (filePath) { + return [filePath]; } - const directories = []; - if (process.env.PATH) { - for (const p of process.env.PATH.split(path2.delimiter)) { - if (p) { - directories.push(p); - } + return []; + } + if (tool.includes(path2.sep)) { + return []; + } + const directories = []; + if (process.env.PATH) { + for (const p of process.env.PATH.split(path2.delimiter)) { + if (p) { + directories.push(p); } } - for (const directory of directories) { - const filePath = yield ioUtil.tryGetExecutablePath(directory + path2.sep + tool, extensions); - if (filePath) { - return filePath; - } + } + const matches = []; + for (const directory of directories) { + const filePath = yield ioUtil.tryGetExecutablePath(path2.join(directory, tool), extensions); + if (filePath) { + matches.push(filePath); } - return ""; - } catch (err) { - throw new Error(`which failed with message ${err.message}`); } + return matches; }); } - exports2.which = which2; + exports2.findInPath = findInPath; function readCopyOptions(options) { const force = options.force == null ? true : options.force; const recursive = Boolean(options.recursive); - return {force, recursive}; + const copySourceDirectory = options.copySourceDirectory == null ? true : Boolean(options.copySourceDirectory); + return {force, recursive, copySourceDirectory}; } function cpDirRecursive(sourceDir, destDir, currentDepth, force) { return __awaiter(this, void 0, void 0, function* () { @@ -1211,96 +1265,500 @@ var require_exec = __commonJS((exports2) => { exports2.exec = exec7; }); -// lib/install/main.ts -var core4 = __toModule(require_core()); - -// lib/install/index.ts -var core3 = __toModule(require_core()); -var exec5 = __toModule(require_exec()); - -// lib/plugins-add/index.ts -var core2 = __toModule(require_core()); -var exec3 = __toModule(require_exec()); -var fs = __toModule(require("fs")); - -// lib/setup/index.ts -var core = __toModule(require_core()); -var exec = __toModule(require_exec()); -var io = __toModule(require_io()); -var os = __toModule(require("os")); -var path = __toModule(require("path")); -async function setupAsdf() { - const asdfPath = await io.which("asdf", false); - if (asdfPath) { - return; - } - const asdfDir = path.join(os.homedir(), ".asdf"); - core.exportVariable("ASDF_DIR", asdfDir); - core.exportVariable("ASDF_DATA_DIR", asdfDir); - core.addPath(`${asdfDir}/bin`); - core.addPath(`${asdfDir}/shims`); - core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); - const branch = core.getInput("asdf_branch", {required: true}); - await exec.exec("git", [ - "clone", - "--depth", - "1", - "--branch", - branch, - "https://github.com/asdf-vm/asdf.git", - asdfDir - ]); -} - -// lib/plugins-add/index.ts -async function pluginList() { - let stdout = ""; - let stderr = ""; - const options = { - listeners: { - stdout: (data) => { - stdout += data.toString(); - }, - stderr: (data) => { - stderr += data.toString(); - } +// node_modules/@actions/io/lib/io-util.js +var require_io_util2 = __commonJS((exports2) => { + "use strict"; + var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); }; - try { - await exec3.exec("asdf", ["plugin-list"], options); - } catch (err) { - if (!/No plugins installed/.test(stderr)) { - throw err; - } - } - return stdout.split("\n"); -} -async function pluginsAdd() { - await setupAsdf(); - let toolVersions = core2.getInput("tool_versions", {required: false}); - if (toolVersions) { - await fs.promises.writeFile(".tool-versions", toolVersions, { - encoding: "utf8" + var _a; + Object.defineProperty(exports2, "__esModule", {value: true}); + var assert_1 = require("assert"); + var fs2 = require("fs"); + var path2 = require("path"); + _a = fs2.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; + exports2.IS_WINDOWS = process.platform === "win32"; + function exists(fsPath) { + return __awaiter(this, void 0, void 0, function* () { + try { + yield exports2.stat(fsPath); + } catch (err) { + if (err.code === "ENOENT") { + return false; + } + throw err; + } + return true; }); - } else { - toolVersions = await fs.promises.readFile(".tool-versions", { - encoding: "utf8" + } + exports2.exists = exists; + function isDirectory(fsPath, useStat = false) { + return __awaiter(this, void 0, void 0, function* () { + const stats = useStat ? yield exports2.stat(fsPath) : yield exports2.lstat(fsPath); + return stats.isDirectory(); }); } - const pluginNames = toolVersions.split("\n").map((x) => x.replace(/#.*/, "").trim()).filter((x) => x.length > 0).map((x) => x.split(" ")[0]); - const installedPluginNames = await pluginList(); - for (const pluginName of pluginNames) { - if (installedPluginNames.includes(pluginName)) { - core2.info(`Skip installing ${pluginName} plugin since it's already installed`); - } else { - core2.info(`Installing ${pluginName} plugin...`); - await exec3.exec("asdf", ["plugin-add", pluginName]); + exports2.isDirectory = isDirectory; + function isRooted(p) { + p = normalizeSeparators(p); + if (!p) { + throw new Error('isRooted() parameter "p" cannot be empty'); + } + if (exports2.IS_WINDOWS) { + return p.startsWith("\\") || /^[A-Z]:/i.test(p); } + return p.startsWith("/"); } -} + exports2.isRooted = isRooted; + function mkdirP(fsPath, maxDepth = 1e3, depth = 1) { + return __awaiter(this, void 0, void 0, function* () { + assert_1.ok(fsPath, "a path argument must be provided"); + fsPath = path2.resolve(fsPath); + if (depth >= maxDepth) + return exports2.mkdir(fsPath); + try { + yield exports2.mkdir(fsPath); + return; + } catch (err) { + switch (err.code) { + case "ENOENT": { + yield mkdirP(path2.dirname(fsPath), maxDepth, depth + 1); + yield exports2.mkdir(fsPath); + return; + } + default: { + let stats; + try { + stats = yield exports2.stat(fsPath); + } catch (err2) { + throw err; + } + if (!stats.isDirectory()) + throw err; + } + } + } + }); + } + exports2.mkdirP = mkdirP; + function tryGetExecutablePath(filePath, extensions) { + return __awaiter(this, void 0, void 0, function* () { + let stats = void 0; + try { + stats = yield exports2.stat(filePath); + } catch (err) { + if (err.code !== "ENOENT") { + console.log(`Unexpected error attempting to determine if executable file exists '${filePath}': ${err}`); + } + } + if (stats && stats.isFile()) { + if (exports2.IS_WINDOWS) { + const upperExt = path2.extname(filePath).toUpperCase(); + if (extensions.some((validExt) => validExt.toUpperCase() === upperExt)) { + return filePath; + } + } else { + if (isUnixExecutable(stats)) { + return filePath; + } + } + } + const originalFilePath = filePath; + for (const extension of extensions) { + filePath = originalFilePath + extension; + stats = void 0; + try { + stats = yield exports2.stat(filePath); + } catch (err) { + if (err.code !== "ENOENT") { + console.log(`Unexpected error attempting to determine if executable file exists '${filePath}': ${err}`); + } + } + if (stats && stats.isFile()) { + if (exports2.IS_WINDOWS) { + try { + const directory = path2.dirname(filePath); + const upperName = path2.basename(filePath).toUpperCase(); + for (const actualName of yield exports2.readdir(directory)) { + if (upperName === actualName.toUpperCase()) { + filePath = path2.join(directory, actualName); + break; + } + } + } catch (err) { + console.log(`Unexpected error attempting to determine the actual case of the file '${filePath}': ${err}`); + } + return filePath; + } else { + if (isUnixExecutable(stats)) { + return filePath; + } + } + } + } + return ""; + }); + } + exports2.tryGetExecutablePath = tryGetExecutablePath; + function normalizeSeparators(p) { + p = p || ""; + if (exports2.IS_WINDOWS) { + p = p.replace(/\//g, "\\"); + return p.replace(/\\\\+/g, "\\"); + } + return p.replace(/\/\/+/g, "/"); + } + function isUnixExecutable(stats) { + return (stats.mode & 1) > 0 || (stats.mode & 8) > 0 && stats.gid === process.getgid() || (stats.mode & 64) > 0 && stats.uid === process.getuid(); + } +}); + +// node_modules/@actions/io/lib/io.js +var require_io2 = __commonJS((exports2) => { + "use strict"; + var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + }; + Object.defineProperty(exports2, "__esModule", {value: true}); + var childProcess = require("child_process"); + var path2 = require("path"); + var util_1 = require("util"); + var ioUtil = require_io_util2(); + var exec7 = util_1.promisify(childProcess.exec); + function cp(source, dest, options = {}) { + return __awaiter(this, void 0, void 0, function* () { + const {force, recursive} = readCopyOptions(options); + const destStat = (yield ioUtil.exists(dest)) ? yield ioUtil.stat(dest) : null; + if (destStat && destStat.isFile() && !force) { + return; + } + const newDest = destStat && destStat.isDirectory() ? path2.join(dest, path2.basename(source)) : dest; + if (!(yield ioUtil.exists(source))) { + throw new Error(`no such file or directory: ${source}`); + } + const sourceStat = yield ioUtil.stat(source); + if (sourceStat.isDirectory()) { + if (!recursive) { + throw new Error(`Failed to copy. ${source} is a directory, but tried to copy without recursive flag.`); + } else { + yield cpDirRecursive(source, newDest, 0, force); + } + } else { + if (path2.relative(source, newDest) === "") { + throw new Error(`'${newDest}' and '${source}' are the same file`); + } + yield copyFile(source, newDest, force); + } + }); + } + exports2.cp = cp; + function mv(source, dest, options = {}) { + return __awaiter(this, void 0, void 0, function* () { + if (yield ioUtil.exists(dest)) { + let destExists = true; + if (yield ioUtil.isDirectory(dest)) { + dest = path2.join(dest, path2.basename(source)); + destExists = yield ioUtil.exists(dest); + } + if (destExists) { + if (options.force == null || options.force) { + yield rmRF(dest); + } else { + throw new Error("Destination already exists"); + } + } + } + yield mkdirP(path2.dirname(dest)); + yield ioUtil.rename(source, dest); + }); + } + exports2.mv = mv; + function rmRF(inputPath) { + return __awaiter(this, void 0, void 0, function* () { + if (ioUtil.IS_WINDOWS) { + try { + if (yield ioUtil.isDirectory(inputPath, true)) { + yield exec7(`rd /s /q "${inputPath}"`); + } else { + yield exec7(`del /f /a "${inputPath}"`); + } + } catch (err) { + if (err.code !== "ENOENT") + throw err; + } + try { + yield ioUtil.unlink(inputPath); + } catch (err) { + if (err.code !== "ENOENT") + throw err; + } + } else { + let isDir = false; + try { + isDir = yield ioUtil.isDirectory(inputPath); + } catch (err) { + if (err.code !== "ENOENT") + throw err; + return; + } + if (isDir) { + yield exec7(`rm -rf "${inputPath}"`); + } else { + yield ioUtil.unlink(inputPath); + } + } + }); + } + exports2.rmRF = rmRF; + function mkdirP(fsPath) { + return __awaiter(this, void 0, void 0, function* () { + yield ioUtil.mkdirP(fsPath); + }); + } + exports2.mkdirP = mkdirP; + function which2(tool, check) { + return __awaiter(this, void 0, void 0, function* () { + if (!tool) { + throw new Error("parameter 'tool' is required"); + } + if (check) { + const result = yield which2(tool, false); + if (!result) { + if (ioUtil.IS_WINDOWS) { + throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.`); + } else { + throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`); + } + } + } + try { + const extensions = []; + if (ioUtil.IS_WINDOWS && process.env.PATHEXT) { + for (const extension of process.env.PATHEXT.split(path2.delimiter)) { + if (extension) { + extensions.push(extension); + } + } + } + if (ioUtil.isRooted(tool)) { + const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions); + if (filePath) { + return filePath; + } + return ""; + } + if (tool.includes("/") || ioUtil.IS_WINDOWS && tool.includes("\\")) { + return ""; + } + const directories = []; + if (process.env.PATH) { + for (const p of process.env.PATH.split(path2.delimiter)) { + if (p) { + directories.push(p); + } + } + } + for (const directory of directories) { + const filePath = yield ioUtil.tryGetExecutablePath(directory + path2.sep + tool, extensions); + if (filePath) { + return filePath; + } + } + return ""; + } catch (err) { + throw new Error(`which failed with message ${err.message}`); + } + }); + } + exports2.which = which2; + function readCopyOptions(options) { + const force = options.force == null ? true : options.force; + const recursive = Boolean(options.recursive); + return {force, recursive}; + } + function cpDirRecursive(sourceDir, destDir, currentDepth, force) { + return __awaiter(this, void 0, void 0, function* () { + if (currentDepth >= 255) + return; + currentDepth++; + yield mkdirP(destDir); + const files = yield ioUtil.readdir(sourceDir); + for (const fileName of files) { + const srcFile = `${sourceDir}/${fileName}`; + const destFile = `${destDir}/${fileName}`; + const srcFileStat = yield ioUtil.lstat(srcFile); + if (srcFileStat.isDirectory()) { + yield cpDirRecursive(srcFile, destFile, currentDepth, force); + } else { + yield copyFile(srcFile, destFile, force); + } + } + yield ioUtil.chmod(destDir, (yield ioUtil.stat(sourceDir)).mode); + }); + } + function copyFile(srcFile, destFile, force) { + return __awaiter(this, void 0, void 0, function* () { + if ((yield ioUtil.lstat(srcFile)).isSymbolicLink()) { + try { + yield ioUtil.lstat(destFile); + yield ioUtil.unlink(destFile); + } catch (e) { + if (e.code === "EPERM") { + yield ioUtil.chmod(destFile, "0666"); + yield ioUtil.unlink(destFile); + } + } + const symlinkFull = yield ioUtil.readlink(srcFile); + yield ioUtil.symlink(symlinkFull, destFile, ioUtil.IS_WINDOWS ? "junction" : null); + } else if (!(yield ioUtil.exists(destFile)) || force) { + yield ioUtil.copyFile(srcFile, destFile); + } + }); + } +}); + +// lib/install/main.ts +var core4 = __toModule(require_core()); + +// lib/install/index.ts +var core3 = __toModule(require_core()); +var exec5 = __toModule(require_exec()); + +// lib/plugins-add/index.ts +var core2 = __toModule(require_core()); +var exec3 = __toModule(require_exec()); +var fs = __toModule(require("fs")); + +// lib/setup/index.ts +var core = __toModule(require_core()); +var exec = __toModule(require_exec()); +var io = __toModule(require_io2()); +var os = __toModule(require("os")); +var path = __toModule(require("path")); +async function setupAsdf() { + const asdfPath = await io.which("asdf", false); + if (asdfPath) { + return; + } + const asdfDir = path.join(os.homedir(), ".asdf"); + core.exportVariable("ASDF_DIR", asdfDir); + core.exportVariable("ASDF_DATA_DIR", asdfDir); + core.addPath(`${asdfDir}/bin`); + core.addPath(`${asdfDir}/shims`); + core.info(`Cloning asdf into ASDF_DIR: ${asdfDir}`); + const branch = core.getInput("asdf_branch", {required: true}); + await exec.exec("git", [ + "clone", + "--depth", + "1", + "--branch", + branch, + "https://github.com/asdf-vm/asdf.git", + asdfDir + ]); +} + +// lib/plugins-add/index.ts +async function pluginList() { + let stdout = ""; + let stderr = ""; + const options = { + listeners: { + stdout: (data) => { + stdout += data.toString(); + }, + stderr: (data) => { + stderr += data.toString(); + } + } + }; + try { + await exec3.exec("asdf", ["plugin-list"], options); + } catch (err) { + if (!/No plugins installed/.test(stderr)) { + throw err; + } + } + return stdout.split("\n"); +} +async function pluginsAdd() { + await setupAsdf(); + let toolVersions = core2.getInput("tool_versions", {required: false}); + if (toolVersions) { + await fs.promises.writeFile(".tool-versions", toolVersions, { + encoding: "utf8" + }); + } else { + toolVersions = await fs.promises.readFile(".tool-versions", { + encoding: "utf8" + }); + } + const pluginNames = toolVersions.split("\n").map((x) => x.replace(/#.*/, "").trim()).filter((x) => x.length > 0).map((x) => x.split(" ")[0]); + const installedPluginNames = await pluginList(); + for (const pluginName of pluginNames) { + if (installedPluginNames.includes(pluginName)) { + core2.info(`Skip installing ${pluginName} plugin since it's already installed`); + } else { + core2.info(`Installing ${pluginName} plugin...`); + await exec3.exec("asdf", ["plugin-add", pluginName]); + } + } +} // lib/install/index.ts async function toolsInstall() { + const dir = core3.getInput("directory", {required: false}); + if (dir) { + process.chdir(dir); + } await pluginsAdd(); const before = core3.getInput("before_install", {required: false}); if (before) { diff --git a/lib/install/index.ts b/lib/install/index.ts index 859ec1ba..1f156f10 100644 --- a/lib/install/index.ts +++ b/lib/install/index.ts @@ -3,6 +3,11 @@ import * as exec from "@actions/exec"; import { pluginsAdd } from "../plugins-add"; export async function toolsInstall(): Promise { + const dir = core.getInput("directory", { required: false }); + if (dir) { + process.chdir(dir); + } + await pluginsAdd(); const before = core.getInput("before_install", { required: false }); diff --git a/plugin-test/main.js b/plugin-test/main.js index bd92e25e..533e9ddc 100644 --- a/plugin-test/main.js +++ b/plugin-test/main.js @@ -296,9 +296,37 @@ var require_core = __commonJS((exports2) => { exports2.getState = getState; }); -// node_modules/@actions/io/lib/io-util.js +// node_modules/@actions/exec/node_modules/@actions/io/lib/io-util.js var require_io_util = __commonJS((exports2) => { "use strict"; + var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + Object.defineProperty(o, k2, {enumerable: true, get: function() { + return m[k]; + }}); + } : function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + o[k2] = m[k]; + }); + var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", {enumerable: true, value: v}); + } : function(o, v) { + o["default"] = v; + }); + var __importStar = exports2 && exports2.__importStar || function(mod) { + if (mod && mod.__esModule) + return mod; + var result = {}; + if (mod != null) { + for (var k in mod) + if (k !== "default" && Object.hasOwnProperty.call(mod, k)) + __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; + }; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function(resolve) { @@ -328,9 +356,9 @@ var require_io_util = __commonJS((exports2) => { }; var _a; Object.defineProperty(exports2, "__esModule", {value: true}); - var assert_1 = require("assert"); - var fs = require("fs"); - var path2 = require("path"); + exports2.getCmdPath = exports2.tryGetExecutablePath = exports2.isRooted = exports2.isDirectory = exports2.exists = exports2.IS_WINDOWS = exports2.unlink = exports2.symlink = exports2.stat = exports2.rmdir = exports2.rename = exports2.readlink = exports2.readdir = exports2.mkdir = exports2.lstat = exports2.copyFile = exports2.chmod = void 0; + var fs = __importStar(require("fs")); + var path2 = __importStar(require("path")); _a = fs.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; exports2.IS_WINDOWS = process.platform === "win32"; function exists(fsPath) { @@ -365,37 +393,6 @@ var require_io_util = __commonJS((exports2) => { return p.startsWith("/"); } exports2.isRooted = isRooted; - function mkdirP(fsPath, maxDepth = 1e3, depth = 1) { - return __awaiter(this, void 0, void 0, function* () { - assert_1.ok(fsPath, "a path argument must be provided"); - fsPath = path2.resolve(fsPath); - if (depth >= maxDepth) - return exports2.mkdir(fsPath); - try { - yield exports2.mkdir(fsPath); - return; - } catch (err) { - switch (err.code) { - case "ENOENT": { - yield mkdirP(path2.dirname(fsPath), maxDepth, depth + 1); - yield exports2.mkdir(fsPath); - return; - } - default: { - let stats; - try { - stats = yield exports2.stat(fsPath); - } catch (err2) { - throw err; - } - if (!stats.isDirectory()) - throw err; - } - } - } - }); - } - exports2.mkdirP = mkdirP; function tryGetExecutablePath(filePath, extensions) { return __awaiter(this, void 0, void 0, function* () { let stats = void 0; @@ -466,11 +463,44 @@ var require_io_util = __commonJS((exports2) => { function isUnixExecutable(stats) { return (stats.mode & 1) > 0 || (stats.mode & 8) > 0 && stats.gid === process.getgid() || (stats.mode & 64) > 0 && stats.uid === process.getuid(); } + function getCmdPath() { + var _a2; + return (_a2 = process.env["COMSPEC"]) !== null && _a2 !== void 0 ? _a2 : `cmd.exe`; + } + exports2.getCmdPath = getCmdPath; }); -// node_modules/@actions/io/lib/io.js +// node_modules/@actions/exec/node_modules/@actions/io/lib/io.js var require_io = __commonJS((exports2) => { "use strict"; + var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + Object.defineProperty(o, k2, {enumerable: true, get: function() { + return m[k]; + }}); + } : function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + o[k2] = m[k]; + }); + var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", {enumerable: true, value: v}); + } : function(o, v) { + o["default"] = v; + }); + var __importStar = exports2 && exports2.__importStar || function(mod) { + if (mod && mod.__esModule) + return mod; + var result = {}; + if (mod != null) { + for (var k in mod) + if (k !== "default" && Object.hasOwnProperty.call(mod, k)) + __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; + }; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function(resolve) { @@ -499,19 +529,22 @@ var require_io = __commonJS((exports2) => { }); }; Object.defineProperty(exports2, "__esModule", {value: true}); - var childProcess = require("child_process"); - var path2 = require("path"); + exports2.findInPath = exports2.which = exports2.mkdirP = exports2.rmRF = exports2.mv = exports2.cp = void 0; + var assert_1 = require("assert"); + var childProcess = __importStar(require("child_process")); + var path2 = __importStar(require("path")); var util_1 = require("util"); - var ioUtil = require_io_util(); + var ioUtil = __importStar(require_io_util()); var exec5 = util_1.promisify(childProcess.exec); + var execFile = util_1.promisify(childProcess.execFile); function cp(source, dest, options = {}) { return __awaiter(this, void 0, void 0, function* () { - const {force, recursive} = readCopyOptions(options); + const {force, recursive, copySourceDirectory} = readCopyOptions(options); const destStat = (yield ioUtil.exists(dest)) ? yield ioUtil.stat(dest) : null; if (destStat && destStat.isFile() && !force) { return; } - const newDest = destStat && destStat.isDirectory() ? path2.join(dest, path2.basename(source)) : dest; + const newDest = destStat && destStat.isDirectory() && copySourceDirectory ? path2.join(dest, path2.basename(source)) : dest; if (!(yield ioUtil.exists(source))) { throw new Error(`no such file or directory: ${source}`); } @@ -555,11 +588,19 @@ var require_io = __commonJS((exports2) => { function rmRF(inputPath) { return __awaiter(this, void 0, void 0, function* () { if (ioUtil.IS_WINDOWS) { + if (/[*"<>|]/.test(inputPath)) { + throw new Error('File path must not contain `*`, `"`, `<`, `>` or `|` on Windows'); + } try { + const cmdPath = ioUtil.getCmdPath(); if (yield ioUtil.isDirectory(inputPath, true)) { - yield exec5(`rd /s /q "${inputPath}"`); + yield exec5(`${cmdPath} /s /c "rd /s /q "%inputPath%""`, { + env: {inputPath} + }); } else { - yield exec5(`del /f /a "${inputPath}"`); + yield exec5(`${cmdPath} /s /c "del /f /a "%inputPath%""`, { + env: {inputPath} + }); } } catch (err) { if (err.code !== "ENOENT") @@ -581,7 +622,7 @@ var require_io = __commonJS((exports2) => { return; } if (isDir) { - yield exec5(`rm -rf "${inputPath}"`); + yield execFile(`rm`, [`-rf`, `${inputPath}`]); } else { yield ioUtil.unlink(inputPath); } @@ -591,7 +632,8 @@ var require_io = __commonJS((exports2) => { exports2.rmRF = rmRF; function mkdirP(fsPath) { return __awaiter(this, void 0, void 0, function* () { - yield ioUtil.mkdirP(fsPath); + assert_1.ok(fsPath, "a path argument must be provided"); + yield ioUtil.mkdir(fsPath, {recursive: true}); }); } exports2.mkdirP = mkdirP; @@ -609,51 +651,63 @@ var require_io = __commonJS((exports2) => { throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`); } } + return result; } - try { - const extensions = []; - if (ioUtil.IS_WINDOWS && process.env.PATHEXT) { - for (const extension of process.env.PATHEXT.split(path2.delimiter)) { - if (extension) { - extensions.push(extension); - } - } - } - if (ioUtil.isRooted(tool)) { - const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions); - if (filePath) { - return filePath; + const matches = yield findInPath(tool); + if (matches && matches.length > 0) { + return matches[0]; + } + return ""; + }); + } + exports2.which = which2; + function findInPath(tool) { + return __awaiter(this, void 0, void 0, function* () { + if (!tool) { + throw new Error("parameter 'tool' is required"); + } + const extensions = []; + if (ioUtil.IS_WINDOWS && process.env["PATHEXT"]) { + for (const extension of process.env["PATHEXT"].split(path2.delimiter)) { + if (extension) { + extensions.push(extension); } - return ""; } - if (tool.includes("/") || ioUtil.IS_WINDOWS && tool.includes("\\")) { - return ""; + } + if (ioUtil.isRooted(tool)) { + const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions); + if (filePath) { + return [filePath]; } - const directories = []; - if (process.env.PATH) { - for (const p of process.env.PATH.split(path2.delimiter)) { - if (p) { - directories.push(p); - } + return []; + } + if (tool.includes(path2.sep)) { + return []; + } + const directories = []; + if (process.env.PATH) { + for (const p of process.env.PATH.split(path2.delimiter)) { + if (p) { + directories.push(p); } } - for (const directory of directories) { - const filePath = yield ioUtil.tryGetExecutablePath(directory + path2.sep + tool, extensions); - if (filePath) { - return filePath; - } + } + const matches = []; + for (const directory of directories) { + const filePath = yield ioUtil.tryGetExecutablePath(path2.join(directory, tool), extensions); + if (filePath) { + matches.push(filePath); } - return ""; - } catch (err) { - throw new Error(`which failed with message ${err.message}`); } + return matches; }); } - exports2.which = which2; + exports2.findInPath = findInPath; function readCopyOptions(options) { const force = options.force == null ? true : options.force; const recursive = Boolean(options.recursive); - return {force, recursive}; + const copySourceDirectory = options.copySourceDirectory == null ? true : Boolean(options.copySourceDirectory); + return {force, recursive, copySourceDirectory}; } function cpDirRecursive(sourceDir, destDir, currentDepth, force) { return __awaiter(this, void 0, void 0, function* () { @@ -1211,6 +1265,406 @@ var require_exec = __commonJS((exports2) => { exports2.exec = exec5; }); +// node_modules/@actions/io/lib/io-util.js +var require_io_util2 = __commonJS((exports2) => { + "use strict"; + var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + }; + var _a; + Object.defineProperty(exports2, "__esModule", {value: true}); + var assert_1 = require("assert"); + var fs = require("fs"); + var path2 = require("path"); + _a = fs.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; + exports2.IS_WINDOWS = process.platform === "win32"; + function exists(fsPath) { + return __awaiter(this, void 0, void 0, function* () { + try { + yield exports2.stat(fsPath); + } catch (err) { + if (err.code === "ENOENT") { + return false; + } + throw err; + } + return true; + }); + } + exports2.exists = exists; + function isDirectory(fsPath, useStat = false) { + return __awaiter(this, void 0, void 0, function* () { + const stats = useStat ? yield exports2.stat(fsPath) : yield exports2.lstat(fsPath); + return stats.isDirectory(); + }); + } + exports2.isDirectory = isDirectory; + function isRooted(p) { + p = normalizeSeparators(p); + if (!p) { + throw new Error('isRooted() parameter "p" cannot be empty'); + } + if (exports2.IS_WINDOWS) { + return p.startsWith("\\") || /^[A-Z]:/i.test(p); + } + return p.startsWith("/"); + } + exports2.isRooted = isRooted; + function mkdirP(fsPath, maxDepth = 1e3, depth = 1) { + return __awaiter(this, void 0, void 0, function* () { + assert_1.ok(fsPath, "a path argument must be provided"); + fsPath = path2.resolve(fsPath); + if (depth >= maxDepth) + return exports2.mkdir(fsPath); + try { + yield exports2.mkdir(fsPath); + return; + } catch (err) { + switch (err.code) { + case "ENOENT": { + yield mkdirP(path2.dirname(fsPath), maxDepth, depth + 1); + yield exports2.mkdir(fsPath); + return; + } + default: { + let stats; + try { + stats = yield exports2.stat(fsPath); + } catch (err2) { + throw err; + } + if (!stats.isDirectory()) + throw err; + } + } + } + }); + } + exports2.mkdirP = mkdirP; + function tryGetExecutablePath(filePath, extensions) { + return __awaiter(this, void 0, void 0, function* () { + let stats = void 0; + try { + stats = yield exports2.stat(filePath); + } catch (err) { + if (err.code !== "ENOENT") { + console.log(`Unexpected error attempting to determine if executable file exists '${filePath}': ${err}`); + } + } + if (stats && stats.isFile()) { + if (exports2.IS_WINDOWS) { + const upperExt = path2.extname(filePath).toUpperCase(); + if (extensions.some((validExt) => validExt.toUpperCase() === upperExt)) { + return filePath; + } + } else { + if (isUnixExecutable(stats)) { + return filePath; + } + } + } + const originalFilePath = filePath; + for (const extension of extensions) { + filePath = originalFilePath + extension; + stats = void 0; + try { + stats = yield exports2.stat(filePath); + } catch (err) { + if (err.code !== "ENOENT") { + console.log(`Unexpected error attempting to determine if executable file exists '${filePath}': ${err}`); + } + } + if (stats && stats.isFile()) { + if (exports2.IS_WINDOWS) { + try { + const directory = path2.dirname(filePath); + const upperName = path2.basename(filePath).toUpperCase(); + for (const actualName of yield exports2.readdir(directory)) { + if (upperName === actualName.toUpperCase()) { + filePath = path2.join(directory, actualName); + break; + } + } + } catch (err) { + console.log(`Unexpected error attempting to determine the actual case of the file '${filePath}': ${err}`); + } + return filePath; + } else { + if (isUnixExecutable(stats)) { + return filePath; + } + } + } + } + return ""; + }); + } + exports2.tryGetExecutablePath = tryGetExecutablePath; + function normalizeSeparators(p) { + p = p || ""; + if (exports2.IS_WINDOWS) { + p = p.replace(/\//g, "\\"); + return p.replace(/\\\\+/g, "\\"); + } + return p.replace(/\/\/+/g, "/"); + } + function isUnixExecutable(stats) { + return (stats.mode & 1) > 0 || (stats.mode & 8) > 0 && stats.gid === process.getgid() || (stats.mode & 64) > 0 && stats.uid === process.getuid(); + } +}); + +// node_modules/@actions/io/lib/io.js +var require_io2 = __commonJS((exports2) => { + "use strict"; + var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + }; + Object.defineProperty(exports2, "__esModule", {value: true}); + var childProcess = require("child_process"); + var path2 = require("path"); + var util_1 = require("util"); + var ioUtil = require_io_util2(); + var exec5 = util_1.promisify(childProcess.exec); + function cp(source, dest, options = {}) { + return __awaiter(this, void 0, void 0, function* () { + const {force, recursive} = readCopyOptions(options); + const destStat = (yield ioUtil.exists(dest)) ? yield ioUtil.stat(dest) : null; + if (destStat && destStat.isFile() && !force) { + return; + } + const newDest = destStat && destStat.isDirectory() ? path2.join(dest, path2.basename(source)) : dest; + if (!(yield ioUtil.exists(source))) { + throw new Error(`no such file or directory: ${source}`); + } + const sourceStat = yield ioUtil.stat(source); + if (sourceStat.isDirectory()) { + if (!recursive) { + throw new Error(`Failed to copy. ${source} is a directory, but tried to copy without recursive flag.`); + } else { + yield cpDirRecursive(source, newDest, 0, force); + } + } else { + if (path2.relative(source, newDest) === "") { + throw new Error(`'${newDest}' and '${source}' are the same file`); + } + yield copyFile(source, newDest, force); + } + }); + } + exports2.cp = cp; + function mv(source, dest, options = {}) { + return __awaiter(this, void 0, void 0, function* () { + if (yield ioUtil.exists(dest)) { + let destExists = true; + if (yield ioUtil.isDirectory(dest)) { + dest = path2.join(dest, path2.basename(source)); + destExists = yield ioUtil.exists(dest); + } + if (destExists) { + if (options.force == null || options.force) { + yield rmRF(dest); + } else { + throw new Error("Destination already exists"); + } + } + } + yield mkdirP(path2.dirname(dest)); + yield ioUtil.rename(source, dest); + }); + } + exports2.mv = mv; + function rmRF(inputPath) { + return __awaiter(this, void 0, void 0, function* () { + if (ioUtil.IS_WINDOWS) { + try { + if (yield ioUtil.isDirectory(inputPath, true)) { + yield exec5(`rd /s /q "${inputPath}"`); + } else { + yield exec5(`del /f /a "${inputPath}"`); + } + } catch (err) { + if (err.code !== "ENOENT") + throw err; + } + try { + yield ioUtil.unlink(inputPath); + } catch (err) { + if (err.code !== "ENOENT") + throw err; + } + } else { + let isDir = false; + try { + isDir = yield ioUtil.isDirectory(inputPath); + } catch (err) { + if (err.code !== "ENOENT") + throw err; + return; + } + if (isDir) { + yield exec5(`rm -rf "${inputPath}"`); + } else { + yield ioUtil.unlink(inputPath); + } + } + }); + } + exports2.rmRF = rmRF; + function mkdirP(fsPath) { + return __awaiter(this, void 0, void 0, function* () { + yield ioUtil.mkdirP(fsPath); + }); + } + exports2.mkdirP = mkdirP; + function which2(tool, check) { + return __awaiter(this, void 0, void 0, function* () { + if (!tool) { + throw new Error("parameter 'tool' is required"); + } + if (check) { + const result = yield which2(tool, false); + if (!result) { + if (ioUtil.IS_WINDOWS) { + throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.`); + } else { + throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`); + } + } + } + try { + const extensions = []; + if (ioUtil.IS_WINDOWS && process.env.PATHEXT) { + for (const extension of process.env.PATHEXT.split(path2.delimiter)) { + if (extension) { + extensions.push(extension); + } + } + } + if (ioUtil.isRooted(tool)) { + const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions); + if (filePath) { + return filePath; + } + return ""; + } + if (tool.includes("/") || ioUtil.IS_WINDOWS && tool.includes("\\")) { + return ""; + } + const directories = []; + if (process.env.PATH) { + for (const p of process.env.PATH.split(path2.delimiter)) { + if (p) { + directories.push(p); + } + } + } + for (const directory of directories) { + const filePath = yield ioUtil.tryGetExecutablePath(directory + path2.sep + tool, extensions); + if (filePath) { + return filePath; + } + } + return ""; + } catch (err) { + throw new Error(`which failed with message ${err.message}`); + } + }); + } + exports2.which = which2; + function readCopyOptions(options) { + const force = options.force == null ? true : options.force; + const recursive = Boolean(options.recursive); + return {force, recursive}; + } + function cpDirRecursive(sourceDir, destDir, currentDepth, force) { + return __awaiter(this, void 0, void 0, function* () { + if (currentDepth >= 255) + return; + currentDepth++; + yield mkdirP(destDir); + const files = yield ioUtil.readdir(sourceDir); + for (const fileName of files) { + const srcFile = `${sourceDir}/${fileName}`; + const destFile = `${destDir}/${fileName}`; + const srcFileStat = yield ioUtil.lstat(srcFile); + if (srcFileStat.isDirectory()) { + yield cpDirRecursive(srcFile, destFile, currentDepth, force); + } else { + yield copyFile(srcFile, destFile, force); + } + } + yield ioUtil.chmod(destDir, (yield ioUtil.stat(sourceDir)).mode); + }); + } + function copyFile(srcFile, destFile, force) { + return __awaiter(this, void 0, void 0, function* () { + if ((yield ioUtil.lstat(srcFile)).isSymbolicLink()) { + try { + yield ioUtil.lstat(destFile); + yield ioUtil.unlink(destFile); + } catch (e) { + if (e.code === "EPERM") { + yield ioUtil.chmod(destFile, "0666"); + yield ioUtil.unlink(destFile); + } + } + const symlinkFull = yield ioUtil.readlink(srcFile); + yield ioUtil.symlink(symlinkFull, destFile, ioUtil.IS_WINDOWS ? "junction" : null); + } else if (!(yield ioUtil.exists(destFile)) || force) { + yield ioUtil.copyFile(srcFile, destFile); + } + }); + } +}); + // lib/plugin-test/main.ts var core3 = __toModule(require_core()); @@ -1221,7 +1675,7 @@ var exec3 = __toModule(require_exec()); // lib/setup/index.ts var core = __toModule(require_core()); var exec = __toModule(require_exec()); -var io = __toModule(require_io()); +var io = __toModule(require_io2()); var os = __toModule(require("os")); var path = __toModule(require("path")); async function setupAsdf() { diff --git a/plugins-add/main.js b/plugins-add/main.js index fc013395..4d934912 100644 --- a/plugins-add/main.js +++ b/plugins-add/main.js @@ -296,9 +296,37 @@ var require_core = __commonJS((exports2) => { exports2.getState = getState; }); -// node_modules/@actions/io/lib/io-util.js +// node_modules/@actions/exec/node_modules/@actions/io/lib/io-util.js var require_io_util = __commonJS((exports2) => { "use strict"; + var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + Object.defineProperty(o, k2, {enumerable: true, get: function() { + return m[k]; + }}); + } : function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + o[k2] = m[k]; + }); + var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", {enumerable: true, value: v}); + } : function(o, v) { + o["default"] = v; + }); + var __importStar = exports2 && exports2.__importStar || function(mod) { + if (mod && mod.__esModule) + return mod; + var result = {}; + if (mod != null) { + for (var k in mod) + if (k !== "default" && Object.hasOwnProperty.call(mod, k)) + __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; + }; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function(resolve) { @@ -328,9 +356,9 @@ var require_io_util = __commonJS((exports2) => { }; var _a; Object.defineProperty(exports2, "__esModule", {value: true}); - var assert_1 = require("assert"); - var fs2 = require("fs"); - var path2 = require("path"); + exports2.getCmdPath = exports2.tryGetExecutablePath = exports2.isRooted = exports2.isDirectory = exports2.exists = exports2.IS_WINDOWS = exports2.unlink = exports2.symlink = exports2.stat = exports2.rmdir = exports2.rename = exports2.readlink = exports2.readdir = exports2.mkdir = exports2.lstat = exports2.copyFile = exports2.chmod = void 0; + var fs2 = __importStar(require("fs")); + var path2 = __importStar(require("path")); _a = fs2.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; exports2.IS_WINDOWS = process.platform === "win32"; function exists(fsPath) { @@ -365,37 +393,6 @@ var require_io_util = __commonJS((exports2) => { return p.startsWith("/"); } exports2.isRooted = isRooted; - function mkdirP(fsPath, maxDepth = 1e3, depth = 1) { - return __awaiter(this, void 0, void 0, function* () { - assert_1.ok(fsPath, "a path argument must be provided"); - fsPath = path2.resolve(fsPath); - if (depth >= maxDepth) - return exports2.mkdir(fsPath); - try { - yield exports2.mkdir(fsPath); - return; - } catch (err) { - switch (err.code) { - case "ENOENT": { - yield mkdirP(path2.dirname(fsPath), maxDepth, depth + 1); - yield exports2.mkdir(fsPath); - return; - } - default: { - let stats; - try { - stats = yield exports2.stat(fsPath); - } catch (err2) { - throw err; - } - if (!stats.isDirectory()) - throw err; - } - } - } - }); - } - exports2.mkdirP = mkdirP; function tryGetExecutablePath(filePath, extensions) { return __awaiter(this, void 0, void 0, function* () { let stats = void 0; @@ -466,11 +463,44 @@ var require_io_util = __commonJS((exports2) => { function isUnixExecutable(stats) { return (stats.mode & 1) > 0 || (stats.mode & 8) > 0 && stats.gid === process.getgid() || (stats.mode & 64) > 0 && stats.uid === process.getuid(); } + function getCmdPath() { + var _a2; + return (_a2 = process.env["COMSPEC"]) !== null && _a2 !== void 0 ? _a2 : `cmd.exe`; + } + exports2.getCmdPath = getCmdPath; }); -// node_modules/@actions/io/lib/io.js +// node_modules/@actions/exec/node_modules/@actions/io/lib/io.js var require_io = __commonJS((exports2) => { "use strict"; + var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + Object.defineProperty(o, k2, {enumerable: true, get: function() { + return m[k]; + }}); + } : function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + o[k2] = m[k]; + }); + var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", {enumerable: true, value: v}); + } : function(o, v) { + o["default"] = v; + }); + var __importStar = exports2 && exports2.__importStar || function(mod) { + if (mod && mod.__esModule) + return mod; + var result = {}; + if (mod != null) { + for (var k in mod) + if (k !== "default" && Object.hasOwnProperty.call(mod, k)) + __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; + }; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function(resolve) { @@ -499,19 +529,22 @@ var require_io = __commonJS((exports2) => { }); }; Object.defineProperty(exports2, "__esModule", {value: true}); - var childProcess = require("child_process"); - var path2 = require("path"); + exports2.findInPath = exports2.which = exports2.mkdirP = exports2.rmRF = exports2.mv = exports2.cp = void 0; + var assert_1 = require("assert"); + var childProcess = __importStar(require("child_process")); + var path2 = __importStar(require("path")); var util_1 = require("util"); - var ioUtil = require_io_util(); + var ioUtil = __importStar(require_io_util()); var exec5 = util_1.promisify(childProcess.exec); + var execFile = util_1.promisify(childProcess.execFile); function cp(source, dest, options = {}) { return __awaiter(this, void 0, void 0, function* () { - const {force, recursive} = readCopyOptions(options); + const {force, recursive, copySourceDirectory} = readCopyOptions(options); const destStat = (yield ioUtil.exists(dest)) ? yield ioUtil.stat(dest) : null; if (destStat && destStat.isFile() && !force) { return; } - const newDest = destStat && destStat.isDirectory() ? path2.join(dest, path2.basename(source)) : dest; + const newDest = destStat && destStat.isDirectory() && copySourceDirectory ? path2.join(dest, path2.basename(source)) : dest; if (!(yield ioUtil.exists(source))) { throw new Error(`no such file or directory: ${source}`); } @@ -555,11 +588,19 @@ var require_io = __commonJS((exports2) => { function rmRF(inputPath) { return __awaiter(this, void 0, void 0, function* () { if (ioUtil.IS_WINDOWS) { + if (/[*"<>|]/.test(inputPath)) { + throw new Error('File path must not contain `*`, `"`, `<`, `>` or `|` on Windows'); + } try { + const cmdPath = ioUtil.getCmdPath(); if (yield ioUtil.isDirectory(inputPath, true)) { - yield exec5(`rd /s /q "${inputPath}"`); + yield exec5(`${cmdPath} /s /c "rd /s /q "%inputPath%""`, { + env: {inputPath} + }); } else { - yield exec5(`del /f /a "${inputPath}"`); + yield exec5(`${cmdPath} /s /c "del /f /a "%inputPath%""`, { + env: {inputPath} + }); } } catch (err) { if (err.code !== "ENOENT") @@ -581,7 +622,7 @@ var require_io = __commonJS((exports2) => { return; } if (isDir) { - yield exec5(`rm -rf "${inputPath}"`); + yield execFile(`rm`, [`-rf`, `${inputPath}`]); } else { yield ioUtil.unlink(inputPath); } @@ -591,7 +632,8 @@ var require_io = __commonJS((exports2) => { exports2.rmRF = rmRF; function mkdirP(fsPath) { return __awaiter(this, void 0, void 0, function* () { - yield ioUtil.mkdirP(fsPath); + assert_1.ok(fsPath, "a path argument must be provided"); + yield ioUtil.mkdir(fsPath, {recursive: true}); }); } exports2.mkdirP = mkdirP; @@ -609,51 +651,63 @@ var require_io = __commonJS((exports2) => { throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`); } } + return result; } - try { - const extensions = []; - if (ioUtil.IS_WINDOWS && process.env.PATHEXT) { - for (const extension of process.env.PATHEXT.split(path2.delimiter)) { - if (extension) { - extensions.push(extension); - } - } - } - if (ioUtil.isRooted(tool)) { - const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions); - if (filePath) { - return filePath; + const matches = yield findInPath(tool); + if (matches && matches.length > 0) { + return matches[0]; + } + return ""; + }); + } + exports2.which = which2; + function findInPath(tool) { + return __awaiter(this, void 0, void 0, function* () { + if (!tool) { + throw new Error("parameter 'tool' is required"); + } + const extensions = []; + if (ioUtil.IS_WINDOWS && process.env["PATHEXT"]) { + for (const extension of process.env["PATHEXT"].split(path2.delimiter)) { + if (extension) { + extensions.push(extension); } - return ""; } - if (tool.includes("/") || ioUtil.IS_WINDOWS && tool.includes("\\")) { - return ""; + } + if (ioUtil.isRooted(tool)) { + const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions); + if (filePath) { + return [filePath]; } - const directories = []; - if (process.env.PATH) { - for (const p of process.env.PATH.split(path2.delimiter)) { - if (p) { - directories.push(p); - } + return []; + } + if (tool.includes(path2.sep)) { + return []; + } + const directories = []; + if (process.env.PATH) { + for (const p of process.env.PATH.split(path2.delimiter)) { + if (p) { + directories.push(p); } } - for (const directory of directories) { - const filePath = yield ioUtil.tryGetExecutablePath(directory + path2.sep + tool, extensions); - if (filePath) { - return filePath; - } + } + const matches = []; + for (const directory of directories) { + const filePath = yield ioUtil.tryGetExecutablePath(path2.join(directory, tool), extensions); + if (filePath) { + matches.push(filePath); } - return ""; - } catch (err) { - throw new Error(`which failed with message ${err.message}`); } + return matches; }); } - exports2.which = which2; + exports2.findInPath = findInPath; function readCopyOptions(options) { const force = options.force == null ? true : options.force; const recursive = Boolean(options.recursive); - return {force, recursive}; + const copySourceDirectory = options.copySourceDirectory == null ? true : Boolean(options.copySourceDirectory); + return {force, recursive, copySourceDirectory}; } function cpDirRecursive(sourceDir, destDir, currentDepth, force) { return __awaiter(this, void 0, void 0, function* () { @@ -1211,6 +1265,406 @@ var require_exec = __commonJS((exports2) => { exports2.exec = exec5; }); +// node_modules/@actions/io/lib/io-util.js +var require_io_util2 = __commonJS((exports2) => { + "use strict"; + var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + }; + var _a; + Object.defineProperty(exports2, "__esModule", {value: true}); + var assert_1 = require("assert"); + var fs2 = require("fs"); + var path2 = require("path"); + _a = fs2.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; + exports2.IS_WINDOWS = process.platform === "win32"; + function exists(fsPath) { + return __awaiter(this, void 0, void 0, function* () { + try { + yield exports2.stat(fsPath); + } catch (err) { + if (err.code === "ENOENT") { + return false; + } + throw err; + } + return true; + }); + } + exports2.exists = exists; + function isDirectory(fsPath, useStat = false) { + return __awaiter(this, void 0, void 0, function* () { + const stats = useStat ? yield exports2.stat(fsPath) : yield exports2.lstat(fsPath); + return stats.isDirectory(); + }); + } + exports2.isDirectory = isDirectory; + function isRooted(p) { + p = normalizeSeparators(p); + if (!p) { + throw new Error('isRooted() parameter "p" cannot be empty'); + } + if (exports2.IS_WINDOWS) { + return p.startsWith("\\") || /^[A-Z]:/i.test(p); + } + return p.startsWith("/"); + } + exports2.isRooted = isRooted; + function mkdirP(fsPath, maxDepth = 1e3, depth = 1) { + return __awaiter(this, void 0, void 0, function* () { + assert_1.ok(fsPath, "a path argument must be provided"); + fsPath = path2.resolve(fsPath); + if (depth >= maxDepth) + return exports2.mkdir(fsPath); + try { + yield exports2.mkdir(fsPath); + return; + } catch (err) { + switch (err.code) { + case "ENOENT": { + yield mkdirP(path2.dirname(fsPath), maxDepth, depth + 1); + yield exports2.mkdir(fsPath); + return; + } + default: { + let stats; + try { + stats = yield exports2.stat(fsPath); + } catch (err2) { + throw err; + } + if (!stats.isDirectory()) + throw err; + } + } + } + }); + } + exports2.mkdirP = mkdirP; + function tryGetExecutablePath(filePath, extensions) { + return __awaiter(this, void 0, void 0, function* () { + let stats = void 0; + try { + stats = yield exports2.stat(filePath); + } catch (err) { + if (err.code !== "ENOENT") { + console.log(`Unexpected error attempting to determine if executable file exists '${filePath}': ${err}`); + } + } + if (stats && stats.isFile()) { + if (exports2.IS_WINDOWS) { + const upperExt = path2.extname(filePath).toUpperCase(); + if (extensions.some((validExt) => validExt.toUpperCase() === upperExt)) { + return filePath; + } + } else { + if (isUnixExecutable(stats)) { + return filePath; + } + } + } + const originalFilePath = filePath; + for (const extension of extensions) { + filePath = originalFilePath + extension; + stats = void 0; + try { + stats = yield exports2.stat(filePath); + } catch (err) { + if (err.code !== "ENOENT") { + console.log(`Unexpected error attempting to determine if executable file exists '${filePath}': ${err}`); + } + } + if (stats && stats.isFile()) { + if (exports2.IS_WINDOWS) { + try { + const directory = path2.dirname(filePath); + const upperName = path2.basename(filePath).toUpperCase(); + for (const actualName of yield exports2.readdir(directory)) { + if (upperName === actualName.toUpperCase()) { + filePath = path2.join(directory, actualName); + break; + } + } + } catch (err) { + console.log(`Unexpected error attempting to determine the actual case of the file '${filePath}': ${err}`); + } + return filePath; + } else { + if (isUnixExecutable(stats)) { + return filePath; + } + } + } + } + return ""; + }); + } + exports2.tryGetExecutablePath = tryGetExecutablePath; + function normalizeSeparators(p) { + p = p || ""; + if (exports2.IS_WINDOWS) { + p = p.replace(/\//g, "\\"); + return p.replace(/\\\\+/g, "\\"); + } + return p.replace(/\/\/+/g, "/"); + } + function isUnixExecutable(stats) { + return (stats.mode & 1) > 0 || (stats.mode & 8) > 0 && stats.gid === process.getgid() || (stats.mode & 64) > 0 && stats.uid === process.getuid(); + } +}); + +// node_modules/@actions/io/lib/io.js +var require_io2 = __commonJS((exports2) => { + "use strict"; + var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + }; + Object.defineProperty(exports2, "__esModule", {value: true}); + var childProcess = require("child_process"); + var path2 = require("path"); + var util_1 = require("util"); + var ioUtil = require_io_util2(); + var exec5 = util_1.promisify(childProcess.exec); + function cp(source, dest, options = {}) { + return __awaiter(this, void 0, void 0, function* () { + const {force, recursive} = readCopyOptions(options); + const destStat = (yield ioUtil.exists(dest)) ? yield ioUtil.stat(dest) : null; + if (destStat && destStat.isFile() && !force) { + return; + } + const newDest = destStat && destStat.isDirectory() ? path2.join(dest, path2.basename(source)) : dest; + if (!(yield ioUtil.exists(source))) { + throw new Error(`no such file or directory: ${source}`); + } + const sourceStat = yield ioUtil.stat(source); + if (sourceStat.isDirectory()) { + if (!recursive) { + throw new Error(`Failed to copy. ${source} is a directory, but tried to copy without recursive flag.`); + } else { + yield cpDirRecursive(source, newDest, 0, force); + } + } else { + if (path2.relative(source, newDest) === "") { + throw new Error(`'${newDest}' and '${source}' are the same file`); + } + yield copyFile(source, newDest, force); + } + }); + } + exports2.cp = cp; + function mv(source, dest, options = {}) { + return __awaiter(this, void 0, void 0, function* () { + if (yield ioUtil.exists(dest)) { + let destExists = true; + if (yield ioUtil.isDirectory(dest)) { + dest = path2.join(dest, path2.basename(source)); + destExists = yield ioUtil.exists(dest); + } + if (destExists) { + if (options.force == null || options.force) { + yield rmRF(dest); + } else { + throw new Error("Destination already exists"); + } + } + } + yield mkdirP(path2.dirname(dest)); + yield ioUtil.rename(source, dest); + }); + } + exports2.mv = mv; + function rmRF(inputPath) { + return __awaiter(this, void 0, void 0, function* () { + if (ioUtil.IS_WINDOWS) { + try { + if (yield ioUtil.isDirectory(inputPath, true)) { + yield exec5(`rd /s /q "${inputPath}"`); + } else { + yield exec5(`del /f /a "${inputPath}"`); + } + } catch (err) { + if (err.code !== "ENOENT") + throw err; + } + try { + yield ioUtil.unlink(inputPath); + } catch (err) { + if (err.code !== "ENOENT") + throw err; + } + } else { + let isDir = false; + try { + isDir = yield ioUtil.isDirectory(inputPath); + } catch (err) { + if (err.code !== "ENOENT") + throw err; + return; + } + if (isDir) { + yield exec5(`rm -rf "${inputPath}"`); + } else { + yield ioUtil.unlink(inputPath); + } + } + }); + } + exports2.rmRF = rmRF; + function mkdirP(fsPath) { + return __awaiter(this, void 0, void 0, function* () { + yield ioUtil.mkdirP(fsPath); + }); + } + exports2.mkdirP = mkdirP; + function which2(tool, check) { + return __awaiter(this, void 0, void 0, function* () { + if (!tool) { + throw new Error("parameter 'tool' is required"); + } + if (check) { + const result = yield which2(tool, false); + if (!result) { + if (ioUtil.IS_WINDOWS) { + throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.`); + } else { + throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`); + } + } + } + try { + const extensions = []; + if (ioUtil.IS_WINDOWS && process.env.PATHEXT) { + for (const extension of process.env.PATHEXT.split(path2.delimiter)) { + if (extension) { + extensions.push(extension); + } + } + } + if (ioUtil.isRooted(tool)) { + const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions); + if (filePath) { + return filePath; + } + return ""; + } + if (tool.includes("/") || ioUtil.IS_WINDOWS && tool.includes("\\")) { + return ""; + } + const directories = []; + if (process.env.PATH) { + for (const p of process.env.PATH.split(path2.delimiter)) { + if (p) { + directories.push(p); + } + } + } + for (const directory of directories) { + const filePath = yield ioUtil.tryGetExecutablePath(directory + path2.sep + tool, extensions); + if (filePath) { + return filePath; + } + } + return ""; + } catch (err) { + throw new Error(`which failed with message ${err.message}`); + } + }); + } + exports2.which = which2; + function readCopyOptions(options) { + const force = options.force == null ? true : options.force; + const recursive = Boolean(options.recursive); + return {force, recursive}; + } + function cpDirRecursive(sourceDir, destDir, currentDepth, force) { + return __awaiter(this, void 0, void 0, function* () { + if (currentDepth >= 255) + return; + currentDepth++; + yield mkdirP(destDir); + const files = yield ioUtil.readdir(sourceDir); + for (const fileName of files) { + const srcFile = `${sourceDir}/${fileName}`; + const destFile = `${destDir}/${fileName}`; + const srcFileStat = yield ioUtil.lstat(srcFile); + if (srcFileStat.isDirectory()) { + yield cpDirRecursive(srcFile, destFile, currentDepth, force); + } else { + yield copyFile(srcFile, destFile, force); + } + } + yield ioUtil.chmod(destDir, (yield ioUtil.stat(sourceDir)).mode); + }); + } + function copyFile(srcFile, destFile, force) { + return __awaiter(this, void 0, void 0, function* () { + if ((yield ioUtil.lstat(srcFile)).isSymbolicLink()) { + try { + yield ioUtil.lstat(destFile); + yield ioUtil.unlink(destFile); + } catch (e) { + if (e.code === "EPERM") { + yield ioUtil.chmod(destFile, "0666"); + yield ioUtil.unlink(destFile); + } + } + const symlinkFull = yield ioUtil.readlink(srcFile); + yield ioUtil.symlink(symlinkFull, destFile, ioUtil.IS_WINDOWS ? "junction" : null); + } else if (!(yield ioUtil.exists(destFile)) || force) { + yield ioUtil.copyFile(srcFile, destFile); + } + }); + } +}); + // lib/plugins-add/main.ts var core3 = __toModule(require_core()); @@ -1222,7 +1676,7 @@ var fs = __toModule(require("fs")); // lib/setup/index.ts var core = __toModule(require_core()); var exec = __toModule(require_exec()); -var io = __toModule(require_io()); +var io = __toModule(require_io2()); var os = __toModule(require("os")); var path = __toModule(require("path")); async function setupAsdf() { diff --git a/setup/main.js b/setup/main.js index ec508b04..22ff4108 100644 --- a/setup/main.js +++ b/setup/main.js @@ -296,9 +296,37 @@ var require_core = __commonJS((exports2) => { exports2.getState = getState; }); -// node_modules/@actions/io/lib/io-util.js +// node_modules/@actions/exec/node_modules/@actions/io/lib/io-util.js var require_io_util = __commonJS((exports2) => { "use strict"; + var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + Object.defineProperty(o, k2, {enumerable: true, get: function() { + return m[k]; + }}); + } : function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + o[k2] = m[k]; + }); + var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", {enumerable: true, value: v}); + } : function(o, v) { + o["default"] = v; + }); + var __importStar = exports2 && exports2.__importStar || function(mod) { + if (mod && mod.__esModule) + return mod; + var result = {}; + if (mod != null) { + for (var k in mod) + if (k !== "default" && Object.hasOwnProperty.call(mod, k)) + __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; + }; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function(resolve) { @@ -328,9 +356,9 @@ var require_io_util = __commonJS((exports2) => { }; var _a; Object.defineProperty(exports2, "__esModule", {value: true}); - var assert_1 = require("assert"); - var fs = require("fs"); - var path2 = require("path"); + exports2.getCmdPath = exports2.tryGetExecutablePath = exports2.isRooted = exports2.isDirectory = exports2.exists = exports2.IS_WINDOWS = exports2.unlink = exports2.symlink = exports2.stat = exports2.rmdir = exports2.rename = exports2.readlink = exports2.readdir = exports2.mkdir = exports2.lstat = exports2.copyFile = exports2.chmod = void 0; + var fs = __importStar(require("fs")); + var path2 = __importStar(require("path")); _a = fs.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; exports2.IS_WINDOWS = process.platform === "win32"; function exists(fsPath) { @@ -365,37 +393,6 @@ var require_io_util = __commonJS((exports2) => { return p.startsWith("/"); } exports2.isRooted = isRooted; - function mkdirP(fsPath, maxDepth = 1e3, depth = 1) { - return __awaiter(this, void 0, void 0, function* () { - assert_1.ok(fsPath, "a path argument must be provided"); - fsPath = path2.resolve(fsPath); - if (depth >= maxDepth) - return exports2.mkdir(fsPath); - try { - yield exports2.mkdir(fsPath); - return; - } catch (err) { - switch (err.code) { - case "ENOENT": { - yield mkdirP(path2.dirname(fsPath), maxDepth, depth + 1); - yield exports2.mkdir(fsPath); - return; - } - default: { - let stats; - try { - stats = yield exports2.stat(fsPath); - } catch (err2) { - throw err; - } - if (!stats.isDirectory()) - throw err; - } - } - } - }); - } - exports2.mkdirP = mkdirP; function tryGetExecutablePath(filePath, extensions) { return __awaiter(this, void 0, void 0, function* () { let stats = void 0; @@ -466,11 +463,44 @@ var require_io_util = __commonJS((exports2) => { function isUnixExecutable(stats) { return (stats.mode & 1) > 0 || (stats.mode & 8) > 0 && stats.gid === process.getgid() || (stats.mode & 64) > 0 && stats.uid === process.getuid(); } + function getCmdPath() { + var _a2; + return (_a2 = process.env["COMSPEC"]) !== null && _a2 !== void 0 ? _a2 : `cmd.exe`; + } + exports2.getCmdPath = getCmdPath; }); -// node_modules/@actions/io/lib/io.js +// node_modules/@actions/exec/node_modules/@actions/io/lib/io.js var require_io = __commonJS((exports2) => { "use strict"; + var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + Object.defineProperty(o, k2, {enumerable: true, get: function() { + return m[k]; + }}); + } : function(o, m, k, k2) { + if (k2 === void 0) + k2 = k; + o[k2] = m[k]; + }); + var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? function(o, v) { + Object.defineProperty(o, "default", {enumerable: true, value: v}); + } : function(o, v) { + o["default"] = v; + }); + var __importStar = exports2 && exports2.__importStar || function(mod) { + if (mod && mod.__esModule) + return mod; + var result = {}; + if (mod != null) { + for (var k in mod) + if (k !== "default" && Object.hasOwnProperty.call(mod, k)) + __createBinding(result, mod, k); + } + __setModuleDefault(result, mod); + return result; + }; var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function(resolve) { @@ -499,19 +529,22 @@ var require_io = __commonJS((exports2) => { }); }; Object.defineProperty(exports2, "__esModule", {value: true}); - var childProcess = require("child_process"); - var path2 = require("path"); + exports2.findInPath = exports2.which = exports2.mkdirP = exports2.rmRF = exports2.mv = exports2.cp = void 0; + var assert_1 = require("assert"); + var childProcess = __importStar(require("child_process")); + var path2 = __importStar(require("path")); var util_1 = require("util"); - var ioUtil = require_io_util(); + var ioUtil = __importStar(require_io_util()); var exec3 = util_1.promisify(childProcess.exec); + var execFile = util_1.promisify(childProcess.execFile); function cp(source, dest, options = {}) { return __awaiter(this, void 0, void 0, function* () { - const {force, recursive} = readCopyOptions(options); + const {force, recursive, copySourceDirectory} = readCopyOptions(options); const destStat = (yield ioUtil.exists(dest)) ? yield ioUtil.stat(dest) : null; if (destStat && destStat.isFile() && !force) { return; } - const newDest = destStat && destStat.isDirectory() ? path2.join(dest, path2.basename(source)) : dest; + const newDest = destStat && destStat.isDirectory() && copySourceDirectory ? path2.join(dest, path2.basename(source)) : dest; if (!(yield ioUtil.exists(source))) { throw new Error(`no such file or directory: ${source}`); } @@ -555,11 +588,19 @@ var require_io = __commonJS((exports2) => { function rmRF(inputPath) { return __awaiter(this, void 0, void 0, function* () { if (ioUtil.IS_WINDOWS) { + if (/[*"<>|]/.test(inputPath)) { + throw new Error('File path must not contain `*`, `"`, `<`, `>` or `|` on Windows'); + } try { + const cmdPath = ioUtil.getCmdPath(); if (yield ioUtil.isDirectory(inputPath, true)) { - yield exec3(`rd /s /q "${inputPath}"`); + yield exec3(`${cmdPath} /s /c "rd /s /q "%inputPath%""`, { + env: {inputPath} + }); } else { - yield exec3(`del /f /a "${inputPath}"`); + yield exec3(`${cmdPath} /s /c "del /f /a "%inputPath%""`, { + env: {inputPath} + }); } } catch (err) { if (err.code !== "ENOENT") @@ -581,7 +622,7 @@ var require_io = __commonJS((exports2) => { return; } if (isDir) { - yield exec3(`rm -rf "${inputPath}"`); + yield execFile(`rm`, [`-rf`, `${inputPath}`]); } else { yield ioUtil.unlink(inputPath); } @@ -591,7 +632,8 @@ var require_io = __commonJS((exports2) => { exports2.rmRF = rmRF; function mkdirP(fsPath) { return __awaiter(this, void 0, void 0, function* () { - yield ioUtil.mkdirP(fsPath); + assert_1.ok(fsPath, "a path argument must be provided"); + yield ioUtil.mkdir(fsPath, {recursive: true}); }); } exports2.mkdirP = mkdirP; @@ -609,51 +651,63 @@ var require_io = __commonJS((exports2) => { throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`); } } + return result; } - try { - const extensions = []; - if (ioUtil.IS_WINDOWS && process.env.PATHEXT) { - for (const extension of process.env.PATHEXT.split(path2.delimiter)) { - if (extension) { - extensions.push(extension); - } - } - } - if (ioUtil.isRooted(tool)) { - const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions); - if (filePath) { - return filePath; + const matches = yield findInPath(tool); + if (matches && matches.length > 0) { + return matches[0]; + } + return ""; + }); + } + exports2.which = which2; + function findInPath(tool) { + return __awaiter(this, void 0, void 0, function* () { + if (!tool) { + throw new Error("parameter 'tool' is required"); + } + const extensions = []; + if (ioUtil.IS_WINDOWS && process.env["PATHEXT"]) { + for (const extension of process.env["PATHEXT"].split(path2.delimiter)) { + if (extension) { + extensions.push(extension); } - return ""; } - if (tool.includes("/") || ioUtil.IS_WINDOWS && tool.includes("\\")) { - return ""; + } + if (ioUtil.isRooted(tool)) { + const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions); + if (filePath) { + return [filePath]; } - const directories = []; - if (process.env.PATH) { - for (const p of process.env.PATH.split(path2.delimiter)) { - if (p) { - directories.push(p); - } + return []; + } + if (tool.includes(path2.sep)) { + return []; + } + const directories = []; + if (process.env.PATH) { + for (const p of process.env.PATH.split(path2.delimiter)) { + if (p) { + directories.push(p); } } - for (const directory of directories) { - const filePath = yield ioUtil.tryGetExecutablePath(directory + path2.sep + tool, extensions); - if (filePath) { - return filePath; - } + } + const matches = []; + for (const directory of directories) { + const filePath = yield ioUtil.tryGetExecutablePath(path2.join(directory, tool), extensions); + if (filePath) { + matches.push(filePath); } - return ""; - } catch (err) { - throw new Error(`which failed with message ${err.message}`); } + return matches; }); } - exports2.which = which2; + exports2.findInPath = findInPath; function readCopyOptions(options) { const force = options.force == null ? true : options.force; const recursive = Boolean(options.recursive); - return {force, recursive}; + const copySourceDirectory = options.copySourceDirectory == null ? true : Boolean(options.copySourceDirectory); + return {force, recursive, copySourceDirectory}; } function cpDirRecursive(sourceDir, destDir, currentDepth, force) { return __awaiter(this, void 0, void 0, function* () { @@ -1211,13 +1265,413 @@ var require_exec = __commonJS((exports2) => { exports2.exec = exec3; }); +// node_modules/@actions/io/lib/io-util.js +var require_io_util2 = __commonJS((exports2) => { + "use strict"; + var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + }; + var _a; + Object.defineProperty(exports2, "__esModule", {value: true}); + var assert_1 = require("assert"); + var fs = require("fs"); + var path2 = require("path"); + _a = fs.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink; + exports2.IS_WINDOWS = process.platform === "win32"; + function exists(fsPath) { + return __awaiter(this, void 0, void 0, function* () { + try { + yield exports2.stat(fsPath); + } catch (err) { + if (err.code === "ENOENT") { + return false; + } + throw err; + } + return true; + }); + } + exports2.exists = exists; + function isDirectory(fsPath, useStat = false) { + return __awaiter(this, void 0, void 0, function* () { + const stats = useStat ? yield exports2.stat(fsPath) : yield exports2.lstat(fsPath); + return stats.isDirectory(); + }); + } + exports2.isDirectory = isDirectory; + function isRooted(p) { + p = normalizeSeparators(p); + if (!p) { + throw new Error('isRooted() parameter "p" cannot be empty'); + } + if (exports2.IS_WINDOWS) { + return p.startsWith("\\") || /^[A-Z]:/i.test(p); + } + return p.startsWith("/"); + } + exports2.isRooted = isRooted; + function mkdirP(fsPath, maxDepth = 1e3, depth = 1) { + return __awaiter(this, void 0, void 0, function* () { + assert_1.ok(fsPath, "a path argument must be provided"); + fsPath = path2.resolve(fsPath); + if (depth >= maxDepth) + return exports2.mkdir(fsPath); + try { + yield exports2.mkdir(fsPath); + return; + } catch (err) { + switch (err.code) { + case "ENOENT": { + yield mkdirP(path2.dirname(fsPath), maxDepth, depth + 1); + yield exports2.mkdir(fsPath); + return; + } + default: { + let stats; + try { + stats = yield exports2.stat(fsPath); + } catch (err2) { + throw err; + } + if (!stats.isDirectory()) + throw err; + } + } + } + }); + } + exports2.mkdirP = mkdirP; + function tryGetExecutablePath(filePath, extensions) { + return __awaiter(this, void 0, void 0, function* () { + let stats = void 0; + try { + stats = yield exports2.stat(filePath); + } catch (err) { + if (err.code !== "ENOENT") { + console.log(`Unexpected error attempting to determine if executable file exists '${filePath}': ${err}`); + } + } + if (stats && stats.isFile()) { + if (exports2.IS_WINDOWS) { + const upperExt = path2.extname(filePath).toUpperCase(); + if (extensions.some((validExt) => validExt.toUpperCase() === upperExt)) { + return filePath; + } + } else { + if (isUnixExecutable(stats)) { + return filePath; + } + } + } + const originalFilePath = filePath; + for (const extension of extensions) { + filePath = originalFilePath + extension; + stats = void 0; + try { + stats = yield exports2.stat(filePath); + } catch (err) { + if (err.code !== "ENOENT") { + console.log(`Unexpected error attempting to determine if executable file exists '${filePath}': ${err}`); + } + } + if (stats && stats.isFile()) { + if (exports2.IS_WINDOWS) { + try { + const directory = path2.dirname(filePath); + const upperName = path2.basename(filePath).toUpperCase(); + for (const actualName of yield exports2.readdir(directory)) { + if (upperName === actualName.toUpperCase()) { + filePath = path2.join(directory, actualName); + break; + } + } + } catch (err) { + console.log(`Unexpected error attempting to determine the actual case of the file '${filePath}': ${err}`); + } + return filePath; + } else { + if (isUnixExecutable(stats)) { + return filePath; + } + } + } + } + return ""; + }); + } + exports2.tryGetExecutablePath = tryGetExecutablePath; + function normalizeSeparators(p) { + p = p || ""; + if (exports2.IS_WINDOWS) { + p = p.replace(/\//g, "\\"); + return p.replace(/\\\\+/g, "\\"); + } + return p.replace(/\/\/+/g, "/"); + } + function isUnixExecutable(stats) { + return (stats.mode & 1) > 0 || (stats.mode & 8) > 0 && stats.gid === process.getgid() || (stats.mode & 64) > 0 && stats.uid === process.getuid(); + } +}); + +// node_modules/@actions/io/lib/io.js +var require_io2 = __commonJS((exports2) => { + "use strict"; + var __awaiter = exports2 && exports2.__awaiter || function(thisArg, _arguments, P, generator) { + function adopt(value) { + return value instanceof P ? value : new P(function(resolve) { + resolve(value); + }); + } + return new (P || (P = Promise))(function(resolve, reject) { + function fulfilled(value) { + try { + step(generator.next(value)); + } catch (e) { + reject(e); + } + } + function rejected(value) { + try { + step(generator["throw"](value)); + } catch (e) { + reject(e); + } + } + function step(result) { + result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); + } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); + }; + Object.defineProperty(exports2, "__esModule", {value: true}); + var childProcess = require("child_process"); + var path2 = require("path"); + var util_1 = require("util"); + var ioUtil = require_io_util2(); + var exec3 = util_1.promisify(childProcess.exec); + function cp(source, dest, options = {}) { + return __awaiter(this, void 0, void 0, function* () { + const {force, recursive} = readCopyOptions(options); + const destStat = (yield ioUtil.exists(dest)) ? yield ioUtil.stat(dest) : null; + if (destStat && destStat.isFile() && !force) { + return; + } + const newDest = destStat && destStat.isDirectory() ? path2.join(dest, path2.basename(source)) : dest; + if (!(yield ioUtil.exists(source))) { + throw new Error(`no such file or directory: ${source}`); + } + const sourceStat = yield ioUtil.stat(source); + if (sourceStat.isDirectory()) { + if (!recursive) { + throw new Error(`Failed to copy. ${source} is a directory, but tried to copy without recursive flag.`); + } else { + yield cpDirRecursive(source, newDest, 0, force); + } + } else { + if (path2.relative(source, newDest) === "") { + throw new Error(`'${newDest}' and '${source}' are the same file`); + } + yield copyFile(source, newDest, force); + } + }); + } + exports2.cp = cp; + function mv(source, dest, options = {}) { + return __awaiter(this, void 0, void 0, function* () { + if (yield ioUtil.exists(dest)) { + let destExists = true; + if (yield ioUtil.isDirectory(dest)) { + dest = path2.join(dest, path2.basename(source)); + destExists = yield ioUtil.exists(dest); + } + if (destExists) { + if (options.force == null || options.force) { + yield rmRF(dest); + } else { + throw new Error("Destination already exists"); + } + } + } + yield mkdirP(path2.dirname(dest)); + yield ioUtil.rename(source, dest); + }); + } + exports2.mv = mv; + function rmRF(inputPath) { + return __awaiter(this, void 0, void 0, function* () { + if (ioUtil.IS_WINDOWS) { + try { + if (yield ioUtil.isDirectory(inputPath, true)) { + yield exec3(`rd /s /q "${inputPath}"`); + } else { + yield exec3(`del /f /a "${inputPath}"`); + } + } catch (err) { + if (err.code !== "ENOENT") + throw err; + } + try { + yield ioUtil.unlink(inputPath); + } catch (err) { + if (err.code !== "ENOENT") + throw err; + } + } else { + let isDir = false; + try { + isDir = yield ioUtil.isDirectory(inputPath); + } catch (err) { + if (err.code !== "ENOENT") + throw err; + return; + } + if (isDir) { + yield exec3(`rm -rf "${inputPath}"`); + } else { + yield ioUtil.unlink(inputPath); + } + } + }); + } + exports2.rmRF = rmRF; + function mkdirP(fsPath) { + return __awaiter(this, void 0, void 0, function* () { + yield ioUtil.mkdirP(fsPath); + }); + } + exports2.mkdirP = mkdirP; + function which2(tool, check) { + return __awaiter(this, void 0, void 0, function* () { + if (!tool) { + throw new Error("parameter 'tool' is required"); + } + if (check) { + const result = yield which2(tool, false); + if (!result) { + if (ioUtil.IS_WINDOWS) { + throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.`); + } else { + throw new Error(`Unable to locate executable file: ${tool}. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.`); + } + } + } + try { + const extensions = []; + if (ioUtil.IS_WINDOWS && process.env.PATHEXT) { + for (const extension of process.env.PATHEXT.split(path2.delimiter)) { + if (extension) { + extensions.push(extension); + } + } + } + if (ioUtil.isRooted(tool)) { + const filePath = yield ioUtil.tryGetExecutablePath(tool, extensions); + if (filePath) { + return filePath; + } + return ""; + } + if (tool.includes("/") || ioUtil.IS_WINDOWS && tool.includes("\\")) { + return ""; + } + const directories = []; + if (process.env.PATH) { + for (const p of process.env.PATH.split(path2.delimiter)) { + if (p) { + directories.push(p); + } + } + } + for (const directory of directories) { + const filePath = yield ioUtil.tryGetExecutablePath(directory + path2.sep + tool, extensions); + if (filePath) { + return filePath; + } + } + return ""; + } catch (err) { + throw new Error(`which failed with message ${err.message}`); + } + }); + } + exports2.which = which2; + function readCopyOptions(options) { + const force = options.force == null ? true : options.force; + const recursive = Boolean(options.recursive); + return {force, recursive}; + } + function cpDirRecursive(sourceDir, destDir, currentDepth, force) { + return __awaiter(this, void 0, void 0, function* () { + if (currentDepth >= 255) + return; + currentDepth++; + yield mkdirP(destDir); + const files = yield ioUtil.readdir(sourceDir); + for (const fileName of files) { + const srcFile = `${sourceDir}/${fileName}`; + const destFile = `${destDir}/${fileName}`; + const srcFileStat = yield ioUtil.lstat(srcFile); + if (srcFileStat.isDirectory()) { + yield cpDirRecursive(srcFile, destFile, currentDepth, force); + } else { + yield copyFile(srcFile, destFile, force); + } + } + yield ioUtil.chmod(destDir, (yield ioUtil.stat(sourceDir)).mode); + }); + } + function copyFile(srcFile, destFile, force) { + return __awaiter(this, void 0, void 0, function* () { + if ((yield ioUtil.lstat(srcFile)).isSymbolicLink()) { + try { + yield ioUtil.lstat(destFile); + yield ioUtil.unlink(destFile); + } catch (e) { + if (e.code === "EPERM") { + yield ioUtil.chmod(destFile, "0666"); + yield ioUtil.unlink(destFile); + } + } + const symlinkFull = yield ioUtil.readlink(srcFile); + yield ioUtil.symlink(symlinkFull, destFile, ioUtil.IS_WINDOWS ? "junction" : null); + } else if (!(yield ioUtil.exists(destFile)) || force) { + yield ioUtil.copyFile(srcFile, destFile); + } + }); + } +}); + // lib/setup/main.ts var core2 = __toModule(require_core()); // lib/setup/index.ts var core = __toModule(require_core()); var exec = __toModule(require_exec()); -var io = __toModule(require_io()); +var io = __toModule(require_io2()); var os = __toModule(require("os")); var path = __toModule(require("path")); async function setupAsdf() {