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

Add beta-switch package #1263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Oksamies
Copy link
Contributor

No description provided.

Copy link
Contributor Author

Oksamies commented Nov 13, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Comment on lines 31 to 33
const desireCookie = new RegExp("betaDesire=([^;]+);").exec(
document.cookie[-1] === ";" ? document.cookie : document.cookie + ";"
)?.[1];
Copy link

Choose a reason for hiding this comment

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

JavaScript does not support negative array indexing. To check if the last character is a semicolon, replace document.cookie[-1] with document.cookie[document.cookie.length - 1]. This will properly access the last character of the string.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Comment on lines 23 to 40
enabledPages.forEach((regPath) => {
const regExecuted = new RegExp(regPath).exec(window.location.pathname);
const found = regExecuted !== null && regExecuted.length < 2;
if (!betaIsAvailable && found) {
betaIsAvailable = true;
}
}, betaIsAvailable);
Copy link

Choose a reason for hiding this comment

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

The forEach has a second argument betaIsAvailable passed as thisArg which appears unintentional and could lead to bugs. The thisArg parameter is meant to set the value of this inside the callback function, but isn't needed here. Consider removing the second argument to forEach.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Comment on lines 6 to 8
"main": "dist/thunderstore-beta-switch.cjs.js",
"module": "dist/thunderstore-beta-switch.esm.js",
"types": "dist/thunderstore-beta-switch.cjs.d.ts",
Copy link

Choose a reason for hiding this comment

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

There appears to be a mismatch between the output paths specified in package.json and TypeScript's actual output. TypeScript's tsc command will generate different file names than what's listed here. To resolve this, either:

  1. Add a bundler (like Rollup or esbuild) to generate the .cjs.js and .esm.js files, or
  2. Update these paths to match TypeScript's output format (typically .js and .d.ts files)

This will ensure the built files are available at the locations the package declares.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

@Oksamies Oksamies force-pushed the 11-13-add_beta-switch_package branch from 2f4a88e to a8ea507 Compare November 19, 2024 11:38
Comment on lines 12 to 16
async function getCookie(key) {
return new RegExp(`${key}=([^;]+);`).exec(
document.cookie[-1] === ";" ? document.cookie : document.cookie + ";"
)?.[1];
}
Copy link

Choose a reason for hiding this comment

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

The document.cookie[-1] check is unsafe since document.cookie may be empty. A simpler and more robust approach would be to always append the semicolon: document.cookie + ';'. This eliminates the need for the conditional and handles empty cookie cases gracefully.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

Comment on lines 17 to 21
async function setCookie(key, value) {
const date = new Date();
date.setFullYear(date.getFullYear() + 1);
document.cookie = `${key}=${value}; expires=${date.toUTCString()}; path=/`;
}
Copy link

Choose a reason for hiding this comment

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

The cookie needs a domain attribute to enable sharing between subdomains. Add ; domain=.thunderstore.temp to the cookie string to allow both thunderstore.temp and new.thunderstore.temp to access it.

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

@Oksamies Oksamies force-pushed the 11-13-add_beta-switch_package branch from a8ea507 to 430cecc Compare November 30, 2024 09:34
@@ -8,6 +8,7 @@ events {
http {
server {
listen 80;
server_name thunderstore.temp
Copy link

Choose a reason for hiding this comment

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

The server_name directive is missing a semicolon, which will cause nginx to fail on startup. The correct syntax is:

server_name thunderstore.temp;

Spotted by Graphite Reviewer

Is this helpful? React 👍 or 👎 to let us know.

@Oksamies Oksamies force-pushed the 11-13-add_beta-switch_package branch from 430cecc to 29e7b60 Compare November 30, 2024 09:39
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.

1 participant