Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use gitignored .env.local in a runtime sharedGlobal #19172

Closed
1 of 4 tasks
martin-mindflow opened this issue Sep 14, 2023 · 4 comments · Fixed by #19801
Closed
1 of 4 tasks

Cannot use gitignored .env.local in a runtime sharedGlobal #19172

martin-mindflow opened this issue Sep 14, 2023 · 4 comments · Fixed by #19801
Assignees
Labels

Comments

@martin-mindflow
Copy link

Current Behavior

I have an nx monorepo, with several libs and apps. I want the .env.local file to be added to the cache hashes, so that all caches are invalidated when this file changes. The file is gitignored, so i can't just put its path in a sharedGlobal, seems like files inside of .gitignore are hard ignored by nx.

So, i use the following conf as a workaround:

    "sharedGlobals": [
      {
        "runtime": "cat .env.local"
      }
    ]

which does not work. ie:

nx lint debug # this is a cache miss, as expected
nx lint debug # cache hit, as expected
echo "whatever" >> .env.local
nx lint debug # this should be a miss but it's a hit :(

which lead me to believe my approach was wrong, but inexplicably, when i use another file in the conf:

    "sharedGlobals": [
      {
        "runtime": "cat file.txt"
      }
    ]
nx lint debug # this is a cache miss, as expected
nx lint debug # cache hit, as expected
echo "whatever" >> file.txt
nx lint debug # cache miss!

Expected Behavior

I'm expecting the cache to behave the same way for both files

GitHub Repo

https://github.com/martin-mindflow/nx-cache-reproduction

Steps to Reproduce

  1. clone the example repo on the main branch
  2. run the following commands sequence:
nx lint debug # this is a cache miss, as expected
nx lint debug # cache hit, as expected
echo "whatever" >> .env.local
nx lint debug # this should be a miss but it's a hit :(
  1. switch to the ok branch
  2. run the following commands sequence:
nx lint debug # this is a cache miss, as expected
nx lint debug # cache hit, as expected
echo "whatever" >> file.txt
nx lint debug # cache miss!

Nx Report

Node   : 18.16.1
   OS     : darwin-arm64
   npm    : 9.5.1

   nx                 : 16.8.1
   @nx/js             : 16.8.1
   @nx/linter         : 16.8.1
   @nx/workspace      : 16.8.1
   @nx/devkit         : 16.8.1
   @nx/eslint-plugin  : 16.8.1
   @nx/react          : 16.8.1
   @nrwl/tao          : 16.8.1
   @nx/vite           : 16.8.1
   @nx/web            : 16.8.1
   typescript         : 5.1.6

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@AgentEnder AgentEnder added the scope: core core nx functionality label Sep 22, 2023
@Chanki-Min
Copy link
Contributor

releated: #19392

@Cammisuli Cammisuli self-assigned this Oct 23, 2023
@Cammisuli
Copy link
Member

Cammisuli commented Oct 23, 2023

There's a way to make this work for your scenario, but while I was testing it, I found an issue 😅

Anyway, once the linked PR is merged, you'll be able to properly use the .nxignore file. Adding !.env.local to that file will whitelist it, and it will be included in hashes. So then in your sharedGlobals named input, you can have this instead:

"sharedGlobals": ["{workspaceRoot}/.env.local"]

Usually folks ignored whole folders, while nxignoreing subfolders, so the logic worked well there. With this scenario, we ignored and whitelisted the same file, so things got weird.

@martin-mindflow
Copy link
Author

Great news! thanks for the follow-up !

Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants