Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down Expand Up @@ -95,6 +95,7 @@ jobs:
- 20.x
- 22.9.0
- 22.x
- 24.x
exclude:
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.17.0
Expand All @@ -104,6 +105,8 @@ jobs:
node-version: 22.9.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 24.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
Expand Down Expand Up @@ -137,9 +140,14 @@ jobs:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Add Problem Matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- name: Test (with coverage on Node >= 24)
if: ${{ startsWith(matrix.node-version, '24') }}
run: npm run test:cover --ignore-scripts
- name: Test (on Node 20 with globbing workaround)
if: ${{ startsWith(matrix.node-version, '20') }}
run: npm run test:node20 --ignore-scripts
- name: Test
if: ${{ !startsWith(matrix.node-version, '24') && !startsWith(matrix.node-version, '20') }}
run: npm test --ignore-scripts
- name: Conclude Check
uses: LouisBrunner/checks-action@v1.6.0
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down Expand Up @@ -71,6 +71,7 @@ jobs:
- 20.x
- 22.9.0
- 22.x
- 24.x
exclude:
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.17.0
Expand All @@ -80,6 +81,8 @@ jobs:
node-version: 22.9.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 24.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
Expand All @@ -103,7 +106,12 @@ jobs:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Add Problem Matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- name: Test (with coverage on Node >= 24)
if: ${{ startsWith(matrix.node-version, '24') }}
run: npm run test:cover --ignore-scripts
- name: Test (on Node 20 with globbing workaround)
if: ${{ startsWith(matrix.node-version, '20') }}
run: npm run test:node20 --ignore-scripts
- name: Test
if: ${{ !startsWith(matrix.node-version, '24') && !startsWith(matrix.node-version, '20') }}
run: npm test --ignore-scripts
4 changes: 2 additions & 2 deletions .github/workflows/post-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down Expand Up @@ -119,8 +119,8 @@ jobs:
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
node-version: 24.x
check-latest: contains('24.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
Expand Down
9 changes: 9 additions & 0 deletions lib/fixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,12 @@ function unParsePerson (person) {
}

function parsePerson (person) {
/* node:coverage disable */
// not possible in normal flow
if (typeof person !== 'string') {
return person
}
/* node:coverage enable */
var matchedName = person.match(/^([^(<]+)/)
var matchedUrl = person.match(/\(([^()]+)\)/)
var matchedEmail = person.match(/<([^<>]+)>/)
Expand Down Expand Up @@ -425,9 +428,12 @@ function addOptionalDepsToDeps (data) {
}

function depObjectify (deps, type, warn) {
/* node:coverage disable */
// not possible in normal flow
if (!deps) {
return {}
}
/* node:coverage enable */
if (typeof deps === 'string') {
deps = deps.trim().split(/[\n\r\s\t ,]+/)
}
Expand Down Expand Up @@ -459,9 +465,12 @@ function objectifyDeps (data, warn) {
}

function bugsTypos (bugs, warn) {
/* node:coverage disable */
// not possible in normal flow
if (!bugs) {
return
}
/* node:coverage enable */
Object.keys(bugs).forEach(function (k) {
if (typos.bugs[k]) {
warn('typo', k, typos.bugs[k], 'bugs')
Expand Down
26 changes: 10 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
},
"main": "lib/normalize.js",
"scripts": {
"test": "tap",
"test": "node --test './test/**/*.js'",
"npmclilint": "npmcli-lint",
"lint": "npm run eslint",
"lintfix": "npm run eslint -- --fix",
"posttest": "npm run lint",
"postsnap": "npm run lintfix --",
"postlint": "template-oss-check",
"snap": "tap",
"snap": "node --test --test-update-snapshots './test/**/*.js'",
"template-oss-apply": "template-oss-apply --force",
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"",
"test:node20": "node --test test",
"test:cover": "node --test --experimental-test-coverage --test-timeout=3000 --test-coverage-lines=97 --test-coverage-functions=97 --test-coverage-branches=97 './test/**/*.js'"
},
"dependencies": {
"hosted-git-info": "^9.0.0",
Expand All @@ -28,8 +30,7 @@
},
"devDependencies": {
"@npmcli/eslint-config": "^6.0.0",
"@npmcli/template-oss": "4.28.1",
"tap": "^16.0.1"
"@npmcli/template-oss": "4.28.1"
},
"files": [
"bin/",
Expand All @@ -41,16 +42,9 @@
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.28.1",
"publish": "true"
},
"tap": {
"branches": 86,
"functions": 92,
"lines": 86,
"statements": 86,
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
"publish": "true",
"testRunner": "node:test",
"latestCiVersion": 24,
"coverageThreshold": 97
}
}
50 changes: 26 additions & 24 deletions test/basic.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
var tap = require('tap')
var normalize = require('../lib/normalize')
var path = require('path')
var fs = require('fs')
const test = require('node:test')
const assert = require('node:assert')
const normalize = require('../lib/normalize')
const path = require('path')
const fs = require('fs')

tap.test('basic test', function (t) {
test('basic test', function (t, done) {
var p = path.resolve(__dirname, './fixtures/read-package-json.json')
fs.readFile(p, function (err, contents) {
if (err) {
Expand All @@ -12,28 +13,29 @@ tap.test('basic test', function (t) {
var originalData = JSON.parse(contents.toString())
var data = JSON.parse(contents.toString())
normalize(data)
t.ok(data)
verifyFields(t, data, originalData)
t.end()
assert.ok(data)
verifyFields(data, originalData)
done()
})
})

function verifyFields (t, normalized, original) {
t.equal(normalized.version, original.version, 'Version field stays same')
t.equal(normalized._id, normalized.name + '@' + normalized.version, 'It gets good id.')
t.equal(normalized.name, original.name, 'Name stays the same.')
t.type(normalized.author, 'object', 'author field becomes object')
t.same(normalized.scripts, original.scripts, 'scripts field (object) stays same')
t.equal(normalized.main, original.main)
function verifyFields (normalized, original) {
assert.strictEqual(normalized.version, original.version, 'Version field stays same')
assert.strictEqual(normalized._id, normalized.name + '@' + normalized.version, 'It gets good id.')
assert.strictEqual(normalized.name, original.name, 'Name stays the same.')
assert.strictEqual(typeof normalized.author, 'object', 'author field becomes object')
assert.deepStrictEqual(normalized.scripts, original.scripts, 'scripts field (object) stays same')
assert.strictEqual(normalized.main, original.main)
// optional deps are folded in.
t.same(normalized.optionalDependencies,
assert.deepStrictEqual(normalized.optionalDependencies,
original.optionalDependencies)
t.has(
normalized.dependencies,
original.optionalDependencies, 'opt depedencies are copied into dependencies'
)
t.has(normalized.dependencies, original.dependencies, 'regular depedencies stay in place')
t.same(normalized.devDependencies, original.devDependencies)
t.type(normalized.bugs, 'object', 'bugs should become object')
t.equal(normalized.bugs.url, 'https://github.com/isaacs/read-package-json/issues')
for (const key in original.optionalDependencies) {
assert.ok(key in normalized.dependencies, 'opt depedencies are copied into dependencies')
}
for (const key in original.dependencies) {
assert.ok(key in normalized.dependencies, 'regular depedencies stay in place')
}
assert.deepStrictEqual(normalized.devDependencies, original.devDependencies)
assert.strictEqual(typeof normalized.bugs, 'object', 'bugs should become object')
assert.strictEqual(normalized.bugs.url, 'https://github.com/isaacs/read-package-json/issues')
}
7 changes: 4 additions & 3 deletions test/consistency.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const t = require('tap')
const test = require('node:test')
const assert = require('node:assert')
const normalize = require('../lib/normalize')
const fs = require('fs')
const path = require('path')
const { promisify } = require('util')
const readFile = promisify(fs.readFile)
const readdir = promisify(fs.readdir)

t.test('consistent normalization', async t => {
test('consistent normalization', async () => {
const entries = await readdir(path.join(__dirname, 'fixtures'))
const verifyConsistency = async (entryName) => {
const warn = () => null
Expand All @@ -17,7 +18,7 @@ t.test('consistent normalization', async t => {
normalize(data, warn)
const clonedData = { ...data }
normalize(data, warn)
t.same(clonedData, data,
assert.deepStrictEqual(clonedData, data,
'Normalization of ' + entryName + ' is consistent.')
}

Expand Down
Loading
Loading