Skip to content

Commit 960b594

Browse files
authored
chore(align-deps): tweak update-preset.mts to preserve comments better (#3855)
1 parent abfb4df commit 960b594

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

.changeset/chubby-towns-push.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

packages/align-deps/scripts/update-preset.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,18 @@ function getIdentifier(node: recast.types.namedTypes.Node): string | null {
5757
function objectProperty(
5858
b: recast.types.builders,
5959
capability: string,
60-
info: MetaPackage | Package
60+
info: MetaPackage | Package,
61+
comments: recast.types.namedTypes.ObjectProperty["comments"] = null
6162
): recast.types.namedTypes.ObjectProperty {
62-
return b.objectProperty(
63-
b.stringLiteral(capability),
64-
b.objectExpression(
63+
return b.objectProperty.from({
64+
comments,
65+
key: b.stringLiteral(capability),
66+
value: b.objectExpression(
6567
Object.entries(info).map(([key, value]) =>
6668
b.objectProperty(b.identifier(key), valueLiteral(b, value))
6769
)
68-
)
69-
);
70+
),
71+
});
7072
}
7173

7274
function valueLiteral(b: recast.types.builders, value: unknown) {
@@ -94,14 +96,16 @@ async function main() {
9496
throw new Error(`Profile file not found: ${profilePath}`);
9597
}
9698
97-
const content = fs.readFileSync(profilePath, "utf-8");
98-
const ast = recast.parse(content, {
99+
const options = {
99100
parser: typescript,
100101
lineTerminator: "\n",
101102
sourceFileName: profilePath,
102103
trailingComma: true,
103104
tokens: false,
104-
});
105+
};
106+
107+
const content = fs.readFileSync(profilePath, "utf-8");
108+
const ast = recast.parse(content, options);
105109
106110
const exportedProfile = ast.program.body.find(
107111
(node) =>
@@ -121,7 +125,8 @@ async function main() {
121125
for (let i = 0; i < numProperties; ++i) {
122126
const id = getIdentifier(properties[i]);
123127
if (isValidIdentifier(id) && id in modules) {
124-
properties[i] = objectProperty(b, id, modules[id]);
128+
const comments = properties[i].comments;
129+
properties[i] = objectProperty(b, id, modules[id], comments);
125130
delete modules[id];
126131
}
127132
}
@@ -134,7 +139,7 @@ async function main() {
134139
properties.push(objectProperty(b, capability, info));
135140
}
136141
137-
fs.writeFileSync(profilePath, recast.print(ast).code, "utf-8");
142+
fs.writeFileSync(profilePath, recast.print(ast, options).code, "utf-8");
138143
info(`Updated profile: ${profilePath}`);
139144
}
140145
}

packages/align-deps/src/presets/microsoft/react-native/profile-0.82.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ export const profile: Profile = {
132132

133133
/*********************
134134
* Community Modules *
135-
*********************/ animation: {
135+
*********************/
136+
137+
animation: {
136138
name: "react-native-reanimated",
137139
version: "^4.1.2",
138140
},

0 commit comments

Comments
 (0)