Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show type on invalid semver error #559

Merged
merged 8 commits into from May 12, 2023
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -33,3 +33,4 @@
!/SECURITY.md
!/tap-snapshots/
!/test/
!/rollup.config.js
tjenkinson marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion classes/semver.js
Expand Up @@ -16,7 +16,7 @@ class SemVer {
version = version.version
}
} else if (typeof version !== 'string') {
throw new TypeError(`Invalid Version: ${require('util').inspect(version)}`)
throw new TypeError(`Invalid Version: ${version}`)
tjenkinson marked this conversation as resolved.
Show resolved Hide resolved
}

if (version.length > MAX_LENGTH) {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -4,8 +4,9 @@
"description": "The semantic version parser used by npm.",
"main": "index.js",
"scripts": {
"test": "tap",
"test": "tap && npm run check-self-contained",
"snap": "tap",
"check-self-contained": "rollup -c --silent > /dev/null",
"lint": "eslint \"**/*.js\"",
"postlint": "template-oss-check",
"lintfix": "npm run lint -- --fix",
Expand All @@ -15,6 +16,8 @@
"devDependencies": {
"@npmcli/eslint-config": "^4.0.0",
"@npmcli/template-oss": "4.14.1",
"@rollup/plugin-commonjs": "^24.1.0",
"rollup": "^3.21.5",
"tap": "^16.0.0"
},
"license": "ISC",
Expand Down
22 changes: 22 additions & 0 deletions rollup.config.js
@@ -0,0 +1,22 @@
const fs = require('fs')
const commonjs = require('@rollup/plugin-commonjs')

const pkgJson = JSON.parse(fs.readFileSync('./package.json', 'utf-8'))

module.exports = {
input: pkgJson.main,
plugins: [
commonjs({
strictRequires: true,
ignoreTryCatch: true,
}),
],
external: Object.keys(pkgJson.dependencies),
onwarn: (e) => {
if (e.code === 'CIRCULAR_DEPENDENCY') {
return
}

throw new Error(e)
},
}
2 changes: 1 addition & 1 deletion test/functions/parse.js
Expand Up @@ -20,7 +20,7 @@ t.test('throw errors if asked to', t => {
parse([], null, true)
}, {
name: 'TypeError',
message: 'Invalid Version: []',
message: 'Invalid Version: ',
})
t.end()
})
Expand Down
1 change: 1 addition & 0 deletions test/map.js
Expand Up @@ -11,6 +11,7 @@ const ignore = [
'tap-snapshots',
'test',
'fixtures',
'rollup.config.js',
]

const { statSync, readdirSync } = require('fs')
Expand Down