Expose `env` to backend applications (#746)

Test Plan:
Add `console.log(require("../../app/version").VERSION_SHORT);` to the
top of `async run()` in `src/cli/commands/load.js`. Run `yarn backend`
and `node bin/sourcecred.js load`, and note that it prints the current
version number. Before this change, it would have raised an error:

```
Error: gitState: not a string: undefined
    at parseGitState (~/git/sourcecred/bin/commands/load.js:1160:64)
```

because the requisite environment variables were not included.

Also, `yarn test --full` passes.

wchargin-branch: backend-env
This commit is contained in:
William Chargin 2018-08-31 15:20:15 -07:00 committed by GitHub
parent 84d505ab12
commit 436cad0326
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 7 deletions

View File

@ -1,9 +1,13 @@
// @no-flow // @no-flow
const webpack = require("webpack"); const webpack = require("webpack");
const eslintFormatter = require("react-dev-utils/eslintFormatter"); const eslintFormatter = require("react-dev-utils/eslintFormatter");
const ModuleScopePlugin = require("react-dev-utils/ModuleScopePlugin"); const ModuleScopePlugin = require("react-dev-utils/ModuleScopePlugin");
const paths = require("./paths"); const paths = require("./paths");
const nodeExternals = require("webpack-node-externals"); const nodeExternals = require("webpack-node-externals");
const getClientEnvironment = require("./env");
const env = getClientEnvironment();
// This is the backend configuration. It builds applications that target // This is the backend configuration. It builds applications that target
// Node and will not run in a browser. // Node and will not run in a browser.
@ -70,11 +74,5 @@ module.exports = (outputPath) => ({
}, },
], ],
}, },
plugins: [ plugins: [new webpack.DefinePlugin(env.stringified)],
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(
process.env.NODE_ENV || "development"
),
}),
],
}); });