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
27 changes: 23 additions & 4 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: push

jobs:
lint:
runs-on: ubuntu-latest
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
Expand All @@ -15,7 +15,7 @@ jobs:
- run: npm run lint

build:
runs-on: ubuntu-latest
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
env:
MODE: production
steps:
Expand All @@ -29,7 +29,26 @@ jobs:

test:
name: test (Node.js ${{ matrix.node }})
runs-on: ubuntu-latest
runs-on: blacksmith-4vcpu-ubuntu-2404
strategy:
matrix:
node: [20, 22, 24]
fail-fast: false
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npm run unit
env:
E2E_PRISMIC_EMAIL: ${{ secrets.E2E_PRISMIC_EMAIL }}
E2E_PRISMIC_PASSWORD: ${{ secrets.E2E_PRISMIC_PASSWORD }}

test-win32:
name: test windows (Node.js ${{ matrix.node }})
runs-on: blacksmith-4vcpu-windows-2025
strategy:
matrix:
node: [20, 22, 24]
Expand All @@ -48,7 +67,7 @@ jobs:

types:
name: "types (TypeScript ${{ matrix.typescript }})"
runs-on: ubuntu-latest
runs-on: blacksmith-2vcpu-ubuntu-2404-arm
strategy:
matrix:
typescript: ["5.4", "5.6", "5.7", "5.8", "5.9"]
Expand Down
8 changes: 3 additions & 5 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { CustomType, SharedSlice } from "@prismicio/types-internal/lib/cust

import { pascalCase } from "change-case";
import { rm } from "node:fs/promises";
import { fileURLToPath, pathToFileURL } from "node:url";
import { pathToFileURL } from "node:url";
import { generateTypes } from "prismic-ts-codegen";
import { glob } from "tinyglobby";

Expand Down Expand Up @@ -79,9 +79,8 @@ export abstract class Adapter {

const libraries = await this.getSliceLibraries();
for (const library of libraries) {
const modelGlob = new URL("*/model.json", library);
const sliceModelPaths = Array.from(
await glob(fileURLToPath(modelGlob), { absolute: true }),
await glob("*/model.json", { absolute: true, cwd: library }),
(path) => pathToFileURL(path),
);
const slices = await Promise.all(
Expand Down Expand Up @@ -139,9 +138,8 @@ export abstract class Adapter {

const libraries = await this.getCustomTypeLibraries();
for (const library of libraries) {
const modelGlob = new URL("*/index.json", library);
const customTypeModelPaths = Array.from(
await glob(fileURLToPath(modelGlob), { absolute: true }),
await glob("*/index.json", { absolute: true, cwd: library }),
(path) => pathToFileURL(path),
);
const customTypes = await Promise.all(
Expand Down
3 changes: 2 additions & 1 deletion src/lib/git.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { realpath } from "node:fs/promises";
import { fileURLToPath, pathToFileURL } from "node:url";
import { x } from "tinyexec";

Expand All @@ -10,7 +11,7 @@ export async function getGitRoot(start: URL): Promise<URL | undefined> {
throwOnError: true,
});
const top = stdout.trim();
return top ? appendTrailingSlash(pathToFileURL(top)) : undefined;
return top ? appendTrailingSlash(pathToFileURL(await realpath(top))) : undefined;
} catch {
return undefined;
}
Expand Down
5 changes: 3 additions & 2 deletions src/project.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { CustomType } from "@prismicio/types-internal/lib/customtypes";

import { readFile, rm, writeFile } from "node:fs/promises";
import { readFile, realpath, rm, writeFile } from "node:fs/promises";
import { fileURLToPath, pathToFileURL } from "node:url";
import * as z from "zod/mini";

import { getVariantData } from "./clients/amplitude";
Expand Down Expand Up @@ -201,7 +202,7 @@ export async function findProjectRoot(): Promise<URL> {
}
}
const projectRoot = new URL(".", configPath);
return projectRoot;
return appendTrailingSlash(pathToFileURL(await realpath(fileURLToPath(projectRoot))));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit weird, but basically we need to ensure we resolve real paths on Windows, otherwise some paths yield %USERPROFILE% while others yield actualUserName

}

export async function safeGetRepositoryName(): Promise<string | undefined> {
Expand Down
4 changes: 2 additions & 2 deletions test/gen-setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ it("supports --help", async ({ expect, prismic }) => {
expect(stdout).toContain("prismic gen setup [options]");
});

it("generates setup files", async ({ expect, project, prismic }) => {
it("generates setup files", { timeout: 30_000 }, async ({ expect, project, prismic }) => {
const { exitCode, stdout } = await prismic("gen", ["setup"]);
expect(exitCode).toBe(0);
expect(stdout).toContain("Generated setup files");
Expand All @@ -25,7 +25,7 @@ it("generates setup files", async ({ expect, project, prismic }) => {
await expect(project).toHaveFile("package-lock.json");
});

it("skips existing files", async ({ expect, project, prismic }) => {
it("skips existing files", { timeout: 30_000 }, async ({ expect, project, prismic }) => {
const customContent = "// custom client file\n";
await writeFile(new URL("prismicio.js", project), customContent);

Expand Down
2 changes: 1 addition & 1 deletion test/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ it("fails when Type Builder is not enabled", async ({ expect, project, prismic,
expect(stderr).toContain("Type Builder");
});

it("installs dependencies", async ({ expect, project, prismic, repo }) => {
it("installs dependencies", { timeout: 30_000 }, async ({ expect, project, prismic, repo }) => {
await rm(new URL("prismic.config.json", project));

const { exitCode } = await prismic("init", ["--repo", repo]);
Expand Down
10 changes: 9 additions & 1 deletion test/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ export const it = test.extend<Fixtures>({
home: async ({}, use) => {
const dir = await mkdtemp(join(tmpdir(), "prismic-test-"));
await use(pathToFileURL(dir + "/"));
await rm(dir, { recursive: true, force: true });
try {
await rm(dir, { recursive: true, force: true });
} catch {
// Noop on CI, retry once with delay locally
if (!process.env.CI) {
await new Promise((res) => setTimeout(res, 1000));
await rm(dir, { recursive: true, force: true });
}
}
},
project: async ({ home, repo }, use) => {
const projectPath = new URL("project/", home);
Expand Down
3 changes: 2 additions & 1 deletion test/pull.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { writeFile, mkdir } from "node:fs/promises";
import { sep } from "node:path";
import { fileURLToPath } from "node:url";
import { x } from "tinyexec";

Expand Down Expand Up @@ -252,7 +253,7 @@ it.sequential("blocks pull when local model files have uncommitted changes", asy
const second = await prismic("pull", ["--repo", repo]);
expect(second.exitCode).toBe(1);
expect(second.stderr).toContain("uncommitted");
expect(second.stderr).toContain(`customtypes/${customType.id}/index.json`);
expect(second.stderr).toContain(`customtypes/${customType.id}/index.json`.replaceAll("/", sep));
});

it.sequential("refuses to delete local models without --force when not tracked by git", async ({
Expand Down