mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-06-16 02:14:50 +08:00
Allow importing package.json (#2468)
* Allow importing package.json * Remove package.json import from App.js template * fix importing package.json * Rename variable to reflect path is relative to root * Check for both package & package.json in ModuleScopePlugin * Use regex to check relative path to package.json * Strictly enforce package.json extension on scope plugin * Add allowedPaths to ModuleScopePlugin ctor and use it to allow app package.json * Remove package.json import from App.js template * Add package.json to react-scripts/template, show package version and name in the template * Remove import package.json from template * Remove template/package.json and its references in code * Update ModuleScopePlugin.js * Update README.md
This commit is contained in:
18
packages/react-dev-utils/ModuleScopePlugin.js
vendored
18
packages/react-dev-utils/ModuleScopePlugin.js
vendored
@@ -13,8 +13,9 @@ const chalk = require('chalk');
|
||||
const path = require('path');
|
||||
|
||||
class ModuleScopePlugin {
|
||||
constructor(appSrc) {
|
||||
constructor(appSrc, allowedFiles = []) {
|
||||
this.appSrc = appSrc;
|
||||
this.allowedFiles = new Set(allowedFiles);
|
||||
}
|
||||
|
||||
apply(resolver) {
|
||||
@@ -40,15 +41,16 @@ class ModuleScopePlugin {
|
||||
if (relative.startsWith('../') || relative.startsWith('..\\')) {
|
||||
return callback();
|
||||
}
|
||||
// Find path from src to the requested file
|
||||
const requestRelative = path.relative(
|
||||
appSrc,
|
||||
path.resolve(
|
||||
path.dirname(request.context.issuer),
|
||||
request.__innerRequest_request
|
||||
)
|
||||
const requestFullPath = path.resolve(
|
||||
path.dirname(request.context.issuer),
|
||||
request.__innerRequest_request
|
||||
);
|
||||
if (this.allowedFiles.has(requestFullPath)) {
|
||||
return callback();
|
||||
}
|
||||
// Find path from src to the requested file
|
||||
// Error if in a parent directory of src/
|
||||
const requestRelative = path.relative(appSrc, requestFullPath);
|
||||
if (
|
||||
requestRelative.startsWith('../') ||
|
||||
requestRelative.startsWith('..\\')
|
||||
|
||||
Reference in New Issue
Block a user