Skip to content

Commit

Permalink
fix(devkit): don't replace begining undescore when creating file (#9870)
Browse files Browse the repository at this point in the history
Underscore is a character usually used for sorting purposes and is absolutely legit. There is no
reason to replace it.

ISSUES CLOSED: #8875
  • Loading branch information
AloisH committed Apr 29, 2022
1 parent bef8240 commit 0bd08cc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/devkit/src/utils/names.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ describe('names', () => {
expect(names('[fooBar]').className).toEqual('FooBar');
expect(names('[...fooBar]').className).toEqual('FooBar');
expect(names('foo-@bar').className).toEqual('FooBar');
expect(names(' foo bar').className).toEqual('FooBar');
expect(names('_foo_bar').className).toEqual('FooBar');
});

it('should support property names', () => {
Expand All @@ -17,6 +19,8 @@ describe('names', () => {
expect(names('[fooBar]').propertyName).toEqual('fooBar');
expect(names('[...fooBar]').propertyName).toEqual('fooBar');
expect(names('foo-@bar').propertyName).toEqual('fooBar');
expect(names(' foo bar').propertyName).toEqual('fooBar');
expect(names('_foo_bar').propertyName).toEqual('fooBar');
});

it('should support file names', () => {
Expand All @@ -26,5 +30,7 @@ describe('names', () => {
expect(names('[fooBar]').fileName).toEqual('[foo-bar]');
expect(names('[...fooBar]').fileName).toEqual('[...foo-bar]');
expect(names('foo-@bar').fileName).toEqual('foo-@bar');
expect(names(' foo bar').fileName).toEqual('-foo-bar');
expect(names('_foo_bar').fileName).toEqual('_foo-bar');
});
});
2 changes: 1 addition & 1 deletion packages/devkit/src/utils/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function toFileName(s: string): string {
return s
.replace(/([a-z\d])([A-Z])/g, '$1_$2')
.toLowerCase()
.replace(/[ _]/g, '-');
.replace(/(?!^[_])[ _]/g, '-');
}

/**
Expand Down

1 comment on commit 0bd08cc

@vercel
Copy link

@vercel vercel bot commented on 0bd08cc Apr 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev

Please sign in to comment.