#haraka

/

      • _smf_1 joined the channel
      • _smf_ has quit
      • DoubleMalt has quit
      • dopesong joined the channel
      • DoubleMalt joined the channel
      • dopesong has quit
      • dopesong joined the channel
      • dopesong has quit
      • dopesong joined the channel
      • dopesong has quit
      • dopesong joined the channel
      • dopesong_ joined the channel
      • dopesong has quit
      • bmonty joined the channel
      • bmonty
        hi all, if I want to test making plugins as a package, is that code in the master branch on github?
      • baudehlo
        yes. I haven't tried it though so you're in a bit of a no mans land.
      • bmonty
        that’s fine
      • I’m planning on replacing my current private mail setup with haraka and I’m working on a plugin to do auth against mongo
      • cek has quit
      • cek joined the channel
      • so, haraka can’t load a plugin if the module is installed in the directory created with “haraka -i”
      • baudehlo
        There may be bugs around that.
      • You may be best off waiting for ultimatt to arrive - he's the one who updated the plugin code to allow for node_modules to work.
      • (he's US west coast)
      • bmonty
        sounds good
      • I’m taking a look at making a patch, but if it’s already done I can wait
      • dopesong_ has quit
      • EyePulp joined the channel
      • well, I made it work…but it’s a real hack job
      • bmonty has quit
      • DoubleMalt has quit
      • bmonty joined the channel
      • ultimatt joined the channel
      • teknix_ joined the channel
      • JinOz has quit
      • JinOz joined the channel
      • EyePulp
        yo ho ho
      • quick question on access.domains - how does the parsing work if I have a few blank lines, some # comments, a few lines of domain rules and then repeat the pattern a few times? Does it care about the blanks/comments in the middle of the file (my read of the source says it doesn't)
      • ultimatt
        no, it doesn't
      • care about blank / empty lines
      • EyePulp
        danke
      • ultimatt
        bitte
      • bmonty joined the channel
      • bmonty
        ultimatt: are you working on anything to load plugins from modules stored in the node_modules folder of a haraka config directory?
      • ultimatt
        bmonty: no
      • dopesong joined the channel
      • that could be interesting...rather than stuffing modules into plugin dir
      • and ~haraka/plugins
      • bmonty
        that’s what I was thinking
      • baudehlo mentioned you may have been working on it
      • ultimatt
        what I've added is making haraka/plugins a bit more like npm
      • in that now haraka/plugins/plugin_name can be a dir instead of a file
      • ie, haraka/plugins/plugin_name/index.js
      • and there's an open PR to increase that support, to also look for a package.json file and follow it's directives
      • so that plugins could be "npm installed"
      • which I think works better than having Haraka depend on globally installed modules
      • bmonty
      • ultimatt
        how do you manage version dependencies?
      • bmonty
        i’ve been messing around with it
      • ultimatt
        IE, when haraka/package.json expects a newer version?
      • bmonty
        that’s a horrible hack I came up with
      • ultimatt
        ohhhhhh, you're loading npm modules from Haraka/node_modules
      • not $GLOBAL_NODE/node_modules
      • I see
      • umm, that's better than what I thought you were talking about
      • _smf_1
        bmonty: wouldn't it be a bit less hacky if you used process.env('HARAKA_DIR') instead of process.cwd() ??
      • _smf_1 is now known as _smf_
      • bmonty
        possibly, I didn’t know about HARAKA_DIR
      • _smf_
        Otherwise it looks OK.
      • ultimatt
        well, it's still sorta hacky
      • as it doesn't have the "npm module awareness"
      • _smf_
        I'm not sure I follow?
      • ultimatt
        it's only going to work for certain npm modules
      • bmonty
        I’d like to have it look at packages.json
      • but making that work is a huge change to the plugin loader
      • ultimatt
        bmonty: exactly
      • full_paths.push(path.resolve(pp, name) + '/' + name + '.js')
      • _smf_
        So basically - it requires that the plugin have <plugin_name>.js in it's root to work correctly.
      • ultimatt
        that's a step forward, but it really ought to be doing the same resolution of names as this:
      • bmonty
        _smf_: yes
      • _smf_
        Instead of reading index.js or whatever is defined in packages.js
      • ultimatt is looking for the npmjs.org link which describes that name resolution process
      • bmonty
        there’s a package for the loader that npm uses
      • you can depend on it and get the same functionality
      • actually, I think require is smart enough to use packages.json as well
      • ultimatt
        that sounds promising...
      • bmonty
        I was just having trouble fooling the plugin loader into believing a plugin exists in the first place
      • ultimatt
        your change helps in that regard
      • _smf_
        Anyway - having a plugin work correctly from <haraka_install_dir>/node_modules/<package_name> would be pretty nice.
      • ultimatt
        agreed.
      • bmonty, "here’s a package for the loader that npm uses" <--- got a URL for that?
      • _smf_
        bmonty: check out the HARAKA_DIR environment variable. It always gets set, so is likely much safer than process.cwd().
      • bmonty
      • _smf_: I’ll check that out
      • ultimatt
        bmonty: excellent, thanks
      • bmonty
        ultimatt: but, I don’t think it’s needed
      • ultimatt
        well, the goal here is to make our plugin logic simpler
      • so that ./plugins or ../node_modules/ will load a npm module
      • and obey the *same* rules as npm module
      • bmonty
        the code at the top of plugins._load_and_compile_plugin is the problem I think
      • ultimatt
        which means that within a npm package, we'll honor dir/index.js, or dir/bin.js, or whatever package.json points to
      • bmonty
        it only looks for a .js file
      • ultimatt
        right, but what if my npm package is foo/bar.js?
      • bmonty
        I think it could be modified to try for the package.json instead of .js
      • require knows how to read the package.json
      • loading the module isn’t really the issue…it’s getting haraka to think the module exists :)
      • ultimatt
        actually, both are issues
      • if _get_plugin_paths() is modified to add ../node_modules
      • then the only issue remaining is making sure we follow npm semantics
      • _smf_
        bmonty/ultimatt: I just checked; bmonty is right. If you do a: var foo = require('./foo') and 'foo' is a directory containing index.js then it reads index.js
      • ultimatt
        _smf_, I know, I made that change.
      • but what about when the file isn't named index.js, and isn't named package/package.js?
      • that's when npm module loading will fail
      • and that's when we want to read package.json and follow the 'bin' directive
      • or 'main'
      • basically, obey the same semantics as 'read-package-json'
      • _smf_
        ultimatt: it's main, not bin.
      • bin is what npm installes in the bin directory
      • ultimatt
        right
      • _smf_
        Ok - bmonty is right; require() honours package.json
      • I've just tried it.
      • If you create foo/package.json and add main: 'lib/foo.js'
      • bmonty
        I was just looking for the reference on that
      • I know I read it earlier today
      • _smf_
        Then create the necessary directories and file; doing a require('./foo') will read package.json, find main and then load lib/foo.js
      • ultimatt
        excellent
      • bmonty
      • _smf_
        So - it should be as easy as adding ../node_modules/plugin_name to the paths.
      • And changing the require() to just load the basename without any extension
      • bmonty
        _load_and_compile_plugin needs some updating to make that work
      • I tried to load a .js file
      • it*
      • and if the file doesn’t exist it throws an error
      • I’m thinking I could add a check for package.json in the catch block
      • ultimatt
        actually, the haraka path is at process.env.HARAKA
      • bmonty
        _smf_: doesn’t look like HARAKA_DIR gets defined
      • ah
      • ok
      • ultimatt
        and optionally, process.env.HARAKA_PLUGIN_PATH
      • _smf_
        Ooops - sorry; yeah; process.env('HARAKA');
      • bmonty
        process.env.HARAKA works
      • _smf_
        bmonty: in load_and_compile_plugin
      • You should be able to just change this:
      • rf = fs.readFileSync(fp[i]);
      • to
      • rf = require(fp[i]);
      • ultimatt
      • _smf_
        And it should still work I think.
      • ultimatt
        right?