Skip to content

Commit

Permalink
fix: conflicting SIGINT handlers (#6289)
Browse files Browse the repository at this point in the history
There were two competing `SIGINT` handlers and the result was unreleased Console resources.

This PR removes the `conf` package (which was registering a `SIGINT` handler) in favor of simple read and write methods for the config file.

Fixes #6018. Supersedes #6275.
  • Loading branch information
skyrpex authored Apr 22, 2024
1 parent 87c2713 commit b7d87b7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 76 deletions.
1 change: 0 additions & 1 deletion apps/wing-console/console/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"@wingconsole/ui": "workspace:^",
"autoprefixer": "^10.4.15",
"bump-pack": "workspace:^",
"conf": "^11.0.2",
"dotenv": "^16.3.1",
"eslint": "^8.48.0",
"nanoid": "^4.0.2",
Expand Down
4 changes: 2 additions & 2 deletions apps/wing-console/console/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"@wingconsole/tsconfig": "workspace:^",
"bump-pack": "workspace:^",
"chokidar": "^3.5.3",
"conf": "^11.0.2",
"constructs": "^10.3",
"cors": "^2.8.5",
"emittery": "^1.0.1",
"env-paths": "^3.0.0",
"esbuild-plugin-raw": "^0.1.7",
"eslint": "^8.48.0",
"express": "^4.19.2",
Expand All @@ -58,4 +58,4 @@
"volta": {
"extends": "../../../../package.json"
}
}
}
40 changes: 30 additions & 10 deletions apps/wing-console/console/server/src/utils/terms-and-conditions.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
// @ts-ignore-next-line
import Conf from "conf";
import * as fs from "node:fs";

import envPaths from "env-paths";

// @ts-ignore-next-line
import License from "../../LICENSE.md?raw";

const PROJECT_NAME = "@wingconsole/server";
const CONFIG_KEY = "termsAndConditions";

const paths = envPaths(PROJECT_NAME);

const getConfig = () => {
try {
return JSON.stringify(
fs.readFileSync(paths.config, "utf8"),
) as unknown as Record<string, any>;
} catch (error) {
console.error(error);
}
};

const saveConfig = (config: Record<string, any>) => {
try {
fs.writeFileSync(paths.config, JSON.stringify(config, undefined, 2));
} catch (error) {
console.error(error);
}
};

export const isTermsAccepted = (): boolean => {
const config = new Conf({
projectName: PROJECT_NAME,
});
const config = getConfig();

const accepted = config.get(CONFIG_KEY) as boolean;
const accepted = config?.[CONFIG_KEY];
return accepted === true;
};

export const acceptTerms = (value: boolean) => {
const config = new Conf({
projectName: PROJECT_NAME,
});
const config = getConfig();

config.set(CONFIG_KEY, value);
saveConfig({
...config,
[CONFIG_KEY]: value,
});
};

export const getLicense = (): string => {
Expand Down
70 changes: 7 additions & 63 deletions pnpm-lock.yaml

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

0 comments on commit b7d87b7

Please sign in to comment.