Skip to content

Commit 9ad72b8

Browse files
committed
fix(funcnamefromrelpath): handle windows path separator correctly
This was a bug on windows resulting from the fact that windows uses a backslash as a path separator whereas most other systems use forwardslash. fix #4
1 parent b359b68 commit 9ad72b8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/export-functions.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
import camelCase from 'camelcase';
33
import glob from 'glob';
44
import set from 'lodash.set';
5-
import { resolve } from 'path';
5+
import { resolve, sep } from 'path';
66

77
function getDirnameFromFilename(__filename: string) {
8-
return __filename.split('/').slice(0, -1).join('/');
8+
return __filename.split(sep).slice(0, -1).join(sep);
99
}
1010

1111
export function funcNameFromRelPathDefault(relPath: string): string {
12-
const relPathArray = relPath.split('/'); /* ? */
12+
const relPathArray = relPath.split(sep); /* ? */
1313
const fileName = relPathArray.pop(); /* ? */
14-
const relDirPathFunctionNameChunk = relPathArray.map((pathFragment) => camelCase(pathFragment)).join('/');
14+
const relDirPathFunctionNameChunk = relPathArray.map((pathFragment) => camelCase(pathFragment)).join(sep);
1515
const fileNameFunctionNameChunk = camelCase(fileName!.split('.')[0]);
1616
const funcName = relDirPathFunctionNameChunk
17-
? `${relDirPathFunctionNameChunk}/${fileNameFunctionNameChunk}`
17+
? `${relDirPathFunctionNameChunk}${sep}${fileNameFunctionNameChunk}`
1818
: fileNameFunctionNameChunk;
19-
return funcName.replace(/\//g, '-');
19+
return funcName.replace(sep, '-');
2020
}
2121

2222
/**

0 commit comments

Comments
 (0)