danburzo / percollate

A command-line tool to turn web pages into readable PDF, EPUB, HTML, or Markdown docs.
https://danburzo.ro/projects/percollate/
MIT License
4.32k stars 166 forks source link

hyphenopoly pattern couldn't be loaded #163

Closed yashha closed 1 year ago

yashha commented 1 year ago

Environment

Description

When using percollate programmatically with hyphanation, the patterns can't be loaded dynamically.

It throws following error:

Error: ENOENT: no such file or directory, open '/home/Arbeitsbereich/js/percollate-api/node_modules/percollate/node_modules/hyphenopoly/patterns/de.wasm'
    at Object.openSync (node:fs:601:3)
    at readFileSync (node:fs:469:35)
    at Proxy.loaderSync (file:///home/Arbeitsbereich/js/percollate-api/node_modules/percollate/src/hyphenate.js:13:11)
    at loadHyphenEngine (file:///home/Arbeitsbereich/js/percollate-api/node_modules/hyphenopoly/hyphenopoly.module.js:289:22)
    at file:///home/Arbeitsbereich/js/percollate-api/node_modules/hyphenopoly/hyphenopoly.module.js:680:9
    at Array.forEach (<anonymous>)
    at Object.H.config (file:///home/Arbeitsbereich/js/percollate-api/node_modules/hyphenopoly/hyphenopoly.module.js:658:17)
    at getHypenatorByLang (file:///home/Arbeitsbereich/js/percollate-api/node_modules/percollate/src/hyphenate.js:10:20)
    at hyphenateDom (file:///home/Arbeitsbereich/js/percollate-api/node_modules/percollate/src/hyphenate.js:29:20)
    at file:///home/Arbeitsbereich/js/percollate-api/node_modules/percollate/index.js:344:30 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/home/Arbeitsbereich/js/percollate-api/node_modules/percollate/node_modules/hyphenopoly/patterns/de.wasm'
}
danburzo commented 1 year ago

Hi @yashha, thanks for logging this issue. You’re right that looking into node_modules is not the way to go because it doesn’t work when percollate is installed as a dependency. And your solution for addressing this is fine, but I feel like this should be fixed in (or with the help of) Hyphenopoly’s loading API.

I’ll open a discussion there.

mnater commented 1 year ago

As of version 5.3.0 of Hyphenopoly the loader/loaderSync- function is now called with a second argument receiving import.meta.url. See https://mnater.github.io/Hyphenopoly/Module.html I hope this helps with loading the patterns (I haven't tested with percolate myself). Please feel free to reopen the issue, if not.

Kind regards, Mathias

danburzo commented 1 year ago

Thank you @mnater, we will test it out and let you know. Cheers!

yashha commented 1 year ago

@danburzo Updated the PR, looks better now.

danburzo commented 1 year ago

Brilliant, thanks @yashha!

danburzo commented 1 year ago

Deployed in percollate@4.0.4