Skip to content

fetchLatest

function fetchLatest(owner: string, repo: string, asset?: string): Promise<Package>

Constructs a new Package object from the latest stable GitHub Release, with a defined fetchInfo property.

When using this function, the asset gets saved to a local cache. However, this function will always make an HTTP request to get the latest release tag. Zip files are extracted using a modified version of the zzlib library.

Unlike Rostruct.fetch, this function does not load release drafts or prereleases.

The function returns a Promise object for convenience. Use the fetchLatestAsync function if you want to wait for the result instead.

Fetching from a large repository

When the asset field is undefined, the source code of the release will be downloaded.

Because Rostruct uses a Lua zip library to extract .zip files, there may be performance issues when extracting large files. Prefer to upload an asset for files you want to run in Rostruct.


Parameters

  • owner: string - The owner of the repository
  • repo: string - The name of the repository
  • asset?: string | undefined - Optional asset to download; If not specified, it downloads the source files

Example usage

This example loads the latest stable release of Roact:

local Roact = Rostruct.fetchLatest("Roblox", "roact")
    :andThen(function(package)
        if package.fetchInfo.updated then
            print("Upgraded to version " .. package.fetchInfo.tag)
        end

        package:build("src/", { Name = "Roact" })

        return package:require(package.tree.Roact)
    end)
    :catch(function(err)
        warn("Error loading Roact:", err)
    end)
    :expect()
local package = Rostruct.fetchLatestAsync("Roblox", "roact")

if package.fetchInfo.updated then
    print("Upgraded to version " .. package.fetchInfo.tag)
end

package:build("src/", { Name = "Roact" })

local Roact = package:requireAsync(package.tree.Roact)