-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(nextjs): remove the need to install @nx/next for production builds
- Loading branch information
Showing
9 changed files
with
302 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/next/src/executors/build/lib/create-next-config-file.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { getWithNxContent } from './create-next-config-file'; | ||
import { stripIndents } from '@nx/devkit'; | ||
|
||
describe('Next.js config: getWithNxContent', () => { | ||
it('should swap distDir and getWithNxContext with static values', () => { | ||
const result = getWithNxContent({ | ||
withNxFile: `with-nx.js`, | ||
withNxContent: stripIndents` | ||
// SHOULD BE LEFT INTACT | ||
const constants = require("next/constants"); | ||
// TO BE SWAPPED | ||
function getWithNxContext() { | ||
const { workspaceRoot, workspaceLayout } = require('@nx/devkit'); | ||
return { | ||
workspaceRoot, | ||
libsDir: workspaceLayout().libsDir, | ||
}; | ||
} | ||
// SHOULD BE LEFT INTACT | ||
function withNx(nextConfig = {}, context = getWithNxContext()) { | ||
return (phase) => { | ||
if (phase === constants.PHASE_PRODUCTION_SERVER) { | ||
//... | ||
} else { | ||
// ... | ||
} | ||
}; | ||
} | ||
// SHOULD BE LEFT INTACT | ||
module.exports.withNx = withNx; | ||
`, | ||
}); | ||
|
||
expect(result).toContain(`const constants = require("next/constants")`); | ||
expect(result).toContain(stripIndents` | ||
// SHOULD BE LEFT INTACT | ||
function withNx(nextConfig = {}, context = getWithNxContext()) { | ||
return (phase) => { | ||
if (phase === constants.PHASE_PRODUCTION_SERVER) { | ||
//... | ||
} else { | ||
// ... | ||
} | ||
}; | ||
} | ||
// SHOULD BE LEFT INTACT | ||
module.exports.withNx = withNx; | ||
`); | ||
expect(result).not.toContain( | ||
`const { workspaceRoot, workspaceLayout } = require('@nx/devkit');` | ||
); | ||
expect(result).toContain(`libsDir: ''`); | ||
expect(result).not.toContain(`libsDir: workspaceLayout.libsDir()`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { NextConfig } from 'next'; | ||
import { composePlugins, NextConfigFn } from './compose-plugins'; | ||
|
||
describe('composePlugins', () => { | ||
it('should combine multiple plugins', async () => { | ||
const nextConfig: NextConfig = { | ||
env: { | ||
original: 'original', | ||
}, | ||
}; | ||
const a = (config: NextConfig): NextConfig => { | ||
config.env['a'] = 'a'; | ||
return config; | ||
}; | ||
const b = (config: NextConfig): NextConfig => { | ||
config.env['b'] = 'b'; | ||
return config; | ||
}; | ||
const fn = await composePlugins(a, b); | ||
const output = await fn(nextConfig)('test', {}); | ||
|
||
expect(output).toEqual({ | ||
env: { | ||
original: 'original', | ||
a: 'a', | ||
b: 'b', | ||
}, | ||
}); | ||
}); | ||
|
||
it('should compose plugins that return an async function', async () => { | ||
const nextConfig: NextConfig = { | ||
env: { | ||
original: 'original', | ||
}, | ||
}; | ||
const a = (config: NextConfig): NextConfig => { | ||
config.env['a'] = 'a'; | ||
return config; | ||
}; | ||
const b = (config: NextConfig): NextConfigFn => { | ||
return (phase: string) => { | ||
config.env['b'] = phase; | ||
return config; | ||
}; | ||
}; | ||
const fn = await composePlugins(a, b); | ||
const output = await fn(nextConfig)('test', {}); | ||
|
||
expect(output).toEqual({ | ||
env: { | ||
original: 'original', | ||
a: 'a', | ||
b: 'test', | ||
}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.