Closed mattapperson closed 10 years ago
Perhaps if guidance were given as to how you would like to see this implemented, others could help? ;)
Definitely a good feature to have. Let me give this a little thought tonight and I'll try to give us something to chew on by tomorrow. My first off-the-top thought is that requires would be relative to the directory from which you called triple
. We could use the node.js require.resolve
to establish exactly which file, and either push it to the build folder of the repl and then require it from within the app or if there's a way, push the content of the file through the socket and then load it that way. I'm guessing the former would be better.
If this executes in context to a ti project, wouldn't you get that for free anyway?
Sent from my iPhone
On Jul 24, 2014, at 11:21 PM, Tony Lukasavage notifications@github.com wrote:
Definitely a good feature to have. Let me give this a little thought tonight and I'll try to give us something to chew on by tomorrow. My first off-the-top thought is that requires would be relative to the directory from which you called triple. We could use the node.js require.resolve to establish exactly which file, and either push it to the build folder of the repl and then require it from within the app or if there's a way, push the content of the file through the socket and then load it that way. I'm guessing the former would be better.
— Reply to this email directly or view it on GitHub.
Right, but if the files aren't already in the project, where are you going to require them from? That's the problem we're trying to solve
@tonylukasavage you could symlink (only works for sim) the process.cwd()
as a special directory name in the Resources and then load from folder (from Ti) instead of trying to push sources.
I'm thinking maybe .include (files) and .module (module) commands might be better? Just a thought
@mattapperson I like the idea of something like .include
or .add
for adding arbitrary files to the REPL, as an entirely separate issue. I don't like .module
though, we should just use require()
. I've already got acorn in the project for validating syntax, so we can use that to find any requires in the input, perhaps use the implementation of .include
under-the-hood, then the require()
will work just as the developer would expect. The only addition to that is that I stand by what I said originally that I think node.js's require.resolve()
should be used relative to process.cwd
to establish exactly what the developer is trying to require. I think for this pass single file requires should be supported, but perhaps in a future ticket we can try to address requires that contain requires themselves. But that is much more complex and time-consuming as you'll have to AST parse every required file, which I'm not psyched about the negative impact that will have on UX initially.
@jhaynie I'd rather try to find a way that will work for all platforms in one shot, rather than add even one more ounce of something that would only work for iOS. We should be able to push files to the appropriate place in the build folder. I think if I get clever enough I can actually use a CLI hook to establish the build folder for the current platform and deploy type, pass that back through the socket to the REPL, and then be able to use a single code base for supporting this on all platforms.
I was thinking include for is files and .module for native ti modules
Interesting, .module
might tricky... I think those need to get loaded before the app is started. Can you add native modules to an already running project dynamically?
Well no (not on iOS). But I was thinking maybe it would auto save state or something and reload with the module?
I'd rather see the following as separate issues:
Require we get free from the SDKif we do the other two correct
.module
might even just be a specialized version of .include
, that takes the name of a native Titanium module, searches the typical places for it, then does an .include
on all the necessary files. Still doesn't solve the dynamic loading problem, but that might just have to be a TIMOB ticket in the end unless someone comes up with a clever hack, or simply an API I've never heard of.
I don't think it even can be done on iOS dynamicly. I mean it "can" but it would be kinda a nasty hacky bugy thing
Maybe native modules are added via a CLI flag when its started?
something like that might be the only way to do it initially
I'lltry and get this ticket knocked out Monday if no one else grabs it by then
Got at least a little done tonight :)
Closing and have broken these down into more specific issues:
The Node REPL allows for modules (both "native" and JS based). It would be great if this could support that as well.