Skip to content

Commit 3ee431d

Browse files
committed
Add comments
1 parent 871bf4e commit 3ee431d

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

packages/react-dev-utils/ModuleScopePlugin.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@ class ModuleScopePlugin {
3434
// Resolve the issuer from our appSrc and make sure it's one of our files
3535
// Maybe an indexOf === 0 would be better?
3636
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!
3838
if (relative[0] === '.') {
3939
return callback();
4040
}
41+
// Find path from src to the requested file
4142
const requestRelative = path.relative(
4243
appSrc,
4344
path.resolve(
4445
path.dirname(request.context.issuer),
4546
request.__innerRequest_request
4647
)
4748
);
49+
// Error if in a parent directory of src/
4850
if (requestRelative[0] === '.') {
4951
callback(
5052
new Error(

packages/react-scripts/config/webpack.config.dev.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,14 @@ module.exports = {
107107
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
108108
'react-native': 'react-native-web',
109109
},
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+
],
111118
},
112119
module: {
113120
strictExportPresence: true,

packages/react-scripts/config/webpack.config.prod.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ module.exports = {
104104
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
105105
'react-native': 'react-native-web',
106106
},
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+
],
108115
},
109116
module: {
110117
strictExportPresence: true,

0 commit comments

Comments
 (0)