fix(core): nextjs-standalone generates package scripts consistent with create-next-app (#21996)

This commit is contained in:
Jack Hsu 2024-02-29 14:49:50 -05:00 committed by GitHub
parent 42ad573405
commit 58cfaae951
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 90 additions and 2 deletions

View File

@ -1706,6 +1706,62 @@ It will show tasks that you can run with Nx.
" "
`; `;
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for angular-standalone preset 1`] = `
{
"build": "nx build",
"start": "nx serve",
"test": "nx test",
}
`;
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for nextjs-standalone preset 1`] = `
{
"build": "nx build",
"dev": "nx dev",
"start": "nx start",
"test": "nx test",
}
`;
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for node-standalone preset 1`] = `
{
"build": "nx build",
"start": "nx serve",
"test": "nx test",
}
`;
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for nuxt-standalone preset 1`] = `
{
"build": "nx build",
"start": "nx serve",
"test": "nx test",
}
`;
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for react-standalone preset 1`] = `
{
"build": "nx build",
"start": "nx serve",
"test": "nx test",
}
`;
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for ts-standalone preset 1`] = `
{
"build": "nx build",
"test": "nx test",
}
`;
exports[`@nx/workspace:generateWorkspaceFiles should create package scripts for vue-standalone preset 1`] = `
{
"build": "nx build",
"start": "nx serve",
"test": "nx test",
}
`;
exports[`@nx/workspace:generateWorkspaceFiles should recommend vscode extensions (angular) 1`] = ` exports[`@nx/workspace:generateWorkspaceFiles should recommend vscode extensions (angular) 1`] = `
[ [
"nrwl.angular-console", "nrwl.angular-console",

View File

@ -230,4 +230,25 @@ describe('@nx/workspace:generateWorkspaceFiles', () => {
const pnpm = tree.read('/proj/pnpm-workspace.yaml').toString(); const pnpm = tree.read('/proj/pnpm-workspace.yaml').toString();
expect(pnpm).toContain('packages/*'); expect(pnpm).toContain('packages/*');
}); });
it.each([
Preset.ReactStandalone,
Preset.VueStandalone,
Preset.NuxtStandalone,
Preset.AngularStandalone,
Preset.NodeStandalone,
Preset.NextJsStandalone,
Preset.TsStandalone,
])('should create package scripts for %s preset', async (preset) => {
await generateWorkspaceFiles(tree, {
name: 'proj',
directory: 'proj',
preset,
defaultBase: 'main',
appName: 'demo',
isCustomPreset: false,
});
expect(readJson(tree, 'proj/package.json').scripts).toMatchSnapshot();
});
}); });

View File

@ -58,6 +58,7 @@ function setPresetProperty(tree: Tree, options: NormalizedSchema) {
return json; return json;
}); });
} }
function createNxJson( function createNxJson(
tree: Tree, tree: Tree,
{ directory, defaultBase, preset }: NormalizedSchema { directory, defaultBase, preset }: NormalizedSchema
@ -163,8 +164,7 @@ function addNpmScripts(tree: Tree, options: NormalizedSchema) {
options.preset === Preset.ReactStandalone || options.preset === Preset.ReactStandalone ||
options.preset === Preset.VueStandalone || options.preset === Preset.VueStandalone ||
options.preset === Preset.NuxtStandalone || options.preset === Preset.NuxtStandalone ||
options.preset === Preset.NodeStandalone || options.preset === Preset.NodeStandalone
options.preset === Preset.NextJsStandalone
) { ) {
updateJson(tree, join(options.directory, 'package.json'), (json) => { updateJson(tree, join(options.directory, 'package.json'), (json) => {
Object.assign(json.scripts, { Object.assign(json.scripts, {
@ -175,6 +175,17 @@ function addNpmScripts(tree: Tree, options: NormalizedSchema) {
return json; return json;
}); });
} }
if (options.preset === Preset.NextJsStandalone) {
updateJson(tree, join(options.directory, 'package.json'), (json) => {
Object.assign(json.scripts, {
dev: 'nx dev',
build: 'nx build',
start: 'nx start',
test: 'nx test',
});
return json;
});
}
if (options.preset === Preset.TsStandalone) { if (options.preset === Preset.TsStandalone) {
updateJson(tree, join(options.directory, 'package.json'), (json) => { updateJson(tree, join(options.directory, 'package.json'), (json) => {
Object.assign(json.scripts, { Object.assign(json.scripts, {