From 425ad1afe2d83ea6a7de232d3c32fea0d1b97258 Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Fri, 9 Feb 2024 16:00:43 -0500 Subject: [PATCH] Revert "chore(core): add one off exception for next.js (#21572)" This reverts commit 26a815c7dfe88769f318ceb382240da8af34519a. --- packages/devkit/src/utils/config-utils.ts | 16 +++---- packages/nx/src/devkit-internals.ts | 1 - packages/nx/src/plugins/js/utils/register.ts | 45 +++++--------------- packages/playwright/plugin.ts | 6 +-- 4 files changed, 18 insertions(+), 50 deletions(-) diff --git a/packages/devkit/src/utils/config-utils.ts b/packages/devkit/src/utils/config-utils.ts index 99c74871dfb130..c6a2cd0c287d15 100644 --- a/packages/devkit/src/utils/config-utils.ts +++ b/packages/devkit/src/utils/config-utils.ts @@ -1,8 +1,9 @@ -import { dirname, extname, join, relative } from 'path'; +import { dirname, extname, join } from 'path'; import { existsSync, readdirSync } from 'fs'; -import { requireNx } from '../../nx'; - -const { workspaceRoot, registerTsProject } = requireNx(); +// eslint-disable-next-line @typescript-eslint/no-restricted-imports +import { workspaceRoot } from 'nx/src/devkit-exports'; +// eslint-disable-next-line @typescript-eslint/no-restricted-imports +import { registerTsProject } from 'nx/src/plugins/js/utils/register'; export let dynamicImport = new Function( 'modulePath', @@ -21,12 +22,7 @@ export async function loadConfigFile( ? join(dirname(configFilePath), 'tsconfig.json') : getRootTsConfigPath(); if (tsConfigPath) { - const unregisterTsProject = registerTsProject( - tsConfigPath, - undefined, - // TODO(@AgentEnder): Remove this hack to make sure that e2e loads properly for next.js - relative(workspaceRoot, dirname(configFilePath)) === 'e2e' - ); + const unregisterTsProject = registerTsProject(tsConfigPath); try { module = await load(configFilePath); } finally { diff --git a/packages/nx/src/devkit-internals.ts b/packages/nx/src/devkit-internals.ts index a24b33c98670ae..1fec764f3a746e 100644 --- a/packages/nx/src/devkit-internals.ts +++ b/packages/nx/src/devkit-internals.ts @@ -20,4 +20,3 @@ export { createProjectRootMappingsFromProjectConfigurations, findProjectForPath, } from './project-graph/utils/find-project-for-path'; -export { registerTsProject } from './plugins/js/utils/register'; diff --git a/packages/nx/src/plugins/js/utils/register.ts b/packages/nx/src/plugins/js/utils/register.ts index a6f174f05c8e5d..3020becc4bb671 100644 --- a/packages/nx/src/plugins/js/utils/register.ts +++ b/packages/nx/src/plugins/js/utils/register.ts @@ -32,31 +32,17 @@ export function registerTsProject(tsConfigPath: string): () => void; * @returns cleanup function * @deprecated This signature will be removed in Nx v19. You should pass the full path to the tsconfig in the first argument. */ +export function registerTsProject(path: string, configFilename: string); export function registerTsProject( path: string, - configFilename: string, - /** - * @deprecated Do not use this.. it's a 1-off exception - */ - useForSwcEnvironmentVariable?: boolean -); -export function registerTsProject( - path: string, - configFilename?: string, - /** - * @deprecated Do not use this.. it's a 1-off exception - */ - useForSwcEnvironmentVariable?: boolean + configFilename?: string ): () => void { const tsConfigPath = configFilename ? join(path, configFilename) : path; const compilerOptions: CompilerOptions = readCompilerOptions(tsConfigPath); const cleanupFunctions: ((...args: unknown[]) => unknown)[] = [ registerTsConfigPaths(tsConfigPath), - registerTranspiler( - compilerOptions, - useForSwcEnvironmentVariable ? tsConfigPath : undefined - ), + registerTranspiler(compilerOptions), ]; // Add ESM support for `.ts` files. @@ -80,8 +66,7 @@ export function registerTsProject( } export function getSwcTranspiler( - compilerOptions: CompilerOptions, - tsConfigPath?: string + compilerOptions: CompilerOptions ): (...args: unknown[]) => unknown { type ISwcRegister = typeof import('@swc-node/register/register')['register']; @@ -89,13 +74,9 @@ export function getSwcTranspiler( const register = require('@swc-node/register/register') .register as ISwcRegister; - if (tsConfigPath) { - process.env.SWC_NODE_PROJECT = tsConfigPath; - } else { - let rootTsConfig = join(workspaceRoot, 'tsconfig.base.json'); - if (existsSync(rootTsConfig)) { - process.env.SWC_NODE_PROJECT = rootTsConfig; - } + let rootTsConfig = join(workspaceRoot, 'tsconfig.base.json'); + if (existsSync(rootTsConfig)) { + process.env.SWC_NODE_PROJECT = rootTsConfig; } const cleanupFn = register(compilerOptions); @@ -127,10 +108,7 @@ export function getTsNodeTranspiler( }; } -export function getTranspiler( - compilerOptions: CompilerOptions, - tsConfigPath?: string -) { +export function getTranspiler(compilerOptions: CompilerOptions) { const preferTsNode = process.env.NX_PREFER_TS_NODE === 'true'; if (!ts) { @@ -144,7 +122,7 @@ export function getTranspiler( compilerOptions.skipLibCheck = true; if (swcNodeInstalled && !preferTsNode) { - return () => getSwcTranspiler(compilerOptions, tsConfigPath); + return () => getSwcTranspiler(compilerOptions); } // We can fall back on ts-node if it's available @@ -162,11 +140,10 @@ export function getTranspiler( * @returns cleanup method */ export function registerTranspiler( - compilerOptions: CompilerOptions, - tsConfigPath?: string + compilerOptions: CompilerOptions ): () => void { // Function to register transpiler that returns cleanup function - const transpiler = getTranspiler(compilerOptions, tsConfigPath); + const transpiler = getTranspiler(compilerOptions); if (!transpiler) { warnNoTranspiler(); diff --git a/packages/playwright/plugin.ts b/packages/playwright/plugin.ts index 6a6eb207ac0479..255dad140daf63 100644 --- a/packages/playwright/plugin.ts +++ b/packages/playwright/plugin.ts @@ -1,5 +1 @@ -export { - createNodes, - PlaywrightPluginOptions, - createDependencies, -} from './src/plugins/plugin'; +export { createNodes, PlaywrightPluginOptions } from './src/plugins/plugin';