Skip to content

Commit

Permalink
fix(Build): Fix Windows build
Browse files Browse the repository at this point in the history
Currently, building Kaoto on Windows is broken due to a problem
resolving the base path of the catalog related to the folder separator.

The fix is to use the `pathToFileURL` function at all times when
resolving paths, so the folder and file paths gets properly resolved.

fix: KaotoIO#1592
  • Loading branch information
lordrip committed Nov 19, 2024
1 parent df577ab commit 9bd6c3d
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/catalog-generator/scripts/json-schema-to-typescript.mts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ async function main() {
}

const indexDefinitionFileName = catalogLibraryIndex.definitions[0].fileName;

/**
* In windows, path starting with C:\ are not supported
* We need to add file:// to the path to make it work
* [pathToFileURL](https://nodejs.org/api/url.html#url_url_pathtofileurl_path)
* Related issue: https://github.com/nodejs/node/issues/31710
*/
const indexFileUri = pathToFileURL(`./dist/camel-catalog/${indexDefinitionFileName}`).toString();
const indexDefinitionContent: CatalogDefinition = (await import(indexFileUri, { assert: { type: 'json' } })).default;

Expand All @@ -77,17 +84,9 @@ async function main() {
return;
}

const baseFolder = indexDefinitionFileName.substring(0, indexDefinitionFileName.lastIndexOf('/'));
const schemaFile = resolve(`./dist/camel-catalog/${baseFolder}/${schema.file}`);

/**
* In windows, path starting with C:\ are not supported
* We need to add file:// to the path to make it work
* [pathToFileURL](https://nodejs.org/api/url.html#url_url_pathtofileurl_path)
* Related issue: https://github.com/nodejs/node/issues/31710
*/
const schemaFileUri = pathToFileURL(schemaFile).toString();
const schemaContent = (await import(schemaFileUri, { assert: { type: 'json' } })).default;
const baseFolder = indexFileUri.substring(0, indexFileUri.lastIndexOf('/'));
const schemaFile = `${baseFolder}/${schema.file}`;
const schemaContent = (await import(schemaFile, { assert: { type: 'json' } })).default;

addTitleToDefinitions(schemaContent);

Expand Down

0 comments on commit 9bd6c3d

Please sign in to comment.