ClojureScript

Support parse.com's Cloud Code environment in :nodejs builds

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code

Description

parse.com's Cloud Code is very similar to node.js but expects no hashbang and doesn't provide util.js, so provide a compiler argument to elide the header and wrap the util.js require in a try...catch

  1. parse.patch
    09/Dec/13 4:55 PM
    1.0 kB
    Travis Vachon
  2. cljs_722.patch
    10/Dec/13 9:47 AM
    2 kB
    Travis Vachon
  3. cljs_722v2.patch
    12/Dec/13 10:53 AM
    0.9 kB
    Travis Vachon
  4. cljs_722v3.patch
    22/Jan/14 7:22 PM
    0.9 kB
    Travis Vachon

Activity

Hide
David Nolen added a comment -

Please format the patch so it can be applied with git am. See http://github.com/clojure/clojurescript/wiki/Patches

Show
David Nolen added a comment - Please format the patch so it can be applied with git am. See http://github.com/clojure/clojurescript/wiki/Patches
Hide
Travis Vachon added a comment -

git am-able patch

Show
Travis Vachon added a comment - git am-able patch
Hide
Travis Vachon added a comment -

sorry about that! will update all the tickets I've filed recently as well

Show
Travis Vachon added a comment - sorry about that! will update all the tickets I've filed recently as well
Hide
Travis Vachon added a comment -

so actually, I think a better solution to this will be to add support for :preamble as proposed here:

https://groups.google.com/forum/#!searchin/clojurescript/preamble/clojurescript/rUIlLfcYZvE/Yskfh4znL_0J

I'm imagining that the default preamble for the :nodejs target will be the hashbang

that will let us a) redefine the require function in our compiled output to squelch the util import and b) avoid writing the hashbang

Show
Travis Vachon added a comment - so actually, I think a better solution to this will be to add support for :preamble as proposed here: https://groups.google.com/forum/#!searchin/clojurescript/preamble/clojurescript/rUIlLfcYZvE/Yskfh4znL_0J I'm imagining that the default preamble for the :nodejs target will be the hashbang that will let us a) redefine the require function in our compiled output to squelch the util import and b) avoid writing the hashbang
Hide
David Nolen added a comment -

so is this ticket superseded by CLJS-723?

Show
David Nolen added a comment - so is this ticket superseded by CLJS-723?
Hide
Travis Vachon added a comment -

yeah - if I can write arbitrary js at the beginning of my compiled file I don't need this patch. Can close.

Show
Travis Vachon added a comment - yeah - if I can write arbitrary js at the beginning of my compiled file I don't need this patch. Can close.
Hide
Travis Vachon added a comment -

arg, it looks like I spoke too soon - redefining require in the cloud code env appears to be impossible. I spent a couple hours trying every scoping trick I could find - it looks like the only way to redefine require is by defining a function (assignment just doesn't seem to take) and that function is always hoisted to the very top, so there's no way to get a handle on the original require function. Parse's sandbox doesn't seem to have another way to reference require, either.

How would you feel about moving {{ (set! cljs.core/string-print (.-print (require "util"))) }} into a function node.js people can call rather than doing it when the module is loaded?

Show
Travis Vachon added a comment - arg, it looks like I spoke too soon - redefining require in the cloud code env appears to be impossible. I spent a couple hours trying every scoping trick I could find - it looks like the only way to redefine require is by defining a function (assignment just doesn't seem to take) and that function is always hoisted to the very top, so there's no way to get a handle on the original require function. Parse's sandbox doesn't seem to have another way to reference require, either. How would you feel about moving {{ (set! cljs.core/string-print (.-print (require "util"))) }} into a function node.js people can call rather than doing it when the module is loaded?
Hide
David Nolen added a comment -

Honestly I'd be happy to remove it altogether and let people just handle this themselves. Or allow people to disable it if they are using the nodejs target option.

Show
David Nolen added a comment - Honestly I'd be happy to remove it altogether and let people just handle this themselves. Or allow people to disable it if they are using the nodejs target option.
Hide
Travis Vachon added a comment -

ok great. I'm inclined to leave it in a function because it feels sort of non-obvious to me - would be nice to help people avoid reinventing in every codebase. I'll attach a new patch.

Show
Travis Vachon added a comment - ok great. I'm inclined to leave it in a function because it feels sort of non-obvious to me - would be nice to help people avoid reinventing in every codebase. I'll attach a new patch.
Hide
Travis Vachon added a comment -

add new patch that just moves the problematic require into a function. the hashbang issue the original patch addressed is better fixed with the preamble work in http://dev.clojure.org/jira/browse/CLJS-723

Show
Travis Vachon added a comment - add new patch that just moves the problematic require into a function. the hashbang issue the original patch addressed is better fixed with the preamble work in http://dev.clojure.org/jira/browse/CLJS-723
Hide
David Nolen added a comment -

Isn't this a breaking change for existing Node.js users?

Show
David Nolen added a comment - Isn't this a breaking change for existing Node.js users?
Hide
Travis Vachon added a comment -

it is yeah, I assumed that was ok because you said you'd be happy to remove it altogether - I'm ok with removing it if you think that's a preferable breaking change.

Show
Travis Vachon added a comment - it is yeah, I assumed that was ok because you said you'd be happy to remove it altogether - I'm ok with removing it if you think that's a preferable breaking change.
Hide
David Nolen added a comment -

Lets rename it to enable-util-print! to match enable-console-print!.

Show
David Nolen added a comment - Lets rename it to enable-util-print! to match enable-console-print!.
Hide
Travis Vachon added a comment -

cool! will do. I'll update the patch today.

Show
Travis Vachon added a comment - cool! will do. I'll update the patch today.
Hide
Travis Vachon added a comment -

rename function to enable-util-print!

Show
Travis Vachon added a comment - rename function to enable-util-print!

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: