Skip to content

Commit

Permalink
Fix formatting and add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
krzkaczor committed Oct 6, 2023
1 parent 33ab0f0 commit 1f52e59
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-baboons-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'typechain': patch
---

Escape dirs starting with digits
2 changes: 1 addition & 1 deletion packages/typechain/src/codegen/createBarrelFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { posix } from 'path'

import { normalizeName } from '../parser/normalizeName'
import { FileDescription } from '../typechain/types'
import {normalizeDirName} from "./normalizeDirName";
import { normalizeDirName } from './normalizeDirName'

/**
* returns barrel files with reexports for all given paths
Expand Down
10 changes: 5 additions & 5 deletions packages/typechain/src/codegen/normalizeDirName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { camelCase } from 'lodash'
* Converts valid directory name to valid variable name. Example: 0directory-name becomes _0DirectoryName
*/
export function normalizeDirName(rawName: string): string {
const transformations: ((s: string) => string)[] = [
(s) => camelCase(s), // convert to camelCase
(s) => s.replace(/^\d/g, (match) => "_" + match), // prepend '_' if contains a leading number
]
const transformations: ((s: string) => string)[] = [
(s) => camelCase(s), // convert to camelCase
(s) => s.replace(/^\d/g, (match) => '_' + match), // prepend '_' if contains a leading number
]

return transformations.reduce((s, t) => t(s), rawName)
return transformations.reduce((s, t) => t(s), rawName)
}
18 changes: 9 additions & 9 deletions packages/typechain/test/codegen/normalizeDirName.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { expect } from 'earljs'

import {normalizeDirName} from "../../src/codegen/normalizeDirName";
import { normalizeDirName } from '../../src/codegen/normalizeDirName'

describe('dir name normalizer', () => {
it('should work', () => {
expect(normalizeDirName('dirname')).toEqual('dirname')
expect(normalizeDirName('dir_name')).toEqual('dirName')
expect(normalizeDirName('0.4.24')).toEqual('_0424')
expect(normalizeDirName('0-4-24')).toEqual('_0424')
expect(normalizeDirName('0424')).toEqual('_0424')
expect(normalizeDirName('0dir-name.1')).toEqual('_0DirName1')
})
it('should work', () => {
expect(normalizeDirName('dirname')).toEqual('dirname')
expect(normalizeDirName('dir_name')).toEqual('dirName')
expect(normalizeDirName('0.4.24')).toEqual('_0424')
expect(normalizeDirName('0-4-24')).toEqual('_0424')
expect(normalizeDirName('0424')).toEqual('_0424')
expect(normalizeDirName('0dir-name.1')).toEqual('_0DirName1')
})
})

0 comments on commit 1f52e59

Please sign in to comment.