Skip to content

Commit 797a46b

Browse files
author
Roman Heckendorf
committed
TASK: fixed npmScopeArg rewriting, exclude all special characters. Only dash-cased name allowed
1 parent 34c541d commit 797a46b

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

packages/create-react-microservice/src/commands/default.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,9 @@ class CreateReactMicroService extends Command {
9999
.findNodeModules({cwd: __dirname})
100100
.map(modulesPath => path.join(__dirname, modulesPath))
101101
.find(modulesPath =>
102-
file.existsSync(
103-
path.join(modulesPath, scaffoldPackageName)
104-
)
102+
file.existsSync(path.join(modulesPath, scaffoldPackageName))
105103
);
106-
const scaffoldPackagePath = path.join(
107-
modulesPath,
108-
scaffoldPackageName
109-
);
104+
const scaffoldPackagePath = path.join(modulesPath, scaffoldPackageName);
110105
const scaffoldPackageJson = file.require(
111106
path.join(scaffoldPackageName, 'package.json')
112107
);
@@ -203,7 +198,7 @@ class CreateReactMicroService extends Command {
203198
const namespace = str
204199
.replace(/\s/g, '-')
205200
.replace(/[0-9]/g, '')
206-
.replace(/[^a-zA-Z]g/g, '')
201+
.replace(/[^a-zA-Z-]/g, '')
207202
.toLowerCase();
208203

209204
return `@${namespace}/`;
@@ -271,7 +266,7 @@ class CreateReactMicroService extends Command {
271266
const srcGitIgnore = path.join(cwd, '.git-ignore');
272267

273268
if (file.existsSync(srcGitIgnore)) {
274-
file.renameSync(srcGitIgnore, path.join(cwd, '.gitignore'))
269+
file.renameSync(srcGitIgnore, path.join(cwd, '.gitignore'));
275270
}
276271

277272
await Command.exec('git', ['init'], opts);

packages/create-react-microservice/src/commands/default.spec.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,47 @@ describe('new Command().safelyCreateNpmScopeArg()', () => {
462462
'@foo-bar-baz/'
463463
);
464464
});
465+
it('should remove all special characters', async () => {
466+
const specialChars = [
467+
'~',
468+
'!',
469+
'@',
470+
'#',
471+
'$',
472+
'%',
473+
'^',
474+
'&',
475+
'*',
476+
'(',
477+
')',
478+
'_',
479+
'|',
480+
'+',
481+
'=',
482+
'?',
483+
';',
484+
':',
485+
',',
486+
'.',
487+
'<',
488+
'>',
489+
'{',
490+
'}',
491+
'[',
492+
']',
493+
'\\',
494+
'/',
495+
"'",
496+
'"',
497+
'`',
498+
'´'
499+
];
500+
specialChars.forEach(character => {
501+
expect(instance.safelyCreateNpmScopeArg(`${character}foo-bar`)).toBe(
502+
'@foo-bar/'
503+
);
504+
});
505+
});
465506
});
466507

467508
describe('new Command().printStartInstructions()', () => {

0 commit comments

Comments
 (0)