Skip to content

Commit

Permalink
Remove Yarn support, rely on auto-install-peers (#213
Browse files Browse the repository at this point in the history
* Remove Yarn installation instructions

* Remove Yarn support, rely on auto-install-peers

pnpm v8 enables auto-install-peers by default and this should automatically
install a lot of the dependencies which we have been manually copying from the
config's peerDependencies to the project's devDependencies

Ref: https://pnpm.io/npmrc#auto-install-peers

Closes #110
Closes #212
  • Loading branch information
karlhorky committed Apr 3, 2023
1 parent aa8fa38 commit beff0b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 58 deletions.
62 changes: 11 additions & 51 deletions bin/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ import {
} from 'node:fs';
import { dirname, join, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import eslintConfigPackageJson from '../package.json' assert { type: 'json' };

const newDevDependenciesToInstall =
/** @type {Partial<typeof projectPackageJson.peerDependencies>} */ (
eslintConfigPackageJson.peerDependencies
);
const newDevDependenciesToInstall = {};

const projectPackageJsonPath = join(process.cwd(), 'package.json');
const projectPackageJson = JSON.parse(
Expand Down Expand Up @@ -47,52 +43,16 @@ if ('react-scripts' in projectDependencies || 'next' in projectDependencies) {
// Add all config peerDependencies to devDependencies of
// project, upgrading existing package versions and
// sorting alphabetically
projectPackageJson.devDependencies = Object.fromEntries(
Object.entries({
...projectPackageJson.devDependencies,
...newDevDependenciesToInstall,
}).sort(),
);

const projectUsesYarn = !existsSync(join(process.cwd(), 'pnpm-lock.yaml'));

if (projectUsesYarn) {
projectPackageJson.resolutions = {
...projectPackageJson.resolutions,
// Force installation of the "dependencies" version of these
// ESLint dependencies to avoid conflicting version numbers
// between `eslint-config-react-app` and
// `@upleveled/eslint-config-upleveled` (they use the same
// ESLint dependencies, but may have slightly different
// versions).
//
// These conflicts can result in ESLint errors like:
//
// ESLint couldn't determine the plugin "import" uniquely.
//
// - /home/runner/work/preflight/preflight/node_modules/eslint-plugin-import/lib/index.js (loaded in ".eslintrc.cjs » @upleveled/eslint-config-upleveled")
// - /home/runner/work/preflight/preflight/node_modules/eslint-config-react-app/node_modules/eslint-plugin-import/lib/index.js (loaded in ".eslintrc.cjs » @upleveled/eslint-config-upleveled » eslint-config-react-app")
...[
'@typescript-eslint/eslint-plugin',
'@typescript-eslint/parser',
'eslint-plugin-import',
'eslint-plugin-jest',
'eslint-plugin-jsx-a11y',
'eslint-plugin-react',
'eslint-plugin-react-hooks',
].reduce(
(resolutions, packageName) => ({
...resolutions,
[packageName]: projectPackageJson.devDependencies[packageName],
}),
{},
),
'@typescript-eslint/utils':
projectPackageJson.devDependencies['@typescript-eslint/parser'],
};
if (Object.keys(newDevDependenciesToInstall).length > 0) {
projectPackageJson.devDependencies = Object.fromEntries(
Object.entries({
...projectPackageJson.devDependencies,
...newDevDependenciesToInstall,
}).sort(),
);
}

if ('next' in projectDependencies && !projectUsesYarn) {
if ('next' in projectDependencies) {
// Remove previous patches in package.json
if (projectPackageJson?.pnpm?.patchedDependencies) {
projectPackageJson.pnpm.patchedDependencies = Object.fromEntries(
Expand All @@ -110,7 +70,7 @@ writeFileSync(

console.log('Installing ESLint config dependencies...');

execSync(`${!projectUsesYarn ? 'pnpm' : 'yarn'} install`, { stdio: 'inherit' });
execSync('pnpm install', { stdio: 'inherit' });

console.log('✅ Done installing dependencies');

Expand Down Expand Up @@ -232,7 +192,7 @@ writeFileSync(

console.log('✅ Done updating .gitignore');

if ('next' in projectDependencies && !projectUsesYarn) {
if ('next' in projectDependencies) {
const patchesPath = join(process.cwd(), 'patches');

// Remove previous patch files
Expand Down
7 changes: 0 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ pnpm add --save-dev @upleveled/eslint-config-upleveled@latest
pnpm upleveled-eslint-install
```

Or, with Yarn:

```sh
yarn add --dev @upleveled/eslint-config-upleveled
yarn upleveled-eslint-install
```

<!--
Old instructions
Expand Down

0 comments on commit beff0b2

Please sign in to comment.