Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve install progress and native unzip #18

Merged
merged 5 commits into from
Oct 9, 2023
Merged

feat: improve install progress and native unzip #18

merged 5 commits into from
Oct 9, 2023

Conversation

lowlighter
Copy link
Contributor

This PR removes the need of --allow-run=powershell (greatly reducing attack vectors for Windows) and --allow-run=unzip by using native JS instead.

It also add some QOL features, such as a progress bar for both downloading/inflating browser archive, along with ASTRAL_QUIET_INSTALL env var that hide Astral's console.log. Also added cleanCache() function so it's possible to add browser install to the unit tests

ezgif-3-c7aa3ea991

@lino-levan
Copy link
Owner

It looks like the windows test is hanging on something. Any ideas why?

@lowlighter
Copy link
Contributor Author

It looks like the windows test is hanging on something. Any ideas why?

Yeah I just debugged on my laptop, for some reason chrome.exe --version actually spawns an interactive instance of the browser, so I think that's why it got stuck
Pretty weird that flag doesn't exist for windows

@lino-levan
Copy link
Owner

That is quite strange, I've noticed a lot of inconsistencies between browsers and different operating systems.

src/cache.ts Outdated Show resolved Hide resolved
src/cache.ts Outdated Show resolved Hide resolved
tests/_get_binary_test.ts Show resolved Hide resolved
src/cache.ts Outdated
Comment on lines 140 to 165
const reader = req.body.getReader();
const archive = await Deno.open(resolve(BASE_PATH, `raw_${VERSION}.zip`), {
write: true,
truncate: true,
create: true,
});
const bar = new ProgressBar({
title: `Downloading ${browser} ${VERSION}`,
total: Number(req.headers.get("Content-Length") ?? 0),
clear: true,
display: ":title :bar :percent",
});
let downloaded = 0;
do {
const { done, value } = await reader.read();
if (done) {
break;
}
await Deno.write(archive.rid, value);
downloaded += value.length;
bar.render(downloaded);
} while (true);
Deno.close(archive.rid);
if (!await isQuietInstall()) {
console.log(`Download complete (${browser} version ${VERSION})`);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the performance of this about the same as writeFile? I'm a little concerned that this might be too slow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally it should be around the same yes (deno use something similar internally when it cannot use the op_fs directly: https://github.com/denoland/deno/blob/29026fac21d85a530d87ca3e94ae0d547557fa23/ext/fs/30_fs.js#L779-L804)
Since it's based on the ReadableStream and WritableStream, there shouldn't be too much as the operation is similar to a pipeTo(), it's just that it peak at the chunk length while the stream is read but since it doesn't copy data into intermediate buffer I don't think it impact performances that much

But maybe for the quiet install we could optimize and fallback on the previous way of writing?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I think quiet install going back to the other path makes sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

I made a small benchmark just to check if it was correct, seems that there isn't a big difference.
I feel like it's worth it to have the progress so you know the programm isn't stuck, but lmk if you'd prefer this to not be the default behaviour

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is valuable. Thanks for the work. Let me review dependencies and I think this PR looks good. I'll give it one more lookover.

Comment on lines +6 to +7
import { ZipReader } from "https://deno.land/x/[email protected]/index.js";
import ProgressBar from "https://deno.land/x/[email protected]/mod.ts";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me review these dependencies. I generally try to avoid unnecessary deps if possible.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright both of these modules look fine.

Copy link
Owner

@lino-levan lino-levan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this LGTM.

Comment on lines +65 to +71
const ci = await Deno.permissions.query({
name: "env",
variable: "CI",
});
if ((ci.state === "granted") && (`${Deno.env.get("CI") ?? ""}`.length)) {
return true;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@lino-levan
Copy link
Owner

Thanks for your great work!

@lino-levan lino-levan merged commit 3c672be into lino-levan:main Oct 9, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants