Skip to content

Commit 6862713

Browse files
author
Maël Nison
committed
Adds a --use-pnp option
1 parent 3609e33 commit 6862713

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

packages/create-react-app/createReactApp.js

+33-7
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const program = new commander.Command(packageJson.name)
7676
'use a non-standard version of react-scripts'
7777
)
7878
.option('--use-npm')
79+
.option('--use-pnp')
7980
.allowUnknownOption()
8081
.on('--help', () => {
8182
console.log(` Only ${chalk.green('<project-directory>')} is required.`);
@@ -178,10 +179,11 @@ createApp(
178179
program.verbose,
179180
program.scriptsVersion,
180181
program.useNpm,
182+
program.usePnp,
181183
hiddenProgram.internalTestingTemplate
182184
);
183185

184-
function createApp(name, verbose, version, useNpm, template) {
186+
function createApp(name, verbose, version, useNpm, usePnp, template) {
185187
const root = path.resolve(name);
186188
const appName = path.basename(root);
187189

@@ -241,7 +243,16 @@ function createApp(name, verbose, version, useNpm, template) {
241243
version = '[email protected]';
242244
}
243245
}
244-
run(root, appName, version, verbose, originalDirectory, template, useYarn);
246+
run(
247+
root,
248+
appName,
249+
version,
250+
verbose,
251+
originalDirectory,
252+
template,
253+
useYarn,
254+
usePnp
255+
);
245256
}
246257

247258
function shouldUseYarn() {
@@ -253,7 +264,7 @@ function shouldUseYarn() {
253264
}
254265
}
255266

256-
function install(root, useYarn, dependencies, verbose, isOnline) {
267+
function install(root, useYarn, usePnp, dependencies, verbose, isOnline) {
257268
return new Promise((resolve, reject) => {
258269
let command;
259270
let args;
@@ -263,6 +274,9 @@ function install(root, useYarn, dependencies, verbose, isOnline) {
263274
if (!isOnline) {
264275
args.push('--offline');
265276
}
277+
if (usePnp) {
278+
args.push('--enable-pnp');
279+
}
266280
[].push.apply(args, dependencies);
267281

268282
// Explicitly set cwd() to work around issues like
@@ -287,6 +301,12 @@ function install(root, useYarn, dependencies, verbose, isOnline) {
287301
'--loglevel',
288302
'error',
289303
].concat(dependencies);
304+
305+
if (usePnp) {
306+
console.log(chalk.yellow("NPM doesn't support PnP."));
307+
console.log(chalk.yellow('Falling back to the regular installs.'));
308+
console.log();
309+
}
290310
}
291311

292312
if (verbose) {
@@ -313,7 +333,8 @@ function run(
313333
verbose,
314334
originalDirectory,
315335
template,
316-
useYarn
336+
useYarn,
337+
usePnp
317338
) {
318339
const packageToInstall = getInstallPackage(version, originalDirectory);
319340
const allDependencies = ['react', 'react-dom', packageToInstall];
@@ -336,9 +357,14 @@ function run(
336357
);
337358
console.log();
338359

339-
return install(root, useYarn, allDependencies, verbose, isOnline).then(
340-
() => packageName
341-
);
360+
return install(
361+
root,
362+
useYarn,
363+
usePnp,
364+
allDependencies,
365+
verbose,
366+
isOnline
367+
).then(() => packageName);
342368
})
343369
.then(async packageName => {
344370
checkNodeVersion(packageName);

tasks/e2e-installs.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,7 @@ yarn start --smoke-test
233233
# Test when PnP is enabled
234234
# ******************************************************************************
235235
cd "$temp_app_path"
236-
echo $OSTYPE
237-
YARN_PLUGNPLAY_OVERRIDE=1 npx create-react-app test-app-pnp
236+
npx create-react-app test-app-pnp --use-pnp
238237
cd test-app-pnp
239238
! exists node_modules
240239
exists .pnp.js

0 commit comments

Comments
 (0)