forked from Automattic/jetpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.pnpmfile.cjs
115 lines (104 loc) · 3.63 KB
/
.pnpmfile.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Note if you change something here, you'll have to make a package.json mismatch pnpm-lock.yaml to
// get it re-run. An easy way to do that is to just edit pnpm-lock.yaml to change the version number
// of husky near the top.
/**
* Fix package dependencies.
*
* We could generally do the same with pnpm.overrides in packages.json, but this allows for comments.
*
* @param {object} pkg - Dependency package.json contents.
* @returns {object} Modified pkg.
*/
function fixDeps( pkg ) {
// Why do they not publish new versions from their monorepo?
if ( pkg.name === '@automattic/format-currency' ) {
// 1.0.0-alpha.0 published 3 years ago
pkg.dependencies[ 'i18n-calypso' ] = '^5';
}
if ( pkg.name === 'i18n-calypso' && pkg.dependencies[ 'interpolate-components' ] ) {
// 5.0.0 published 2 years ago
pkg.dependencies[ 'interpolate-components' ] = 'npm:@automattic/interpolate-components@^1.2.0';
}
// Even though Storybook works with webpack 5, they still have a bunch of deps on webpack4.
if ( pkg.name.startsWith( '@storybook/' ) ) {
if ( pkg.dependencies[ '@storybook/builder-webpack4' ] ) {
pkg.dependencies[ '@storybook/builder-webpack4' ] = 'npm:@storybook/builder-webpack5@^6';
}
if ( pkg.dependencies[ '@storybook/manager-webpack4' ] ) {
pkg.dependencies[ '@storybook/manager-webpack4' ] = 'npm:@storybook/manager-webpack5@^6';
}
if ( pkg.dependencies.webpack ) {
pkg.dependencies.webpack = '^5';
}
if ( pkg.dependencies[ '@types/webpack' ] ) {
pkg.dependencies[ '@types/webpack' ] = '^5';
}
}
// Project is supposedly not dead, but still isn't being updated.
// For our purposes at least it seems to work fine with jest-environment-jsdom 27.
// https://github.com/enzymejs/enzyme-matchers/issues/353
if ( pkg.name === 'jest-environment-enzyme' ) {
pkg.dependencies[ 'jest-environment-jsdom' ] = '^27';
}
// Unpin browserslist here.
if (
pkg.name === 'react-dev-utils' &&
pkg.dependencies.browserslist.match( /^\d+\.\d+\.\d+$/ )
) {
pkg.dependencies.browserslist = '^' + pkg.dependencies.browserslist;
}
// Regular expression DOS.
if ( pkg.dependencies.trim === '0.0.1' ) {
pkg.dependencies.trim = '^0.0.3';
}
return pkg;
}
/**
* Fix package peer dependencies.
*
* This can't be done with pnpm.overrides.
*
* @param {object} pkg - Dependency package.json contents.
* @returns {object} Modified pkg.
*/
function fixPeerDeps( pkg ) {
// React 17 is entirely compatible with React 16, but a lot of junk hasn't updated deps yet.
for ( const p of [ 'react', 'react-dom' ] ) {
if (
pkg.peerDependencies?.[ p ] &&
pkg.peerDependencies[ p ].match( /(?:^|\|\|\s*)(?:\^16|16\.x)/ ) &&
! pkg.peerDependencies[ p ].match( /(?:^|\|\|\s*)(?:\^17|17\.x)/ )
) {
pkg.peerDependencies[ p ] += ' || ^17';
}
}
// Outdated. Looks like they're going to drop the eslint-config-wpcalypso package entirely with
// eslint-plugin-wpcalypso 5.1.0, but they haven't released that yet.
if ( pkg.name === 'eslint-config-wpcalypso' ) {
pkg.peerDependencies.eslint = '^8';
pkg.peerDependencies[ 'eslint-plugin-inclusive-language' ] = '*';
pkg.peerDependencies[ 'eslint-plugin-jsdoc' ] = '*';
pkg.peerDependencies[ 'eslint-plugin-wpcalypso' ] = '*';
}
return pkg;
}
/**
* Pnpm package hook.
*
* @see https://pnpm.io/pnpmfile#hooksreadpackagepkg-context-pkg--promisepkg
* @param {object} pkg - Dependency package.json contents.
* @param {object} context - Pnpm object of some sort.
* @returns {object} Modified pkg.
*/
function readPackage( pkg, context ) {
if ( pkg.name ) {
pkg = fixDeps( pkg, context );
pkg = fixPeerDeps( pkg, context );
}
return pkg;
}
module.exports = {
hooks: {
readPackage,
},
};