diff --git a/.changeset/giant-scissors-hug.md b/.changeset/giant-scissors-hug.md new file mode 100644 index 000000000..c2d78d237 --- /dev/null +++ b/.changeset/giant-scissors-hug.md @@ -0,0 +1,5 @@ +--- +"@trigger.dev/cli": patch +--- + +Parse .env file using dotenv instead of hand-parsing it diff --git a/packages/cli/package.json b/packages/cli/package.json index 5aeb459e9..a8e089c28 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -57,6 +57,7 @@ "chokidar": "^3.5.3", "commander": "^9.4.1", "degit": "^2.8.4", + "dotenv": "^16.3.1", "execa": "^7.0.0", "gradient-string": "^2.0.2", "inquirer": "^9.1.4", diff --git a/packages/cli/src/commands/dev.ts b/packages/cli/src/commands/dev.ts index 439bac5fb..848a506ef 100644 --- a/packages/cli/src/commands/dev.ts +++ b/packages/cli/src/commands/dev.ts @@ -8,6 +8,7 @@ import { pathExists, readFile } from "../utils/fileSystem.js"; import { logger } from "../utils/logger.js"; import { resolvePath } from "../utils/parseNameAndPath.js"; import { TriggerApi } from "../utils/triggerApi.js"; +import dotenv from "dotenv"; export const DevCommandOptionsSchema = z.object({ port: z.coerce.number(), @@ -195,26 +196,17 @@ async function getTriggerApiDetails(path: string, envFile: string) { process.exit(1); } - if ( - !resolvedEnvFile.content.includes("TRIGGER_API_KEY") || - !resolvedEnvFile.content.includes("TRIGGER_API_URL") - ) { + const parsedEnvFile = dotenv.parse(resolvedEnvFile.content); + + if (!parsedEnvFile.TRIGGER_API_KEY || !parsedEnvFile.TRIGGER_API_KEY) { logger.error( `You must add TRIGGER_API_KEY and TRIGGER_API_URL to your ${envFile} file.` ); process.exit(1); } - const envFileLines = resolvedEnvFile.content.split("\n"); - const apiKeyLine = envFileLines.find((line) => - line.includes("TRIGGER_API_KEY") - ); - const apiUrlLine = envFileLines.find((line) => - line.includes("TRIGGER_API_URL") - ); - - const apiKey = apiKeyLine?.split("=")[1]; - const apiUrl = apiUrlLine?.split("=")[1]; + const apiKey = parsedEnvFile.TRIGGER_API_KEY; + const apiUrl = parsedEnvFile.TRIGGER_API_URL; if (!apiKey || !apiUrl) { logger.error( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ea6dfed5b..e7238ca78 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -557,6 +557,7 @@ importers: chokidar: ^3.5.3 commander: ^9.4.1 degit: ^2.8.4 + dotenv: ^16.3.1 execa: ^7.0.0 gradient-string: ^2.0.2 inquirer: ^9.1.4 @@ -580,6 +581,7 @@ importers: chokidar: 3.5.3 commander: 9.5.0 degit: 2.8.4 + dotenv: 16.3.1 execa: 7.0.0 gradient-string: 2.0.2 inquirer: 9.1.4 @@ -11462,7 +11464,7 @@ packages: /axios/0.21.4_debug@4.3.2: resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} dependencies: - follow-redirects: 1.15.2_debug@4.3.2 + follow-redirects: 1.15.2 transitivePeerDependencies: - debug dev: false @@ -13186,6 +13188,11 @@ packages: engines: {node: '>=12'} dev: true + /dotenv/16.3.1: + resolution: {integrity: sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==} + engines: {node: '>=12'} + dev: false + /duplexer2/0.1.4: resolution: {integrity: sha512-asLFVfWWtJ90ZyOUHMqk7/S2w2guQKxUI2itj3d92ADHhxUSbCMGi1f1cBcJ7xM1To+pE/Khbwo1yuNbMEPKeA==} dependencies: @@ -15249,18 +15256,6 @@ packages: optional: true dev: false - /follow-redirects/1.15.2_debug@4.3.2: - resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==} - engines: {node: '>=4.0'} - peerDependencies: - debug: '*' - peerDependenciesMeta: - debug: - optional: true - dependencies: - debug: 4.3.2 - dev: false - /for-each/0.3.3: resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} dependencies: