From 1f52e5907885433dcd484a2b43b28ea8b82633d5 Mon Sep 17 00:00:00 2001 From: Krzysztof Kaczor Date: Fri, 6 Oct 2023 16:38:32 +0200 Subject: [PATCH] Fix formatting and add changeset --- .changeset/cold-baboons-pull.md | 5 +++++ .../typechain/src/codegen/createBarrelFiles.ts | 2 +- .../typechain/src/codegen/normalizeDirName.ts | 10 +++++----- .../test/codegen/normalizeDirName.test.ts | 18 +++++++++--------- 4 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 .changeset/cold-baboons-pull.md diff --git a/.changeset/cold-baboons-pull.md b/.changeset/cold-baboons-pull.md new file mode 100644 index 000000000..107bcc310 --- /dev/null +++ b/.changeset/cold-baboons-pull.md @@ -0,0 +1,5 @@ +--- +'typechain': patch +--- + +Escape dirs starting with digits diff --git a/packages/typechain/src/codegen/createBarrelFiles.ts b/packages/typechain/src/codegen/createBarrelFiles.ts index 02eb5d73a..f1e764db6 100644 --- a/packages/typechain/src/codegen/createBarrelFiles.ts +++ b/packages/typechain/src/codegen/createBarrelFiles.ts @@ -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 diff --git a/packages/typechain/src/codegen/normalizeDirName.ts b/packages/typechain/src/codegen/normalizeDirName.ts index e61fdb7e7..d83e03963 100644 --- a/packages/typechain/src/codegen/normalizeDirName.ts +++ b/packages/typechain/src/codegen/normalizeDirName.ts @@ -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) } diff --git a/packages/typechain/test/codegen/normalizeDirName.test.ts b/packages/typechain/test/codegen/normalizeDirName.test.ts index 713b5f856..033895065 100644 --- a/packages/typechain/test/codegen/normalizeDirName.test.ts +++ b/packages/typechain/test/codegen/normalizeDirName.test.ts @@ -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') + }) })