@openrewrite/recipes-angular 1.9.0 → 1.10.0-20260813-195315
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +84 -2
- package/dist/index.js.map +1 -1
- package/dist/migration/add-eager-change-detection.d.ts +8 -0
- package/dist/migration/add-eager-change-detection.d.ts.map +1 -0
- package/dist/migration/add-eager-change-detection.js +130 -0
- package/dist/migration/add-eager-change-detection.js.map +1 -0
- package/dist/migration/add-istanbul-instrumenter.d.ts +8 -0
- package/dist/migration/add-istanbul-instrumenter.d.ts.map +1 -0
- package/dist/migration/add-istanbul-instrumenter.js +80 -0
- package/dist/migration/add-istanbul-instrumenter.js.map +1 -0
- package/dist/migration/add-no-incremental-hydration.d.ts +8 -0
- package/dist/migration/add-no-incremental-hydration.d.ts.map +1 -0
- package/dist/migration/add-no-incremental-hydration.js +69 -0
- package/dist/migration/add-no-incremental-hydration.js.map +1 -0
- package/dist/migration/add-strict-templates-false.d.ts +8 -0
- package/dist/migration/add-strict-templates-false.d.ts.map +1 -0
- package/dist/migration/add-strict-templates-false.js +84 -0
- package/dist/migration/add-strict-templates-false.js.map +1 -0
- package/dist/migration/add-trust-proxy-headers.d.ts +8 -0
- package/dist/migration/add-trust-proxy-headers.d.ts.map +1 -0
- package/dist/migration/add-trust-proxy-headers.js +82 -0
- package/dist/migration/add-trust-proxy-headers.js.map +1 -0
- package/dist/migration/add-with-xhr.d.ts +8 -0
- package/dist/migration/add-with-xhr.d.ts.map +1 -0
- package/dist/migration/add-with-xhr.js +70 -0
- package/dist/migration/add-with-xhr.js.map +1 -0
- package/dist/migration/js-support.d.ts +6 -0
- package/dist/migration/js-support.d.ts.map +1 -0
- package/dist/migration/js-support.js +94 -0
- package/dist/migration/js-support.js.map +1 -0
- package/dist/migration/json-support.d.ts +19 -0
- package/dist/migration/json-support.d.ts.map +1 -0
- package/dist/migration/json-support.js +117 -0
- package/dist/migration/json-support.js.map +1 -0
- package/dist/migration/migrate-input-to-signal.d.ts.map +1 -1
- package/dist/migration/migrate-input-to-signal.js +3 -67
- package/dist/migration/migrate-input-to-signal.js.map +1 -1
- package/dist/migration/migrate-model-with-output.d.ts +8 -0
- package/dist/migration/migrate-model-with-output.d.ts.map +1 -0
- package/dist/migration/migrate-model-with-output.js +192 -0
- package/dist/migration/migrate-model-with-output.js.map +1 -0
- package/dist/migration/remove-with-fetch.d.ts +8 -0
- package/dist/migration/remove-with-fetch.d.ts.map +1 -0
- package/dist/migration/remove-with-fetch.js +73 -0
- package/dist/migration/remove-with-fetch.js.map +1 -0
- package/dist/migration/rename-angular-js-globals.d.ts +8 -0
- package/dist/migration/rename-angular-js-globals.d.ts.map +1 -0
- package/dist/migration/rename-angular-js-globals.js +56 -0
- package/dist/migration/rename-angular-js-globals.js.map +1 -0
- package/dist/migration/rename-default-change-detection.d.ts +8 -0
- package/dist/migration/rename-default-change-detection.d.ts.map +1 -0
- package/dist/migration/rename-default-change-detection.js +52 -0
- package/dist/migration/rename-default-change-detection.js.map +1 -0
- package/dist/migration/rename-ssr-experimental-platform.d.ts +8 -0
- package/dist/migration/rename-ssr-experimental-platform.d.ts.map +1 -0
- package/dist/migration/rename-ssr-experimental-platform.js +124 -0
- package/dist/migration/rename-ssr-experimental-platform.js.map +1 -0
- package/dist/migration/replace-create-ng-module-ref.d.ts +8 -0
- package/dist/migration/replace-create-ng-module-ref.d.ts.map +1 -0
- package/dist/migration/replace-create-ng-module-ref.js +51 -0
- package/dist/migration/replace-create-ng-module-ref.js.map +1 -0
- package/dist/migration/suppress-safe-navigation-diagnostics.d.ts +8 -0
- package/dist/migration/suppress-safe-navigation-diagnostics.d.ts.map +1 -0
- package/dist/migration/suppress-safe-navigation-diagnostics.js +55 -0
- package/dist/migration/suppress-safe-navigation-diagnostics.js.map +1 -0
- package/dist/migration/upgrade-to-angular-22.d.ts +14 -0
- package/dist/migration/upgrade-to-angular-22.d.ts.map +1 -0
- package/dist/migration/upgrade-to-angular-22.js +112 -0
- package/dist/migration/upgrade-to-angular-22.js.map +1 -0
- package/dist/search/find-can-match-usage.d.ts +8 -0
- package/dist/search/find-can-match-usage.d.ts.map +1 -0
- package/dist/search/find-can-match-usage.js +53 -0
- package/dist/search/find-can-match-usage.js.map +1 -0
- package/dist/search/find-check-no-changes-usage.d.ts +8 -0
- package/dist/search/find-check-no-changes-usage.d.ts.map +1 -0
- package/dist/search/find-check-no-changes-usage.js +50 -0
- package/dist/search/find-check-no-changes-usage.js.map +1 -0
- package/dist/search/find-http-xhr-backend-usage.d.ts +8 -0
- package/dist/search/find-http-xhr-backend-usage.d.ts.map +1 -0
- package/dist/search/find-http-xhr-backend-usage.js +65 -0
- package/dist/search/find-http-xhr-backend-usage.js.map +1 -0
- package/dist/search/find-implicit-params-inheritance.d.ts +8 -0
- package/dist/search/find-implicit-params-inheritance.d.ts.map +1 -0
- package/dist/search/find-implicit-params-inheritance.js +74 -0
- package/dist/search/find-implicit-params-inheritance.js.map +1 -0
- package/dist/search/find-provide-routes-usage.d.ts +8 -0
- package/dist/search/find-provide-routes-usage.d.ts.map +1 -0
- package/dist/search/find-provide-routes-usage.js +64 -0
- package/dist/search/find-provide-routes-usage.js.map +1 -0
- package/dist/search/find-template-safe-navigation.d.ts +8 -0
- package/dist/search/find-template-safe-navigation.d.ts.map +1 -0
- package/dist/search/find-template-safe-navigation.js +105 -0
- package/dist/search/find-template-safe-navigation.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +60 -0
- package/src/migration/add-eager-change-detection.ts +109 -0
- package/src/migration/add-istanbul-instrumenter.ts +62 -0
- package/src/migration/add-no-incremental-hydration.ts +49 -0
- package/src/migration/add-strict-templates-false.ts +62 -0
- package/src/migration/add-trust-proxy-headers.ts +61 -0
- package/src/migration/add-with-xhr.ts +50 -0
- package/src/migration/js-support.ts +92 -0
- package/src/migration/json-support.ts +119 -0
- package/src/migration/migrate-input-to-signal.ts +1 -67
- package/src/migration/migrate-model-with-output.ts +201 -0
- package/src/migration/remove-with-fetch.ts +53 -0
- package/src/migration/rename-angular-js-globals.ts +37 -0
- package/src/migration/rename-default-change-detection.ts +33 -0
- package/src/migration/rename-ssr-experimental-platform.ts +108 -0
- package/src/migration/replace-create-ng-module-ref.ts +32 -0
- package/src/migration/suppress-safe-navigation-diagnostics.ts +42 -0
- package/src/migration/upgrade-to-angular-22.ts +92 -0
- package/src/search/find-can-match-usage.ts +32 -0
- package/src/search/find-check-no-changes-usage.ts +29 -0
- package/src/search/find-http-xhr-backend-usage.ts +44 -0
- package/src/search/find-implicit-params-inheritance.ts +49 -0
- package/src/search/find-provide-routes-usage.ts +43 -0
- package/src/search/find-template-safe-navigation.ts +72 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 the original author or authors.
|
|
4
|
+
*
|
|
5
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AddNoIncrementalHydration = void 0;
|
|
18
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
19
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
20
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
21
|
+
const HYDRATION_FEATURES = ['withIncrementalHydration', 'withNoIncrementalHydration'];
|
|
22
|
+
class AddNoIncrementalHydration extends rewrite_1.Recipe {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this.name = "org.openrewrite.angular.migration.add-no-incremental-hydration";
|
|
26
|
+
this.displayName = "Add `withNoIncrementalHydration()` to `provideClientHydration()`";
|
|
27
|
+
this.description = "Adds the `withNoIncrementalHydration()` opt out to `provideClientHydration()` calls that do not " +
|
|
28
|
+
"already configure incremental hydration. Angular 22 enables incremental hydration by default; the opt out retains the previous behavior.";
|
|
29
|
+
}
|
|
30
|
+
editor() {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
33
|
+
visitMethodInvocation(method, p) {
|
|
34
|
+
const _super = Object.create(null, {
|
|
35
|
+
visitMethodInvocation: { get: () => super.visitMethodInvocation }
|
|
36
|
+
});
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
const m = yield _super.visitMethodInvocation.call(this, method, p);
|
|
40
|
+
if (!m || m.name.simpleName !== 'provideClientHydration')
|
|
41
|
+
return m;
|
|
42
|
+
const elements = ((_b = (_a = m.arguments) === null || _a === void 0 ? void 0 : _a.elements) !== null && _b !== void 0 ? _b : []).filter(rp => rp.element.kind !== java_1.J.Kind.Empty);
|
|
43
|
+
if (elements.some(rp => isHydrationFeatureCall(rp.element)))
|
|
44
|
+
return m;
|
|
45
|
+
(0, javascript_1.maybeAddImport)(this, {
|
|
46
|
+
module: '@angular/platform-browser',
|
|
47
|
+
member: 'withNoIncrementalHydration',
|
|
48
|
+
onlyIfReferenced: false
|
|
49
|
+
});
|
|
50
|
+
let builder = javascript_1.Template.builder().code('provideClientHydration(');
|
|
51
|
+
for (const element of elements) {
|
|
52
|
+
builder = builder.param(element.element).code(', ');
|
|
53
|
+
}
|
|
54
|
+
const t = builder.code('withNoIncrementalHydration())').build();
|
|
55
|
+
return yield t.apply(m, this.cursor);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}();
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.AddNoIncrementalHydration = AddNoIncrementalHydration;
|
|
63
|
+
function isHydrationFeatureCall(expression) {
|
|
64
|
+
if (expression.kind !== java_1.J.Kind.MethodInvocation)
|
|
65
|
+
return false;
|
|
66
|
+
const invocation = expression;
|
|
67
|
+
return (0, java_1.isIdentifier)(invocation.name) && HYDRATION_FEATURES.includes(invocation.name.simpleName);
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=add-no-incremental-hydration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-no-incremental-hydration.js","sourceRoot":"","sources":["../../src/migration/add-no-incremental-hydration.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;AAEH,kDAA2E;AAC3E,gEAA4F;AAC5F,oDAA0D;AAE1D,MAAM,kBAAkB,GAAG,CAAC,0BAA0B,EAAE,4BAA4B,CAAC,CAAC;AAEtF,MAAa,yBAA0B,SAAQ,gBAAM;IAArD;;QACa,SAAI,GAAG,gEAAgE,CAAC;QACxE,gBAAW,GAAW,kEAAkE,CAAC;QACzF,gBAAW,GAAW,kGAAkG;YAC7H,0IAA0I,CAAC;IA0BnJ,CAAC;IAxBS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBACzC,qBAAqB,CAAC,MAA0B,EAAE,CAAmB;;;;;;wBAChF,MAAM,CAAC,GAAG,MAAM,OAAM,qBAAqB,YAAC,MAAM,EAAE,CAAC,CAAuB,CAAC;wBAC7E,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,KAAK,wBAAwB;4BAAE,OAAO,CAAC,CAAC;wBAEnE,MAAM,QAAQ,GAAG,CAAC,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IAAI,CAAC,UAAU,CAAC,CAAC;AACpG,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class AddStrictTemplatesFalse extends Recipe {
|
|
3
|
+
readonly name = "org.openrewrite.angular.migration.add-strict-templates-false";
|
|
4
|
+
readonly displayName: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=add-strict-templates-false.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-strict-templates-false.d.ts","sourceRoot":"","sources":["../../src/migration/add-strict-templates-false.ts"],"names":[],"mappings":"AAMA,OAAO,EAAe,gBAAgB,EAAY,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAInG,qBAAa,uBAAwB,SAAQ,MAAM;IAC/C,QAAQ,CAAC,IAAI,kEAAkE;IAC/E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAqD;IACjF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAC8F;IAEpH,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA6C9D"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 the original author or authors.
|
|
4
|
+
*
|
|
5
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AddStrictTemplatesFalse = void 0;
|
|
18
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
19
|
+
const json_1 = require("@openrewrite/rewrite/json");
|
|
20
|
+
const json_support_1 = require("./json-support");
|
|
21
|
+
class AddStrictTemplatesFalse extends rewrite_1.Recipe {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...arguments);
|
|
24
|
+
this.name = "org.openrewrite.angular.migration.add-strict-templates-false";
|
|
25
|
+
this.displayName = "Add `strictTemplates: false` to `tsconfig.json`";
|
|
26
|
+
this.description = "Adds `\"strictTemplates\": false` to `angularCompilerOptions` in `tsconfig.json` when the option is not set. " +
|
|
27
|
+
"Angular 22 turned strict template type checking on by default; setting it explicitly avoids new compilation errors.";
|
|
28
|
+
}
|
|
29
|
+
editor() {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
return new class extends json_1.JsonVisitor {
|
|
32
|
+
constructor() {
|
|
33
|
+
super(...arguments);
|
|
34
|
+
this.baseIndent = ' ';
|
|
35
|
+
}
|
|
36
|
+
visitDocument(doc, p) {
|
|
37
|
+
const _super = Object.create(null, {
|
|
38
|
+
visitDocument: { get: () => super.visitDocument }
|
|
39
|
+
});
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
this.baseIndent = (0, json_1.detectIndent)(doc);
|
|
42
|
+
if ((0, json_support_1.declaresAngularCompilerOptions)(doc))
|
|
43
|
+
return _super.visitDocument.call(this, doc, p);
|
|
44
|
+
if (!(0, json_support_1.isRootTsconfig)(doc.sourcePath))
|
|
45
|
+
return doc;
|
|
46
|
+
const root = doc.value;
|
|
47
|
+
if (!(0, json_1.isObject)(root))
|
|
48
|
+
return doc;
|
|
49
|
+
const indent = (0, json_support_1.memberIndent)(root, this.baseIndent);
|
|
50
|
+
const newMember = (0, json_support_1.buildMember)('angularCompilerOptions', {
|
|
51
|
+
kind: json_1.Json.Kind.Object,
|
|
52
|
+
id: (0, rewrite_1.randomId)(),
|
|
53
|
+
prefix: (0, json_1.space)(' '),
|
|
54
|
+
markers: rewrite_1.emptyMarkers,
|
|
55
|
+
members: [(0, json_1.rightPadded)((0, json_support_1.buildMember)('strictTemplates', (0, json_support_1.literal)('false', false), '\n' + indent + this.baseIndent), (0, json_1.space)('\n' + indent))],
|
|
56
|
+
}, '\n' + indent);
|
|
57
|
+
return Object.assign(Object.assign({}, doc), { value: (0, json_support_1.appendMember)(root, newMember, '\n') });
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
visitMember(member, p) {
|
|
61
|
+
const _super = Object.create(null, {
|
|
62
|
+
visitMember: { get: () => super.visitMember }
|
|
63
|
+
});
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
const m = yield _super.visitMember.call(this, member, p);
|
|
66
|
+
if (!m)
|
|
67
|
+
return m;
|
|
68
|
+
if ((0, json_1.getMemberKeyName)(m) !== 'angularCompilerOptions' || !(0, json_1.isObject)(m.value))
|
|
69
|
+
return m;
|
|
70
|
+
const options = m.value;
|
|
71
|
+
const hasStrictTemplates = options.members.some(rp => (0, json_1.isMember)(rp.element) && (0, json_1.getMemberKeyName)(rp.element) === 'strictTemplates');
|
|
72
|
+
if (hasStrictTemplates)
|
|
73
|
+
return m;
|
|
74
|
+
const indent = (0, json_support_1.memberIndent)(options, this.baseIndent.repeat(2));
|
|
75
|
+
const newMember = (0, json_support_1.buildMember)('strictTemplates', (0, json_support_1.literal)('false', false), '\n' + indent);
|
|
76
|
+
return Object.assign(Object.assign({}, m), { value: (0, json_support_1.appendMember)(options, newMember, '\n' + this.baseIndent) });
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.AddStrictTemplatesFalse = AddStrictTemplatesFalse;
|
|
84
|
+
//# sourceMappingURL=add-strict-templates-false.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-strict-templates-false.js","sourceRoot":"","sources":["../../src/migration/add-strict-templates-false.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;AAEH,kDAAmG;AACnG,oDAAoI;AACpI,iDAAgI;AAEhI,MAAa,uBAAwB,SAAQ,gBAAM;IAAnD;;QACa,SAAI,GAAG,8DAA8D,CAAC;QACtE,gBAAW,GAAW,iDAAiD,CAAC;QACxE,gBAAW,GAAW,+GAA+G;YAC1I,qHAAqH,CAAC;IA+C9H,CAAC;IA7CS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,kBAA6B;gBAA3C;;oBACC,eAAU,GAAG,IAAI,CAAC;gBAyC9B,CAAC;gBAvCmB,aAAa,CAAC,GAAkB,EAAE,CAAmB;;;;;wBACjE,IAAI,CAAC,UAAU,GAAG,IAAA,mBAAY,EAAC,GAAG,CAAC,CAAC;wBAEpC,IAAI,IAAA,6CAA8B,EAAC,GAAG,CAAC;4BAAE,OAAO,OAAM,aAAa,YAAC,GAAG,EAAE,CAAC,EAAE;wBAC5E,IAAI,CAAC,IAAA,6BAAc,EAAC,GAAG,CAAC,UAAU,CAAC;4BAAE,OAAO,GAAG,CAAC;wBAEhD,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC;wBACvB,IAAI,CAAC,IAAA,eAAQ,EAAC,IAAI,CAAC;4BAAE,OAAO,GAAG,CAAC;wBAEhC,MAAM,MAAM,GAAG,IAAA,2BAAY,EAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;wBACnD,MAAM,SAAS,GAAG,IAAA,0BAAW,EAAC,wBAAwB,EAAE;4BACpD,IAAI,EAAE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AAO,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;wBAChE,MAAM,SAAS,GAAG,IAAA,0BAAW,EAAC,iBAAiB,EAAE,IAAA,sBAAO,EAAC,OAAO,EAAE,KAAK,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC,CAAC;wBAEzF,OAAO,gCAAI,CAAC,KAAE,KAAK,EAAE,IAAA,2BAAY,EAAC,OAAO,EAAE,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAgB,CAAC;oBAClG,CAAC;iBAAA;aACJ,EAAE,CAAC;QACR,CAAC;KAAA;CACJ;AAnDD,0DAmDC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ExecutionContext, Recipe, TreeVisitor } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class AddTrustProxyHeaders extends Recipe {
|
|
3
|
+
readonly name = "org.openrewrite.angular.migration.add-trust-proxy-headers";
|
|
4
|
+
readonly displayName: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=add-trust-proxy-headers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-trust-proxy-headers.d.ts","sourceRoot":"","sources":["../../src/migration/add-trust-proxy-headers.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAS3E,qBAAa,oBAAqB,SAAQ,MAAM;IAC5C,QAAQ,CAAC,IAAI,+DAA+D;IAC5E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAuD;IACnF,QAAQ,CAAC,WAAW,EAAE,MAAM,CAGe;IAErC,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CA0B9D"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 the original author or authors.
|
|
4
|
+
*
|
|
5
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AddTrustProxyHeaders = void 0;
|
|
18
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
19
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
20
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
21
|
+
const APP_ENGINES = ['AngularNodeAppEngine', 'AngularAppEngine'];
|
|
22
|
+
const TODO_COMMENT = "// TODO: This is a security-sensitive option. Remove if not needed. " +
|
|
23
|
+
"For more information, see https://angular.dev/best-practices/security#configuring-trusted-proxy-headers";
|
|
24
|
+
class AddTrustProxyHeaders extends rewrite_1.Recipe {
|
|
25
|
+
constructor() {
|
|
26
|
+
super(...arguments);
|
|
27
|
+
this.name = "org.openrewrite.angular.migration.add-trust-proxy-headers";
|
|
28
|
+
this.displayName = "Add `trustProxyHeaders` to the Angular app engine";
|
|
29
|
+
this.description = "Adds `trustProxyHeaders: ['x-forwarded-host', 'x-forwarded-proto']` to " +
|
|
30
|
+
"`new AngularNodeAppEngine()` and `new AngularAppEngine()`. Angular 22 stopped trusting forwarded headers " +
|
|
31
|
+
"by default; the option restores the previous behavior and carries a TODO to remove it when the server " +
|
|
32
|
+
"does not sit behind a trusted proxy.";
|
|
33
|
+
}
|
|
34
|
+
editor() {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
37
|
+
visitNewClass(newClass, p) {
|
|
38
|
+
const _super = Object.create(null, {
|
|
39
|
+
visitNewClass: { get: () => super.visitNewClass }
|
|
40
|
+
});
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
var _a, _b, _c, _d;
|
|
43
|
+
const n = yield _super.visitNewClass.call(this, newClass, p);
|
|
44
|
+
if (!n || !n.class || !(0, java_1.isIdentifier)(n.class) || !APP_ENGINES.includes(n.class.simpleName))
|
|
45
|
+
return n;
|
|
46
|
+
const args = ((_b = (_a = n.arguments) === null || _a === void 0 ? void 0 : _a.elements) !== null && _b !== void 0 ? _b : []).filter(rp => rp.element.kind !== java_1.J.Kind.Empty);
|
|
47
|
+
if (args.length > 1)
|
|
48
|
+
return n;
|
|
49
|
+
const options = args.length === 1 ? args[0].element : undefined;
|
|
50
|
+
if (options && options.kind !== java_1.J.Kind.NewClass)
|
|
51
|
+
return n;
|
|
52
|
+
if (options && declaresTrustProxyHeaders(options))
|
|
53
|
+
return n;
|
|
54
|
+
const engine = n.class.simpleName;
|
|
55
|
+
const existing = (_d = (_c = options === null || options === void 0 ? void 0 : options.body) === null || _c === void 0 ? void 0 : _c.statements.filter(rp => rp.element.kind !== java_1.J.Kind.Empty)) !== null && _d !== void 0 ? _d : [];
|
|
56
|
+
let builder = javascript_1.Template.builder().code(`new ${engine}({\n ${TODO_COMMENT}\n trustProxyHeaders: ['x-forwarded-host', 'x-forwarded-proto'],`);
|
|
57
|
+
for (const statement of existing) {
|
|
58
|
+
builder = builder.code('\n ').param(statement.element).code(',');
|
|
59
|
+
}
|
|
60
|
+
const t = builder.code('\n})').build();
|
|
61
|
+
return yield t.apply(n, this.cursor);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.AddTrustProxyHeaders = AddTrustProxyHeaders;
|
|
69
|
+
function declaresTrustProxyHeaders(options) {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
return ((_b = (_a = options.body) === null || _a === void 0 ? void 0 : _a.statements) !== null && _b !== void 0 ? _b : []).some(rp => {
|
|
72
|
+
const element = rp.element;
|
|
73
|
+
// A spread may supply the option from elsewhere, which we cannot see from here
|
|
74
|
+
if (element.kind === javascript_1.JS.Kind.Spread)
|
|
75
|
+
return true;
|
|
76
|
+
if (element.kind !== javascript_1.JS.Kind.PropertyAssignment)
|
|
77
|
+
return false;
|
|
78
|
+
const name = element.name.element;
|
|
79
|
+
return (0, java_1.isIdentifier)(name) && name.simpleName === 'trustProxyHeaders';
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=add-trust-proxy-headers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-trust-proxy-headers.js","sourceRoot":"","sources":["../../src/migration/add-trust-proxy-headers.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;AAEH,kDAA2E;AAC3E,gEAAgF;AAChF,oDAA0D;AAE1D,MAAM,WAAW,GAAG,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,CAAC;AAEjE,MAAM,YAAY,GAAG,sEAAsE;IACvF,yGAAyG,CAAC;AAE9G,MAAa,oBAAqB,SAAQ,gBAAM;IAAhD;;QACa,SAAI,GAAG,2DAA2D,CAAC;QACnE,gBAAW,GAAW,mDAAmD,CAAC;QAC1E,gBAAW,GAAW,yEAAyE;YACpG,2GAA2G;YAC3G,wGAAwG;YACxG,sCAAsC,CAAC;IA4B/C,CAAC;IA1BS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8B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or } from "@openrewrite/rewrite";
|
|
2
|
+
export declare class AddWithXhr extends Recipe {
|
|
3
|
+
readonly name = "org.openrewrite.angular.migration.add-with-xhr";
|
|
4
|
+
readonly displayName: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
editor(): Promise<TreeVisitor<any, ExecutionContext>>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=add-with-xhr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-with-xhr.d.ts","sourceRoot":"","sources":["../../src/migration/add-with-xhr.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAM3E,qBAAa,UAAW,SAAQ,MAAM;IAClC,QAAQ,CAAC,IAAI,oDAAoD;IACjE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAA8C;IAC1E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAEmE;IAEzF,MAAM,IAAI,OAAO,CAAC,WAAW,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;CAwB9D"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 the original author or authors.
|
|
4
|
+
*
|
|
5
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
6
|
+
*/
|
|
7
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.AddWithXhr = void 0;
|
|
18
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
19
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
20
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
21
|
+
const BACKEND_FEATURES = ['withFetch', 'withXhr'];
|
|
22
|
+
class AddWithXhr extends rewrite_1.Recipe {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(...arguments);
|
|
25
|
+
this.name = "org.openrewrite.angular.migration.add-with-xhr";
|
|
26
|
+
this.displayName = "Add `withXhr()` to `provideHttpClient()`";
|
|
27
|
+
this.description = "Adds `withXhr()` to `provideHttpClient()` calls that select neither a `withFetch()` nor a " +
|
|
28
|
+
"`withXhr()` backend. Angular 22 made `FetchBackend` the default `HttpBackend`; `withXhr()` keeps the previous " +
|
|
29
|
+
"`XMLHttpRequest` based backend, which is also the only one that reports upload progress.";
|
|
30
|
+
}
|
|
31
|
+
editor() {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return new class extends javascript_1.JavaScriptVisitor {
|
|
34
|
+
visitMethodInvocation(method, p) {
|
|
35
|
+
const _super = Object.create(null, {
|
|
36
|
+
visitMethodInvocation: { get: () => super.visitMethodInvocation }
|
|
37
|
+
});
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
const m = yield _super.visitMethodInvocation.call(this, method, p);
|
|
41
|
+
if (!m || m.select || !(0, java_1.isIdentifier)(m.name) || m.name.simpleName !== 'provideHttpClient')
|
|
42
|
+
return m;
|
|
43
|
+
const elements = ((_b = (_a = m.arguments) === null || _a === void 0 ? void 0 : _a.elements) !== null && _b !== void 0 ? _b : []).filter(rp => rp.element.kind !== java_1.J.Kind.Empty);
|
|
44
|
+
if (elements.some(rp => isBackendFeatureCall(rp.element)))
|
|
45
|
+
return m;
|
|
46
|
+
(0, javascript_1.maybeAddImport)(this, {
|
|
47
|
+
module: '@angular/common/http',
|
|
48
|
+
member: 'withXhr',
|
|
49
|
+
onlyIfReferenced: false
|
|
50
|
+
});
|
|
51
|
+
let builder = javascript_1.Template.builder().code('provideHttpClient(');
|
|
52
|
+
for (const element of elements) {
|
|
53
|
+
builder = builder.param(element.element).code(', ');
|
|
54
|
+
}
|
|
55
|
+
const t = builder.code('withXhr())').build();
|
|
56
|
+
return yield t.apply(m, this.cursor);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.AddWithXhr = AddWithXhr;
|
|
64
|
+
function isBackendFeatureCall(expression) {
|
|
65
|
+
if (expression.kind !== java_1.J.Kind.MethodInvocation)
|
|
66
|
+
return false;
|
|
67
|
+
const invocation = expression;
|
|
68
|
+
return !invocation.select && (0, java_1.isIdentifier)(invocation.name) && BACKEND_FEATURES.includes(invocation.name.simpleName);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=add-with-xhr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-with-xhr.js","sourceRoot":"","sources":["../../src/migration/add-with-xhr.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;AAEH,kDAA2E;AAC3E,gEAA4F;AAC5F,oDAA0D;AAE1D,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;AAElD,MAAa,UAAW,SAAQ,gBAAM;IAAtC;;QACa,SAAI,GAAG,gDAAgD,CAAC;QACxD,gBAAW,GAAW,0CAA0C,CAAC;QACjE,gBAAW,GAAW,4FAA4F;YACvH,gHAAgH;YAChH,0FAA0F,CAAC;IA0BnG,CAAC;IAxBS,MAAM;;YACR,OAAO,IAAI,KAAM,SAAQ,8BAAmC;gBACzC,qBAAqB,CAAC,MAA0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ACJ,EAAE,CAAC;QACR,CAAC;KAAA;CACJ;AA/BD,gCA+BC;AAED,SAAS,oBAAoB,CAAC,UAAa;IACvC,IAAI,UAAU,CAAC,IAAI,KAAK,QAAC,CAAC,IAAI,CAAC,gBAAgB;QAAE,OAAO,KAAK,CAAC;IAC9D,MAAM,UAAU,GAAG,UAAgC,CAAC;IACpD,OAAO,CAAC,UAAU,CAAC,MAAM,IAAI,IAAA,mBAAY,EAAC,UAAU,CAAC,IAAI,CAAC,IAAI,gBAAgB,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACxH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { J } from "@openrewrite/rewrite/java";
|
|
2
|
+
export declare function buildPropertyAssignment(key: string, value: string): any;
|
|
3
|
+
export declare function buildOptionsObject(properties: any[]): any;
|
|
4
|
+
export declare function identifier(simpleName: string, prefix?: J.Space): J.Identifier;
|
|
5
|
+
export declare function rightPadded<T>(element: T, prefix?: J.Space): any;
|
|
6
|
+
//# sourceMappingURL=js-support.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-support.d.ts","sourceRoot":"","sources":["../../src/migration/js-support.ts"],"names":[],"mappings":"AAQA,OAAO,EAAa,CAAC,EAAc,MAAM,2BAA2B,CAAC;AAErE,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,CAgCvE;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,GAAG,EAAE,GAAG,GAAG,CA+BzD;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,UAAa,GAAG,CAAC,CAAC,UAAU,CAUhF;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,UAAa,GAAG,GAAG,CAEnE"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 the original author or authors.
|
|
4
|
+
*
|
|
5
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.buildPropertyAssignment = buildPropertyAssignment;
|
|
9
|
+
exports.buildOptionsObject = buildOptionsObject;
|
|
10
|
+
exports.identifier = identifier;
|
|
11
|
+
exports.rightPadded = rightPadded;
|
|
12
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
13
|
+
const javascript_1 = require("@openrewrite/rewrite/javascript");
|
|
14
|
+
const java_1 = require("@openrewrite/rewrite/java");
|
|
15
|
+
function buildPropertyAssignment(key, value) {
|
|
16
|
+
return {
|
|
17
|
+
kind: javascript_1.JS.Kind.PropertyAssignment,
|
|
18
|
+
id: (0, rewrite_1.randomId)(),
|
|
19
|
+
prefix: java_1.singleSpace,
|
|
20
|
+
markers: rewrite_1.emptyMarkers,
|
|
21
|
+
name: {
|
|
22
|
+
kind: java_1.J.Kind.RightPadded,
|
|
23
|
+
element: {
|
|
24
|
+
kind: java_1.J.Kind.Identifier,
|
|
25
|
+
id: (0, rewrite_1.randomId)(),
|
|
26
|
+
prefix: java_1.emptySpace,
|
|
27
|
+
markers: rewrite_1.emptyMarkers,
|
|
28
|
+
simpleName: key,
|
|
29
|
+
annotations: [],
|
|
30
|
+
type: undefined,
|
|
31
|
+
},
|
|
32
|
+
after: java_1.emptySpace,
|
|
33
|
+
markers: rewrite_1.emptyMarkers,
|
|
34
|
+
},
|
|
35
|
+
assigmentToken: 'Colon',
|
|
36
|
+
initializer: {
|
|
37
|
+
kind: java_1.J.Kind.Literal,
|
|
38
|
+
id: (0, rewrite_1.randomId)(),
|
|
39
|
+
prefix: java_1.singleSpace,
|
|
40
|
+
markers: rewrite_1.emptyMarkers,
|
|
41
|
+
value: value,
|
|
42
|
+
valueSource: `'${value}'`,
|
|
43
|
+
unicodeEscapes: undefined,
|
|
44
|
+
type: undefined,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function buildOptionsObject(properties) {
|
|
49
|
+
return {
|
|
50
|
+
kind: java_1.J.Kind.NewClass,
|
|
51
|
+
id: (0, rewrite_1.randomId)(),
|
|
52
|
+
prefix: java_1.emptySpace,
|
|
53
|
+
markers: rewrite_1.emptyMarkers,
|
|
54
|
+
enclosing: undefined,
|
|
55
|
+
new: java_1.emptySpace,
|
|
56
|
+
clazz: undefined,
|
|
57
|
+
arguments: {
|
|
58
|
+
kind: 'org.openrewrite.java.tree.JContainer',
|
|
59
|
+
before: java_1.emptySpace,
|
|
60
|
+
markers: rewrite_1.emptyMarkers,
|
|
61
|
+
elements: [],
|
|
62
|
+
},
|
|
63
|
+
body: {
|
|
64
|
+
kind: java_1.J.Kind.Block,
|
|
65
|
+
id: (0, rewrite_1.randomId)(),
|
|
66
|
+
prefix: java_1.emptySpace,
|
|
67
|
+
markers: rewrite_1.emptyMarkers,
|
|
68
|
+
static: { kind: java_1.J.Kind.RightPadded, element: false, after: java_1.emptySpace, markers: rewrite_1.emptyMarkers },
|
|
69
|
+
statements: properties.map(p => ({
|
|
70
|
+
kind: java_1.J.Kind.RightPadded,
|
|
71
|
+
element: p,
|
|
72
|
+
after: java_1.emptySpace,
|
|
73
|
+
markers: rewrite_1.emptyMarkers,
|
|
74
|
+
})),
|
|
75
|
+
end: java_1.singleSpace,
|
|
76
|
+
},
|
|
77
|
+
constructorType: undefined,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
function identifier(simpleName, prefix = java_1.emptySpace) {
|
|
81
|
+
return {
|
|
82
|
+
kind: java_1.J.Kind.Identifier,
|
|
83
|
+
id: (0, rewrite_1.randomId)(),
|
|
84
|
+
prefix,
|
|
85
|
+
markers: rewrite_1.emptyMarkers,
|
|
86
|
+
simpleName,
|
|
87
|
+
annotations: [],
|
|
88
|
+
type: undefined,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
function rightPadded(element, prefix = java_1.emptySpace) {
|
|
92
|
+
return { kind: java_1.J.Kind.RightPadded, element, after: prefix, markers: rewrite_1.emptyMarkers };
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=js-support.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-support.js","sourceRoot":"","sources":["../../src/migration/js-support.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAMH,0DAgCC;AAED,gDA+BC;AAED,gCAUC;AAED,kCAEC;AArFD,kDAA4D;AAC5D,gEAAmD;AACnD,oDAAqE;AAErE,SAAgB,uBAAuB,CAAC,GAAW,EAAE,KAAa;IAC9D,OAAO;QACH,IAAI,EAAE,eAAE,CAAC,IAAI,CAAC,kBAAkB;QAChC,EAAE,EAAE,IAAA,kBAAQ,GAAE;QACd,MAAM,EAAE,kBAAW;QACnB,OAAO,EAAE,sBAAY;QACrB,IAAI,EAAE;YACF,IAAI,EAAE,QAAC,CAAC,IAAI,CAAC,WAAW;YACxB,OAAO,EAAE;gBACL,IAAI,EAAE,QAAC,CAAC,IAAI,CAAC,UAAU;gBACvB,EAAE,EAAE,IAAA,kBAAQ,GAAE;gBACd,MAAM,EAAE,iBAAU;gBAClB,OAAO,EAAE,sBAAY;gBACrB,UAAU,EAAE,GAAG;gBACf,WAAW,EAAE,EAAE;gBACf,IAAI,EAAE,SAAS;aAClB;YACD,KAAK,EAAE,iBAAU;YACjB,OAAO,EAAE,sBAAY;SACxB;QACD,cAAc,EAAE,OAAO;QACvB,WAAW,EAAE;YACT,IAAI,EAAE,QAAC,CAAC,IAAI,CAAC,OAAO;YACpB,EAAE,EAAE,IAAA,kBAAQ,GAAE;YACd,MAAM,EAAE,kBAAW;YACnB,OAAO,EAAE,sBAAY;YACrB,KAAK,EAAE,KAAK;YACZ,WAAW,EAAE,IAAI,KAAK,GAAG;YACzB,cAAc,EAAE,SAAS;YACzB,IAAI,EAAE,SAAS;SAClB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,EAAE,SAAS;KACF,CAAC;AACtB,CAAC;AAED,SAAgB,WAAW,CAAI,OAAU,EAAE,MAAM,GAAG,iBAAU;IAC1D,OAAO,EAAC,IAAI,EAAE,QAAC,CAAC,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,sBAAY,EAAC,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Json } from "@openrewrite/rewrite/json";
|
|
2
|
+
export declare function isRootTsconfig(sourcePath: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* `extends` replaces `angularCompilerOptions` wholesale rather than merging it, so a derived
|
|
5
|
+
* tsconfig that declares the block needs its own copy of every option set in the root.
|
|
6
|
+
*/
|
|
7
|
+
export declare function declaresAngularCompilerOptions(doc: Json.Document): boolean;
|
|
8
|
+
export declare function literal(source: string, value: unknown): Json.Literal;
|
|
9
|
+
export declare function buildMember(key: string, value: Json.Value, keyPrefix?: string): Json.Member;
|
|
10
|
+
export declare function memberIndent(obj: Json.Object, fallback: string): string;
|
|
11
|
+
export declare function findMemberIndex(obj: Json.Object, key: string): number;
|
|
12
|
+
export declare function appendMember(obj: Json.Object, newMember: Json.Member, fallbackClosingWhitespace: string): Json.Object;
|
|
13
|
+
/**
|
|
14
|
+
* Adds `leaf` at `keys`, creating missing intermediate objects. Returns `obj` unchanged when the
|
|
15
|
+
* path already exists, or when an intermediate key holds something other than an object.
|
|
16
|
+
* `indent` is the indentation of the members of `obj`.
|
|
17
|
+
*/
|
|
18
|
+
export declare function addMemberPath(obj: Json.Object, keys: string[], leaf: Json.Value, indent: string, indentUnit: string): Json.Object;
|
|
19
|
+
//# sourceMappingURL=json-support.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-support.d.ts","sourceRoot":"","sources":["../../src/migration/json-support.ts"],"names":[],"mappings":"AAOA,OAAO,EAAuC,IAAI,EAAqB,MAAM,2BAA2B,CAAC;AAEzG,wBAAgB,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,EAAE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAG1E;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC,OAAO,CASpE;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,SAAK,GAAG,IAAI,CAAC,MAAM,CAgBvF;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMvE;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,yBAAyB,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,CAarH;AAkBD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,CAmBjI"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2026 the original author or authors.
|
|
4
|
+
*
|
|
5
|
+
* Moderne Proprietary. Only for use by Moderne customers under the terms of a commercial contract.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.isRootTsconfig = isRootTsconfig;
|
|
9
|
+
exports.declaresAngularCompilerOptions = declaresAngularCompilerOptions;
|
|
10
|
+
exports.literal = literal;
|
|
11
|
+
exports.buildMember = buildMember;
|
|
12
|
+
exports.memberIndent = memberIndent;
|
|
13
|
+
exports.findMemberIndex = findMemberIndex;
|
|
14
|
+
exports.appendMember = appendMember;
|
|
15
|
+
exports.addMemberPath = addMemberPath;
|
|
16
|
+
const rewrite_1 = require("@openrewrite/rewrite");
|
|
17
|
+
const json_1 = require("@openrewrite/rewrite/json");
|
|
18
|
+
function isRootTsconfig(sourcePath) {
|
|
19
|
+
var _a;
|
|
20
|
+
return ((_a = sourcePath.split('/').pop()) !== null && _a !== void 0 ? _a : '') === 'tsconfig.json';
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* `extends` replaces `angularCompilerOptions` wholesale rather than merging it, so a derived
|
|
24
|
+
* tsconfig that declares the block needs its own copy of every option set in the root.
|
|
25
|
+
*/
|
|
26
|
+
function declaresAngularCompilerOptions(doc) {
|
|
27
|
+
const root = doc.value;
|
|
28
|
+
return (0, json_1.isObject)(root) && findMemberIndex(root, 'angularCompilerOptions') !== -1;
|
|
29
|
+
}
|
|
30
|
+
function literal(source, value) {
|
|
31
|
+
return {
|
|
32
|
+
kind: json_1.Json.Kind.Literal,
|
|
33
|
+
id: (0, rewrite_1.randomId)(),
|
|
34
|
+
prefix: (0, json_1.space)(' '),
|
|
35
|
+
markers: rewrite_1.emptyMarkers,
|
|
36
|
+
source,
|
|
37
|
+
value
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function buildMember(key, value, keyPrefix = '') {
|
|
41
|
+
return {
|
|
42
|
+
kind: json_1.Json.Kind.Member,
|
|
43
|
+
id: (0, rewrite_1.randomId)(),
|
|
44
|
+
prefix: (0, json_1.space)(''),
|
|
45
|
+
markers: rewrite_1.emptyMarkers,
|
|
46
|
+
key: (0, json_1.rightPadded)({
|
|
47
|
+
kind: json_1.Json.Kind.Literal,
|
|
48
|
+
id: (0, rewrite_1.randomId)(),
|
|
49
|
+
prefix: (0, json_1.space)(keyPrefix),
|
|
50
|
+
markers: rewrite_1.emptyMarkers,
|
|
51
|
+
source: `"${key}"`,
|
|
52
|
+
value: key
|
|
53
|
+
}, (0, json_1.space)('')),
|
|
54
|
+
value
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function memberIndent(obj, fallback) {
|
|
58
|
+
const first = obj.members.find(rp => (0, json_1.isMember)(rp.element));
|
|
59
|
+
if (!first)
|
|
60
|
+
return fallback;
|
|
61
|
+
const firstPrefix = first.element.key.element.prefix.whitespace;
|
|
62
|
+
const match = firstPrefix.match(/\n([ \t]+)/);
|
|
63
|
+
return match ? match[1] : fallback;
|
|
64
|
+
}
|
|
65
|
+
function findMemberIndex(obj, key) {
|
|
66
|
+
return obj.members.findIndex(rp => (0, json_1.isMember)(rp.element) && (0, json_1.getMemberKeyName)(rp.element) === key);
|
|
67
|
+
}
|
|
68
|
+
function appendMember(obj, newMember, fallbackClosingWhitespace) {
|
|
69
|
+
// An empty object holds a single Json.Empty placeholder rather than any members
|
|
70
|
+
const members = obj.members.filter(rp => (0, json_1.isMember)(rp.element));
|
|
71
|
+
const closing = members.length > 0
|
|
72
|
+
? members[members.length - 1].after
|
|
73
|
+
: (0, json_1.space)(fallbackClosingWhitespace);
|
|
74
|
+
if (members.length > 0) {
|
|
75
|
+
members[members.length - 1] = Object.assign(Object.assign({}, members[members.length - 1]), { after: (0, json_1.space)('') });
|
|
76
|
+
}
|
|
77
|
+
members.push((0, json_1.rightPadded)(newMember, closing));
|
|
78
|
+
return Object.assign(Object.assign({}, obj), { members });
|
|
79
|
+
}
|
|
80
|
+
/** `indent` is the indentation of the member the returned value is assigned to. */
|
|
81
|
+
function buildNestedValue(keys, leaf, indent, indentUnit) {
|
|
82
|
+
if (keys.length === 0)
|
|
83
|
+
return leaf;
|
|
84
|
+
const childIndent = indent + indentUnit;
|
|
85
|
+
return {
|
|
86
|
+
kind: json_1.Json.Kind.Object,
|
|
87
|
+
id: (0, rewrite_1.randomId)(),
|
|
88
|
+
prefix: (0, json_1.space)(' '),
|
|
89
|
+
markers: rewrite_1.emptyMarkers,
|
|
90
|
+
members: [(0, json_1.rightPadded)(buildMember(keys[0], buildNestedValue(keys.slice(1), leaf, childIndent, indentUnit), '\n' + childIndent), (0, json_1.space)('\n' + indent))],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Adds `leaf` at `keys`, creating missing intermediate objects. Returns `obj` unchanged when the
|
|
95
|
+
* path already exists, or when an intermediate key holds something other than an object.
|
|
96
|
+
* `indent` is the indentation of the members of `obj`.
|
|
97
|
+
*/
|
|
98
|
+
function addMemberPath(obj, keys, leaf, indent, indentUnit) {
|
|
99
|
+
const index = findMemberIndex(obj, keys[0]);
|
|
100
|
+
if (index === -1) {
|
|
101
|
+
const newMember = buildMember(keys[0], buildNestedValue(keys.slice(1), leaf, indent, indentUnit), '\n' + indent);
|
|
102
|
+
return appendMember(obj, newMember, '\n' + indent.slice(0, Math.max(0, indent.length - indentUnit.length)));
|
|
103
|
+
}
|
|
104
|
+
if (keys.length === 1)
|
|
105
|
+
return obj;
|
|
106
|
+
const member = obj.members[index].element;
|
|
107
|
+
if (!(0, json_1.isObject)(member.value))
|
|
108
|
+
return obj;
|
|
109
|
+
const child = member.value;
|
|
110
|
+
const updated = addMemberPath(child, keys.slice(1), leaf, memberIndent(child, indent + indentUnit), indentUnit);
|
|
111
|
+
if (updated === child)
|
|
112
|
+
return obj;
|
|
113
|
+
const members = [...obj.members];
|
|
114
|
+
members[index] = Object.assign(Object.assign({}, members[index]), { element: Object.assign(Object.assign({}, member), { value: updated }) });
|
|
115
|
+
return Object.assign(Object.assign({}, obj), { members });
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=json-support.js.map
|