-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add bsb-js dependency * Add ReasonAsset type * Actually add the Reason asset type * Add OCaml file type, add integration test, remote unused imports * use promisify for reading files * Fix integration tests
- Loading branch information
1 parent
9f56e42
commit 47e9192
Showing
7 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const bsb = require('bsb-js'); | ||
const fs = require('fs'); | ||
const JSAsset = require('./JSAsset'); | ||
const promisify = require('../utils/promisify'); | ||
const readFile = promisify(fs.readFile); | ||
|
||
class ReasonAsset extends JSAsset { | ||
async parse(code) { | ||
// This runs BuckleScript - the Reason to JS compiler. | ||
// Other Asset types use `localRequire` but the `bsb-js` package already | ||
// does that internally. This should also take care of error handling in | ||
// the Reason compilation process. | ||
if (process.env.NODE_ENV !== 'test') { | ||
await bsb.runBuild(); | ||
} | ||
|
||
// This is a simplified use-case for Reason - it only loads the recommended | ||
// BuckleScript configuration to simplify the file processing. | ||
const outputFile = this.name.replace(/\.(re|ml)$/, '.bs.js'); | ||
const outputContent = await readFile(outputFile); | ||
this.contents = outputContent.toString(); | ||
|
||
// After loading the compiled JS source, use the normal JS behavior. | ||
return await super.parse(this.contents); | ||
} | ||
} | ||
|
||
module.exports = ReasonAsset; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var local = require('./local.re'); | ||
|
||
module.exports = function () { | ||
return local.a + local.b; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
let a = 1; | ||
|
||
let b = 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const {bundle, run, assertBundleTree} = require('./utils'); | ||
|
||
describe('reason', function() { | ||
it('should produce a bundle', async function() { | ||
let b = await bundle(__dirname + '/integration/reason/index.js'); | ||
|
||
assert.equal(b.assets.size, 2); | ||
assert.equal(b.childBundles.size, 0); | ||
|
||
let output = run(b); | ||
assert.equal(typeof output, 'function'); | ||
assert.equal(output(), 3); | ||
}); | ||
}); |