make sure a fileWithoutFileType is returned from both functions

This commit is contained in:
Emil Lerch 2024-04-28 23:08:35 -07:00
parent 85271de77d
commit 811a846949
Signed by: lobo
GPG Key ID: A7B62D657EF764F8
4 changed files with 36 additions and 2 deletions

3
dist/index.js vendored
View File

@ -82174,8 +82174,9 @@ var require_versions = __commonJS({
throw new Error(`Could not find version ${useVersion || version3} for platform ${host}`); throw new Error(`Could not find version ${useVersion || version3} for platform ${host}`);
} }
const downloadUrl = meta[host].tarball; const downloadUrl = meta[host].tarball;
const fileWithoutFileType = downloadUrl.match(/.*\/(.*)(\.zip|\.tar\..*$)/)[1];
const variantName = path2.basename(meta[host].tarball).replace(`.${ext}`, "").replace(/\+\S*$/, ""); 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"); __name(resolveVersion2, "resolveVersion");
module2.exports = { module2.exports = {

23
flake.nix Normal file
View File

@ -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
];
};
}
);
}

View File

@ -32,36 +32,43 @@ async function test () {
assert.deepEqual(await resolveVersion('x64', 'linux', '0.7.0'), { 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', 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', variantName: 'zig-linux-x86_64-0.7.0',
version: '0.7.0' version: '0.7.0'
}) })
assert.deepEqual(await resolveVersion('x64', 'win32', '0.4.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', 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', variantName: 'zig-windows-x86_64-0.4.0',
version: '0.4.0' version: '0.4.0'
}) })
assert.deepEqual(await resolveVersion('arm64', 'darwin', '0.11.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', 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', variantName: 'zig-macos-aarch64-0.11.0',
version: '0.11.0' version: '0.11.0'
}) })
assert.deepEqual(await resolveVersion('arm64', 'darwin', '2024.1.0-mach'), { 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', 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', variantName: 'zig-macos-aarch64-0.12.0-dev.2063',
version: '2024.1.0-mach' version: '2024.1.0-mach'
}) })
assert.deepEqual(await resolveVersion('x64', 'linux', '2024.3.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', 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', variantName: 'zig-linux-x86_64-0.12.0-dev.3180',
version: '2024.3.0-mach' version: '2024.3.0-mach'
}) })
assert.deepEqual(await resolveVersion('x64', 'win32', '2024.1.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', 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', variantName: 'zig-windows-x86_64-0.12.0-dev.2063',
version: '2024.1.0-mach' version: '2024.1.0-mach'
}) })
assert.deepEqual(await resolveVersion('arm64', 'darwin', '2024.3.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', 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', variantName: 'zig-macos-aarch64-0.12.0-dev.3180',
version: '2024.3.0-mach' version: '2024.3.0-mach'
}) })

View File

@ -69,6 +69,7 @@ function getJSON (opts) {
* to determine the appropriate downloadUrl, etc. * to determine the appropriate downloadUrl, etc.
* *
* @returns {string} download URL for the version * @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} variant name for the version - should be used as cache key
* @returns {string} version name - use for display only * @returns {string} version name - use for display only
*/ */
@ -108,13 +109,15 @@ async function resolveVersion (arch, platform, version) {
} }
const downloadUrl = meta[host].tarball 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 // 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 // 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 // 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 // it. This is important as it is used as the cache key
const variantName = path.basename(meta[host].tarball).replace(`.${ext}`, '').replace(/\+\S*$/, '') 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 = { module.exports = {