diff --git a/packages/project/src/package.ts b/packages/project/src/package.ts index 5b5f376..252a8d6 100644 --- a/packages/project/src/package.ts +++ b/packages/project/src/package.ts @@ -23,14 +23,16 @@ const DependenciesSchema = z.record(NameSchema, VersionFormat); const RegistryUrisSchema = z.array(z.string()); export const JaculusProjectTypeSchema = z.enum(["code", "jacly"]); -const JaculusSchema = z.object({ - registry: RegistryUrisSchema.optional(), - blocks: z.string().optional(), - projectType: JaculusProjectTypeSchema.optional(), - template: z.boolean().optional(), - projectFormatVersion: z.number().optional(), - jaclyVersion: VersionFormat.optional(), -}); +const JaculusSchema = z + .object({ + registry: RegistryUrisSchema.optional(), + blocks: z.string().optional(), + projectType: JaculusProjectTypeSchema.optional(), + template: z.boolean().optional(), + projectFormatVersion: z.number().optional(), + jaclyVersion: VersionFormat.optional(), + }) + .catchall(z.unknown()); const ExportKeyValueSchema = z.record(z.string(), z.string()); diff --git a/test/project/package.test.ts b/test/project/package.test.ts index aae2bd4..20ce65c 100644 --- a/test/project/package.test.ts +++ b/test/project/package.test.ts @@ -32,7 +32,9 @@ describe("Package JSON", () => { core: "0.0.24", "led-strip": "1.2.3", }, - registry: ["https://registry.example.com", "https://backup.registry.com"], + jaculus: { + registry: ["https://registry.example.com", "https://backup.registry.com"], + }, }; const packagePath = path.join(tempDir, "package.json"); @@ -46,7 +48,9 @@ describe("Package JSON", () => { expect(loaded.description).to.equal("A test package"); expect(loaded.dependencies).to.have.property("core", "0.0.24"); expect(loaded.dependencies).to.have.property("led-strip", "1.2.3"); - expect(loaded.registry).to.be.an("array").that.includes("https://registry.example.com"); + expect(loaded.jaculus?.registry) + .to.be.an("array") + .that.includes("https://registry.example.com"); }); it("should load minimal valid package.json with only dependencies", async () => { @@ -68,7 +72,7 @@ describe("Package JSON", () => { expect(loaded.name).to.equal("minimal-package"); expect(loaded.version).to.equal("1.0.0"); expect(loaded.description).to.be.undefined; - expect(loaded.registry).to.be.undefined; + expect(loaded.jaculus).to.be.undefined; }); it("should load package.json with empty dependencies", async () => { @@ -263,7 +267,9 @@ describe("Package JSON", () => { core: "0.0.24", "led-strip": "1.2.3", }, - registry: ["https://registry.example.com"], + jaculus: { + registry: ["https://registry.example.com"], + }, }; await savePackageJson(mockFs, path.join(tempDir, "package.json"), packageData); @@ -384,7 +390,9 @@ describe("Package JSON", () => { core: "0.0.24", "test-lib": "2.1.0-beta", }, - registry: ["https://test.registry.com", "https://backup.registry.com"], + jaculus: { + registry: ["https://test.registry.com", "https://backup.registry.com"], + }, }; await savePackageJson(mockFs, path.join(tempDir, "roundtrip.json"), originalData); diff --git a/test/project/testHelpers.ts b/test/project/testHelpers.ts index 4c25802..cd1ad6d 100644 --- a/test/project/testHelpers.ts +++ b/test/project/testHelpers.ts @@ -155,8 +155,11 @@ export function createPackageJson( name: "test-project", version: "0.0.1", dependencies, - registry, ...additionalFields, + jaculus: { + registry, + ...(additionalFields.jaculus || {}), + }, }; fs.mkdirSync(projectPath, { recursive: true }); @@ -176,7 +179,7 @@ export async function createMockRegistry( logger: Logger = createMockLogger() ): Promise { const pkg = await loadPackageJson(fs, path.join(projectPath, "package.json")); - return new Registry(pkg.registry, getRequest, logger); + return new Registry(pkg.jaculus?.registry, getRequest, logger); } export function createTestDir(prefix: string = "jaculus-test-"): string { @@ -200,7 +203,7 @@ export function createProjectStructure( createPackageJson( projectPath, packageData.dependencies || {}, - packageData.registry || [registryBasePath], + packageData.jaculus?.registry || [registryBasePath], packageData ); } else {