diff --git a/e2e/next/src/next.test.ts b/e2e/next/src/next.test.ts index 8987c45cbb6cc..0006c54f0b481 100644 --- a/e2e/next/src/next.test.ts +++ b/e2e/next/src/next.test.ts @@ -45,10 +45,14 @@ describe('Next.js Applications', () => { const appName = uniq('app'); const nextLib = uniq('nextlib'); const jsLib = uniq('tslib'); + const buildableLib = uniq('buildablelib'); runCLI(`generate @nrwl/next:app ${appName} --no-interactive --style=css`); runCLI(`generate @nrwl/next:lib ${nextLib} --no-interactive`); runCLI(`generate @nrwl/js:lib ${jsLib} --no-interactive`); + runCLI( + `generate @nrwl/js:lib ${buildableLib} --no-interactive --bundler=vite` + ); // Create file in public that should be copied to dist updateFile(`apps/${appName}/public/a/b.txt`, `Hello World!`); @@ -77,27 +81,36 @@ describe('Next.js Applications', () => { updateFile( `libs/${jsLib}/src/lib/${jsLib}.ts`, ` - export function testFn(): string { + export function jsLib(): string { return 'Hello Nx'; }; // testing whether async-await code in Node / Next.js api routes works as expected - export async function testAsyncFn() { + export async function jsLibAsync() { return await Promise.resolve('hell0'); } ` ); + updateFile( + `libs/${buildableLib}/src/lib/${buildableLib}.ts`, + ` + export function buildableLib(): string { + return 'Hello Buildable'; + }; + ` + ); + const mainPath = `apps/${appName}/pages/index.tsx`; const content = readFile(mainPath); updateFile( `apps/${appName}/pages/api/hello.ts`, ` - import { testAsyncFn } from '@${proj}/${jsLib}'; + import { jsLibAsync } from '@${proj}/${jsLib}'; export default async function handler(_, res) { - const value = await testAsyncFn(); + const value = await jsLibAsync(); res.send(value); } ` @@ -106,7 +119,8 @@ describe('Next.js Applications', () => { updateFile( mainPath, ` - import { testFn } from '@${proj}/${jsLib}'; + import { jsLib } from '@${proj}/${jsLib}'; + import { buildableLib } from '@${proj}/${buildableLib}'; /* eslint-disable */ import dynamic from 'next/dynamic'; @@ -119,7 +133,8 @@ describe('Next.js Applications', () => { ``, `
- {testFn()} + {jsLib()} + {buildableLib()}
` @@ -194,7 +209,7 @@ describe('Next.js Applications', () => { updateFile( `libs/${jsLib}/src/lib/${jsLib}.ts`, ` - export function testFn(): string { + export function jsLib(): string { return process.env.NX_CUSTOM_VAR; }; ` @@ -204,11 +219,11 @@ describe('Next.js Applications', () => { `apps/${appName}/pages/index.tsx`, ` import React from 'react'; - import { testFn } from '@${proj}/${jsLib}'; + import { jsLib } from '@${proj}/${jsLib}'; export const Index = ({ greeting }: any) => { return ( -

{testFn()}

+

{jsLib()}

); }; export default Index; diff --git a/packages/next/plugins/with-nx.ts b/packages/next/plugins/with-nx.ts index fb3c7f4ac7302..0da1d723a8f8e 100644 --- a/packages/next/plugins/with-nx.ts +++ b/packages/next/plugins/with-nx.ts @@ -134,7 +134,7 @@ export function withNx( } = getNxContext(graph, originalTarget); const projectDirectory = projectNode.data.root; - if (!options.buildLibsFromSource && targetName) { + if (options.buildLibsFromSource === false && targetName) { const result = calculateProjectDependencies( graph, workspaceRoot, diff --git a/packages/next/src/utils/buildable-libs.ts b/packages/next/src/utils/buildable-libs.ts index a12ae0723dfe7..e69de29bb2d1d 100644 --- a/packages/next/src/utils/buildable-libs.ts +++ b/packages/next/src/utils/buildable-libs.ts @@ -1,30 +0,0 @@ -import { - DependentBuildableProjectNode, - findMissingBuildDependencies, -} from '@nrwl/workspace/src/utilities/buildable-libs-utils'; -import * as chalk from 'chalk'; -import { ExecutorContext, stripIndents } from '@nrwl/devkit'; - -export function assertDependentProjectsHaveBeenBuilt( - dependencies: DependentBuildableProjectNode[], - context: ExecutorContext -) { - const missing = findMissingBuildDependencies( - context.root, - context.projectName, - context.targetName, - dependencies - ); - if (missing.length > 0) { - throw new Error( - chalk.red(stripIndents` - Some of the project ${ - context.projectName - }'s dependencies have not been built yet. - - Please build these libraries first: - ${missing.map((x) => ` - ${x.node.name}`).join('\n')} - `) - ); - } -}