Skip to content
Michael Bullington edited this page Jul 8, 2015 · 3 revisions

This is a quick step-by-step guide on how calzone works internally. Thankfully, the Builder/Compiler/Patcher/Scraper classes abstract this all out for you.

Classes:

  • Builder - High level abstraction for the calzone building process.

  • Compiler - Compiles a wrapper.js file using various sources.

  • Patcher - Patches JS code into the dart2js output, removes main method, removes dart2js typedef checking. If the target is for node.js, it also injects a custom node.js preamble.

  • Scraper - A patched version of the dart2js output with a scraper file that prints to JSON.

Steps:

  1. Dart file is built using dart2js (optionally minified), and exports an .info.json file.

  2. The dart2js output is 'scraped'. A file is patched into the output that will format a list of mangled names for libraries/classes/functions/fields, and print that to JSON. The Scraper then runs the patched file in node.js and returns the decoded JSON. The compiler will use this to get mangled names.

  3. A wrapper is compiled from the dart2js output with the Compiler class. The Compiler class will take information from three sources to build the wrapper.

  • .info.json - The .info.json file provides information about classes, fields, functions, and libraries. This is the main source calzone uses to compile the wrapper.

  • Scraper Output - As explained in Step #2, the Compiler uses the output from the scraper to get access to the mangled names of functions, classes, and fields. Theoretically, we could do this from the wrapper at runtime. However, doing as much as possible in the compile step is a big boost in startup time.

  • Analyzer - We use the Dart Analyzer library (along with a fork of the analysis library tweaked for our needs, check it out here). This lets us identify methods that are setters or getters (.info.json doesn't reliably provide that information). It also gives us a list of static fields, and any default values for functions.

  1. The compiled wrapper is patched into the dart2js output.

  2. This is the final file (without any minification or Browserify, we use those as a further step in IOT-DSA/sdk-dslink-javascript, but that is not within the scope of this page). Some of our transformers might use CommonJS or node.js modules, so if you use any of those and want to run this on the browser, you'll also want to use Browserify/Webpack/whatever.

Clone this wiki locally