@@ -4,21 +4,41 @@ import path from "node:path";
44import yaml from "yaml" ;
55
66// Dependabot config uses posix path, so normalize.
7- const normalizePath = ( pkgs , root ) =>
8- pkgs . map ( p => {
7+ function normalizePath ( pkgs , root ) {
8+ return pkgs . map ( p => {
99 const pkgPath = path . relative ( root , p . path ) ;
1010 p . path = path . posix . resolve ( "/" , pkgPath . split ( path . sep ) . join ( path . posix . sep ) ) ;
1111 return p ;
1212 } ) ;
13+ }
14+
15+ function isWorkspaceDependency ( localPackages , dependencyName , dependencyMeta ) {
16+ return localPackages . has ( dependencyName ) && dependencyMeta . version . startsWith ( "link" ) ;
17+ }
18+
19+ function getWorkspaceDependencies ( localPackages , pkg ) {
20+ const { dependencies = { } , devDependencies = { } } = pkg ;
21+
22+ const filterWorkspaceDeps = ( [ dependencyName , dependencyMeta ] ) => {
23+ return isWorkspaceDependency ( localPackages , dependencyName , dependencyMeta ) ? [ dependencyName ] : [ ] ;
24+ } ;
25+
26+ const deps = Object . entries ( dependencies ) . flatMap ( filterWorkspaceDeps ) ;
27+
28+ const devDeps = Object . entries ( devDependencies ) . flatMap ( filterWorkspaceDeps ) ;
29+
30+ return [ ...deps , ...devDeps ] ;
31+ }
1332
1433function main ( ) {
1534 const root = execSync ( "git rev-parse --show-toplevel" , { encoding : "utf-8" } ) . trim ( ) ;
16- const listing = execSync ( "pnpm ls --recursive --json --depth -1 " , {
35+ const listing = execSync ( "pnpm ls --recursive --json --depth 0 " , {
1736 encoding : "utf-8"
1837 } ) . trim ( ) ;
1938
2039 const packages = normalizePath ( JSON . parse ( listing !== "" ? listing : "[]" ) , root ) ;
2140 packages . sort ( ( a , b ) => a . name . normalize ( ) . localeCompare ( b . name . normalize ( ) ) ) ;
41+ const localPackages = new Set ( packages . map ( pkg => pkg . name ) ) ;
2242
2343 const dependabotConfig = {
2444 version : 2 ,
@@ -30,17 +50,23 @@ function main() {
3050 interval : "weekly"
3151 }
3252 } ,
33- ...packages . map ( pkg => ( {
34- "package-ecosystem" : "npm" ,
35- directory : pkg . path ,
36- schedule : { interval : "weekly" } ,
37- ignore : [
38- // Disable updates for typescript as we will update it manually.
39- { "dependency-name" : "typescript" } ,
40- // Disable major updates for all dependencies
41- { "dependency-name" : "*" , "update-types" : [ "version-update:semver-major" ] }
42- ]
43- } ) )
53+ ...packages . map ( pkg => {
54+ const localDeps = getWorkspaceDependencies ( localPackages , pkg ) ;
55+ return {
56+ "package-ecosystem" : "npm" ,
57+ directory : pkg . path ,
58+ schedule : { interval : "weekly" } ,
59+ ignore : [
60+ // Disable updates for typescript as we will update it manually.
61+ { "dependency-name" : "typescript" } ,
62+ // We also ignore local dependencies as dependabot have errors when query this
63+ // packages in npm registry.
64+ ...localDeps . map ( name => ( { "dependency-name" : name } ) ) ,
65+ // Disable major updates for all dependencies
66+ { "dependency-name" : "*" , "update-types" : [ "version-update:semver-major" ] }
67+ ]
68+ } ;
69+ } )
4470 ]
4571 } ;
4672
0 commit comments