File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -34,17 +34,19 @@ class ModuleScopePlugin {
34
34
// Resolve the issuer from our appSrc and make sure it's one of our files
35
35
// Maybe an indexOf === 0 would be better?
36
36
const relative = path . relative ( appSrc , request . context . issuer ) ;
37
- // If we go back , not our request!
37
+ // If it's not in src/ or a subdirectory , not our request!
38
38
if ( relative [ 0 ] === '.' ) {
39
39
return callback ( ) ;
40
40
}
41
+ // Find path from src to the requested file
41
42
const requestRelative = path . relative (
42
43
appSrc ,
43
44
path . resolve (
44
45
path . dirname ( request . context . issuer ) ,
45
46
request . __innerRequest_request
46
47
)
47
48
) ;
49
+ // Error if in a parent directory of src/
48
50
if ( requestRelative [ 0 ] === '.' ) {
49
51
callback (
50
52
new Error (
Original file line number Diff line number Diff line change @@ -107,7 +107,14 @@ module.exports = {
107
107
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
108
108
'react-native' : 'react-native-web' ,
109
109
} ,
110
- plugins : [ new ModuleScopePlugin ( paths . appSrc ) ] ,
110
+ plugins : [
111
+ // Prevents users from importing files from outside of src/ (or node_modules/).
112
+ // This often causes confusion because we only process files within src/ with babel.
113
+ // To fix this, we prevent you from importing files out of src/ -- if you'd like to,
114
+ // please link the files into your node_modules/ and let module-resolution kick in.
115
+ // Make sure your source files are compiled, as they will not be processed in any way.
116
+ new ModuleScopePlugin ( paths . appSrc ) ,
117
+ ] ,
111
118
} ,
112
119
module : {
113
120
strictExportPresence : true ,
Original file line number Diff line number Diff line change @@ -104,7 +104,14 @@ module.exports = {
104
104
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
105
105
'react-native' : 'react-native-web' ,
106
106
} ,
107
- plugins : [ new ModuleScopePlugin ( paths . appSrc ) ] ,
107
+ plugins : [
108
+ // Prevents users from importing files from outside of src/ (or node_modules/).
109
+ // This often causes confusion because we only process files within src/ with babel.
110
+ // To fix this, we prevent you from importing files out of src/ -- if you'd like to,
111
+ // please link the files into your node_modules/ and let module-resolution kick in.
112
+ // Make sure your source files are compiled, as they will not be processed in any way.
113
+ new ModuleScopePlugin ( paths . appSrc ) ,
114
+ ] ,
108
115
} ,
109
116
module : {
110
117
strictExportPresence : true ,
You can’t perform that action at this time.
0 commit comments