Skip to content

Commit 05f8601

Browse files
authored
Merge pull request #15 from jaculus-org/fix-lib-schema
refactor: update Jaculus schema to encapsulate registry under jaculus…
2 parents a3cc928 + 65f6532 commit 05f8601

3 files changed

Lines changed: 29 additions & 16 deletions

File tree

packages/project/src/package.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ const DependenciesSchema = z.record(NameSchema, VersionFormat);
2323
const RegistryUrisSchema = z.array(z.string());
2424
export const JaculusProjectTypeSchema = z.enum(["code", "jacly"]);
2525

26-
const JaculusSchema = z.object({
27-
registry: RegistryUrisSchema.optional(),
28-
blocks: z.string().optional(),
29-
projectType: JaculusProjectTypeSchema.optional(),
30-
template: z.boolean().optional(),
31-
projectFormatVersion: z.number().optional(),
32-
jaclyVersion: VersionFormat.optional(),
33-
});
26+
const JaculusSchema = z
27+
.object({
28+
registry: RegistryUrisSchema.optional(),
29+
blocks: z.string().optional(),
30+
projectType: JaculusProjectTypeSchema.optional(),
31+
template: z.boolean().optional(),
32+
projectFormatVersion: z.number().optional(),
33+
jaclyVersion: VersionFormat.optional(),
34+
})
35+
.catchall(z.unknown());
3436

3537
const ExportKeyValueSchema = z.record(z.string(), z.string());
3638

test/project/package.test.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ describe("Package JSON", () => {
3232
core: "0.0.24",
3333
"led-strip": "1.2.3",
3434
},
35-
registry: ["https://registry.example.com", "https://backup.registry.com"],
35+
jaculus: {
36+
registry: ["https://registry.example.com", "https://backup.registry.com"],
37+
},
3638
};
3739

3840
const packagePath = path.join(tempDir, "package.json");
@@ -46,7 +48,9 @@ describe("Package JSON", () => {
4648
expect(loaded.description).to.equal("A test package");
4749
expect(loaded.dependencies).to.have.property("core", "0.0.24");
4850
expect(loaded.dependencies).to.have.property("led-strip", "1.2.3");
49-
expect(loaded.registry).to.be.an("array").that.includes("https://registry.example.com");
51+
expect(loaded.jaculus?.registry)
52+
.to.be.an("array")
53+
.that.includes("https://registry.example.com");
5054
});
5155

5256
it("should load minimal valid package.json with only dependencies", async () => {
@@ -68,7 +72,7 @@ describe("Package JSON", () => {
6872
expect(loaded.name).to.equal("minimal-package");
6973
expect(loaded.version).to.equal("1.0.0");
7074
expect(loaded.description).to.be.undefined;
71-
expect(loaded.registry).to.be.undefined;
75+
expect(loaded.jaculus).to.be.undefined;
7276
});
7377

7478
it("should load package.json with empty dependencies", async () => {
@@ -263,7 +267,9 @@ describe("Package JSON", () => {
263267
core: "0.0.24",
264268
"led-strip": "1.2.3",
265269
},
266-
registry: ["https://registry.example.com"],
270+
jaculus: {
271+
registry: ["https://registry.example.com"],
272+
},
267273
};
268274

269275
await savePackageJson(mockFs, path.join(tempDir, "package.json"), packageData);
@@ -384,7 +390,9 @@ describe("Package JSON", () => {
384390
core: "0.0.24",
385391
"test-lib": "2.1.0-beta",
386392
},
387-
registry: ["https://test.registry.com", "https://backup.registry.com"],
393+
jaculus: {
394+
registry: ["https://test.registry.com", "https://backup.registry.com"],
395+
},
388396
};
389397

390398
await savePackageJson(mockFs, path.join(tempDir, "roundtrip.json"), originalData);

test/project/testHelpers.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,11 @@ export function createPackageJson(
155155
name: "test-project",
156156
version: "0.0.1",
157157
dependencies,
158-
registry,
159158
...additionalFields,
159+
jaculus: {
160+
registry,
161+
...(additionalFields.jaculus || {}),
162+
},
160163
};
161164

162165
fs.mkdirSync(projectPath, { recursive: true });
@@ -176,7 +179,7 @@ export async function createMockRegistry(
176179
logger: Logger = createMockLogger()
177180
): Promise<Registry> {
178181
const pkg = await loadPackageJson(fs, path.join(projectPath, "package.json"));
179-
return new Registry(pkg.registry, getRequest, logger);
182+
return new Registry(pkg.jaculus?.registry, getRequest, logger);
180183
}
181184

182185
export function createTestDir(prefix: string = "jaculus-test-"): string {
@@ -200,7 +203,7 @@ export function createProjectStructure(
200203
createPackageJson(
201204
projectPath,
202205
packageData.dependencies || {},
203-
packageData.registry || [registryBasePath],
206+
packageData.jaculus?.registry || [registryBasePath],
204207
packageData
205208
);
206209
} else {

0 commit comments

Comments
 (0)