diff --git a/packages/@sanity/core/package.json b/packages/@sanity/core/package.json index 2bae9bf0f7b..24753791bce 100644 --- a/packages/@sanity/core/package.json +++ b/packages/@sanity/core/package.json @@ -40,6 +40,7 @@ "configstore": "^3.0.0", "debug": "^3.1.0", "deep-sort-object": "^1.0.1", + "dotenv": "^8.2.0", "es6-promisify": "^6.0.0", "execa": "^1.0.0", "filesize": "^3.5.6", diff --git a/packages/@sanity/core/src/actions/exec/execScript.js b/packages/@sanity/core/src/actions/exec/execScript.js index fc05c1c5e23..6753abcb678 100644 --- a/packages/@sanity/core/src/actions/exec/execScript.js +++ b/packages/@sanity/core/src/actions/exec/execScript.js @@ -1,7 +1,13 @@ const spawn = require('child_process').spawn const path = require('path') +const dotenv = require('dotenv') const fse = require('fs-extra') +// Try to load .env files from the current directory +// eslint-disable-next-line no-process-env +const env = process.env.NODE_ENV || 'development' +dotenv.config({path: path.join(process.cwd(), `.env.${env}`)}) + module.exports = async args => { // In case of specifying --with-user-token , use the "token" as the script const script = args.argsWithoutOptions[0] || args.extOptions['with-user-token']