Skip to content

Commit e8be58e

Browse files
committed
fix: unify relative path notation
1 parent 8e41184 commit e8be58e

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/buildServerFile.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ const ${isAsync ? 'asyncM' : 'm'}ethodToHandlerWithSchema = (
6363
`;
6464

6565
export default (input: string, project?: string) => {
66-
const { imports, consts, controllers } = createControllersText(`${input}/api`, project ?? input);
66+
const posixInput = input.replaceAll('\\', '/');
67+
const { imports, consts, controllers } = createControllersText(
68+
`${posixInput}/api`,
69+
project ?? posixInput,
70+
);
6771
const hasStringArrayTypeQuery = controllers.includes('parseStringArrayTypeQueryParams(');
6872
const hasNumberTypeQuery = controllers.includes('parseNumberTypeQueryParams(');
6973
const hasBooleanTypeQuery = controllers.includes('parseBooleanTypeQueryParams(');
@@ -429,6 +433,6 @@ ${controllers}
429433
return app;
430434
};
431435
`,
432-
filePath: path.posix.join(input, '$server.ts'),
436+
filePath: path.posix.join(posixInput, '$server.ts'),
433437
};
434438
};

src/createControllersText.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ export default (appDir: string, project: string) => {
209209
let paramsValidators = cascadingValidators;
210210

211211
const nameToPath = (fileType: string): PathItem => {
212-
const path = `${input}/${fileType}`.replace(appDir, './api');
213-
const hash = createHash(path);
212+
const val = `./${path.posix.join('api', dirPath, fileType)}`;
213+
const hash = createHash(val);
214214

215-
return { importName: `${fileType}Fn_${hash}`, name: `${fileType}_${hash}`, path };
215+
return { importName: `${fileType}Fn_${hash}`, name: `${fileType}_${hash}`, path: val };
216216
};
217217

218218
const validatorsFilePath = path.join(input, 'validators.ts');

tests/build.spec.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@ test('build', () => {
2222
.filter(d => d.isDirectory())
2323
.map(d => `${inputDir}/${d.name}`)
2424
.forEach(input => {
25-
const result = build(input);
26-
expect(result.text).toBe(
25+
const result1 = build(input);
26+
const result2 = build(`./${input}`);
27+
const result3 = build(input.replace('/', '\\'));
28+
const result4 = build(`.\\${input.replace('/', '\\')}`);
29+
30+
expect(result1).toEqual(result2);
31+
expect(result2).toEqual(result3);
32+
expect(result3).toEqual(result4);
33+
34+
expect(result1.text).toBe(
2735
fs
28-
.readFileSync(result.filePath, 'utf8')
36+
.readFileSync(result1.filePath, 'utf8')
2937
.replace(/\r/g, '')
3038
.replace(/\n +\/\/ @ts-expect-error/g, ''),
3139
);

0 commit comments

Comments
 (0)