You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that the --exclude-file file path is passed directly to the new XmlDocument, but this class expects the file content instead of the file path.
/home/earenas/projects/my_project/node_modules/xmldoc/lib/xmldoc.js:92
throw err;
^
Error: Non-whitespace before first tag.
Line: 0
Column: 1
Char: p
at error (/home/earenas/projects/my_project/node_modules/sax/lib/sax.js:652:10)
at strictFail (/home/earenas/projects/my_project/node_modules/sax/lib/sax.js:678:7)
at beginWhiteSpace (/home/earenas/projects/my_project/node_modules/sax/lib/sax.js:952:7)
at SAXParser.write (/home/earenas/projects/my_project/node_modules/sax/lib/sax.js:1007:11)
at new XmlDocument (/home/earenas/projects/my_project/node_modules/xmldoc/lib/xmldoc.js:281:17)
at /home/earenas/projects/my_project/node_modules/xliff-simple-merge/dist/src/merge.js:184:160
at Array.map (<anonymous>)
at mergeWithMapping (/home/earenas/projects/my_project/node_modules/xliff-simple-merge/dist/src/merge.js:184:141)
at merge (/home/earenas/projects/my_project/node_modules/xliff-simple-merge/dist/src/merge.js:116:37)
at Object.<anonymous> (/home/earenas/projects/my_project/node_modules/xliff-simple-merge/dist/src/index.js:29:37)
Node.js v18.15.0
The sax library error indicates the exclude file starts with the invalid character p instead of starting by a proper XML tag. However, if I change the --exclude-file option to aaa.xlf it shows the same error but telling that a is not a valid start (the file aaa.xlf doesn't even exist).
I debugged the execution and found that the mergeWithMapping function expects options.excludeFiles to be the XML content as it happens with the inFilesContent argument:
exportfunctionmergeWithMapping(inFilesContent: string|string[],destFileContent: string,options?: MergeOptions,destFilePath?: string): [mergedDestFileContent: string,idMappging: {[oldId: string]: string}]{inFilesContent=Array.isArray(inFilesContent) ? inFilesContent : [inFilesContent];constinDocs=inFilesContent.map(inFileContent=>newXmlDocument(inFileContent));// <-------------------- XmlDocument uses the inFileContentconstxliffVersion=inDocs[0].attr.versionas'1.2'|'2.0'??'1.2';constdestDoc=newXmlDocument(destFileContent.match(/^[\n\r\s]*$/) ? createEmptyTarget(xliffVersion==='2.0',extractSourceLocale(inDocs[0],xliffVersion==='2.0'),extractTargetLocale(destFilePath)) : destFileContent);constexcludeDocs=(options?.excludeFiles??[]).map(excludeFile=>newXmlDocument(excludeFile));// <-------------------- BUT this excludeFile is not the content but the path!!constdestUnitsParent=xliffVersion==='2.0' ? destDoc.childNamed('file')! : destDoc.childNamed('file')?.childNamed('body')!;constexcludeUnits=excludeDocs.map(excludeDoc=>getUnits(excludeDoc,xliffVersion)??[]).flat(1);constexcludeUnitsId=newSet<string>(excludeUnits.map(unit=>unit.attr.id!));constinUnits=inDocs.map(inDoc=>getUnits(inDoc,xliffVersion)??[]).flat(1).filter(inUnit=>!excludeUnitsId.has(inUnit.attr.id));
...
I suppose that the fix should be loading the file at the index.ts as you do with the inFilesContent variable.
Please, let me know if I should provide more information or any kind support.
The text was updated successfully, but these errors were encountered:
Hi @daniel-sc, thanks for this useful library!
Summary
It seems that the
--exclude-file
file path is passed directly to thenew XmlDocument
, but this class expects the file content instead of the file path.Execution and error
Error command:
Error output:
The sax library error indicates the exclude file starts with the invalid character
p
instead of starting by a proper XML tag. However, if I change the--exclude-file
option toaaa.xlf
it shows the same error but telling thata
is not a valid start (the fileaaa.xlf
doesn't even exist).Workaround
Passing the actual content works:
npx xliff-simple-merge \ -i projects/user-console/src/locale/messages.xlf \ -e "$(cat projects/shared/src/locale/messages.xlf)" \ -d output.xlf
Possible solution
I debugged the execution and found that the
mergeWithMapping
function expectsoptions.excludeFiles
to be the XML content as it happens with theinFilesContent
argument:I suppose that the fix should be loading the file at the
index.ts
as you do with theinFilesContent
variable.Please, let me know if I should provide more information or any kind support.
The text was updated successfully, but these errors were encountered: