Skip to content

Commit 58cfaae

Browse files
authored
fix(core): nextjs-standalone generates package scripts consistent with create-next-app (#21996)
1 parent 42ad573 commit 58cfaae

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

packages/workspace/src/generators/new/__snapshots__/generate-workspace-files.spec.ts.snap

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,62 @@ It will show tasks that you can run with Nx.
17061706
"
17071707
`;
17081708

1709+
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for angular-standalone preset 1`] = `
1710+
{
1711+
"build": "nx build",
1712+
"start": "nx serve",
1713+
"test": "nx test",
1714+
}
1715+
`;
1716+
1717+
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for nextjs-standalone preset 1`] = `
1718+
{
1719+
"build": "nx build",
1720+
"dev": "nx dev",
1721+
"start": "nx start",
1722+
"test": "nx test",
1723+
}
1724+
`;
1725+
1726+
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for node-standalone preset 1`] = `
1727+
{
1728+
"build": "nx build",
1729+
"start": "nx serve",
1730+
"test": "nx test",
1731+
}
1732+
`;
1733+
1734+
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for nuxt-standalone preset 1`] = `
1735+
{
1736+
"build": "nx build",
1737+
"start": "nx serve",
1738+
"test": "nx test",
1739+
}
1740+
`;
1741+
1742+
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for react-standalone preset 1`] = `
1743+
{
1744+
"build": "nx build",
1745+
"start": "nx serve",
1746+
"test": "nx test",
1747+
}
1748+
`;
1749+
1750+
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for ts-standalone preset 1`] = `
1751+
{
1752+
"build": "nx build",
1753+
"test": "nx test",
1754+
}
1755+
`;
1756+
1757+
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for vue-standalone preset 1`] = `
1758+
{
1759+
"build": "nx build",
1760+
"start": "nx serve",
1761+
"test": "nx test",
1762+
}
1763+
`;
1764+
17091765
exports[`@nx/workspace:generateWorkspaceFiles should recommend vscode extensions (angular) 1`] = `
17101766
[
17111767
"nrwl.angular-console",

packages/workspace/src/generators/new/generate-workspace-files.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,25 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
230230
const pnpm = tree.read('/proj/pnpm-workspace.yaml').toString();
231231
expect(pnpm).toContain('packages/*');
232232
});
233+
234+
it.each([
235+
Preset.ReactStandalone,
236+
Preset.VueStandalone,
237+
Preset.NuxtStandalone,
238+
Preset.AngularStandalone,
239+
Preset.NodeStandalone,
240+
Preset.NextJsStandalone,
241+
Preset.TsStandalone,
242+
])('should create package scripts for %s preset', async (preset) => {
243+
await generateWorkspaceFiles(tree, {
244+
name: 'proj',
245+
directory: 'proj',
246+
preset,
247+
defaultBase: 'main',
248+
appName: 'demo',
249+
isCustomPreset: false,
250+
});
251+
252+
expect(readJson(tree, 'proj/package.json').scripts).toMatchSnapshot();
253+
});
233254
});

packages/workspace/src/generators/new/generate-workspace-files.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function setPresetProperty(tree: Tree, options: NormalizedSchema) {
5858
return json;
5959
});
6060
}
61+
6162
function createNxJson(
6263
tree: Tree,
6364
{ directory, defaultBase, preset }: NormalizedSchema
@@ -163,8 +164,7 @@ function addNpmScripts(tree: Tree, options: NormalizedSchema) {
163164
options.preset === Preset.ReactStandalone ||
164165
options.preset === Preset.VueStandalone ||
165166
options.preset === Preset.NuxtStandalone ||
166-
options.preset === Preset.NodeStandalone ||
167-
options.preset === Preset.NextJsStandalone
167+
options.preset === Preset.NodeStandalone
168168
) {
169169
updateJson(tree, join(options.directory, 'package.json'), (json) => {
170170
Object.assign(json.scripts, {
@@ -175,6 +175,17 @@ function addNpmScripts(tree: Tree, options: NormalizedSchema) {
175175
return json;
176176
});
177177
}
178+
if (options.preset === Preset.NextJsStandalone) {
179+
updateJson(tree, join(options.directory, 'package.json'), (json) => {
180+
Object.assign(json.scripts, {
181+
dev: 'nx dev',
182+
build: 'nx build',
183+
start: 'nx start',
184+
test: 'nx test',
185+
});
186+
return json;
187+
});
188+
}
178189
if (options.preset === Preset.TsStandalone) {
179190
updateJson(tree, join(options.directory, 'package.json'), (json) => {
180191
Object.assign(json.scripts, {

0 commit comments

Comments
 (0)