-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic remote plugin loading? #1
Comments
script src= would take care of executing the remote script (from raw.github.com, pastebin.com/raw.php, etc.) but the package information file package.json is JSON, not JSON-P, so it cannot cross domains without server-side processing or CORS |
Found this on npm: https://github.com/crcn/plugin.js "Simple plugin system for javascript" - supports remote plugin with "dnode" https://npmjs.org/package/dnode-plugin, appears to be focused on server-side node.js however. |
First part of this in 7633174 - instantiate() now accepts a plugin factory constructor, name, opts, can be passed in directly |
Found this for CORS: http://cors.maxogden.com/ "This API enables cross-origin requests to anywhere." via https://gist.github.com/maxogden/8795074 - demo: https://robwu.nl/cors-anywhere.html source: https://github.com/Rob--W/cors-anywhere/ - could host on https://github.com/joyent/node/wiki/Node-Hosting + and also: http://allow-any-origin.appspot.com/ |
checkout requirebin.com if you haven't yet. it is using browserifyCDN. since processed modules are cached, things are fairly performant. |
http://requirebin.com https://github.com/maxogden/requirebin https://github.com/jfhbrook/browserify-cdn https://wzrd.in looks to be the closest to what I'm looking for, but maybe its possible to go further and "browserify npm" (using appropriate shims for web FS access, CORS for remote file fetching, etc.) so a remote service is not needed? $ npm install npm
$ cat try.js
var npm = require('npm');
npm.load();
npm.commands.install();
$ browserify try.js > b2.js then loading into Chrome, crashes at: /**
* Creates a Cursor instance based off the given `writable stream` instance.
*/
function ansi (stream, options) {
if (stream._ansicursor) { // <-- *** cannot read property _ansicursor of undefined
return stream._ansicursor
} else {
return stream._ansicursor = new Cursor(stream, options)
}
}
module.exports = exports = ansi from: log.cursor = ansi(process.stderr)
more progress: var Writable = require('stream').Writable;
process.stdout = new Writable();
process.stderr = new Writable();
process.stdout.write = function() {
console.log('STDOUT', arguments);
};
process.stderr.write = function() {
console.log('STDERR', arguments);
};
process.binding = function() {
return {fs: ''}
};
process.argv = ['npm'];
var npm = require('npm');
npm.load();
npm.commands.install(); now crashes on fs.stat - browserify provides an empty fs object; need to replace it with https://github.com/mmckegg/web-fs . trying to replace builtins (better way to do this?): var browserify = require('browserify');
require('browserify/lib/builtins').fs = 'node_modules/web-fs/index.js';
var b = browserify();
b.add('./try.js');
b.bundle().pipe(process.stdout); but web-fs is not completely API-compatible with fs, it requires instantiation: tmp $ cat create-webfs.js
var webfs = require('web-fs');
module.exports = webfs(); require('browserify/lib/builtins').fs = 'create-webfs.js'; this now crashes in getEntry(this.entry…), where this.entry(=root parameter) is undefined, during fs.stat(p + ext …) on "/npm". Standard error output from browserified npm is:
so there is probably much that would need to be done to make this work edit: got a "browserified npm" to at least load (few commands work) in the browser: https://github.com/deathcap/webnpm |
I've played with these ideas before, a lot of exciting potential! |
Ah, nice to see there is other interest in CORS-enabling the NPM registry, hopefully it happens! Until then I tried a couple CORS proxies deathcap/webnpm@944d03d deathcap/webnpm#1, unfortunately there are some problems. http://cors.maxogden.com/http://registry.npmjs.org and http://cors-anywhere.herokuapp.com/http://registry.npmjs.org (which run https://github.com/Rob--W/cors-anywhere/) always return |
You can now do things like: npm.commands.view(['voxel-engine']) and your browser will fetch information from the NPM registry, via the CORS proxy. Closes GH-1 Ref voxel/voxel-plugins#1
Currently plugins have to be predetermined at compile time for inclusion with browserify (require('voxel-foo'), for browserify to recognize its needed). Some kind of dynamic or remote plugin loading mechanism could be worthwhile.
Notes from voxel/voxelmetaverse#23:
voxel-plugins allows for consistently and easily loading plugins, supports dynamic enable/disable, but you still need to pre-bundle the modules in package.json for browserify to include in bundle.js. Would be neat if plugins could be dynamically loaded across the web from anywhere.
NPM modules can load arbitrarily many other modules, so a resolution process is needed — some discussion here, including an idea to browserify NPM:
browserify/browserify#314 browserify browserify
To load resources across the web: CORS, Access-Control-Allow-Origin: *. Tool for client-side OAuth to GitHub: Gatekeeper
requirebin + browserify-cdn gets very close to what I'd like, but the modules are "compiled" server-side using npm (may not be too much of a problem, though it would be nice to allow loading plugins directly from GitHub, gists, pastebin, etc. without server-side processing).
$script.get('http://example.com/foo.js', function(){}) using https://github.com/ded/script.js allows loading remote scripts (similar to script src=http://example.com/) + http://wzrd.in/ server-side compilation for dependencies?
The text was updated successfully, but these errors were encountered: