diff --git a/dist/index.js b/dist/index.js index d672725..edfadbd 100644 --- a/dist/index.js +++ b/dist/index.js @@ -14748,6 +14748,14 @@ const { isUint8Array, isArrayBuffer } = __nccwpck_require__(9830) const { File: UndiciFile } = __nccwpck_require__(8511) const { parseMIMEType, serializeAMimeType } = __nccwpck_require__(685) +let random +try { + const crypto = __nccwpck_require__(6005) + random = (max) => crypto.randomInt(0, max) +} catch { + random = (max) => Math.floor(Math.random(max)) +} + let ReadableStream = globalThis.ReadableStream /** @type {globalThis['File']} */ @@ -14833,7 +14841,7 @@ function extractBody (object, keepalive = false) { // Set source to a copy of the bytes held by object. source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength)) } else if (util.isFormDataLike(object)) { - const boundary = `----formdata-undici-0${`${Math.floor(Math.random() * 1e11)}`.padStart(11, '0')}` + const boundary = `----formdata-undici-0${`${random(1e11)}`.padStart(11, '0')}` const prefix = `--${boundary}\r\nContent-Disposition: form-data` /*! formdata-polyfill. MIT License. Jimmy Wärting */ @@ -29614,6 +29622,14 @@ module.exports = require("net"); /***/ }), +/***/ 6005: +/***/ ((module) => { + +"use strict"; +module.exports = require("node:crypto"); + +/***/ }), + /***/ 5673: /***/ ((module) => { @@ -31424,128 +31440,128 @@ module.exports = parseParams var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (() => { -const core = __nccwpck_require__(2186) -const process = __nccwpck_require__(7282) -const spawn = (__nccwpck_require__(2081).spawnSync) -const path = __nccwpck_require__(1017) -const fs = __nccwpck_require__(7147) -const URL = (__nccwpck_require__(7310).URL) -const { https } = __nccwpck_require__(7707) -const AdmZip = __nccwpck_require__(6761) -const HttpsProxyAgent = __nccwpck_require__(7219) - -function selectPlatform(platform, version) { - if (platform) { - return [null, platform] - } - - let major, minor, patch = version.split('.').map((s) => parseInt(s)) - if (process.platform === 'win32') { - if (process.arch === 'arm64') { - if (major < 1 || major == 1 && minor < 12) { - return [new Error(`Windows ARM builds are only available for 1.12.0 and later`), ''] - } - else { - return [null, 'winarm64'] - } - } - else if (process.arch === 'x64') { - return [null, 'win'] - } - else { - return [new Error(`Unsupported architecture '${process.arch}'`), ''] - } - } - else if (process.platform === 'linux') { - if (process.arch === 'arm64') { - if (major < 1 || major == 1 && minor < 12) { - return [new Error(`Linux ARM builds are only available for 1.12.0 and later`), ''] - } - else { - return [null, 'linux-aarch64'] - } - } - else if (process.arch === 'x64') { - return [null, 'linux'] - } - else { - return [new Error(`Unsupported architecture '${process.arch}'`), ''] - } - } - else if (process.platform === 'darwin') { - return [null, 'mac'] - } - else { - return [new Error(`Unsupported platform '${process.platform}'`), ''] - } -} - -try { - const version = core.getInput('version', {required: true}) - const destDir = core.getInput('destination') || 'ninja-build' - const proxyServer = core.getInput('http_proxy') - - const [error, platform] = selectPlatform(core.getInput('platform'), version) - if (error) throw error - - const url = new URL(`https://github.com/ninja-build/ninja/releases/download/v${version}/ninja-${platform}.zip`) - - if (proxyServer) { - console.log(`using proxy ${proxyServer}`) - url.agent = new HttpsProxyAgent(proxyServer) - } - - console.log(`downloading ${url}`) - const request = https.get(url, {followAllRedirects: true}, result => { - const data = [] - - result.on('data', chunk => data.push(chunk)) - - result.on('end', () => { - const length = data.reduce((len, chunk) => len + chunk.length, 0) - const buffer = Buffer.alloc(length) - - data.reduce((pos, chunk) => { - chunk.copy(buffer, pos) - return pos + chunk.length - }, 0) - - const zip = new AdmZip(buffer) - const entry = zip.getEntries()[0] - const ninjaName = entry.entryName - - const fullDestDir = path.resolve(process.cwd(), destDir) - if (!fs.existsSync(fullDestDir)) fs.mkdirSync(fullDestDir, {recursive: true}) - - zip.extractEntryTo(ninjaName, fullDestDir, /*maintainEntryPath*/false, /*overwrite*/true) - - const fullFileDir = path.join(fullDestDir, ninjaName) - if (!fs.existsSync(fullFileDir)) throw new Error(`failed to extract to '${fullFileDir}'`) - - fs.chmodSync(fullFileDir, '755') - - console.log(`extracted '${ninjaName}' to '${fullFileDir}'`) - - core.addPath(fullDestDir) - console.log(`added '${fullDestDir}' to PATH`) - - const result = spawn(ninjaName, ['--version'], {encoding: 'utf8'}) - if (result.error) throw error - - const installedVersion = result.stdout.trim() - - console.log(`$ ${ninjaName} --version`) - console.log(installedVersion) - - if (installedVersion != version) { - throw new Error('incorrect version detected (bad PATH configuration?)') - } - }) - }) - request.on('error', error => { throw error }) -} catch (error) { - core.setFailed(error.message) -} +const core = __nccwpck_require__(2186) +const process = __nccwpck_require__(7282) +const spawn = (__nccwpck_require__(2081).spawnSync) +const path = __nccwpck_require__(1017) +const fs = __nccwpck_require__(7147) +const URL = (__nccwpck_require__(7310).URL) +const { https } = __nccwpck_require__(7707) +const AdmZip = __nccwpck_require__(6761) +const HttpsProxyAgent = __nccwpck_require__(7219) + +function selectPlatform(platform, version) { + if (platform) { + return [null, platform] + } + + let major, minor, patch = version.split('.').map((s) => parseInt(s)) + if (process.platform === 'win32') { + if (process.arch === 'arm64') { + if (major < 1 || major == 1 && minor < 12) { + return [new Error(`Windows ARM builds are only available for 1.12.0 and later`), ''] + } + else { + return [null, 'winarm64'] + } + } + else if (process.arch === 'x64') { + return [null, 'win'] + } + else { + return [new Error(`Unsupported architecture '${process.arch}'`), ''] + } + } + else if (process.platform === 'linux') { + if (process.arch === 'arm64') { + if (major < 1 || major == 1 && minor < 12) { + return [new Error(`Linux ARM builds are only available for 1.12.0 and later`), ''] + } + else { + return [null, 'linux-aarch64'] + } + } + else if (process.arch === 'x64') { + return [null, 'linux'] + } + else { + return [new Error(`Unsupported architecture '${process.arch}'`), ''] + } + } + else if (process.platform === 'darwin') { + return [null, 'mac'] + } + else { + return [new Error(`Unsupported platform '${process.platform}'`), ''] + } +} + +try { + const version = core.getInput('version', {required: true}) + const destDir = core.getInput('destination') || 'ninja-build' + const proxyServer = core.getInput('http_proxy') + + const [error, platform] = selectPlatform(core.getInput('platform'), version) + if (error) throw error + + const url = new URL(`https://github.com/ninja-build/ninja/releases/download/v${version}/ninja-${platform}.zip`) + + if (proxyServer) { + console.log(`using proxy ${proxyServer}`) + url.agent = new HttpsProxyAgent(proxyServer) + } + + console.log(`downloading ${url}`) + const request = https.get(url, {followAllRedirects: true}, result => { + const data = [] + + result.on('data', chunk => data.push(chunk)) + + result.on('end', () => { + const length = data.reduce((len, chunk) => len + chunk.length, 0) + const buffer = Buffer.alloc(length) + + data.reduce((pos, chunk) => { + chunk.copy(buffer, pos) + return pos + chunk.length + }, 0) + + const zip = new AdmZip(buffer) + const entry = zip.getEntries()[0] + const ninjaName = entry.entryName + + const fullDestDir = path.resolve(process.cwd(), destDir) + if (!fs.existsSync(fullDestDir)) fs.mkdirSync(fullDestDir, {recursive: true}) + + zip.extractEntryTo(ninjaName, fullDestDir, /*maintainEntryPath*/false, /*overwrite*/true) + + const fullFileDir = path.join(fullDestDir, ninjaName) + if (!fs.existsSync(fullFileDir)) throw new Error(`failed to extract to '${fullFileDir}'`) + + fs.chmodSync(fullFileDir, '755') + + console.log(`extracted '${ninjaName}' to '${fullFileDir}'`) + + core.addPath(fullDestDir) + console.log(`added '${fullDestDir}' to PATH`) + + const result = spawn(ninjaName, ['--version'], {encoding: 'utf8'}) + if (result.error) throw error + + const installedVersion = result.stdout.trim() + + console.log(`$ ${ninjaName} --version`) + console.log(installedVersion) + + if (installedVersion != version) { + throw new Error('incorrect version detected (bad PATH configuration?)') + } + }) + }) + request.on('error', error => { throw error }) +} catch (error) { + core.setFailed(error.message) +} })(); diff --git a/package-lock.json b/package-lock.json index 9ae235d..d68a16e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -151,9 +151,9 @@ } }, "node_modules/undici": { - "version": "5.28.4", - "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz", - "integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==", + "version": "5.28.5", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.5.tgz", + "integrity": "sha512-zICwjrDrcrUE0pyyJc1I2QzBkLM8FINsgOrt6WjA+BgajVq9Nxu2PbFFXUrAggLfDXlZGZBVZYw7WNV5KiBiBA==", "dev": true, "license": "MIT", "dependencies": {