From 811a8469491f560e0316f80e78d9d2dde378a92c Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Sun, 28 Apr 2024 23:08:35 -0700 Subject: [PATCH] make sure a fileWithoutFileType is returned from both functions --- dist/index.js | 3 ++- flake.nix | 23 +++++++++++++++++++++++ test.js | 7 +++++++ versions.js | 5 ++++- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 flake.nix diff --git a/dist/index.js b/dist/index.js index 601bcb6..4923f05 100644 --- a/dist/index.js +++ b/dist/index.js @@ -82174,8 +82174,9 @@ var require_versions = __commonJS({ throw new Error(`Could not find version ${useVersion || version3} for platform ${host}`); } const downloadUrl = meta[host].tarball; + const fileWithoutFileType = downloadUrl.match(/.*\/(.*)(\.zip|\.tar\..*$)/)[1]; const variantName = path2.basename(meta[host].tarball).replace(`.${ext}`, "").replace(/\+\S*$/, ""); - return { downloadUrl, variantName, version: useVersion || version3 }; + return { downloadUrl, fileWithoutFileType, variantName, version: useVersion || version3 }; } __name(resolveVersion2, "resolveVersion"); module2.exports = { diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b9326aa --- /dev/null +++ b/flake.nix @@ -0,0 +1,23 @@ +{ + description = "Good basic flake template"; + inputs = { + nixpkgs.url = "nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + systempkgs = nixpkgs.legacyPackages.${system}; + in + { + devShells.default = systempkgs.mkShell { + buildInputs = with systempkgs; [ + # specific nodejs versions available, e.g. nodejs_18 + nodejs_20 + nodePackages.typescript-language-server + ]; + }; + } + ); +} diff --git a/test.js b/test.js index 7418d53..16843be 100644 --- a/test.js +++ b/test.js @@ -32,36 +32,43 @@ async function test () { assert.deepEqual(await resolveVersion('x64', 'linux', '0.7.0'), { downloadUrl: 'https://ziglang.org/download/0.7.0/zig-linux-x86_64-0.7.0.tar.xz', + fileWithoutFileType: 'zig-linux-x86_64-0.7.0', variantName: 'zig-linux-x86_64-0.7.0', version: '0.7.0' }) assert.deepEqual(await resolveVersion('x64', 'win32', '0.4.0'), { downloadUrl: 'https://ziglang.org/download/0.4.0/zig-windows-x86_64-0.4.0.zip', + fileWithoutFileType: 'zig-windows-x86_64-0.4.0', variantName: 'zig-windows-x86_64-0.4.0', version: '0.4.0' }) assert.deepEqual(await resolveVersion('arm64', 'darwin', '0.11.0'), { downloadUrl: 'https://ziglang.org/download/0.11.0/zig-macos-aarch64-0.11.0.tar.xz', + fileWithoutFileType: 'zig-macos-aarch64-0.11.0', variantName: 'zig-macos-aarch64-0.11.0', version: '0.11.0' }) assert.deepEqual(await resolveVersion('arm64', 'darwin', '2024.1.0-mach'), { downloadUrl: 'https://pkg.machengine.org/zig/zig-macos-aarch64-0.12.0-dev.2063+804cee3b9.tar.xz', + fileWithoutFileType: 'zig-macos-aarch64-0.12.0-dev.2063+804cee3b9', variantName: 'zig-macos-aarch64-0.12.0-dev.2063', version: '2024.1.0-mach' }) assert.deepEqual(await resolveVersion('x64', 'linux', '2024.3.0-mach'), { downloadUrl: 'https://pkg.machengine.org/zig/zig-linux-x86_64-0.12.0-dev.3180+83e578a18.tar.xz', + fileWithoutFileType: 'zig-linux-x86_64-0.12.0-dev.3180+83e578a18', variantName: 'zig-linux-x86_64-0.12.0-dev.3180', version: '2024.3.0-mach' }) assert.deepEqual(await resolveVersion('x64', 'win32', '2024.1.0-mach'), { downloadUrl: 'https://pkg.machengine.org/zig/zig-windows-x86_64-0.12.0-dev.2063+804cee3b9.zip', + fileWithoutFileType: 'zig-windows-x86_64-0.12.0-dev.2063+804cee3b9', variantName: 'zig-windows-x86_64-0.12.0-dev.2063', version: '2024.1.0-mach' }) assert.deepEqual(await resolveVersion('arm64', 'darwin', '2024.3.0-mach'), { downloadUrl: 'https://pkg.machengine.org/zig/zig-macos-aarch64-0.12.0-dev.3180+83e578a18.tar.xz', + fileWithoutFileType: 'zig-macos-aarch64-0.12.0-dev.3180+83e578a18', variantName: 'zig-macos-aarch64-0.12.0-dev.3180', version: '2024.3.0-mach' }) diff --git a/versions.js b/versions.js index 019cf4c..c1d6b0a 100644 --- a/versions.js +++ b/versions.js @@ -69,6 +69,7 @@ function getJSON (opts) { * to determine the appropriate downloadUrl, etc. * * @returns {string} download URL for the version + * @returns {string} file without file type (to match the function above) * @returns {string} variant name for the version - should be used as cache key * @returns {string} version name - use for display only */ @@ -108,13 +109,15 @@ async function resolveVersion (arch, platform, version) { } const downloadUrl = meta[host].tarball + + const fileWithoutFileType = downloadUrl.match(/.*\/(.*)(\.zip|\.tar\..*$)/)[1] // If this is mach, we could end up with '+sha...' at the end of this, as // a version of '2024.1.0-mach' will resolve to a specific dev version // So, while the function is not called with "+...", we still have to deal with // it. This is important as it is used as the cache key const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '').replace(/\+\S*$/, '') - return { downloadUrl, variantName, version: useVersion || version } + return { downloadUrl, fileWithoutFileType, variantName, version: useVersion || version } } module.exports = {