-
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.
module.system.node.allow_root_relative
Summary: #8156 made me aware that some users want to be able to import their code using root-relative paths. They were misusing `module.system.node.resolve_dirname`, which worked for them due to a bug, and experiencing odd behaviors. This stack of diffs demonstrates the behavior, fixes the bug (breaking the use case), and adds first-class support for this use case. This diff adds a new `.flowconfig` option which allows you to import modules using a root-relative path. Reviewed By: jbrown215 Differential Revision: D18190689 fbshipit-source-id: e61325ee847361a2873327b8302f3662799d6f58
- Loading branch information
1 parent
11d5b89
commit c6a56c6
Showing
17 changed files
with
358 additions
and
1 deletion.
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
2 changes: 2 additions & 0 deletions
2
tests/config_module_system_node_allow_root_relative/.flowconfig
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 @@ | ||
[options] | ||
module.system.node.allow_root_relative=true |
4 changes: 4 additions & 0 deletions
4
tests/config_module_system_node_allow_root_relative/ambiguous.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,4 @@ | ||
// @flow | ||
|
||
const value: "user_code" = "user_code"; | ||
export default value; |
238 changes: 238 additions & 0 deletions
238
..._module_system_node_allow_root_relative/config_module_system_node_allow_root_relative.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,238 @@ | ||
Error ----------------------------------------------------------------------------------------------- subdir/test.js:7:2 | ||
|
||
Cannot cast `ambiguous` to empty because string literal `user_code` [1] is incompatible with empty [2]. | ||
|
||
subdir/test.js:7:2 | ||
7| (ambiguous: empty) | ||
^^^^^^^^^ | ||
|
||
References: | ||
ambiguous.js:3:14 | ||
3| const value: "user_code" = "user_code"; | ||
^^^^^^^^^^^ [1] | ||
subdir/test.js:7:13 | ||
7| (ambiguous: empty) | ||
^^^^^ [2] | ||
|
||
|
||
Error ---------------------------------------------------------------------------------------------- subdir/test.js:10:2 | ||
|
||
Cannot cast `sub_ambiguous` to empty because string literal `user_code` [1] is incompatible with empty [2]. | ||
|
||
subdir/test.js:10:2 | ||
10| (sub_ambiguous: empty) | ||
^^^^^^^^^^^^^ | ||
|
||
References: | ||
subdir/ambiguous.js:3:14 | ||
3| const value: "user_code" = "user_code"; | ||
^^^^^^^^^^^ [1] | ||
subdir/test.js:10:17 | ||
10| (sub_ambiguous: empty) | ||
^^^^^ [2] | ||
|
||
|
||
Error ---------------------------------------------------------------------------------------------- subdir/test.js:14:2 | ||
|
||
Cannot cast `user_code` to empty because string literal `user_code` [1] is incompatible with empty [2]. | ||
|
||
subdir/test.js:14:2 | ||
14| (user_code: empty) | ||
^^^^^^^^^ | ||
|
||
References: | ||
user_code.js:3:14 | ||
3| const value: "user_code" = "user_code"; | ||
^^^^^^^^^^^ [1] | ||
subdir/test.js:14:13 | ||
14| (user_code: empty) | ||
^^^^^ [2] | ||
|
||
|
||
Error ---------------------------------------------------------------------------------------------- subdir/test.js:17:2 | ||
|
||
Cannot cast `sub_user_code` to empty because string literal `user_code` [1] is incompatible with empty [2]. | ||
|
||
subdir/test.js:17:2 | ||
17| (sub_user_code: empty) | ||
^^^^^^^^^^^^^ | ||
|
||
References: | ||
subdir/user_code.js:3:14 | ||
3| const value: "user_code" = "user_code"; | ||
^^^^^^^^^^^ [1] | ||
subdir/test.js:17:17 | ||
17| (sub_user_code: empty) | ||
^^^^^ [2] | ||
|
||
|
||
Error ---------------------------------------------------------------------------------------------- subdir/test.js:21:2 | ||
|
||
Cannot cast `node_code` to empty because string literal `node_code` [1] is incompatible with empty [2]. | ||
|
||
subdir/test.js:21:2 | ||
21| (node_code: empty) | ||
^^^^^^^^^ | ||
|
||
References: | ||
node_modules/node_code.js:3:14 | ||
3| const value: "node_code" = "node_code"; | ||
^^^^^^^^^^^ [1] | ||
subdir/test.js:21:13 | ||
21| (node_code: empty) | ||
^^^^^ [2] | ||
|
||
|
||
Error ---------------------------------------------------------------------------------------------- subdir/test.js:24:2 | ||
|
||
Cannot cast `sub_node_code` to empty because string literal `node_code` [1] is incompatible with empty [2]. | ||
|
||
subdir/test.js:24:2 | ||
24| (sub_node_code: empty) | ||
^^^^^^^^^^^^^ | ||
|
||
References: | ||
node_modules/subdir/node_code.js:3:14 | ||
3| const value: "node_code" = "node_code"; | ||
^^^^^^^^^^^ [1] | ||
subdir/test.js:24:17 | ||
24| (sub_node_code: empty) | ||
^^^^^ [2] | ||
|
||
|
||
Error --------------------------------------------------------------------------------------------- subdir/test.js:27:25 | ||
|
||
Cannot resolve module `nonexistent`. | ||
|
||
27| import nonexistent from 'nonexistent' | ||
^^^^^^^^^^^^^ | ||
|
||
|
||
Error --------------------------------------------------------------------------------------------- subdir/test.js:28:29 | ||
|
||
Cannot resolve module `subdir/nonexistent`. | ||
|
||
28| import sub_nonexistent from 'subdir/nonexistent' | ||
^^^^^^^^^^^^^^^^^^^^ | ||
|
||
|
||
Error ------------------------------------------------------------------------------------------------------ test.js:5:2 | ||
|
||
Cannot cast `ambiguous` to empty because string literal `user_code` [1] is incompatible with empty [2]. | ||
|
||
test.js:5:2 | ||
5| (ambiguous: empty) | ||
^^^^^^^^^ | ||
|
||
References: | ||
ambiguous.js:3:14 | ||
3| const value: "user_code" = "user_code"; | ||
^^^^^^^^^^^ [1] | ||
test.js:5:13 | ||
5| (ambiguous: empty) | ||
^^^^^ [2] | ||
|
||
|
||
Error ------------------------------------------------------------------------------------------------------ test.js:8:2 | ||
|
||
Cannot cast `sub_ambiguous` to empty because string literal `user_code` [1] is incompatible with empty [2]. | ||
|
||
test.js:8:2 | ||
8| (sub_ambiguous: empty) | ||
^^^^^^^^^^^^^ | ||
|
||
References: | ||
subdir/ambiguous.js:3:14 | ||
3| const value: "user_code" = "user_code"; | ||
^^^^^^^^^^^ [1] | ||
test.js:8:17 | ||
8| (sub_ambiguous: empty) | ||
^^^^^ [2] | ||
|
||
|
||
Error ----------------------------------------------------------------------------------------------------- test.js:12:2 | ||
|
||
Cannot cast `user_code` to empty because string literal `user_code` [1] is incompatible with empty [2]. | ||
|
||
test.js:12:2 | ||
12| (user_code: empty) | ||
^^^^^^^^^ | ||
|
||
References: | ||
user_code.js:3:14 | ||
3| const value: "user_code" = "user_code"; | ||
^^^^^^^^^^^ [1] | ||
test.js:12:13 | ||
12| (user_code: empty) | ||
^^^^^ [2] | ||
|
||
|
||
Error ----------------------------------------------------------------------------------------------------- test.js:15:2 | ||
|
||
Cannot cast `sub_user_code` to empty because string literal `user_code` [1] is incompatible with empty [2]. | ||
|
||
test.js:15:2 | ||
15| (sub_user_code: empty) | ||
^^^^^^^^^^^^^ | ||
|
||
References: | ||
subdir/user_code.js:3:14 | ||
3| const value: "user_code" = "user_code"; | ||
^^^^^^^^^^^ [1] | ||
test.js:15:17 | ||
15| (sub_user_code: empty) | ||
^^^^^ [2] | ||
|
||
|
||
Error ----------------------------------------------------------------------------------------------------- test.js:19:2 | ||
|
||
Cannot cast `node_code` to empty because string literal `node_code` [1] is incompatible with empty [2]. | ||
|
||
test.js:19:2 | ||
19| (node_code: empty) | ||
^^^^^^^^^ | ||
|
||
References: | ||
node_modules/node_code.js:3:14 | ||
3| const value: "node_code" = "node_code"; | ||
^^^^^^^^^^^ [1] | ||
test.js:19:13 | ||
19| (node_code: empty) | ||
^^^^^ [2] | ||
|
||
|
||
Error ----------------------------------------------------------------------------------------------------- test.js:22:2 | ||
|
||
Cannot cast `sub_node_code` to empty because string literal `node_code` [1] is incompatible with empty [2]. | ||
|
||
test.js:22:2 | ||
22| (sub_node_code: empty) | ||
^^^^^^^^^^^^^ | ||
|
||
References: | ||
node_modules/subdir/node_code.js:3:14 | ||
3| const value: "node_code" = "node_code"; | ||
^^^^^^^^^^^ [1] | ||
test.js:22:17 | ||
22| (sub_node_code: empty) | ||
^^^^^ [2] | ||
|
||
|
||
Error ---------------------------------------------------------------------------------------------------- test.js:25:25 | ||
|
||
Cannot resolve module `nonexistent`. | ||
|
||
25| import nonexistent from 'nonexistent' | ||
^^^^^^^^^^^^^ | ||
|
||
|
||
Error ---------------------------------------------------------------------------------------------------- test.js:26:29 | ||
|
||
Cannot resolve module `subdir/nonexistent`. | ||
|
||
26| import sub_nonexistent from 'subdir/nonexistent' | ||
^^^^^^^^^^^^^^^^^^^^ | ||
|
||
|
||
|
||
Found 16 errors |
4 changes: 4 additions & 0 deletions
4
tests/config_module_system_node_allow_root_relative/node_modules/ambiguous.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
tests/config_module_system_node_allow_root_relative/node_modules/node_code.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
tests/config_module_system_node_allow_root_relative/node_modules/subdir/ambiguous.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
tests/config_module_system_node_allow_root_relative/node_modules/subdir/node_code.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
tests/config_module_system_node_allow_root_relative/subdir/ambiguous.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,4 @@ | ||
// @flow | ||
|
||
const value: "user_code" = "user_code"; | ||
export default value; |
28 changes: 28 additions & 0 deletions
28
tests/config_module_system_node_allow_root_relative/subdir/test.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,28 @@ | ||
// @flow | ||
// Same file as test.js in the root directory. | ||
// This tests that the paths really are root-relative | ||
|
||
// These exist in both user code and node_modules, but user code wins | ||
import ambiguous from 'ambiguous'; | ||
(ambiguous: empty) | ||
|
||
import sub_ambiguous from 'subdir/ambiguous'; | ||
(sub_ambiguous: empty) | ||
|
||
// These exist in only user code | ||
import user_code from 'user_code'; | ||
(user_code: empty) | ||
|
||
import sub_user_code from 'subdir/user_code'; | ||
(sub_user_code: empty) | ||
|
||
// These exist in only node code | ||
import node_code from 'node_code'; | ||
(node_code: empty) | ||
|
||
import sub_node_code from 'subdir/node_code'; | ||
(sub_node_code: empty) | ||
|
||
// These exist nowhere | ||
import nonexistent from 'nonexistent' | ||
import sub_nonexistent from 'subdir/nonexistent' |
Oops, something went wrong.