News for hackers. Stuff that matters.
Re:Node v4.0.0 by msoad on Tuesday September 08, 2015 @03:43PM (#10187784)
When node supports `import` how you'll import node modules?

I hope it works like this

    import {readFile} from 'fs';
    import {clone} from 'lodash';
rather than explicitly providing "correct" URL to the modules.

EDIT: edited the syntax.

Re:Node v4.0.0 by codecurve on Tuesday September 08, 2015 @04:01PM (#10187887)
You'll be able to achieve that behaviour when node also supports destructuring.

    import { readFile, writeFile } from 'fs';
    import { clone } from 'lodash';
Re:Node v4.0.0 by awalGarg on Wednesday September 09, 2015 @09:37AM (#10191319)
Not really. The destructuring syntax used in the imports is not the same as the standard array and object destructuring.

Section 15.2.1.16 of the current stable ES6 specification specifies how the import syntax is resolved, and it doesn't use destructuring.

P.S. Sorry too lazy to get a clickable link from the spec :P see http://awal.js.org/especser/#15.2.1.16 if you really wanna read it

Re:Node v4.0.0 by WalterSear on Wednesday September 09, 2015 @01:05AM (#10189786)
As I understand it, that still involves importing the whole file, rather than just the part you need. If that is an issue, lodash is parted out by method, so you can do this instead:

  import clone from 'lodash/lang/clone'
Re:Node v4.0.0 by loganfsmyth on Tuesday September 08, 2015 @08:40PM (#10189024)
Just a nit, but that isn't destructuring. Named import syntax has several differences, since name aliasing uses a different format and you cannot nest or provide default values.
Re:Node v4.0.0 by msoad on Tuesday September 08, 2015 @04:07PM (#10187928)
oops I forgot the braces! ok then, it's cool. I'm happy it does resolving to node_modules and all that automatically.
Re:Node v4.0.0 by pluma on Thursday September 10, 2015 @05:37AM (#10197025)
It's just syntactic sugar for `require`, mostly. The import mechanism should behave the same.
Re:Node v4.0.0 by jkrems on Tuesday September 08, 2015 @11:42PM (#10189548)
Adding support for `import` will be a huge breaking change unless all existing packages have to opt-into it somehow. I don't think anybody has a good plan for this yet, apart from treating it as syntactic sugar for CommonJS.
Re:Node v4.0.0 by pluma on Thursday September 10, 2015 @05:41AM (#10197044)
The only problem are "default exports", i.e. overriding `module.exports` directly. In Node the exported names are just properties of the `module.exports` object but in ES6 the named exports are entirely separate from the default export. IIRC module.exports was not actually part of CommonJS although nowadays most people just use that word to mean "whatever Node does".
Re:Node v4.0.0 by nawitus on Tuesday September 08, 2015 @04:46PM (#10188132)
You can already use that syntax with Babel.
Re:Node v4.0.0 by amelius on Tuesday September 08, 2015 @04:09PM (#10187939)
I wonder how that would work asynchronously. Or when the file is used from both the browser and node.
Re:Node v4.0.0 by loganfsmyth on Tuesday September 08, 2015 @08:42PM (#10189035)
ES6 imports are declarative, so dependencies are resolved and executed before the body of the module is executed. That means you don't conceptually have to think about whether your dependencies are loading synchronously or asynchronously.
Re:Node v4.0.0 by Jimmed on Tuesday September 08, 2015 @04:15PM (#10187968)
If you're building isomorphic code for the browser using webpack, you can quite happily chunk certain modules into separate bundles which will be loaded asynchronously when needed. It's pretty awesome.