npm-3-troubled-case

This article has been translated from this article, original article was written by @mizchi.


I just have run npm install -g npm@3 and trying to use it today. 3.1.2 seems VERY BETA(I don’t know the actual meaning of this whether close or far from alpha), it will be major release at some future time.

a flatter node_modules directory

All of your dependencies will be sitting next to each other at the top level. Only when there are conflicts will modules be installed at deeper levels. This make things data volume reduction when there are conflicts.

“require” hasn’t changed at all

Now it has become possible to require directly not only child module but also grandchild. For example, when use foo module depended on bar module, it has become possible to do require('bar'). This means the possibility of rewritten dynamically a module required. I concerned about this problem.

An actual example

It required same module by cache when use same version between child and grandchild. From a standpoint of child module, set global option when child module assume grand child module as singleton, it suddenly has broken because of flat directory.

e.g. To use marked module

gfm-marked/gfm-marked.js

1
2
3
4
5
6
var marked = require('marked');
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true
});
module.exports = marked

not-gfm-marked/not-gfm-marked.js

1
2
3
4
5
6
var marked = require('marked');
marked.setOptions({
renderer: new marked.Renderer(),
gfm: false
});
module.exports = marked

index.js

1
2
3
4
5
6
var notGfm = require('not-gfm-marked');
var gfm = require('gfm-marked');

// There is no fenced code block,
// but it become valid by the order required
notGfm('```hello```');

It seems very rare case, but it might be so hard to resolve it. The other side, browserify doesn’t support npm@3 yet. We need to wait a little.

Thanks.

See also

good day to start blogging

I went back to the parents’ home last night for the first time in a long time. It has passed about a half-year from last time, but my family and my dog seems very well. We have got a lot of catching up to do. Especially I’d like to know if my parents has any thoughts on living abroad. I didn’t know the detail about my parent’s past, when and when did they somewhere, but I knew only the vague information that they lived somewhere in several years. I tried asking them about it, they couldn’t remember about that just because that things was a long time ago. Probably, that was vaguely fun. Anyway, I didn’t get any deep information into my hands.

Next day, I went to cool place called “OSS cafe”. Here is where many freelance worker and OSS hackers implicitly gather. Frequently they have held the event. Today “Coder Dojo” was held, to teach programming for children, children created some kind of application or game and presented about what did they do and how did it. Seems so hot, I got a motivation to create something from them. I did OSS activity to create npm and solve an issue by affected that. That’s good to relax and write a code I want and someone want.

Today was such a peaceful day.