diff --git a/.gitignore b/.gitignore index 69209fd40..2ad11bee5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ /build/ node_modules/ NOTES +config/local* # KaTeX files *.min.css diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json new file mode 100644 index 000000000..4076b2e04 --- /dev/null +++ b/config/custom-environment-variables.json @@ -0,0 +1,24 @@ +{ + "nodes": { + "fallbackPublicExplorer": "FALLBACK_PUBLIC_EXPLORER", + "apiVersion": "API_VERSION", + "defaultHttpdPort": "DEFAULT_HTTPD_PORT", + "defaultLocalHttpdPort": "DEFAULT_LOCAL_HTTPD_PORT", + "defaultHttpdHostname": "DEFAULT_HTTPD_HOSTNAME", + "defaultHttpdScheme": "DEFAULT_HTTPD_SCHEME", + "defaultNodePort": "DEFAULT_NODE_PORT", + "pinned": { + "__name": "PINNED_NODES", + "__format": "json" + } + }, + "supportWebsite": "SUPPORT_WEBSITE", + "reactions": { + "__name": "REACTIONS", + "__format": "json" + }, + "fallbackPreferredSeed": { + "__name": "FALLBACK_PREFERRED_SEED", + "__format": "json" + } +} diff --git a/src/config.json b/config/default.json similarity index 100% rename from src/config.json rename to config/default.json diff --git a/config/production.json b/config/production.json new file mode 120000 index 000000000..90abb0c46 --- /dev/null +++ b/config/production.json @@ -0,0 +1 @@ +default.json \ No newline at end of file diff --git a/config/test.json b/config/test.json new file mode 100644 index 000000000..7e9033abc --- /dev/null +++ b/config/test.json @@ -0,0 +1,17 @@ +{ + "nodes": { + "defaultHttpdPort": 8081, + "defaultLocalHttpdPort": 8081, + "defaultHttpdHostname": "127.0.0.1", + "defaultHttpdScheme": "http", + "pinned": [ + { + "baseUrl": { + "hostname": "127.0.0.1", + "port": 8081, + "scheme": "http" + } + } + ] + } +} diff --git a/httpd-client/lib/fetcher.ts b/httpd-client/lib/fetcher.ts index 82ef422d5..4e36132ff 100644 --- a/httpd-client/lib/fetcher.ts +++ b/httpd-client/lib/fetcher.ts @@ -3,7 +3,7 @@ import type { ZodIssue, ZodType, TypeOf } from "zod"; -import { config } from "@app/lib/config"; +import config from "virtual:config"; import { compare } from "compare-versions"; export interface BaseUrl { diff --git a/httpd-client/vite.config.ts b/httpd-client/vite.config.ts index 0b5959a8c..1ff90c882 100644 --- a/httpd-client/vite.config.ts +++ b/httpd-client/vite.config.ts @@ -1,7 +1,14 @@ -import { defineConfig } from "vite"; +import nodeConfig from "config"; import path from "node:path"; +import virtual from "vite-plugin-virtual"; +import { defineConfig } from "vite"; export default defineConfig({ + plugins: [ + virtual({ + "virtual:config": nodeConfig.util.toObject(), + }), + ], test: { environment: "happy-dom", include: ["httpd-client/tests/*.test.ts"], diff --git a/module.d.ts b/module.d.ts new file mode 100644 index 000000000..71193ab34 --- /dev/null +++ b/module.d.ts @@ -0,0 +1,19 @@ +declare module "virtual:*" { + const config: { + nodes: { + apiVersion: string; + fallbackPublicExplorer: string; + defaultHttpdPort: number; + defaultHttpdHostname: string; + defaultLocalHttpdPort: number; + defaultNodePort: number; + defaultHttpdScheme: string; + pinned: { baseUrl: BaseUrl }[]; + }; + reactions: string[]; + supportWebsite: string; + fallbackPreferredSeed: BaseUrl; + }; + + export default config; +} diff --git a/package-lock.json b/package-lock.json index ddff135d7..c1780632e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,6 +33,7 @@ "@playwright/test": "^1.42.1", "@sveltejs/vite-plugin-svelte": "^3.0.2", "@tsconfig/svelte": "^5.0.3", + "@types/config": "^3.3.4", "@types/dompurify": "^3.0.5", "@types/katex": "^0.16.7", "@types/lodash": "^4.17.0", @@ -42,6 +43,7 @@ "@types/wait-on": "^5.3.4", "@typescript-eslint/eslint-plugin": "^7.4.0", "chalk": "^5.3.0", + "config": "^3.3.11", "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-no-only-tests": "^3.1.0", @@ -55,6 +57,7 @@ "svelte-check": "^3.6.8", "typescript": "^5.4.3", "vite": "^5.2.6", + "vite-plugin-virtual": "^0.3.0", "vitest": "^1.4.0", "wait-on": "^7.2.0" }, @@ -1020,6 +1023,12 @@ "integrity": "sha512-Ms0t9K0oxioSb0lrZ5NRysx0nE/KsojYOG+db9v6wSaU/+P37vc0WRmh1QE1c8IAtTniD4yEhffGQuTKF8uaPw==", "dev": true }, + "node_modules/@types/config": { + "version": "3.3.4", + "resolved": "https://registry.npmjs.org/@types/config/-/config-3.3.4.tgz", + "integrity": "sha512-qFiTLnWy+TdPSMIXFHP+87lFXFRM4SXjRS+CSB66+56TrpLNw003y1sh7DGaaC1NGesxgKoT5FDy6dyA1Xju/g==", + "dev": true + }, "node_modules/@types/dompurify": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/@types/dompurify/-/dompurify-3.0.5.tgz", @@ -1894,6 +1903,18 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, + "node_modules/config": { + "version": "3.3.11", + "resolved": "https://registry.npmjs.org/config/-/config-3.3.11.tgz", + "integrity": "sha512-Dhn63ZoWCW5EMg4P0Sl/XNsj/7RLiUIA1x1npCy+m2cRwRHzLnt3UtYtxRDMZW/6oOMdWhCzaGYkOcajGgrAOA==", + "dev": true, + "dependencies": { + "json5": "^2.2.3" + }, + "engines": { + "node": ">= 10.0.0" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -3159,6 +3180,18 @@ "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", "dev": true }, + "node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "dev": true, + "bin": { + "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/jsonc-parser": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.2.1.tgz", @@ -5017,6 +5050,15 @@ "url": "https://opencollective.com/vitest" } }, + "node_modules/vite-plugin-virtual": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/vite-plugin-virtual/-/vite-plugin-virtual-0.3.0.tgz", + "integrity": "sha512-TOtrWw6jKrJNXfxhGRUiQzfAP1gRkYkVzMkJNjHUJ8idLuxf8eeeDKZKZHhdeYfaCc/87rv+KvWE2iCy1QInWA==", + "dev": true, + "peerDependencies": { + "vite": "^2.0.0 || ^3.0.0 || ^4.0.0 || ^5.0.0" + } + }, "node_modules/vite/node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", diff --git a/package.json b/package.json index 28cf35912..63260635b 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "check": "scripts/check", "format": "npx prettier '**/*.@(ts|js|svelte|json|css|html|yml)' --write", "test:unit": "TZ='UTC' vitest run", - "test:e2e": "TZ='UTC' playwright test", - "test:httpd-api:unit": "TZ='UTC' vitest run --config httpd-client/vite.config.ts --reporter verbose" + "test:e2e": "NODE_CONFIG_ENV='test' TZ='UTC' playwright test", + "test:httpd-api:unit": "NODE_CONFIG_ENV='test' TZ='UTC' vitest run --config httpd-client/vite.config.ts --reporter verbose" }, "type": "module", "engines": { @@ -19,6 +19,7 @@ "@playwright/test": "^1.42.1", "@sveltejs/vite-plugin-svelte": "^3.0.2", "@tsconfig/svelte": "^5.0.3", + "@types/config": "^3.3.4", "@types/dompurify": "^3.0.5", "@types/katex": "^0.16.7", "@types/lodash": "^4.17.0", @@ -28,6 +29,7 @@ "@types/wait-on": "^5.3.4", "@typescript-eslint/eslint-plugin": "^7.4.0", "chalk": "^5.3.0", + "config": "^3.3.11", "eslint": "^8.57.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-no-only-tests": "^3.1.0", @@ -41,6 +43,7 @@ "svelte-check": "^3.6.8", "typescript": "^5.4.3", "vite": "^5.2.6", + "vite-plugin-virtual": "^0.3.0", "vitest": "^1.4.0", "wait-on": "^7.2.0" }, diff --git a/src/App.svelte b/src/App.svelte index dd8f2c75b..14df38fb7 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -31,7 +31,7 @@ void httpd.initialize().finally(() => void router.loadFromLocation()); - if (!window.VITEST && !window.PLAYWRIGHT && import.meta.env.PROD) { + if (import.meta.env.PROD) { const plausible = Plausible({ domain: "app.radicle.xyz" }); plausible.enableAutoPageviews(); diff --git a/src/App/Settings.svelte b/src/App/Settings.svelte index 9e1370a36..d44a7797d 100644 --- a/src/App/Settings.svelte +++ b/src/App/Settings.svelte @@ -1,6 +1,6 @@