diff --git a/.commitlintrc.js b/.commitlintrc.js index cf8f3d76..5b0b1a52 100644 --- a/.commitlintrc.js +++ b/.commitlintrc.js @@ -1,10 +1,9 @@ -// This file is automatically added by @npmcli/template-oss. Do not edit. +/* This file is automatically added by @npmcli/template-oss. Do not edit. */ module.exports = { extends: ['@commitlint/config-conventional'], - // If you change rules be sure to also update release-please.yml rules: { - 'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'chore', 'deps']], + 'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'deps', 'chore']], 'header-max-length': [2, 'always', 80], 'subject-case': [0, 'always', ['lower-case', 'sentence-case', 'start-case']], }, diff --git a/.eslintrc.js b/.eslintrc.js index 022767bc..5db9f815 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,4 +1,6 @@ -// This file is automatically added by @npmcli/template-oss. Do not edit. +/* This file is automatically added by @npmcli/template-oss. Do not edit. */ + +'use strict' const { readdirSync: readdir } = require('fs') @@ -7,6 +9,7 @@ const localConfigs = readdir(__dirname) .map((file) => `./${file}`) module.exports = { + root: true, extends: [ '@npmcli', ...localConfigs, diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ef874313..2c54b0d2 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1,3 @@ -* @npm/cli-team +# This file is automatically added by @npmcli/template-oss. Do not edit. + +* @npm/cli-team diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index fa80b2de..d043192f 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -3,52 +3,52 @@ name: Bug description: File a bug/issue title: "[BUG] " -labels: [Bug, Needs Triage] +labels: [ Bug, Needs Triage ] + body: -- type: checkboxes - attributes: - label: Is there an existing issue for this? - description: Please [search here](./issues) to see if an issue already exists for your problem. - options: - - label: I have searched the existing issues - required: true -- type: textarea - attributes: - label: Current Behavior - description: A clear & concise description of what you're experiencing. - validations: - required: false -- type: textarea - attributes: - label: Expected Behavior - description: A clear & concise description of what you expected to happen. - validations: - required: false -- type: textarea - attributes: - label: Steps To Reproduce - description: Steps to reproduce the behavior. - value: | - 1. In this environment... - 2. With this config... - 3. Run '...' - 4. See error... - validations: - required: false -- type: textarea - attributes: - label: Environment - description: | - examples: - - **npm**: 7.6.3 - - **Node**: 13.14.0 - - **OS**: Ubuntu 20.04 - - **platform**: Macbook Pro - value: | + - type: checkboxes + attributes: + label: Is there an existing issue for this? + description: Please [search here](./issues) to see if an issue already exists for your problem. + options: + - label: I have searched the existing issues + required: true + - type: textarea + attributes: + label: Current Behavior + description: A clear & concise description of what you're experiencing. + validations: + required: false + - type: textarea + attributes: + label: Expected Behavior + description: A clear & concise description of what you expected to happen. + validations: + required: false + - type: textarea + attributes: + label: Steps To Reproduce + description: Steps to reproduce the behavior. + value: | + 1. In this environment... + 2. With this config... + 3. Run '...' + 4. See error... + validations: + required: false + - type: textarea + attributes: + label: Environment + description: | + examples: + - **npm**: 7.6.3 + - **Node**: 13.14.0 + - **OS**: Ubuntu 20.04 + - **platform**: Macbook Pro + value: | - npm: - Node: - OS: - platform: - validations: - required: false - + validations: + required: false diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4c8e23f4..96d8eafb 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,16 +1,17 @@ # This file is automatically added by @npmcli/template-oss. Do not edit. version: 2 + updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: daily - allow: - - dependency-type: direct - versioning-strategy: increase - commit-message: - prefix: deps - prefix-development: chore - labels: - - "Dependencies" + - package-ecosystem: npm + directory: "/" + schedule: + interval: daily + allow: + - dependency-type: direct + versioning-strategy: increase-if-necessary + commit-message: + prefix: deps + prefix-development: chore + labels: + - "Dependencies" diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml index 5f07e044..64716120 100644 --- a/.github/workflows/audit.yml +++ b/.github/workflows/audit.yml @@ -3,21 +3,25 @@ name: Audit on: + workflow_dispatch: schedule: # "At 01:00 on Monday" https://crontab.guru/#0_1_*_*_1 - cron: "0 1 * * 1" - workflow_dispatch: jobs: audit: - name: npm audit runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - name: Setup git user + run: | + git config --global user.email "npm-cli+bot@github.com" + git config --global user.name "npm CLI robot" + - uses: actions/setup-node@v3 with: - node-version: '16' - - name: Install deps - run: npm i --package-lock - - name: Audit - run: npm audit + node-version: 16.x + - name: Update npm to latest + run: npm i --prefer-online --no-fund --no-audit -g npm@latest + - run: npm -v + - run: npm i --ignore-scripts --no-audit --no-fund --package-lock + - run: npm audit diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 175457e2..7a62d9a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,10 @@ name: CI on: + workflow_dispatch: pull_request: + branches: + - '*' push: branches: - main @@ -16,38 +19,54 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - name: Setup git user + run: | + git config --global user.email "npm-cli+bot@github.com" + git config --global user.name "npm CLI robot" + - uses: actions/setup-node@v3 with: - node-version: '16' - - run: npm i --prefer-online -g npm@latest - - run: npm i + node-version: 16.x + - name: Update npm to latest + run: npm i --prefer-online --no-fund --no-audit -g npm@latest + - run: npm -v + - run: npm i --ignore-scripts --no-audit --no-fund - run: npm run lint test: strategy: fail-fast: false matrix: - node-version: [12.13.0, 12.x, 14.15.0, 14.x, 16.13.0, 16.x] + node-version: + - 12.13.0 + - 12.x + - 14.15.0 + - 14.x + - 16.0.0 + - 16.x platform: - - os: ubuntu-latest - shell: bash - - os: macos-latest - shell: bash - - os: windows-latest - shell: cmd + - os: ubuntu-latest + shell: bash + - os: macos-latest + shell: bash + - os: windows-latest + shell: cmd runs-on: ${{ matrix.platform.os }} defaults: run: shell: ${{ matrix.platform.shell }} steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - name: Setup git user + run: | + git config --global user.email "npm-cli+bot@github.com" + git config --global user.name "npm CLI robot" + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - # node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows - name: Update to workable npm (windows) - if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12') || startsWith(matrix.node-version, '14')) + # node 12 and 14 ship with npm@6, which is known to fail when updating itself in windows + if: matrix.platform.os == 'windows-latest' && (startsWith(matrix.node-version, '12.') || startsWith(matrix.node-version, '14.')) run: | curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz tar xf npm-7.5.4.tgz @@ -55,8 +74,13 @@ jobs: node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz cd .. rmdir /s /q package - - name: Update npm + - name: Update npm to 7 + # If we do test on npm 10 it needs npm7 + if: startsWith(matrix.node-version, '10.') + run: npm i --prefer-online --no-fund --no-audit -g npm@7 + - name: Update npm to latest + if: ${{ !startsWith(matrix.node-version, '10.') }} run: npm i --prefer-online --no-fund --no-audit -g npm@latest - run: npm -v - - run: npm i + - run: npm i --ignore-scripts --no-audit --no-fund - run: npm test --ignore-scripts diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c7694c49..5d974116 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -4,10 +4,14 @@ name: "CodeQL" on: push: - branches: [ main ] + branches: + - main + - latest pull_request: # The branches below must be a subset of the branches above - branches: [ main ] + branches: + - main + - latest schedule: # "At 03:00 on Monday" https://crontab.guru/#0_3_*_*_1 - cron: "0 3 * * 1" @@ -24,15 +28,17 @@ jobs: strategy: fail-fast: false matrix: - language: [ 'javascript' ] + language: [ javascript ] steps: - - name: Checkout repository - uses: actions/checkout@v2 - - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + - uses: actions/checkout@v3 + - name: Setup git user + run: | + git config --global user.email "npm-cli+bot@github.com" + git config --global user.name "npm CLI robot" + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/post-dependabot.yml b/.github/workflows/post-dependabot.yml index 3093c306..b6e81e6e 100644 --- a/.github/workflows/post-dependabot.yml +++ b/.github/workflows/post-dependabot.yml @@ -1,35 +1,43 @@ # This file is automatically added by @npmcli/template-oss. Do not edit. -name: "Post Dependabot Actions" +name: Post Dependabot Actions + on: pull_request -# https://docs.github.com/en/rest/overview/permissions-required-for-github-apps +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions permissions: contents: write jobs: - Install: + template-oss-apply: runs-on: ubuntu-latest - if: ${{ github.actor == 'dependabot[bot]' }} + if: github.actor == 'dependabot[bot]' steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - name: Setup git user + run: | + git config --global user.email "npm-cli+bot@github.com" + git config --global user.name "npm CLI robot" + - uses: actions/setup-node@v3 with: - node-version: '16' + node-version: 16.x + - name: Update npm to latest + run: npm i --prefer-online --no-fund --no-audit -g npm@latest + - run: npm -v - name: Dependabot metadata id: metadata uses: dependabot/fetch-metadata@v1.1.1 with: github-token: "${{ secrets.GITHUB_TOKEN }}" - name: npm install and commit - if: ${{contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')}} + if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss') env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - git config --local user.email "ops+npm-cli@npmjs.com" - git config --local user.name "npm cli ops bot" gh pr checkout ${{ github.event.pull_request.number }} - npm install + npm install --ignore-scripts --no-audit --no-fund + npm run template-oss-apply git add . git commit -am "chore: postinstall for dependabot template-oss PR" git push + npm run lint diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 948960e7..72230764 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -4,24 +4,35 @@ name: Pull Request Linting on: pull_request: - types: [opened, reopened, edited, synchronize] + types: + - opened + - reopened + - edited + - synchronize jobs: check: name: Check PR Title or Commits runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: actions/setup-node@v2 + - name: Setup git user + run: | + git config --global user.email "npm-cli+bot@github.com" + git config --global user.name "npm CLI robot" + - uses: actions/setup-node@v3 with: - node-version: '16' + node-version: 16.x + - name: Update npm to latest + run: npm i --prefer-online --no-fund --no-audit -g npm@latest + - run: npm -v - name: Install deps - run: | - npm i -D @commitlint/cli @commitlint/config-conventional + run: npm i -D @commitlint/cli @commitlint/config-conventional - name: Check commits OR PR title env: PR_TITLE: ${{ github.event.pull_request.title }} run: | - npx commitlint -x @commitlint/config-conventional -V --from origin/main --to ${{ github.event.pull_request.head.sha }} || echo $PR_TITLE | npx commitlint -x @commitlint/config-conventional -V + npx --offline commitlint -V --from origin/main --to ${{ github.event.pull_request.head.sha }} \ + || echo $PR_TITLE | npx --offline commitlint -V diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index c5a165f3..ab3a9105 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -6,19 +6,21 @@ on: push: branches: - main + - latest jobs: release-please: runs-on: ubuntu-latest steps: - - uses: google-github-actions/release-please-action@v2 + - uses: google-github-actions/release-please-action@v3 id: release with: release-type: node - # If you change changelog-types be sure to also update commitlintrc.js changelog-types: > - [{"type":"feat","section":"Features","hidden":false}, - {"type":"fix","section":"Bug Fixes","hidden":false}, - {"type":"docs","section":"Documentation","hidden":false}, - {"type":"deps","section":"Dependencies","hidden":false}, - {"type":"chore","hidden":true}] + [ + {"type":"feat","section":"Features","hidden":false}, + {"type":"fix","section":"Bug Fixes","hidden":false}, + {"type":"docs","section":"Documentation","hidden":false}, + {"type":"deps","section":"Dependencies","hidden":false}, + {"type":"chore","hidden":true} + ] diff --git a/.gitignore b/.gitignore index 6ed44c72..be5771f0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,20 +4,23 @@ /* # keep these -!/.commitlintrc.js -!/.npmrc -!/.eslintrc* -!/.github +!/.eslintrc.local.* !**/.gitignore -!/package.json -!/docs -!/bin -!/lib +!/docs/ +!/tap-snapshots/ +!/test/ !/map.js -!/tap-snapshots -!/test -!/scripts +!/scripts/ !/README* !/LICENSE* -!/SECURITY* !/CHANGELOG* +!/.commitlintrc.js +!/.eslintrc.js +!/.github/ +!/.gitignore +!/.npmrc +!/CODE_OF_CONDUCT.md +!/SECURITY.md +!/bin/ +!/lib/ +!/package.json diff --git a/.npmrc b/.npmrc index 878b7dde..529f93e7 100644 --- a/.npmrc +++ b/.npmrc @@ -1,3 +1,3 @@ -;This file is automatically added by @npmcli/template-oss. Do not edit. +; This file is automatically added by @npmcli/template-oss. Do not edit. package-lock=false diff --git a/CHANGELOG.md b/CHANGELOG.md index f729cbbb..d7481a29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,17 @@ -# Change Log +# Changelog -All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [5.1.0](https://github.com/npm/hosted-git-info/compare/v5.0.0...v5.1.0) (2022-08-09) + + +### Features + +* add method to get an edit link to a file ([ad02952](https://github.com/npm/hosted-git-info/commit/ad02952f89fbdc99e67ae0d5308029395bde3331)) + + +### Bug Fixes + +* add comments to empty catch blocks for linting ([70a770d](https://github.com/npm/hosted-git-info/commit/70a770d1202128e15887d69dfd5c930e4ff29a00)) -<a name="4.0.0"></a> ## [5.0.0](https://www.github.com/npm/hosted-git-info/compare/v4.1.0...v5.0.0) (2022-03-14) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..167043c2 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,7 @@ +<!-- This file is automatically added by @npmcli/template-oss. Do not edit. --> + +All interactions in this repo are covered by the [npm Code of +Conduct](https://docs.npmjs.com/policies/conduct) + +The npm cli team may, at its own discretion, moderate, remove, or edit +any interactions such as pull requests, issues, and comments. diff --git a/lib/git-host-info.js b/lib/git-host-info.js index 9a9720fa..cdc1e460 100644 --- a/lib/git-host-info.js +++ b/lib/git-host-info.js @@ -6,6 +6,7 @@ const maybeEncode = (arg) => arg ? encodeURIComponent(arg) : '' const defaults = { sshtemplate: ({ domain, user, project, committish }) => `git@${domain}:${user}/${project}.git${maybeJoin('#', committish)}`, sshurltemplate: ({ domain, user, project, committish }) => `git+ssh://git@${domain}/${user}/${project}.git${maybeJoin('#', committish)}`, + edittemplate: ({ domain, user, project, committish, editpath, path }) => `https://${domain}/${user}/${project}${maybeJoin('/', editpath, '/', maybeEncode(committish || 'master'), '/', path)}`, browsetemplate: ({ domain, user, project, committish, treepath }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish))}`, browsefiletemplate: ({ domain, user, project, committish, treepath, path, fragment, hashformat }) => `https://${domain}/${user}/${project}/${treepath}/${maybeEncode(committish || 'master')}/${path}${maybeJoin('#', hashformat(fragment || ''))}`, docstemplate: ({ domain, user, project, treepath, committish }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish))}#readme`, @@ -24,6 +25,7 @@ gitHosts.github = Object.assign({}, defaults, { protocols: ['git:', 'http:', 'git+ssh:', 'git+https:', 'ssh:', 'https:'], domain: 'github.com', treepath: 'tree', + editpath: 'edit', filetemplate: ({ auth, user, project, committish, path }) => `https://${maybeJoin(auth, '@')}raw.githubusercontent.com/${user}/${project}/${maybeEncode(committish) || 'master'}/${path}`, gittemplate: ({ auth, domain, user, project, committish }) => `git://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`, tarballtemplate: ({ domain, user, project, committish }) => `https://codeload.${domain}/${user}/${project}/tar.gz/${maybeEncode(committish) || 'master'}`, @@ -53,6 +55,8 @@ gitHosts.bitbucket = Object.assign({}, defaults, { protocols: ['git+ssh:', 'git+https:', 'ssh:', 'https:'], domain: 'bitbucket.org', treepath: 'src', + editpath: '?mode=edit', + edittemplate: ({ domain, user, project, committish, treepath, path, editpath }) => `https://${domain}/${user}/${project}${maybeJoin('/', treepath, '/', maybeEncode(committish || 'master'), '/', path, editpath)}`, tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/get/${maybeEncode(committish) || 'master'}.tar.gz`, extract: (url) => { let [, user, project, aux] = url.pathname.split('/', 4) @@ -76,6 +80,7 @@ gitHosts.gitlab = Object.assign({}, defaults, { protocols: ['git+ssh:', 'git+https:', 'ssh:', 'https:'], domain: 'gitlab.com', treepath: 'tree', + editpath: '-/edit', httpstemplate: ({ auth, domain, user, project, committish }) => `git+https://${maybeJoin(auth, '@')}${domain}/${user}/${project}.git${maybeJoin('#', committish)}`, tarballtemplate: ({ domain, user, project, committish }) => `https://${domain}/${user}/${project}/repository/archive.tar.gz?ref=${maybeEncode(committish) || 'master'}`, extract: (url) => { @@ -102,8 +107,10 @@ gitHosts.gitlab = Object.assign({}, defaults, { gitHosts.gist = Object.assign({}, defaults, { protocols: ['git:', 'git+ssh:', 'git+https:', 'ssh:', 'https:'], domain: 'gist.github.com', + editpath: 'edit', sshtemplate: ({ domain, project, committish }) => `git@${domain}:${project}.git${maybeJoin('#', committish)}`, sshurltemplate: ({ domain, project, committish }) => `git+ssh://git@${domain}/${project}.git${maybeJoin('#', committish)}`, + edittemplate: ({ domain, user, project, committish, editpath }) => `https://${domain}/${user}/${project}${maybeJoin('/', maybeEncode(committish))}/${editpath}`, browsetemplate: ({ domain, project, committish }) => `https://${domain}/${project}${maybeJoin('/', maybeEncode(committish))}`, browsefiletemplate: ({ domain, project, committish, path, hashformat }) => `https://${domain}/${project}${maybeJoin('/', maybeEncode(committish))}${maybeJoin('#', hashformat(path))}`, docstemplate: ({ domain, project, committish }) => `https://${domain}/${project}${maybeJoin('/', maybeEncode(committish))}`, diff --git a/lib/git-host.js b/lib/git-host.js index 8a975e92..bb65d4d9 100644 --- a/lib/git-host.js +++ b/lib/git-host.js @@ -95,6 +95,10 @@ class GitHost { return this._fill(this.filetemplate, { ...opts, path }) } + edit (path, opts) { + return this._fill(this.edittemplate, { ...opts, path }) + } + getDefaultRepresentation () { return this.default } diff --git a/lib/index.js b/lib/index.js index 8bce6b3c..d5d63c66 100644 --- a/lib/index.js +++ b/lib/index.js @@ -46,8 +46,8 @@ function fromUrl (giturl, opts) { return } - const url = isGitHubShorthand(giturl) ? 'github:' + giturl : correctProtocol(giturl) - const parsed = parseGitUrl(url) + const correctedUrl = isGitHubShorthand(giturl) ? 'github:' + giturl : correctProtocol(giturl) + const parsed = parseGitUrl(correctedUrl) if (!parsed) { return parsed } @@ -229,7 +229,9 @@ const parseGitUrl = (giturl) => { let result try { result = new url.URL(giturl) - } catch (err) {} + } catch { + // this fn should never throw + } if (result) { return result @@ -238,7 +240,9 @@ const parseGitUrl = (giturl) => { const correctedUrl = correctUrl(giturl) try { result = new url.URL(correctedUrl) - } catch (err) {} + } catch { + // this fn should never throw + } return result } diff --git a/package.json b/package.json index 0153b085..07a5587c 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "hosted-git-info", - "version": "5.0.0", + "version": "5.1.0", "description": "Provides metadata and conversions from repository urls for GitHub, Bitbucket and GitLab", "main": "./lib/index.js", "repository": { "type": "git", - "url": "git+https://github.com/npm/hosted-git-info.git" + "url": "https://github.com/npm/hosted-git-info.git" }, "keywords": [ "git", @@ -27,30 +27,32 @@ "snap": "tap", "test": "tap", "test:coverage": "tap --coverage-report=html", - "lint": "eslint '**/*.js'", - "postlint": "npm-template-check", - "template-copy": "npm-template-copy --force", - "lintfix": "npm run lint -- --fix" + "lint": "eslint \"**/*.js\"", + "postlint": "template-oss-check", + "lintfix": "npm run lint -- --fix", + "template-oss-apply": "template-oss-apply --force" }, "dependencies": { "lru-cache": "^7.5.1" }, "devDependencies": { - "@npmcli/template-oss": "^2.9.2", - "tap": "^15.1.6" + "@npmcli/eslint-config": "^3.0.1", + "@npmcli/template-oss": "3.5.0", + "tap": "^16.0.1" }, "files": [ - "bin", - "lib" + "bin/", + "lib/" ], "engines": { - "node": "^12.13.0 || ^14.15.0 || >=16" + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" }, "tap": { "color": 1, "coverage": true }, "templateOSS": { - "version": "2.9.2" + "//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", + "version": "3.5.0" } } diff --git a/test/bitbucket.js b/test/bitbucket.js index 4668e594..88795f41 100644 --- a/test/bitbucket.js +++ b/test/bitbucket.js @@ -181,6 +181,8 @@ t.test('string methods populate correctly', t => { t.equal(parsed.hash(), '', 'hash() returns empty string when committish is unset') t.equal(parsed.ssh(), 'git@bitbucket.org:foo/bar.git') t.equal(parsed.sshurl(), 'git+ssh://git@bitbucket.org/foo/bar.git') + t.equal(parsed.edit(), 'https://bitbucket.org/foo/bar') + t.equal(parsed.edit('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/master/lib/index.js?mode=edit') t.equal(parsed.browse(), 'https://bitbucket.org/foo/bar') t.equal(parsed.browse('/lib/index.js'), 'https://bitbucket.org/foo/bar/src/master/lib/index.js') t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://bitbucket.org/foo/bar/src/master/lib/index.js#l100') diff --git a/test/gist.js b/test/gist.js index 93135507..09c8392c 100644 --- a/test/gist.js +++ b/test/gist.js @@ -345,6 +345,8 @@ t.test('string methods populate correctly', t => { t.equal(parsed.hash(), '', 'hash() returns empty string when committish is unset') t.equal(parsed.ssh(), 'git@gist.github.com:feedbeef.git') t.equal(parsed.sshurl(), 'git+ssh://git@gist.github.com/feedbeef.git') + t.equal(parsed.edit(), 'https://gist.github.com/foo/feedbeef/edit', 'gist link only redirects with a user') + t.equal(parsed.edit('/lib/index.js'), 'https://gist.github.com/foo/feedbeef/edit', 'gist link only redirects with a user') t.equal(parsed.browse(), 'https://gist.github.com/feedbeef') t.equal(parsed.browse('/lib/index.js'), 'https://gist.github.com/feedbeef#file-libindex-js') t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://gist.github.com/feedbeef#file-libindex-js') diff --git a/test/github.js b/test/github.js index 23be1412..3311f32e 100644 --- a/test/github.js +++ b/test/github.js @@ -230,6 +230,9 @@ t.test('string methods populate correctly', t => { t.equal(parsed.hash(), '', 'hash() returns empty string when committish is unset') t.equal(parsed.ssh(), 'git@github.com:foo/bar.git') t.equal(parsed.sshurl(), 'git+ssh://git@github.com/foo/bar.git') + t.equal(parsed.edit(), 'https://github.com/foo/bar') + t.equal(parsed.edit('/lib/index.js'), 'https://github.com/foo/bar/edit/master/lib/index.js') + t.equal(parsed.edit('/lib/index.js', { committish: 'docs' }), 'https://github.com/foo/bar/edit/docs/lib/index.js') t.equal(parsed.browse(), 'https://github.com/foo/bar') t.equal(parsed.browse('/lib/index.js'), 'https://github.com/foo/bar/tree/master/lib/index.js') t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://github.com/foo/bar/tree/master/lib/index.js#l100') diff --git a/test/gitlab.js b/test/gitlab.js index 1975b3e6..be5187b8 100644 --- a/test/gitlab.js +++ b/test/gitlab.js @@ -287,6 +287,8 @@ t.test('string methods populate correctly', t => { t.equal(parsed.hash(), '', 'hash() returns empty string when committish is unset') t.equal(parsed.ssh(), 'git@gitlab.com:foo/bar.git') t.equal(parsed.sshurl(), 'git+ssh://git@gitlab.com/foo/bar.git') + t.equal(parsed.edit(), 'https://gitlab.com/foo/bar') + t.equal(parsed.edit('/lib/index.js'), 'https://gitlab.com/foo/bar/-/edit/master/lib/index.js') t.equal(parsed.browse(), 'https://gitlab.com/foo/bar') t.equal(parsed.browse('/lib/index.js'), 'https://gitlab.com/foo/bar/tree/master/lib/index.js') t.equal(parsed.browse('/lib/index.js', 'L100'), 'https://gitlab.com/foo/bar/tree/master/lib/index.js#l100') diff --git a/test/sourcehut.js b/test/sourcehut.js index 779bacd6..f0f3a765 100644 --- a/test/sourcehut.js +++ b/test/sourcehut.js @@ -94,6 +94,8 @@ t.test('string methods populate correctly', t => { t.equal(parsed.hash(), '', 'hash() returns empty string when committish is unset') t.equal(parsed.ssh(), 'git@git.sr.ht:~foo/bar.git') t.equal(parsed.sshurl(), 'git+ssh://git@git.sr.ht/~foo/bar.git') + t.equal(parsed.edit('/lib/index.js'), 'https://git.sr.ht/~foo/bar', 'no editing, link to browse') + t.equal(parsed.edit(), 'https://git.sr.ht/~foo/bar', 'no editing, link to browse') t.equal(parsed.browse(), 'https://git.sr.ht/~foo/bar') t.equal(parsed.browse('/lib/index.js'), 'https://git.sr.ht/~foo/bar/tree/main/lib/index.js') t.equal(