Skip to content

Commit

Permalink
Merge branch 'main' into jc.update-walrus
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcharles committed Aug 14, 2024
2 parents bfb3dae + c2135a0 commit 49e8ba4
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 102 deletions.
98 changes: 60 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ wasmtime = { workspace = true }
wasmtime-wasi = { workspace = true }
wasi-common = { workspace = true }
walrus = "0.21.1"
swc_core = { version = "0.96.0", features = [
swc_core = { version = "0.100.6", features = [
"common_sourcemap",
"ecma_ast",
"ecma_parser",
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl JS {

fn parse_module(&self) -> Result<Module> {
let source_map: SourceMap = Default::default();
let file = source_map.new_source_file_from(FileName::Anon, self.source_code.clone());
let file = source_map.new_source_file_from(FileName::Anon.into(), self.source_code.clone());
let mut errors = vec![];
parser::parse_file_as_module(
&file,
Expand Down
4 changes: 4 additions & 0 deletions npm/javy-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Changed

- Download version 3.0.1 of Javy instead of the latest released version of Javy.

## [0.2.0] - 2023-08-17

### Removed
Expand Down
20 changes: 4 additions & 16 deletions npm/javy-cli/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Javy npm package
# javy-cli npm package

**This package is deprecated. Please download the appropriate release from [Javy's release page](https://github.com/bytecodealliance/javy/releases).**

This is the npm package for Javy. The package contains a small Node script
that downloads the appropriate Javy binary on demand and invokes it with the
parameters given.
parameters given.

## Usage

Expand All @@ -13,17 +15,3 @@ $ npm install -g javy-cli
# Directly invoke it via npm
$ npx javy-cli@latest
```

## Updating javy

The npm package will automatically download the newest version of Javy if a
newer version is available.

## Using a specific version of javy

To use a specific version of Javy, set the environment variable
`FORCE_RELEASE` to the version you would like to use.

```
FORCE_RELEASE=v1.1.0 npx javy-cli@latest
```
37 changes: 5 additions & 32 deletions npm/javy-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import cachedir from "cachedir";

const REPO = "bytecodealliance/javy";
const NAME = "javy";
const VERSION = "v3.0.1";

async function main() {
try {
const version = await getDesiredVersionNumber();
if (!(await isBinaryDownloaded(version))) {
await downloadBinary(version);
if (!(await isBinaryDownloaded(VERSION))) {
await downloadBinary(VERSION);
}
const result = childProcess.spawnSync(binaryPath(version), getArgs(), {
const result = childProcess.spawnSync(binaryPath(VERSION), getArgs(), {
stdio: "inherit",
});
process.exitCode = result.status === null ? 1 : result.status;
Expand All @@ -30,7 +30,7 @@ async function main() {
// We delete the cached binary because that cached binary will never run successfully and
// stops `javy-cli` from redownloading the binary.
console.error(`${NAME} was not downloaded correctly. Please retry.`);
fs.unlinkSync(binaryPath(version));
fs.unlinkSync(binaryPath(VERSION));
}
} catch (e) {
console.error(e);
Expand Down Expand Up @@ -80,33 +80,6 @@ async function downloadBinary(version) {
await fs.promises.chmod(binaryPath(version), 0o775);
}

/**
* getDesiredVersionNumber returns the version number of the release that
* should be downloaded and launched. If the FORCE_RELEASE env variable is set,
* that will be used as the desired version number, if not, we determine the
* latest release available on GitHub.
*
* GitHub has a public Release API, but rate limits it per IP, so that the
* CLI can end up breaking. Instead, we use a little trick. You can download
* artifacts from the latest release by using `latest` as your version number.
* The server will respond with a 302 redirect to the artifact's URL. That URL
* contains the actual release version number, which we can extract.
*/
async function getDesiredVersionNumber() {
if (process.env.FORCE_RELEASE) return process.env.FORCE_RELEASE;
const resp = await fetch(
`https://github.com/${REPO}/releases/latest/download/lol`,
{ redirect: "manual" }
);
if (resp.status != 302) {
throw Error(
`Could not determine latest release using the GitHub (Status code ${resp.status
}): ${await resp.text().catch(() => "<No error message>")}`
);
}
return resp.headers.get("location").split("/").at(-2);
}

function binaryUrl(version) {
return `https://github.com/${REPO}/releases/download/${version}/${NAME}-${platarch()}-${version}.gz`;
}
Expand Down
Loading

0 comments on commit 49e8ba4

Please sign in to comment.