Add tmp workaround to fix CRA repro in PnP mode

This commit is contained in:
Gaëtan Maisse 2022-02-17 20:25:44 +01:00
parent 4cfc80c379
commit f517d56aad
No known key found for this signature in database
GPG Key ID: D934C0EF3714A8A8
2 changed files with 18 additions and 5 deletions

View File

@ -6,6 +6,11 @@ nodeLinker: node-modules
npmRegistryServer: "https://registry.yarnpkg.com" npmRegistryServer: "https://registry.yarnpkg.com"
packageExtensions:
babel-preset-react-app@10.0.x:
dependencies:
"@babel/plugin-proposal-private-property-in-object": ^7.16.0
plugins: plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs - path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript" spec: "@yarnpkg/plugin-typescript"

View File

@ -2,6 +2,7 @@ import path from 'path';
import { writeJSON } from 'fs-extra'; import { writeJSON } from 'fs-extra';
import shell, { ExecOptions } from 'shelljs'; import shell, { ExecOptions } from 'shelljs';
import chalk from 'chalk'; import chalk from 'chalk';
import { cra, cra_typescript } from './configs';
const logger = console; const logger = console;
@ -69,15 +70,24 @@ export const exec = async (
}); });
}; };
const installYarn2 = async ({ cwd, pnp }: Options) => { const installYarn2 = async ({ cwd, pnp, name }: Options) => {
const command = [ const command = [
`yarn set version berry`, `yarn set version berry`,
`yarn config set enableGlobalCache true`, `yarn config set enableGlobalCache true`,
`yarn config set nodeLinker ${pnp ? 'pnp' : 'node-modules'}`, `yarn config set nodeLinker ${pnp ? 'pnp' : 'node-modules'}`,
].join(' && '); ];
// FIXME: Some dependencies used by CRA aren't listed in its package.json
// Next line is a hack to remove as soon as CRA will have added these missing deps
// for details see https://github.com/facebook/create-react-app/pull/11751
if ([cra.name, cra_typescript.name].includes(name)) {
command.push(
`yarn config set packageExtensions --json '{ "babel-preset-react-app@10.0.x": { "dependencies": { "@babel/plugin-proposal-private-property-in-object": "^7.16.0" } } }'`
);
}
await exec( await exec(
command, command.join(' && '),
{ cwd }, { cwd },
{ startMessage: `🧶 Installing Yarn 2`, errorMessage: `🚨 Installing Yarn 2 failed` } { startMessage: `🧶 Installing Yarn 2`, errorMessage: `🚨 Installing Yarn 2 failed` }
); );
@ -107,8 +117,6 @@ const configureYarn2ForE2E = async ({ cwd }: Options) => {
const generate = async ({ cwd, name, appName, version, generator }: Options) => { const generate = async ({ cwd, name, appName, version, generator }: Options) => {
const command = generator.replace(/{{appName}}/g, appName).replace(/{{version}}/g, version); const command = generator.replace(/{{appName}}/g, appName).replace(/{{version}}/g, version);
console.log('generate', { command, generator });
await exec( await exec(
command, command,
{ cwd }, { cwd },