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
5 changes: 5 additions & 0 deletions .changeset/fix-extractor-json-overwrite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@baseplate-dev/sync': patch
---

Fix extractor.json being silently overwritten when it already exists but fails schema validation during auto-generation
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export async function tryCreateExtractorJson(
EXTRACTOR_CONFIG_FILENAME,
);

if (fsAdapter.existsSync(extractorJsonPath)) {
throw new Error(
`extractor.json already exists at ${extractorJsonPath} but could not be loaded. Please fix the existing file before running extraction.`,
);
}

// Create the extractor.json content
const extractorConfig = {
name: generatorPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,32 @@ describe('tryCreateExtractorJson', () => {
);
});

it('should throw error when extractor.json already exists', async () => {
// Arrange
const packagePath = '/test-package';
const generatorName = 'test-package#auth/login';
const packageMap = new Map<string, string>([
['test-package', '/test-package'],
]);

vol.fromJSON({
[`${packagePath}/src/generators/auth/login/login.generator.ts`]:
'export const generator = {};',
[`${packagePath}/src/generators/auth/login/extractor.json`]:
'{"name": "INVALID NAME"}',
});

// Act & Assert
await expect(
tryCreateExtractorJson({
packageMap,
generatorName,
}),
).rejects.toThrowError(
/extractor\.json already exists at .+ but could not be loaded/,
);
});

it('should create properly formatted JSON with newline', async () => {
// Arrange
const packagePath = '/test-package';
Expand Down
Loading