Skip to content

Commit

Permalink
feat(core): updated dotenv and switched to import 'dotenv/config'
Browse files Browse the repository at this point in the history
  • Loading branch information
Phillip9587 authored and FrozenPandaz committed Jul 29, 2021
1 parent 9f1e530 commit 7aa706a
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 58 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -130,7 +130,7 @@
"cz-customizable": "^6.2.0",
"depcheck": "^1.3.1",
"document-register-element": "^1.13.1",
"dotenv": "8.2.0",
"dotenv": "~10.0.0",
"ejs": "^3.1.5",
"eslint": "7.10.0",
"eslint-config-next": "^11.0.1",
Expand Down
5 changes: 1 addition & 4 deletions packages/cypress/src/executors/cypress/cypress.impl.ts
@@ -1,3 +1,4 @@
import 'dotenv/config';
import { basename, dirname, join } from 'path';
import { installedCypressVersion } from '../../utils/cypress-version';
import {
Expand Down Expand Up @@ -37,10 +38,6 @@ export interface CypressExecutorOptions extends Json {
testingType?: 'component' | 'e2e';
}

try {
require('dotenv').config();
} catch (e) {}

export default async function cypressExecutor(
options: CypressExecutorOptions,
context: ExecutorContext
Expand Down
11 changes: 2 additions & 9 deletions packages/jest/src/executors/jest/jest.impl.ts
@@ -1,3 +1,4 @@
import 'dotenv/config';
import { runCLI } from 'jest';
import { readConfig } from 'jest-config';
import { utils as jestReporterUtils } from '@jest/reporters';
Expand All @@ -9,15 +10,7 @@ import { ExecutorContext, TaskGraph } from '@nrwl/devkit';
import { join } from 'path';
import { getSummary } from './summary';

try {
require('dotenv').config();
} catch (e) {
// noop
}

if (process.env.NODE_ENV === null || process.env.NODE_ENV === undefined) {
(process.env as any).NODE_ENV = 'test';
}
process.env.NODE_ENV ??= 'test';

export async function jestExecutor(
options: JestExecutorOptions,
Expand Down
7 changes: 2 additions & 5 deletions packages/next/src/executors/build/build.impl.ts
@@ -1,3 +1,4 @@
import 'dotenv/config';
import { ExecutorContext } from '@nrwl/devkit';

import build from 'next/dist/build';
Expand All @@ -18,16 +19,12 @@ import {
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
import { assertDependentProjectsHaveBeenBuilt } from '../../utils/buildable-libs';

try {
require('dotenv').config();
} catch (e) {}

export default async function buildExecutor(
options: NextBuildBuilderOptions,
context: ExecutorContext
) {
let dependencies: DependentBuildableProjectNode[] = [];
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
process.env.NODE_ENV ||= 'production';

const root = resolve(context.root, options.root);

Expand Down
5 changes: 1 addition & 4 deletions packages/next/src/executors/export/export.impl.ts
@@ -1,3 +1,4 @@
import 'dotenv/config';
import {
ExecutorContext,
parseTargetString,
Expand All @@ -19,10 +20,6 @@ import {
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
import { assertDependentProjectsHaveBeenBuilt } from '../../utils/buildable-libs';

try {
require('dotenv').config();
} catch (e) {}

export default async function exportExecutor(
options: NextExportBuilderOptions,
context: ExecutorContext
Expand Down
5 changes: 1 addition & 4 deletions packages/next/src/executors/server/server.impl.ts
@@ -1,3 +1,4 @@
import 'dotenv/config';
import {
ExecutorContext,
logger,
Expand Down Expand Up @@ -30,10 +31,6 @@ import {
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
import { assertDependentProjectsHaveBeenBuilt } from '../../utils/buildable-libs';

try {
require('dotenv').config();
} catch (e) {}

const infoPrefix = `[ ${chalk.dim(chalk.cyan('info'))} ] `;
const readyPrefix = `[ ${chalk.green('ready')} ]`;

Expand Down
5 changes: 1 addition & 4 deletions packages/node/src/executors/build/build.impl.ts
@@ -1,3 +1,4 @@
import 'dotenv/config';
import { ExecutorContext } from '@nrwl/devkit';

import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
Expand All @@ -18,10 +19,6 @@ import { BuildNodeBuilderOptions } from '../../utils/types';
import { normalizeBuildOptions } from '../../utils/normalize';
import { generatePackageJson } from '../../utils/generate-package-json';

try {
require('dotenv').config();
} catch (e) {}

export type NodeBuildEvent = {
outfile: string;
success: boolean;
Expand Down
5 changes: 1 addition & 4 deletions packages/node/src/executors/execute/execute.impl.ts
@@ -1,3 +1,4 @@
import 'dotenv/config';
import {
runExecutor,
stripIndents,
Expand All @@ -14,10 +15,6 @@ import * as treeKill from 'tree-kill';
import { NodeBuildEvent } from '../build/build.impl';
import { BuildNodeBuilderOptions } from '../../utils/types';

try {
require('dotenv').config();
} catch (e) {}

export const enum InspectType {
Inspect = 'inspect',
InspectBrk = 'inspect-brk',
Expand Down
8 changes: 3 additions & 5 deletions packages/nx-plugin/src/executors/e2e/e2e.impl.ts
@@ -1,4 +1,7 @@
import 'dotenv/config';

import type { ExecutorContext } from '@nrwl/devkit';

import {
convertNxExecutor,
logger,
Expand All @@ -9,11 +12,6 @@ import {
import { jestExecutor } from '@nrwl/jest/src/executors/jest/jest.impl';
import type { NxPluginE2EExecutorOptions } from './schema';

try {
require('dotenv').config();
// eslint-disable-next-line no-empty
} catch (e) {}

export async function* nxPluginE2EExecutor(
options: NxPluginE2EExecutorOptions,
context: ExecutorContext
Expand Down
@@ -1,3 +1,4 @@
import 'dotenv/config';
import { basename, join, sep } from 'path';
import { tmpdir } from 'os';
import { constants, copyFileSync, mkdtempSync, statSync } from 'fs';
Expand All @@ -23,10 +24,6 @@ export interface StorybookBuilderOptions {
docsMode?: boolean;
}

try {
require('dotenv').config();
} catch (e) {}

export default async function buildStorybookExecutor(
options: StorybookBuilderOptions,
context: ExecutorContext
Expand Down
5 changes: 1 addition & 4 deletions packages/storybook/src/executors/storybook/storybook.impl.ts
@@ -1,3 +1,4 @@
import 'dotenv/config';
import { basename, join, sep } from 'path';
import { tmpdir } from 'os';
import { constants, copyFileSync, mkdtempSync, statSync } from 'fs';
Expand Down Expand Up @@ -34,10 +35,6 @@ export interface StorybookExecutorOptions {
docsMode?: boolean;
}

try {
require('dotenv').config();
} catch (e) {}

export default async function* storybookExecutor(
options: StorybookExecutorOptions,
context: ExecutorContext
Expand Down
8 changes: 8 additions & 0 deletions packages/workspace/migrations.json
Expand Up @@ -902,6 +902,14 @@
"version": "~4.3.5"
}
}
},
"12.7.0": {
"version": "12.7.0-beta.0",
"packages": {
"dotenv": {
"version": "~10.0.0"
}
}
}
}
}
2 changes: 1 addition & 1 deletion packages/workspace/package.json
Expand Up @@ -62,7 +62,7 @@
"chokidar": "^3.5.1",
"cosmiconfig": "^4.0.0",
"fs-extra": "^9.1.0",
"dotenv": "8.2.0",
"dotenv": "~10.0.0",
"glob": "7.1.4",
"ignore": "^5.0.4",
"npm-run-all": "^4.1.5",
Expand Down
Expand Up @@ -5,16 +5,16 @@ import * as yargsParser from 'yargs-parser';

export const LARGE_BUFFER = 1024 * 1000000;

function loadEnvVars(path?: string) {
async function loadEnvVars(path?: string) {
if (path) {
const result = require('dotenv').config({ path });
const result = (await import('dotenv')).config({ path });
if (result.error) {
throw result.error;
}
} else {
try {
require('dotenv').config();
} catch (e) {}
(await import('dotenv')).config();
} catch {}
}
}

Expand Down Expand Up @@ -67,7 +67,7 @@ export default async function (
options: RunCommandsBuilderOptions,
context: ExecutorContext
): Promise<{ success: boolean }> {
loadEnvVars(options.envFile);
await loadEnvVars(options.envFile);
const normalized = normalizeOptions(options);

if (options.readyWhen && !options.parallel) {
Expand Down
Expand Up @@ -11,7 +11,7 @@ Object {
"@nrwl/tao": "*",
"@nrwl/workspace": "*",
"@types/node": "14.14.33",
"dotenv": "8.2.0",
"dotenv": "~10.0.0",
"prettier": "^2.3.1",
"ts-node": "~9.1.1",
"typescript": "~4.3.5",
Expand Down Expand Up @@ -56,7 +56,7 @@ Object {
"@nrwl/tao": "*",
"@nrwl/workspace": "*",
"@types/node": "14.14.33",
"dotenv": "8.2.0",
"dotenv": "~10.0.0",
"prettier": "^2.3.1",
"ts-node": "~9.1.1",
"typescript": "~4.3.5",
Expand Down Expand Up @@ -102,7 +102,7 @@ Object {
"@nrwl/tao": "*",
"@nrwl/workspace": "*",
"@types/node": "14.14.33",
"dotenv": "8.2.0",
"dotenv": "~10.0.0",
"prettier": "^2.3.1",
"ts-node": "~9.1.1",
"typescript": "~4.3.5",
Expand Down
Expand Up @@ -39,7 +39,7 @@
"@nrwl/cli": "<%= nxVersion %>",
"@nrwl/workspace": "<%= nxVersion %>",
"@types/node": "14.14.33",
"dotenv": "8.2.0",
"dotenv": "~10.0.0",
"ts-node": "~9.1.1",
"typescript": "<%= typescriptVersion %>",
"prettier": "<%= prettierVersion %>"
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -11600,6 +11600,11 @@ dotenv@^6.2.0:
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.2.0.tgz#941c0410535d942c8becf28d3f357dbd9d476064"
integrity sha512-HygQCKUBSFl8wKQZBSemMywRWcEDNidvNbjGVyZu3nbZ8qq9ubiPoGLMdRDpfSrpkkm9BXYFkpKxxFX38o/76w==

dotenv@~10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==

downshift@^6.0.15:
version "6.1.3"
resolved "https://registry.yarnpkg.com/downshift/-/downshift-6.1.3.tgz#e794b7805d24810968f21e81ad6bdd9f3fdc40da"
Expand Down

0 comments on commit 7aa706a

Please sign in to comment.