revine 1.0.6 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -5,4 +5,5 @@ export { NavLink } from "./components/NavLink.js";
5
5
  export { defineConfig } from "./runtime/defineConfig.js";
6
6
  export type { LayoutProps } from "./runtime/types.js";
7
7
  export type { LinkProps } from "./components/Link.js";
8
+ export { env, envAll } from "./runtime/env.js";
8
9
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,cAAc,EACd,WAAW,EACX,WAAW,EACX,SAAS,EACT,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,cAAc,EACd,WAAW,EACX,WAAW,EACX,SAAS,EACT,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/client.js CHANGED
@@ -2,3 +2,4 @@ export { Outlet, RouterProvider, useLocation, useNavigate, useParams, useSearchP
2
2
  export { Link } from "./components/Link.js";
3
3
  export { NavLink } from "./components/NavLink.js";
4
4
  export { defineConfig } from "./runtime/defineConfig.js";
5
+ export { env, envAll } from "./runtime/env.js";
@@ -1,6 +1,7 @@
1
1
  export declare const defaultViteConfig: {
2
2
  plugins: any[];
3
3
  logLevel: string;
4
+ envPrefix: string;
4
5
  server: {
5
6
  clearScreen: boolean;
6
7
  open: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../../../src/runtime/bundler/defaults/vite.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;CAa7B,CAAC"}
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../../../src/runtime/bundler/defaults/vite.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;CAgB7B,CAAC"}
@@ -4,6 +4,9 @@ import { revineLoggerPlugin } from "../viteLoggerPlugin.js";
4
4
  export const defaultViteConfig = {
5
5
  plugins: [react(), revinePlugin(), revineLoggerPlugin()],
6
6
  logLevel: "silent",
7
+ // Only expose env variables prefixed with REVINE_PUBLIC_ to the browser bundle.
8
+ // Variables without this prefix are never included in client-side code.
9
+ envPrefix: "REVINE_PUBLIC_",
7
10
  server: {
8
11
  clearScreen: false,
9
12
  open: false,
@@ -1 +1 @@
1
- {"version":3,"file":"generateConfig.d.ts","sourceRoot":"","sources":["../../../src/runtime/bundler/generateConfig.ts"],"names":[],"mappings":"AAUA,wBAAsB,wBAAwB,iBAyB7C"}
1
+ {"version":3,"file":"generateConfig.d.ts","sourceRoot":"","sources":["../../../src/runtime/bundler/generateConfig.ts"],"names":[],"mappings":"AA8CA,wBAAsB,wBAAwB,iBAiC7C"}
@@ -1,16 +1,54 @@
1
+ import dotenv from "dotenv";
2
+ import fs from "fs-extra";
1
3
  import { merge } from "lodash-es";
2
4
  import path from "path";
3
- import fs from "fs-extra";
4
5
  import { defaultViteConfig } from "./defaults/vite.js";
5
6
  import { loadUserConfig } from "./utils/loadUserConfig.js";
7
+ /**
8
+ * Reads all .env files in the project root and returns a Vite `define` map
9
+ * that replaces `process.env.REVINE_PUBLIC_*` with the actual string values
10
+ * at build/dev time — exactly like Next.js does with process.env.
11
+ *
12
+ * Only REVINE_PUBLIC_ prefixed variables are exposed to the browser bundle.
13
+ * All other variables are ignored for safety.
14
+ */
15
+ function buildProcessEnvDefines(cwd) {
16
+ const defines = {};
17
+ // Load .env, .env.local, .env.development / .env.production in priority order
18
+ const envFiles = [
19
+ ".env",
20
+ ".env.local",
21
+ `.env.${process.env.NODE_ENV || "development"}`,
22
+ `.env.${process.env.NODE_ENV || "development"}.local`,
23
+ ];
24
+ for (const file of envFiles) {
25
+ const filePath = path.resolve(cwd, file);
26
+ if (fs.existsSync(filePath)) {
27
+ const parsed = dotenv.parse(fs.readFileSync(filePath));
28
+ for (const [key, value] of Object.entries(parsed)) {
29
+ if (key.startsWith("REVINE_PUBLIC_")) {
30
+ // Replace process.env.REVINE_PUBLIC_FOO with the literal string value
31
+ defines[`process.env.${key}`] = JSON.stringify(value);
32
+ }
33
+ }
34
+ }
35
+ }
36
+ return defines;
37
+ }
6
38
  export async function generateRevineViteConfig() {
39
+ const cwd = process.cwd();
7
40
  // Load the user's revine.config.ts
8
41
  const userConfig = (await loadUserConfig());
9
42
  // Merge user "vite" overrides with your default config
10
43
  const finalConfig = merge({}, defaultViteConfig, userConfig.vite || {});
44
+ // Inject process.env.REVINE_PUBLIC_* defines so users can write:
45
+ // const token = process.env.REVINE_PUBLIC_GITHUB_TOKEN;
46
+ // These are statically replaced at build time — nothing leaks to the bundle.
47
+ const processEnvDefines = buildProcessEnvDefines(cwd);
48
+ finalConfig.define = merge({}, processEnvDefines, finalConfig.define || {});
11
49
  // Dynamically add Tailwind if present in the project
12
50
  try {
13
- const projectPkgPath = path.resolve(process.cwd(), "package.json");
51
+ const projectPkgPath = path.resolve(cwd, "package.json");
14
52
  const pkg = await fs.readJson(projectPkgPath);
15
53
  const hasTailwind = pkg.devDependencies?.["@tailwindcss/vite"] ||
16
54
  pkg.dependencies?.["@tailwindcss/vite"];
@@ -0,0 +1,20 @@
1
+ /**
2
+ * env() — Revine's typed helper for accessing public environment variables.
3
+ *
4
+ * Usage:
5
+ * import { env } from "revine";
6
+ * const token = env("REVINE_PUBLIC_GITHUB_TOKEN");
7
+ *
8
+ * Rules:
9
+ * - Variables MUST be prefixed with REVINE_PUBLIC_ to be exposed to the browser.
10
+ * - Variables without this prefix are never included in the client bundle.
11
+ * - Values are replaced at build time by Vite (static string replacement).
12
+ * - Never use import.meta.env directly — always use this helper.
13
+ */
14
+ export declare function env(key: string): string | undefined;
15
+ /**
16
+ * All public env variables as a typed object.
17
+ * Keys are the full variable names including the REVINE_PUBLIC_ prefix.
18
+ */
19
+ export declare function envAll(): Record<string, string | undefined>;
20
+ //# sourceMappingURL=env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/runtime/env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEnD;AAED;;;GAGG;AACH,wBAAgB,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAQ3D"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * env() — Revine's typed helper for accessing public environment variables.
3
+ *
4
+ * Usage:
5
+ * import { env } from "revine";
6
+ * const token = env("REVINE_PUBLIC_GITHUB_TOKEN");
7
+ *
8
+ * Rules:
9
+ * - Variables MUST be prefixed with REVINE_PUBLIC_ to be exposed to the browser.
10
+ * - Variables without this prefix are never included in the client bundle.
11
+ * - Values are replaced at build time by Vite (static string replacement).
12
+ * - Never use import.meta.env directly — always use this helper.
13
+ */
14
+ export function env(key) {
15
+ return import.meta.env[key];
16
+ }
17
+ /**
18
+ * All public env variables as a typed object.
19
+ * Keys are the full variable names including the REVINE_PUBLIC_ prefix.
20
+ */
21
+ export function envAll() {
22
+ const all = {};
23
+ for (const [key, value] of Object.entries(import.meta.env)) {
24
+ if (key.startsWith("REVINE_PUBLIC_")) {
25
+ all[key] = value;
26
+ }
27
+ }
28
+ return all;
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "revine",
3
- "version": "1.0.6",
3
+ "version": "1.1.1",
4
4
  "description": "A react framework, but better.",
5
5
  "license": "MIT",
6
6
  "author": "Rachit Bharadwaj",
@@ -29,6 +29,7 @@
29
29
  "@vitejs/plugin-react": "^4.2.1",
30
30
  "chalk": "^5.4.1",
31
31
  "commander": "^13.1.0",
32
+ "dotenv": "^16.4.5",
32
33
  "fs-extra": "^11.3.0",
33
34
  "inquirer": "^12.4.1",
34
35
  "lodash-es": "^4.17.21",
@@ -39,6 +40,7 @@
39
40
  },
40
41
  "devDependencies": {
41
42
  "@tailwindcss/vite": "^4.2.0",
43
+ "@types/dotenv": "^8.2.3",
42
44
  "@types/fs-extra": "^11.0.4",
43
45
  "@types/lodash-es": "^4.17.9",
44
46
  "@types/node": "^22.13.0",
package/src/client.ts CHANGED
@@ -11,4 +11,5 @@ export { Link } from "./components/Link.js";
11
11
  export { NavLink } from "./components/NavLink.js";
12
12
  export { defineConfig } from "./runtime/defineConfig.js";
13
13
  export type { LayoutProps } from "./runtime/types.js";
14
- export type { LinkProps } from "./components/Link.js";
14
+ export type { LinkProps } from "./components/Link.js";
15
+ export { env, envAll } from "./runtime/env.js";
@@ -5,6 +5,9 @@ import { revineLoggerPlugin } from "../viteLoggerPlugin.js";
5
5
  export const defaultViteConfig = {
6
6
  plugins: [react(), revinePlugin(), revineLoggerPlugin()],
7
7
  logLevel: "silent",
8
+ // Only expose env variables prefixed with REVINE_PUBLIC_ to the browser bundle.
9
+ // Variables without this prefix are never included in client-side code.
10
+ envPrefix: "REVINE_PUBLIC_",
8
11
  server: {
9
12
  clearScreen: false,
10
13
  open: false,
@@ -1,6 +1,7 @@
1
+ import dotenv from "dotenv";
2
+ import fs from "fs-extra";
1
3
  import { merge } from "lodash-es";
2
4
  import path from "path";
3
- import fs from "fs-extra";
4
5
  import { defaultViteConfig } from "./defaults/vite.js";
5
6
  import { loadUserConfig } from "./utils/loadUserConfig.js";
6
7
 
@@ -8,16 +9,59 @@ interface UserConfig {
8
9
  vite?: Record<string, unknown>;
9
10
  }
10
11
 
12
+ /**
13
+ * Reads all .env files in the project root and returns a Vite `define` map
14
+ * that replaces `process.env.REVINE_PUBLIC_*` with the actual string values
15
+ * at build/dev time — exactly like Next.js does with process.env.
16
+ *
17
+ * Only REVINE_PUBLIC_ prefixed variables are exposed to the browser bundle.
18
+ * All other variables are ignored for safety.
19
+ */
20
+ function buildProcessEnvDefines(cwd: string): Record<string, string> {
21
+ const defines: Record<string, string> = {};
22
+
23
+ // Load .env, .env.local, .env.development / .env.production in priority order
24
+ const envFiles = [
25
+ ".env",
26
+ ".env.local",
27
+ `.env.${process.env.NODE_ENV || "development"}`,
28
+ `.env.${process.env.NODE_ENV || "development"}.local`,
29
+ ];
30
+
31
+ for (const file of envFiles) {
32
+ const filePath = path.resolve(cwd, file);
33
+ if (fs.existsSync(filePath)) {
34
+ const parsed = dotenv.parse(fs.readFileSync(filePath));
35
+ for (const [key, value] of Object.entries(parsed)) {
36
+ if (key.startsWith("REVINE_PUBLIC_")) {
37
+ // Replace process.env.REVINE_PUBLIC_FOO with the literal string value
38
+ defines[`process.env.${key}`] = JSON.stringify(value);
39
+ }
40
+ }
41
+ }
42
+ }
43
+
44
+ return defines;
45
+ }
46
+
11
47
  export async function generateRevineViteConfig() {
48
+ const cwd = process.cwd();
49
+
12
50
  // Load the user's revine.config.ts
13
51
  const userConfig = (await loadUserConfig()) as UserConfig;
14
52
 
15
53
  // Merge user "vite" overrides with your default config
16
54
  const finalConfig = merge({}, defaultViteConfig, userConfig.vite || {});
17
55
 
56
+ // Inject process.env.REVINE_PUBLIC_* defines so users can write:
57
+ // const token = process.env.REVINE_PUBLIC_GITHUB_TOKEN;
58
+ // These are statically replaced at build time — nothing leaks to the bundle.
59
+ const processEnvDefines = buildProcessEnvDefines(cwd);
60
+ finalConfig.define = merge({}, processEnvDefines, finalConfig.define || {});
61
+
18
62
  // Dynamically add Tailwind if present in the project
19
63
  try {
20
- const projectPkgPath = path.resolve(process.cwd(), "package.json");
64
+ const projectPkgPath = path.resolve(cwd, "package.json");
21
65
  const pkg = await fs.readJson(projectPkgPath);
22
66
  const hasTailwind =
23
67
  pkg.devDependencies?.["@tailwindcss/vite"] ||
@@ -0,0 +1,30 @@
1
+ /**
2
+ * env() — Revine's typed helper for accessing public environment variables.
3
+ *
4
+ * Usage:
5
+ * import { env } from "revine";
6
+ * const token = env("REVINE_PUBLIC_GITHUB_TOKEN");
7
+ *
8
+ * Rules:
9
+ * - Variables MUST be prefixed with REVINE_PUBLIC_ to be exposed to the browser.
10
+ * - Variables without this prefix are never included in the client bundle.
11
+ * - Values are replaced at build time by Vite (static string replacement).
12
+ * - Never use import.meta.env directly — always use this helper.
13
+ */
14
+ export function env(key: string): string | undefined {
15
+ return (import.meta.env as Record<string, string | undefined>)[key];
16
+ }
17
+
18
+ /**
19
+ * All public env variables as a typed object.
20
+ * Keys are the full variable names including the REVINE_PUBLIC_ prefix.
21
+ */
22
+ export function envAll(): Record<string, string | undefined> {
23
+ const all: Record<string, string | undefined> = {};
24
+ for (const [key, value] of Object.entries(import.meta.env)) {
25
+ if (key.startsWith("REVINE_PUBLIC_")) {
26
+ all[key] = value as string | undefined;
27
+ }
28
+ }
29
+ return all;
30
+ }
@@ -0,0 +1,10 @@
1
+ # Public environment variables — exposed to the browser bundle.
2
+ # Variables MUST be prefixed with REVINE_PUBLIC_ to be accessible in your app.
3
+ # Copy this file to .env and fill in your values.
4
+
5
+ # Example:
6
+ # REVINE_PUBLIC_API_URL=https://api.example.com
7
+ # REVINE_PUBLIC_APP_NAME=My Revine App
8
+
9
+ # ⚠️ Variables WITHOUT the REVINE_PUBLIC_ prefix are NEVER sent to the browser.
10
+ # Use those for server-side secrets only (they stay in Node processes).
@@ -1,2 +1,21 @@
1
1
  /// <reference types="vite/client" />
2
2
  /// <reference types="revine/routing" />
3
+
4
+ /**
5
+ * Augment ImportMetaEnv so TypeScript knows about your REVINE_PUBLIC_ variables.
6
+ *
7
+ * Add your own variables here:
8
+ *
9
+ * interface ImportMetaEnv {
10
+ * readonly REVINE_PUBLIC_API_URL: string;
11
+ * readonly REVINE_PUBLIC_GITHUB_TOKEN: string;
12
+ * }
13
+ */
14
+ interface ImportMetaEnv {
15
+ // Add your REVINE_PUBLIC_ variables here
16
+ [key: `REVINE_PUBLIC_${string}`]: string | undefined;
17
+ }
18
+
19
+ interface ImportMeta {
20
+ readonly env: ImportMetaEnv;
21
+ }