Skip to content

Commit 5e8195c

Browse files
LubosLubos
authored andcommitted
refactor: rename compiler export to tsc
1 parent 4389c5d commit 5e8195c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1593
-1603
lines changed

docs/openapi-ts/community/contributing/building.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ Your [pull request](https://help.github.com/articles/using-pull-requests) must:
2121
- contain a clean history of small, incremental, logically separate commits, with no merge commits
2222
- use clear commit messages
2323
- be possible to merge automatically
24+
25+
## Start `@hey-api/openapi-ts`
26+
27+
Run `pnpm --filter @hey-api/openapi-ts dev`.

packages/openapi-ts/src/generate/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { fileURLToPath } from 'node:url';
44

55
import ts from 'typescript';
66

7-
import type { ImportExportItemObject } from '../compiler/utils';
87
import type { Client } from '../plugins/@hey-api/client-core/types';
98
import { getClientPlugin } from '../plugins/@hey-api/client-core/utils';
109
import type { DefinePlugin } from '../plugins/types';
10+
import type { ImportExportItemObject } from '../tsc/utils';
1111
import type { Config } from '../types/config';
1212
import { ensureDirSync, relativeModulePath } from './utils';
1313

packages/openapi-ts/src/generate/file/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@ import path from 'node:path';
33

44
import ts from 'typescript';
55

6-
import { compiler } from '../../compiler';
7-
import {
8-
type ImportExportItemObject,
9-
tsNodeToString,
10-
} from '../../compiler/utils';
116
import type { IR } from '../../ir/types';
127
import { getUniqueComponentName } from '../../openApi/shared/transforms/utils';
138
import { ensureValidIdentifier } from '../../openApi/shared/utils/identifier';
9+
import { tsc } from '../../tsc';
10+
import { type ImportExportItemObject, tsNodeToString } from '../../tsc/utils';
1411
import type { StringCase } from '../../types/case';
1512
import { stringCase } from '../../utils/stringCase';
1613
import { ensureDirSync } from '../utils';
@@ -199,7 +196,7 @@ export class GeneratedFile {
199196
public getNode(id: string): NodeInfo {
200197
if (!this.nodes[id]) {
201198
this.nodes[id] = {
202-
node: compiler.typeReferenceNode({ typeName: '' }),
199+
node: tsc.typeReferenceNode({ typeName: '' }),
203200
};
204201
}
205202
return this.nodes[id]!;
@@ -382,7 +379,7 @@ export class GeneratedFile {
382379
}
383380
}
384381

385-
const node = compiler.namedImportDeclarations({
382+
const node = tsc.namedImportDeclarations({
386383
imports,
387384
module: resolvedModule,
388385
});
@@ -421,7 +418,7 @@ export class GeneratedFile {
421418
components: Object.values(this.names),
422419
});
423420
this.names[id] = name;
424-
const node = compiler.typeReferenceNode({ typeName: name });
421+
const node = tsc.typeReferenceNode({ typeName: name });
425422
// update node
426423
if (!this.nodes[id]) {
427424
this.nodes[id] = { node };

packages/openapi-ts/src/generate/legacy/indexFile.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { compiler } from '../../compiler';
21
import { getClientPlugin } from '../../plugins/@hey-api/client-core/utils';
2+
import { tsc } from '../../tsc';
33
import type { Files } from '../../types/utils';
44
import { getConfig, legacyNameFromConfig } from '../../utils/config';
55
import { GeneratedFile } from '../file';
@@ -15,7 +15,7 @@ export const generateIndexFile = ({ files }: { files: Files }): void => {
1515

1616
if (legacyNameFromConfig(config)) {
1717
files.index.add(
18-
compiler.exportNamedDeclaration({
18+
tsc.exportNamedDeclaration({
1919
exports: legacyNameFromConfig(config)!,
2020
module: `./${legacyNameFromConfig(config)}`,
2121
}),
@@ -24,22 +24,22 @@ export const generateIndexFile = ({ files }: { files: Files }): void => {
2424

2525
if (config.exportCore) {
2626
files.index.add(
27-
compiler.exportNamedDeclaration({
27+
tsc.exportNamedDeclaration({
2828
exports: 'ApiError',
2929
module: './core/ApiError',
3030
}),
3131
);
3232
if (config.plugins['@hey-api/sdk']?.config.response === 'response') {
3333
files.index.add(
34-
compiler.exportNamedDeclaration({
34+
tsc.exportNamedDeclaration({
3535
exports: { asType: true, name: 'ApiResult' },
3636
module: './core/ApiResult',
3737
}),
3838
);
3939
}
4040
if (legacyNameFromConfig(config)) {
4141
files.index.add(
42-
compiler.exportNamedDeclaration({
42+
tsc.exportNamedDeclaration({
4343
exports: 'BaseHttpRequest',
4444
module: './core/BaseHttpRequest',
4545
}),
@@ -48,14 +48,14 @@ export const generateIndexFile = ({ files }: { files: Files }): void => {
4848
const clientPlugin = getClientPlugin(config);
4949
if (clientPlugin.name !== 'legacy/angular') {
5050
files.index.add(
51-
compiler.exportNamedDeclaration({
51+
tsc.exportNamedDeclaration({
5252
exports: ['CancelablePromise', 'CancelError'],
5353
module: './core/CancelablePromise',
5454
}),
5555
);
5656
}
5757
files.index.add(
58-
compiler.exportNamedDeclaration({
58+
tsc.exportNamedDeclaration({
5959
exports: ['OpenAPI', { asType: true, name: 'OpenAPIConfig' }],
6060
module: './core/OpenAPI',
6161
}),
@@ -73,7 +73,7 @@ export const generateIndexFile = ({ files }: { files: Files }): void => {
7373

7474
if (file.exportFromIndex) {
7575
files.index!.add(
76-
compiler.exportAllDeclaration({
76+
tsc.exportAllDeclaration({
7777
module: `./${file.nameWithoutExtension()}`,
7878
}),
7979
);

packages/openapi-ts/src/generate/output.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import path from 'node:path';
22

33
import ts from 'typescript';
44

5-
import { compiler } from '../compiler';
65
import type { IR } from '../ir/types';
76
import { getClientPlugin } from '../plugins/@hey-api/client-core/utils';
7+
import { tsc } from '../tsc';
88
import { generateClientBundle } from './client';
99
import { findTsConfigPath, loadTsConfig } from './tsConfig';
1010
import { removeDirSync } from './utils';
@@ -70,9 +70,7 @@ export const generateOutput = async ({ context }: { context: IR.Context }) => {
7070
}
7171
// TODO: parser - add export method for more granular control over
7272
// what's exported so we can support named exports
73-
indexFile.add(
74-
compiler.exportAllDeclaration({ module: resolvedModule }),
75-
);
73+
indexFile.add(tsc.exportAllDeclaration({ module: resolvedModule }));
7674
}
7775

7876
file.write('\n\n', tsConfig);

packages/openapi-ts/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ export const createClient = async (
118118
export const defineConfig = async (config: Configs): Promise<UserConfig> =>
119119
typeof config === 'function' ? await config() : config;
120120

121-
export { compiler } from './compiler';
122121
export { defaultPaginationKeywords } from './config/parser';
123122
export { defaultPlugins } from './config/plugins';
124123
export type { IR } from './ir/types';
@@ -140,6 +139,7 @@ export type { Client } from './plugins/@hey-api/client-core/types';
140139
export type { ExpressionTransformer } from './plugins/@hey-api/transformers/expressions';
141140
export { definePluginConfig } from './plugins/shared/utils/config';
142141
export type { DefinePlugin, Plugin } from './plugins/types';
142+
export { compiler, tsc } from './tsc';
143143
export type { UserConfig } from './types/config';
144144
export type { LegacyIR } from './types/types';
145145
export { utils } from './utils/exports';

packages/openapi-ts/src/plugins/@hey-api/client-core/client.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { compiler } from '../../../compiler';
21
import { clientModulePath } from '../../../generate/client';
2+
import { tsc } from '../../../tsc';
33
import { parseUrl } from '../../../utils/url';
44
import { typesId } from '../typescript/ref';
55
import type { PluginHandler } from './types';
@@ -93,24 +93,24 @@ export const createClient = ({ plugin }: Parameters<PluginHandler>[0]) => {
9393
}
9494

9595
const createConfigParameters = [
96-
compiler.callExpression({
96+
tsc.callExpression({
9797
functionName: createConfig.name,
9898
parameters: defaultValues.length
99-
? [compiler.objectExpression({ obj: defaultValues })]
99+
? [tsc.objectExpression({ obj: defaultValues })]
100100
: undefined,
101101
types: clientOptions.name
102-
? [compiler.typeReferenceNode({ typeName: clientOptions.name })]
102+
? [tsc.typeReferenceNode({ typeName: clientOptions.name })]
103103
: undefined,
104104
}),
105105
];
106106

107-
const statement = compiler.constVariable({
107+
const statement = tsc.constVariable({
108108
exportConst: true,
109-
expression: compiler.callExpression({
109+
expression: tsc.callExpression({
110110
functionName: createClient.name,
111111
parameters: createClientConfig
112112
? [
113-
compiler.callExpression({
113+
tsc.callExpression({
114114
functionName: createClientConfig.name,
115115
parameters: createConfigParameters,
116116
}),

packages/openapi-ts/src/plugins/@hey-api/client-core/createClientConfig.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { compiler } from '../../../compiler';
21
import { clientModulePath } from '../../../generate/client';
2+
import { tsc } from '../../../tsc';
33
import { clientId } from '../client-core/utils';
44
import { typesId } from '../typescript/ref';
55
import type { PluginHandler } from './types';
@@ -34,12 +34,12 @@ export const createClientConfigType = ({
3434
name: 'ClientOptions',
3535
});
3636

37-
const defaultClientOptionsType = compiler.typeReferenceNode({
37+
const defaultClientOptionsType = tsc.typeReferenceNode({
3838
typeName: defaultClientOptions.name,
3939
});
40-
const tType = compiler.typeReferenceNode({ typeName: 'T' });
40+
const tType = tsc.typeReferenceNode({ typeName: 'T' });
4141

42-
const typeCreateClientConfig = compiler.typeAliasDeclaration({
42+
const typeCreateClientConfig = tsc.typeAliasDeclaration({
4343
comment: [
4444
'The `createClientConfig()` function will be called on client initialization',
4545
"and the returned object will become the client's initial configuration.",
@@ -50,26 +50,26 @@ export const createClientConfigType = ({
5050
],
5151
exportType: true,
5252
name: 'CreateClientConfig',
53-
type: compiler.functionTypeNode({
53+
type: tsc.functionTypeNode({
5454
parameters: [
55-
compiler.parameterDeclaration({
55+
tsc.parameterDeclaration({
5656
name: 'override',
5757
required: false,
58-
type: compiler.typeReferenceNode({
58+
type: tsc.typeReferenceNode({
5959
typeArguments: [
60-
compiler.typeIntersectionNode({
60+
tsc.typeIntersectionNode({
6161
types: [defaultClientOptionsType, tType],
6262
}),
6363
],
6464
typeName: configType.name,
6565
}),
6666
}),
6767
],
68-
returnType: compiler.typeReferenceNode({
68+
returnType: tsc.typeReferenceNode({
6969
typeArguments: [
70-
compiler.typeIntersectionNode({
70+
tsc.typeIntersectionNode({
7171
types: [
72-
compiler.typeReferenceNode({
72+
tsc.typeReferenceNode({
7373
typeArguments: [defaultClientOptionsType],
7474
typeName: 'Required',
7575
}),
@@ -83,7 +83,7 @@ export const createClientConfigType = ({
8383
typeParameters: [
8484
{
8585
default: clientOptions.name
86-
? compiler.typeReferenceNode({ typeName: clientOptions.name })
86+
? tsc.typeReferenceNode({ typeName: clientOptions.name })
8787
: undefined,
8888
extends: defaultClientOptionsType,
8989
name: 'T',

packages/openapi-ts/src/plugins/@hey-api/schemas/plugin-legacy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { compiler } from '../../../compiler';
21
import { GeneratedFile } from '../../../generate/file';
32
import type { OpenApiV2Schema, OpenApiV3Schema } from '../../../openApi';
43
import { ensureValidTypeScriptJavaScriptIdentifier } from '../../../openApi';
4+
import { tsc } from '../../../tsc';
55
import { getConfig } from '../../../utils/config';
66
import type { HeyApiSchemasPlugin } from './types';
77

@@ -93,8 +93,8 @@ export const handlerLegacy: HeyApiSchemasPlugin['LegacyHandler'] = ({
9393
schema: OpenApiV2Schema | OpenApiV3Schema,
9494
) => {
9595
const obj = ensureValidSchemaOutput(schema);
96-
const expression = compiler.objectExpression({ obj });
97-
const statement = compiler.constVariable({
96+
const expression = tsc.objectExpression({ obj });
97+
const statement = tsc.constVariable({
9898
assertion: 'const',
9999
exportConst: true,
100100
expression,

packages/openapi-ts/src/plugins/@hey-api/schemas/plugin.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { compiler } from '../../../compiler';
21
import type { IR } from '../../../ir/types';
32
import type { OpenApiV2_0_XTypes } from '../../../openApi/2.0.x';
43
import type { OpenApiV3_0_XTypes } from '../../../openApi/3.0.x';
54
import type { OpenApiV3_1_XTypes } from '../../../openApi/3.1.x';
65
import { ensureValidIdentifier } from '../../../openApi/shared/utils/identifier';
76
import type { OpenApi } from '../../../openApi/types';
7+
import { tsc } from '../../../tsc';
88
import type { HeyApiSchemasPlugin } from './types';
99

1010
const schemasId = 'schemas';
@@ -373,10 +373,10 @@ const schemasV2_0_X = ({
373373
plugin,
374374
schema,
375375
});
376-
const statement = compiler.constVariable({
376+
const statement = tsc.constVariable({
377377
assertion: 'const',
378378
exportConst: true,
379-
expression: compiler.objectExpression({ obj }),
379+
expression: tsc.objectExpression({ obj }),
380380
name: schemaName({ name, plugin, schema }),
381381
});
382382
context.file({ id: schemasId })!.add(statement);
@@ -401,10 +401,10 @@ const schemasV3_0_X = ({
401401
plugin,
402402
schema,
403403
});
404-
const statement = compiler.constVariable({
404+
const statement = tsc.constVariable({
405405
assertion: 'const',
406406
exportConst: true,
407-
expression: compiler.objectExpression({ obj }),
407+
expression: tsc.objectExpression({ obj }),
408408
name: schemaName({ name, plugin, schema }),
409409
});
410410
context.file({ id: schemasId })!.add(statement);
@@ -429,10 +429,10 @@ const schemasV3_1_X = ({
429429
plugin,
430430
schema,
431431
});
432-
const statement = compiler.constVariable({
432+
const statement = tsc.constVariable({
433433
assertion: 'const',
434434
exportConst: true,
435-
expression: compiler.objectExpression({ obj }),
435+
expression: tsc.objectExpression({ obj }),
436436
name: schemaName({ name, plugin, schema }),
437437
});
438438
context.file({ id: schemasId })!.add(statement);

0 commit comments

Comments
 (0)