Skip to content

Commit 2e59258

Browse files
authored
chore: release prep for v1.25.1
* chore: release prep for v1.25.1 * fix: fixed formatting * chore: final release prep
1 parent 6a98293 commit 2e59258

File tree

8 files changed

+154
-59
lines changed

8 files changed

+154
-59
lines changed

CHANGELOG.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,33 @@ This project attempts to follow [Keep a Changelog](https://keepachangelog.com/en
2222

2323
---
2424

25+
## [1.25.1]
26+
27+
### Added
28+
29+
- Introduced new **environment diagnostics endpoint** at `src/routes/api/env-check/+server.js`.
30+
- Returns resolved build and runtime environment data for verification.
31+
- Useful for confirming `ENV_MODE` / `PUBLIC_ENV_MODE` propagation on Vercel builds.
32+
- Helps troubleshoot environment mismatches between build-time and client-side contexts.
33+
34+
### Changed
35+
36+
- **vite.config.js**
37+
- Enhanced configuration to log build mode and environment variables during bundling.
38+
- Prints `mode`, `ENV_MODE`, `PUBLIC_ENV_MODE`, and `NODE_ENV` to aid CI/CD debugging.
39+
- Uses color-coded console output for clear visibility in build logs.
40+
- **env.js**
41+
- Simplified and stabilized environment detection logic for better cross-environment consistency.
42+
- Removed redundant imports and corrected handling of static vs dynamic `BUILD_ENV_MODE`.
43+
- Improved comments and type annotations for maintainability and IDE autocompletion.
44+
45+
### Developer Experience
46+
47+
- Build logs now clearly display environment information before bundling.
48+
- `env-check` API endpoint provides real-time environment inspection without rebuilding.
49+
50+
---
51+
2552
## [1.25.0]
2653

2754
### Added
@@ -1583,7 +1610,8 @@ This enables analytics filtering and CSP hardening for the audit environment.
15831610

15841611
<!-- Link references -->
15851612

1586-
[Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.0...HEAD
1613+
[Unreleased]: https://github.com/netwk-pro/netwk-pro.github.io/compare/v1.25.1...HEAD
1614+
[1.25.1]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.1
15871615
[1.25.0]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.25.0
15881616
[1.24.5]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.5
15891617
[1.24.4]: https://github.com/netwk-pro/netwk-pro.github.io/releases/tag/v1.24.4

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@networkpro/web",
33
"private": false,
4-
"version": "1.25.0",
4+
"version": "1.25.1",
55
"description": "Locking Down Networks, Unlocking Confidence™ | Security, Networking, Privacy — Network Pro Strategies",
66
"keywords": [
77
"advisory",

src/hooks.server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import { detectEnvironment } from '$lib/utils/env.js';
1414
*/
1515
export async function handle({ event, resolve }) {
1616
const response = await resolve(event);
17-
const { isAudit, isTest, isProd } = detectEnvironment();
1817

19-
console.log('[CSP Debug ENV]', detectEnvironment());
18+
const { isAudit, isTest, isProd, effective, mode } = detectEnvironment();
19+
console.log('[CSP Debug ENV]', { mode, effective, isProd, isAudit, isTest });
2020

2121
// Determine report URI
2222
const reportUri =

src/lib/stores/posthog.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,28 @@ let ph = null;
4545
export async function initPostHog() {
4646
if (initialized || typeof window === 'undefined') return;
4747

48-
const { isAudit, isDev, isTest, mode } = detectEnvironment();
48+
const { isAudit, isDev, isTest, mode, effective } = detectEnvironment();
4949

5050
// 🌐 Hybrid hostname + environment guard
5151
const host = window.location.hostname;
5252
const isAuditHost = /(^|\.)audit\.netwk\.pro$/i.test(host);
5353
const effectiveAudit = isAudit || isAuditHost;
5454

55+
// 🧭 Log environment context before any conditional logic
56+
console.info('[PostHog ENV]', {
57+
buildMode: mode,
58+
effectiveMode: effective,
59+
host,
60+
effectiveAudit,
61+
isDev,
62+
isTest,
63+
});
64+
65+
// 🚫 Skip analytics in audit context
5566
if (effectiveAudit) {
56-
console.info(`[PostHog] Skipping analytics (${mode} mode, host: ${host}).`);
67+
console.info(
68+
`[PostHog] Skipping analytics (${effective} mode, host: ${host}).`,
69+
);
5770
return;
5871
}
5972

src/lib/utils/env.js

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,49 +26,56 @@ This file is part of Network Pro.
2626

2727
/**
2828
* @typedef {object} EnvironmentInfo
29-
* @property {string} mode - The detected environment mode (`dev`, `prod`, `audit`, etc.).
30-
* @property {boolean} isDev - True when running in a development or local environment.
31-
* @property {boolean} isProd - True when running in production.
32-
* @property {boolean} isAudit - True when running in audit / staging environments.
33-
* @property {boolean} isCI - True when running in continuous integration (CI) pipelines.
34-
* @property {boolean} isTest - True when running under test or mock environments.
29+
* @property {string} mode - The build-time environment mode.
30+
* @property {string} effective - The environment actually being used (after host fallback).
31+
* @property {boolean} isDev
32+
* @property {boolean} isProd
33+
* @property {boolean} isAudit
34+
* @property {boolean} isCI
35+
* @property {boolean} isTest
3536
*/
3637

3738
/**
38-
* Normalizes environment detection across client, SSR, and build contexts.
39-
* Uses `import.meta.env` for Vite build-time vars and `process.env` for runtime vars.
39+
* Build-time mode injected by Vite.
40+
* Always baked into the client bundle.
41+
* Falls back to 'production' if nothing else is defined.
42+
*/
43+
export const BUILD_ENV_MODE =
44+
import.meta.env.PUBLIC_ENV_MODE || import.meta.env.MODE || 'production';
45+
46+
/**
47+
* Detects the current environment, combining build-time
48+
* and runtime (hostname-based) checks.
49+
* Works safely in both Node and browser contexts.
4050
*
41-
* @returns {EnvironmentInfo} Normalized environment context flags.
51+
* @returns {EnvironmentInfo}
4252
*/
4353
export function detectEnvironment() {
44-
/** @type {string | undefined} */
45-
const viteMode = import.meta.env?.MODE;
46-
/** @type {string | undefined} */
47-
const publicEnvMode = import.meta.env?.PUBLIC_ENV_MODE;
54+
const mode = BUILD_ENV_MODE;
55+
56+
// Client-side fallback for audit/netwk environments
57+
const host = typeof window !== 'undefined' ? window.location.hostname : '';
58+
59+
const hostIsAudit = /(^|\.)audit\.netwk\.pro$/i.test(host);
4860

49-
/** @type {string | undefined} */
50-
const nodeEnv =
51-
typeof process !== 'undefined' && process?.env?.NODE_ENV
52-
? process.env.NODE_ENV
53-
: undefined;
61+
const isDev = ['development', 'dev'].includes(mode);
62+
const isProd = ['production', 'prod'].includes(mode);
63+
const isAudit = mode === 'audit' || hostIsAudit;
64+
const isCI = mode === 'ci';
65+
const isTest = mode === 'test';
5466

55-
/** @type {string | undefined} */
56-
const envMode =
57-
typeof process !== 'undefined' && process?.env?.ENV_MODE
58-
? process.env.ENV_MODE
59-
: undefined;
67+
// Prefer host-based detection if it disagrees with build-time
68+
const effective = hostIsAudit && !isAudit ? 'audit(host)' : mode;
6069

61-
// Fallback order — guarantees a mode string even if nothing is set
62-
/** @type {string} */
63-
const mode = envMode || publicEnvMode || viteMode || nodeEnv || 'unknown';
70+
if (typeof window === 'undefined') {
71+
// Only log on server / build to avoid client noise
72+
console.log('[detectEnvironment] Build mode:', mode);
73+
if (hostIsAudit && mode !== 'audit') {
74+
console.log(
75+
'[detectEnvironment] Host suggests audit, overriding build-time mode.',
76+
);
77+
}
78+
}
6479

65-
// Return a normalized, typed object
66-
return {
67-
mode,
68-
isDev: ['development', 'dev'].includes(mode),
69-
isProd: ['production', 'prod'].includes(mode),
70-
isAudit: mode === 'audit',
71-
isCI: mode === 'ci',
72-
isTest: mode === 'test',
73-
};
80+
return { mode, effective, isDev, isProd, isAudit, isCI, isTest };
7481
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* ==========================================================================
2+
src/routes/api/env-check/+server.js
3+
4+
Copyright © 2025 Network Pro Strategies (Network Pro™)
5+
SPDX-License-Identifier: CC-BY-4.0 OR GPL-3.0-or-later
6+
This file is part of Network Pro.
7+
========================================================================== */
8+
9+
/**
10+
* @file Returns the current environment state (client + server vars)
11+
* @type {import('@sveltejs/kit').RequestHandler}
12+
*/
13+
export async function GET() {
14+
const data = {
15+
NODE_ENV: process.env.NODE_ENV,
16+
ENV_MODE: process.env.ENV_MODE,
17+
PUBLIC_ENV_MODE: process.env.PUBLIC_ENV_MODE,
18+
IMPORT_META_MODE: import.meta.env.MODE,
19+
IMPORT_META_PUBLIC: import.meta.env.PUBLIC_ENV_MODE,
20+
};
21+
22+
return new Response(JSON.stringify(data, null, 2), {
23+
headers: { 'Content-Type': 'application/json' },
24+
});
25+
}

vite.config.js

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,42 @@ import tsconfigPaths from 'vite-tsconfig-paths'; // NEW: tsconfig/jsconfig alias
1717
// Compute absolute project root
1818
const projectRoot = fileURLToPath(new URL('.', import.meta.url));
1919

20-
export default defineConfig({
21-
plugins: [
22-
tsconfigPaths(), // Insert before sveltekit()
23-
devtoolsJson({
24-
projectRoot: resolve(projectRoot), // Correct key name
25-
normalizeForWindowsContainer: true, // optional, helps with path consistency on Windows or WSL
26-
uuid: 'ad0db4f4-6172-4c1e-ae17-26b1bee53764',
27-
}),
28-
sveltekit(),
29-
lightningcssPlugin({
30-
minify: process.env.NODE_ENV === 'production',
31-
pruneUnusedFontFaceRules: true,
32-
pruneUnusedKeyframes: true,
33-
removeUnusedFontFaces: true,
34-
}),
35-
],
20+
export default defineConfig(({ mode }) => {
21+
// --- 🧩 Log Build Environment Info -------------------------------------
22+
console.log(
23+
'\x1b[36m%s\x1b[0m',
24+
'──────────────────────────────────────────────',
25+
);
26+
console.log('\x1b[33m%s\x1b[0m', `📦 Building Network Pro — mode: ${mode}`);
27+
console.log(
28+
'\x1b[36m%s\x1b[0m',
29+
'──────────────────────────────────────────────',
30+
);
31+
console.log('ENV_MODE:', process.env.ENV_MODE);
32+
console.log('PUBLIC_ENV_MODE:', process.env.PUBLIC_ENV_MODE);
33+
console.log('NODE_ENV:', process.env.NODE_ENV);
34+
console.log(
35+
'\x1b[36m%s\x1b[0m',
36+
'──────────────────────────────────────────────',
37+
);
38+
39+
// -----------------------------------------------------------------------
40+
41+
return {
42+
plugins: [
43+
tsconfigPaths(),
44+
devtoolsJson({
45+
projectRoot: resolve(projectRoot),
46+
normalizeForWindowsContainer: true,
47+
uuid: 'ad0db4f4-6172-4c1e-ae17-26b1bee53764',
48+
}),
49+
sveltekit(),
50+
lightningcssPlugin({
51+
minify: process.env.NODE_ENV === 'production',
52+
pruneUnusedFontFaceRules: true,
53+
pruneUnusedKeyframes: true,
54+
removeUnusedFontFaces: true,
55+
}),
56+
],
57+
};
3658
});

0 commit comments

Comments
 (0)