Skip to content

Commit

Permalink
Adds a --use-pnp option
Browse files Browse the repository at this point in the history
  • Loading branch information
Maël Nison committed Oct 1, 2018
1 parent 3609e33 commit 6862713
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
40 changes: 33 additions & 7 deletions packages/create-react-app/createReactApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const program = new commander.Command(packageJson.name)
'use a non-standard version of react-scripts'
)
.option('--use-npm')
.option('--use-pnp')
.allowUnknownOption()
.on('--help', () => {
console.log(` Only ${chalk.green('<project-directory>')} is required.`);
Expand Down Expand Up @@ -178,10 +179,11 @@ createApp(
program.verbose,
program.scriptsVersion,
program.useNpm,
program.usePnp,
hiddenProgram.internalTestingTemplate
);

function createApp(name, verbose, version, useNpm, template) {
function createApp(name, verbose, version, useNpm, usePnp, template) {
const root = path.resolve(name);
const appName = path.basename(root);

Expand Down Expand Up @@ -241,7 +243,16 @@ function createApp(name, verbose, version, useNpm, template) {
version = 'react-scripts@0.9.x';
}
}
run(root, appName, version, verbose, originalDirectory, template, useYarn);
run(
root,
appName,
version,
verbose,
originalDirectory,
template,
useYarn,
usePnp
);
}

function shouldUseYarn() {
Expand All @@ -253,7 +264,7 @@ function shouldUseYarn() {
}
}

function install(root, useYarn, dependencies, verbose, isOnline) {
function install(root, useYarn, usePnp, dependencies, verbose, isOnline) {
return new Promise((resolve, reject) => {
let command;
let args;
Expand All @@ -263,6 +274,9 @@ function install(root, useYarn, dependencies, verbose, isOnline) {
if (!isOnline) {
args.push('--offline');
}
if (usePnp) {
args.push('--enable-pnp');
}
[].push.apply(args, dependencies);

// Explicitly set cwd() to work around issues like
Expand All @@ -287,6 +301,12 @@ function install(root, useYarn, dependencies, verbose, isOnline) {
'--loglevel',
'error',
].concat(dependencies);

if (usePnp) {
console.log(chalk.yellow("NPM doesn't support PnP."));
console.log(chalk.yellow('Falling back to the regular installs.'));
console.log();
}
}

if (verbose) {
Expand All @@ -313,7 +333,8 @@ function run(
verbose,
originalDirectory,
template,
useYarn
useYarn,
usePnp
) {
const packageToInstall = getInstallPackage(version, originalDirectory);
const allDependencies = ['react', 'react-dom', packageToInstall];
Expand All @@ -336,9 +357,14 @@ function run(
);
console.log();

return install(root, useYarn, allDependencies, verbose, isOnline).then(
() => packageName
);
return install(
root,
useYarn,
usePnp,
allDependencies,
verbose,
isOnline
).then(() => packageName);
})
.then(async packageName => {
checkNodeVersion(packageName);
Expand Down
3 changes: 1 addition & 2 deletions tasks/e2e-installs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ yarn start --smoke-test
# Test when PnP is enabled
# ******************************************************************************
cd "$temp_app_path"
echo $OSTYPE
YARN_PLUGNPLAY_OVERRIDE=1 npx create-react-app test-app-pnp
npx create-react-app test-app-pnp --use-pnp
cd test-app-pnp
! exists node_modules
exists .pnp.js
Expand Down

0 comments on commit 6862713

Please sign in to comment.