MihaiValentin / lunr-languages

A collection of languages stemmers and stopwords for Lunr Javascript library
Other
431 stars 163 forks source link

Add index file to fix includes require problems with nodejs #25

Open polo2ro opened 7 years ago

polo2ro commented 7 years ago

I got some problems with nodejs and the migration from npm 2 to npm 3. This is a proposal to fix the issue, with for example:

const lunrLanguages = require('lunr-languages'); ... lunrLanguages.stemmer(lunr); lunrLanguages.fr(lunr);

npm 2 and npm 3 do not host file at the same place so direct use of require() is not possible

MihaiValentin commented 7 years ago

Hi @polo2ro and thanks a lot for proposing this MR!

Adding all the languages in a single index file seems a nice idea, but generally lunr and lunr-languages usecase is to use a single language, depending of the locale of the project.

IIRC requiring lunar-languages/index.js will automatically import ALL the languages, which would add quite some bloat.

Regarding npm version, can you please detail the problem? Thanks!

polo2ro commented 7 years ago

Hi, The root problem is the compatibility with npm 2 and 3 because folder structure has been modified. My project was build with npm 2, then i deleted my node_modules folder and install with npm v3

here is a commit in my project where i changed the code compatible with npm 2 : https://github.com/polo2ro/hexo-generator-lunr/commit/deee214a1cab10a2ca49838d780fd189a425ec08#diff-b58e2f1cee2acff55355343774e6d576

Here is the npm doc where the new folder structure is explained: https://docs.npmjs.com/how-npm-works/npm3

with npm2 the structure was:

with npm3 the structure is:

Let me know if i can work on this the way you want it. maybe i can return an object with some loading functions for each languages?