keithwhor / nodal

API Services Made Easy With Node.js
http://www.nodaljs.com/
MIT License
4.51k stars 209 forks source link

use of require within module.exports #216

Closed reggi closed 8 years ago

reggi commented 8 years ago

Just got one of your emails so I'm hoping this feedback is solicited.

I'm looking through the docs and I'm seeing a lot of references to module.exports and calling require through your codebase. These two things erk me a bit because they don't mesh well with ES6.

In ES6 import needs to be a top level function, and those pesky requires are a bit odd.

Thoughts on this would be appreciated.

This is so odd to me...

module.exports = (() => {

  'use strict';

  const Command = require('cmnd').Command;

  const fs = require('fs-extra');
  const path = require('path');
  const inquirer = require('inquirer');
  const inflect = require('i')();
  const colors = require('colors/safe');
  const async = require('async');
  const http = require('http');
keithwhor commented 8 years ago

Hey! Thanks for checking everything out.

You're right. We can change this design pattern, and should in the future.

Ideally, imports first, immediately followed by the module.exports line. Would like to keep the IIFE there for now until we're using native exports. I haven't been following node 5.x development lately, do you have a ref for when we'll see import / export land? (Quickly searching yielded nothing of interest.)

reggi commented 8 years ago

@keithwhor Thanks for the quick response. Not exactly sure when it will land in as official syntax, I've been using babel in my personal projects. Are you against using babel?

keithwhor commented 8 years ago

No problem. Working all the time. :)

Yeah, I am. For the front-end I can see why it makes sense --- browser vendors have wildly different implementations. Babel fills the same niche jQuery used to, except for higher level syntax instead of the DOM API.

Here I want to avoid build steps because it's very important to me that the solution I provide is lightweight and easy to debug. I'd rather stay in the (still very fast moving!) world of what V8 provides natively.