-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: This diff adds a new configuration option to Flow: `module_resolver`. It points to an executable that consumes a stream of JSON objects under the form `[request, issuer]`, and outputs a stream of paths in response. Since it's been my first work with OCaml since quite a long time there's probably errors and odity in my code, feel free to point them 🙂 Some of them I have in mind (maybe they can be fixed in a followup pass, you tell me): - The JSON payload is crafted with sprintf, I wasn't sure how to properly generate a JSON string - For the same reason, the resolver returns a stream of paths instead of an actual JSON object because I wasn't sure how to parse them in Flow - Related to the previous point, the resolver doesn't have a way to notify Flow that a request cannot be satisfied (it would be solved if the return object was a `[err, result]` entity). - If the `module_resolver` is invalid, Flow will currently hang (I thought `create_process` would "throw", but maybe it doesn't make sense in OCaml?) Closes #6132 Reviewed By: gabelevi Differential Revision: D7619501 Pulled By: arcanis fbshipit-source-id: a4bf8b89a6f94a8f1e8dac92ae1789a3c7be77f2
- Loading branch information
Maël Nison
authored and
Nat Mote
committed
Jun 5, 2018
1 parent
ed80625
commit 08b0c8f
Showing
27 changed files
with
338 additions
and
4 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
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
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 @@ | ||
[options] | ||
module.system=haste | ||
module.resolver=./resolver.js |
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,2 @@ | ||
all: false | ||
shell: test.sh |
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 @@ | ||
No errors! |
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,4 @@ | ||
// @providesModule hello | ||
// @flow | ||
|
||
require('world'); |
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,38 @@ | ||
#!/usr/bin/env node | ||
|
||
var fs = require('fs'); | ||
var StringDecoder = require('string_decoder'); | ||
|
||
var buffer = ''; | ||
var decoder = new StringDecoder.StringDecoder(); | ||
|
||
var ext = 'foo'; | ||
|
||
process.stdin.on('data', function (chunk) { | ||
buffer += decoder.write(chunk); | ||
|
||
do { | ||
var index = buffer.indexOf('\n'); | ||
if (index === -1) { | ||
break; | ||
} | ||
|
||
var line = buffer.slice(0, index); | ||
buffer = buffer.slice(index + 1); | ||
|
||
try { | ||
var path = __dirname + '/' + JSON.parse(line)[0] + '.' + ext + '.js'; | ||
if (fs.existsSync(path)) { | ||
process.stdout.write(JSON.stringify([null, path]) + '\n'); | ||
} else { | ||
process.stdout.write(JSON.stringify([{ | ||
message: `File not found`, | ||
}, null]) + '\n'); | ||
} | ||
} catch (error) { | ||
process.stdout.write(JSON.stringify([{ | ||
message: error.message, | ||
}, null]) + '\n'); | ||
} | ||
} while (true); | ||
}); |
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 @@ | ||
#!/bin/bash | ||
. ../assert.sh | ||
FLOW=$1 | ||
|
||
assert_ok "$FLOW" status . |
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,4 @@ | ||
// @providesModule world | ||
// @flow | ||
|
||
require('hello'); |
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 @@ | ||
[options] | ||
module.system=haste | ||
module.resolver=<PROJECT_ROOT>/resolver.js |
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,2 @@ | ||
all: false | ||
shell: test.sh |
1 change: 1 addition & 0 deletions
1
tests/custom-resolver-projectroot/custom-resolver-projectroot.exp
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 @@ | ||
No errors! |
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,4 @@ | ||
// @providesModule hello | ||
// @flow | ||
|
||
require('./world'); |
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,38 @@ | ||
#!/usr/bin/env node | ||
|
||
var fs = require('fs'); | ||
var StringDecoder = require('string_decoder'); | ||
|
||
var buffer = ''; | ||
var decoder = new StringDecoder.StringDecoder(); | ||
|
||
var ext = 'foo'; | ||
|
||
process.stdin.on('data', function (chunk) { | ||
buffer += decoder.write(chunk); | ||
|
||
do { | ||
var index = buffer.indexOf('\n'); | ||
if (index === -1) { | ||
break; | ||
} | ||
|
||
var line = buffer.slice(0, index); | ||
buffer = buffer.slice(index + 1); | ||
|
||
try { | ||
var path = __dirname + '/' + JSON.parse(line)[0] + '.' + ext + '.js'; | ||
if (fs.existsSync(path)) { | ||
process.stdout.write(JSON.stringify([null, path]) + '\n'); | ||
} else { | ||
process.stdout.write(JSON.stringify([{ | ||
message: `File not found`, | ||
}, null]) + '\n'); | ||
} | ||
} catch (error) { | ||
process.stdout.write(JSON.stringify([{ | ||
message: error.message, | ||
}, null]) + '\n'); | ||
} | ||
} while (true); | ||
}); |
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 @@ | ||
#!/bin/bash | ||
. ../assert.sh | ||
FLOW=$1 | ||
|
||
assert_ok "$FLOW" status . |
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,4 @@ | ||
// @providesModule world | ||
// @flow | ||
|
||
require('hello'); |
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 @@ | ||
[options] | ||
module.resolver=./resolver.js | ||
module.system=haste |
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,2 @@ | ||
all: false | ||
shell: test.sh |
Oops, something went wrong.