@@ -38,7 +38,6 @@ import { cn } from "~/utils/cn";
38
38
import { ProjectParamSchema , v3BillingPath , v3EnvironmentVariablesPath } from "~/utils/pathBuilder" ;
39
39
import { EnvironmentVariablesRepository } from "~/v3/environmentVariables/environmentVariablesRepository.server" ;
40
40
import { EnvironmentVariableKey } from "~/v3/environmentVariables/repository" ;
41
- import dotenv from "dotenv" ;
42
41
import { Paragraph } from "~/components/primitives/Paragraph" ;
43
42
import { TextLink } from "~/components/primitives/TextLink" ;
44
43
import {
@@ -48,6 +47,49 @@ import {
48
47
TooltipTrigger ,
49
48
} from "~/components/primitives/Tooltip" ;
50
49
50
+ // https://github.com/motdotla/dotenv/blob/master/lib/main.js
51
+ // dotenv imports a bunch of stuff from node which gives annoying warnings when vite externalizes them
52
+ // Not a real concern but if this function is all you're using, we can inline it
53
+ function parseEnv ( src : string ) {
54
+ const LINE =
55
+ / (?: ^ | ^ ) \s * (?: e x p o r t \s + ) ? ( [ \w . - ] + ) (?: \s * = \s * ?| : \s + ?) ( \s * ' (?: \\ ' | [ ^ ' ] ) * ' | \s * " (?: \\ " | [ ^ " ] ) * " | \s * ` (?: \\ ` | [ ^ ` ] ) * ` | [ ^ # \r \n ] + ) ? \s * (?: # .* ) ? (?: $ | $ ) / gm;
56
+ const obj = { } ;
57
+
58
+ // Convert buffer to string
59
+ let lines = src . toString ( ) ;
60
+
61
+ // Convert line breaks to same format
62
+ lines = lines . replace ( / \r \n ? / gm, "\n" ) ;
63
+
64
+ let match ;
65
+ while ( ( match = LINE . exec ( lines ) ) != null ) {
66
+ const key = match [ 1 ] ;
67
+
68
+ // Default undefined or null to empty string
69
+ let value = match [ 2 ] || "" ;
70
+
71
+ // Remove whitespace
72
+ value = value . trim ( ) ;
73
+
74
+ // Check if double quoted
75
+ const maybeQuote = value [ 0 ] ;
76
+
77
+ // Remove surrounding quotes
78
+ value = value . replace ( / ^ ( [ ' " ` ] ) ( [ \s \S ] * ) \1$ / gm, "$2" ) ;
79
+
80
+ // Expand newlines if double quoted
81
+ if ( maybeQuote === '"' ) {
82
+ value = value . replace ( / \\ n / g, "\n" ) ;
83
+ value = value . replace ( / \\ r / g, "\r" ) ;
84
+ }
85
+
86
+ // @ts -ignore
87
+ obj [ key ] = value ;
88
+ }
89
+
90
+ return obj ;
91
+ }
92
+
51
93
export const loader = async ( { request, params } : LoaderFunctionArgs ) => {
52
94
const userId = await requireUserId ( request ) ;
53
95
const { projectParam } = ProjectParamSchema . parse ( params ) ;
@@ -364,7 +406,7 @@ function VariableFields({
364
406
let text = clipboardData . getData ( "text" ) ;
365
407
if ( ! text ) return ;
366
408
367
- const variables = dotenv . parse ( text ) ;
409
+ const variables = parseEnv ( text ) ;
368
410
const keyValuePairs = Object . entries ( variables ) . map ( ( [ key , value ] ) => ( { key, value } ) ) ;
369
411
370
412
//do the default paste
0 commit comments