From 9d5a3830bea3f499ea821029a6f657c02d2d7501 Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Tue, 22 Aug 2023 20:00:37 -0400 Subject: [PATCH] feat(misc): remove dotenv from executors (#18719) --- e2e/node/src/node.test.ts | 37 +++++++++++++++++++ packages/cypress/package.json | 1 - .../src/executors/cypress/cypress.impl.ts | 1 - packages/esbuild/package.json | 1 - .../src/executors/esbuild/esbuild.impl.ts | 1 - packages/jest/package.json | 1 - packages/jest/src/executors/jest/jest.impl.ts | 1 - packages/next/package.json | 1 - .../next/src/executors/build/build.impl.ts | 1 - .../next/src/executors/export/export.impl.ts | 1 - .../executors/server/custom-server.impl.ts | 1 - .../next/src/executors/server/server.impl.ts | 1 - packages/plugin/package.json | 1 - packages/plugin/src/executors/e2e/e2e.impl.ts | 2 - packages/rollup/package.json | 1 - .../src/executors/rollup/rollup.impl.ts | 1 - packages/storybook/package.json | 1 - .../build-storybook/build-storybook.impl.ts | 1 - .../src/executors/storybook/storybook.impl.ts | 1 - packages/storybook/src/executors/utils.ts | 1 - packages/vite/package.json | 1 - .../vite/src/executors/build/build.impl.ts | 1 - .../executors/dev-server/dev-server.impl.ts | 1 - packages/webpack/package.json | 1 - .../src/executors/webpack/webpack.impl.ts | 1 - 25 files changed, 37 insertions(+), 25 deletions(-) diff --git a/e2e/node/src/node.test.ts b/e2e/node/src/node.test.ts index febf9604647ef..36fd194093276 100644 --- a/e2e/node/src/node.test.ts +++ b/e2e/node/src/node.test.ts @@ -144,6 +144,43 @@ describe('Node Applications', () => { expect(additionalResult).toContain('Hello Additional World!'); }, 60000); + it('should be able to generate an empty application with variable in .env file', async () => { + const originalEnvPort = process.env.PORT; + const port = 3457; + process.env.PORT = `${port}`; + const nodeapp = uniq('nodeapp'); + + runCLI( + `generate @nx/node:app ${nodeapp} --linter=eslint --bundler=webpack --framework=none` + ); + await setMaxWorkers(); + + updateFile('.env', `NX_FOOBAR="test foo bar"`); + + updateFile( + `apps/${nodeapp}/src/main.ts`, + `console.log('foobar: ' + process.env['NX_FOOBAR']);` + ); + + await runCLIAsync(`build ${nodeapp}`); + checkFilesExist(`dist/apps/${nodeapp}/main.js`); + + // check serving + const p = await runCommandUntil( + `serve ${nodeapp} --port=${port} --watch=false`, + (output) => { + process.stdout.write(output); + return output.includes(`foobar: test foo bar`); + } + ); + try { + await promisifiedTreeKill(p.pid, 'SIGKILL'); + await killPorts(port); + } finally { + process.env.port = originalEnvPort; + } + }, 60000); + it('should be able to generate an express application', async () => { const nodeapp = uniq('nodeapp'); const originalEnvPort = process.env.PORT; diff --git a/packages/cypress/package.json b/packages/cypress/package.json index 63c8a67a7d70d..396222be65601 100644 --- a/packages/cypress/package.json +++ b/packages/cypress/package.json @@ -36,7 +36,6 @@ "dependencies": { "@phenomnomnominal/tsquery": "~5.0.1", "detect-port": "^1.5.1", - "dotenv": "~16.3.1", "semver": "7.5.3", "tslib": "^2.3.0", "@nx/devkit": "file:../devkit", diff --git a/packages/cypress/src/executors/cypress/cypress.impl.ts b/packages/cypress/src/executors/cypress/cypress.impl.ts index 27ca6aed51792..7a86df95b3f65 100644 --- a/packages/cypress/src/executors/cypress/cypress.impl.ts +++ b/packages/cypress/src/executors/cypress/cypress.impl.ts @@ -10,7 +10,6 @@ import { output, } from '@nx/devkit'; import { getExecutorInformation } from 'nx/src/command-line/run/executor-utils'; -import 'dotenv/config'; import { existsSync, readdirSync, unlinkSync, writeFileSync } from 'fs'; import { basename, dirname, join } from 'path'; import { getTempTailwindPath } from '../../utils/ct-helpers'; diff --git a/packages/esbuild/package.json b/packages/esbuild/package.json index 27b7137ff237a..42f0ed771d2e8 100644 --- a/packages/esbuild/package.json +++ b/packages/esbuild/package.json @@ -30,7 +30,6 @@ }, "dependencies": { "chalk": "^4.1.0", - "dotenv": "~16.3.1", "fast-glob": "3.2.7", "fs-extra": "^11.1.0", "tslib": "^2.3.0", diff --git a/packages/esbuild/src/executors/esbuild/esbuild.impl.ts b/packages/esbuild/src/executors/esbuild/esbuild.impl.ts index 2dea65586078e..f9d7c4b6f1b06 100644 --- a/packages/esbuild/src/executors/esbuild/esbuild.impl.ts +++ b/packages/esbuild/src/executors/esbuild/esbuild.impl.ts @@ -1,4 +1,3 @@ -import 'dotenv/config'; import * as chalk from 'chalk'; import type { ExecutorContext } from '@nx/devkit'; import { cacheDir, joinPathFragments, logger, stripIndents } from '@nx/devkit'; diff --git a/packages/jest/package.json b/packages/jest/package.json index 8d15dafb2255c..b626d67894dba 100644 --- a/packages/jest/package.json +++ b/packages/jest/package.json @@ -38,7 +38,6 @@ "@jest/test-result": "^29.4.1", "@phenomnomnominal/tsquery": "~5.0.1", "chalk": "^4.1.0", - "dotenv": "~16.3.1", "identity-obj-proxy": "3.0.0", "jest-config": "^29.4.1", "jest-resolve": "^29.4.1", diff --git a/packages/jest/src/executors/jest/jest.impl.ts b/packages/jest/src/executors/jest/jest.impl.ts index 193bc9b82649b..2c8210d5cb89f 100644 --- a/packages/jest/src/executors/jest/jest.impl.ts +++ b/packages/jest/src/executors/jest/jest.impl.ts @@ -1,4 +1,3 @@ -import 'dotenv/config'; import { runCLI } from 'jest'; import { readConfig, readConfigs } from 'jest-config'; import { utils as jestReporterUtils } from '@jest/reporters'; diff --git a/packages/next/package.json b/packages/next/package.json index a71714c7a64a6..c050f39561902 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -38,7 +38,6 @@ "@svgr/webpack": "^8.0.1", "chalk": "^4.1.0", "copy-webpack-plugin": "^10.2.4", - "dotenv": "~16.3.1", "fs-extra": "^11.1.0", "ignore": "^5.0.4", "semver": "7.5.3", diff --git a/packages/next/src/executors/build/build.impl.ts b/packages/next/src/executors/build/build.impl.ts index a08c7f795b12a..10b8d44b0a93b 100644 --- a/packages/next/src/executors/build/build.impl.ts +++ b/packages/next/src/executors/build/build.impl.ts @@ -1,4 +1,3 @@ -import 'dotenv/config'; import { ExecutorContext, logger, diff --git a/packages/next/src/executors/export/export.impl.ts b/packages/next/src/executors/export/export.impl.ts index 75d9c7ff5c7be..417fabeb59f1d 100644 --- a/packages/next/src/executors/export/export.impl.ts +++ b/packages/next/src/executors/export/export.impl.ts @@ -1,4 +1,3 @@ -import 'dotenv/config'; import { ExecutorContext, parseTargetString, diff --git a/packages/next/src/executors/server/custom-server.impl.ts b/packages/next/src/executors/server/custom-server.impl.ts index d360c8a605106..0c7f30794ea0f 100644 --- a/packages/next/src/executors/server/custom-server.impl.ts +++ b/packages/next/src/executors/server/custom-server.impl.ts @@ -1,4 +1,3 @@ -import 'dotenv/config'; import { ExecutorContext, parseTargetString, runExecutor } from '@nx/devkit'; import { join } from 'path'; diff --git a/packages/next/src/executors/server/server.impl.ts b/packages/next/src/executors/server/server.impl.ts index f5f83e4f60601..50aed2c417655 100644 --- a/packages/next/src/executors/server/server.impl.ts +++ b/packages/next/src/executors/server/server.impl.ts @@ -1,4 +1,3 @@ -import 'dotenv/config'; import { ExecutorContext, parseTargetString, diff --git a/packages/plugin/package.json b/packages/plugin/package.json index 2a1eda40b34c7..b52aca1e9e93f 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -29,7 +29,6 @@ }, "dependencies": { "@phenomnomnominal/tsquery": "~5.0.1", - "dotenv": "~16.3.1", "fs-extra": "^11.1.0", "tslib": "^2.3.0", "@nx/devkit": "file:../devkit", diff --git a/packages/plugin/src/executors/e2e/e2e.impl.ts b/packages/plugin/src/executors/e2e/e2e.impl.ts index f29ca0a2f3983..19de9a4bb72d9 100644 --- a/packages/plugin/src/executors/e2e/e2e.impl.ts +++ b/packages/plugin/src/executors/e2e/e2e.impl.ts @@ -1,5 +1,3 @@ -import 'dotenv/config'; - import type { ExecutorContext } from '@nx/devkit'; import { diff --git a/packages/rollup/package.json b/packages/rollup/package.json index b2c2041a95cb5..24e1c2f18a351 100644 --- a/packages/rollup/package.json +++ b/packages/rollup/package.json @@ -37,7 +37,6 @@ "autoprefixer": "^10.4.9", "babel-plugin-transform-async-to-promises": "^0.8.15", "chalk": "^4.1.0", - "dotenv": "~16.3.1", "fast-glob": "^3.2.7", "postcss": "^8.4.14", "rollup": "^2.56.2", diff --git a/packages/rollup/src/executors/rollup/rollup.impl.ts b/packages/rollup/src/executors/rollup/rollup.impl.ts index c07ed5053ca4e..687ccadaeabd9 100644 --- a/packages/rollup/src/executors/rollup/rollup.impl.ts +++ b/packages/rollup/src/executors/rollup/rollup.impl.ts @@ -1,4 +1,3 @@ -import 'dotenv/config'; import * as ts from 'typescript'; import * as rollup from 'rollup'; import * as peerDepsExternal from 'rollup-plugin-peer-deps-external'; diff --git a/packages/storybook/package.json b/packages/storybook/package.json index 526f803d47187..7828c521f8c09 100644 --- a/packages/storybook/package.json +++ b/packages/storybook/package.json @@ -30,7 +30,6 @@ "migrations": "./migrations.json" }, "dependencies": { - "dotenv": "~16.3.1", "@phenomnomnominal/tsquery": "~5.0.1", "semver": "7.5.3", "tslib": "^2.3.0", 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 5d825594761ee..6b437c71157d0 100644 --- a/packages/storybook/src/executors/build-storybook/build-storybook.impl.ts +++ b/packages/storybook/src/executors/build-storybook/build-storybook.impl.ts @@ -1,7 +1,6 @@ import { ExecutorContext, logger } from '@nx/devkit'; import * as build from '@storybook/core-server'; import { CLIOptions } from '@storybook/types'; -import 'dotenv/config'; import { pleaseUpgrade, storybookConfigExistsCheck, diff --git a/packages/storybook/src/executors/storybook/storybook.impl.ts b/packages/storybook/src/executors/storybook/storybook.impl.ts index 99b900617fb84..27fdfc92e79a2 100644 --- a/packages/storybook/src/executors/storybook/storybook.impl.ts +++ b/packages/storybook/src/executors/storybook/storybook.impl.ts @@ -1,6 +1,5 @@ import { ExecutorContext, logger } from '@nx/devkit'; import * as build from '@storybook/core-server'; -import 'dotenv/config'; import { pleaseUpgrade, storybookConfigExistsCheck, diff --git a/packages/storybook/src/executors/utils.ts b/packages/storybook/src/executors/utils.ts index fac27968c2443..47500706dd7e2 100644 --- a/packages/storybook/src/executors/utils.ts +++ b/packages/storybook/src/executors/utils.ts @@ -2,7 +2,6 @@ import { joinPathFragments, logger } from '@nx/devkit'; import { findNodes } from '@nx/js'; -import 'dotenv/config'; import { existsSync, readFileSync } from 'fs'; import { join } from 'path'; import { gte } from 'semver'; diff --git a/packages/vite/package.json b/packages/vite/package.json index c05638249e292..ed9f35ffc8874 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -31,7 +31,6 @@ "dependencies": { "@phenomnomnominal/tsquery": "~5.0.1", "@swc/helpers": "~0.5.0", - "dotenv": "~16.3.1", "enquirer": "~2.3.6", "@nx/devkit": "file:../devkit", "@nx/js": "file:../js", diff --git a/packages/vite/src/executors/build/build.impl.ts b/packages/vite/src/executors/build/build.impl.ts index 24649df190cf5..b534b7885df53 100644 --- a/packages/vite/src/executors/build/build.impl.ts +++ b/packages/vite/src/executors/build/build.impl.ts @@ -1,4 +1,3 @@ -import 'dotenv/config'; import { ExecutorContext, logger, diff --git a/packages/vite/src/executors/dev-server/dev-server.impl.ts b/packages/vite/src/executors/dev-server/dev-server.impl.ts index 2ed3171b35bf7..5e5456bc9f139 100644 --- a/packages/vite/src/executors/dev-server/dev-server.impl.ts +++ b/packages/vite/src/executors/dev-server/dev-server.impl.ts @@ -1,4 +1,3 @@ -import 'dotenv/config'; import { ExecutorContext } from '@nx/devkit'; import { createServer, InlineConfig, mergeConfig, ViteDevServer } from 'vite'; diff --git a/packages/webpack/package.json b/packages/webpack/package.json index cece6cd013be8..d3bf4b262403f 100644 --- a/packages/webpack/package.json +++ b/packages/webpack/package.json @@ -38,7 +38,6 @@ "copy-webpack-plugin": "^10.2.4", "css-loader": "^6.4.0", "css-minimizer-webpack-plugin": "^5.0.0", - "dotenv": "~16.3.1", "fork-ts-checker-webpack-plugin": "7.2.13", "ignore": "^5.0.4", "less": "4.1.3", diff --git a/packages/webpack/src/executors/webpack/webpack.impl.ts b/packages/webpack/src/executors/webpack/webpack.impl.ts index 6376cfd7629be..695e52f39b992 100644 --- a/packages/webpack/src/executors/webpack/webpack.impl.ts +++ b/packages/webpack/src/executors/webpack/webpack.impl.ts @@ -1,4 +1,3 @@ -import 'dotenv/config'; import { ExecutorContext, logger, stripIndents } from '@nx/devkit'; import { eachValueFrom } from '@nx/devkit/src/utils/rxjs-for-await'; import type { Configuration, Stats } from 'webpack';