fix(CLI): allow scoped npm package names
switch to npm's validate-npm-package-name internally Fixes #68
This commit is contained in:
@@ -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 = `| __| | | | '_ \\ / _ \\/ __|/ __| '__| | '_ \\|`;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user