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

fix(nextjs): inline dev-only dependencies and add e2e test to catch issues #16890

Merged
merged 1 commit into from
May 9, 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
6 changes: 6 additions & 0 deletions e2e/next/src/next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ describe('Next.js Applications', () => {
`dist/packages/${appName}/public/shared/ui/hello.txt`
);

// Check that compiled next config does not contain bad imports
const nextConfigPath = `dist/packages/${appName}/next.config.js`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were adding a lint rule. Is this just a stand-in until we have that set up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add the lint rule, but also want to make sure it doesn't get into the built file in case we missed something in lint.

expect(nextConfigPath).not.toContain(`require("../`); // missing relative paths
expect(nextConfigPath).not.toContain(`require("nx/`); // dev-only packages
expect(nextConfigPath).not.toContain(`require("@nx/`); // dev-only packages

// Check that `nx serve <app> --prod` works with previous production build (e.g. `nx build <app>`).
const prodServePort = 4000;
const prodServeProcess = await runCommandUntil(
Expand Down
6 changes: 4 additions & 2 deletions packages/next/plugins/with-nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import type { NextConfigFn } from '../src/utils/config';
import type { NextBuildBuilderOptions } from '../src/utils/types';
import type { DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils';
import type { ProjectGraph, ProjectGraphProjectNode, Target } from '@nx/devkit';
import { readTsConfigPaths } from '@nx/js';
import { findAllProjectNodeDependencies } from 'nx/src/utils/project-graph-utils';

export interface WithNxOptions extends NextConfig {
nx?: {
Expand Down Expand Up @@ -222,6 +220,10 @@ function withNx(
forNextVersion('>=13.1.0', () => {
if (!graph.dependencies[project]) return;

const { readTsConfigPaths } = require('@nx/js');
const {
findAllProjectNodeDependencies,
} = require('nx/src/utils/project-graph-utils');
const paths = readTsConfigPaths();
const deps = findAllProjectNodeDependencies(project);
nextConfig.transpilePackages ??= [];
Expand Down