fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #353 from hey-api/fix/cwd-output

fix: output path no longer required to be within cwd

authored by

Lubos and committed by
GitHub
97f28e07 05dd1d32

+5 -32
+5
.changeset/three-keys-confess.md
··· 1 + --- 2 + "@hey-api/openapi-ts": patch 3 + --- 4 + 5 + fix: output path no longer required to be within cwd
-5
packages/openapi-ts/src/index.ts
··· 10 10 import { getConfig, setConfig } from './utils/config'; 11 11 import { getOpenApiSpec } from './utils/getOpenApiSpec'; 12 12 import { registerHandlebarTemplates } from './utils/handlebars'; 13 - import { isSubDirectory } from './utils/isSubdirectory'; 14 13 import { postProcessClient } from './utils/postprocess'; 15 14 import { writeClient } from './utils/write/client'; 16 15 ··· 124 123 125 124 if (!userConfig.output) { 126 125 throw new Error('🚫 output not provided - provide path where we should generate your client'); 127 - } 128 - 129 - if (!isSubDirectory(process.cwd(), userConfig.output)) { 130 - throw new Error('🚫 output must be within the current working directory'); 131 126 } 132 127 133 128 if (postfixServices && postfixServices !== 'Service') {
-21
packages/openapi-ts/src/utils/__tests__/isSubdirectory.spec.ts
··· 1 - import path from 'node:path'; 2 - 3 - import { describe, expect, it } from 'vitest'; 4 - 5 - import { isSubDirectory } from '../isSubdirectory'; 6 - 7 - describe('isSubDirectory', () => { 8 - it.each([ 9 - ['/', '/', false], 10 - ['.', '.', false], 11 - ['./project', './project', false], 12 - ['./project', '../', false], 13 - ['./project', '../../', false], 14 - ['./', './output', true], 15 - ['./', '../output', false], 16 - ['./', '../../../../../output', false], 17 - ])('isSubDirectory(%s, %s) -> %s', (a, b, expected) => { 18 - const result = isSubDirectory(path.resolve(a), path.resolve(b)); 19 - expect(result).toBe(expected); 20 - }); 21 - });
-6
packages/openapi-ts/src/utils/isSubdirectory.ts
··· 1 - import path from 'node:path'; 2 - 3 - export const isSubDirectory = (parent: string, child: string) => { 4 - const relative = path.relative(parent, child); 5 - return Boolean(relative) && !relative.startsWith('..') && !path.isAbsolute(relative); 6 - };