Skip to content

Commit

Permalink
Fix getting env variables from import.meta.env.SOME_KEY (#400)
Browse files Browse the repository at this point in the history
* Fix getting env variables from import.meta.env.SOME_KEY

* remove double comment

* tighten the check using AST tests

---------

Co-authored-by: Mateusz Burzyński <[email protected]>
  • Loading branch information
mellson and Andarist authored Nov 14, 2023
1 parent ca05e2d commit bcaeedc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/nervous-vans-appear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@xstate/cli': patch
---

Fix getting env variables from import.meta.env.SOME_KEY
9 changes: 6 additions & 3 deletions packages/machine-extractor/src/sky/skyConfigNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ const StringLiteralOrEnvKey = unionType([
throw new Error("Couldn't find API key in any of the env files");
}

// Let's find the last part of the expression (identifier), e.g. `API_KEY` in `process.env.API_KEY`
// Let's find the env key, e.g. `API_KEY` in `process.env.API_KEY` or in `import.meta.env.API_KEY`
const envVariableName =
(t.isMetaProperty(node.object) ||
t.buildMatchMemberExpression('process.env')(node.object)) &&
(t.buildMatchMemberExpression('process.env')(node.object) ||
(t.isMemberExpression(node.object) &&
t.isMetaProperty(node.object.object) &&
t.isIdentifier(node.object.property) &&
node.object.property.name === 'env')) &&
t.isIdentifier(node.property)
? node.property.name
: null;
Expand Down

0 comments on commit bcaeedc

Please sign in to comment.