Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements v2 #200

Merged
merged 4 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 33 additions & 35 deletions packages/e2e-runner/src/executors/run/run.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,57 +21,55 @@ 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, options))
runningTargets = targets.map((targetOptions) => new NxTarget(targetOptions))

try {
// Start all targets
await Promise.all(runningTargets.map((nxTarget) => nxTarget.setup()))

} catch {
await killTargets()

return { success: false }
}

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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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')
})
})
26 changes: 20 additions & 6 deletions packages/e2e-runner/src/executors/run/utils/nx-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -24,13 +22,11 @@ export class NxTarget {

private readonly isAvailable: () => Promise<boolean>
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
Expand Down Expand Up @@ -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<void> {
let processExitedReject = (error: Error) => {}

Expand Down
2 changes: 1 addition & 1 deletion packages/gcp-cloud-run/src/executors/deploy/deploy.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
]))
}
Expand Down
37 changes: 37 additions & 0 deletions packages/react-email/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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": {}
}
]
}
15 changes: 15 additions & 0 deletions packages/react-email/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# @nx-extend/react-email

<a href="https://www.npmjs.com/package/@nx-extend/react-email" rel="nofollow">
<img src="https://badgen.net/npm/v/@nx-extend/react-email" alt="@nx-extend/react-email NPM package">
</a>

**Nx plugin for building emails with [React Email](https://react.email)**.

## Setup

### Install

```sh
npm install -D @nx-extend/react-email
```
7 changes: 7 additions & 0 deletions packages/react-email/executors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"executors": {

},
"builders": {
}
}
8 changes: 8 additions & 0 deletions packages/react-email/generators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json-schema.org/schema",
"name": "react-email",
"version": "0.0.1",
"generators": {

}
}
12 changes: 12 additions & 0 deletions packages/react-email/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* eslint-disable */
export default {
displayName: 'react-email',
preset: '../../jest.preset.js',
globals: {},
transform: {
'^.+\\.[tj]sx?$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }]
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/packages/react-email',
testEnvironment: 'node'
}
20 changes: 20 additions & 0 deletions packages/react-email/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
64 changes: 64 additions & 0 deletions packages/react-email/project.json
Original file line number Diff line number Diff line change
@@ -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": []
}
Empty file.
13 changes: 13 additions & 0 deletions packages/react-email/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
11 changes: 11 additions & 0 deletions packages/react-email/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -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"]
}
16 changes: 16 additions & 0 deletions packages/react-email/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
3 changes: 3 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
],
"@nx-extend/vercel": [
"packages/vercel/src/index.ts"
],
"@nx-extend/react-email": [
"packages/react-email/src/index.ts"
]
}
},
Expand Down
Loading
Loading