Skip to content
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
6 changes: 2 additions & 4 deletions src/commands/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,15 @@ export default createCommand(config, async ({ values }) => {
localCustomTypes.map((customType) => customType.model),
{
getKey: (model) => model.id,
equals: (a, b) =>
JSON.stringify(canonicalizeCustomType(a)) === JSON.stringify(canonicalizeCustomType(b)),
equals: (remote, local) => JSON.stringify(canonicalizeCustomType(remote)) === JSON.stringify(local),
},
);
const sliceOps = diffArrays(
remoteSlices,
localSlices.map((slice) => slice.model),
{
getKey: (model) => model.id,
equals: (a, b) =>
JSON.stringify(canonicalizeSlice(a)) === JSON.stringify(canonicalizeSlice(b)),
equals: (remote, local) => JSON.stringify(canonicalizeSlice(remote)) === JSON.stringify(local),
},
);

Expand Down
27 changes: 26 additions & 1 deletion test/pull.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pascalCase } from "change-case";
import { writeFile, mkdir } from "node:fs/promises";
import { readFile, writeFile, mkdir } from "node:fs/promises";
import { sep } from "node:path";
import { fileURLToPath } from "node:url";
import { x } from "tinyexec";
Expand Down Expand Up @@ -250,6 +250,31 @@ it.sequential("removes route when page type is deleted", async ({
await expect(project).not.toHaveRoute({ type: customType.id });
});

it.sequential("rewrites model files whose key order is not canonical", async ({
expect,
project,
prismic,
repo,
token,
host,
}) => {
const customType = buildCustomType();
await insertCustomType(customType, { repo, token, host });

const first = await prismic("pull", ["--repo", repo]);
expect(first.exitCode, first.stderr).toBe(0);

const modelPath = new URL(`customtypes/${customType.id}/index.json`, project);
const canonical = await readFile(modelPath, "utf8");
const reversed = Object.fromEntries(Object.entries(JSON.parse(canonical)).reverse());
await writeFile(modelPath, JSON.stringify(reversed, null, 2));

const second = await prismic("pull", ["--repo", repo, "--force"]);
expect(second.exitCode, second.stderr).toBe(0);
expect(second.stdout).toContain("updated 1");
expect(await readFile(modelPath, "utf8")).toBe(canonical);
});

it.sequential("blocks pull when local model files have uncommitted changes", async ({
expect,
project,
Expand Down
Loading