infojunkie / musicxml-player

A TypeScript component that loads and plays MusicXML files in the browser using Web Audio and Web MIDI.
https://blog.karimratib.me/demos/musicxml/
GNU General Public License v3.0
34 stars 6 forks source link

Bundling of webaudiofont and saxon-js #21

Closed deevus closed 1 year ago

deevus commented 1 year ago

WebAudioFont

Uses patch-package to support bundling webaudiofont by adding an export for WebAudioFontPlayer.

Saxon JS

Updated ./dist/saxon-js/SaxonJS2.rt.js to assign variables to window explicitly. Importing the package into src/index.ts.

/claim #17

deevus commented 1 year ago

The solution for saxon-js is a bit hacky, but it works with very little changes. 🤷

infojunkie commented 1 year ago

Thank you, that's great! Some comments:

musicxml-player@0.5.4 postinstall patch-package

patch-package 7.0.0 Applying patches... Error: Version string '3.0.04' cannot be parsed from /home/kratib/src/infojunkie/testing/musicxml-player/node_modules/webaudiofont/package.json

patch-package finished with 1 error(s).

added 807 packages, and audited 808 packages in 2m

100 packages are looking for funding run npm fund for details

found 0 vulnerabilities $ patch -p1 < patches/webaudiofont+3.0.4.patch patching file node_modules/webaudiofont/npm/dist/WebAudioFontPlayer.js Hunk #1 FAILED at 1220 (different line endings). 1 out of 1 hunk FAILED -- saving rejects to file node_modules/webaudiofont/npm/dist/WebAudioFontPlayer.js.rej $ dos2unix node_modules/webaudiofont/npm/dist/WebAudioFontPlayer.js dos2unix: converting file node_modules/webaudiofont/npm/dist/WebAudioFontPlayer.js to Unix format... $ patch -p1 < patches/webaudiofont+3.0.4.patch patching file node_modules/webaudiofont/npm/dist/WebAudioFontPlayer.js


I wonder if there's an option to `patch-package` that ignores the "line endings" error, e.g. something to pass to `patch` https://stackoverflow.com/questions/7754972/how-do-i-get-patch-to-ignore-carriage-returns

- Would be great to create and apply a patch to `saxon-js` since it's a vendor library, but I will accept your PR without this enhancement.
deevus commented 1 year ago

Weird issue. I'm on MacOS so you would think that the line-endings would be the same.

With regards to using it to patch SaxonJS, I don't think it supports patching arbitrary files. I'll take a look.

deevus commented 1 year ago

The error is a bit weird. Where is the version string 3.0.04 coming from? All references I can find say 3.0.4

Error: Version string '3.0.04' cannot be parsed from /home/kratib/src/infojunkie/testing/musicxml-player/node_modules/webaudiofont/package.json
deevus commented 1 year ago

Ohhh I see what's going on. There's a typo in webaudiofont's package.json. The published version is 3.0.4 but the package.json has 3.0.04. This is what is breaking patch-package.

deevus commented 1 year ago

@infojunkie Please try again

deevus commented 1 year ago

Btw I've added a patch for SaxonJS, but since the vendor files are in the index, it won't have any effect. However if you update SaxonJS you can run the patch again.

infojunkie commented 1 year ago

Thanks, this works really great. I appreciate the way you identified the problems with the 2 dependencies and decided to patch them as a pragmatic fix. Well done!

I have some cleaning up to do on this branch before I can merge into main.

deevus commented 1 year ago

No problem 😊

I appreciate the opportunity