From 87d4aa3533e89b718473fe8cfd8712b930a902b8 Mon Sep 17 00:00:00 2001 From: Phillip Barta Date: Mon, 10 May 2021 19:38:36 +0200 Subject: [PATCH] feat(core): updated dotenv and switched to import 'dotenv/config' updated dotenv and @types/node and added the migration switched from require('dotenv').config() to import 'dotenv/config' --- package.json | 4 ++-- .../cypress/src/executors/cypress/cypress.impl.ts | 5 +---- packages/jest/src/executors/jest/jest.impl.ts | 11 ++--------- packages/next/src/executors/build/build.impl.ts | 7 ++----- packages/next/src/executors/export/export.impl.ts | 5 +---- packages/next/src/executors/server/server.impl.ts | 5 +---- packages/node/src/executors/build/build.impl.ts | 5 +---- packages/node/src/executors/execute/execute.impl.ts | 5 +---- packages/nx-plugin/src/builders/e2e/e2e.impl.ts | 6 +----- .../build-storybook/build-storybook.impl.ts | 5 +---- .../src/executors/storybook/storybook.impl.ts | 7 ++----- packages/workspace/migrations.json | 13 +++++++++++++ packages/workspace/package.json | 2 +- .../src/executors/run-commands/run-commands.impl.ts | 10 +++++----- .../generators/new/__snapshots__/new.spec.ts.snap | 12 ++++++------ .../generators/workspace/files/package.json__tmpl__ | 4 ++-- .../workspace/src/tasks-runner/task-orchestrator.ts | 4 ++-- yarn.lock | 13 +++++++++---- 18 files changed, 53 insertions(+), 70 deletions(-) diff --git a/package.json b/package.json index 5fe2c432b7599d..59a25b20d20e55 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/packages/cypress/src/executors/cypress/cypress.impl.ts b/packages/cypress/src/executors/cypress/cypress.impl.ts index dec35dd5b3f9a2..bd5a8109d387c5 100644 --- a/packages/cypress/src/executors/cypress/cypress.impl.ts +++ b/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 { @@ -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 diff --git a/packages/jest/src/executors/jest/jest.impl.ts b/packages/jest/src/executors/jest/jest.impl.ts index 1971d0bad76674..1ae4e0af5a23aa 100644 --- a/packages/jest/src/executors/jest/jest.impl.ts +++ b/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, diff --git a/packages/next/src/executors/build/build.impl.ts b/packages/next/src/executors/build/build.impl.ts index 2079d382af2321..6d6831cf331e87 100644 --- a/packages/next/src/executors/build/build.impl.ts +++ b/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'; @@ -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); diff --git a/packages/next/src/executors/export/export.impl.ts b/packages/next/src/executors/export/export.impl.ts index 09d362a2ca5c9a..1622ce210d20ac 100644 --- a/packages/next/src/executors/export/export.impl.ts +++ b/packages/next/src/executors/export/export.impl.ts @@ -1,3 +1,4 @@ +import 'dotenv/config'; import { ExecutorContext, parseTargetString, @@ -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 diff --git a/packages/next/src/executors/server/server.impl.ts b/packages/next/src/executors/server/server.impl.ts index 82fda3c7ba5229..feffd408da5040 100644 --- a/packages/next/src/executors/server/server.impl.ts +++ b/packages/next/src/executors/server/server.impl.ts @@ -1,3 +1,4 @@ +import 'dotenv/config'; import { ExecutorContext, logger, @@ -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')} ]`; diff --git a/packages/node/src/executors/build/build.impl.ts b/packages/node/src/executors/build/build.impl.ts index 79fa9d35d4dadc..1ebd5865a77884 100644 --- a/packages/node/src/executors/build/build.impl.ts +++ b/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'; @@ -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; diff --git a/packages/node/src/executors/execute/execute.impl.ts b/packages/node/src/executors/execute/execute.impl.ts index f4059a37421975..4723311c5e78af 100644 --- a/packages/node/src/executors/execute/execute.impl.ts +++ b/packages/node/src/executors/execute/execute.impl.ts @@ -1,3 +1,4 @@ +import 'dotenv/config'; import { runExecutor, stripIndents, @@ -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', diff --git a/packages/nx-plugin/src/builders/e2e/e2e.impl.ts b/packages/nx-plugin/src/builders/e2e/e2e.impl.ts index b195873568e500..8e6e05f4fbb2f4 100644 --- a/packages/nx-plugin/src/builders/e2e/e2e.impl.ts +++ b/packages/nx-plugin/src/builders/e2e/e2e.impl.ts @@ -1,3 +1,4 @@ +import 'dotenv/config'; import { BuilderContext, createBuilder, @@ -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) { diff --git a/packages/storybook/src/executors/build-storybook/build-storybook.impl.ts b/packages/storybook/src/executors/build-storybook/build-storybook.impl.ts index 4d283fcaa8260a..ab46e39c886831 100644 --- a/packages/storybook/src/executors/build-storybook/build-storybook.impl.ts +++ b/packages/storybook/src/executors/build-storybook/build-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'; @@ -23,10 +24,6 @@ export interface StorybookBuilderOptions { docsMode?: boolean; } -try { - require('dotenv').config(); -} catch (e) {} - export default async function buildStorybookExecutor( options: StorybookBuilderOptions, context: ExecutorContext diff --git a/packages/storybook/src/executors/storybook/storybook.impl.ts b/packages/storybook/src/executors/storybook/storybook.impl.ts index 80e0db8406f671..5960b6a3476d15 100644 --- a/packages/storybook/src/executors/storybook/storybook.impl.ts +++ b/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'; @@ -29,10 +30,6 @@ export interface StorybookExecutorOptions { docsMode?: boolean; } -try { - require('dotenv').config(); -} catch (e) {} - export default async function* storybookExecutor( options: StorybookExecutorOptions, context: ExecutorContext @@ -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); } diff --git a/packages/workspace/migrations.json b/packages/workspace/migrations.json index b6dec206f645fc..b748d0dd38afec 100644 --- a/packages/workspace/migrations.json +++ b/packages/workspace/migrations.json @@ -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 + } + } } } } diff --git a/packages/workspace/package.json b/packages/workspace/package.json index d05bfb92c70de8..0301e82174deab 100644 --- a/packages/workspace/package.json +++ b/packages/workspace/package.json @@ -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", diff --git a/packages/workspace/src/executors/run-commands/run-commands.impl.ts b/packages/workspace/src/executors/run-commands/run-commands.impl.ts index e6cb7967d9739c..7ffc40fe374d47 100644 --- a/packages/workspace/src/executors/run-commands/run-commands.impl.ts +++ b/packages/workspace/src/executors/run-commands/run-commands.impl.ts @@ -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 {} } } @@ -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) { diff --git a/packages/workspace/src/generators/new/__snapshots__/new.spec.ts.snap b/packages/workspace/src/generators/new/__snapshots__/new.spec.ts.snap index c6c95cd997d738..35298d2b5b622b 100644 --- a/packages/workspace/src/generators/new/__snapshots__/new.spec.ts.snap +++ b/packages/workspace/src/generators/new/__snapshots__/new.spec.ts.snap @@ -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", @@ -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", @@ -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", diff --git a/packages/workspace/src/generators/workspace/files/package.json__tmpl__ b/packages/workspace/src/generators/workspace/files/package.json__tmpl__ index 1121dae0858c8c..85af8facdf732f 100644 --- a/packages/workspace/src/generators/workspace/files/package.json__tmpl__ +++ b/packages/workspace/src/generators/workspace/files/package.json__tmpl__ @@ -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 %>" diff --git a/packages/workspace/src/tasks-runner/task-orchestrator.ts b/packages/workspace/src/tasks-runner/task-orchestrator.ts index b181fdd329e4e9..a290b31ab5c03b 100644 --- a/packages/workspace/src/tasks-runner/task-orchestrator.ts +++ b/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'; @@ -564,5 +564,5 @@ function parseEnv(path: string) { try { const envContents = readFileSync(path); return dotenv.parse(envContents); - } catch (e) {} + } catch {} } diff --git a/yarn.lock b/yarn.lock index 036abdbcea12c3..d20bacd7c59711 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"