diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 356387a89..b406ba7ed 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,7 +16,7 @@ jobs: permissions: contents: read steps: - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - name: Enable corepack run: corepack enable diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7450bf66f..b9c6e36e4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,7 +50,7 @@ jobs: client-id: ${{ vars.INCREASE_RELEASES_CLIENT_ID }} private-key: ${{ secrets.INCREASE_RELEASES_PRIVATE_KEY }} - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - name: Enable corepack run: corepack enable @@ -89,7 +89,7 @@ jobs: client-id: ${{ vars.INCREASE_RELEASES_CLIENT_ID }} private-key: ${{ secrets.INCREASE_RELEASES_PRIVATE_KEY }} - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 with: fetch-depth: 0 token: ${{ steps.app-token.outputs.token }} diff --git a/.github/workflows/self-test.yml b/.github/workflows/self-test.yml index 75caae8a1..1a06243af 100644 --- a/.github/workflows/self-test.yml +++ b/.github/workflows/self-test.yml @@ -30,7 +30,7 @@ jobs: client-id: ${{ vars.INCREASE_RELEASES_CLIENT_ID }} private-key: ${{ secrets.INCREASE_RELEASES_PRIVATE_KEY }} - - uses: actions/checkout@v6 + - uses: actions/checkout@v7 - name: Enable corepack run: corepack enable diff --git a/package.json b/package.json index bab1382cb..e77406066 100644 --- a/package.json +++ b/package.json @@ -43,21 +43,21 @@ }, "homepage": "https://github.com/increase/release-please#readme", "devDependencies": { - "@actions/core": "^1.11.1", + "@actions/core": "^3.0.1", "@biomejs/biome": "^2.4.15", "@octokit/types": "^16.0.0", "@types/diff": "^5.0.2", "@types/jsonpath": "^0.2.0", "@types/lerna__package": "^5.1.0", "@types/lerna__package-graph": "^5.1.0", - "@types/node": "^24.12.4", + "@types/node": "^26.0.1", "@types/semver": "^7.7.1", "@types/xmldom": "^0.1.31", "@types/yargs": "^17.0.0", "@vercel/ncc": "^0.38.4", + "@vitest/coverage-v8": "^4.1.9", "ajv": "^8.18.0", "ajv-formats": "^3.0.1", - "@vitest/coverage-v8": "^4.0.18", "msw": "^2.10.2", "vitest": "^4.1.9" }, @@ -71,7 +71,7 @@ "@octokit/graphql": "^9.0.3", "@octokit/plugin-retry": "8.1.0", "@octokit/plugin-throttling": "11.0.3", - "@octokit/request": "^10.0.9", + "@octokit/request": "^10.0.11", "@octokit/request-error": "^7.1.0", "@octokit/rest": "^22.0.1", "@types/npm-package-arg": "^6.1.0", @@ -80,17 +80,14 @@ "conventional-changelog-conventionalcommits": "^6.0.0", "conventional-changelog-writer": "^6.0.0", "conventional-commits-filter": "^3.0.0", - "detect-indent": "^6.1.0", "diff": "^5.2.2", "http-proxy-agent": "^9.0.0", "https-proxy-agent": "^7.0.6", "jsonpath": "^1.3.0", "node-html-parser": "^6.0.0", - "semver": "^7.8.0", + "semver": "^7.8.5", "type-fest": "^5.6.0", "typescript": "^5.9.3", - "unist-util-visit": "^2.0.3", - "unist-util-visit-parents": "^3.1.1", "xpath": "^0.0.34", "yaml": "^2.8.3", "yargs": "^17.0.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e21054807..3db546490 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -48,8 +48,8 @@ importers: specifier: 11.0.3 version: 11.0.3(@octokit/core@7.0.6) '@octokit/request': - specifier: ^10.0.9 - version: 10.0.9 + specifier: ^10.0.11 + version: 10.0.11 '@octokit/request-error': specifier: ^7.1.0 version: 7.1.0 @@ -74,9 +74,6 @@ importers: conventional-commits-filter: specifier: ^3.0.0 version: 3.0.0 - detect-indent: - specifier: ^6.1.0 - version: 6.1.0 diff: specifier: ^5.2.2 version: 5.2.2 @@ -93,20 +90,14 @@ importers: specifier: ^6.0.0 version: 6.1.13 semver: - specifier: ^7.8.0 - version: 7.8.0 + specifier: ^7.8.5 + version: 7.8.5 type-fest: specifier: ^5.6.0 version: 5.6.0 typescript: specifier: ^5.9.3 version: 5.9.3 - unist-util-visit: - specifier: ^2.0.3 - version: 2.0.3 - unist-util-visit-parents: - specifier: ^3.1.1 - version: 3.1.1 xpath: specifier: ^0.0.34 version: 0.0.34 @@ -118,8 +109,8 @@ importers: version: 17.7.2 devDependencies: '@actions/core': - specifier: ^1.11.1 - version: 1.11.1 + specifier: ^3.0.1 + version: 3.0.1 '@biomejs/biome': specifier: ^2.4.15 version: 2.4.15 @@ -139,8 +130,8 @@ importers: specifier: ^5.1.0 version: 5.1.3 '@types/node': - specifier: ^24.12.4 - version: 24.12.4 + specifier: ^26.0.1 + version: 26.0.1 '@types/semver': specifier: ^7.7.1 version: 7.7.1 @@ -154,8 +145,8 @@ importers: specifier: ^0.38.4 version: 0.38.4 '@vitest/coverage-v8': - specifier: ^4.0.18 - version: 4.1.6(vitest@4.1.9) + specifier: ^4.1.9 + version: 4.1.9(vitest@4.1.9) ajv: specifier: ^8.18.0 version: 8.20.0 @@ -164,24 +155,24 @@ importers: version: 3.0.1(ajv@8.20.0) msw: specifier: ^2.10.2 - version: 2.14.6(@types/node@24.12.4)(typescript@5.9.3) + version: 2.14.6(@types/node@26.0.1)(typescript@5.9.3) vitest: specifier: ^4.1.9 - version: 4.1.9(@types/node@24.12.4)(@vitest/coverage-v8@4.1.6)(msw@2.14.6(@types/node@24.12.4)(typescript@5.9.3))(vite@8.0.13(@types/node@24.12.4)(yaml@2.9.0)) + version: 4.1.9(@types/node@26.0.1)(@vitest/coverage-v8@4.1.9)(msw@2.14.6(@types/node@26.0.1)(typescript@5.9.3))(vite@8.0.13(@types/node@26.0.1)(yaml@2.9.0)) packages: - '@actions/core@1.11.1': - resolution: {integrity: sha512-hXJCSrkwfA46Vd9Z3q4cpEpHB1rL5NG04+/rbqW9d3+CSvtB1tYe8UTpAlixa1vj0m/ULglfEK2UKxMGxCxv5A==} + '@actions/core@3.0.1': + resolution: {integrity: sha512-a6d/Nwahm9fliVGRhdhofo40HjHQasUPusmc7vBfyky+7Z+P2A1J68zyFVaNcEclc/Se+eO595oAr5nwEIoIUA==} - '@actions/exec@1.1.1': - resolution: {integrity: sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==} + '@actions/exec@3.0.0': + resolution: {integrity: sha512-6xH/puSoNBXb72VPlZVm7vQ+svQpFyA96qdDBvhB8eNZOE8LtPf9L4oAsfzK/crCL8YZ+19fKYVnM63Sl+Xzlw==} - '@actions/http-client@2.2.3': - resolution: {integrity: sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==} + '@actions/http-client@4.0.1': + resolution: {integrity: sha512-+Nvd1ImaOZBSoPbsUtEhv+1z99H12xzncCkz0a3RuehINE81FZSe2QTj3uvAPTcJX/SCzUQHQ0D1GrPMbrPitg==} - '@actions/io@1.1.3': - resolution: {integrity: sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==} + '@actions/io@3.0.2': + resolution: {integrity: sha512-nRBchcMM+QK1pdjO7/idu86rbJI5YHUKCvKs0KxnSYbVe3F51UfGxuZX4Qy/fWlp6l7gWFwIkrOzN+oUK03kfw==} '@babel/code-frame@7.12.11': resolution: {integrity: sha512-Zt1yodBx1UcyiePMSkWnU4hPqhwq7hGi2nFL1LeA3EUl+q2LQx16MISgJ0+z7dnmgvP9QtIleuETGOiOH1RcIw==} @@ -190,10 +181,6 @@ packages: resolution: {integrity: sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==} engines: {node: '>=6.9.0'} - '@babel/helper-validator-identifier@7.19.1': - resolution: {integrity: sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==} - engines: {node: '>=6.9.0'} - '@babel/helper-validator-identifier@7.28.5': resolution: {integrity: sha512-qSs4ifwzKJSV39ucNjsvc6WVHs6b7S03sOh2OcHF9UHfVPqWWALUsNUVzhSBiItjRZoLHx7nIarVjqKVusUZ1Q==} engines: {node: '>=6.9.0'} @@ -503,6 +490,10 @@ packages: resolution: {integrity: sha512-KMQIfq5sOPpkQYajXHwnhjCC0slzCNScLHs9JafXc4RAJI+9f+jNDlBNaIMTvazOPLgb4BnlhGJOTbnN0wIjPw==} engines: {node: '>= 20'} + '@octokit/request@10.0.11': + resolution: {integrity: sha512-+s7HUxjfFqOMS9VlIwDffq0MikjSAK0gSpG73W+meAvVAvX4MBrHYTK5Bj3Uot55qFT4gzUtfzE4mGWY4Br8/Q==} + engines: {node: '>= 20'} + '@octokit/request@10.0.9': resolution: {integrity: sha512-o8Bi3f608eyM+7BmBiUWxFsdjLb3/ym1cQek5LZOv9KkZcxRrHCPhhRzm6xjO6HVZ85ItD6+sTsjxo821SVa/A==} engines: {node: '>= 20'} @@ -679,14 +670,17 @@ packages: '@types/lerna__package@5.1.3': resolution: {integrity: sha512-oHJSN1MQM4ZC6spkjq/8DTJ13uZkpJW10T9KXztHtVOJQja7GRs96oL9/UEjRIjcgUT5fzrov+ygzYZcG+nN4A==} - '@types/minimist@1.2.2': - resolution: {integrity: sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==} + '@types/minimist@1.2.5': + resolution: {integrity: sha512-hov8bUuiLiyFPGyFPE1lwWhmzYbirOXQNNo40+y3zow8aFVTeyn3VWL0VFFfdNddA8S4Vf0Tc062rzyNr7Paag==} '@types/node@24.12.4': resolution: {integrity: sha512-GUUEShf+PBCGW2KaXwcIt3Yk+e3pkKwWKb9GSyM9WQVE+ep2jzmHdGsHzu4wgcZy5fN9FBdVzjpBQsYlpfpgLA==} - '@types/normalize-package-data@2.4.1': - resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==} + '@types/node@26.0.1': + resolution: {integrity: sha512-fc3KiUoBt6kie0N9bIW3E47vZsuaMf0PM2AaUpLCLT0s/LvX1nxAim6Fc049cNxODPpGm6qRAuUOB86SkRuPQw==} + + '@types/normalize-package-data@2.4.4': + resolution: {integrity: sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==} '@types/npm-package-arg@6.1.4': resolution: {integrity: sha512-vDgdbMy2QXHnAruzlv68pUtXCjmqUk3WrBAsRboRovsOmxbfn/WiYCjmecyKjGztnMps5dWp4Uq2prp+Ilo17Q==} @@ -719,11 +713,11 @@ packages: resolution: {integrity: sha512-8LwjnlP39s08C08J5NstzriPvW1SP8Zfpp1BvC2sI35kPeZnHfxVkCwu4/+Wodgnd60UtT1n8K8zw+Mp7J9JmQ==} hasBin: true - '@vitest/coverage-v8@4.1.6': - resolution: {integrity: sha512-36l628fQ/9a/8ihy97eOtEnvWQEdqULQOJtcaxtoNq0G1w3Mxd4szSahOaMM9/NGyZ+hyKcMtIW/WIxq0XQViQ==} + '@vitest/coverage-v8@4.1.9': + resolution: {integrity: sha512-G9/lgqibheLVBDRuya45EbsEXTYcWoSG+TLg7i2axuzx0Eq62eXn+aWXyaVdV5vKvFSWd6ywcX8hA7la9Pvu8g==} peerDependencies: - '@vitest/browser': 4.1.6 - vitest: 4.1.6 + '@vitest/browser': 4.1.9 + vitest: 4.1.9 peerDependenciesMeta: '@vitest/browser': optional: true @@ -742,9 +736,6 @@ packages: vite: optional: true - '@vitest/pretty-format@4.1.6': - resolution: {integrity: sha512-h5SxD/IzNhZYnrSZRsUZQIC+vD0GY8cUvq0iwsmkFKixRCKLLWqCXa/FIQ4S1R+sI+PGoojkHsdNrbZiM9Qpgw==} - '@vitest/pretty-format@4.1.9': resolution: {integrity: sha512-s0iufns3iIFitdgm+YR7g1whCAaGtXz459VS9/PqyKDEEFgYIhsHOQmXgIgDuYCt7DeQmiZT0Qe2OA2p4ZPu5A==} @@ -757,9 +748,6 @@ packages: '@vitest/spy@4.1.9': resolution: {integrity: sha512-fHpsS6mIi+PiEW+vcRVOMkX1oSaPKne3VOclSFICPcGOmfKgXPU5iAah+wcNcj2xPrCCmfq99IDGf+EojhhvhA==} - '@vitest/utils@4.1.6': - resolution: {integrity: sha512-FxIY+U81R3LGKCxaHHFRQ5+g6/iRgGLmeHWdp2Amj4ljQRrEIWHmZyDfDYBRZlpyqA7qKxtS9DD1dhk8RnRIVQ==} - '@vitest/utils@4.1.9': resolution: {integrity: sha512-A51o8ymO5PpqlWNnBP9ZHPXDIpuMtTLlGSjN7la4US+LJzoUMyhwjA5QXlm39JexgwHKW4Xjs8Z2d3dLCXOeuA==} @@ -974,10 +962,6 @@ packages: resolution: {integrity: sha512-rlpvsxUtM0PQvy9iZe640/IWwWYyBsTApREbA1pHOpmOUIl9MkP/U4z7vTtg4Oaojvqhxt7sdufnT0EzGaR31g==} engines: {node: '>=4'} - detect-indent@6.1.0: - resolution: {integrity: sha512-reYkTUJAZb9gUuZ2RvVCNhVHdg62RHnJ7WJl8ftMi4diZ6NWlciOzQN88pUhSELEwflJht4oQDv0F0BMlwaYtA==} - engines: {node: '>=8'} - detect-libc@2.1.2: resolution: {integrity: sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==} engines: {node: '>=8'} @@ -1013,6 +997,10 @@ packages: error-ex@1.3.2: resolution: {integrity: sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==} + es-errors@1.3.0: + resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==} + engines: {node: '>= 0.4'} + es-module-lexer@2.2.0: resolution: {integrity: sha512-3lGxdTXCLfe1MYfTz1y2ksAAUM4NAOP6rPEjxGJVKO7TZ5+tvHCaQWGpC4Y3IXvW3ece0Cz1cIP4FWBxOnGCTQ==} @@ -1093,8 +1081,8 @@ packages: engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} os: [darwin] - function-bind@1.1.1: - resolution: {integrity: sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==} + function-bind@1.1.2: + resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} gauge@4.0.4: resolution: {integrity: sha512-f9m+BEN5jkg6a0fZjleidjN51VE1X+mPFQ2DJ0uv1V39oCLCbsGe6yjbBnp7eK7z/+GAon99a3nHuqbuuthyPg==} @@ -1136,9 +1124,9 @@ packages: has-unicode@2.0.1: resolution: {integrity: sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==} - has@1.0.3: - resolution: {integrity: sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==} - engines: {node: '>= 0.4.0'} + hasown@2.0.4: + resolution: {integrity: sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==} + engines: {node: '>= 0.4'} he@1.2.0: resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==} @@ -1187,8 +1175,9 @@ packages: is-arrayish@0.2.1: resolution: {integrity: sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==} - is-core-module@2.11.0: - resolution: {integrity: sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==} + is-core-module@2.16.2: + resolution: {integrity: sha512-evOr8xfXKxE6qSR0hSXL2r3sd7ALj8+7jQEUvPYcm5sgZFdJ+AYzT6yNmJenvIYQBgIGwfwz08sL8zoL7yq2BA==} + engines: {node: '>= 0.4'} is-fullwidth-code-point@3.0.0: resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} @@ -1383,8 +1372,8 @@ packages: resolution: {integrity: sha512-Q4r8ghd80yhO/0j1O3B2BjweX3fiHg9cdOwjJd2J76Q135c+NDxGCqdYKQ1SKBuFfgWbAUzBfvYjPUEeNgqN1A==} engines: {node: '>= 6'} - minimist@1.2.7: - resolution: {integrity: sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==} + minimist@1.2.8: + resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} modify-values@1.0.1: resolution: {integrity: sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw==} @@ -1446,9 +1435,6 @@ packages: nth-check@2.1.1: resolution: {integrity: sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w==} - obug@2.1.1: - resolution: {integrity: sha512-uTqF9MuPraAQ+IsnPf366RG4cP9RtUi7MLO1N3KEc+wb0a6yKpeL0lmk2IB1jY5KHPAlTc6T/JRdC/YqxHNwkQ==} - obug@2.1.3: resolution: {integrity: sha512-9miFgM2OFba7hB+pRgvtV84pYTBaoTHohvmIgiRt6dRIzbwEOIaNaP+dIlGs2fNFoB0SeISs0Jz5WFVRid6Xyg==} engines: {node: '>=12.20.0'} @@ -1538,8 +1524,9 @@ packages: resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} engines: {node: '>=0.10.0'} - resolve@1.22.1: - resolution: {integrity: sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==} + resolve@1.22.12: + resolution: {integrity: sha512-TyeJ1zif53BPfHootBGwPRYT1RUt6oGWsaQr8UyZW/eAm9bKoijtvruSDEmZHm92CwS9nj7/fWttqPCgzep8CA==} + engines: {node: '>= 0.4'} hasBin: true retry@0.13.1: @@ -1561,13 +1548,13 @@ packages: resolution: {integrity: sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==} hasBin: true - semver@7.6.1: - resolution: {integrity: sha512-f/vbBsu+fOiYt+lmwZV0rVwJScl46HppnOA1ZvIuBWKOTlllpyJ3bfVax76/OrhCH38dyxoDIA8K7uB963IYgA==} + semver@7.8.0: + resolution: {integrity: sha512-AcM7dV/5ul4EekoQ29Agm5vri8JNqRyj39o0qpX6vDF2GZrtutZl5RwgD1XnZjiTAfncsJhMI48QQH3sN87YNA==} engines: {node: '>=10'} hasBin: true - semver@7.8.0: - resolution: {integrity: sha512-AcM7dV/5ul4EekoQ29Agm5vri8JNqRyj39o0qpX6vDF2GZrtutZl5RwgD1XnZjiTAfncsJhMI48QQH3sN87YNA==} + semver@7.8.5: + resolution: {integrity: sha512-Y7/KDsb8LjooZpwaqGyulO6DQlksgCncchHGk+sZIY4SBvUocMBEFH5Ur1fI4dV+Jvl0w6cjvucaIi40puRioA==} engines: {node: '>=10'} hasBin: true @@ -1599,17 +1586,17 @@ packages: resolution: {integrity: sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==} engines: {node: '>=0.10.0'} - spdx-correct@3.1.1: - resolution: {integrity: sha512-cOYcUWwhCuHCXi49RhFRCyJEK3iPj1Ziz9DpViV3tbZOwXD49QzIN3MpOLJNxh2qwq2lJJZaKMVw9qNi4jTC0w==} + spdx-correct@3.2.0: + resolution: {integrity: sha512-kN9dJbvnySHULIluDHy32WHRUu3Og7B9sbY7tsFLctQkIqnMh3hErYgdMjTYuqmcXX+lK5T1lnUt3G7zNswmZA==} - spdx-exceptions@2.3.0: - resolution: {integrity: sha512-/tTrYOC7PPI1nUAgx34hUpqXuyJG+DTHJTnIULG4rDygi4xu/tfgmq1e1cIRwRzwZgo4NLySi+ricLkZkw4i5A==} + spdx-exceptions@2.5.0: + resolution: {integrity: sha512-PiU42r+xO4UbUS1buo3LPJkjlO7430Xn5SVAhdpzzsPHsjbYVflnnFdATgabnLude+Cqu25p6N+g2lw/PFsa4w==} spdx-expression-parse@3.0.1: resolution: {integrity: sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==} - spdx-license-ids@3.0.12: - resolution: {integrity: sha512-rr+VVSXtRhO4OHbXUiAF7xW3Bo9DuuF6C5jH+q/x15j2jniycgKbxU09Hr0WqlSLUs4i4ltHGXqTe7VHclYWyA==} + spdx-license-ids@3.0.23: + resolution: {integrity: sha512-CWLcCCH7VLu13TgOH+r8p1O/Znwhqv/dbb6lqWy67G+pT1kHmeD/+V36AVb/vq8QMIQwVShJ6Ssl5FPh0fuSdw==} split@1.0.1: resolution: {integrity: sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==} @@ -1733,8 +1720,8 @@ packages: engines: {node: '>=14.17'} hasBin: true - uglify-js@3.17.4: - resolution: {integrity: sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==} + uglify-js@3.19.3: + resolution: {integrity: sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ==} engines: {node: '>=0.8.0'} hasBin: true @@ -1744,6 +1731,9 @@ packages: undici-types@7.16.0: resolution: {integrity: sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==} + undici-types@8.3.0: + resolution: {integrity: sha512-j375ScV60dom+YkPFIfTLcOiPxkN/buHz5GobjLhixFuANaNs3C9l4GmrWqejgXWJ7BbJcFYpTEUkS1Ge8bpZQ==} + undici@6.25.0: resolution: {integrity: sha512-ZgpWDC5gmNiuY9CnLVXEH8rl50xhRCuLNA97fAUnKi8RRuV4E6KG31pDTsLVUKnohJE0I3XDrTeEydAXRw47xg==} engines: {node: '>=18.17'} @@ -1917,10 +1907,6 @@ packages: resolution: {integrity: sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==} engines: {node: '>=10'} - yargs-parser@20.2.9: - resolution: {integrity: sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w==} - engines: {node: '>=10'} - yargs-parser@21.1.1: resolution: {integrity: sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==} engines: {node: '>=12'} @@ -1935,21 +1921,21 @@ packages: snapshots: - '@actions/core@1.11.1': + '@actions/core@3.0.1': dependencies: - '@actions/exec': 1.1.1 - '@actions/http-client': 2.2.3 + '@actions/exec': 3.0.0 + '@actions/http-client': 4.0.1 - '@actions/exec@1.1.1': + '@actions/exec@3.0.0': dependencies: - '@actions/io': 1.1.3 + '@actions/io': 3.0.2 - '@actions/http-client@2.2.3': + '@actions/http-client@4.0.1': dependencies: tunnel: 0.0.6 undici: 6.25.0 - '@actions/io@1.1.3': {} + '@actions/io@3.0.2': {} '@babel/code-frame@7.12.11': dependencies: @@ -1957,13 +1943,11 @@ snapshots: '@babel/helper-string-parser@7.27.1': {} - '@babel/helper-validator-identifier@7.19.1': {} - '@babel/helper-validator-identifier@7.28.5': {} '@babel/highlight@7.18.6': dependencies: - '@babel/helper-validator-identifier': 7.19.1 + '@babel/helper-validator-identifier': 7.28.5 chalk: 2.4.2 js-tokens: 4.0.0 @@ -2045,30 +2029,30 @@ snapshots: '@inquirer/ansi@2.0.5': {} - '@inquirer/confirm@6.0.13(@types/node@24.12.4)': + '@inquirer/confirm@6.0.13(@types/node@26.0.1)': dependencies: - '@inquirer/core': 11.1.10(@types/node@24.12.4) - '@inquirer/type': 4.0.5(@types/node@24.12.4) + '@inquirer/core': 11.1.10(@types/node@26.0.1) + '@inquirer/type': 4.0.5(@types/node@26.0.1) optionalDependencies: - '@types/node': 24.12.4 + '@types/node': 26.0.1 - '@inquirer/core@11.1.10(@types/node@24.12.4)': + '@inquirer/core@11.1.10(@types/node@26.0.1)': dependencies: '@inquirer/ansi': 2.0.5 '@inquirer/figures': 2.0.5 - '@inquirer/type': 4.0.5(@types/node@24.12.4) + '@inquirer/type': 4.0.5(@types/node@26.0.1) cli-width: 4.1.0 fast-wrap-ansi: 0.2.0 mute-stream: 3.0.0 signal-exit: 4.1.0 optionalDependencies: - '@types/node': 24.12.4 + '@types/node': 26.0.1 '@inquirer/figures@2.0.5': {} - '@inquirer/type@4.0.5(@types/node@24.12.4)': + '@inquirer/type@4.0.5(@types/node@26.0.1)': optionalDependencies: - '@types/node': 24.12.4 + '@types/node': 26.0.1 '@jridgewell/resolve-uri@3.1.2': {} @@ -2085,7 +2069,7 @@ snapshots: '@lerna/validation-error': 6.4.1 npm-package-arg: 8.1.1 npmlog: 6.0.2 - semver: 7.6.1 + semver: 7.8.0 '@lerna/package@6.4.1': dependencies: @@ -2095,7 +2079,7 @@ snapshots: '@lerna/prerelease-id-from-version@6.4.1': dependencies: - semver: 7.6.1 + semver: 7.8.0 '@lerna/validation-error@6.4.1': dependencies: @@ -2271,6 +2255,15 @@ snapshots: dependencies: '@octokit/types': 16.0.0 + '@octokit/request@10.0.11': + dependencies: + '@octokit/endpoint': 11.0.3 + '@octokit/request-error': 7.1.0 + '@octokit/types': 16.0.0 + content-type: 2.0.0 + json-with-bigint: 3.5.8 + universal-user-agent: 7.0.3 + '@octokit/request@10.0.9': dependencies: '@octokit/endpoint': 11.0.3 @@ -2431,13 +2424,17 @@ snapshots: dependencies: '@types/npm-package-arg': 6.1.4 - '@types/minimist@1.2.2': {} + '@types/minimist@1.2.5': {} '@types/node@24.12.4': dependencies: undici-types: 7.16.0 - '@types/normalize-package-data@2.4.1': {} + '@types/node@26.0.1': + dependencies: + undici-types: 8.3.0 + + '@types/normalize-package-data@2.4.4': {} '@types/npm-package-arg@6.1.4': {} @@ -2465,19 +2462,19 @@ snapshots: '@vercel/ncc@0.38.4': {} - '@vitest/coverage-v8@4.1.6(vitest@4.1.9)': + '@vitest/coverage-v8@4.1.9(vitest@4.1.9)': dependencies: '@bcoe/v8-coverage': 1.0.2 - '@vitest/utils': 4.1.6 + '@vitest/utils': 4.1.9 ast-v8-to-istanbul: 1.0.0 istanbul-lib-coverage: 3.2.2 istanbul-lib-report: 3.0.1 istanbul-reports: 3.2.0 magicast: 0.5.3 - obug: 2.1.1 + obug: 2.1.3 std-env: 4.1.0 tinyrainbow: 3.1.0 - vitest: 4.1.9(@types/node@24.12.4)(@vitest/coverage-v8@4.1.6)(msw@2.14.6(@types/node@24.12.4)(typescript@5.9.3))(vite@8.0.13(@types/node@24.12.4)(yaml@2.9.0)) + vitest: 4.1.9(@types/node@26.0.1)(@vitest/coverage-v8@4.1.9)(msw@2.14.6(@types/node@26.0.1)(typescript@5.9.3))(vite@8.0.13(@types/node@26.0.1)(yaml@2.9.0)) '@vitest/expect@4.1.9': dependencies: @@ -2488,18 +2485,14 @@ snapshots: chai: 6.2.2 tinyrainbow: 3.1.0 - '@vitest/mocker@4.1.9(msw@2.14.6(@types/node@24.12.4)(typescript@5.9.3))(vite@8.0.13(@types/node@24.12.4)(yaml@2.9.0))': + '@vitest/mocker@4.1.9(msw@2.14.6(@types/node@26.0.1)(typescript@5.9.3))(vite@8.0.13(@types/node@26.0.1)(yaml@2.9.0))': dependencies: '@vitest/spy': 4.1.9 estree-walker: 3.0.3 magic-string: 0.30.21 optionalDependencies: - msw: 2.14.6(@types/node@24.12.4)(typescript@5.9.3) - vite: 8.0.13(@types/node@24.12.4)(yaml@2.9.0) - - '@vitest/pretty-format@4.1.6': - dependencies: - tinyrainbow: 3.1.0 + msw: 2.14.6(@types/node@26.0.1)(typescript@5.9.3) + vite: 8.0.13(@types/node@26.0.1)(yaml@2.9.0) '@vitest/pretty-format@4.1.9': dependencies: @@ -2519,12 +2512,6 @@ snapshots: '@vitest/spy@4.1.9': {} - '@vitest/utils@4.1.6': - dependencies: - '@vitest/pretty-format': 4.1.6 - convert-source-map: 2.0.0 - tinyrainbow: 3.1.0 - '@vitest/utils@4.1.9': dependencies: '@vitest/pretty-format': 4.1.9 @@ -2684,7 +2671,7 @@ snapshots: handlebars: 4.7.9 json-stringify-safe: 5.0.1 meow: 8.1.2 - semver: 7.6.1 + semver: 7.8.5 split: 1.0.1 conventional-commits-filter@3.0.0: @@ -2725,8 +2712,6 @@ snapshots: detect-indent@5.0.0: {} - detect-indent@6.1.0: {} - detect-libc@2.1.2: {} diff@5.2.2: {} @@ -2761,6 +2746,8 @@ snapshots: dependencies: is-arrayish: 0.2.1 + es-errors@1.3.0: {} + es-module-lexer@2.2.0: {} escalade@3.1.2: {} @@ -2819,7 +2806,7 @@ snapshots: fsevents@2.3.3: optional: true - function-bind@1.1.1: {} + function-bind@1.1.2: {} gauge@4.0.4: dependencies: @@ -2849,12 +2836,12 @@ snapshots: handlebars@4.7.9: dependencies: - minimist: 1.2.7 + minimist: 1.2.8 neo-async: 2.6.2 source-map: 0.6.1 wordwrap: 1.0.0 optionalDependencies: - uglify-js: 3.17.4 + uglify-js: 3.19.3 hard-rejection@2.1.0: {} @@ -2864,9 +2851,9 @@ snapshots: has-unicode@2.0.1: {} - has@1.0.3: + hasown@2.0.4: dependencies: - function-bind: 1.1.1 + function-bind: 1.1.2 he@1.2.0: {} @@ -2914,9 +2901,9 @@ snapshots: is-arrayish@0.2.1: {} - is-core-module@2.11.0: + is-core-module@2.16.2: dependencies: - has: 1.0.3 + hasown: 2.0.4 is-fullwidth-code-point@3.0.0: {} @@ -3050,7 +3037,7 @@ snapshots: make-dir@4.0.0: dependencies: - semver: 7.6.1 + semver: 7.8.0 map-obj@1.0.1: {} @@ -3058,7 +3045,7 @@ snapshots: meow@8.1.2: dependencies: - '@types/minimist': 1.2.2 + '@types/minimist': 1.2.5 camelcase-keys: 6.2.2 decamelize-keys: 1.1.1 hard-rejection: 2.1.0 @@ -3068,7 +3055,7 @@ snapshots: redent: 3.0.0 trim-newlines: 3.0.1 type-fest: 0.18.1 - yargs-parser: 20.2.9 + yargs-parser: 20.2.4 min-indent@1.0.1: {} @@ -3086,15 +3073,15 @@ snapshots: is-plain-obj: 1.1.0 kind-of: 6.0.3 - minimist@1.2.7: {} + minimist@1.2.8: {} modify-values@1.0.1: {} ms@2.1.2: {} - msw@2.14.6(@types/node@24.12.4)(typescript@5.9.3): + msw@2.14.6(@types/node@26.0.1)(typescript@5.9.3): dependencies: - '@inquirer/confirm': 6.0.13(@types/node@24.12.4) + '@inquirer/confirm': 6.0.13(@types/node@26.0.1) '@mswjs/interceptors': 0.41.9 '@open-draft/deferred-promise': 3.0.0 '@types/statuses': 2.0.6 @@ -3135,21 +3122,21 @@ snapshots: normalize-package-data@2.5.0: dependencies: hosted-git-info: 2.8.9 - resolve: 1.22.1 + resolve: 1.22.12 semver: 5.7.2 validate-npm-package-license: 3.0.4 normalize-package-data@3.0.3: dependencies: hosted-git-info: 4.1.0 - is-core-module: 2.11.0 - semver: 7.6.1 + is-core-module: 2.16.2 + semver: 7.8.5 validate-npm-package-license: 3.0.4 npm-package-arg@8.1.1: dependencies: hosted-git-info: 3.0.8 - semver: 7.6.1 + semver: 7.8.0 validate-npm-package-name: 3.0.0 npmlog@6.0.2: @@ -3163,8 +3150,6 @@ snapshots: dependencies: boolbase: 1.0.0 - obug@2.1.1: {} - obug@2.1.3: {} once@1.4.0: @@ -3224,7 +3209,7 @@ snapshots: read-pkg@5.2.0: dependencies: - '@types/normalize-package-data': 2.4.1 + '@types/normalize-package-data': 2.4.4 normalize-package-data: 2.5.0 parse-json: 5.2.0 type-fest: 0.6.0 @@ -3244,9 +3229,10 @@ snapshots: require-from-string@2.0.2: {} - resolve@1.22.1: + resolve@1.22.12: dependencies: - is-core-module: 2.11.0 + es-errors: 1.3.0 + is-core-module: 2.16.2 path-parse: 1.0.7 supports-preserve-symlinks-flag: 1.0.0 @@ -3279,10 +3265,10 @@ snapshots: semver@5.7.2: {} - semver@7.6.1: {} - semver@7.8.0: {} + semver@7.8.5: {} + set-blocking@2.0.0: {} set-cookie-parser@3.1.0: {} @@ -3301,19 +3287,19 @@ snapshots: source-map@0.6.1: {} - spdx-correct@3.1.1: + spdx-correct@3.2.0: dependencies: spdx-expression-parse: 3.0.1 - spdx-license-ids: 3.0.12 + spdx-license-ids: 3.0.23 - spdx-exceptions@2.3.0: {} + spdx-exceptions@2.5.0: {} spdx-expression-parse@3.0.1: dependencies: - spdx-exceptions: 2.3.0 - spdx-license-ids: 3.0.12 + spdx-exceptions: 2.5.0 + spdx-license-ids: 3.0.23 - spdx-license-ids@3.0.12: {} + spdx-license-ids@3.0.23: {} split@1.0.1: dependencies: @@ -3409,13 +3395,15 @@ snapshots: typescript@5.9.3: {} - uglify-js@3.17.4: + uglify-js@3.19.3: optional: true underscore@1.13.8: {} undici-types@7.16.0: {} + undici-types@8.3.0: {} + undici@6.25.0: {} unist-util-is@4.1.0: {} @@ -3443,14 +3431,14 @@ snapshots: validate-npm-package-license@3.0.4: dependencies: - spdx-correct: 3.1.1 + spdx-correct: 3.2.0 spdx-expression-parse: 3.0.1 validate-npm-package-name@3.0.0: dependencies: builtins: 1.0.3 - vite@8.0.13(@types/node@24.12.4)(yaml@2.9.0): + vite@8.0.13(@types/node@26.0.1)(yaml@2.9.0): dependencies: lightningcss: 1.32.0 picomatch: 4.0.4 @@ -3458,14 +3446,14 @@ snapshots: rolldown: 1.0.1 tinyglobby: 0.2.17 optionalDependencies: - '@types/node': 24.12.4 + '@types/node': 26.0.1 fsevents: 2.3.3 yaml: 2.9.0 - vitest@4.1.9(@types/node@24.12.4)(@vitest/coverage-v8@4.1.6)(msw@2.14.6(@types/node@24.12.4)(typescript@5.9.3))(vite@8.0.13(@types/node@24.12.4)(yaml@2.9.0)): + vitest@4.1.9(@types/node@26.0.1)(@vitest/coverage-v8@4.1.9)(msw@2.14.6(@types/node@26.0.1)(typescript@5.9.3))(vite@8.0.13(@types/node@26.0.1)(yaml@2.9.0)): dependencies: '@vitest/expect': 4.1.9 - '@vitest/mocker': 4.1.9(msw@2.14.6(@types/node@24.12.4)(typescript@5.9.3))(vite@8.0.13(@types/node@24.12.4)(yaml@2.9.0)) + '@vitest/mocker': 4.1.9(msw@2.14.6(@types/node@26.0.1)(typescript@5.9.3))(vite@8.0.13(@types/node@26.0.1)(yaml@2.9.0)) '@vitest/pretty-format': 4.1.9 '@vitest/runner': 4.1.9 '@vitest/snapshot': 4.1.9 @@ -3482,11 +3470,11 @@ snapshots: tinyexec: 1.2.4 tinyglobby: 0.2.17 tinyrainbow: 3.1.0 - vite: 8.0.13(@types/node@24.12.4)(yaml@2.9.0) + vite: 8.0.13(@types/node@26.0.1)(yaml@2.9.0) why-is-node-running: 2.3.0 optionalDependencies: - '@types/node': 24.12.4 - '@vitest/coverage-v8': 4.1.6(vitest@4.1.9) + '@types/node': 26.0.1 + '@vitest/coverage-v8': 4.1.9(vitest@4.1.9) transitivePeerDependencies: - msw @@ -3547,8 +3535,6 @@ snapshots: yargs-parser@20.2.4: {} - yargs-parser@20.2.9: {} - yargs-parser@21.1.1: {} yargs@16.2.0: diff --git a/src/commit.ts b/src/commit.ts index 2a49292e4..c3d2a265d 100644 --- a/src/commit.ts +++ b/src/commit.ts @@ -12,10 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -// eslint-disable-next-line @typescript-eslint/no-var-requires -const visit = require('unist-util-visit'); -// eslint-disable-next-line @typescript-eslint/no-var-requires -const visitWithAncestors = require('unist-util-visit-parents'); +import {visit, visitWithAncestors} from './util/unist-visit'; + const NUMBER_REGEX = /^[0-9]+$/; import {PullRequest} from './pull-request'; import {logger as defaultLogger, Logger} from './util/logger'; diff --git a/src/main.ts b/src/main.ts index 35018d17b..7172f52e8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -19,7 +19,6 @@ // access library return values; here we capture the structured results and // surface them via `core.setOutput`. -import * as core from '@actions/core'; import {parseRepoUrl} from './util/parse-repo-url'; import {GitHub} from './github'; @@ -32,6 +31,11 @@ import { } from './manifest'; import {PullRequest} from './pull-request'; +// @actions/core is published as ESM-only as of v3, but this action is +// bundled by ncc as CommonJS, so it must be loaded via dynamic import. +type Core = typeof import('@actions/core'); +let core: Core; + type Command = 'release-pr' | 'github-release' | 'both'; interface ActionInputs { @@ -211,13 +215,20 @@ async function main(): Promise { core.setOutput('pr', firstPr ? JSON.stringify(firstPr) : ''); } -main().catch(err => { - // We deliberately avoid printing the request object (which can contain the - // token) the way the CLI's handleError does; @actions/core.setFailed already - // surfaces a clean error to the workflow summary. - const message = err instanceof Error ? err.message : String(err); - if (err instanceof Error && err.stack) { - core.debug(err.stack); +async function run(): Promise { + core = await import('@actions/core'); + try { + await main(); + } catch (err) { + // We deliberately avoid printing the request object (which can contain + // the token) the way the CLI's handleError does; @actions/core.setFailed + // already surfaces a clean error to the workflow summary. + const message = err instanceof Error ? err.message : String(err); + if (err instanceof Error && err.stack) { + core.debug(err.stack); + } + core.setFailed(`release-please action failed: ${message}`); } - core.setFailed(`release-please action failed: ${message}`); -}); +} + +run(); diff --git a/src/util/detect-indent.ts b/src/util/detect-indent.ts new file mode 100644 index 000000000..0ed86bf52 --- /dev/null +++ b/src/util/detect-indent.ts @@ -0,0 +1,153 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Vendored from detect-indent (MIT, sindresorhus/detect-indent), which as of +// v7 is published as ESM-only and can no longer be `require()`d from this +// CommonJS codebase. + +const INDENT_REGEX = /^(?:( )+|\t+)/; + +type IndentType = 'space' | 'tab'; + +function shouldIgnoreSingleSpace( + ignoreSingleSpaces: boolean, + indentType: IndentType, + value: number +): boolean { + return ignoreSingleSpaces && indentType === 'space' && value === 1; +} + +function encodeIndentsKey(indentType: IndentType, indentAmount: number) { + return (indentType === 'space' ? 's' : 't') + String(indentAmount); +} + +function decodeIndentsKey(indentsKey: string) { + const type: IndentType = indentsKey[0] === 's' ? 'space' : 'tab'; + const amount = Number(indentsKey.slice(1)); + return {type, amount}; +} + +function makeIndentsMap(string: string, ignoreSingleSpaces: boolean) { + const indents = new Map(); + + let previousSize = 0; + let previousIndentType = ''; + let key: string | undefined; + + for (const line of string.split(/\n/g)) { + if (!line) { + continue; + } + + const matches = line.match(INDENT_REGEX); + + if (matches === null) { + previousSize = 0; + previousIndentType = ''; + continue; + } + + const indent = matches[0].length; + const indentType: IndentType = matches[1] ? 'space' : 'tab'; + + if (shouldIgnoreSingleSpace(ignoreSingleSpaces, indentType, indent)) { + continue; + } + + if (indentType !== previousIndentType) { + previousSize = 0; + } + + previousIndentType = indentType; + + let use = 1; + let weight = 0; + + const indentDifference = indent - previousSize; + previousSize = indent; + + if (indentDifference === 0) { + use = 0; + weight = 1; + } else { + const absoluteIndentDifference = Math.abs(indentDifference); + + if ( + shouldIgnoreSingleSpace( + ignoreSingleSpaces, + indentType, + absoluteIndentDifference + ) + ) { + continue; + } + + key = encodeIndentsKey(indentType, absoluteIndentDifference); + } + + if (key !== undefined) { + const entry = indents.get(key); + indents.set( + key, + entry === undefined ? [1, 0] : [entry[0] + use, entry[1] + weight] + ); + } + } + + return indents; +} + +function getMostUsedKey(indents: Map) { + let result: string | undefined; + let maxUsed = 0; + let maxWeight = 0; + + for (const [key, [usedCount, weight]] of indents) { + if (usedCount > maxUsed || (usedCount === maxUsed && weight > maxWeight)) { + maxUsed = usedCount; + maxWeight = weight; + result = key; + } + } + + return result; +} + +function makeIndentString(type: IndentType, amount: number) { + return (type === 'space' ? ' ' : '\t').repeat(amount); +} + +export function detectIndent(string: string): { + amount: number; + type?: IndentType; + indent: string; +} { + let indents = makeIndentsMap(string, true); + if (indents.size === 0) { + indents = makeIndentsMap(string, false); + } + + const keyOfMostUsedIndent = getMostUsedKey(indents); + + let type: IndentType | undefined; + let amount = 0; + let indent = ''; + + if (keyOfMostUsedIndent !== undefined) { + ({type, amount} = decodeIndentsKey(keyOfMostUsedIndent)); + indent = makeIndentString(type, amount); + } + + return {amount, type, indent}; +} diff --git a/src/util/json-stringify.ts b/src/util/json-stringify.ts index 60f0cf72b..5e4aee33a 100644 --- a/src/util/json-stringify.ts +++ b/src/util/json-stringify.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import detectIndent = require('detect-indent'); +import {detectIndent} from './detect-indent'; export function jsonStringify( parsed: object, diff --git a/src/util/unist-visit.ts b/src/util/unist-visit.ts new file mode 100644 index 000000000..785adf35f --- /dev/null +++ b/src/util/unist-visit.ts @@ -0,0 +1,82 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Minimal replacement for unist-util-visit/unist-util-visit-parents (both +// MIT, unifiedjs/unist-util-visit*), which as of unist-util-visit@3 / +// unist-util-visit-parents@4 are published as ESM-only and can no longer be +// `require()`d from this CommonJS codebase. We only ever call these with a +// node-type test (string or array of strings, or omitted to match every +// node) and a visitor that doesn't use the SKIP/EXIT control signals, so a +// full port of the upstream packages isn't needed. + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +type UnistNode = {type: string; children?: any[]}; + +function matchesTest( + node: UnistNode, + test: string | string[] | undefined +): boolean { + if (test === undefined) { + return true; + } + return Array.isArray(test) ? test.includes(node.type) : node.type === test; +} + +// Loosely typed (like the `require()`-based code this replaces) since +// call sites annotate the visited node as whichever specific AST subtype +// they expect at that point in the tree, not the type of the tree root. +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function visit( + tree: any, // eslint-disable-line @typescript-eslint/no-explicit-any + testOrVisitor: string | string[] | ((node: any) => void), // eslint-disable-line @typescript-eslint/no-explicit-any + maybeVisitor?: (node: any) => void // eslint-disable-line @typescript-eslint/no-explicit-any +): void { + const test = + typeof testOrVisitor === 'function' ? undefined : testOrVisitor; + const visitor = + typeof testOrVisitor === 'function' ? testOrVisitor : maybeVisitor; + if (!tree || !visitor) { + return; + } + + const walk = (node: UnistNode) => { + if (matchesTest(node, test)) { + visitor(node); + } + for (const child of node.children ?? []) { + walk(child); + } + }; + walk(tree); +} + +export function visitWithAncestors( + tree: any, // eslint-disable-line @typescript-eslint/no-explicit-any + test: string | string[] | undefined, + visitor: (node: any, ancestors: any[]) => void // eslint-disable-line @typescript-eslint/no-explicit-any +): void { + if (!tree) { + return; + } + + const walk = (node: UnistNode, ancestors: UnistNode[]) => { + if (matchesTest(node, test)) { + visitor(node, ancestors); + } + for (const child of node.children ?? []) { + walk(child, [...ancestors, node]); + } + }; + walk(tree, []); +}