Skip to content

Commit 026d5c4

Browse files
committed
fix(cli): make the package.json and angular.json edits no-op when unchanged
ensureDevScript and angularProxyEdit re-serialized the whole file even when nothing needed adding, which reformatted the user's package.json/angular.json and made the edit op non-idempotent. Both now return the source untouched when the target value is already present, so the file-writer skips the file. Also reference vite.config.* / nuxt.config.* in the patcher summary messages.
1 parent 804672a commit 026d5c4

6 files changed

Lines changed: 23 additions & 8 deletions

File tree

apps/cli/src/lib/orca/patchers/rule/angular/angular-json.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,19 @@ export function angularProxyEdit(opts: {
6060
});
6161
}
6262
const options = isObject(serve.options) ? (serve.options as Record<string, unknown>) : {};
63+
let changed = false;
6364
if (options.proxyConfig === undefined) {
6465
options.proxyConfig = opts.proxyConfig;
66+
changed = true;
6567
}
6668
if (opts.port !== undefined && options.port === undefined) {
6769
options.port = opts.port;
70+
changed = true;
71+
}
72+
// Nothing to add — return the source untouched so the edit op skips it
73+
// instead of reformatting (re-indenting) the user's angular.json.
74+
if (!changed) {
75+
return source;
6876
}
6977
serve.options = options;
7078
// Preserve the user's key order (JSON, no comments) instead of sorting.

apps/cli/src/lib/orca/patchers/rule/angular/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ const SDK_DEPENDENCY = "@zitadel/sdk-angular";
1717
*/
1818
function ensureDevScript(source: string | undefined): string {
1919
const pkg: Record<string, unknown> = source ? parseJsonObject(source, "package.json") : {};
20-
const scripts: Record<string, unknown> = isObject(pkg.scripts) ? { ...pkg.scripts } : {};
21-
if (scripts.dev === undefined) {
22-
scripts.dev = "ng serve";
20+
const scripts = isObject(pkg.scripts) ? pkg.scripts : undefined;
21+
// Leave an existing dev script untouched, returning the source unchanged so
22+
// the edit op skips the file instead of reformatting the user's package.json.
23+
if (source !== undefined && scripts?.dev !== undefined) {
24+
return source;
2325
}
24-
pkg.scripts = scripts;
26+
pkg.scripts = { ...(scripts ?? {}), dev: "ng serve" };
2527
return `${stableStringify(pkg)}\n`;
2628
}
2729

apps/cli/src/lib/orca/patchers/rule/nuxt/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const NUXT_CONFIG_PATHS = configCandidates("nuxt.config");
2222
/**
2323
* Rule-based patcher for a Nuxt app. Like Next.js, Nuxt proxies the backend and
2424
* verifies the session through server middleware — here the `@zitadel/sdk-nuxt`
25-
* module, registered via a non-destructive `nuxt.config.ts` edit. Contributes
25+
* module, registered via a non-destructive `nuxt.config.*` edit. Contributes
2626
* the login/register/profile pages (the raw `<zitadel-login>`/`<zitadel-logout>`
2727
* elements), the client/server plugins, the `app.vue` router, and the SDK dep.
2828
*/
@@ -89,7 +89,7 @@ export class NuxtPatcher extends AbstractRulePatcher {
8989
return {
9090
title: "Nuxt integration",
9191
detail:
92-
"Wrote login/register/profile pages + plugins and registered @zitadel/sdk-nuxt in nuxt.config.ts.",
92+
"Wrote login/register/profile pages + plugins and registered @zitadel/sdk-nuxt in nuxt.config.*.",
9393
};
9494
}
9595
}

apps/cli/src/lib/orca/patchers/rule/react/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class ReactPatcher extends AbstractRulePatcher implements ViteSupport {
6363
return {
6464
title: "React (Vite) integration",
6565
detail:
66-
"Wrote src/App.tsx auth entry and merged the /__nextgen dev proxy into vite.config.ts.",
66+
"Wrote src/App.tsx auth entry and merged the /__nextgen dev proxy into vite.config.*.",
6767
};
6868
}
6969
}

apps/cli/src/lib/orca/patchers/rule/vue/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class VuePatcher extends AbstractRulePatcher implements ViteSupport {
5858
return {
5959
title: "Vue (Vite) integration",
6060
detail:
61-
"Wrote src/App.vue auth entry and merged the /__nextgen dev proxy into vite.config.ts.",
61+
"Wrote src/App.vue auth entry and merged the /__nextgen dev proxy into vite.config.*.",
6262
};
6363
}
6464
}

apps/cli/tests/unit/lib/orca/patchers/rule/angular/angular-json.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ describe("angularProxyEdit", () => {
2626
expect(JSON.parse(out).projects.app.architect.serve.options.proxyConfig).toBe("mine.cjs");
2727
});
2828

29+
it("returns the source untouched when proxyConfig and port are already set", () => {
30+
const once = edit(ng({ architect: { serve: { options: {} } } }));
31+
expect(edit(once)).toBe(once);
32+
});
33+
2934
it("resolves the project named by defaultProject", () => {
3035
const out = edit(
3136
JSON.stringify({

0 commit comments

Comments
 (0)