Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(package): fix package order #120

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/libs/node-package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe("createNewNodePackageEncodedContent()", () => {
const result = createNewNodePackageEncodedContent(new SemVer("1.3.0"));

expect(result).toEqual(
"ewogICJuYW1lIjogIkBvd25lci9hcHBsaWNhdGlvbiIsCiAgImJ1Z3MiOiB7CiAgICAidXJsIjogImh0dHA6Ly9idWdzLmNvbSIsCiAgICAiZW1haWwiOiAiYnVnc0BlbWFpbC5jb20iCiAgfSwKICAiYXV0aG9yIjogewogICAgIm5hbWUiOiAiTmFtZSIsCiAgICAiZW1haWwiOiAibmFtZUBlbWFpbC5jb20iLAogICAgInVybCI6ICJodHRwOi8vbmFtZS5jb20iCiAgfSwKICAiZGVwZW5kZW5jaWVzIjoge30sCiAgInZlcnNpb24iOiAiMS4zLjAiCn0K",
"ewogICJuYW1lIjogIkBvd25lci9hcHBsaWNhdGlvbiIsCiAgInZlcnNpb24iOiAiMS4zLjAiLAogICJidWdzIjogewogICAgInVybCI6ICJodHRwOi8vYnVncy5jb20iLAogICAgImVtYWlsIjogImJ1Z3NAZW1haWwuY29tIgogIH0sCiAgImF1dGhvciI6IHsKICAgICJuYW1lIjogIk5hbWUiLAogICAgImVtYWlsIjogIm5hbWVAZW1haWwuY29tIiwKICAgICJ1cmwiOiAiaHR0cDovL25hbWUuY29tIgogIH0sCiAgImRlcGVuZGVuY2llcyI6IHt9Cn0K",
);
});
});
12 changes: 10 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32394,8 +32394,16 @@ function createNewNodePackageEncodedContent(version) {
core.debug(`Creating new ${PACKAGE_FILE_NAME} encoded content...`);
const packageFile = (0,external_fs_.readFileSync)(PACKAGE_FILE_NAME, "utf8");
const content = JSON.parse(packageFile);
content["version"] = version.version;
const newContent = Buffer.from(JSON.stringify(content, null, 2) + "\n").toString("base64");
const orderedContent = {
name: content["name"],
version: version.version,
};
for (const [key, value] of Object.entries(content)) {
if (!["name", "version"].includes(key)) {
orderedContent[key] = value;
}
}
const newContent = Buffer.from(JSON.stringify(orderedContent, null, 2) + "\n").toString("base64");
core.info(`${PACKAGE_FILE_NAME} updated.`);
return newContent;
}, `Error while creating new ${PACKAGE_FILE_NAME} encoded content.`);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions src/libs/node-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,17 @@ export function createNewNodePackageEncodedContent(version: SemVer) {
core.debug(`Creating new ${PACKAGE_FILE_NAME} encoded content...`);
const packageFile = readFileSync(PACKAGE_FILE_NAME, "utf8");
const content = JSON.parse(packageFile) as Record<string, unknown>;
content["version"] = version.version;
const orderedContent: Record<string, unknown> = {
name: content["name"],
version: version.version,
};
for (const [key, value] of Object.entries(content)) {
if (!["name", "version"].includes(key)) {
orderedContent[key] = value;
}
}
const newContent = Buffer.from(
JSON.stringify(content, null, 2) + "\n",
JSON.stringify(orderedContent, null, 2) + "\n",
).toString("base64");
core.info(`${PACKAGE_FILE_NAME} updated.`);

Expand Down
Loading