Closed zefhemel closed 13 years ago
Yep, npm dropped support for the modules hash. The irony is I switched to it a while back because Isaac said it was the most future proof. I'm actually not sure how to preserve the require('nstore/pluginX') style modules in the new npm. Care to submit a patch for package.json?
I had the same problem with persistence.js, also wasn't able to preserve the require('.../...') style there either.
Tried to patch it with:
"main": "lib/nstore.js",
But then there seem to be other problems. It says it cannot find the pattern
library, which, in turn probably has the same problem.
Bleh. This deprecation really requires modules to have a significant amount of code change made to the way they export. If you add:
"directories": {
"lib": "./lib",
}
to your package.json, you can then access the individual files as such:
var Queue = require('pattern/lib/pattern/queue');
But I think to properly fix this, you have to rewrite pattern in such a way that you can access the submodules like Hash and Queue through the top-level object. Something like:
var pattern = require('pattern');
var hash = pattern.hash;
var queue = pattern.queue;
And inside the pattern module's index.js, you configure your object to export hash and queue. Make sense?
Yeah, that's what I usually do. See https://github.com/creationix/creationix/blob/master/index.js for an example. I don't have time to do this right now, but I'll take a pull request.
Awesome. I'll fork & try patching this in tonight.
Hmm, I wonder if this is a good idea for pattern since the root object it the parent prototype for everything. Then all objects created would have properties stuck no them which is not good. We might need to re-think how the whole thing is structured.
It almost feels like with this new structure, you can't export multiple root objects. Hash, Queue and Pattern all have to become independently distributed & require()'d modules. That's what I mean about code changes being required. The way Pattern is written, yea, it almost requires a re-engineering.
Maybe Hash becomes PatternHash?
Or pattern (the root-level-object) becomes a creator for the 3 child objects. Something like:
var PatternGenerator = require('pattern'); // Is a singleton class, to be compatible with npm 0.3.9+
var Hash = PatternGenerator.create('hash'); // Creates a Hash object
var Queue = PatternGenerator.create('queue'); // Creates a Queue object
var Pattern = PatternGenerator.create('pattern'); // or maybe Pattern.create()?
I have the same problem :/ Is there any solution avaiable?
Any solutions / workarounds. I'm a node.js/nbm noob. So I'd appreciate some detail on the workarounds.
Fixed now. I had to refactor pattern and nstore to be friendly to the new npm.
When I install nStore with npm it seems to install fine. However, when I require('nstore'), node tells me the module cannot be found.