Skip to content

Commit 35897bf

Browse files
authored
Remove unnecessary dependencies from wp-build package.json files (#54061)
wp-build itself doesn't seem to care; apparently the only reason we have these dependencies is because of the `import/no-extraneous-dependencies` eslint rule. Meanwhile, Renovate wants to scan and update these package.json files even though their dependency declarations aren't used for anything. We can set the `packageDir` option to `import/no-extraneous-dependencies` to point it at the package's actual package.json file, and then add a structure lint check to ensure people don't re-add these dependencies.
1 parent 15ced7a commit 35897bf

169 files changed

Lines changed: 275 additions & 1814 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/files/lint-project-structure.sh‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,15 +228,26 @@ for PROJECT in projects/*/*; do
228228
fi
229229

230230
# - package.json link deps should not point outside the project.
231+
# - wp-build dummy package.json should not have any dependencies.
231232
for f in $( git ls-files "$PROJECT/package.json" "$PROJECT/*/package.json" ); do
232-
while IFS=$'\t' read -r DEPTYPE DEP LINK; do
233-
RP=$( realpath -m --relative-to="$PROJECT/" "${f%/*}/$LINK" )
234-
if [[ "$RP" == ../* ]]; then
235-
EXIT=1
236-
LINE=$(jq --stream -r --arg DEPTYPE "$DEPTYPE" --arg DEP "$DEP" 'if length == 1 then .[0][:-1] else .[0] end | if . == [$DEPTYPE,$DEP] then ",line=\( input_line_number )" else empty end' "$f")
237-
echo "::error file=$f${LINE}::Dependency \`$DEP\` should not try to link outside of the project. Cross-project interactions should be done via public APIs."
238-
fi
239-
done < <( jq -r 'to_entries[] | .key as $deptype | select( [ "dependencies", "devDependencies", "optionalDependencies", "peerDependencies" ] | index( $deptype ) ) | .value | to_entries[] | select( .value | startswith( "link:" ) or startswith( "file:" ) ) | [ $deptype, .key, ( .value | sub( "^[^:]*:"; "" ) ) ] | @tsv' "$f" )
233+
if [[ "$f" == "$PROJECT"/?(packages|routes|widgets)/*/package.json ]]; then
234+
for DEPTYPE in dependencies devDependencies optionalDependencies peerDependencies; do
235+
LINE=$(jq --stream -r --arg DEPTYPE "$DEPTYPE" 'if length == 1 then .[0][:-1] else .[0] end | if . == [$DEPTYPE] then ",line=\( input_line_number )" else empty end' "$f")
236+
if [[ -n "$LINE" ]]; then
237+
EXIT=1
238+
echo "::error file=$f${LINE}::Wp-build package.json files should not have $DEPTYPE. Any dependencies they require should be in the project's base package.json (\`$PROJECT/package.json\`)."
239+
fi
240+
done
241+
else
242+
while IFS=$'\t' read -r DEPTYPE DEP LINK; do
243+
RP=$( realpath -m --relative-to="$PROJECT/" "${f%/*}/$LINK" )
244+
if [[ "$RP" == ../* ]]; then
245+
EXIT=1
246+
LINE=$(jq --stream -r --arg DEPTYPE "$DEPTYPE" --arg DEP "$DEP" 'if length == 1 then .[0][:-1] else .[0] end | if . == [$DEPTYPE,$DEP] then ",line=\( input_line_number )" else empty end' "$f")
247+
echo "::error file=$f${LINE}::Dependency \`$DEP\` should not try to link outside of the project. Cross-project interactions should be done via public APIs."
248+
fi
249+
done < <( jq -r 'to_entries[] | .key as $deptype | select( [ "dependencies", "devDependencies", "optionalDependencies", "peerDependencies" ] | index( $deptype ) ) | .value | to_entries[] | select( .value | startswith( "link:" ) or startswith( "file:" ) ) | [ $deptype, .key, ( .value | sub( "^[^:]*:"; "" ) ) ] | @tsv' "$f" )
250+
fi
240251
done
241252

242253
# - should have only one of jsconfig.json or tsconfig.json.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: fixed
3+
Comment: Clean up unnecessary external dependencies in wp-build package.json files after fixing eslint `import/no-extraneous-dependencies` configuration.
4+
5+

‎projects/packages/activity-log/packages/init/package.json‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,5 @@
55
"type": "module",
66
"wpScript": true,
77
"module": "build-module/index.mjs",
8-
"wpScriptModuleExports": "./build-module/index.mjs",
9-
"dependencies": {
10-
"@automattic/jetpack-wp-build-polyfills": "workspace:*"
11-
}
8+
"wpScriptModuleExports": "./build-module/index.mjs"
129
}

‎projects/packages/activity-log/routes/dashboard/package.json‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,6 @@
11
{
22
"version": "1.0.0",
33
"private": true,
4-
"dependencies": {
5-
"@automattic/jetpack-analytics": "workspace:*",
6-
"@automattic/jetpack-base-styles": "workspace:*",
7-
"@automattic/jetpack-components": "workspace:*",
8-
"@automattic/jetpack-connection": "workspace:*",
9-
"@tanstack/react-query": "^5.90.8",
10-
"@types/react": "19.3.0",
11-
"@wordpress/api-fetch": "7.57.0",
12-
"@wordpress/components": "42.0.0",
13-
"@wordpress/compose": "8.10.0",
14-
"@wordpress/data": "10.57.0",
15-
"@wordpress/dataviews": "20.0.0",
16-
"@wordpress/date": "5.57.0",
17-
"@wordpress/element": "9.0.0",
18-
"@wordpress/i18n": "6.30.0",
19-
"@wordpress/icons": "18.0.0",
20-
"@wordpress/route": "0.23.0",
21-
"@wordpress/theme": "2.3.0",
22-
"@wordpress/ui": "0.24.0",
23-
"@wordpress/url": "4.57.0"
24-
},
254
"route": {
265
"path": "/",
276
"page": "jetpack-activity-log-dashboard"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: fixed
3+
Comment: Clean up unnecessary external dependencies in wp-build package.json files after fixing eslint `import/no-extraneous-dependencies` configuration.
4+
5+

‎projects/packages/ads/eslint.config.mjs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ export default defineConfig( makeBaseConfig( import.meta.url ), {
1414
'jsdoc/require-returns': 'off',
1515
'jsdoc/check-indentation': 'off',
1616
'jsdoc/escape-inline-tags': 'off',
17-
'import/no-extraneous-dependencies': 'off',
1817
},
1918
} );

‎projects/packages/ads/widgets/wordads-chart-tabs/package.json‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,5 @@
22
"name": "@automattic/jetpack-ads-widget-chart-tabs",
33
"version": "0.1.0-alpha",
44
"private": true,
5-
"type": "module",
6-
"dependencies": {
7-
"@automattic/jetpack-premium-analytics-sdk": "workspace:*",
8-
"@wordpress/element": "9.0.0",
9-
"@wordpress/i18n": "^6.9.0",
10-
"@wordpress/icons": "^18.0.0",
11-
"@wordpress/widget-primitives": "0.9.0",
12-
"react": "19.3.0"
13-
}
5+
"type": "module"
146
}

‎projects/packages/ads/widgets/wordads-earnings-history/package.json‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,5 @@
22
"name": "@automattic/jetpack-ads-widget-earnings-history",
33
"version": "0.1.0-alpha",
44
"private": true,
5-
"type": "module",
6-
"dependencies": {
7-
"@automattic/jetpack-premium-analytics-sdk": "workspace:*",
8-
"@wordpress/i18n": "^6.9.0",
9-
"@wordpress/icons": "^18.0.0",
10-
"@wordpress/widget-primitives": "0.9.0",
11-
"react": "19.3.0"
12-
}
5+
"type": "module"
136
}

‎projects/packages/ads/widgets/wordads-highlights/package.json‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,5 @@
22
"name": "@automattic/jetpack-ads-widget-highlights",
33
"version": "0.1.0-alpha",
44
"private": true,
5-
"type": "module",
6-
"dependencies": {
7-
"@automattic/jetpack-premium-analytics-sdk": "workspace:*",
8-
"@wordpress/i18n": "^6.9.0",
9-
"@wordpress/icons": "^18.0.0",
10-
"@wordpress/widget-primitives": "0.9.0",
11-
"react": "19.3.0"
12-
}
5+
"type": "module"
136
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Significance: patch
2+
Type: fixed
3+
Comment: Clean up unnecessary external dependencies in wp-build package.json files after fixing eslint `import/no-extraneous-dependencies` configuration.
4+
5+

0 commit comments

Comments
 (0)