revine 1.1.0 → 1.1.2
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/runtime/bundler/defaults/vite.d.ts +5 -0
- package/dist/runtime/bundler/defaults/vite.d.ts.map +1 -1
- package/dist/runtime/bundler/defaults/vite.js +7 -0
- package/dist/runtime/bundler/generateConfig.d.ts.map +1 -1
- package/dist/runtime/bundler/generateConfig.js +40 -2
- package/package.json +3 -1
- package/src/runtime/bundler/defaults/vite.ts +7 -0
- package/src/runtime/bundler/generateConfig.ts +46 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../../../src/runtime/bundler/defaults/vite.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../../../src/runtime/bundler/defaults/vite.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;CAsB7B,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import react from "@vitejs/plugin-react";
|
|
2
|
+
import path from "path";
|
|
2
3
|
import { revinePlugin } from "../revinePlugin.js";
|
|
3
4
|
import { revineLoggerPlugin } from "../viteLoggerPlugin.js";
|
|
4
5
|
export const defaultViteConfig = {
|
|
@@ -7,6 +8,12 @@ export const defaultViteConfig = {
|
|
|
7
8
|
// Only expose env variables prefixed with REVINE_PUBLIC_ to the browser bundle.
|
|
8
9
|
// Variables without this prefix are never included in client-side code.
|
|
9
10
|
envPrefix: "REVINE_PUBLIC_",
|
|
11
|
+
resolve: {
|
|
12
|
+
alias: {
|
|
13
|
+
// @ always points to the user's project /src directory
|
|
14
|
+
"@": path.resolve(process.cwd(), "src"),
|
|
15
|
+
},
|
|
16
|
+
},
|
|
10
17
|
server: {
|
|
11
18
|
clearScreen: false,
|
|
12
19
|
open: false,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateConfig.d.ts","sourceRoot":"","sources":["../../../src/runtime/bundler/generateConfig.ts"],"names":[],"mappings":"
|
|
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(
|
|
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"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "revine",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
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",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import react from "@vitejs/plugin-react";
|
|
2
|
+
import path from "path";
|
|
2
3
|
import { revinePlugin } from "../revinePlugin.js";
|
|
3
4
|
import { revineLoggerPlugin } from "../viteLoggerPlugin.js";
|
|
4
5
|
|
|
@@ -8,6 +9,12 @@ export const defaultViteConfig = {
|
|
|
8
9
|
// Only expose env variables prefixed with REVINE_PUBLIC_ to the browser bundle.
|
|
9
10
|
// Variables without this prefix are never included in client-side code.
|
|
10
11
|
envPrefix: "REVINE_PUBLIC_",
|
|
12
|
+
resolve: {
|
|
13
|
+
alias: {
|
|
14
|
+
// @ always points to the user's project /src directory
|
|
15
|
+
"@": path.resolve(process.cwd(), "src"),
|
|
16
|
+
},
|
|
17
|
+
},
|
|
11
18
|
server: {
|
|
12
19
|
clearScreen: false,
|
|
13
20
|
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(
|
|
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"] ||
|