Skip to content

Commit

Permalink
fix(react): apply review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Oct 3, 2023
1 parent 65fa142 commit caedb36
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 92 deletions.
12 changes: 0 additions & 12 deletions graph/client-e2e/jest.config.ts

This file was deleted.

10 changes: 0 additions & 10 deletions graph/client-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
"sourceRoot": "graph/client-e2e/src",
"projectType": "application",
"targets": {
"pre-e2e": {
"inputs": ["default", "^production", "{workspaceRoot}/jest.preset.js"],
"executor": "@nx/jest:jest",
"options": {
"jestConfig": "{projectRoot}/jest.config.ts",
"passWithNoTests": true
},
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"]
},
"e2e-base": {
"dependsOn": ["pre-e2e"],
"executor": "@nx/cypress:cypress",
"options": {
"testingType": "e2e",
Expand Down
11 changes: 0 additions & 11 deletions graph/client-e2e/src/ensure-cypress.spec.ts

This file was deleted.

9 changes: 2 additions & 7 deletions graph/client-e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"sourceMap": false,
"outDir": "../../dist/out-tsc",
"allowJs": true,
"types": ["cypress", "jest", "node"],
"types": ["cypress", "node"],
"lib": ["DOM"]
},
"files": [],
Expand All @@ -16,10 +16,5 @@
"src/**/*.ts",
"src/**/*.js"
],
"references": [
{
"path": "./tsconfig.spec.json"
}
],
"exclude": ["src/**/*.spec.ts"]
"references": []
}
10 changes: 0 additions & 10 deletions graph/client-e2e/tsconfig.spec.json

This file was deleted.

15 changes: 8 additions & 7 deletions packages/angular/src/builders/utilities/module-federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { join } from 'path';
import { existsSync, readFileSync } from 'fs';
import { logger } from '@nx/devkit';
import { tsNodeRegister } from '@nx/js/src/utils/typescript/tsnode-register';
import { registerTsProject } from 'nx/src/utils/register';

export function getDynamicRemotes(
project: ProjectConfiguration,
Expand Down Expand Up @@ -91,19 +92,19 @@ function getModuleFederationConfig(

let moduleFederationConfigPath = moduleFederationConfigPathJS;

let tsNodeService;
let cleanupTranspiler = () => {};
if (existsSync(moduleFederationConfigPathTS)) {
tsNodeService = tsNodeRegister(moduleFederationConfigPathTS, tsconfigPath, {
transpileOnly: true,
});
cleanupTranspiler = registerTsProject(
moduleFederationConfigPathTS,
tsconfigPath
);
moduleFederationConfigPath = moduleFederationConfigPathTS;
}

try {
const config = require(moduleFederationConfigPath);
if (tsNodeService) {
tsNodeService.enabled(false);
}
cleanupTranspiler();

return {
mfeConfig: config.default || config,
mfConfigPath: moduleFederationConfigPath,
Expand Down
15 changes: 5 additions & 10 deletions packages/angular/src/builders/utilities/webpack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { merge } from 'webpack-merge';
import { tsNodeRegister } from '@nx/js/src/utils/typescript/tsnode-register';
import { registerTsProject } from 'nx/src/utils/register';

export async function mergeCustomWebpackConfig(
baseWebpackConfig: any,
Expand All @@ -26,12 +27,9 @@ export async function mergeCustomWebpackConfig(
}

export function resolveCustomWebpackConfig(path: string, tsConfig: string) {
const tsNodeService = tsNodeRegister(path, tsConfig);

const cleanupTranspiler = registerTsProject(path, tsConfig);
const customWebpackConfig = require(path);
if (tsNodeService) {
tsNodeService.enabled(false);
}
cleanupTranspiler();
// If the user provides a configuration in TS file
// then there are 2 cases for exporting an object. The first one is:
// `module.exports = { ... }`. And the second one is:
Expand All @@ -45,12 +43,9 @@ export function resolveIndexHtmlTransformer(
tsConfig: string,
target: import('@angular-devkit/architect').Target
) {
const tsNodeService = tsNodeRegister(path, tsConfig);
const cleanupTranspiler = registerTsProject(path, tsConfig);
const indexTransformer = require(path);

if (tsNodeService) {
tsNodeService.enabled(false);
}
cleanupTranspiler();

const transform = indexTransformer.default ?? indexTransformer;

Expand Down
15 changes: 3 additions & 12 deletions packages/js/src/utils/typescript/tsnode-register.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import type { RegisterOptions, Service } from 'ts-node';

export function tsNodeRegister(
file: string,
tsConfig?: string,
tsNodeOptions?: RegisterOptions
): Service | undefined {
export function tsNodeRegister(file: string, tsConfig?: string) {
if (!file?.endsWith('.ts')) return;
// Register TS compiler lazily
const tsNodeService = require('ts-node').register({
require('ts-node').register({
project: tsConfig,
compilerOptions: {
module: 'CommonJS',
types: ['node'],
},
...tsNodeOptions,
});

if (!tsConfig) return tsNodeService;
if (!tsConfig) return;

// Register paths in tsConfig
const tsconfigPaths = require('tsconfig-paths');
Expand All @@ -25,6 +18,4 @@ export function tsNodeRegister(
if (baseUrl && paths) {
tsconfigPaths.register({ baseUrl, paths });
}

return tsNodeService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { findMatchingProjects } from 'nx/src/utils/find-matching-projects';
import { fork } from 'child_process';
import { existsSync } from 'fs';
import { tsNodeRegister } from '@nx/js/src/utils/typescript/tsnode-register';
import { registerTsProject } from 'nx/src/utils/register';

type ModuleFederationDevServerOptions = WebDevServerOptions & {
devRemotes?: string | string[];
Expand Down Expand Up @@ -54,19 +55,19 @@ function getModuleFederationConfig(
let moduleFederationConfigPath = moduleFederationConfigPathJS;

// create a no-op so this can be called with issue
let tsNodeService;
let cleanupTranspiler = () => {};
if (existsSync(moduleFederationConfigPathTS)) {
tsNodeService = tsNodeRegister(moduleFederationConfigPathTS, tsconfigPath, {
transpileOnly: true,
});
cleanupTranspiler = registerTsProject(
moduleFederationConfigPathTS,
tsconfigPath
);
moduleFederationConfigPath = moduleFederationConfigPathTS;
}

try {
const config = require(moduleFederationConfigPath);
if (tsNodeService) {
tsNodeService.enabled(false);
}
cleanupTranspiler();

return config.default || config;
} catch {
throw new Error(
Expand Down
9 changes: 3 additions & 6 deletions packages/webpack/src/utils/webpack/custom-webpack.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { tsNodeRegister } from '@nx/js/src/utils/typescript/tsnode-register';
import { registerTsProject } from 'nx/src/utils/register';

export function resolveCustomWebpackConfig(path: string, tsConfig: string) {
const tsNodeService = tsNodeRegister(path, tsConfig);

const cleanupTranspiler = registerTsProject(path, tsConfig);
const customWebpackConfig = require(path);

if (tsNodeService) {
tsNodeService.enabled(false);
}
cleanupTranspiler();

// If the user provides a configuration in TS file
// then there are 2 cases for exporing an object. The first one is:
Expand Down

0 comments on commit caedb36

Please sign in to comment.