Gozala / scratch-kit

Scratchpad for add-on SDK
https://addons.mozilla.org/en-US/firefox/addon/scratch-kit/
15 stars 5 forks source link

easier to make 'require' work with existing addon scope #13

Open gregglind opened 12 years ago

gregglind commented 12 years ago

from an addon's 'main' sandbox,

 scratchpad({'sandbox': this})

how to adapt 'core.js' to allow

 require('some_other_module')  // or  require('api-uitls/something') 

to work?

(useful for addon development)

gregglind commented 12 years ago

I got this far, but it's clearly not quite right :)

function baseURI() { // return prefs.base || env.CFX_BASE || 'resource:///modules/' return "resource://testpilot2-at-ux-dot-mozilla-dot-org/" }

 let paths = {
    '/': 'file:///',
    '': baseURI(),
    "./": "resource://testpilot2-at-ux-dot-mozilla-dot-org/testpilot2/lib/"
  };

let loader = Loader({
  paths: paths
});

let require = Require(loader,{'id':'','uri':baseURI()});

let tputils = require("testpilot2/lib/tputils");

console.log(typeof tputils.In);

console.log(uneval(tputils.In));

console.log(require('./status'));  // doesn't quite work?