@hey-api/openapi-ts 0.94.2 → 0.94.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -149,6 +149,7 @@ function getOutput(userConfig) {
149
149
  },
150
150
  format: null,
151
151
  lint: null,
152
+ module: {},
152
153
  path: "",
153
154
  postProcess: [],
154
155
  preferExportAll: false
@@ -162,13 +163,25 @@ function getOutput(userConfig) {
162
163
  string: (name) => ({ name })
163
164
  },
164
165
  value: fields.fileName
166
+ }),
167
+ module: valueToObject({
168
+ defaultValue: {
169
+ extension: fields.importFileExtension,
170
+ resolve: fields.resolveModuleName
171
+ },
172
+ mappers: { object: (moduleFields) => ({
173
+ ...moduleFields,
174
+ extension: fields.importFileExtension ?? moduleFields.extension,
175
+ resolve: fields.resolveModuleName ?? moduleFields.resolve
176
+ }) },
177
+ value: fields.module
165
178
  })
166
179
  }) },
167
180
  value: userOutput
168
181
  });
169
182
  output.tsConfig = loadTsConfig(findTsConfigPath(__dirname$1, output.tsConfigPath));
170
- if (output.importFileExtension === void 0 && (output.tsConfig?.compilerOptions?.moduleResolution === "nodenext" || output.tsConfig?.compilerOptions?.moduleResolution === "NodeNext" || output.tsConfig?.compilerOptions?.moduleResolution === "node16" || output.tsConfig?.compilerOptions?.moduleResolution === "Node16" || output.tsConfig?.compilerOptions?.module === "nodenext" || output.tsConfig?.compilerOptions?.module === "NodeNext" || output.tsConfig?.compilerOptions?.module === "node16" || output.tsConfig?.compilerOptions?.module === "Node16")) output.importFileExtension = ".js";
171
- if (output.importFileExtension && !output.importFileExtension.startsWith(".")) output.importFileExtension = `.${output.importFileExtension}`;
183
+ if (output.module.extension === void 0 && (output.tsConfig?.compilerOptions?.moduleResolution === "nodenext" || output.tsConfig?.compilerOptions?.moduleResolution === "NodeNext" || output.tsConfig?.compilerOptions?.moduleResolution === "node16" || output.tsConfig?.compilerOptions?.moduleResolution === "Node16" || output.tsConfig?.compilerOptions?.module === "nodenext" || output.tsConfig?.compilerOptions?.module === "NodeNext" || output.tsConfig?.compilerOptions?.module === "node16" || output.tsConfig?.compilerOptions?.module === "Node16")) output.module.extension = ".js";
184
+ if (output.module.extension && !output.module.extension.startsWith(".")) output.module.extension = `.${output.module.extension}`;
172
185
  output.postProcess = normalizePostProcess(userOutput.postProcess ?? legacyPostProcess);
173
186
  output.source = resolveSource(output);
174
187
  return output;
@@ -4088,28 +4101,21 @@ var TypeScriptRenderer = class TypeScriptRenderer {
4088
4101
  */
4089
4102
  _header;
4090
4103
  /**
4091
- * Whether `export * from 'module'` should be used when possible instead of named exports.
4092
- *
4093
- * @private
4094
- */
4095
- _preferExportAll;
4096
- /**
4097
- * Controls whether imports/exports include a file extension (e.g., '.ts' or '.js').
4104
+ * Options for module specifier resolution.
4098
4105
  *
4099
4106
  * @private
4100
4107
  */
4101
- _preferFileExtension;
4108
+ _module;
4102
4109
  /**
4103
- * Optional function to transform module specifiers.
4110
+ * Whether `export * from 'module'` should be used when possible instead of named exports.
4104
4111
  *
4105
4112
  * @private
4106
4113
  */
4107
- _resolveModuleName;
4114
+ _preferExportAll;
4108
4115
  constructor(args = {}) {
4109
4116
  this._header = args.header;
4117
+ this._module = args.module;
4110
4118
  this._preferExportAll = args.preferExportAll ?? false;
4111
- this._preferFileExtension = args.preferFileExtension ?? "";
4112
- this._resolveModuleName = args.resolveModuleName;
4113
4119
  }
4114
4120
  render(ctx) {
4115
4121
  const header = typeof this._header === "function" ? this._header(ctx) : this._header;
@@ -4168,10 +4174,10 @@ var TypeScriptRenderer = class TypeScriptRenderer {
4168
4174
  const sortKey = moduleSortKey({
4169
4175
  file: ctx.file,
4170
4176
  fromFile: exp.from,
4171
- preferFileExtension: this._preferFileExtension,
4177
+ preferFileExtension: this._module?.extension || "",
4172
4178
  root: ctx.project.root
4173
4179
  });
4174
- const modulePath = this._resolveModuleName?.(sortKey[2]) ?? sortKey[2];
4180
+ const modulePath = this._module?.resolve?.(sortKey[2], ctx) ?? sortKey[2];
4175
4181
  const [groupIndex] = sortKey;
4176
4182
  if (!groups.has(groupIndex)) groups.set(groupIndex, /* @__PURE__ */ new Map());
4177
4183
  const moduleMap = groups.get(groupIndex);
@@ -4212,10 +4218,10 @@ var TypeScriptRenderer = class TypeScriptRenderer {
4212
4218
  const sortKey = moduleSortKey({
4213
4219
  file: ctx.file,
4214
4220
  fromFile: imp.from,
4215
- preferFileExtension: this._preferFileExtension,
4221
+ preferFileExtension: this._module?.extension || "",
4216
4222
  root: ctx.project.root
4217
4223
  });
4218
- const modulePath = this._resolveModuleName?.(sortKey[2]) ?? sortKey[2];
4224
+ const modulePath = this._module?.resolve?.(sortKey[2], ctx) ?? sortKey[2];
4219
4225
  const [groupIndex] = sortKey;
4220
4226
  if (!groups.has(groupIndex)) groups.set(groupIndex, /* @__PURE__ */ new Map());
4221
4227
  const moduleMap = groups.get(groupIndex);
@@ -5419,7 +5425,7 @@ function renameFile({ filePath, project, renamed }) {
5419
5425
  renamed.set(name, renamedName);
5420
5426
  }
5421
5427
  }
5422
- function replaceImports({ filePath, header, meta, renamed }) {
5428
+ function replaceImports({ filePath, header, module, renamed }) {
5423
5429
  let content = fs.readFileSync(filePath, "utf8");
5424
5430
  if (isEnvironment("development")) {
5425
5431
  content = content.replace(/from\s+['"]\.\.\/\.\.\/client-core\/bundle\//g, "from '../core/");
@@ -5430,7 +5436,7 @@ function replaceImports({ filePath, header, meta, renamed }) {
5430
5436
  const extension = path.extname(importPath);
5431
5437
  const fileName = path.basename(importPath, extension);
5432
5438
  const importDir = path.dirname(importPath);
5433
- const replacedName = (renamed.get(fileName) ?? fileName) + (meta.importFileExtension ? meta.importFileExtension : extension);
5439
+ const replacedName = (renamed.get(fileName) ?? fileName) + (module.extension ? module.extension : extension);
5434
5440
  return match.slice(0, importIndex) + [importDir, replacedName].filter(Boolean).join("/") + match.slice(importIndex + importPath.length);
5435
5441
  });
5436
5442
  content = `${header ?? ""}${content}`;
@@ -5439,7 +5445,7 @@ function replaceImports({ filePath, header, meta, renamed }) {
5439
5445
  /**
5440
5446
  * Creates a `client` folder containing the same modules as the client package.
5441
5447
  */
5442
- function generateClientBundle({ header, meta, outputPath, plugin, project }) {
5448
+ function generateClientBundle({ header, module, outputPath, plugin, project }) {
5443
5449
  const renamed = /* @__PURE__ */ new Map();
5444
5450
  const headerPrefix = outputHeaderToPrefix({
5445
5451
  defaultValue: ["// This file is auto-generated by @hey-api/openapi-ts"],
@@ -5472,14 +5478,14 @@ function generateClientBundle({ header, meta, outputPath, plugin, project }) {
5472
5478
  for (const file of coreFiles) replaceImports({
5473
5479
  filePath: path.resolve(coreOutputPath, file),
5474
5480
  header: headerPrefix,
5475
- meta,
5481
+ module,
5476
5482
  renamed
5477
5483
  });
5478
5484
  const clientFiles = fs.readdirSync(clientOutputPath);
5479
5485
  for (const file of clientFiles) replaceImports({
5480
5486
  filePath: path.resolve(clientOutputPath, file),
5481
5487
  header: headerPrefix,
5482
- meta,
5488
+ module,
5483
5489
  renamed
5484
5490
  });
5485
5491
  return renamed;
@@ -6332,8 +6338,10 @@ const dateExpressions = ({ dataExpression, schema }) => {
6332
6338
  //#region src/plugins/@hey-api/transformers/plugin.ts
6333
6339
  const dataVariableName = "data";
6334
6340
  const buildingSymbols = /* @__PURE__ */ new Set();
6335
- const isNodeReturnStatement = (node) => node["~dsl"] === "ReturnTsDsl";
6336
- const schemaResponseTransformerNodes = ({ plugin, schema }) => {
6341
+ function isNodeReturnStatement(node) {
6342
+ return node["~dsl"] === "ReturnTsDsl";
6343
+ }
6344
+ function schemaResponseTransformerNodes({ plugin, schema }) {
6337
6345
  const nodes = processSchemaType({
6338
6346
  dataExpression: $(dataVariableName),
6339
6347
  plugin,
@@ -6344,8 +6352,8 @@ const schemaResponseTransformerNodes = ({ plugin, schema }) => {
6344
6352
  if (!isNodeReturnStatement(last)) nodes.push($.return(dataVariableName));
6345
6353
  }
6346
6354
  return nodes;
6347
- };
6348
- const processSchemaType = ({ dataExpression, plugin, schema }) => {
6355
+ }
6356
+ function processSchemaType({ dataExpression, plugin, schema }) {
6349
6357
  if (schema.$ref) {
6350
6358
  const query = {
6351
6359
  category: "transform",
@@ -6450,14 +6458,16 @@ const processSchemaType = ({ dataExpression, plugin, schema }) => {
6450
6458
  }
6451
6459
  for (const transformer of plugin.config.transformers) {
6452
6460
  const t = transformer({
6461
+ $,
6453
6462
  config: plugin.config,
6454
6463
  dataExpression,
6464
+ plugin,
6455
6465
  schema
6456
6466
  });
6457
6467
  if (t) return t;
6458
6468
  }
6459
6469
  return [];
6460
- };
6470
+ }
6461
6471
  const handler$9 = ({ plugin }) => {
6462
6472
  plugin.forEach("operation", ({ operation }) => {
6463
6473
  const { response } = operationResponsesMap(operation);
@@ -7266,7 +7276,11 @@ function createVisitor$4(config) {
7266
7276
  }
7267
7277
  const transformersPlugin = ctx.plugin.getPlugin("@hey-api/transformers");
7268
7278
  if (transformersPlugin?.config.typeTransformers) for (const typeTransformer of transformersPlugin.config.typeTransformers) {
7269
- const typeNode = typeTransformer({ schema });
7279
+ const typeNode = typeTransformer({
7280
+ $,
7281
+ plugin: transformersPlugin,
7282
+ schema
7283
+ });
7270
7284
  if (typeNode) return {
7271
7285
  meta: defaultMeta$2(schema),
7272
7286
  type: typeNode
@@ -15912,4 +15926,4 @@ async function resolveJobs({ logger, userConfigs }) {
15912
15926
 
15913
15927
  //#endregion
15914
15928
  export { postProcessors as _, clientDefaultConfig as a, TypeScriptRenderer as c, reserved as d, keywords as f, getTypedConfig as g, getClientPlugin as h, generateClientBundle as i, TsDslContext as l, TsDsl as m, defaultPlugins as n, clientDefaultMeta as o, regexp as p, clientPluginHandler as r, $ as s, resolveJobs as t, ctx as u };
15915
- //# sourceMappingURL=init-C6327prb.mjs.map
15929
+ //# sourceMappingURL=init-OaZZcRie.mjs.map