Skip to content

Commit 6727da4

Browse files
committed
Allow importing package.json
1 parent 31a4d14 commit 6727da4

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

packages/react-dev-utils/ModuleScopePlugin.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ class ModuleScopePlugin {
3737
// Maybe an indexOf === 0 would be better?
3838
const relative = path.relative(appSrc, request.context.issuer);
3939
// If it's not in src/ or a subdirectory, not our request!
40-
if (
41-
relative.startsWith('../') ||
42-
relative.startsWith('..\\')
43-
) {
40+
if (relative.startsWith('../') || relative.startsWith('..\\')) {
41+
return callback();
42+
}
43+
const descriptionFileRelativeToRoot = path.relative(
44+
request.descriptionFileRoot,
45+
request.descriptionFilePath
46+
);
47+
if (descriptionFileRelativeToRoot === 'package.json') {
4448
return callback();
4549
}
4650
// Find path from src to the requested file
@@ -53,8 +57,7 @@ class ModuleScopePlugin {
5357
);
5458
// Error if in a parent directory of src/
5559
if (
56-
requestRelative.startsWith('../') ||
57-
requestRelative.startsWith('..\\')
60+
requestRelative.startsWith('../') || requestRelative.startsWith('..\\')
5861
) {
5962
callback(
6063
new Error(

packages/react-scripts/template/src/App.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Component } from 'react';
22
import logo from './logo.svg';
33
import './App.css';
4+
import { version, name } from '../../package.json';
45

56
class App extends Component {
67
render() {
@@ -9,6 +10,7 @@ class App extends Component {
910
<div className="App-header">
1011
<img src={logo} className="App-logo" alt="logo" />
1112
<h2>Welcome to React</h2>
13+
<p>{`${name} v${version}`}</p>
1214
</div>
1315
<p className="App-intro">
1416
To get started, edit <code>src/App.js</code> and save to reload.

0 commit comments

Comments
 (0)