Closed rosano closed 1 year ago
Hmm, I know at least one instance of 2.0 (beta.3) running with node.js in production:
https://github.com/67P/hubot-remotestorage-logger/blob/master/package.json#L22
Can you link the code to reproduce it perhaps?
It seems to me that in the following code:
features-loaded
is emittedstoreFile
doesn't resolvevar Bookmarks = { name: 'bookmarks', builder: function(privateClient, publicClient) {
return {
exports: {
addBookmark: function(bookmark) {
return privateClient.storeFile('application/json', bookmark.id, bookmark);
}
}
}
}};
const remoteStorage = new RemoteStorage({ modules: [ Bookmarks ] });
'not-connected,connected,disconnected,error,features-loaded,connecting,authing,wire-busy,wire-done,sync-req-done,sync-done,network-offline,network-online,sync-interval-change'.split(',').forEach(function (e) {
remoteStorage.on(e, function() {
console.log('did emit ' + e);
});
});
remoteStorage.access.claim('bookmarks', 'rw');
console.log('did write', await remoteStorage.bookmarks.addBookmark({
id: 'alfa',
url: 'http://unhosted.org',
description: 'Unhosted Adventures',
tags: ['unhosted', 'remotestorage', 'no-backend']
}));
Here is a small package if that's helpful: Archive.zip
I hotfixed the release/remotestorage.js
file (replacing exports=XMLHttpRequest
with exports=(typeof XMLHttpRequest === 'undefined' ? null : XMLHttpRequest)
) to avoid crashing on nodejs, maybe it wasn't a good idea?
Looks like we lost the documentation about bringing your own XMLHttpRequest
or Fetch
when using node.js. Here's an adapted version, which also logs and uses the ready
event and it works just fine on node.js 16:
https://gist.github.com/raucao/c2d3c4d95fbd9bc138df13010b891a32
This updated version also shows that the bookmark is there (in memory).
Our documentation should also note that Node v18 includes fetch natively.
Ok, should I try a PR to check for node < 18 and at log/warn/throw? Or is this the kind of thing that should only be in documentation?
Either way, I think it should be documented in https://remotestoragejs.readthedocs.io/en/latest/nodejs.html.
I'm finally trying to migrate from 1.x and am having some trouble with my libraries that include rs.js via nodejs. Basically my mocha tests are all timing out because they're waiting for rs.js to return or resolve promises.
It seems to me that on nodejs:
ready
event is now not emittedput
methods get called, so I might be stuck when writing to write a file.Any pointers as to what might have changed for nodejs?