Skip to content

Remove dotenv dependency#704

Merged
slifty merged 1 commit into
mainfrom
640-remove-dotenv
Jan 11, 2024
Merged

Remove dotenv dependency#704
slifty merged 1 commit into
mainfrom
640-remove-dotenv

Conversation

@slifty

@slifty slifty commented Jan 5, 2024

Copy link
Copy Markdown
Member

This PR removes dotenv from the repository. Developers who don't want to manually source their .env file might consider populating required variables themselves using a tool like direnv.

To test:

  1. make sure your environment variables are loaded into your shell (source .env)
  2. run npm i
  3. idk man... uh... run tests? or run the program?
  4. yeah that's it! run npm run test
  5. run npm run start:dev

Resolves #640

@slifty slifty requested a review from jasonaowen January 5, 2024 18:33
@codecov

codecov Bot commented Jan 5, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0bde481) 93.05% compared to head (3f0e8c8) 93.04%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #704      +/-   ##
==========================================
- Coverage   93.05%   93.04%   -0.01%     
==========================================
  Files          86       86              
  Lines        1396     1394       -2     
  Branches      216      216              
==========================================
- Hits         1299     1297       -2     
  Misses         92       92              
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment thread src/test/globalSetup.ts
Comment on lines -6 to -8
// TODO: reconsider use of '.env.test' if or when
// https://github.com/ThomWright/postgres-migrations/pull/93 gets merged/fixed.
dotenv.config({ path: '.env.test' });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh - this seems relevant! Currently my .env.test is pointing at a different database than my .env. Is that still necessary? In #611 we switched to a fork of postgres-migrations which fixes the schema issue, and it looks like that PR starts making use of the new functionality. Is it safe to point the tests at the same database as my local dev instance?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasonaowen yes indeed you can use the local dev instance!

The dotenv package is primarily useful for helping developers manage
their local environment variables (in deployment contexts we populate
environment variables directly via our provisioning processes).

There are other tools that developers can use for managing their local
environment, and instead of having that live in the code base we should
have our devs use whatever tool they find most convenient.

Issue #640 Remove dotenv
@slifty slifty force-pushed the 640-remove-dotenv branch from a3a246b to 3f0e8c8 Compare January 11, 2024 18:04

@reefdog reefdog left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the worst code I have ever seen in my life. Approved.

@slifty slifty merged commit b42098b into main Jan 11, 2024
@slifty slifty deleted the 640-remove-dotenv branch January 11, 2024 19:24
@bickelj

bickelj commented Jan 12, 2024

Copy link
Copy Markdown
Contributor

For some reason this merge broke the automated deployment to the test environment yesterday.

Ah, package.json still references dotenv for migrate:

                "migrate": "node -r dotenv/config dist/scripts/migrate.js",
                "migrate:dev": "ts-node -r dotenv/config src/scripts/migrate.ts | pino-pretty",

@bickelj

bickelj commented Jan 12, 2024

Copy link
Copy Markdown
Contributor

I thought it would be as simple as removing -r dotenv/config from both of those lines, but I can't fully verify because of a lack of S3 variables. Setting them to dummy values and using source .env or . .env prior to running migrate still doesn't let me get past this, I'm probably overlooking something simple though:

$ npm run migrate:dev

> @pdc/service@0.3.0 migrate:dev
> ts-node src/scripts/migrate.ts | pino-pretty

/home/user/code/ots/ext/PhilanthropyDataCommons/service/src/s3Client.ts:10
} = requireEnv(
              ^
Error: Environment variables missing: [ "S3_ACCESS_KEY_ID", "S3_ACCESS_SECRET", "S3_ENDPOINT", "S3_PATH_STYLE", "S3_REGION" ]
    at Object.<anonymous> (/home/user/code/ots/ext/PhilanthropyDataCommons/service/src/s3Client.ts:10:15)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module.m._compile (/home/user/code/ots/ext/PhilanthropyDataCommons/service/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Object.require.extensions.<computed> [as .ts] (/home/user/code/ots/ext/PhilanthropyDataCommons/service/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Function.Module._load (node:internal/modules/cjs/loader:960:12)
    at Module.require (node:internal/modules/cjs/loader:1143:19)
    at require (node:internal/modules/cjs/helpers:121:18)
    at Object.<anonymous> (/home/user/code/ots/ext/PhilanthropyDataCommons/service/src/tasks/processBulkUpload.ts:6:1)

@reefdog

reefdog commented Jan 12, 2024

Copy link
Copy Markdown
Contributor

@bickelj Great catch! Re: source .env not being sufficient, Dan and I realized locally you need to set -a before source .env.

I know Dan uses direnv to load these automatically, and I intend to set it up as well. You can do whatever you'd like locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove dotenv

4 participants