1
0
mirror of synced 2025-11-08 21:07:23 +00:00

fix(CLI): allow scoped npm package names

switch to npm's validate-npm-package-name internally

Fixes #68
This commit is contained in:
Jason Dreyzehner
2018-03-13 20:40:37 -04:00
parent 0bb76c24e6
commit 83fdc67c50
5 changed files with 26 additions and 4 deletions

View File

@@ -13,7 +13,7 @@ import {
install,
Placeholders
} from '../tasks';
import { getIntro, Runner } from '../utils';
import { getIntro, Runner, validateName } from '../utils';
test('errors if outdated', async t => {
nock.disableNetConnect();
@@ -101,6 +101,12 @@ test('checkArgs always returns { install } (so --no-install works in interactive
t.deepEqual(opts, { install: true });
});
test('only accepts valid package names', async t => {
t.true(validateName('package-name'));
t.true(validateName('package-name-2'));
t.true(validateName('@example/package-name-2'));
});
test('ascii art shows if stdout has 85+ columns', async t => {
const jumbo = getIntro(100);
const snippet = `| __| | | | '_ \\ / _ \\/ __|/ __| '__| | '_ \\|`;

View File

@@ -1,6 +1,7 @@
import chalk from 'chalk';
import { existsSync } from 'fs';
import gradient from 'gradient-string';
import validateNpmPackageName from 'validate-npm-package-name';
export enum Runner {
Npm = 'npm',
Yarn = 'yarn'
@@ -31,8 +32,8 @@ export interface TypescriptStarterOptions
TypescriptStarterInferredOptions {}
export function validateName(input: string): true | string {
return !/^\s*[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*\s*$/.test(input)
? 'Name should be in-kebab-case'
return !validateNpmPackageName(input).validForNewPackages
? 'Name should be in-kebab-case (for npm)'
: existsSync(input)
? `The "${input}" path already exists in this directory.`
: true;