Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Hyphenopoly module path to loader() / loaderSync()? #207

Closed
danburzo opened this issue Nov 21, 2023 · 1 comment
Closed

Provide Hyphenopoly module path to loader() / loaderSync()? #207

danburzo opened this issue Nov 21, 2023 · 1 comment
Assignees

Comments

@danburzo
Copy link

Since Hyphenopoly requires an explicit loader / loaderSync function in Node and other non-browser JS runtimes, it would be great if these functions received Hyphenopoly’s module URL as a second argument, to make it easier to locate the patterns folder.

For example, percollate, which uses Hyphenopoly for hyphenation, can be run either as a standalone CLI or a Node.js dependency. As I’ve just been reminded, only the former has node_modules/hyphenopoly/patterns.

Getting import.meta.url as the second argument to the loader() / loaderSync() functions — or, even better, maybe something like new URL('./patterns', import.meta.url) — would help us prevent things like createRequire() to locate the patterns folder:

// before
loaderSync: file => {
  return readFileSync(
    createRequire(import.meta.url).resolve(`hyphenopoly/patterns/${file}`)
  );
}

// after
loaderSync: (file, patternsFolder) => {
   return readFileSync(new URL(`./${file}`, patternsFolder));
}

cc @yashha

@mnater mnater self-assigned this Nov 22, 2023
@mnater
Copy link
Owner

mnater commented Nov 22, 2023

Thanks for pointing to this. It makes the loaders a lot simpler indeed.

@mnater mnater closed this as completed in b732a4f Nov 24, 2023
mnater added a commit that referenced this issue Nov 24, 2023
danburzo pushed a commit to danburzo/percollate that referenced this issue Nov 25, 2023
* Fixed the loading of the hyphenopoly language patterns, which did not work when using percollate programmatically. (#163)

* Update hyphenopoly after it updated the language loadaing behavior. #163
mnater/Hyphenopoly#207
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants