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
updated dotenv and @types/node and added the migration
switched from require('dotenv').config() to
import 'dotenv/config'
  • Loading branch information
Phillip9587 committed May 14, 2021
1 parent bcdbb02 commit 87d4aa3
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 70 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -94,7 +94,7 @@
"@types/jasminewd2": "~2.0.3",
"@types/jest": "26.0.8",
"@types/marked": "^2.0.0",
"@types/node": "14.14.37",
"@types/node": "~14.14.45",
"@types/prettier": "2.0.0",
"@types/react": "17.0.3",
"@types/react-dom": "17.0.3",
Expand Down Expand Up @@ -131,7 +131,7 @@
"cz-customizable": "^6.2.0",
"depcheck": "^1.3.1",
"document-register-element": "^1.13.1",
"dotenv": "8.2.0",
"dotenv": "~9.0.2",
"ejs": "^3.1.5",
"eslint": "7.10.0",
"eslint-config-prettier": "^8.1.0",
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 @@ -36,10 +37,6 @@ export interface CypressExecutorOptions extends Json {
skipServe: boolean;
}

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,18 +1,11 @@
import 'dotenv/config';
import { runCLI } from 'jest';
import * as path from 'path';
import { JestExecutorOptions } from './schema';
import { Config } from '@jest/types';
import { ExecutorContext } from '@nrwl/devkit';

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 @@ -15,15 +16,11 @@ import { createProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import { calculateProjectDependencies } 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
) {
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 @@ -16,10 +17,6 @@ import { createProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import { calculateProjectDependencies } 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 @@ -27,10 +28,6 @@ import { createProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import { calculateProjectDependencies } 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 { createProjectGraph } from '@nrwl/workspace/src/core/project-graph';
Expand All @@ -19,10 +20,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
6 changes: 1 addition & 5 deletions packages/nx-plugin/src/builders/e2e/e2e.impl.ts
@@ -1,3 +1,4 @@
import 'dotenv/config';
import {
BuilderContext,
createBuilder,
Expand All @@ -8,11 +9,6 @@ import { from } from 'rxjs';
import { concatMap, switchMap } from 'rxjs/operators';
import { Schema } from './schema';

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

export type NxPluginE2EBuilderOptions = Schema;

function buildTarget(context: BuilderContext, target: string) {
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
7 changes: 2 additions & 5 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 @@ -29,10 +30,6 @@ export interface StorybookExecutorOptions {
docsMode?: boolean;
}

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

export default async function* storybookExecutor(
options: StorybookExecutorOptions,
context: ExecutorContext
Expand All @@ -50,7 +47,7 @@ export default async function* storybookExecutor(
}

function runInstance(options: StorybookExecutorOptions) {
process.env.NODE_ENV = process.env.NODE_ENV ?? 'development';
process.env.NODE_ENV ??= 'development';
return buildDevStandalone({ ...options, ci: true } as any);
}

Expand Down
13 changes: 13 additions & 0 deletions packages/workspace/migrations.json
Expand Up @@ -879,6 +879,19 @@
"alwaysAddToPackageJson": false
}
}
},
"12.3.0": {
"version": "12.3.0",
"packages": {
"dotenv": {
"version": "~9.0.2",
"alwaysAddToPackageJson": false
},
"@types/node": {
"version": "~14.14.45",
"alwaysAddToPackageJson": false
}
}
}
}
}
2 changes: 1 addition & 1 deletion packages/workspace/package.json
Expand Up @@ -61,7 +61,7 @@
"@nrwl/linter": "*",
"cosmiconfig": "^4.0.0",
"fs-extra": "^9.1.0",
"dotenv": "8.2.0",
"dotenv": "~9.0.2",
"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 @@ -62,7 +62,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 @@ -10,8 +10,8 @@ Object {
"@nrwl/cli": "*",
"@nrwl/tao": "*",
"@nrwl/workspace": "*",
"@types/node": "14.14.33",
"dotenv": "8.2.0",
"@types/node": "~14.14.45",
"dotenv": "~9.0.2",
"prettier": "2.2.1",
"ts-node": "~9.1.1",
"typescript": "~4.2.4",
Expand Down Expand Up @@ -55,8 +55,8 @@ Object {
"@nrwl/cli": "*",
"@nrwl/tao": "*",
"@nrwl/workspace": "*",
"@types/node": "14.14.33",
"dotenv": "8.2.0",
"@types/node": "~14.14.44",
"dotenv": "~9.0.2",
"prettier": "2.2.1",
"ts-node": "~9.1.1",
"typescript": "~4.2.4",
Expand Down Expand Up @@ -101,8 +101,8 @@ Object {
"@nrwl/react": "*",
"@nrwl/tao": "*",
"@nrwl/workspace": "*",
"@types/node": "14.14.33",
"dotenv": "8.2.0",
"@types/node": "~14.14.44",
"dotenv": "~9.0.2",
"prettier": "2.2.1",
"ts-node": "~9.1.1",
"typescript": "~4.2.4",
Expand Down
Expand Up @@ -38,8 +38,8 @@
"@nrwl/tao": "<%= nxVersion %>",
"@nrwl/cli": "<%= nxVersion %>",
"@nrwl/workspace": "<%= nxVersion %>",
"@types/node": "14.14.33",
"dotenv": "8.2.0",
"@types/node": "~14.14.45",
"dotenv": "~9.0.2",
"ts-node": "~9.1.1",
"typescript": "<%= typescriptVersion %>",
"prettier": "<%= prettierVersion %>"
Expand Down
4 changes: 2 additions & 2 deletions packages/workspace/src/tasks-runner/task-orchestrator.ts
@@ -1,6 +1,6 @@
import { Workspaces } from '@nrwl/tao/src/shared/workspace';
import { ChildProcess, fork } from 'child_process';
import * as dotenv from 'dotenv';
import dotenv = require('dotenv');
import { readFileSync, writeFileSync } from 'fs';
import { ProjectGraph } from '../core/project-graph';
import { appRootPath } from '../utilities/app-root';
Expand Down Expand Up @@ -564,5 +564,5 @@ function parseEnv(path: string) {
try {
const envContents = readFileSync(path);
return dotenv.parse(envContents);
} catch (e) {}
} catch {}
}
13 changes: 9 additions & 4 deletions yarn.lock
Expand Up @@ -4097,10 +4097,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.50.tgz#e9b2e85fafc15f2a8aa8fdd41091b983da5fd6ee"
integrity sha512-5ImO01Fb8YsEOYpV+aeyGYztcYcjGsBvN4D7G5r1ef2cuQOpymjWNQi5V0rKHE6PC2ru3HkoUr/Br2/8GUA84w==

"@types/node@14.14.37":
version "14.14.37"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.37.tgz#a3dd8da4eb84a996c36e331df98d82abd76b516e"
integrity sha512-XYmBiy+ohOR4Lh5jE379fV2IU+6Jn4g5qASinhitfyO71b/sCo6MKsMLF5tc7Zf2CE8hViVQyYSobJNke8OvUw==
"@types/node@~14.14.45":
version "14.14.45"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.45.tgz#ec2dfb5566ff814d061aef7e141575aedba245cf"
integrity sha512-DssMqTV9UnnoxDWu959sDLZzfvqCF0qDNRjaWeYSui9xkFe61kKo4l1TWNTQONpuXEm+gLMRvdlzvNHBamzmEw==

"@types/normalize-package-data@^2.4.0":
version "2.4.0"
Expand Down Expand Up @@ -10108,6 +10108,11 @@ dotenv@^6.2.0:
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.2.0.tgz#941c0410535d942c8becf28d3f357dbd9d476064"
integrity sha512-HygQCKUBSFl8wKQZBSemMywRWcEDNidvNbjGVyZu3nbZ8qq9ubiPoGLMdRDpfSrpkkm9BXYFkpKxxFX38o/76w==

dotenv@~9.0.2:
version "9.0.2"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-9.0.2.tgz#dacc20160935a37dea6364aa1bef819fb9b6ab05"
integrity sha512-I9OvvrHp4pIARv4+x9iuewrWycX6CcZtoAu1XrzPxc5UygMJXJZYmBsynku8IkrJwgypE5DGNjDPmPRhDCptUg==

downshift@^6.0.6:
version "6.1.0"
resolved "https://registry.yarnpkg.com/downshift/-/downshift-6.1.0.tgz#f008063d9b63935910d9db12ead07979ab51ce66"
Expand Down

0 comments on commit 87d4aa3

Please sign in to comment.