From 139ac952c71fc0ef3a9b84f558dee1e2ec2010f3 Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Sat, 16 Dec 2023 17:02:21 +0100 Subject: [PATCH 1/4] chore: Added empty `@nx-extend/react-email` package --- packages/react-email/.eslintrc.json | 37 ++++++++++++++ packages/react-email/README.md | 15 ++++++ packages/react-email/executors.json | 7 +++ packages/react-email/generators.json | 8 ++++ packages/react-email/jest.config.ts | 12 +++++ packages/react-email/package.json | 20 ++++++++ packages/react-email/project.json | 64 +++++++++++++++++++++++++ packages/react-email/src/index.ts | 0 packages/react-email/tsconfig.json | 13 +++++ packages/react-email/tsconfig.lib.json | 11 +++++ packages/react-email/tsconfig.spec.json | 16 +++++++ tsconfig.base.json | 3 ++ yarn.lock | 6 +++ 13 files changed, 212 insertions(+) create mode 100644 packages/react-email/.eslintrc.json create mode 100644 packages/react-email/README.md create mode 100644 packages/react-email/executors.json create mode 100644 packages/react-email/generators.json create mode 100644 packages/react-email/jest.config.ts create mode 100644 packages/react-email/package.json create mode 100644 packages/react-email/project.json create mode 100644 packages/react-email/src/index.ts create mode 100644 packages/react-email/tsconfig.json create mode 100644 packages/react-email/tsconfig.lib.json create mode 100644 packages/react-email/tsconfig.spec.json diff --git a/packages/react-email/.eslintrc.json b/packages/react-email/.eslintrc.json new file mode 100644 index 00000000..4960e00d --- /dev/null +++ b/packages/react-email/.eslintrc.json @@ -0,0 +1,37 @@ +{ + "extends": "../../.eslintrc.json", + "ignorePatterns": [ + "!**/*" + ], + "rules": {}, + "overrides": [ + { + "files": [ + "*.ts", + "*.tsx", + "*.js", + "*.jsx" + ], + "parserOptions": { + "project": [ + "packages/react-email/tsconfig.*?.json" + ] + }, + "rules": {} + }, + { + "files": [ + "*.ts", + "*.tsx" + ], + "rules": {} + }, + { + "files": [ + "*.js", + "*.jsx" + ], + "rules": {} + } + ] +} diff --git a/packages/react-email/README.md b/packages/react-email/README.md new file mode 100644 index 00000000..52272505 --- /dev/null +++ b/packages/react-email/README.md @@ -0,0 +1,15 @@ +# @nx-extend/react-email + + + @nx-extend/react-email NPM package + + +**Nx plugin for building emails with [React Email](https://react.email)**. + +## Setup + +### Install + +```sh +npm install -D @nx-extend/react-email +``` diff --git a/packages/react-email/executors.json b/packages/react-email/executors.json new file mode 100644 index 00000000..05897106 --- /dev/null +++ b/packages/react-email/executors.json @@ -0,0 +1,7 @@ +{ + "executors": { + + }, + "builders": { + } +} diff --git a/packages/react-email/generators.json b/packages/react-email/generators.json new file mode 100644 index 00000000..5805fd22 --- /dev/null +++ b/packages/react-email/generators.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://json-schema.org/schema", + "name": "react-email", + "version": "0.0.1", + "generators": { + + } +} diff --git a/packages/react-email/jest.config.ts b/packages/react-email/jest.config.ts new file mode 100644 index 00000000..af50b79c --- /dev/null +++ b/packages/react-email/jest.config.ts @@ -0,0 +1,12 @@ +/* eslint-disable */ +export default { + displayName: 'react-email', + preset: '../../jest.preset.js', + globals: {}, + transform: { + '^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '/tsconfig.spec.json' }] + }, + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'], + coverageDirectory: '../../coverage/packages/react-email', + testEnvironment: 'node' +} diff --git a/packages/react-email/package.json b/packages/react-email/package.json new file mode 100644 index 00000000..7bc3a9bd --- /dev/null +++ b/packages/react-email/package.json @@ -0,0 +1,20 @@ +{ + "name": "@nx-extend/react-email", + "version": "0.0.1", + "keywords": [ + "nx", + "react-email" + ], + "homepage": "https://github.com/TriPSs/nx-extend/blob/master/packages/react-email/README.md", + "bugs": { + "url": "https://github.com/tripss/nx-extend/issues" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/tripss/nx-extend" + }, + "license": "MIT", + "main": "src/index.js", + "builders": "./executors.json", + "generators": "./generators.json" +} diff --git a/packages/react-email/project.json b/packages/react-email/project.json new file mode 100644 index 00000000..8ac46c7c --- /dev/null +++ b/packages/react-email/project.json @@ -0,0 +1,64 @@ +{ + "name": "react-email", + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "sourceRoot": "packages/react-email/src", + "projectType": "library", + "targets": { + "lint": { + "executor": "@nrwl/linter:eslint", + "options": { + "lintFilePatterns": ["packages/react-email/**/*.ts"] + } + }, + "test": { + "executor": "@nx/jest:jest", + "outputs": ["{workspaceRoot}/coverage/packages/react-email"], + "options": { + "jestConfig": "packages/react-email/jest.config.ts" + } + }, + "build": { + "executor": "@nx/js:tsc", + "outputs": ["{options.outputPath}"], + "options": { + "outputPath": "dist/packages/react-email", + "tsConfig": "packages/react-email/tsconfig.lib.json", + "packageJson": "packages/react-email/package.json", + "main": "packages/react-email/src/index.ts", + "buildableProjectDepsInPackageJsonType": "dependencies", + "assets": [ + "packages/react-email/*.md", + { + "input": "./packages/react-email/src", + "glob": "**/*.!(ts)", + "output": "./src" + }, + { + "input": "./packages/react-email", + "glob": "generators.json", + "output": "." + }, + { + "input": "./packages/react-email", + "glob": "executors.json", + "output": "." + } + ], + "updateBuildableProjectDepsInPackageJson": true + } + }, + "version": { + "executor": "@jscutlery/semver:version", + "options": { + "tagPrefix": "${target}@" + } + }, + "publish": { + "executor": "nx:run-commands", + "options": { + "command": "npm publish ./dist/packages/react-email --access public || true" + } + } + }, + "tags": [] +} diff --git a/packages/react-email/src/index.ts b/packages/react-email/src/index.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/react-email/tsconfig.json b/packages/react-email/tsconfig.json new file mode 100644 index 00000000..62ebbd94 --- /dev/null +++ b/packages/react-email/tsconfig.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.base.json", + "files": [], + "include": [], + "references": [ + { + "path": "./tsconfig.lib.json" + }, + { + "path": "./tsconfig.spec.json" + } + ] +} diff --git a/packages/react-email/tsconfig.lib.json b/packages/react-email/tsconfig.lib.json new file mode 100644 index 00000000..3ce6be94 --- /dev/null +++ b/packages/react-email/tsconfig.lib.json @@ -0,0 +1,11 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../../dist/out-tsc", + "declaration": true, + "types": ["node"] + }, + "exclude": ["**/*.spec.ts", "jest.config.ts"], + "include": ["**/*.ts"] +} diff --git a/packages/react-email/tsconfig.spec.json b/packages/react-email/tsconfig.spec.json new file mode 100644 index 00000000..831ab648 --- /dev/null +++ b/packages/react-email/tsconfig.spec.json @@ -0,0 +1,16 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "outDir": "../../dist/out-tsc", + "module": "commonjs", + "types": ["jest", "node"] + }, + "include": [ + "**/*.spec.ts", + "**/*.spec.tsx", + "**/*.spec.js", + "**/*.spec.jsx", + "**/*.d.ts", + "jest.config.ts" + ] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index eedf72be..088bf290 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -62,6 +62,9 @@ ], "@nx-extend/vercel": [ "packages/vercel/src/index.ts" + ], + "@nx-extend/react-email": [ + "packages/react-email/src/index.ts" ] } }, diff --git a/yarn.lock b/yarn.lock index 51c67530..20579f0f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4555,6 +4555,12 @@ __metadata: languageName: unknown linkType: soft +"@nx-extend/react-email@workspace:packages/react-email": + version: 0.0.0-use.local + resolution: "@nx-extend/react-email@workspace:packages/react-email" + languageName: unknown + linkType: soft + "@nx-extend/strapi@workspace:packages/strapi": version: 0.0.0-use.local resolution: "@nx-extend/strapi@workspace:packages/strapi" From f7f630c49b3d035b54e24220e1f54f5595039894 Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Sat, 16 Dec 2023 17:02:48 +0100 Subject: [PATCH 2/4] fix(gcp-cloud-run): Fixed source directory undefined when generating repo info file --- packages/gcp-cloud-run/src/executors/deploy/deploy.impl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gcp-cloud-run/src/executors/deploy/deploy.impl.ts b/packages/gcp-cloud-run/src/executors/deploy/deploy.impl.ts index cfb29a9a..d4e47fec 100644 --- a/packages/gcp-cloud-run/src/executors/deploy/deploy.impl.ts +++ b/packages/gcp-cloud-run/src/executors/deploy/deploy.impl.ts @@ -123,7 +123,7 @@ export async function deployExecutor( execCommand(buildCommand([ 'gcloud debug source gen-repo-info-file', - `--source-directory=${sourceRoot}`, + `--source-directory=${sourceRoot || './'}`, `--output-directory=${distDirectory}` ])) } From 321e7453da3b3b3ca9f4233359e0617a4cfb162c Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Tue, 19 Dec 2023 17:01:00 +0100 Subject: [PATCH 3/4] feat(e2e-runner): Support injecting env variables into `checkUrl` Fixes #88 --- .../e2e-runner/src/executors/run/run.impl.ts | 2 +- .../run/utils/__tests__/nx-target.spec.ts | 15 +++++++++++ .../src/executors/run/utils/nx-target.ts | 26 ++++++++++++++----- 3 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 packages/e2e-runner/src/executors/run/utils/__tests__/nx-target.spec.ts diff --git a/packages/e2e-runner/src/executors/run/run.impl.ts b/packages/e2e-runner/src/executors/run/run.impl.ts index 4e7ac16e..d0c27b67 100644 --- a/packages/e2e-runner/src/executors/run/run.impl.ts +++ b/packages/e2e-runner/src/executors/run/run.impl.ts @@ -25,7 +25,7 @@ export async function endToEndRunner( const { runner, targets, ...rest } = options - runningTargets = targets.map((targetOptions) => new NxTarget(targetOptions, options)) + runningTargets = targets.map((targetOptions) => new NxTarget(targetOptions)) try { // Start all targets diff --git a/packages/e2e-runner/src/executors/run/utils/__tests__/nx-target.spec.ts b/packages/e2e-runner/src/executors/run/utils/__tests__/nx-target.spec.ts new file mode 100644 index 00000000..72a49912 --- /dev/null +++ b/packages/e2e-runner/src/executors/run/utils/__tests__/nx-target.spec.ts @@ -0,0 +1,15 @@ +import { NxTarget } from '../nx-target' + +describe('NxTarget', () => { + it('should inject env variables in "checkUrl" option', () => { + process.env.SUPER_FAKE_PORT = '3000' + + const target = new NxTarget({ + target: 'fake', + checkUrl: 'http://LOCALHOST:$SUPER_FAKE_PORT/$DOES_NOT_EXIST' + }) + + // @ts-expect-error is a private prop + expect(target.options.checkUrl).toEqual('http://LOCALHOST:3000/$DOES_NOT_EXIST') + }) +}) diff --git a/packages/e2e-runner/src/executors/run/utils/nx-target.ts b/packages/e2e-runner/src/executors/run/utils/nx-target.ts index 924901ca..aca23e6e 100644 --- a/packages/e2e-runner/src/executors/run/utils/nx-target.ts +++ b/packages/e2e-runner/src/executors/run/utils/nx-target.ts @@ -3,8 +3,6 @@ import { readCachedProjectGraph } from '@nx/workspace/src/core/project-graph' import { getPackageManagerExecCommand, USE_VERBOSE_LOGGING } from '@nx-extend/core' import * as childProcess from 'child_process' -import type { RunOptions } from '../run.impl' - import { isApiLive } from './is-api-live' import { wait } from './wait' @@ -24,13 +22,11 @@ export class NxTarget { private readonly isAvailable: () => Promise private readonly options: NxTargetOptions - private readonly runOptions: RunOptions private killed = false - constructor(options: NxTargetOptions, runOptions: RunOptions) { - this.options = options - this.runOptions = runOptions + constructor(options: NxTargetOptions) { + this.options = this.processOptions(options) this.isAvailable = () => isApiLive(options.checkUrl, { rejectUnauthorized: options.rejectUnauthorized @@ -61,6 +57,24 @@ export class NxTarget { this.killed = true } + private processOptions(options: NxTargetOptions): NxTargetOptions { + if (options.checkUrl.includes('$')) { + const variables = options.checkUrl.match(/\$[A-Z_-]+/g) + + if (variables && variables.length > 0) { + for (const variable of variables) { + const envVariable = variable.replace('$', '') + + if (envVariable in process.env) { + options.checkUrl = options.checkUrl.replace(variable, process.env[envVariable]) + } + } + } + } + + return options + } + private async startProcess(): Promise { let processExitedReject = (error: Error) => {} From 3cc8ff26e5a258ba19f070a2dc8dc78ea558a89c Mon Sep 17 00:00:00 2001 From: Tycho Bokdam Date: Tue, 19 Dec 2023 17:08:42 +0100 Subject: [PATCH 4/4] refactor(e2e-runner): Improve implementation --- .../e2e-runner/src/executors/run/run.impl.ts | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/packages/e2e-runner/src/executors/run/run.impl.ts b/packages/e2e-runner/src/executors/run/run.impl.ts index d0c27b67..16b7f52f 100644 --- a/packages/e2e-runner/src/executors/run/run.impl.ts +++ b/packages/e2e-runner/src/executors/run/run.impl.ts @@ -21,8 +21,6 @@ export async function endToEndRunner( options: RunOptions, context: ExecutorContext ): Promise<{ success: boolean }> { - let success: boolean - const { runner, targets, ...rest } = options runningTargets = targets.map((targetOptions) => new NxTarget(targetOptions)) @@ -30,6 +28,7 @@ export async function endToEndRunner( try { // Start all targets await Promise.all(runningTargets.map((nxTarget) => nxTarget.setup())) + } catch { await killTargets() @@ -37,41 +36,40 @@ export async function endToEndRunner( } try { - if (runner === 'cypress') { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const cypressExecutor = require('@nx/cypress/src/executors/cypress/cypress.impl').default - - success = (await cypressExecutor(rest, context)).success - } else if (runner === 'playwright') { - logger.warn('Runner "playwright" is no longer maintained in favor of @nx/playwright!') - - // eslint-disable-next-line @typescript-eslint/no-var-requires - const playwrightExecutor = require('@nx-extend/playwright/src/executors/test/test.impl').default - - success = (await playwrightExecutor(rest, context)).success - } else if (runner === '@nx/playwright') { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const playwrightExecutor = require('@nx/playwright').playwrightExecutor - - success = (await playwrightExecutor(rest, context)).success - } else if (runner === 'run-commands') { - // eslint-disable-next-line @typescript-eslint/no-var-requires - const runCommandsExecutor = require('nx/src/executors/run-commands/run-commands.impl').default - - success = (await runCommandsExecutor(rest as RunCommandsOptions, context)).success - } else { - throw new Error(`Unknown runner "${runner}"`) - } - } catch (error) { - console.error(error) + switch (runner) { + case 'cypress': + // eslint-disable-next-line @typescript-eslint/no-var-requires + const cypressExecutor = require('@nx/cypress/src/executors/cypress/cypress.impl').default - success = false - } + return await cypressExecutor(rest, context) - // Kill all targets - await killTargets() + case 'playwright': + logger.warn('Runner "playwright" is no longer maintained in favor of @nx/playwright!') + + // eslint-disable-next-line @typescript-eslint/no-var-requires + const playwrightExecutor = require('@nx-extend/playwright/src/executors/test/test.impl').default + + return await playwrightExecutor(rest, context) - return { success } + case '@nx/playwright': + // eslint-disable-next-line @typescript-eslint/no-var-requires + const nxPlaywrightExecutor = require('@nx/playwright').playwrightExecutor + + return await nxPlaywrightExecutor(rest, context) + + case 'run-commands': + // eslint-disable-next-line @typescript-eslint/no-var-requires + const runCommandsExecutor = require('nx/src/executors/run-commands/run-commands.impl').default + + return await runCommandsExecutor(rest as RunCommandsOptions, context) + + default: + throw new Error(`Unknown runner "${runner}"`) + } + } finally { + // Kill all targets + await killTargets() + } } process.on('exit', () => killTargets())