Skip to content

Commit

Permalink
Revert "chore(core): add one off exception for next.js (#21572)"
Browse files Browse the repository at this point in the history
This reverts commit 26a815c.
  • Loading branch information
xiongemi committed Feb 9, 2024
1 parent 424cd8f commit 425ad1a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 50 deletions.
16 changes: 6 additions & 10 deletions packages/devkit/src/utils/config-utils.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -21,12 +22,7 @@ export async function loadConfigFile<T extends object = any>(
? 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 {
Expand Down
1 change: 0 additions & 1 deletion packages/nx/src/devkit-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ export {
createProjectRootMappingsFromProjectConfigurations,
findProjectForPath,
} from './project-graph/utils/find-project-for-path';
export { registerTsProject } from './plugins/js/utils/register';
45 changes: 11 additions & 34 deletions packages/nx/src/plugins/js/utils/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -80,22 +66,17 @@ export function registerTsProject(
}

export function getSwcTranspiler(
compilerOptions: CompilerOptions,
tsConfigPath?: string
compilerOptions: CompilerOptions
): (...args: unknown[]) => unknown {
type ISwcRegister = typeof import('@swc-node/register/register')['register'];

// These are requires to prevent it from registering when it shouldn't
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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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();
Expand Down
6 changes: 1 addition & 5 deletions packages/playwright/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
export {
createNodes,
PlaywrightPluginOptions,
createDependencies,
} from './src/plugins/plugin';
export { createNodes, PlaywrightPluginOptions } from './src/plugins/plugin';

0 comments on commit 425ad1a

Please sign in to comment.