Skip to content

Commit 0f0a688

Browse files
authored
Environment variables pasting uses dotenv (#1075)
* Add dotenv package to the webapp frontend, required some polyfills * Use dotenv to parse the pasted env vars. Make the panel wider on larger screens
1 parent 7ff8f0e commit 0f0a688

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.v3.$projectParam.environment-variables.new/route.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { cn } from "~/utils/cn";
3838
import { ProjectParamSchema, v3EnvironmentVariablesPath } from "~/utils/pathBuilder";
3939
import { EnvironmentVariablesRepository } from "~/v3/environmentVariables/environmentVariablesRepository.server";
4040
import { EnvironmentVariableKey } from "~/v3/environmentVariables/repository";
41+
import dotenv from "dotenv";
4142

4243
export const loader = async ({ request, params }: LoaderFunctionArgs) => {
4344
const userId = await requireUserId(request);
@@ -183,7 +184,7 @@ export default function Page() {
183184
}
184185
}}
185186
>
186-
<DialogContent>
187+
<DialogContent className="md:max-w-2xl lg:max-w-3xl">
187188
<DialogHeader>New environment variables</DialogHeader>
188189
<Form
189190
method="post"
@@ -308,20 +309,12 @@ function VariableFields({
308309
if (!clipboardData) return;
309310

310311
let text = clipboardData.getData("text");
311-
//replace carriage returns
312-
text = text.replace(/\r/g, "");
313-
const lines = text.split("\n");
312+
if (!text) return;
314313

315-
const keyValuePairs = lines.flatMap((line) => {
316-
if (line.trim().startsWith("#")) return [];
317-
318-
const split = line.split("=");
319-
if (split.length === 2) {
320-
return [{ key: split[0], value: split[1] }];
321-
}
322-
return [];
323-
});
314+
const variables = dotenv.parse(text);
315+
const keyValuePairs = Object.entries(variables).map(([key, value]) => ({ key, value }));
324316

317+
//do the default paste
325318
if (keyValuePairs.length === 0) return;
326319

327320
//prevent default pasting

apps/webapp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"cronstrue": "^2.21.0",
109109
"cross-env": "^7.0.3",
110110
"cuid": "^2.1.8",
111+
"dotenv": "^16.4.5",
111112
"emails": "workspace:*",
112113
"evt": "^2.4.13",
113114
"express": "^4.18.1",

apps/webapp/remix.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
"random-words",
2222
"superjson",
2323
],
24+
browserNodeBuiltinsPolyfill: { modules: { path: true, os: true, crypto: true } },
2425
watchPaths: async () => {
2526
return [
2627
"../../packages/core/src/**/*",

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)