shiftapi 0.0.19 → 0.0.21

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.
@@ -59,12 +59,13 @@ function indent(text, spaces = 2) {
59
59
  const prefix = " ".repeat(spaces);
60
60
  return text.split("\n").map((line) => line ? prefix + line : line).join("\n");
61
61
  }
62
- function dtsTemplate(generatedTypes) {
62
+ function dtsTemplate(generatedTypes, openapiImport) {
63
+ const src = openapiImport ?? "openapi-fetch";
63
64
  return `// Auto-generated by shiftapi. Do not edit.
64
65
  declare module "@shiftapi/client" {
65
66
  ${indent(generatedTypes)}
66
67
 
67
- import type createClient from "openapi-fetch";
68
+ import type createClient from "${src}";
68
69
 
69
70
  export const client: ReturnType<typeof createClient<paths>>;
70
71
  export { createClient };
@@ -86,7 +87,7 @@ export { createClient };
86
87
  function nextClientJsTemplate(port, baseUrl, devApiPrefix) {
87
88
  if (!devApiPrefix) {
88
89
  return `// Auto-generated by @shiftapi/next. Do not edit.
89
- import createClient from "openapi-fetch";
90
+ import createClient from "./openapi-fetch.js";
90
91
 
91
92
  const baseUrl =
92
93
  process.env.NEXT_PUBLIC_SHIFTAPI_BASE_URL || ${JSON.stringify(baseUrl)};
@@ -99,7 +100,7 @@ export { createClient };
99
100
  }
100
101
  const devServerUrl = `http://localhost:${port}`;
101
102
  return `// Auto-generated by @shiftapi/next. Do not edit.
102
- import createClient from "openapi-fetch";
103
+ import createClient from "./openapi-fetch.js";
103
104
 
104
105
  const baseUrl =
105
106
  process.env.NEXT_PUBLIC_SHIFTAPI_BASE_URL ||
@@ -146,15 +147,22 @@ function writeGeneratedFiles(typesRoot, generatedDts, baseUrl, options) {
146
147
  if (!existsSync(outDir)) {
147
148
  mkdirSync(outDir, { recursive: true });
148
149
  }
149
- writeFileSync(resolve(outDir, "client.d.ts"), dtsTemplate(generatedDts));
150
+ const useLocalOpenapi = !!options?.openapiSource;
151
+ writeFileSync(resolve(outDir, "client.d.ts"), dtsTemplate(generatedDts, useLocalOpenapi ? "./openapi-fetch.js" : void 0));
150
152
  writeFileSync(resolve(outDir, "client.js"), options?.clientJsContent ?? clientJsTemplate(baseUrl));
153
+ if (options?.openapiSource) {
154
+ writeFileSync(resolve(outDir, "openapi-fetch.js"), options.openapiSource);
155
+ }
156
+ if (options?.openapiDts) {
157
+ writeFileSync(resolve(outDir, "openapi-fetch.d.ts"), options.openapiDts);
158
+ }
151
159
  writeFileSync(
152
160
  resolve(outDir, "tsconfig.json"),
153
161
  JSON.stringify(
154
162
  {
155
163
  compilerOptions: {
156
164
  paths: {
157
- [MODULE_ID]: ["./client.d.ts"]
165
+ [MODULE_ID]: ["./client"]
158
166
  }
159
167
  }
160
168
  },
@@ -176,15 +184,15 @@ function patchTsConfigPaths(tsconfigDir, typesRoot) {
176
184
  );
177
185
  return;
178
186
  }
179
- const dtsRel = relative(tsconfigDir, resolve(typesRoot, ".shiftapi", "client.d.ts"));
180
- const dtsPath = dtsRel.startsWith("..") ? dtsRel : `./${dtsRel}`;
187
+ const clientRel = relative(tsconfigDir, resolve(typesRoot, ".shiftapi", "client"));
188
+ const clientPath = clientRel.startsWith("..") ? clientRel : `./${clientRel}`;
181
189
  tsconfig.compilerOptions = tsconfig.compilerOptions || {};
182
190
  tsconfig.compilerOptions.paths = tsconfig.compilerOptions.paths || {};
183
191
  const existing = tsconfig.compilerOptions.paths[MODULE_ID];
184
- if (Array.isArray(existing) && existing.length === 1 && existing[0] === dtsPath) {
192
+ if (Array.isArray(existing) && existing.length === 1 && existing[0] === clientPath) {
185
193
  return;
186
194
  }
187
- tsconfig.compilerOptions.paths[MODULE_ID] = [dtsPath];
195
+ tsconfig.compilerOptions.paths[MODULE_ID] = [clientPath];
188
196
  const detectedIndent = raw.match(/^[ \t]+/m)?.[0] ?? " ";
189
197
  writeFileSync(tsconfigPath, stringify(tsconfig, null, detectedIndent) + "\n");
190
198
  console.log(
@@ -7,6 +7,8 @@ declare function regenerateTypes(serverEntry: string, goRoot: string, baseUrl: s
7
7
  }>;
8
8
  declare function writeGeneratedFiles(typesRoot: string, generatedDts: string, baseUrl: string, options?: {
9
9
  clientJsContent?: string;
10
+ openapiSource?: string;
11
+ openapiDts?: string;
10
12
  }): void;
11
13
  declare function patchTsConfigPaths(tsconfigDir: string, typesRoot: string): void;
12
14
 
@@ -23,7 +25,7 @@ declare function extractSpec(serverEntry: string, goRoot: string): object;
23
25
  */
24
26
  declare function generateTypes(spec: object): Promise<string>;
25
27
 
26
- declare function dtsTemplate(generatedTypes: string): string;
28
+ declare function dtsTemplate(generatedTypes: string, openapiImport?: string): string;
27
29
  declare function clientJsTemplate(baseUrl: string): string;
28
30
  declare function nextClientJsTemplate(port: number, baseUrl: string, devApiPrefix?: string): string;
29
31
  declare function virtualModuleTemplate(baseUrl: string, devApiPrefix?: string): string;
package/dist/internal.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  regenerateTypes,
12
12
  virtualModuleTemplate,
13
13
  writeGeneratedFiles
14
- } from "./chunk-DQX3QC7F.js";
14
+ } from "./chunk-7OWLTM22.js";
15
15
  import {
16
16
  defineConfig,
17
17
  findConfigDir,
package/dist/prepare.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  generateTypes,
5
5
  patchTsConfigPaths,
6
6
  writeGeneratedFiles
7
- } from "./chunk-DQX3QC7F.js";
7
+ } from "./chunk-7OWLTM22.js";
8
8
  import {
9
9
  loadConfig
10
10
  } from "./chunk-EQN44FQG.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shiftapi",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "CLI and codegen for shiftapi – fully-typed TypeScript clients from Go servers",
5
5
  "author": "Frank Chiarulli Jr. <frank@frankchiarulli.com>",
6
6
  "license": "MIT",