Skip to content

Commit

Permalink
doc(bundle-source): describe moduleFormats
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Feb 28, 2020
1 parent deb8ee7 commit a41d67d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/bundle-source/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,34 @@ or inside an async function (and therefore outside of Jessie), do:
const { moduleFormat, source, sourceMap } = await sourceBundleP;
...
```

## getExport moduleFormat

The first main `moduleFormat` is the `"getExport"` format. It generates
source like:

```js
function getExport() {
let exports = {};
const module = { exports };
// CommonJS source translated from the inputs.
...
return module.exports;
}
```

To evaluate it and obtain the resulting module namespace, you need to endow
a `require` function to resolve external imports.

## nestedEvaluate moduleFormat

This is logically similar to the `getExport` format, except that the code
may additionally depend upon a `nestedEvaluate(src)` function to be used
to evaluate submodules in the same context as the parent function.

The advantage of this format is that it helps preserve the filenames within
the bundle in the event of any stack traces.

Also, the toplevel `getExport(filePrefix = "/bundled-source")` accepts an
optional `filePrefix` argument in order to help sanitize stack
traces (which is prepended to relative paths for the bundled files).

0 comments on commit a41d67d

Please sign in to comment.