Skip to content

Commit

Permalink
fix: validate package name and bin
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Mar 1, 2024
1 parent 2762d80 commit c0eb1b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"normalize-package-data": "^3.0.3",
"semver": "^7.6.0",
"sort-package-json": "^2.8.0",
"validate-npm-package-name": "^5.0.0",
"yeoman-environment": "^3.15.1",
"yeoman-generator": "^5.8.0"
},
Expand All @@ -43,6 +44,7 @@
"@types/node": "^18",
"@types/semver": "^7.5.7",
"@types/shelljs": "^0.8.11",
"@types/validate-npm-package-name": "^4.0.2",
"@types/yeoman-generator": "^5.2.11",
"chai": "^4.4.1",
"commitlint": "^17.7.2",
Expand Down
3 changes: 3 additions & 0 deletions src/generators/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Interfaces} from '@oclif/core'
import {execSync} from 'node:child_process'
import * as fs from 'node:fs'
import * as path from 'node:path'
import validatePkgName from 'validate-npm-package-name'
import Generator from 'yeoman-generator'

import {compact, isEmpty, uniq} from '../util'
Expand Down Expand Up @@ -159,12 +160,14 @@ export default class CLI extends Generator {
message: 'npm package name',
name: 'name',
type: 'input',
validate: (d: string) => validatePkgName(d).validForNewPackages || 'Invalid package name',
},
{
default: (answers: {name: string}) => answers.name,
message: 'command bin name the CLI will export',
name: 'bin',
type: 'input',
validate: (d: string) => /^[\w-]+$/.test(d) || 'Invalid bin name',
},
{
default: defaults.description,
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,11 @@
dependencies:
"@types/node" "*"

"@types/validate-npm-package-name@^4.0.2":
version "4.0.2"
resolved "https://registry.yarnpkg.com/@types/validate-npm-package-name/-/validate-npm-package-name-4.0.2.tgz#df0f7dac25df7761f7476605ddac54cb1abda26e"
integrity sha512-lrpDziQipxCEeK5kWxvljWYhUvOiB2A9izZd9B2AFarYAkqZshb4lPbRs7zKEic6eGtH8V/2qJW+dPp9OtF6bw==

"@types/vinyl@*", "@types/vinyl@^2.0.4":
version "2.0.11"
resolved "https://registry.yarnpkg.com/@types/vinyl/-/vinyl-2.0.11.tgz#b95a5bb007e7a0a61dad5a8971dc9922abbc2629"
Expand Down

0 comments on commit c0eb1b4

Please sign in to comment.